Change $WANTARRAY and repl_wantarray to allow specifying void context.
[sepia.git] / sepia.texi
blob39c01f98f20eb4a3c43a12942d1e9801ccc7e2fd
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename sepia.info
4 @settitle SEPIA: Simple Emacs Perl Integration
5 @dircategory Emacs
6 @direntry
7 * Sepia: (sepia).    Simple Emacs Perl Integration.
8 @end direntry
9 @c %**end of header
11 @titlepage
12 @title Sepia: Simple Emacs Perl Integration
13 @author Sean O'Rourke
14 @end titlepage
16 @macro kbinding{key,cmd}
17 @item \key\ `\cmd\'
18 @kindex \key\
19 @end macro
21 @macro fitem{name}
22 @item \name\
23 @findex \name\
24 @end macro
26 @macro xxx{stuff}
27 @b{XXX: \stuff\}
28 @end macro
30 @node Top, Introduction, (dir), (dir)
32 @ifinfo
33 @top SEPIA
34 @end ifinfo
36 @ifhtml
37 @image{Sepia,,,,jpg}
38 @end ifhtml
40 Sepia is a set of Perl development tools for Emacs supporting code
41 navigation and interactive evaluation.
43 @menu
44 * Introduction::                
45 * Editing::                     
46 * Interactive Perl::            
47 * CPAN browsing::               
48 * Customization::               
49 * Internals::                   
50 * Credits::                     
51 * Function Index::              
52 * Variable Index::              
53 @end menu
55 @c ============================================================
56 @node Introduction, Editing, Top, Top
57 @chapter Introduction
59 Sepia is a set of tools for Perl development in Emacs.  Its goal is to
60 extend CPerl mode to support fast code navigation and interactive
61 development.  It is inspired by Emacs' current support for a number of
62 other languages, including Lisp, Python, and Emacs Lisp.
64 @menu
65 * Getting Started::             
66 * Philosophy::                  
67 * Related Work::                
68 @end menu
70 @node Getting Started, Philosophy, Introduction, Introduction
71 @section Getting Started
73 To install Sepia, its Emacs Lisp files must be in Emacs'
74 @code{load-path}, and the @file{lib} directory must be in Perl's
75 @code{@@INC}.  Assuming that Sepia has been unpacked in
76 @file{~/sepia}, it can be installed by adding the following lines to
77 @file{~/.emacs}:
79 @example
80 (add-to-list 'load-path "~/sepia")
81 (setq sepia-perl5lib (list (expand-file-name "~/sepia/lib")))
82 (defalias 'perl-mode 'sepia-mode)
83 (require 'sepia)
84 @end example
86 Then to bring up the interactive Perl prompt, type @kbd{M-x sepia-repl}.
88 @node Philosophy, Related Work, Getting Started, Introduction
89 @section Philosophy
91 A development environment should support three activities: code
92 spelunking, interaction, and customization.  Emacs as an environment for
93 developing Emacs Lisp thoroughly supports all of them: It has commands
94 to visit individual functions' code and documentation, commands to
95 evaluate or step through expressions, and an architecture that
96 encourages customization in Emacs Lisp.  As an environment for Perl,
97 however, it is lacking: there is limited interactivity with the Perl
98 debugger, and reasonable documentation browsing, but no support for
99 navigating, editing, and re-evaluating code.  Sepia attempts to remedy
100 the situation.
102 Modern IDEs also support these three activities, but do so awkwardly.
103 Rather than having functions to visit definitions (@kbd{find-function})
104 and search for functions (@kbd{apropos}), they clutter the screen with
105 class and file trees.  Rather than supporting interactive evaluation of
106 small pieces of code, they perform background semantic checking on whole
107 projects and highlight errors.  Rather than allowing minor
108 customizations to grow organically into features, they support limited
109 configuration files and baroque plug-in APIs.  Sepia tries to adhere to
110 the apparent Emacs philosophy that rich semantic information should be
111 unobtrusive, and that the best way to build working code is to start
112 by experimenting with small pieces.
114 Language support packages for Emacs vary widely in the degree to which
115 they make use of or replace existing Emacs features.  Minimal modes
116 provide keyword-based syntax highlighting and an unadorned comint buffer
117 as an interpreter.  Others provide their own specialized equivalents of
118 comint, eldoc, completion, and other Emacs features.  Sepia takes a
119 third approach by trying to do as much as possible with existing Emacs
120 features, even when they are not optimal for Perl.  For example, it uses
121 comint to communicate with the subprocess, eldoc to display
122 documentation, and grep to list source locations.
124 This approach has three advantages: First, it maximizes the number of
125 features that can be supported with limited development time.  Second,
126 it respects users' settings.  A seasoned Emacs user may have changed
127 hundreds of settings, so a mode that reimplements features will have to
128 support equivalent settings, and will force the user to re-specify them.
129 Finally, this approach respects decades of development spent, as Neal
130 Stephenson put it, ``focused with maniacal intensity on the deceptively
131 simple-seeming problem of editing text.''  Many non-obvious choices go
132 into making a polished interface, and while a reimplementation gets rid
133 of accumulated cruft, it must rediscover these hidden trade-offs.
135 Anyways, I hope you enjoy using Sepia.  Its development style is strange
136 for someone used Perl's typical mix of one-liners and edit-save-run, but
137 once you are accustomed to it, you may find it very effective.
139 @node Related Work,  , Philosophy, Introduction
140 @comment  node-name,  next,  previous,  up
141 @section Related Work
143 A number of more-or-less related Emacs extensions are currently under
144 development.  Here is a list of the ones I have heard about, along with
145 my brief impression of how they differ from Sepia.  Since I use none of
146 them regularly, these impressions should be taken with a grain of salt.
148 @table @cite
150 @item PDE
152 PDE is similar to Sepia in offering an interactive Lisp-like development
153 environment interfacing with a long-running Perl process.  It seems more
154 ambitious, and therefore a bit more invasive.
156 @url{http://search.cpan.org/search?query=pde&mode=module}
158 @item Devel::PerlySense
160 Devel::PerlySense offers a more Eclipse-like development environment,
161 with offline code analysis via @acronym{PPI}.
163 @url{http://search.cpan.org/search?query=devel::perlysense&mode=module}
165 @item Emacs::EPL
167 Emacs::EPL is a low-level IPC interface between Emacs and Perl.  Sepia
168 was originally based on Emacs::EPL, but the current
169 @command{comint}-based implementation proved more maintainable.
171 @url{http://search.cpan.org/search?query=emacs::epl&mode=module}
173 @end table
175 @c ============================================================
176 @node Editing, Interactive Perl, Introduction, Top
177 @chapter Editing
178 @findex sepia-mode
180 Sepia's first contribution is a set of commands to explore a Perl
181 codebase.  These include commands to browse and display documentation,
182 to find function definitions, and to query a cross-reference database of
183 function and variable uses.  Sepia also provides intelligent symbol
184 completion.
186 @menu
187 * Completion::                  
188 * Navigation::                  
189 * Documentation::               
190 * Other commands::              
191 @end menu
193 @node Completion, Navigation, Editing, Editing
194 @section Completion
196 Sepia implements partial-word completion that communicates with the
197 inferior Perl process.  For example, @samp{%S:X:v_u} completes to
198 @samp{%Sepia::Xref::var_use} when Sepia is loaded.  This completion only
199 operates on functions and global variables known to the Perl
200 interpreter, so it works best when code and interpreter are in sync.
202 More precisely, completion examines the text before point and tries each
203 of the following in turn, using the first successful approach:
205 @enumerate
206 @item
207 If the text looks like a method call (e.g. @samp{$object->f} or
208 @samp{Class->f}), complete on methods.
210 @item
211 If it looks like a variable (e.g. @samp{%hash} or @samp{$scalar}),
212 complete first on lexical, then global variables.
214 @item
215 Complete on modules and functions.
217 @item
218 Otherwise, complete on Perl built-in operators.
219 @end enumerate
221 For each of the first three cases, completions candidates are first
222 generated by splitting the text on characters @code{[:_]} and matching
223 the resulting word parts.  For example, @samp{X:a_b} will complete to
224 all symbols matching @samp{^X[^:]*:+a[^:_]*_b} such as
225 @samp{Xref::a_bug} and @samp{X::always_bites_me}.  If the module parts
226 of the input match a module exactly and completions exist, they are not
227 expanded.  For example, @samp{X:a} will expand only to @samp{X::aa} when
228 @samp{X::aa} and @samp{Xx::aa} exist.  If no matches result, the text is
229 treated as an acronym.  For example, @samp{dry} will complete to
230 @samp{dont_repeat_yourself}.  @emph{Note: partial-word completion is not
231 currently supported for lexicals.}
233 Completion is performed by the following commands:
234 @table @kbd
235 @item M-x sepia-complete-symbol
236 @findex sepia-complete-symbol
237 Complete the symbol before point as described above.  This is always
238 case-sensitive, independent of @code{completion-ignore-case}.
240 @item TAB
241 @itemx M-x sepia-indent-or-complete
242 @findex sepia-indent-or-complete
243 First try to reindent the current line.  If its indentation does not
244 change, then try to expand an abbrev at point (unless
245 @code{sepia-indent-expand-abbrev} is @code{nil}).  If no abbrev is
246 expanded, then call @code{sepia-complete-symbol}.
248 @end table
250 @node Navigation, Documentation, Completion, Editing
251 @section Navigation
253 Sepia provides several commands for navigating program source.  All of
254 them rely on information from the inferior Perl process, so it is
255 important both that it be running, and that its internal representation
256 of the program match the program source.  The commands marked (Xref)
257 below also rely on a cross-reference database, which must be explicitly
258 rebuilt by calling @code{xref-rebuild} when the program changes.
260 There are two basic kinds of navigation commands.  The first kind jumps
261 directly to the first matching location when possible, prompting only if
262 no such location is found.  These commands find only a single location.
264 @c direct-jump commands
265 @table @kbd
267 @item M-. M-.
268 @itemx M-x sepia-dwim
269 @findex sepia-dwim
270 Guess what kind of identifier is at point, and try to do the right
271 thing: for a function, find its definition(s); for a variable, find its
272 uses; for a module, view its documentation; otherwise, prompt for the
273 name of a function to visit.  @code{sepia-dwim} automatically goes to
274 the first function definition or variable use found.
276 @item M-. l
277 @itemx M-x sepia-location
278 @findex sepia-location
279 Jump directly to the definition of the function at point, prompting if
280 point is not on a known function.  If multiple definitions are found,
281 choose one arbitrarily.  This function is similar to @code{sepia-defs},
282 and the two should probably be merged.
284 @item M-. j
285 @itemx M-x sepia-jump-to-symbol
286 @findex sepia-jump-to-symbol
287 Navigate to a function using ``ido'' interactive completion.  Within
288 interactive completion, press @key{:} to descend into a package,
289 @key{DEL} to ascend to a parent package, and @key{RET} to go to the
290 currently-selected function.
292 @end table
294 The second kind of navigation commands always prompts the user -- though
295 usually with a sensible default value -- and finds multiple locations.
296 When called with a prefix argument, these commands present their results
297 in a @code{grep-mode} buffer.  When called @emph{without} a prefix
298 argument, they place all results on the found-location ring and jump
299 directly to the first.  The remaining locations can be cycled through by
300 calls to @code{sepia-next}.
302 @c prompt-and-go commands
303 @table @kbd
304 @item M-. f @var{name} @key{RET}
305 @itemx M-x sepia-defs
306 @findex sepia-defs
307 Find definition(s) of function @var{name}.
309 @item M-. m @var{name} @key{RET}
310 @itemx M-x sepia-module-find @var{name} @key{RET}
311 @findex sepia-module-find
312 Find the source of module @var{name}.
314 @item M-. a @var{regexp} @key{RET}
315 @itemx M-x sepia-apropos @var{regexp} @key{RET}
316 @findex sepia-apropos
317 Find definitions of all functions whose names match @var{regexp}.
319 @item M-x sepia-apropos-module @var{regexp} @key{RET}
320 @findex sepia-apropos-module
321 Find all installed modules matching @var{regexp}.  This function may be
322 slow the first time it is called, because it has to build a list of
323 installed modules.
325 @item M-. c @var{name} @key{RET}
326 @itemx M-x sepia-callers @var{name} @key{RET}
327 @findex sepia-callers
328 (Xref) Find calls to function @var{name}.
330 @item M-. C @var{name} @key{RET}
331 @itemx M-x sepia-callees @var{name} @key{RET}
332 @findex sepia-callees
333 (Xref) Find the definitions of functions called by @var{name}.
335 @item M-. v @var{name} @key{RET}
336 @itemx M-x sepia-var-uses @var{name} @key{RET}
337 @findex sepia-var-uses
338 (Xref) Find uses of the global variable @var{name}.
340 @item M-. V @var{name} @key{RET}
341 @itemx M-x sepia-var-defs @var{name} @key{RET}
342 @findex sepia-var-defs
343 (Xref) Find definitions of global variable @var{name}.  Since Perl's
344 global variables are not declared, this is rarely useful
346 @c XXX: broken, so don't mention it.
347 @c @item M-. A @var{regexp} @key{RET}
348 @c @itemx M-x sepia-var-apropos
349 @c @findex sepia-var-apropos
350 @c Find definitions of all variables whose names match @var{regexp}.  Since
351 @c this function does not handle lexical variables, and since Perl's global
352 @c variables are not declared, this is rarely useful.
354 @end table
356 Finally, there are several other navigation-related commands that do not
357 fit into either of the above categories.
359 @c other commands
360 @table @kbd
361 @item M-,
362 @itemx M-x sepia-next
363 @findex sepia-next
364 Cycle through the definitions found by the previous @key{M-.} search.
366 @item M-. r
367 @itemx M-x sepia-rebuild
368 @findex sepia-rebuild
369 Rebuild the cross-reference database by walking the op-tree and
370 stashes.
372 @item M-. t
373 @itemx M-x find-tag
374 Execute the @code{find-tag} command typically bound to @key{M-.}.
376 @end table
378 @node Documentation, Other commands, Navigation, Editing
379 @section Documentation
381 Sepia can be used to browse installed modules' documentation, to format
382 and display the current buffer's POD, and to browse the list of modules
383 installed on the system.
385 @table @kbd
386 @item M-. d @var{name} @key{RET}
387 @itemx M-x sepia-perldoc-this
388 @findex sepia-perldoc-this
389 View documentation for module @var{name} or Perl manual page @var{name}.
391 @item C-c C-d
392 @itemx M-x sepia-view-pod
393 @findex sepia-view-pod
394 Format and view the current buffer's documentation.
396 @item sepia-package-list
397 @findex sepia-package-list
398 Browse a tree of installed packages.  This lists only the top-level
399 packages from installed distributions, so if package @code{My::Stuff}
400 also provides @code{My::Stuff::Details}, it will not be displayed.  When
401 Emacs-w3m is available, each module is linked to its documentation.
403 @item sepia-module-list
404 @findex sepia-module-list
405 Browse a tree of both top-level and internal packages, like
406 @code{sepia-package-list}.
408 @end table
410 @findex sepia-install-eldoc
411 Sepia also integrates with eldoc (at least in GNU Emacs >= 22).
412 Documentation for Perl operators and control structures is taken from
413 CPerl mode.  Sepia will also display documentation for user-defined
414 functions if their POD is formatted in the standard way, with functions
415 described in a ``=head2'' or ``=item'' entry.  To load user
416 documentation, visit the relevant file and type @kbd{M-x
417 sepia-doc-update}.
419 If @code{Module::CoreList} is available, Sepia's eldoc function will
420 also display the first version of Perl with which a module was shipped.
421 This is intended to give the programmer a sense of when he is creating
422 external dependencies.
424 @node Other commands,  , Documentation, Editing
425 @section Other commands
427 @table @kbd
428 @item M-x sepia-rename-lexical
429 @findex sepia-rename-lexical
430 Rename a variable in the function at point, querying for each
431 replacement when called with a prefix argument.  Currently, this is only
432 a thin wrapper around @code{query-replace}.
433 @end table
436 @c ============================================================
437 @node Interactive Perl, CPAN browsing, Editing, Top
438 @chapter Interactive Perl
440 @findex sepia-repl
441 Sepia's second main contribution is an interactive interface (REPL) to
442 an inferior Perl process.  The interface is based on GUD mode, and
443 inherits many of its bindings; this chapter discusses only the Sepia
444 extensions.  To start or switch to the repl, type @kbd{M-x sepia-repl}.
445 As in Sepia mode, @key{TAB} in the REPL performs partial-word completion
446 with @code{sepia-complete-symbol}.
448 @c == REPL behavior ==
449 @c - $_/@_
450 @c - RET & eval/newline
451 @c - eval context
453 Sepia also provides a number of other ways to evaluate pieces of code in
454 Perl, and commands to process buffer text using the inferior process.
456 Finally, Sepia comes with the @kbd{sepl} program, a standalone REPL that
457 can be run from the command-line, and provides many features of the
458 Emacs-based REPL.
460 @menu
461 * Shortcuts::                   
462 * Debugger::                    
463 * Evaluation::                  
464 * Mutilation::                  
465 * Scratchpad::                  
466 @end menu
468 @node Shortcuts, Debugger, Interactive Perl, Interactive Perl
469 @section Shortcuts
471 ``Shortcuts'' are commands handled specially by the REPL rather than
472 being evaluated as Perl code.  They either communicate with the REPL
473 function, or provide a convenient interface to Sepia variables and
474 functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
475 abbreviated to the shortest unique prefix.  The debugger defines
476 additional shortcuts (@xref{Debugger}.).
478 @table @kbd
479 @item break @var{file}:@var{line} [@var{expr}]
480 Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
481 supplied, stop only if it evaluates to true.
483 @item cd @var{dir}
484 Change Perl's current directory to @var{dir}.
486 @item debug [@var{val}]
487 Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.
489 @item define @var{name} ['@var{doc}'] @var{body...}
490 Define @var{name} as a shortcut for Perl code @var{body}, with optional
491 documentation @var{doc}, surrounded by single quotes.  @var{body} is
492 passed the raw command-line text as its first argument.
494 @item format @var{type}
495 Set the output format to @var{type}, either ``dumper'' (using
496 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
497 (@code{YAML}), or ``plain'' (stringification).  Default: ``dumper''.
499 @item help
500 Display a list of shortcuts.
502 @item load [@var{file}]
503 Reload saved variables from @var{file} (or @file{~/.sepia-save}),
504 created by @kbd{save}.
506 @item lsbreak
507 List breakpoints.
509 @item methods @var{name} [@var{regexp}]
510 Display a list of functions defined in package @var{name} and its
511 @code{ISA}-ancestors matching optional pattern @var{regexp}.
513 @item package @var{name}
514 Set the default evaluation package to @var{name}.
516 @item pwd
517 Show the process's current working directory.
519 @item quit
520 Exit the inferior Perl process.
522 @item reload [@var{module} | @var{/pattern/}]
523 Reload @var{module} (but not its dependencies), or all modules matching
524 @var{pattern}.
526 @item freload @var{module}
527 Reload @var{module} and all of its dependencies.
529 @item restart
530 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
531 mostly of interest when working on Sepia itself, and will fail
532 catastrophically if @file{Sepia.pm} fails to compile.
534 @item save [@var{pattern} [@var{file}]]
535 Save variables matching @var{pattern} (or all variables) to @var{file}
536 (or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
537 saving magic variables can have unpredictable results, using @kbd{save}
538 without a pattern argument is risky.  Sepia excludes common magic
539 variables and dangerous packages, but its list is not foolproof.
541 @item shell [@var{command}]
542 Execute shell command @var{command}, displaying its standard output and
543 standard error.
545 @item size [@var{package} [@var{regexp}]]
546 List the variables in @var{package} (or the current package) along with
547 their total sizes.  This requires the @code{Devel::Size} module.
549 @item strict [@var{val}]
550 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
551 given.  Note that turning strictness off and on clears the REPL's
552 lexical environment.
554 @item test [@var{file}]
555 Run tests in the current directory.  If @var{file} is given, only run
556 test @var{file} or @file{t/@var{file}}
558 @item time [@var{val}]
559 Set time display to @var{val}, or toggle it if @var{val} is not given.
560 With time display enabled, Sepia will use @code{BSD::Resource} and/or
561 @code{Time::HiRes} to display wall clock time and CPU usage for the
562 previous command as part of the prompt.
564 @item undef @var{name}
565 Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
566 used to remove built-in shortcuts.
568 @item wantarray [@var{val}]
569 Set the evaluation context to @var{val}: @code{@@} means array, @code{$}
570 means scalar, and anything else means void.
572 @item who @var{package} [@var{regexp}]
573 @itemx who [@var{regexp}]
574 List identifiers in @var{package} (main by default) matching
575 optional @var{regexp}.
577 @end table
579 @node Debugger, Evaluation, Shortcuts, Interactive Perl
580 @section Debugger
582 Sepia uses Perl's debugger hooks and GUD mode to support conditional
583 breakpoints and single-stepping, and overrides Perl's @code{die()} to
584 invoke the debugger rather than unwind the stack.  This makes it
585 possible to produce a backtrace, inspect and modify global variables,
586 and even continue execution when a program tries to kill itself.  If the
587 PadWalker module is available, Sepia also provides functions to inspect
588 and modify lexical variables.
590 The debugger has its own set of shortcuts, also prefixed by a comma.
592 @table @kbd
593 @item backtrace
594 Show a backtrace.
596 @item delete
597 Delete the current breakpoint.
599 @item down @var{n}
600 @itemx up @var{n}
601 Move the current stack frame up or down by @var{n} (or one) frames.
603 @item inspect [@var{n}]
604 Inspect lexicals in the current frame or frame @var{n}, counting upward
605 from 1.
607 @item next [@var{n}]
608 Advance @var{n} (or one) lines, skipping subroutine calls.
610 @item quit
611 @itemx die
612 @itemx warn
613 Continue as the program would have executed without debugger
614 intervention, dying if the debugger was called from @code{die()}.
616 @item return @var{expr}
617 Continue execution as if @code{die()} had returned the value of
618 @var{expr}, which is evaluated in the global environment.
620 @item step [@var{n}]
621 Step forward @var{n} (or one) lines, descending into subroutines.
623 @item xreturn @var{sub} @var{expr}
624 Return @var{expr} from the innermost call to @var{sub}.  This is a
625 somewhat dangerous and experimental feature, but is probably more useful
626 than returning a value from @code{die()}.
628 @end table
630 @node Evaluation, Mutilation, Debugger, Interactive Perl
631 @section Evaluation
633 When interactive Perl is running, Sepia can evaluate regions of code in
634 the inferior Perl process.  The following commands assume that this
635 process has already been started by calling @code{sepia-repl}.
637 @table @kbd
638 @item C-M-x
639 @itemx M-x sepia-eval-defun
640 @findex sepia-eval-defun
641 Evaluate the function around point in the inferior Perl process.  If it
642 contains errors, jump to the location of the first.
644 @item C-c C-l
645 @itemx M-x sepia-load-file
646 @findex sepia-load-file
647 Save the current buffer, then reload its file and if warnings or errors
648 occur, display an error buffer.  With a prefix argument, also rebuild
649 the cross-reference index.
651 @item C-c e
652 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
653 @findex sepia-eval-expression
654 Evaluate @var{expr} in scalar context and echo the result.  With a
655 prefix argument, evaluate in list context.
657 @item C-c!
658 @itemx sepia-set-cwd
659 @findex sepia-set-cwd
660 Set the REPL's working directory to the current buffer's directory.
662 @end table
664 @node Mutilation, Scratchpad, Evaluation, Interactive Perl
665 @section Mutilation
667 Sepia contains several functions to operate on regions of text using the
668 interactive Perl process.  These functions can be used like standard
669 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
670 the functions and variables in the interactive session are available.
672 @table @kbd
673 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
674 @findex sepia-perl-pe-region
675 Evaluate @var{code} on each line in the region with @code{$_} bound to
676 the line text, collecting the resulting values of @code{$_}.  With a
677 prefix argument, replace the region with the result.
679 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
680 @findex sepia-perl-ne-region
681 Evaluate @var{code} as above, but collect the results instead.
683 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
684 @findex sepia-perlize-region
685 Evaluate @var{code} once with @code{$_} bound to the entire region,
686 collecting the final value of @code{$_}.  With a prefix argument,
687 replace the region.
689 @end table
691 @node Scratchpad,  , Mutilation, Interactive Perl
692 @section Scratchpad
694 @findex sepia-scratch
695 Sepia also supports a scratchpad, another form of interaction inspired
696 by Emacs' @code{*scratch*} buffer.  To create or switch to the
697 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
698 like Sepia mode, except @key{C-j} evaluates the current line and prints
699 the result on the next line.
701 @c ============================================================
702 @node  CPAN browsing, Customization, Interactive Perl, Top
703 @chapter CPAN browsing
705 Sepia has rudimentary support for browsing documentation and installing
706 modules from CPAN.  Modules whose names, descriptions, or authors match
707 a query are displayed in a @code{*sepia-cpan*} buffer, in which the
708 following commands are available:
710 @table @kbd
711 @item s
712 @itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
713 @findex sepia-cpan-search
714 List modules whose names match @var{pattern}.
716 @item /
717 @itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
718 @findex sepia-cpan-desc
719 List modules whose names or descriptions match @var{pattern}.
721 @item l
722 @itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
723 @findex sepia-cpan-list
724 List modules authored by @var{name}.
726 @item r
727 @itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
728 @findex sepia-cpan-readme
729 Fetch and display @var{module}'s README file.
731 @item d
732 @itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
733 @findex sepia-cpan-doc
734 Browse @var{module}'s documentation on @url{http://search.cpan.org}.
736 @item i
737 @itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
738 @findex sepia-cpan-install
739 Install @var{module} and its prerequisites.  This feature is not yet
740 well tested.
742 @end table
744 @c ============================================================
745 @node Customization, Internals, CPAN browsing, Top
746 @chapter Customization
748 While Sepia can be customized in both the Perl and Emacs Lisp, most of
749 the user-accessible configuration is in the latter.
751 @menu
752 * Emacs Variables::             
753 * Perl Variables::              
754 @end menu
756 @node Emacs Variables, Perl Variables, Customization, Customization
757 @section Emacs Variables
759 Since Sepia tries where possible to reuse existing Emacs functionality,
760 its behavior should already be covered by existing customizations.  The
761 two variables most likely to need customization are
762 @kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
763 configuration can be done with @kbd{sepia-mode-hook}, while
764 REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.
766 @vtable @kbd
768 @item sepia-complete-methods
769 If non-@code{nil}, @code{sepia-complete-symbol} will complete
770 simple method calls of the form @code{$x->} or @code{Module->}.  Since
771 the former requires evaluation of @code{$x}, this can be disabled.
772 Default: @code{T}.
774 @item sepia-eval-defun-include-decls
775 If non-@code{nil}, attempt to generate a declaration list for
776 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
777 such as that calling functions without parentheses, because the presence
778 of declarations affects the parsing of barewords.  Default: @code{T}.
780 @item sepia-indent-expand-abbrev
781 If non-@code{nil}, @code{sepia-indent-or-complete} will, if
782 reindentation does not change the current line, expand an abbreviation
783 before point rather than performing completion.  Only if no abbreviation
784 is found will it perform completion.  Default: @code{T}.
786 @item sepia-module-list-function
787 The function to view a tree of installed modules.  Default:
788 @code{w3m-find-file} if Emacs-w3m is installed, or
789 @code{browse-url-of-buffer} otherwise.
791 @item sepia-perldoc-function
792 The function called to view installed modules' documentation.  Default:
793 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
794 otherwise.
796 @item sepia-perl5lib
797 A list of directories to include in @code{PERL5LIB} when starting
798 interactive Perl.  Default: @code{nil}.
800 @item sepia-prefix-key
801 The prefix to use for for functions in @code{sepia-keymap}.  Default:
802 @key{M-.}.
804 @item sepia-program-name
805 The Perl program name for interactive Perl.  Default: ``perl''.
807 @item sepia-use-completion
808 If non-@code{nil}, various Sepia functions will generate completion
809 candidates from interactive Perl when called interactively.  This may be
810 slow or undesirable in some situations.  Default: @code{T}.
812 @item sepia-view-pod-function
813 The function called to view the current buffer's documentation.
814 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
815 @code{sepia-perldoc-buffer} otherwise.
817 @end vtable
819 @node Perl Variables,  , Emacs Variables, Customization
820 @section Perl Variables
822 When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.
824 The following variables in the Sepia package control various aspects of
825 interactive evaluation.
827 @table @code
829 @item $PACKAGE
830 The package in which user input is evaluated, determined automatically
831 when code is evaluated from a buffer.  Default: @code{main}.
833 @item $PRINTER
834 The function called to format interactive output, normally set with the
835 @code{printer} shortcut.
837 @item $COLUMNATE
838 If true, columnate simple arrays independent of the value of
839 @code{$PRINTER}.  Default: true.
841 @item $PS1
842 The trailing end of the prompt string, which should end with ``> ''.
843 Default: @code{"> "}.
845 @item $STOPDIE
846 If true, calls to @code{die} from interactive code will invoke the Sepia
847 debugger.  Default: true.
849 @item $STOPWARN
850 If true, calls to @code{warn} from interactive code will invoke the
851 Sepia debugger.  Default: false.
853 @item $WANTARRAY
854 If @code{@@}, evaluate interactive expressions in list context, if
855 @code{$}, scalar, otherwise, void.  Default: @code{@@}.
857 @end table
859 Additional REPL shortcuts can be defined with
860 @kbd{Sepia::define_shortcut}.  For example
862 @example
863 Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
864     'time', 'Display the current time.';
865 @end example
867 defines a shortcut ``time'' that displays the current time.  For
868 details, see the code in @file{Sepia.pm}.
870 @c ============================================================
871 @node Internals, Credits, Customization, Top
872 @chapter Internals
874 Many things remain unexplained except by the code itself, and some
875 details mentioned above should probably be given less prominence.  For
876 developer documentation, please see the POD for @code{Sepia} and
877 @code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.
879 @node Credits, Function Index, Internals, Top
880 @unnumbered Credits
882 @table @asis
883 @item Hilko Bengen
884 Found and motivated me to fix a bunch of bugs, created Debian packages.
886 @item Ævar Arnfjörð Bjarmason
887 Miscellaneous fixes.  Tested unicode support.
889 @item Ye Wenbin
890 Found and fixed numerous bugs.
892 @item Free Software
893 Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
894 B::Xref, all of which are Free software.
896 @end table
898 @c ============================================================
899 @node Function Index, Variable Index, Credits, Top
900 @unnumbered Function Index
901 @printindex fn
903 @node Variable Index,  , Function Index, Top
904 @unnumbered Variable Index
905 @printindex vr
907 @bye