* copyedit
[sepia.git] / sepia.texi
blobe5749075c871d5732dcc733de4a787c2a89f8b2e
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 @end table
184 @c ============================================================
185 @node Editing, Interactive Perl, Introduction, Top
186 @chapter Editing
187 @findex sepia-mode
189 Sepia's first contribution is a set of commands to explore a Perl
190 codebase.  These include commands to browse and display documentation,
191 to find function definitions, and to query a cross-reference database of
192 function and variable uses.  Sepia also provides intelligent symbol
193 completion.
195 @menu
196 * Completion::                  
197 * Navigation::                  
198 * Documentation::               
199 * Other commands::              
200 @end menu
202 @node Completion, Navigation, Editing, Editing
203 @section Completion
205 Sepia implements partial-word completion that communicates with the
206 inferior Perl process.  For example, @samp{%S:X:v_u} completes to
207 @samp{%Sepia::Xref::var_use} when Sepia is loaded.  This completion only
208 operates on functions and global variables known to the Perl
209 interpreter, so it works best when code and interpreter are in sync.
211 More precisely, completion examines the text before point and tries each
212 of the following in turn, using the first successful approach:
214 @enumerate
215 @item
216 If the text looks like a method call (e.g. @samp{$object->f} or
217 @samp{Class->f}), complete on methods.
219 @item
220 If it looks like a variable (e.g. @samp{%hash} or @samp{$scalar}),
221 complete first on lexical, then global variables.
223 @item
224 Complete on modules and functions.
226 @item
227 Otherwise, complete on Perl built-in operators.
228 @end enumerate
230 For each of the first three cases, completions candidates are first
231 generated by splitting the text on characters @code{[:_]} and matching
232 the resulting word parts.  For example, @samp{X:a_b} will complete to
233 all symbols matching @samp{^X[^:]*:+a[^:_]*_b} such as
234 @samp{Xref::a_bug} and @samp{X::always_bites_me}.  If the module parts
235 of the input match a module exactly and completions exist, they are not
236 expanded.  For example, @samp{X:a} will expand only to @samp{X::aa} when
237 @samp{X::aa} and @samp{Xx::aa} exist.  If no matches result, the text is
238 treated as an acronym.  For example, @samp{dry} will complete to
239 @samp{dont_repeat_yourself}.  @emph{Note: partial-word completion is not
240 currently supported for lexicals.}
242 Completion is performed by the following commands:
243 @table @kbd
244 @item M-x sepia-complete-symbol
245 @findex sepia-complete-symbol
246 Complete the symbol before point as described above.  This is always
247 case-sensitive, independent of @code{completion-ignore-case}.
249 @item TAB
250 @itemx M-x sepia-indent-or-complete
251 @findex sepia-indent-or-complete
252 First try to reindent the current line.  If its indentation does not
253 change, then try to expand an abbrev at point (unless
254 @code{sepia-indent-expand-abbrev} is @code{nil}).  If no abbrev is
255 expanded, then call @code{sepia-complete-symbol}.
257 @end table
259 @node Navigation, Documentation, Completion, Editing
260 @section Navigation
262 Sepia provides several commands for navigating program source.  All of
263 them rely on information from the inferior Perl process, so it is
264 important both that it be running, and that its internal representation
265 of the program match the program source.  The commands marked (Xref)
266 below also rely on a cross-reference database, which must be explicitly
267 rebuilt by calling @code{xref-rebuild} when the program changes.
269 There are two basic kinds of navigation commands.  The first kind jumps
270 directly to the first matching location when possible, prompting only if
271 no such location is found.  These commands find only a single location.
273 @c direct-jump commands
274 @table @kbd
276 @item M-. M-.
277 @itemx M-x sepia-dwim
278 @findex sepia-dwim
279 Guess what kind of identifier is at point, and try to do the right
280 thing: for a function, find its definition(s); for a variable, find its
281 uses; for a module, view its documentation; otherwise, prompt for the
282 name of a function to visit.  @code{sepia-dwim} automatically goes to
283 the first function definition or variable use found.
285 @item M-. d
286 @itemx M-x sepia-location
287 @findex sepia-location
288 Jump directly to the definition of the function at point, prompting if
289 point is not on a known function.  If multiple definitions are found,
290 choose one arbitrarily.  This function is similar to @code{sepia-defs},
291 and the two should probably be merged.
293 @item M-. j
294 @itemx M-x sepia-jump-to-symbol
295 @findex sepia-jump-to-symbol
296 Navigate to a function using ``ido'' interactive completion.  Within
297 interactive completion, press @key{:} to descend into a package,
298 @key{DEL} to ascend to a parent package, and @key{RET} to go to the
299 currently-selected function.
301 @item M-. l
302 @itemx M-x sepia-pod-follow-link-at-point
303 @findex sepia-pod-follow-link-at-point
304 Follow the POD link (@code{L<...>}) at point, or prompt for a link if
305 there is none.  Go to the appropriate location in the document source
306 or, with a prefix argument, in the rendered documentation.  This can be
307 especially useful when writing links in your own documentation.
309 @end table
311 The second kind of navigation commands always prompts the user -- though
312 usually with a sensible default value -- and finds multiple locations.
313 When called with a prefix argument, these commands present their results
314 in a @code{grep-mode} buffer.  When called @emph{without} a prefix
315 argument, they place all results on the found-location ring and jump
316 directly to the first.  The remaining locations can be cycled through by
317 calls to @code{sepia-next}.
319 @c prompt-and-go commands
320 @table @kbd
321 @item M-. f @var{name} @key{RET}
322 @itemx M-x sepia-defs
323 @findex sepia-defs
324 Find definition(s) of function @var{name}.
326 @item M-. m @var{name} @key{RET}
327 @itemx M-x sepia-module-find @var{name} @key{RET}
328 @findex sepia-module-find
329 Find the source of module @var{name}.
331 @item M-. a @var{regexp} @key{RET}
332 @itemx M-x sepia-apropos @var{regexp} @key{RET}
333 @findex sepia-apropos
334 Find definitions of all functions whose names match @var{regexp}.
336 @item M-x sepia-apropos-module @var{regexp} @key{RET}
337 @findex sepia-apropos-module
338 Find all installed modules matching @var{regexp}.  This function may be
339 slow the first time it is called, because it has to build a list of
340 installed modules.
342 @item M-. c @var{name} @key{RET}
343 @itemx M-x sepia-callers @var{name} @key{RET}
344 @findex sepia-callers
345 (Xref) Find calls to function @var{name}.
347 @item M-. C @var{name} @key{RET}
348 @itemx M-x sepia-callees @var{name} @key{RET}
349 @findex sepia-callees
350 (Xref) Find the definitions of functions called by @var{name}.
352 @item M-. v @var{name} @key{RET}
353 @itemx M-x sepia-var-uses @var{name} @key{RET}
354 @findex sepia-var-uses
355 (Xref) Find uses of the global variable @var{name}.
357 @item M-. V @var{name} @key{RET}
358 @itemx M-x sepia-var-defs @var{name} @key{RET}
359 @findex sepia-var-defs
360 (Xref) Find definitions of global variable @var{name}.  Since Perl's
361 global variables are not declared, this is rarely useful
363 @c XXX: broken, so don't mention it.
364 @c @item M-. A @var{regexp} @key{RET}
365 @c @itemx M-x sepia-var-apropos
366 @c @findex sepia-var-apropos
367 @c Find definitions of all variables whose names match @var{regexp}.  Since
368 @c this function does not handle lexical variables, and since Perl's global
369 @c variables are not declared, this is rarely useful.
371 @end table
373 Finally, there are several other navigation-related commands that do not
374 fit into either of the above categories.
376 @c other commands
377 @table @kbd
378 @item M-,
379 @itemx M-x sepia-next
380 @findex sepia-next
381 Cycle through the definitions found by the previous @key{M-.} search.
383 @item M-. r
384 @itemx M-x sepia-rebuild
385 @findex sepia-rebuild
386 Rebuild the cross-reference database by walking the op-tree and
387 stashes.
389 @item M-. t
390 @itemx M-x find-tag
391 Execute the @code{find-tag} command typically bound to @key{M-.}.
393 @end table
395 @node Documentation, Other commands, Navigation, Editing
396 @section Documentation
398 Sepia can be used to browse installed modules' documentation, to format
399 and display the current buffer's POD, and to browse the list of modules
400 installed on the system.
402 @table @kbd
403 @item M-. p @var{name} @key{RET}
404 @itemx M-x sepia-perldoc-this
405 @findex sepia-perldoc-this
406 View documentation for module @var{name} or Perl manual page @var{name}.
408 @item C-c C-d
409 @itemx M-x sepia-view-pod
410 @findex sepia-view-pod
411 Format and view the current buffer's documentation.
413 @item sepia-package-list
414 @findex sepia-package-list
415 Browse a tree of installed packages.  This lists only the top-level
416 packages from installed distributions, so if package @code{My::Stuff}
417 also provides @code{My::Stuff::Details}, it will not be displayed.  When
418 Emacs-w3m is available, each module is linked to its documentation.
420 @item sepia-module-list
421 @findex sepia-module-list
422 Browse a tree of both top-level and internal packages, like
423 @code{sepia-package-list}.
425 @end table
427 @findex sepia-install-eldoc
428 Sepia also integrates with eldoc (at least in GNU Emacs >= 22).
429 Documentation for Perl operators and control structures is taken from
430 CPerl mode.  Sepia will also display documentation for user-defined
431 functions if their POD is formatted in the standard way, with functions
432 described in a ``=head2'' or ``=item'' entry.  To load user
433 documentation, visit the relevant file and type @kbd{M-x
434 sepia-doc-update}.
436 If @code{Module::CoreList} is available, Sepia's eldoc function will
437 also display the first version of Perl with which a module was shipped.
438 This is intended to give the programmer a sense of when he is creating
439 external dependencies.
441 @node Other commands,  , Documentation, Editing
442 @section Other commands
444 @table @kbd
445 @item M-x sepia-rename-lexical
446 @findex sepia-rename-lexical
447 Rename a variable in the function at point, querying for each
448 replacement when called with a prefix argument.  Currently, this is only
449 a thin wrapper around @code{query-replace}.
450 @end table
453 @c ============================================================
454 @node Interactive Perl, CPAN browsing, Editing, Top
455 @chapter Interactive Perl
457 @findex sepia-repl
458 Sepia's second main contribution is an interactive interface (REPL) to
459 an inferior Perl process.  The interface is based on GUD mode, and
460 inherits many of its bindings; this chapter discusses only the Sepia
461 extensions.  To start or switch to the repl, type @kbd{M-x sepia-repl}.
462 As in Sepia mode, @key{TAB} in the REPL performs partial-word completion
463 with @code{sepia-complete-symbol}.
465 @c == REPL behavior ==
466 @c - $_/@_
467 @c - RET & eval/newline
468 @c - eval context
470 Sepia also provides a number of other ways to evaluate pieces of code in
471 Perl, and commands to process buffer text using the inferior process.
473 Finally, Sepia comes with the @kbd{sepl} program, a standalone REPL that
474 can be run from the command-line, and provides many features of the
475 Emacs-based REPL.
477 @menu
478 * Shortcuts::                   
479 * Debugger::                    
480 * Evaluation::                  
481 * Mutilation::                  
482 * Scratchpad::                  
483 @end menu
485 @node Shortcuts, Debugger, Interactive Perl, Interactive Perl
486 @section Shortcuts
488 ``Shortcuts'' are commands handled specially by the REPL rather than
489 being evaluated as Perl code.  They either communicate with the REPL
490 function, or provide a convenient interface to Sepia variables and
491 functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
492 abbreviated to the shortest unique prefix.  The debugger defines
493 additional shortcuts (@xref{Debugger}.).
495 @table @kbd
496 @item break @var{file}:@var{line} [@var{expr}]
497 Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
498 supplied, stop only if it evaluates to true.
500 @item cd @var{dir}
501 Change Perl's current directory to @var{dir}.
503 @item debug [@var{val}]
504 Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.
506 @item define @var{name} ['@var{doc}'] @var{body...}
507 Define @var{name} as a shortcut for Perl code @var{body}, with optional
508 documentation @var{doc}, surrounded by single quotes.  @var{body} is
509 passed the raw command-line text as its first argument.
511 @item format @var{type}
512 Set the output format to @var{type}, either ``dumper'' (using
513 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
514 (@code{YAML}), ``peek'' (@code{Devel::Peek}), ``dumpvar''
515 (@code{dumpvar.pl}, somewhat rough), or ``plain'' (stringification).
516 Default: ``dumper''.
518 Note that this setting is independent of @code{$COLUMNATE} and
519 @code{$STRINGIFY}.
521 @item help
522 Display a list of shortcuts.
524 @item load [@var{file}]
525 Reload saved variables from @var{file} (or @file{~/.sepia-save}),
526 created by @kbd{save}.
528 @item lsbreak
529 List breakpoints.
531 @item lsmod [@var{pattern}]
532 List currently-loaded modules matching optional @var{pattern}.
534 @item methods @var{name} [@var{regexp}]
535 Display a list of functions defined in package @var{name} and its
536 @code{ISA}-ancestors matching optional pattern @var{regexp}.
538 @item package @var{name}
539 Set the default evaluation package to @var{name}.
541 @item pwd
542 Show the process's current working directory.
544 @item quit
545 Exit the inferior Perl process.
547 @item reload [@var{module} | @var{/pattern/}]
548 Reload @var{module} (but not its dependencies), or all modules matching
549 @var{pattern}.
551 @item freload @var{module}
552 Reload @var{module} and all of its dependencies.
554 @item restart
555 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
556 mostly of interest when working on Sepia itself, and will fail
557 catastrophically if @file{Sepia.pm} fails to compile.
559 @item save [@var{pattern} [@var{file}]]
560 Save variables matching @var{pattern} (or all variables) to @var{file}
561 (or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
562 saving magic variables can have unpredictable results, using @kbd{save}
563 without a pattern argument is risky.  Sepia excludes common magic
564 variables and dangerous packages, but its list is not foolproof.
566 @item shell [@var{command}]
567 Execute shell command @var{command}, displaying its standard output and
568 standard error.
570 @item size [@var{package} [@var{regexp}]]
571 List the variables in @var{package} (or the current package) along with
572 their total sizes.  This requires the @code{Devel::Size} module.
574 @item strict [@var{val}]
575 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
576 given.  Note that turning strictness off and on clears the REPL's
577 lexical environment.
579 @item test [@var{file}]
580 Run tests in the current directory.  If @var{file} is given, only run
581 test @var{file} or @file{t/@var{file}}
583 @item time [@var{val}]
584 Set time display to @var{val}, or toggle it if @var{val} is not given.
585 With time display enabled, Sepia will use @code{BSD::Resource} and/or
586 @code{Time::HiRes} to display wall clock time and CPU usage for the
587 previous command as part of the prompt.
589 @item undef @var{name}
590 Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
591 used to remove built-in shortcuts.
593 @item wantarray [@var{val}]
594 Set the evaluation context to @var{val}: @code{@@} means array, @code{$}
595 means scalar, and anything else means void.
597 @item who @var{package} [@var{regexp}]
598 @itemx who [@var{regexp}]
599 List identifiers in @var{package} (main by default) matching
600 optional @var{regexp}.
602 @end table
604 @node Debugger, Evaluation, Shortcuts, Interactive Perl
605 @section Debugger
607 Sepia uses Perl's debugger hooks and GUD mode to support conditional
608 breakpoints and single-stepping, and overrides Perl's @code{die()} to
609 invoke the debugger rather than unwind the stack.  This makes it
610 possible to produce a backtrace, inspect and modify global variables,
611 and even continue execution when a program tries to kill itself.  If the
612 PadWalker module is available, Sepia also provides functions to inspect
613 and modify lexical variables.
615 The debugger has its own set of shortcuts, also prefixed by a comma.
617 @table @kbd
618 @item backtrace
619 Show a backtrace.
621 @item delete
622 Delete the current breakpoint.
624 @item down @var{n}
625 @itemx up @var{n}
626 Move the current stack frame up or down by @var{n} (or one) frames.
628 @item inspect [@var{n}]
629 Inspect lexicals in the current frame or frame @var{n}, counting upward
630 from 1.
632 @item next [@var{n}]
633 Advance @var{n} (or one) lines, skipping subroutine calls.
635 @item quit
636 @itemx die
637 @itemx warn
638 Continue as the program would have executed without debugger
639 intervention, dying if the debugger was called from @code{die()}.
641 @item return @var{expr}
642 Continue execution as if @code{die()} had returned the value of
643 @var{expr}, which is evaluated in the global environment.
645 @item step [@var{n}]
646 Step forward @var{n} (or one) lines, descending into subroutines.
648 @item xreturn @var{sub} @var{expr}
649 Return @var{expr} from the innermost call to @var{sub}.  This is a
650 somewhat dangerous and experimental feature, but is probably more useful
651 than returning a value from @code{die()}.
653 @end table
655 @node Evaluation, Mutilation, Debugger, Interactive Perl
656 @section Evaluation
658 When interactive Perl is running, Sepia can evaluate regions of code in
659 the inferior Perl process.  The following commands assume that this
660 process has already been started by calling @code{sepia-repl}.
662 @table @kbd
663 @item C-M-x
664 @itemx M-x sepia-eval-defun
665 @findex sepia-eval-defun
666 Evaluate the function around point in the inferior Perl process.  If it
667 contains errors, jump to the location of the first.
669 @item C-c C-l
670 @itemx M-x sepia-load-file
671 @findex sepia-load-file
672 Save the current buffer, then reload its file and if warnings or errors
673 occur, display an error buffer.  With a prefix argument, also rebuild
674 the cross-reference index.
676 @item C-c e
677 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
678 @findex sepia-eval-expression
679 Evaluate @var{expr} in scalar context and echo the result.  With a
680 prefix argument, evaluate in list context.
682 @item C-c!
683 @itemx sepia-set-cwd
684 @findex sepia-set-cwd
685 Set the REPL's working directory to the current buffer's directory.
687 @end table
689 @node Mutilation, Scratchpad, Evaluation, Interactive Perl
690 @section Mutilation
692 Sepia contains several functions to operate on regions of text using the
693 interactive Perl process.  These functions can be used like standard
694 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
695 the functions and variables in the interactive session are available.
697 @table @kbd
698 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
699 @findex sepia-perl-pe-region
700 Evaluate @var{code} on each line in the region with @code{$_} bound to
701 the line text, collecting the resulting values of @code{$_}.  With a
702 prefix argument, replace the region with the result.
704 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
705 @findex sepia-perl-ne-region
706 Evaluate @var{code} as above, but collect the results instead.
708 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
709 @findex sepia-perlize-region
710 Evaluate @var{code} once with @code{$_} bound to the entire region,
711 collecting the final value of @code{$_}.  With a prefix argument,
712 replace the region.
714 @end table
716 @node Scratchpad,  , Mutilation, Interactive Perl
717 @section Scratchpad
719 @findex sepia-scratch
720 Sepia also supports a scratchpad, another form of interaction inspired
721 by Emacs' @code{*scratch*} buffer.  To create or switch to the
722 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
723 like Sepia mode, except @key{C-j} evaluates the current line and prints
724 the result on the next line.
726 @c ============================================================
727 @node  CPAN browsing, Customization, Interactive Perl, Top
728 @chapter CPAN browsing
730 Sepia has rudimentary support for browsing documentation and installing
731 modules from CPAN.  Modules whose names, descriptions, or authors match
732 a query are displayed in a @code{*sepia-cpan*} buffer, in which the
733 following commands are available:
735 @table @kbd
736 @item s
737 @itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
738 @findex sepia-cpan-search
739 List modules whose names match @var{pattern}.
741 @item /
742 @itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
743 @findex sepia-cpan-desc
744 List modules whose names or descriptions match @var{pattern}.
746 @item l
747 @itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
748 @findex sepia-cpan-list
749 List modules authored by @var{name}.
751 @item r
752 @itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
753 @findex sepia-cpan-readme
754 Fetch and display @var{module}'s README file.
756 @item d
757 @itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
758 @findex sepia-cpan-doc
759 Browse @var{module}'s documentation on @url{http://search.cpan.org}.
761 @item i
762 @itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
763 @findex sepia-cpan-install
764 Install @var{module} and its prerequisites.  This feature is not yet
765 well tested.
767 @end table
769 @c ============================================================
770 @node Customization, Internals, CPAN browsing, Top
771 @chapter Customization
773 While Sepia can be customized in both the Perl and Emacs Lisp, most of
774 the user-accessible configuration is in the latter.
776 @menu
777 * Emacs Customization::             
778 * Perl Customization::              
779 @end menu
781 @node Emacs Customization, Perl Customization, Customization, Customization
782 @section Emacs Customization
784 Since Sepia tries where possible to reuse existing Emacs functionality,
785 its behavior should already be covered by existing customizations.  The
786 two variables most likely to need customization are
787 @kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
788 configuration can be done with @kbd{sepia-mode-hook}, while
789 REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.
791 @vtable @kbd
793 @item sepia-complete-methods
794 If non-@code{nil}, @code{sepia-complete-symbol} will complete
795 simple method calls of the form @code{$x->} or @code{Module->}.  Since
796 the former requires evaluation of @code{$x}, this can be disabled.
797 Default: @code{t}.
799 @item sepia-eval-defun-include-decls
800 If non-@code{nil}, attempt to generate a declaration list for
801 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
802 such as that calling functions without parentheses, because the presence
803 of declarations affects the parsing of barewords.  Default: @code{t}.
805 @item sepia-indent-expand-abbrev
806 If non-@code{nil}, @code{sepia-indent-or-complete} will, if
807 reindentation does not change the current line, expand an abbreviation
808 before point rather than performing completion.  Only if no abbreviation
809 is found will it perform completion.  Default: @code{t}.
811 @item sepia-module-list-function
812 The function to view a tree of installed modules.  Default:
813 @code{w3m-find-file} if Emacs-w3m is installed, or
814 @code{browse-url-of-buffer} otherwise.
816 @item sepia-perldoc-function
817 The function called to view installed modules' documentation.  Default:
818 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
819 otherwise.
821 @item sepia-perl5lib
822 A list of directories to include in @code{PERL5LIB} when starting
823 interactive Perl.  Default: @code{nil}.
825 @item sepia-prefix-key
826 The prefix to use for for functions in @code{sepia-keymap}.  Default:
827 @key{M-.}.
829 @item sepia-program-name
830 The Perl program name for interactive Perl.  Default: ``perl''.
832 @item sepia-use-completion
833 If non-@code{nil}, various Sepia functions will generate completion
834 candidates from interactive Perl when called interactively.  This may be
835 slow or undesirable in some situations.  Default: @code{t}.
837 @item sepia-view-pod-function
838 The function called to view the current buffer's documentation.
839 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
840 @code{sepia-perldoc-buffer} otherwise.
842 @end vtable
844 @node Perl Customization,  , Emacs Customization, Customization
845 @section Perl Customization
847 When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.
849 The following variables in the Sepia package control various aspects of
850 interactive evaluation.
852 @table @code
854 @item $PACKAGE
855 The package in which user input is evaluated, determined automatically
856 when code is evaluated from a buffer.  Default: @code{main}.
858 @item $PRINTER
859 The function called to format interactive output, normally set with the
860 @code{printer} shortcut.
862 @item $COLUMNATE
863 If true, columnate simple arrays independent of the value of
864 @code{$PRINTER}.  Default: true.
866 @item $STRINGIFY
867 If true, stringify objects that overload the operation independent of
868 the value of @code{$PRINTER}.  Default: true.
870 @item $PS1
871 The trailing end of the prompt string, which should end with ``> ''.
872 Default: @code{"> "}.
874 @item $STOPDIE
875 If true, calls to @code{die} from interactive code will invoke the Sepia
876 debugger.  Default: true.
878 @item $STOPWARN
879 If true, calls to @code{warn} from interactive code will invoke the
880 Sepia debugger.  Default: false.
882 @item $WANTARRAY
883 If @code{@@}, evaluate interactive expressions in list context, if
884 @code{$}, scalar, otherwise, void.  Default: @code{@@}.
886 @end table
888 Additional REPL shortcuts can be defined as follows:
890 @table @code
892 @item Sepia::define_shortcut @var{name}, @var{function} [, @var{shortdoc} [, @var{longdoc}]]
894 Define a shortcut @var{name} to call @var{function}.  Also define a
895 short usage message @var{shortdoc} and documentation @var{longdoc}.  For
896 example,
898 @example
900 Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
901     'time', 'Display the current time.';
903 @end example
905 defines a shortcut ``time'' that displays the current time.  For more
906 examples, see the function @var{define_shortcuts} code in
907 @file{Sepia.pm}.
909 @item Sepia::alias_shortcut @var{new}, @var{old}
911 Make @var{new} an alias for @var{old}.
913 @end table
916 @c ============================================================
917 @node Internals, FAQ, Customization, Top
918 @chapter Internals
920 Many things remain unexplained except by the code itself, and some
921 details mentioned above should probably be given less prominence.  For
922 developer documentation, please see the POD for @code{Sepia} and
923 @code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.
925 @node FAQ, Credits, Internals, Top
926 @chapter FAQ
928 @table @asis
929 @item Can I use @code{Sepia} outside of Emacs?
930 Sepia comes with the @file{sepl} program, a command-line REPL using the
931 @code{Sepia::Readline} module, that provides many features of the
932 Emacs-based REPL.  It could be improved, though -- patches welcome!
934 @file{sepl} currently provides completion for @code{Term::ReadLine::Gnu}
935 and @code{Term::ReadLine::Perl}.  If you have neither of these, using
936 @file{rlwrap} might be the best option.
938 @item Why is the documentation in TeXInfo format?!
939 TeXInfo is the worst form of documentation, except for all the others.
940 TeX and LaTeX produce beautiful printed output, and Info is the best way
941 to view documentation in Emacs for things that are not themselves part
942 of Emacs (i.e. ``can have docstrings'').
944 It's awful to edit, being both verbose and redundant -- just look at
945 AUCTeX's @code{texinfo-every-node-update} for desperate placation of the
946 suck, then try to figure out what's wrong when @file{makeinfo} complains
947 about @code{texinfo-every-node-update}'s output -- but it's what we
948 have.  At least it sucks less than @code{DocBook}, raw HTML, or
949 @file{troff}.
951 @end table
953 @node Credits, Function Index, FAQ, Top
954 @unnumbered Credits
956 @table @asis
957 @item Hilko Bengen
958 Found and motivated me to fix a bunch of bugs, created Debian packages.
960 @item Ævar Arnfjörð Bjarmason
961 Miscellaneous fixes.  Tested unicode support.
963 @item Ye Wenbin
964 Found and fixed numerous bugs.
966 @item Free Software
967 Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
968 B::Xref, all of which are Free software.
970 @end table
972 @c ============================================================
973 @node Function Index, Variable Index, Credits, Top
974 @unnumbered Function Index
975 @printindex fn
977 @node Variable Index,  , Function Index, Top
978 @unnumbered Variable Index
979 @printindex vr
981 @bye