* README: add development information.
[sepia.git] / sepia.texi
blob672536401561d985d42a75d61bc776b97ca1c5bf
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 @menu
457 * Shortcuts::                   
458 * Debugger::                    
459 * Evaluation::                  
460 * Mutilation::                  
461 * Scratchpad::                  
462 @end menu
464 @node Shortcuts, Debugger, Interactive Perl, Interactive Perl
465 @section Shortcuts
467 ``Shortcuts'' are commands handled specially by the REPL rather than
468 being evaluated as Perl code.  They either communicate with the REPL
469 function, or provide a convenient interface to Sepia variables and
470 functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
471 abbreviated to the shortest unique prefix.  The debugger defines
472 additional shortcuts (@xref{Debugger}.).
474 @table @kbd
475 @item break @var{file}:@var{line} [@var{expr}]
476 Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
477 supplied, stop only if it evaluates to true.
479 @item cd @var{dir}
480 Change Perl's current directory to @var{dir}.
482 @item debug [@var{val}]
483 Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.
485 @item define @var{name} ['@var{doc}'] @var{body...}
486 Define @var{name} as a shortcut for Perl code @var{body}, with optional
487 documentation @var{doc}, surrounded by single quotes.  @var{body} is
488 passed the raw command-line text as its first argument.
490 @item format @var{type}
491 Set the output format to @var{type}, either ``dumper'' (using
492 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
493 (@code{YAML}), or ``plain'' (stringification).  Default: ``dumper''.
495 @item help
496 Display a list of shortcuts.
498 @item load [@var{file}]
499 Reload saved variables from @var{file} (or @file{~/.sepia-save}),
500 created by @kbd{save}.
502 @item lsbreak
503 List breakpoints.
505 @item methods @var{name} [@var{regexp}]
506 Display a list of functions defined in package @var{name} and its
507 @code{ISA}-ancestors matching optional pattern @var{regexp}.
509 @item package @var{name}
510 Set the default evaluation package to @var{name}.
512 @item pwd
513 Show the process's current working directory.
515 @item quit
516 Exit the inferior Perl process.
518 @item reload [@var{module} | @var{/pattern/}]
519 Reload @var{module} (but not its dependencies), or all modules matching
520 @var{pattern}.
522 @item freload @var{module}
523 Reload @var{module} and all of its dependencies.
525 @item restart
526 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
527 mostly of interest when working on Sepia itself, and will fail
528 catastrophically if @file{Sepia.pm} fails to compile.
530 @item save [@var{pattern} [@var{file}]]
531 Save variables matching @var{pattern} (or all variables) to @var{file}
532 (or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
533 saving magic variables can have unpredictable results, using @kbd{save}
534 without a pattern argument is risky.  Sepia excludes common magic
535 variables and dangerous packages, but its list is not foolproof.
537 @item shell [@var{command}]
538 Execute shell command @var{command}, displaying its standard output and
539 standard error.
541 @item size [@var{package} [@var{regexp}]]
542 List the variables in @var{package} (or the current package) along with
543 their total sizes.  This requires the @code{Devel::Size} module.
545 @item strict [@var{val}]
546 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
547 given.  Note that turning strictness off and on clears the REPL's
548 lexical environment.
550 @item test [@var{file}]
551 Run tests in the current directory.  If @var{file} is given, only run
552 test @var{file} or @file{t/@var{file}}
554 @item time [@var{val}]
555 Set time display to @var{val}, or toggle it if @var{val} is not given.
556 With time display enabled, Sepia will use @code{BSD::Resource} and/or
557 @code{Time::HiRes} to display wall clock time and CPU usage for the
558 previous command as part of the prompt.
560 @item undef @var{name}
561 Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
562 used to remove built-in shortcuts.
564 @item wantarray [@var{val}]
565 Set the evaluation context to @var{val}, or toggle between scalar and
566 array context.
568 @item who @var{package} [@var{regexp}]
569 @itemx who [@var{regexp}]
570 List identifiers in @var{package} (main by default) matching
571 optional @var{regexp}.
573 @end table
575 @node Debugger, Evaluation, Shortcuts, Interactive Perl
576 @section Debugger
578 Sepia uses Perl's debugger hooks and GUD mode to support conditional
579 breakpoints and single-stepping, and overrides Perl's @code{die()} to
580 invoke the debugger rather than unwind the stack.  This makes it
581 possible to produce a backtrace, inspect and modify global variables,
582 and even continue execution when a program tries to kill itself.  If the
583 PadWalker module is available, Sepia also provides functions to inspect
584 and modify lexical variables.
586 The debugger has its own set of shortcuts, also prefixed by a comma.
588 @table @kbd
589 @item backtrace
590 Show a backtrace.
592 @item delete
593 Delete the current breakpoint.
595 @item down @var{n}
596 @itemx up @var{n}
597 Move the current stack frame up or down by @var{n} (or one) frames.
599 @item inspect [@var{n}]
600 Inspect lexicals in the current frame or frame @var{n}, counting upward
601 from 1.
603 @item next [@var{n}]
604 Advance @var{n} (or one) lines, skipping subroutine calls.
606 @item quit
607 @itemx die
608 @itemx warn
609 Continue as the program would have executed without debugger
610 intervention, dying if the debugger was called from @code{die()}.
612 @item return @var{expr}
613 Continue execution as if @code{die()} had returned the value of
614 @var{expr}, which is evaluated in the global environment.
616 @item step [@var{n}]
617 Step forward @var{n} (or one) lines, descending into subroutines.
619 @item xreturn @var{sub} @var{expr}
620 Return @var{expr} from the innermost call to @var{sub}.  This is a
621 somewhat dangerous and experimental feature, but is probably more useful
622 than returning a value from @code{die()}.
624 @end table
626 @node Evaluation, Mutilation, Debugger, Interactive Perl
627 @section Evaluation
629 When interactive Perl is running, Sepia can evaluate regions of code in
630 the inferior Perl process.  The following commands assume that this
631 process has already been started by calling @code{sepia-repl}.
633 @table @kbd
634 @item C-M-x
635 @itemx M-x sepia-eval-defun
636 @findex sepia-eval-defun
637 Evaluate the function around point in the inferior Perl process.  If it
638 contains errors, jump to the location of the first.
640 @item C-c C-l
641 @itemx M-x sepia-load-file
642 @findex sepia-load-file
643 Save the current buffer, then reload its file and if warnings or errors
644 occur, display an error buffer.  With a prefix argument, also rebuild
645 the cross-reference index.
647 @item C-c e
648 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
649 @findex sepia-eval-expression
650 Evaluate @var{expr} in scalar context and echo the result.  With a
651 prefix argument, evaluate in list context.
653 @item C-c!
654 @itemx sepia-set-cwd
655 @findex sepia-set-cwd
656 Set the REPL's working directory to the current buffer's directory.
658 @end table
660 @node Mutilation, Scratchpad, Evaluation, Interactive Perl
661 @section Mutilation
663 Sepia contains several functions to operate on regions of text using the
664 interactive Perl process.  These functions can be used like standard
665 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
666 the functions and variables in the interactive session are available.
668 @table @kbd
669 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
670 @findex sepia-perl-pe-region
671 Evaluate @var{code} on each line in the region with @code{$_} bound to
672 the line text, collecting the resulting values of @code{$_}.  With a
673 prefix argument, replace the region with the result.
675 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
676 @findex sepia-perl-ne-region
677 Evaluate @var{code} as above, but collect the results instead.
679 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
680 @findex sepia-perlize-region
681 Evaluate @var{code} once with @code{$_} bound to the entire region,
682 collecting the final value of @code{$_}.  With a prefix argument,
683 replace the region.
685 @end table
687 @node Scratchpad,  , Mutilation, Interactive Perl
688 @section Scratchpad
690 @findex sepia-scratch
691 Sepia also supports a scratchpad, another form of interaction inspired
692 by Emacs' @code{*scratch*} buffer.  To create or switch to the
693 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
694 like Sepia mode, except @key{C-j} evaluates the current line and prints
695 the result on the next line.
697 @c ============================================================
698 @node  CPAN browsing, Customization, Interactive Perl, Top
699 @chapter CPAN browsing
701 Sepia has rudimentary support for browsing documentation and installing
702 modules from CPAN.  Modules whose names, descriptions, or authors match
703 a query are displayed in a @code{*sepia-cpan*} buffer, in which the
704 following commands are available:
706 @table @kbd
707 @item s
708 @itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
709 @findex sepia-cpan-search
710 List modules whose names match @var{pattern}.
712 @item /
713 @itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
714 @findex sepia-cpan-desc
715 List modules whose names or descriptions match @var{pattern}.
717 @item l
718 @itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
719 @findex sepia-cpan-list
720 List modules authored by @var{name}.
722 @item r
723 @itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
724 @findex sepia-cpan-readme
725 Fetch and display @var{module}'s README file.
727 @item d
728 @itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
729 @findex sepia-cpan-doc
730 Browse @var{module}'s documentation on @url{http://search.cpan.org}.
732 @item i
733 @itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
734 @findex sepia-cpan-install
735 Install @var{module} and its prerequisites.  This feature is not yet
736 well tested.
738 @end table
740 @c ============================================================
741 @node Customization, Internals, CPAN browsing, Top
742 @chapter Customization
744 While Sepia can be customized in both the Perl and Emacs Lisp, most of
745 the user-accessible configuration is in the latter.
747 @menu
748 * Emacs Variables::             
749 * Perl Variables::              
750 @end menu
752 @node Emacs Variables, Perl Variables, Customization, Customization
753 @section Emacs Variables
755 Since Sepia tries where possible to reuse existing Emacs functionality,
756 its behavior should already be covered by existing customizations.  The
757 two variables most likely to need customization are
758 @kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
759 configuration can be done with @kbd{sepia-mode-hook}, while
760 REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.
762 @vtable @kbd
764 @item sepia-complete-methods
765 If non-@code{nil}, @code{sepia-complete-symbol} will complete
766 simple method calls of the form @code{$x->} or @code{Module->}.  Since
767 the former requires evaluation of @code{$x}, this can be disabled.
768 Default: @code{T}.
770 @item sepia-eval-defun-include-decls
771 If non-@code{nil}, attempt to generate a declaration list for
772 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
773 such as that calling functions without parentheses, because the presence
774 of declarations affects the parsing of barewords.  Default: @code{T}.
776 @item sepia-indent-expand-abbrev
777 If non-@code{nil}, @code{sepia-indent-or-complete} will, if
778 reindentation does not change the current line, expand an abbreviation
779 before point rather than performing completion.  Only if no abbreviation
780 is found will it perform completion.  Default: @code{T}.
782 @item sepia-module-list-function
783 The function to view a tree of installed modules.  Default:
784 @code{w3m-find-file} if Emacs-w3m is installed, or
785 @code{browse-url-of-buffer} otherwise.
787 @item sepia-perldoc-function
788 The function called to view installed modules' documentation.  Default:
789 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
790 otherwise.
792 @item sepia-perl5lib
793 A list of directories to include in @code{PERL5LIB} when starting
794 interactive Perl.  Default: @code{nil}.
796 @item sepia-prefix-key
797 The prefix to use for for functions in @code{sepia-keymap}.  Default:
798 @key{M-.}.
800 @item sepia-program-name
801 The Perl program name for interactive Perl.  Default: ``perl''.
803 @item sepia-use-completion
804 If non-@code{nil}, various Sepia functions will generate completion
805 candidates from interactive Perl when called interactively.  This may be
806 slow or undesirable in some situations.  Default: @code{T}.
808 @item sepia-view-pod-function
809 The function called to view the current buffer's documentation.
810 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
811 @code{sepia-perldoc-buffer} otherwise.
813 @end vtable
815 @node Perl Variables,  , Emacs Variables, Customization
816 @section Perl Variables
818 When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.
819 The following variables in the Sepia package control various aspects of
820 interactive evaluation.
822 @table @code
824 @item $PACKAGE
825 The package in which user input is evaluated, determined automatically
826 when code is evaluated from a buffer.  Default: @code{main}.
828 @item $PRINTER
829 The function called to format interactive output, normally set with the
830 @code{printer} shortcut.
832 @item $PRINT_PRETTY
833 If true, format some values nicely independent of the value of
834 @code{$PRINTER}.  Currently, this means columnating lists of simple
835 scalars.  Default: true.
837 @item $PS1
838 The trailing end of the prompt string, which should end with ``> ''.
839 Default: @code{"> "}.
841 @item $STOPDIE
842 If true, calls to @code{die} from interactive code will invoke the Sepia
843 debugger.  Default: true.
845 @item $STOPWARN
846 If true, calls to @code{warn} from interactive code will invoke the
847 Sepia debugger.  Default: false.
849 @item $WANTARRAY
850 If true, evaluate interactive expressions in list context.  Default: true.
852 @end table
854 Additional REPL shortcuts can be defined with
855 @kbd{Sepia::define_shortcut}.  For example
857 @example
858 Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
859     'time', 'Display the current time.';
860 @end example
862 defines a shortcut ``time'' that displays the current time.  For
863 details, see the code in @file{Sepia.pm}.
865 @c ============================================================
866 @node Internals, Credits, Customization, Top
867 @chapter Internals
869 Many things remain unexplained except by the code itself, and some
870 details mentioned above should probably be given less prominence.  For
871 developer documentation, please see the POD for @code{Sepia} and
872 @code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.
874 @node Credits, Function Index, Internals, Top
875 @unnumbered Credits
877 @table @asis
878 @item Hilko Bengen
879 Found and motivated me to fix a bunch of bugs, created Debian packages.
881 @item Ævar Arnfjörð Bjarmason
882 Miscellaneous fixes.  Tested unicode support.
884 @item Ye Wenbin
885 Found and fixed numerous bugs.
887 @item Free Software
888 Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
889 B::Xref, all of which are Free software.
891 @end table
893 @c ============================================================
894 @node Function Index, Variable Index, Credits, Top
895 @unnumbered Function Index
896 @printindex fn
898 @node Variable Index,  , Function Index, Top
899 @unnumbered Variable Index
900 @printindex vr
902 @bye