retrieve shortcut list from inferior process.
[sepia.git] / sepia.texi
blob8158b7d115da1d044169c3ffa90cad84ddb602e4
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 @copying
10 Copyright @copyright{} 2005-2010 Sean O'Rourke.  All rights reserved,
11 some wrongs reversed.  This module is distributed under the same terms
12 as Perl.
13 @end copying
14 @c %**end of header
16 @titlepage
17 @title Sepia: Simple Emacs Perl Integration
18 @author Sean O'Rourke
19 @end titlepage
21 @macro kbinding{key,cmd}
22 @item \key\ `\cmd\'
23 @kindex \key\
24 @end macro
26 @macro fitem{name}
27 @item \name\
28 @findex \name\
29 @end macro
31 @macro xxx{stuff}
32 @b{XXX: \stuff\}
33 @end macro
35 @node Top, Introduction, (dir), (dir)
37 @ifinfo
38 @top SEPIA
39 @end ifinfo
41 @ifhtml
42 @image{Sepia,,,,jpg}
43 @end ifhtml
45 Sepia is a set of Perl development tools for Emacs supporting code
46 navigation and interactive evaluation.
48 @menu
49 * Introduction::
50 * Editing::
51 * Interactive Perl::
52 * CPAN browsing::
53 * Customization::
54 * Internals::
55 * FAQ::
56 * Credits::                     
57 * Function Index::
58 * Variable Index::
59 @end menu
61 @c ============================================================
62 @node Introduction, Editing, Top, Top
63 @chapter Introduction
65 Sepia is a set of tools for Perl development in Emacs.  Its goal is to
66 extend CPerl mode to support fast code navigation and interactive
67 development.  It is inspired by Emacs' current support for a number of
68 other languages, including Lisp, Python, and Emacs Lisp.
70 @menu
71 * Getting Started::             
72 * Philosophy::                  
73 * Related Work::                
74 @end menu
76 @node Getting Started, Philosophy, Introduction, Introduction
77 @section Getting Started
79 To install Sepia, its Emacs Lisp files must be in Emacs'
80 @code{load-path}, and the @file{lib} directory must be in Perl's
81 @code{@@INC}.  Assuming that Sepia has been unpacked in
82 @file{~/sepia}, it can be installed by adding the following lines to
83 @file{~/.emacs}:
85 @example
86 (add-to-list 'load-path "~/sepia")
87 (setq sepia-perl5lib (list (expand-file-name "~/sepia/lib")))
88 (defalias 'perl-mode 'sepia-mode)
89 (require 'sepia)
90 @end example
92 Then to bring up the interactive Perl prompt, type @kbd{M-x sepia-repl}.
94 @node Philosophy, Related Work, Getting Started, Introduction
95 @section Philosophy
97 A development environment should support three activities: code
98 spelunking, interaction, and customization.  Emacs as an environment for
99 developing Emacs Lisp thoroughly supports all of them: It has commands
100 to visit individual functions' code and documentation, commands to
101 evaluate or step through expressions, and an architecture that
102 encourages customization in Emacs Lisp.  As an environment for Perl,
103 however, it is lacking: there is limited interactivity with the Perl
104 debugger, and reasonable documentation browsing, but no support for
105 navigating, editing, and re-evaluating code.  Sepia attempts to remedy
106 the situation.
108 Modern IDEs also support these three activities, but do so awkwardly.
109 Rather than having functions to visit definitions (@kbd{find-function})
110 and search for functions (@kbd{apropos}), they clutter the screen with
111 class and file trees.  Rather than supporting interactive evaluation of
112 small pieces of code, they perform background semantic checking on whole
113 projects and highlight errors.  Rather than allowing minor
114 customizations to grow organically into features, they support limited
115 configuration files and baroque plug-in APIs@footnote{In my brief
116 experience with Visual Studio, I was struck by the fact that I saw
117 several toolbars, a couple of navigation windows, and a tiny view of the
118 actual code.  Sometimes a tooltip would obscure part of that tiny
119 window.}.  Sepia tries to adhere to the apparent Emacs philosophy that
120 rich semantic information should be unobtrusive, and that the best way
121 to build working code is to start by experimenting with small pieces.
123 Language support packages for Emacs vary widely in the degree to which
124 they make use of or replace existing Emacs features.  Minimal modes
125 provide keyword-based syntax highlighting and an unadorned comint buffer
126 as an interpreter.  Others provide their own specialized equivalents of
127 comint, eldoc, completion, and other Emacs features.  Sepia takes a
128 third approach by trying to do as much as possible with existing Emacs
129 features, even when they are not optimal for Perl.  For example, it uses
130 comint to communicate with the subprocess, eldoc to display
131 documentation, and grep to list source locations.
133 This approach has three advantages: First, it maximizes the number of
134 features that can be supported with limited development time.  Second,
135 it respects users' settings.  A seasoned Emacs user may have changed
136 hundreds of settings, so a mode that reimplements features will have to
137 support equivalent settings, and will force the user to re-specify them.
138 Finally, this approach respects decades of development spent, as Neal
139 Stephenson put it, ``focused with maniacal intensity on the deceptively
140 simple-seeming problem of editing text.''  Many non-obvious choices go
141 into making a polished interface, and while a reimplementation gets rid
142 of accumulated cruft, it must rediscover these hidden trade-offs.
144 Anyways, I hope you enjoy using Sepia.  Its development style is strange
145 for someone used Perl's typical mix of one-liners and edit-save-run, but
146 once you are accustomed to it, you may find it very effective.
148 @node Related Work,  , Philosophy, Introduction
149 @comment  node-name,  next,  previous,  up
150 @section Related Work
152 A number of more-or-less related Emacs extensions are currently under
153 development.  Here is a list of the ones I have heard about, along with
154 my brief impression of how they differ from Sepia.  Since I use none of
155 them regularly, these impressions should be taken with a grain of salt.
157 @table @cite
159 @item Emacs::PDE
161 PDE is similar to Sepia in offering an interactive Lisp-like development
162 environment interfacing with a long-running Perl process.  It seems more
163 ambitious, and therefore a bit more invasive.
165 @url{http://search.cpan.org/dist/Emacs-PDE/}
167 @item Devel::PerlySense
169 Devel::PerlySense offers a more Eclipse-like development environment,
170 with offline code analysis via @acronym{PPI}.
172 @url{http://search.cpan.org/dist/Devel-PerlySense/}
174 @item Emacs::EPL
176 Emacs::EPL is a low-level IPC interface between Emacs and Perl.  Sepia
177 was originally based on Emacs::EPL, but the current
178 @command{comint}-based implementation proved more maintainable.
180 @url{http://search.cpan.org/dist/Emacs-EPL/}
182 @item Stylish
184 Stylish is a similar effort with a very different implementation
185 philosophy, requiring maximal rather than minimal dependencies in both
186 Perl and Emacs, and reimplementing @command{comint} in Emacs.
188 @url{http://github.com/jrockway/stylish.git}
190 @end table
192 @c ============================================================
193 @node Editing, Interactive Perl, Introduction, Top
194 @chapter Editing
195 @findex sepia-mode
197 Sepia's first contribution is a set of commands to explore a Perl
198 codebase.  These include commands to browse and display documentation,
199 to find function definitions, and to query a cross-reference database of
200 function and variable uses.  Sepia also provides intelligent symbol
201 completion.
203 @menu
204 * Completion::                  
205 * Navigation::                  
206 * Documentation::               
207 * Other commands::              
208 @end menu
210 @node Completion, Navigation, Editing, Editing
211 @section Completion
213 Sepia implements partial-word completion that communicates with the
214 inferior Perl process.  For example, @samp{%S:X:v_u} completes to
215 @samp{%Sepia::Xref::var_use} when Sepia is loaded.  This completion only
216 operates on functions and global variables known to the Perl
217 interpreter, so it works best when code and interpreter are in sync.
219 More precisely, completion examines the text before point and tries each
220 of the following in turn, using the first successful approach:
222 @enumerate
223 @item
224 If the text looks like a method call (e.g. @samp{$object->f} or
225 @samp{Class->f}), complete on methods.
227 @item
228 If it looks like a variable (e.g. @samp{%hash} or @samp{$scalar}),
229 complete first on lexical, then global variables.
231 @item
232 Complete on modules and functions.
234 @item
235 Otherwise, complete on Perl built-in operators.
236 @end enumerate
238 For each of the first three cases, completions candidates are first
239 generated by splitting the text on characters @code{[:_]} and matching
240 the resulting word parts.  For example, @samp{X:a_b} will complete to
241 all symbols matching @samp{^X[^:]*:+a[^:_]*_b} such as
242 @samp{Xref::a_bug} and @samp{X::always_bites_me}.  If the module parts
243 of the input match a module exactly and completions exist, they are not
244 expanded.  For example, @samp{X:a} will expand only to @samp{X::aa} when
245 @samp{X::aa} and @samp{Xx::aa} exist.  If no matches result, the text is
246 treated as an acronym.  For example, @samp{dry} will complete to
247 @samp{dont_repeat_yourself}.  @emph{Note: partial-word completion is not
248 currently supported for lexicals.}
250 Completion is performed by the following commands:
251 @table @kbd
252 @item M-x sepia-complete-symbol
253 @findex sepia-complete-symbol
254 Complete the symbol before point as described above.  This is always
255 case-sensitive, independent of @code{completion-ignore-case}.
257 @item TAB
258 @itemx M-x sepia-indent-or-complete
259 @findex sepia-indent-or-complete
260 First try to reindent the current line.  If its indentation does not
261 change, then try to expand an abbrev at point (unless
262 @code{sepia-indent-expand-abbrev} is @code{nil}).  If no abbrev is
263 expanded, then call @code{sepia-complete-symbol}.
265 @end table
267 @node Navigation, Documentation, Completion, Editing
268 @section Navigation
270 Sepia provides several commands for navigating program source.  All of
271 them rely on information from the inferior Perl process, so it is
272 important both that it be running, and that its internal representation
273 of the program match the program source.  The commands marked (Xref)
274 below also rely on a cross-reference database, which must be explicitly
275 rebuilt by calling @code{xref-rebuild} when the program changes.
277 There are two basic kinds of navigation commands.  The first kind jumps
278 directly to the first matching location when possible, prompting only if
279 no such location is found.  These commands find only a single location.
281 @c direct-jump commands
282 @table @kbd
284 @item M-. M-.
285 @itemx M-x sepia-dwim
286 @findex sepia-dwim
287 Guess what kind of identifier is at point, and try to do the right
288 thing: for a function, find its definition(s); for a variable, find its
289 uses; for a module, view its documentation; otherwise, prompt for the
290 name of a function to visit.  @code{sepia-dwim} automatically goes to
291 the first function definition or variable use found.
293 @item M-. d
294 @itemx M-x sepia-location
295 @findex sepia-location
296 Jump directly to the definition of the function at point, prompting if
297 point is not on a known function.  If multiple definitions are found,
298 choose one arbitrarily.  This function is similar to @code{sepia-defs},
299 and the two should probably be merged.
301 @item M-. j
302 @itemx M-x sepia-jump-to-symbol
303 @findex sepia-jump-to-symbol
304 Navigate to a function using ``ido'' interactive completion.  Within
305 interactive completion, press @key{:} to descend into a package,
306 @key{DEL} to ascend to a parent package, and @key{RET} to go to the
307 currently-selected function.
309 @item M-. l
310 @itemx M-x sepia-pod-follow-link-at-point
311 @findex sepia-pod-follow-link-at-point
312 Follow the POD link (@code{L<...>}) at point, or prompt for a link if
313 there is none.  Go to the appropriate location in the document source
314 or, with a prefix argument, in the rendered documentation.  This can be
315 especially useful when writing links in your own documentation.
317 @end table
319 The second kind of navigation commands always prompts the user -- though
320 usually with a sensible default value -- and finds multiple locations.
321 When called with a prefix argument, these commands present their results
322 in a @code{grep-mode} buffer.  When called @emph{without} a prefix
323 argument, they place all results on the found-location ring and jump
324 directly to the first.  The remaining locations can be cycled through by
325 calls to @code{sepia-next}.
327 @c prompt-and-go commands
328 @table @kbd
329 @item M-. f @var{name} @key{RET}
330 @itemx M-x sepia-defs
331 @findex sepia-defs
332 Find definition(s) of function @var{name}.
334 @item M-. m @var{name} @key{RET}
335 @itemx M-x sepia-module-find @var{name} @key{RET}
336 @findex sepia-module-find
337 Find the source of module @var{name}.
339 @item M-. a @var{regexp} @key{RET}
340 @itemx M-x sepia-apropos @var{regexp} @key{RET}
341 @findex sepia-apropos
342 Find definitions of all functions whose names match @var{regexp}.
344 @item M-x sepia-apropos-module @var{regexp} @key{RET}
345 @findex sepia-apropos-module
346 Find all installed modules matching @var{regexp}.  This function may be
347 slow the first time it is called, because it has to build a list of
348 installed modules.
350 @item M-. c @var{name} @key{RET}
351 @itemx M-x sepia-callers @var{name} @key{RET}
352 @findex sepia-callers
353 (Xref) Find calls to function @var{name}.
355 @item M-. C @var{name} @key{RET}
356 @itemx M-x sepia-callees @var{name} @key{RET}
357 @findex sepia-callees
358 (Xref) Find the definitions of functions called by @var{name}.
360 @item M-. v @var{name} @key{RET}
361 @itemx M-x sepia-var-uses @var{name} @key{RET}
362 @findex sepia-var-uses
363 (Xref) Find uses of the global variable @var{name}.
365 @item M-. V @var{name} @key{RET}
366 @itemx M-x sepia-var-defs @var{name} @key{RET}
367 @findex sepia-var-defs
368 (Xref) Find definitions of global variable @var{name}.  Since Perl's
369 global variables are not declared, this is rarely useful
371 @c XXX: broken, so don't mention it.
372 @c @item M-. A @var{regexp} @key{RET}
373 @c @itemx M-x sepia-var-apropos
374 @c @findex sepia-var-apropos
375 @c Find definitions of all variables whose names match @var{regexp}.  Since
376 @c this function does not handle lexical variables, and since Perl's global
377 @c variables are not declared, this is rarely useful.
379 @end table
381 Finally, there are several other navigation-related commands that do not
382 fit into either of the above categories.
384 @c other commands
385 @table @kbd
386 @item M-,
387 @itemx M-x sepia-next
388 @findex sepia-next
389 Cycle through the definitions found by the previous @key{M-.} search.
391 @item M-. r
392 @itemx M-x sepia-rebuild
393 @findex sepia-rebuild
394 Rebuild the cross-reference database by walking the op-tree and
395 stashes.
397 @item M-. t
398 @itemx M-x find-tag
399 Execute the @code{find-tag} command typically bound to @key{M-.}.
401 @end table
403 @node Documentation, Other commands, Navigation, Editing
404 @section Documentation
406 Sepia can be used to browse installed modules' documentation, to format
407 and display the current buffer's POD, and to browse the list of modules
408 installed on the system.
410 @table @kbd
411 @item M-. p @var{name} @key{RET}
412 @itemx M-x sepia-perldoc-this
413 @findex sepia-perldoc-this
414 View documentation for module @var{name} or Perl manual page @var{name}.
416 @item C-c C-d
417 @itemx M-x sepia-view-pod
418 @findex sepia-view-pod
419 Format and view the current buffer's documentation.
421 @item sepia-package-list
422 @findex sepia-package-list
423 Browse a tree of installed packages.  This lists only the top-level
424 packages from installed distributions, so if package @code{My::Stuff}
425 also provides @code{My::Stuff::Details}, it will not be displayed.  When
426 Emacs-w3m is available, each module is linked to its documentation.
428 @item sepia-module-list
429 @findex sepia-module-list
430 Browse a tree of both top-level and internal packages, like
431 @code{sepia-package-list}.
433 @end table
435 @findex sepia-install-eldoc
436 Sepia also integrates with eldoc (at least in GNU Emacs >= 22).
437 Documentation for Perl operators and control structures is taken from
438 CPerl mode.  Sepia will also display documentation for user-defined
439 functions if their POD is formatted in the standard way, with functions
440 described in a ``=head2'' or ``=item'' entry.  To load user
441 documentation, visit the relevant file and type @kbd{M-x
442 sepia-doc-update}.
444 If @code{Module::CoreList} is available, Sepia's eldoc function will
445 also display the first version of Perl with which a module was shipped.
446 This is intended to give the programmer a sense of when he is creating
447 external dependencies.
449 @node Other commands,  , Documentation, Editing
450 @section Other commands
452 @table @kbd
453 @item M-x sepia-rename-lexical
454 @findex sepia-rename-lexical
455 Rename a variable in the function at point, querying for each
456 replacement when called with a prefix argument.  Currently, this is only
457 a thin wrapper around @code{query-replace}.
458 @end table
461 @c ============================================================
462 @node Interactive Perl, CPAN browsing, Editing, Top
463 @chapter Interactive Perl
465 @findex sepia-repl
466 Sepia's second main contribution is an interactive interface (REPL) to
467 an inferior Perl process.  The interface is based on GUD mode, and
468 inherits many of its bindings; this chapter discusses only the Sepia
469 extensions.  To start or switch to the repl, type @kbd{M-x sepia-repl}.
470 As in Sepia mode, @key{TAB} in the REPL performs partial-word completion
471 with @code{sepia-complete-symbol}.
473 @c == REPL behavior ==
474 @c - $_/@_
475 @c - RET & eval/newline
476 @c - eval context
478 Sepia also provides a number of other ways to evaluate pieces of code in
479 Perl, and commands to process buffer text using the inferior process.
481 Finally, Sepia comes with the @kbd{sepl} program, a standalone REPL that
482 can be run from the command-line, and provides many features of the
483 Emacs-based REPL.
485 @menu
486 * Shortcuts::                   
487 * Debugger::                    
488 * Evaluation::                  
489 * Mutilation::                  
490 * Scratchpad::                  
491 @end menu
493 @node Shortcuts, Debugger, Interactive Perl, Interactive Perl
494 @section Shortcuts
496 ``Shortcuts'' are commands handled specially by the REPL rather than
497 being evaluated as Perl code.  They either communicate with the REPL
498 function, or provide a convenient interface to Sepia variables and
499 functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
500 abbreviated to the shortest unique prefix.  The debugger defines
501 additional shortcuts (@xref{Debugger}.).
503 @table @kbd
504 @item break @var{file}:@var{line} [@var{expr}]
505 Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
506 supplied, stop only if it evaluates to true.
508 @item cd @var{dir}
509 Change Perl's current directory to @var{dir}.
511 @item debug [@var{val}]
512 Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.
514 @item define @var{name} ['@var{doc}'] @var{body...}
515 Define @var{name} as a shortcut for Perl code @var{body}, with optional
516 documentation @var{doc}, surrounded by single quotes.  @var{body} is
517 passed the raw command-line text as its first argument.
519 @item format @var{type}
520 Set the output format to @var{type}, either ``dumper'' (using
521 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
522 (@code{YAML}), ``peek'' (@code{Devel::Peek}), ``dumpvar''
523 (@code{dumpvar.pl}, somewhat rough), or ``plain'' (stringification).
524 Default: ``dumper''.
526 Note that this setting is independent of @code{$COLUMNATE} and
527 @code{$STRINGIFY}.
529 @item help
530 Display a list of shortcuts.
532 @item load [@var{file}]
533 Reload saved variables from @var{file} (or @file{~/.sepia-save}),
534 created by @kbd{save}.
536 @item lsbreak
537 List breakpoints.
539 @item lsmod [@var{pattern}]
540 List currently-loaded modules matching optional @var{pattern}.
542 @item methods @var{name} [@var{regexp}]
543 Display a list of functions defined in package @var{name} and its
544 @code{ISA}-ancestors matching optional pattern @var{regexp}.
546 @item package @var{name}
547 Set the default evaluation package to @var{name}.
549 @item pwd
550 Show the process's current working directory.
552 @item quit
553 Exit the inferior Perl process.
555 @item reload [@var{module} | @var{/pattern/}]
556 Reload @var{module} (but not its dependencies), or all modules matching
557 @var{pattern}.
559 @item freload @var{module}
560 Reload @var{module} and all of its dependencies.
562 @item restart
563 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
564 mostly of interest when working on Sepia itself, and will fail
565 catastrophically if @file{Sepia.pm} fails to compile.
567 @item save [@var{pattern} [@var{file}]]
568 Save variables matching @var{pattern} (or all variables) to @var{file}
569 (or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
570 saving magic variables can have unpredictable results, using @kbd{save}
571 without a pattern argument is risky.  Sepia excludes common magic
572 variables and dangerous packages, but its list is not foolproof.
574 @item shell [@var{command}]
575 Execute shell command @var{command}, displaying its standard output and
576 standard error.
578 @item size @var{package} [@var{regexp}]
579 @item size [@var{regexp}]
580 List the variables in @var{package} (or the current package) along with
581 their total sizes.  This requires the @code{Devel::Size} module.  In
582 strict mode, list lexical variables if no @var{package} is given.
584 @item strict [@var{val}]
585 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
586 given.  Note that turning strictness off and on clears the REPL's
587 lexical environment.
589 @item test [@var{file}]
590 Run tests in the current directory.  If @var{file} is given, only run
591 test @var{file} or @file{t/@var{file}}
593 @item time [@var{val}]
594 Set time display to @var{val}, or toggle it if @var{val} is not given.
595 With time display enabled, Sepia will use @code{BSD::Resource} and/or
596 @code{Time::HiRes} to display wall clock time and CPU usage for the
597 previous command as part of the prompt.
599 @item undef @var{name}
600 Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
601 used to remove built-in shortcuts.
603 @item wantarray [@var{val}]
604 Set the evaluation context to @var{val}: @code{@@} means array, @code{$}
605 means scalar, and anything else means void.
607 @item who @var{package} [@var{regexp}]
608 @itemx who [@var{regexp}]
609 List identifiers in @var{package} (main by default) matching optional
610 @var{regexp.}  In strict mode, list lexical variables if no
611 @var{package} is given.
613 @end table
615 @node Debugger, Evaluation, Shortcuts, Interactive Perl
616 @section Debugger
618 Sepia uses Perl's debugger hooks and GUD mode to support conditional
619 breakpoints and single-stepping, and overrides Perl's @code{die()} to
620 invoke the debugger rather than unwind the stack.  This makes it
621 possible to produce a backtrace, inspect and modify global variables,
622 and even continue execution when a program tries to kill itself.  If the
623 PadWalker module is available, Sepia also provides functions to inspect
624 and modify lexical variables.
626 The debugger has its own set of shortcuts, also prefixed by a comma.
628 @table @kbd
629 @item backtrace
630 Show a backtrace.
632 @item delete
633 Delete the current breakpoint.
635 @item down @var{n}
636 @itemx up @var{n}
637 Move the current stack frame up or down by @var{n} (or one) frames.
639 @item inspect [@var{n}]
640 Inspect lexicals in the current frame or frame @var{n}, counting upward
641 from 1.
643 @item next [@var{n}]
644 Advance @var{n} (or one) lines, skipping subroutine calls.
646 @item quit
647 @itemx die
648 @itemx warn
649 Continue as the program would have executed without debugger
650 intervention, dying if the debugger was called from @code{die()}.
652 @item return @var{expr}
653 Continue execution as if @code{die()} had returned the value of
654 @var{expr}, which is evaluated in the global environment.
656 @item step [@var{n}]
657 Step forward @var{n} (or one) lines, descending into subroutines.
659 @item xreturn @var{sub} @var{expr}
660 Return @var{expr} from the innermost call to @var{sub}.  This is a
661 somewhat dangerous and experimental feature, but is probably more useful
662 than returning a value from @code{die()}.
664 @end table
666 @node Evaluation, Mutilation, Debugger, Interactive Perl
667 @section Evaluation
669 When interactive Perl is running, Sepia can evaluate regions of code in
670 the inferior Perl process.  The following commands assume that this
671 process has already been started by calling @code{sepia-repl}.
673 @table @kbd
674 @item C-M-x
675 @itemx M-x sepia-eval-defun
676 @findex sepia-eval-defun
677 Evaluate the function around point in the inferior Perl process.  If it
678 contains errors, jump to the location of the first.
680 @item C-c C-l
681 @itemx M-x sepia-load-file
682 @findex sepia-load-file
683 Save the current buffer, then reload its file and if warnings or errors
684 occur, display an error buffer.  With a prefix argument, also rebuild
685 the cross-reference index.
687 @item C-c e
688 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
689 @findex sepia-eval-expression
690 Evaluate @var{expr} in scalar context and echo the result.  With a
691 prefix argument, evaluate in list context.
693 @item C-c!
694 @itemx sepia-set-cwd
695 @findex sepia-set-cwd
696 Set the REPL's working directory to the current buffer's directory.
698 @end table
700 @node Mutilation, Scratchpad, Evaluation, Interactive Perl
701 @section Mutilation
703 Sepia contains several functions to operate on regions of text using the
704 interactive Perl process.  These functions can be used like standard
705 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
706 the functions and variables in the interactive session are available.
708 @table @kbd
709 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
710 @findex sepia-perl-pe-region
711 Evaluate @var{code} on each line in the region with @code{$_} bound to
712 the line text, collecting the resulting values of @code{$_}.  With a
713 prefix argument, replace the region with the result.
715 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
716 @findex sepia-perl-ne-region
717 Evaluate @var{code} as above, but collect the results instead.
719 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
720 @findex sepia-perlize-region
721 Evaluate @var{code} once with @code{$_} bound to the entire region,
722 collecting the final value of @code{$_}.  With a prefix argument,
723 replace the region.
725 @end table
727 @node Scratchpad,  , Mutilation, Interactive Perl
728 @section Scratchpad
730 @findex sepia-scratch
731 Sepia also supports a scratchpad, another form of interaction inspired
732 by Emacs' @code{*scratch*} buffer.  To create or switch to the
733 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
734 like Sepia mode, except @key{C-j} evaluates the current line and prints
735 the result on the next line.
737 @c ============================================================
738 @node  CPAN browsing, Customization, Interactive Perl, Top
739 @chapter CPAN browsing
741 Sepia has rudimentary support for browsing documentation and installing
742 modules from CPAN.  Modules whose names, descriptions, or authors match
743 a query are displayed in a @code{*sepia-cpan*} buffer, in which the
744 following commands are available:
746 @table @kbd
747 @item s
748 @itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
749 @findex sepia-cpan-search
750 List modules whose names match @var{pattern}.
752 @item /
753 @itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
754 @findex sepia-cpan-desc
755 List modules whose names or descriptions match @var{pattern}.
757 @item l
758 @itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
759 @findex sepia-cpan-list
760 List modules authored by @var{name}.
762 @item r
763 @itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
764 @findex sepia-cpan-readme
765 Fetch and display @var{module}'s README file.
767 @item d
768 @itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
769 @findex sepia-cpan-doc
770 Browse @var{module}'s documentation on @url{http://search.cpan.org}.
772 @item i
773 @itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
774 @findex sepia-cpan-install
775 Install @var{module} and its prerequisites.  This feature is not yet
776 well tested.
778 @end table
780 @c ============================================================
781 @node Customization, Internals, CPAN browsing, Top
782 @chapter Customization
784 While Sepia can be customized in both the Perl and Emacs Lisp, most of
785 the user-accessible configuration is in the latter.
787 @menu
788 * Emacs Customization::             
789 * Perl Customization::              
790 @end menu
792 @node Emacs Customization, Perl Customization, Customization, Customization
793 @section Emacs Customization
795 Since Sepia tries where possible to reuse existing Emacs functionality,
796 its behavior should already be covered by existing customizations.  The
797 two variables most likely to need customization are
798 @kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
799 configuration can be done with @kbd{sepia-mode-hook}, while
800 REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.
802 @vtable @kbd
804 @item sepia-complete-methods
805 If non-@code{nil}, @code{sepia-complete-symbol} will complete
806 simple method calls of the form @code{$x->} or @code{Module->}.  Since
807 the former requires evaluation of @code{$x}, this can be disabled.
808 Default: @code{t}.
810 @item sepia-eval-defun-include-decls
811 If non-@code{nil}, attempt to generate a declaration list for
812 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
813 such as that calling functions without parentheses, because the presence
814 of declarations affects the parsing of barewords.  Default: @code{t}.
816 @item sepia-indent-expand-abbrev
817 If non-@code{nil}, @code{sepia-indent-or-complete} will, if
818 reindentation does not change the current line, expand an abbreviation
819 before point rather than performing completion.  Only if no abbreviation
820 is found will it perform completion.  Default: @code{t}.
822 @item sepia-module-list-function
823 The function to view a tree of installed modules.  Default:
824 @code{w3m-find-file} if Emacs-w3m is installed, or
825 @code{browse-url-of-buffer} otherwise.
827 @item sepia-perldoc-function
828 The function called to view installed modules' documentation.  Default:
829 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
830 otherwise.
832 @item sepia-perl5lib
833 A list of directories to include in @code{PERL5LIB} when starting
834 interactive Perl.  Default: @code{nil}.
836 @item sepia-prefix-key
837 The prefix to use for for functions in @code{sepia-keymap}.  Default:
838 @key{M-.}.
840 @item sepia-program-name
841 The Perl program name for interactive Perl.  Default: ``perl''.
843 @item sepia-use-completion
844 If non-@code{nil}, various Sepia functions will generate completion
845 candidates from interactive Perl when called interactively.  This may be
846 slow or undesirable in some situations.  Default: @code{t}.
848 @item sepia-view-pod-function
849 The function called to view the current buffer's documentation.
850 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
851 @code{sepia-perldoc-buffer} otherwise.
853 @end vtable
855 @node Perl Customization,  , Emacs Customization, Customization
856 @section Perl Customization
858 When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.
860 The following variables in the Sepia package control various aspects of
861 interactive evaluation.
863 @table @code
865 @item $PACKAGE
866 The package in which user input is evaluated, determined automatically
867 when code is evaluated from a buffer.  Default: @code{main}.
869 @item $PRINTER
870 The function called to format interactive output, normally set with the
871 @code{printer} shortcut.
873 @item $COLUMNATE
874 If true, columnate simple arrays independent of the value of
875 @code{$PRINTER}.  Default: true.
877 @item $STRINGIFY
878 If true, stringify objects that overload the operation independent of
879 the value of @code{$PRINTER}.  Default: true.
881 @item $PS1
882 The trailing end of the prompt string, which should end with ``> ''.
883 Default: @code{"> "}.
885 @item $STOPDIE
886 If true, calls to @code{die} from interactive code will invoke the Sepia
887 debugger.  Default: true.
889 @item $STOPWARN
890 If true, calls to @code{warn} from interactive code will invoke the
891 Sepia debugger.  Default: false.
893 @item $WANTARRAY
894 If @code{@@}, evaluate interactive expressions in list context, if
895 @code{$}, scalar, otherwise, void.  Default: @code{@@}.
897 @end table
899 Additional REPL shortcuts can be defined as follows:
901 @table @code
903 @item Sepia::define_shortcut @var{name}, @var{function} [, @var{shortdoc} [, @var{longdoc}]]
905 Define a shortcut @var{name} to call @var{function}.  Also define a
906 short usage message @var{shortdoc} and documentation @var{longdoc}.  For
907 example,
909 @example
911 Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
912     'time', 'Display the current time.';
914 @end example
916 defines a shortcut ``time'' that displays the current time.  For more
917 examples, see the function @var{define_shortcuts} code in
918 @file{Sepia.pm}.
920 @item Sepia::alias_shortcut @var{new}, @var{old}
922 Make @var{new} an alias for @var{old}.
924 @end table
927 @c ============================================================
928 @node Internals, FAQ, Customization, Top
929 @chapter Internals
931 Many things remain unexplained except by the code itself, and some
932 details mentioned above should probably be given less prominence.  For
933 developer documentation, please see the POD for @code{Sepia} and
934 @code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.
936 @node FAQ, Credits, Internals, Top
937 @chapter FAQ
939 @table @asis
940 @item Can I use @code{Sepia} outside of Emacs?
941 Sepia comes with the @file{sepl} program, a command-line REPL using the
942 @code{Sepia::Readline} module, that provides many features of the
943 Emacs-based REPL.  It could be improved, though -- patches welcome!
945 @file{sepl} currently provides completion for @code{Term::ReadLine::Gnu}
946 and @code{Term::ReadLine::Perl}.  If you have neither of these, using
947 @file{rlwrap} might be the best option.
949 @item Why is the documentation in TeXInfo format?!
950 TeXInfo is the worst form of documentation, except for all the others.
951 TeX and LaTeX produce beautiful printed output, and Info is the best way
952 to view documentation in Emacs for things that are not themselves part
953 of Emacs (i.e. ``can have docstrings'').
955 It's awful to edit, being both verbose and redundant -- just look at
956 AUCTeX's @code{texinfo-every-node-update} for desperate placation of the
957 suck, then try to figure out what's wrong when @file{makeinfo} complains
958 about @code{texinfo-every-node-update}'s output -- but it's what we
959 have.  At least it sucks less than @code{DocBook}, raw HTML, or
960 @file{troff}.
962 @end table
964 @node Credits, Function Index, FAQ, Top
965 @unnumbered Credits
967 @table @asis
968 @item Hilko Bengen
969 Found and motivated me to fix a bunch of bugs, created Debian packages.
971 @item Ævar Arnfjörð Bjarmason
972 Miscellaneous fixes.  Tested unicode support.
974 @item Ye Wenbin
975 Found and fixed numerous bugs.
977 @item Free Software
978 Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
979 B::Xref, all of which are Free software.
981 @end table
983 @c ============================================================
984 @node Function Index, Variable Index, Credits, Top
985 @unnumbered Function Index
986 @printindex fn
988 @node Variable Index,  , Function Index, Top
989 @unnumbered Variable Index
990 @printindex vr
992 @bye