5 Sepia - Simple Emacs-Perl Interface
11 M-x load-library RET sepia RET
14 At the prompt in the C<*sepia-repl*> buffer:
18 For more information, please see F<Sepia.html> or F<sepia.info>, which
19 come with the distribution.
26 use Sepia
::Debug
; # THIS TURNS ON DEBUGGING INFORMATION!
28 use Scalar
::Util
'looks_like_number';
31 use vars
qw($PS1 %REPL %RK %REPL_DOC %REPL_SHORT %PRINTER
33 $REPL_LEVEL $PACKAGE $WANTARRAY $PRINTER $STRICT $PRINT_PRETTY
38 eval { require Lexical::Persistence; import Lexical::Persistence };
40 print "Strict mode requires Lexical::Persistence.\n";
43 my $x = as_boolean(shift, $STRICT);
45 $STRICT = new Lexical::Persistence;
56 eval { require Module::CoreList };
60 *core_version = sub { Module::CoreList->first_release(@_) };
66 eval { use List::Util 'max' };
71 $ret = $_ if $_ > $ret;
80 eval { require Devel::Size };
82 print "Size requires Devel::Size.\n";
84 *Sepia::repl_size = sub {
86 ## XXX: C&P from repl_who:
87 my ($pkg, $re) = split ' ', shift || '';
88 if ($pkg =~ /^\/(.*)\/?$/) {
91 } elsif (!$re && !%{$pkg.'::'}) {
98 my @who = who($pkg, $re);
99 my $len = max(3, map { length } @who) + 4;
100 my $fmt = '%-'.$len."s%10d\n";
101 print 'Var', ' ' x ($len + 2), "Bytes\n";
102 print '-' x ($len-4), ' ' x 9, '-' x 5, "\n";
104 next unless /^[\$\@\%\&]/; # skip subs.
105 next if $_ eq '%SIG';
106 my $res = eval "no strict; package $pkg; Devel::Size::total_size \\$_;";
107 print "aiee: $@\n" if $@;
108 printf $fmt, $_, $res;
117 Sepia is a set of features to make Emacs a better tool for Perl
118 development. This package contains the Perl side of the
119 implementation, including all user-serviceable parts (for the
120 cross-referencing facility see L<Sepia::Xref>). This document is
121 aimed as Sepia developers; for user documentation, see
124 Though not intended to be used independent of the Emacs interface, the
125 Sepia module's functionality can be used through a rough procedural
128 =head2 C<@compls = completions($string [, $type])>
130 Find a list of completions for C<$string> with glob type C<$type>,
131 which may be "SCALAR", "HASH", "ARRAY", "CODE", "IO", or the special
132 value "VARIABLE", which means either scalar, hash, or array.
133 Completion operates on word subparts separated by [:_], so
134 e.g. "S:m_w" completes to "Sepia::my_walksymtable".
136 =head2 C<@compls = method_completions($expr, $string [,$eval])>
138 Complete among methods on the object returned by C<$expr>. The
139 C<$eval> argument, if present, is a function used to do the
140 evaluation; the default is C<eval>, but for example the Sepia REPL
141 uses C<Sepia::repl_eval>. B<Warning>: Since it has to evaluate
142 C<$expr>, method completion can be extremely problematic. Use with
149 # Do that crazy multi-word identifier completion thing:
151 return qr/.*/ if $re eq '';
154 s/(?:^|(?<=[A-Za-z\d]))(([^A-Za-z\d])\2*)/[A-Za-z\\d]*$2+/g;
156 } split /:+/, $re, -1;
158 if ($re !~ /[^\w\d_^:]/) {
159 $re =~ s/(?<=[A-Za-z\d])(([^A-Za-z\d])\2*)/[A-Za-z\\d]*$2+/g;
167 %sigil = qw(ARRAY @ SCALAR $ HASH %);
173 local $_ = /^::/ ?
$_ : "::$_";
174 defined *{$_}{CODE
} || defined *{$_}{IO
} || (/::$/ && %$_);
177 ## XXX: Careful about autovivification here! Specifically:
178 ## defined *FOO{HASH} # => ''
179 ## defined %FOO # => ''
180 ## defined *FOO{HASH} # => 1
185 local $_ = /^::/ ?
$_ : "::$_";
186 if ($type eq 'SCALAR') {
188 } elsif ($type eq 'VARIABLE') {
189 defined $$_ || defined *{$_}{HASH
} || defined *{$_}{ARRAY
};
198 $ch =~ /[A-Z]/ ?
$ch : '['.uc($ch).$ch.']';
201 sub all_abbrev_completions
203 use vars
'&_completions';
204 local *_completions
= sub {
206 my ($stash, @e) = @_;
207 my $ch = '[A-Za-z0-9]*';
208 my $re1 = "^".maybe_icase
($e[0]).$ch.join('', map {
209 '_'.maybe_icase
($_).$ch
212 my $re2 = maybe_icase
$e[0];
213 $re2 = qr/^$re2.*::$/;
214 my @ret = grep !/::$/ && /$re1/, keys %{$stash};
215 my @pkgs = grep /$re2/, keys %{$stash};
216 (map("$stash$_", @ret),
217 @e > 1 ?
map { _completions
"$stash$_", @e[1..$#e] } @pkgs :
218 map { "$stash$_" } @pkgs)
220 map { s/^:://; $_ } _completions
('::', split //, shift);
225 my ($icase, $re) = @_;
227 $icase ?
qr/^$re.*$/i : qr/^$re.*$/;
232 my $icase = $_[0] !~ /[A-Z]/;
233 my @parts = split /:+/, shift, -1;
234 my $re = apropos_re
$icase, pop @parts;
235 use vars
'&_completions';
236 local *_completions
= sub {
240 map { "$stash$_" } grep /$re/, keys %{$stash};
242 my $re2 = $icase ?
qr/^$_[0].*::$/i : qr/^$_[0].*::$/;
243 my @pkgs = grep /$re2/, keys %{$stash};
244 map { _completions
"$stash$_", @_[1..$#_] } @pkgs
247 map { s/^:://; $_ } _completions
('::', @parts);
252 my ($type, $str, $t);
253 my %h = qw(@ ARRAY % HASH & CODE * IO $ SCALAR);
255 @rh{values %h} = keys %h;
257 ($type, $str) = $_[0] =~ /^([\%\$\@\&]?)(.*)/;
259 $type = $h{$type} if $type;
263 $t = $rh{$type} if $type;
266 $type ? filter_typed
$type : filter_untyped
267 } all_completions
$str;
268 if (!@ret && $str !~ /:/) {
270 $type ? filter_typed
$type : filter_untyped
271 } all_abbrev_completions
$str;
273 @ret = map { s/^:://; "$t$_" } @ret;
274 # ## XXX: Control characters, $", and $1, etc. confuse Emacs, so
277 length > 0 && !looks_like_number
$_ && !/^[^\w\d_]$/ && !/^_</ && !/^[[:cntrl:]]/
281 sub method_completions
283 my ($x, $fn, $eval) = @_;
286 $eval ||= 'CORE::eval';
288 return unless ($x =~ /^\$/ && ($x = $eval->("ref($x)")))
289 || $eval->('%'.$x.'::');
291 my $re = _apropos_re
$fn;
292 ## Filter out overload methods "(..."
293 return sort { $a cmp $b } map { s/.*:://; $_ }
294 grep { defined *{$_}{CODE
} && /::$re/ && !/\(/ }
299 =head2 C<@locs = location(@names)>
301 Return a list of [file, line, name] triples, one for each function
311 if (my ($pfx, $name) = $str =~ /^([\%\$\@]?)(.+)/) {
313 warn "Sorry -- can't lookup variables.";
316 # XXX: svref_2object only seems to work with a package
317 # tacked on, but that should probably be done
319 $name = 'main::'.$name unless $name =~ /::/;
320 my $cv = B
::svref_2object
(\
&{$name});
321 if ($cv && defined($cv = $cv->START) && !$cv->isa('B::NULL')) {
322 my ($file, $line) = ($cv->file, $cv->line);
323 if ($file !~ /^\//) {
331 my ($shortname) = $name =~ /^(?:.*::)([^:]+)$/;
332 [Cwd
::abs_path
($file), $line, $shortname || $name]
334 # warn "Bad CV for $name: $cv";
345 =head2 C<@matches = apropos($name [, $is_regex])>
347 Search for function C<$name>, either in all packages or, if C<$name>
348 is qualified, only in one package. If C<$is_regex> is true, the
349 non-package part of C<$name> is a regular expression.
353 sub my_walksymtable
(&*)
359 &$f for keys %$stash;
360 _walk
("$stash$_") for grep /(?<!main)::$/, keys %$stash;
367 my ($it, $re, @types) = @_;
370 $stashp = grep /STASH/, @types;
371 @types = grep !/STASH/, @types;
376 if ($it =~ /^(.*::)([^:]+)$/) {
377 my ($stash, $name) = ($1, $2);
382 my $name = qr/^$name/;
387 my $stashnm = "$stash$_";
391 defined($_ eq 'SCALAR' ?
$$stashnm : *{$stashnm}{$_})
395 defined &$it ?
$it : ();
399 my $findre = $re ?
qr/$it/ : qr/^\Q$it\E$/;
401 push @ret, "$stash$_" if /$findre/;
403 map { s/^:*(?:main:+)*//;$_ } @ret;
407 =head2 C<@names = mod_subs($pack)>
409 Find subs in package C<$pack>.
417 my $stash = \
%{"$p\::"};
419 grep { defined &{"$p\::$_"} } keys %$stash;
423 =head2 C<@decls = mod_decls($pack)>
425 Generate a list of declarations for all subroutines in package
436 my $proto = prototype(\
&{"$pack\::$sn"});
437 $proto = defined($proto) ?
"($proto)" : '';
440 return wantarray ?
@ret : join '', @ret;
443 =head2 C<$info = module_info($module, $type)>
445 Emacs-called function to get module information.
451 eval { require Module
::Info
; import Module
::Info
};
459 $info = Module
::Info
->new_from_file($m);
461 (my $file = $m) =~ s
|::|/|g
;
463 if (exists $INC{$file}) {
464 $info = Module
::Info
->new_from_loaded($m);
466 $info = Module
::Info
->new_from_module($m);
477 =head2 C<$file = mod_file($mod)>
479 Find the likely file owner for module C<$mod>.
487 while ($m && !exists $INC{"$m.pm"}) {
488 $m =~ s
#(?:^|/)[^/]+$##;
490 $m ?
$INC{"$m.pm"} : undef;
493 =head2 C<@mods = package_list>
495 Gather a list of all distributions on the system. XXX UNUSED
503 eval 'require ExtUtils::Installed';
504 $INST = new ExtUtils
::Installed
;
511 sort { $a cmp $b } inst
()->modules;
514 =head2 C<@mods = module_list>
516 Gather a list of all packages (.pm files, really) installed on the
517 system, grouped by distribution. XXX UNUSED
523 @_ = package_list
unless @_;
524 my $incre = join '|', map quotemeta, @INC;
525 $incre = qr
|(?
:$incre)/|;
529 s/$incre//; s
|/|::|g
;$_
530 } grep /\.pm$/, $inst->files($_)]
534 =head2 C<@mods = doc_list>
536 Gather a list of all documented packages (.?pm files, really)
537 installed on the system, grouped by distribution. XXX UNUSED
543 @_ = package_list
unless @_;
547 s/.*man.\///; s|/|::|g
;s/\..?pm//; $_
548 } grep /\..pm$/, $inst->files($_)]
552 =head2 C<lexicals($subname)>
554 Return a list of C<$subname>'s lexical variables. Note that this
555 includes all nested scopes -- I don't know if or how Perl
556 distinguishes inner blocks.
562 my $cv = B
::svref_2object
(\
&{+shift});
563 return unless $cv && ($cv = $cv->PADLIST);
564 my ($names, $vals) = $cv->ARRAY;
566 my $name = $_->PV; $name =~ s/\0.*$//; $name
567 } grep B
::class($_) ne 'SPECIAL', $names->ARRAY;
570 =head2 C<$lisp = tolisp($perl)>
572 Convert a Perl scalar to some ELisp equivalent.
578 my $thing = @_ == 1 ?
shift : \
@_;
581 if (!defined $thing) {
583 } elsif (looks_like_number
$thing) {
586 ## XXX Elisp and perl have slightly different
587 ## escaping conventions, so we do this crap instead.
588 $thing =~ s/["\\]/\\$1/g;
591 } elsif ($t eq 'GLOB') {
592 (my $name = $$thing) =~ s/\*main:://;
594 } elsif ($t eq 'ARRAY') {
595 '(' . join(' ', map { tolisp
($_) } @
$thing).')'
596 } elsif ($t eq 'HASH') {
597 '(' . join(' ', map {
598 '(' . tolisp
($_) . " . " . tolisp
($thing->{$_}) . ')'
600 } elsif ($t eq 'Regexp') {
601 "'(regexp . \"" . quotemeta($thing) . '")';
602 # } elsif ($t eq 'IO') {
608 =head2 C<printer(\@res, $wantarray)>
610 Print C<@res> appropriately on the current filehandle. If C<$ISEVAL>
611 is true, use terse format. Otherwise, use human-readable format,
612 which can use either L<Data::Dumper>, L<YAML>, or L<Data::Dump>.
618 eval { require Data
::Dumper
};
619 local $Data::Dumper
::Deparse
= 1;
620 local $Data::Dumper
::Indent
= 0;
622 my $thing = @res > 1 ? \
@res : $res[0];
624 $_ = Data
::Dumper
::Dumper
($thing);
628 if (length $_ > ($ENV{COLUMNS
} || 80)) {
629 $Data::Dumper
::Indent
= 1;
631 $_ = Data
::Dumper
::Dumper
($thing);
644 eval { require YAML
};
646 $PRINTER{dumper
}->();
652 eval { require Data
::Dump
};
654 $PRINTER{dumper
}->();
656 Data
::Dump
::dump(\
@res);
664 my ($wantarray) = @_;
667 $::__
= @res == 1 ?
$res[0] : [@res];
671 } elsif (@res == 1 && UNIVERSAL
::can
($res[0], '()')) {
674 } elsif (!$ISEVAL && $PRINT_PRETTY && @res > 1 && !grep ref, @res) {
675 $res = columnate
(@res);
679 $res = $PRINTER{$PRINTER}->();
682 print ';;;', length $res, "\n$res\n";
698 "$PACKAGE ".($WANTARRAY ?
'@' : '$').$PS1
704 Data
::Dumper
->Dump([$_[0]], [$_[1]]);
711 my $n1 = int(2*$n/3);
713 s/(.{$n1,$n}) /$1\n/g;
717 =head2 C<define_shortcut $name, $sub [, $doc [, $shortdoc]]>
719 Define $name as a shortcut for function $sub.
725 my ($name, $doc, $short, $fn);
731 ($name, $fn, $doc) = @_;
734 ($name, $fn, $short, $doc) = @_;
737 $REPL_DOC{$name} = $doc;
738 $REPL_SHORT{$name} = $short;
743 define_shortcut
'help', \
&Sepia
::repl_help
,
745 'Display help on all commands, or just CMD.';
746 define_shortcut
'cd', \
&Sepia
::repl_chdir
,
747 'cd DIR', 'Change directory to DIR';
748 define_shortcut
'pwd', \
&Sepia
::repl_pwd
,
749 'Show current working directory';
750 define_shortcut
'methods', \
&Sepia
::repl_methods
,
752 'List methods for reference or package X, matching optional pattern RE';
753 define_shortcut
'package', \
&Sepia
::repl_package
,
754 'package PKG', 'Set evaluation package to PKG';
755 define_shortcut
'who', \
&Sepia
::repl_who
,
757 'List variables and subs in PKG matching optional pattern RE.';
758 define_shortcut
'wantarray', \
&Sepia
::repl_wantarray
,
759 'wantarray [0|1]', 'Set or toggle evaluation context';
760 define_shortcut
'format', \
&Sepia
::repl_format
,
761 'format [TYPE]', "Set output formatter to TYPE (one of 'dumper', 'dump', 'yaml', 'plain'; default: 'dumper'), or show current type.";
762 define_shortcut
'strict', \
&Sepia
::repl_strict
,
763 'strict [0|1]', 'Turn \'use strict\' mode on or off';
764 define_shortcut
'quit', \
&Sepia
::repl_quit
,
766 define_shortcut
'reload', \
&Sepia
::repl_reload
,
767 'Reload Sepia.pm and relaunch the REPL.';
768 define_shortcut
'shell', \
&Sepia
::repl_shell
,
769 'shell CMD ...', 'Run CMD in the shell';
770 define_shortcut
'eval', \
&Sepia
::repl_eval
,
771 'eval EXP', '(internal)';
772 define_shortcut
'size', \
&Sepia
::repl_size
,
774 'List total sizes of objects in PKG matching optional pattern RE.';
775 define_shortcut define
=> \
&Sepia
::repl_define
,
776 'define NAME [\'doc\'] BODY',
777 'Define NAME as a shortcut executing BODY';
778 define_shortcut
undef => \
&Sepia
::repl_undef
,
779 'undef NAME', 'Undefine shortcut NAME';
784 my $width = $ENV{COLUMNS
} || 80;
789 my $full = $RK{$args};
792 flow
($width - length $RK{$full} - 4, $REPL_DOC{$full}), "\n";
794 print "$args: no such command\n";
797 my $left = 1 + max
map length, values %REPL_SHORT;
798 print "REPL commands (prefixed with ','):\n";
800 for (sort keys %REPL) {
801 my $flow = flow
($width - $left, $REPL_DOC{$_});
802 $flow =~ s/(.)\n/"$1\n".(' ' x $left)/eg;
803 printf "%-${left}s%s\n", $REPL_SHORT{$_}, $flow;
811 my ($name, $doc, $body);
812 if (/^\s*(\S+)\s+'((?:[^'\\]|\\.)*)'\s+(.+)/) {
813 ($name, $doc, $body) = ($1, $2, $3);
814 } elsif (/^\s*(\S+)\s+(\S.*)/) {
815 ($name, $doc, $body) = ($1, $2, $2);
817 print "usage: define NAME ['doc'] BODY...\n";
820 my $sub = eval "sub { do { $body } }";
822 print "usage: define NAME ['doc'] BODY...\n\t$@\n";
825 define_shortcut
$name, $sub, $doc;
826 %RK = abbrev
keys %REPL;
834 my $full = $RK{$name};
837 delete $REPL_SHORT{$full};
838 delete $REPL_DOC{$full};
839 %RK = abbrev
keys %REPL;
841 print "$name: no such shortcut.\n";
850 print "printer = $PRINTER, pretty = @{[$PRINT_PRETTY ? 1 : 0]}\n";
852 my %formats = abbrev
keys %PRINTER;
853 if (exists $formats{$t}) {
854 $PRINTER = $formats{$t};
856 warn "No such format '$t' (dumper, dump, yaml, plain).\n";
863 chomp(my $dir = shift);
864 $dir =~ s/^~\//$ENV{HOME
}\
//;
865 $dir =~ s/\$HOME/$ENV{HOME}/;
868 my $ecmd = '(cd "'.Cwd
::getcwd
().'")';
869 print ";;;###".length($ecmd)."\n$ecmd\n";
871 warn "Can't chdir\n";
877 print Cwd
::getcwd
(), "\n";
882 my ($pack, $re_str) = @_;
884 my $re = qr/$re_str/;
886 if ($re_str =~ /^[\$\@\%\&]/) {
887 ## sigil given -- match it
888 sort grep /$re/, map {
889 my $name = $pack.'::'.$_;
890 (defined *{$name}{HASH
} ?
'%'.$_ : (),
891 defined *{$name}{ARRAY
} ?
'@'.$_ : (),
892 defined *{$name}{CODE
} ?
$_ : (),
893 defined ${$name} ?
'$'.$_ : (), # ?
895 } grep !/::$/ && !/^(?:_<|[^\w])/ && /$re/, keys %{$pack.'::'};
897 ## no sigil -- don't match it
899 my $name = $pack.'::'.$_;
900 (defined *{$name}{HASH
} ?
'%'.$_ : (),
901 defined *{$name}{ARRAY
} ?
'@'.$_ : (),
902 defined *{$name}{CODE
} ?
$_ : (),
903 defined ${$name} ?
'$'.$_ : (), # ?
905 } grep !/::$/ && !/^(?:_<|[^\w])/ && /$re/, keys %{$pack.'::'};
913 my $width = $ENV{COLUMNS
} || 80;
915 $len = length if $len < length;
917 my $nc = int($width / ($len+1)) || 1;
918 my $nr = int(@_ / $nc) + (@_ % $nc ?
1 : 0);
919 my $fmt = ('%-'.($len+1).'s') x
($nc-1) . "%s\n";
920 my @incs = map { $_ * $nr } 0..$nc-1;
922 for my $r (0..$nr-1) {
923 $str .= sprintf $fmt, map { defined($_) ?
$_ : '' }
924 @_[map { $r + $_ } @incs];
932 my ($pkg, $re) = split ' ', shift;
934 if ($pkg =~ /^\/(.*)\
/?$/) {
937 } elsif (!$re && !%{$pkg.'::'}) {
941 print columnate who
($pkg || $PACKAGE, $re);
946 my ($pack, $qualified) = @_;
948 my @own = $qualified ?
grep {
950 } map { "$pack\::$_" } keys %{$pack.'::'}
952 defined *{"$pack\::$_"}{CODE
}
953 } keys %{$pack.'::'};
954 (@own, defined *{$pack.'::ISA'}{ARRAY
}
955 ?
(map methods
($_, $qualified), @
{$pack.'::ISA'}) : ());
960 my ($x, $re) = split ' ', shift;
964 $x = $REPL{eval}->("ref $x");
969 print columnate
sort { $a cmp $b } grep /$re/, methods
$x;
974 my ($val, $cur) = @_;
976 length($val) ?
$val : !$cur;
981 $WANTARRAY = as_boolean
shift, $WANTARRAY;
986 chomp(my $p = shift);
990 # my $ecmd = '(setq sepia-eval-package "'.$p.'")';
991 # print ";;;###".length($ecmd)."\n$ecmd\n";
993 warn "Can't go to package $p -- doesn't exist!\n";
1004 do $INC{'Sepia.pm'};
1006 print "Reload failed:\n$@\n";
1008 $REPL_LEVEL = 0; # ok?
1023 # local $PACKAGE = $pkg || $PACKAGE;
1026 $buf = 'scalar($buf)';
1028 my $ctx = join(',', keys %{$STRICT->get_context('_')});
1029 $ctx = $ctx ?
"my ($ctx);" : '';
1030 $buf = eval "sub { package $PACKAGE; use strict; $ctx $buf }";
1032 print "ERROR\n$@\n";
1035 $STRICT->call($buf);
1037 $buf = "do { package $PACKAGE; no strict; $buf }";
1046 ## Collects warnings for REPL
1059 print ';;;'.length($tmp)."\n$tmp\n";
1063 print "warning: $_\n";
1072 I need user feedback! Please send questions or comments to seano\@cpan.org.
1073 Sepia version $Sepia::VERSION.
1074 Type ",h" for help, or ",q" to quit.
1080 Execute a command interpreter on standard input and standard output.
1081 If you want to use different descriptors, localize them before
1082 calling C<repl()>. The prompt has a few bells and whistles, including:
1086 =item Obviously-incomplete lines are treated as multiline input (press
1087 'return' twice or 'C-c' to discard).
1089 =item C<die> is overridden to enter a debugging repl at the point
1094 Behavior is controlled in part through the following package-globals:
1098 =item C<$PACKAGE> -- evaluation package
1100 =item C<$PRINTER> -- result printer (default: dumper)
1102 =item C<$PS1> -- the default prompt
1104 =item C<$STRICT> -- whether 'use strict' is applied to input
1106 =item C<$WANTARRAY> -- evaluation context
1108 =item C<$PRINT_PRETTY> -- format some output nicely (default = 1)
1110 Format some values nicely, independent of $PRINTER. Currently, this
1111 displays arrays of scalars as columns.
1113 =item C<$REPL_LEVEL> -- level of recursive repl() calls
1115 If zero, then initialization takes place.
1117 =item C<%REPL> -- maps shortcut names to handlers
1119 =item C<%REPL_DOC> -- maps shortcut names to documentation
1121 =item C<%REPL_SHORT> -- maps shortcut names to brief usage
1130 if ($REPL_LEVEL == 0) {
1132 -f
"$ENV{HOME}/.sepiarc" and do "$ENV{HOME}/.sepiarc";
1133 warn ".sepiarc: $@\n" if $@
;
1135 local $REPL_LEVEL = $REPL_LEVEL + 1;
1141 my $nextrepl = sub { $sigged = 1; };
1144 local *CORE
::GLOBAL
::die = \
&Sepia
::Debug
::die;
1145 local *CORE
::GLOBAL
::warn = \
&Sepia
::Debug
::warn;
1147 Sepia
::Debug
::add_repl_commands
;
1148 repl_banner
if $REPL_LEVEL == 1;
1150 my @sigs = qw(INT TERM PIPE ALRM);
1152 $SIG{$_} = $nextrepl for @sigs;
1153 repl
: while (defined(my $in = <STDIN
>)) {
1163 if ($buf =~ /^<<(\d+)\n(.*)/) {
1168 while ($len && defined($tmp = read STDIN
, $buf, $len, length $buf)) {
1173 ## Only install a magic handler if no one else is playing.
1174 local $SIG{__WARN__
} = $SIG{__WARN__
};
1176 unless ($SIG{__WARN__
}) {
1177 $SIG{__WARN__
} = 'Sepia::sig_warn';
1179 if ($buf =~ /^,(\S+)\s*(.*)/s) {
1180 ## Inspector shortcuts
1182 if (exists $Sepia::RK
{$short}) {
1186 $Sepia::REPL
{$Sepia::RK
{$short}}->($arg, wantarray);
1188 if (grep /^$short/, keys %Sepia::REPL
) {
1189 print "Ambiguous shortcut '$short': ",
1190 join(', ', sort grep /^$short/, keys %Sepia::REPL
),
1193 print "Unrecognized shortcut '$short'\n";
1201 @res = $REPL{eval}->($buf);
1204 ## Always return results for an eval request
1205 Sepia
::printer \
@res, wantarray;
1206 Sepia
::printer
[$@
], wantarray;
1207 # print_warnings $ISEVAL;
1210 } elsif ($@
=~ /(?:at|before) EOF(?:$| at)/m) {
1211 ## Possibly-incomplete line
1213 print "Error:\n$@\n*** cancel ***\n", prompt
;
1220 # $@ =~ s/(.*) at eval .*/$1/;
1221 # don't complain if we're abandoning execution
1222 # from the debugger.
1223 unless (ref $@
eq 'Sepia::Debug') {
1225 print "\n" unless $@
=~ /\n\z/;
1233 if ($buf !~ /;\s*$/ && $buf !~ /^,/) {
1234 ## Be quiet if it ends with a semicolon, or if we
1235 ## executed a shortcut.
1236 Sepia
::printer \
@res, wantarray;
1242 wantarray ?
@REPL_RESULT : $REPL_RESULT[0]
1247 tolisp
($REPL{eval}->(shift));
1250 =head2 C<$status = html_module_list([$file [, $prefix]])>
1252 Generate an HTML list of installed modules, looking inside of
1253 packages. If C<$prefix> is missing, uses "about://perldoc/". If
1254 $file is given, write the result to $file; otherwise, return it as a
1257 =head2 C<$status = html_package_list([$file [, $prefix]])>
1259 Generate an HTML list of installed top-level modules, without looking
1260 inside of packages. If C<$prefix> is missing, uses
1261 "about://perldoc/". $file is the same as for C<html_module_list>.
1265 sub html_module_list
1267 my ($file, $base) = @_;
1268 $base ||= 'about://perldoc/';
1270 return unless $inst;
1272 open OUT
, ">", $file || \
$out or return;
1273 print OUT
"<html><body><ul>";
1276 for (package_list
) {
1277 push @
{$ns{$1}}, $_ if /^([^:]+)/;
1279 for (sort keys %ns) {
1280 print OUT
qq{<li
><b
>$_</b
><ul
>} if @
{$ns{$_}} > 1;
1281 for (sort @
{$ns{$_}}) {
1283 s/.*man.\///; s|/|::|g
; s/\.\d(?:pm)?$//; $_
1284 } grep /\.\d(?:pm)?$/, sort $inst->files($_);
1286 print OUT
qq{<li
><a href
="$base$fs[0]">$fs[0]</a
>};
1288 print OUT
qq{<li
>$_<ul
>};
1290 print OUT
qq{<li
><a href
="$base$_">$_</a
>};
1295 print OUT
qq{</ul
>} if @
{$ns{$_}} > 1;
1297 print OUT
"</ul></body></html>\n";
1302 sub html_package_list
1304 my ($file, $base) = @_;
1305 return unless inst
();
1306 $base ||= 'about://perldoc/';
1308 open OUT
, ">", $file || \
$out or return;
1309 print OUT
"<html><body><ul>";
1312 for (package_list
) {
1313 push @
{$ns{$1}}, $_ if /^([^:]+)/;
1315 for (sort keys %ns) {
1316 if (@
{$ns{$_}} == 1) {
1318 qq{<li
><a href
="$base$ns{$_}[0]">$ns{$_}[0]</a
>};
1320 print OUT
qq{<li
><b
>$_</b
><ul
>};
1321 print OUT
qq{<li
><a href
="$base$_">$_</a
>}
1322 for sort @
{$ns{$_}};
1323 print OUT
qq{</ul
>};
1326 print OUT
"</ul></body></html>\n";
1336 See the README file included with the distribution.
1340 Sepia's public GIT repository is located at L<http://repo.or.cz/w/sepia.git>.
1342 There are several modules for Perl development in Emacs on CPAN,
1343 including L<Devel::PerlySense> and L<PDE>. For a complete list, see
1344 L<http://emacswiki.org/cgi-bin/wiki/PerlLanguage>.
1348 Sean O'Rourke, E<lt>seano@cpan.orgE<gt>
1350 Bug reports welcome, patches even more welcome.
1354 Copyright (C) 2005-2008 Sean O'Rourke. All rights reserved, some
1355 wrongs reversed. This module is distributed under the same terms as