Clean up URLs.
[sepia.git] / sepia.texi
blob9064c9f33d7900eca3d79e95b33ebbc90863a7bb
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-. l
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 @end table
303 The second kind of navigation commands always prompts the user -- though
304 usually with a sensible default value -- and finds multiple locations.
305 When called with a prefix argument, these commands present their results
306 in a @code{grep-mode} buffer.  When called @emph{without} a prefix
307 argument, they place all results on the found-location ring and jump
308 directly to the first.  The remaining locations can be cycled through by
309 calls to @code{sepia-next}.
311 @c prompt-and-go commands
312 @table @kbd
313 @item M-. f @var{name} @key{RET}
314 @itemx M-x sepia-defs
315 @findex sepia-defs
316 Find definition(s) of function @var{name}.
318 @item M-. m @var{name} @key{RET}
319 @itemx M-x sepia-module-find @var{name} @key{RET}
320 @findex sepia-module-find
321 Find the source of module @var{name}.
323 @item M-. a @var{regexp} @key{RET}
324 @itemx M-x sepia-apropos @var{regexp} @key{RET}
325 @findex sepia-apropos
326 Find definitions of all functions whose names match @var{regexp}.
328 @item M-x sepia-apropos-module @var{regexp} @key{RET}
329 @findex sepia-apropos-module
330 Find all installed modules matching @var{regexp}.  This function may be
331 slow the first time it is called, because it has to build a list of
332 installed modules.
334 @item M-. c @var{name} @key{RET}
335 @itemx M-x sepia-callers @var{name} @key{RET}
336 @findex sepia-callers
337 (Xref) Find calls to function @var{name}.
339 @item M-. C @var{name} @key{RET}
340 @itemx M-x sepia-callees @var{name} @key{RET}
341 @findex sepia-callees
342 (Xref) Find the definitions of functions called by @var{name}.
344 @item M-. v @var{name} @key{RET}
345 @itemx M-x sepia-var-uses @var{name} @key{RET}
346 @findex sepia-var-uses
347 (Xref) Find uses of the global variable @var{name}.
349 @item M-. V @var{name} @key{RET}
350 @itemx M-x sepia-var-defs @var{name} @key{RET}
351 @findex sepia-var-defs
352 (Xref) Find definitions of global variable @var{name}.  Since Perl's
353 global variables are not declared, this is rarely useful
355 @c XXX: broken, so don't mention it.
356 @c @item M-. A @var{regexp} @key{RET}
357 @c @itemx M-x sepia-var-apropos
358 @c @findex sepia-var-apropos
359 @c Find definitions of all variables whose names match @var{regexp}.  Since
360 @c this function does not handle lexical variables, and since Perl's global
361 @c variables are not declared, this is rarely useful.
363 @end table
365 Finally, there are several other navigation-related commands that do not
366 fit into either of the above categories.
368 @c other commands
369 @table @kbd
370 @item M-,
371 @itemx M-x sepia-next
372 @findex sepia-next
373 Cycle through the definitions found by the previous @key{M-.} search.
375 @item M-. r
376 @itemx M-x sepia-rebuild
377 @findex sepia-rebuild
378 Rebuild the cross-reference database by walking the op-tree and
379 stashes.
381 @item M-. t
382 @itemx M-x find-tag
383 Execute the @code{find-tag} command typically bound to @key{M-.}.
385 @end table
387 @node Documentation, Other commands, Navigation, Editing
388 @section Documentation
390 Sepia can be used to browse installed modules' documentation, to format
391 and display the current buffer's POD, and to browse the list of modules
392 installed on the system.
394 @table @kbd
395 @item M-. d @var{name} @key{RET}
396 @itemx M-x sepia-perldoc-this
397 @findex sepia-perldoc-this
398 View documentation for module @var{name} or Perl manual page @var{name}.
400 @item C-c C-d
401 @itemx M-x sepia-view-pod
402 @findex sepia-view-pod
403 Format and view the current buffer's documentation.
405 @item sepia-package-list
406 @findex sepia-package-list
407 Browse a tree of installed packages.  This lists only the top-level
408 packages from installed distributions, so if package @code{My::Stuff}
409 also provides @code{My::Stuff::Details}, it will not be displayed.  When
410 Emacs-w3m is available, each module is linked to its documentation.
412 @item sepia-module-list
413 @findex sepia-module-list
414 Browse a tree of both top-level and internal packages, like
415 @code{sepia-package-list}.
417 @end table
419 @findex sepia-install-eldoc
420 Sepia also integrates with eldoc (at least in GNU Emacs >= 22).
421 Documentation for Perl operators and control structures is taken from
422 CPerl mode.  Sepia will also display documentation for user-defined
423 functions if their POD is formatted in the standard way, with functions
424 described in a ``=head2'' or ``=item'' entry.  To load user
425 documentation, visit the relevant file and type @kbd{M-x
426 sepia-doc-update}.
428 If @code{Module::CoreList} is available, Sepia's eldoc function will
429 also display the first version of Perl with which a module was shipped.
430 This is intended to give the programmer a sense of when he is creating
431 external dependencies.
433 @node Other commands,  , Documentation, Editing
434 @section Other commands
436 @table @kbd
437 @item M-x sepia-rename-lexical
438 @findex sepia-rename-lexical
439 Rename a variable in the function at point, querying for each
440 replacement when called with a prefix argument.  Currently, this is only
441 a thin wrapper around @code{query-replace}.
442 @end table
445 @c ============================================================
446 @node Interactive Perl, CPAN browsing, Editing, Top
447 @chapter Interactive Perl
449 @findex sepia-repl
450 Sepia's second main contribution is an interactive interface (REPL) to
451 an inferior Perl process.  The interface is based on GUD mode, and
452 inherits many of its bindings; this chapter discusses only the Sepia
453 extensions.  To start or switch to the repl, type @kbd{M-x sepia-repl}.
454 As in Sepia mode, @key{TAB} in the REPL performs partial-word completion
455 with @code{sepia-complete-symbol}.
457 @c == REPL behavior ==
458 @c - $_/@_
459 @c - RET & eval/newline
460 @c - eval context
462 Sepia also provides a number of other ways to evaluate pieces of code in
463 Perl, and commands to process buffer text using the inferior process.
465 Finally, Sepia comes with the @kbd{sepl} program, a standalone REPL that
466 can be run from the command-line, and provides many features of the
467 Emacs-based REPL.
469 @menu
470 * Shortcuts::                   
471 * Debugger::                    
472 * Evaluation::                  
473 * Mutilation::                  
474 * Scratchpad::                  
475 @end menu
477 @node Shortcuts, Debugger, Interactive Perl, Interactive Perl
478 @section Shortcuts
480 ``Shortcuts'' are commands handled specially by the REPL rather than
481 being evaluated as Perl code.  They either communicate with the REPL
482 function, or provide a convenient interface to Sepia variables and
483 functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
484 abbreviated to the shortest unique prefix.  The debugger defines
485 additional shortcuts (@xref{Debugger}.).
487 @table @kbd
488 @item break @var{file}:@var{line} [@var{expr}]
489 Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
490 supplied, stop only if it evaluates to true.
492 @item cd @var{dir}
493 Change Perl's current directory to @var{dir}.
495 @item debug [@var{val}]
496 Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.
498 @item define @var{name} ['@var{doc}'] @var{body...}
499 Define @var{name} as a shortcut for Perl code @var{body}, with optional
500 documentation @var{doc}, surrounded by single quotes.  @var{body} is
501 passed the raw command-line text as its first argument.
503 @item format @var{type}
504 Set the output format to @var{type}, either ``dumper'' (using
505 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
506 (@code{YAML}), ``peek'' (@code{Devel::Peek}), ``dumpvar''
507 (@code{dumpvar.pl}, somewhat rough), or ``plain'' (stringification).
508 Default: ``dumper''.
510 Note that this setting is independent of @code{$COLUMNATE} and
511 @code{$STRINGIFY}.
513 @item help
514 Display a list of shortcuts.
516 @item load [@var{file}]
517 Reload saved variables from @var{file} (or @file{~/.sepia-save}),
518 created by @kbd{save}.
520 @item lsbreak
521 List breakpoints.
523 @item lsmod [@var{pattern}]
524 List currently-loaded modules matching optional @var{pattern}.
526 @item methods @var{name} [@var{regexp}]
527 Display a list of functions defined in package @var{name} and its
528 @code{ISA}-ancestors matching optional pattern @var{regexp}.
530 @item package @var{name}
531 Set the default evaluation package to @var{name}.
533 @item pwd
534 Show the process's current working directory.
536 @item quit
537 Exit the inferior Perl process.
539 @item reload [@var{module} | @var{/pattern/}]
540 Reload @var{module} (but not its dependencies), or all modules matching
541 @var{pattern}.
543 @item freload @var{module}
544 Reload @var{module} and all of its dependencies.
546 @item restart
547 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
548 mostly of interest when working on Sepia itself, and will fail
549 catastrophically if @file{Sepia.pm} fails to compile.
551 @item save [@var{pattern} [@var{file}]]
552 Save variables matching @var{pattern} (or all variables) to @var{file}
553 (or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
554 saving magic variables can have unpredictable results, using @kbd{save}
555 without a pattern argument is risky.  Sepia excludes common magic
556 variables and dangerous packages, but its list is not foolproof.
558 @item shell [@var{command}]
559 Execute shell command @var{command}, displaying its standard output and
560 standard error.
562 @item size [@var{package} [@var{regexp}]]
563 List the variables in @var{package} (or the current package) along with
564 their total sizes.  This requires the @code{Devel::Size} module.
566 @item strict [@var{val}]
567 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
568 given.  Note that turning strictness off and on clears the REPL's
569 lexical environment.
571 @item test [@var{file}]
572 Run tests in the current directory.  If @var{file} is given, only run
573 test @var{file} or @file{t/@var{file}}
575 @item time [@var{val}]
576 Set time display to @var{val}, or toggle it if @var{val} is not given.
577 With time display enabled, Sepia will use @code{BSD::Resource} and/or
578 @code{Time::HiRes} to display wall clock time and CPU usage for the
579 previous command as part of the prompt.
581 @item undef @var{name}
582 Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
583 used to remove built-in shortcuts.
585 @item wantarray [@var{val}]
586 Set the evaluation context to @var{val}: @code{@@} means array, @code{$}
587 means scalar, and anything else means void.
589 @item who @var{package} [@var{regexp}]
590 @itemx who [@var{regexp}]
591 List identifiers in @var{package} (main by default) matching
592 optional @var{regexp}.
594 @end table
596 @node Debugger, Evaluation, Shortcuts, Interactive Perl
597 @section Debugger
599 Sepia uses Perl's debugger hooks and GUD mode to support conditional
600 breakpoints and single-stepping, and overrides Perl's @code{die()} to
601 invoke the debugger rather than unwind the stack.  This makes it
602 possible to produce a backtrace, inspect and modify global variables,
603 and even continue execution when a program tries to kill itself.  If the
604 PadWalker module is available, Sepia also provides functions to inspect
605 and modify lexical variables.
607 The debugger has its own set of shortcuts, also prefixed by a comma.
609 @table @kbd
610 @item backtrace
611 Show a backtrace.
613 @item delete
614 Delete the current breakpoint.
616 @item down @var{n}
617 @itemx up @var{n}
618 Move the current stack frame up or down by @var{n} (or one) frames.
620 @item inspect [@var{n}]
621 Inspect lexicals in the current frame or frame @var{n}, counting upward
622 from 1.
624 @item next [@var{n}]
625 Advance @var{n} (or one) lines, skipping subroutine calls.
627 @item quit
628 @itemx die
629 @itemx warn
630 Continue as the program would have executed without debugger
631 intervention, dying if the debugger was called from @code{die()}.
633 @item return @var{expr}
634 Continue execution as if @code{die()} had returned the value of
635 @var{expr}, which is evaluated in the global environment.
637 @item step [@var{n}]
638 Step forward @var{n} (or one) lines, descending into subroutines.
640 @item xreturn @var{sub} @var{expr}
641 Return @var{expr} from the innermost call to @var{sub}.  This is a
642 somewhat dangerous and experimental feature, but is probably more useful
643 than returning a value from @code{die()}.
645 @end table
647 @node Evaluation, Mutilation, Debugger, Interactive Perl
648 @section Evaluation
650 When interactive Perl is running, Sepia can evaluate regions of code in
651 the inferior Perl process.  The following commands assume that this
652 process has already been started by calling @code{sepia-repl}.
654 @table @kbd
655 @item C-M-x
656 @itemx M-x sepia-eval-defun
657 @findex sepia-eval-defun
658 Evaluate the function around point in the inferior Perl process.  If it
659 contains errors, jump to the location of the first.
661 @item C-c C-l
662 @itemx M-x sepia-load-file
663 @findex sepia-load-file
664 Save the current buffer, then reload its file and if warnings or errors
665 occur, display an error buffer.  With a prefix argument, also rebuild
666 the cross-reference index.
668 @item C-c e
669 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
670 @findex sepia-eval-expression
671 Evaluate @var{expr} in scalar context and echo the result.  With a
672 prefix argument, evaluate in list context.
674 @item C-c!
675 @itemx sepia-set-cwd
676 @findex sepia-set-cwd
677 Set the REPL's working directory to the current buffer's directory.
679 @end table
681 @node Mutilation, Scratchpad, Evaluation, Interactive Perl
682 @section Mutilation
684 Sepia contains several functions to operate on regions of text using the
685 interactive Perl process.  These functions can be used like standard
686 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
687 the functions and variables in the interactive session are available.
689 @table @kbd
690 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
691 @findex sepia-perl-pe-region
692 Evaluate @var{code} on each line in the region with @code{$_} bound to
693 the line text, collecting the resulting values of @code{$_}.  With a
694 prefix argument, replace the region with the result.
696 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
697 @findex sepia-perl-ne-region
698 Evaluate @var{code} as above, but collect the results instead.
700 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
701 @findex sepia-perlize-region
702 Evaluate @var{code} once with @code{$_} bound to the entire region,
703 collecting the final value of @code{$_}.  With a prefix argument,
704 replace the region.
706 @end table
708 @node Scratchpad,  , Mutilation, Interactive Perl
709 @section Scratchpad
711 @findex sepia-scratch
712 Sepia also supports a scratchpad, another form of interaction inspired
713 by Emacs' @code{*scratch*} buffer.  To create or switch to the
714 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
715 like Sepia mode, except @key{C-j} evaluates the current line and prints
716 the result on the next line.
718 @c ============================================================
719 @node  CPAN browsing, Customization, Interactive Perl, Top
720 @chapter CPAN browsing
722 Sepia has rudimentary support for browsing documentation and installing
723 modules from CPAN.  Modules whose names, descriptions, or authors match
724 a query are displayed in a @code{*sepia-cpan*} buffer, in which the
725 following commands are available:
727 @table @kbd
728 @item s
729 @itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
730 @findex sepia-cpan-search
731 List modules whose names match @var{pattern}.
733 @item /
734 @itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
735 @findex sepia-cpan-desc
736 List modules whose names or descriptions match @var{pattern}.
738 @item l
739 @itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
740 @findex sepia-cpan-list
741 List modules authored by @var{name}.
743 @item r
744 @itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
745 @findex sepia-cpan-readme
746 Fetch and display @var{module}'s README file.
748 @item d
749 @itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
750 @findex sepia-cpan-doc
751 Browse @var{module}'s documentation on @url{http://search.cpan.org}.
753 @item i
754 @itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
755 @findex sepia-cpan-install
756 Install @var{module} and its prerequisites.  This feature is not yet
757 well tested.
759 @end table
761 @c ============================================================
762 @node Customization, Internals, CPAN browsing, Top
763 @chapter Customization
765 While Sepia can be customized in both the Perl and Emacs Lisp, most of
766 the user-accessible configuration is in the latter.
768 @menu
769 * Emacs Customization::             
770 * Perl Customization::              
771 @end menu
773 @node Emacs Customization, Perl Customization, Customization, Customization
774 @section Emacs Customization
776 Since Sepia tries where possible to reuse existing Emacs functionality,
777 its behavior should already be covered by existing customizations.  The
778 two variables most likely to need customization are
779 @kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
780 configuration can be done with @kbd{sepia-mode-hook}, while
781 REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.
783 @vtable @kbd
785 @item sepia-complete-methods
786 If non-@code{nil}, @code{sepia-complete-symbol} will complete
787 simple method calls of the form @code{$x->} or @code{Module->}.  Since
788 the former requires evaluation of @code{$x}, this can be disabled.
789 Default: @code{T}.
791 @item sepia-eval-defun-include-decls
792 If non-@code{nil}, attempt to generate a declaration list for
793 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
794 such as that calling functions without parentheses, because the presence
795 of declarations affects the parsing of barewords.  Default: @code{T}.
797 @item sepia-indent-expand-abbrev
798 If non-@code{nil}, @code{sepia-indent-or-complete} will, if
799 reindentation does not change the current line, expand an abbreviation
800 before point rather than performing completion.  Only if no abbreviation
801 is found will it perform completion.  Default: @code{T}.
803 @item sepia-module-list-function
804 The function to view a tree of installed modules.  Default:
805 @code{w3m-find-file} if Emacs-w3m is installed, or
806 @code{browse-url-of-buffer} otherwise.
808 @item sepia-perldoc-function
809 The function called to view installed modules' documentation.  Default:
810 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
811 otherwise.
813 @item sepia-perl5lib
814 A list of directories to include in @code{PERL5LIB} when starting
815 interactive Perl.  Default: @code{nil}.
817 @item sepia-prefix-key
818 The prefix to use for for functions in @code{sepia-keymap}.  Default:
819 @key{M-.}.
821 @item sepia-program-name
822 The Perl program name for interactive Perl.  Default: ``perl''.
824 @item sepia-use-completion
825 If non-@code{nil}, various Sepia functions will generate completion
826 candidates from interactive Perl when called interactively.  This may be
827 slow or undesirable in some situations.  Default: @code{T}.
829 @item sepia-view-pod-function
830 The function called to view the current buffer's documentation.
831 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
832 @code{sepia-perldoc-buffer} otherwise.
834 @end vtable
836 @node Perl Customization,  , Emacs Customization, Customization
837 @section Perl Customization
839 When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.
841 The following variables in the Sepia package control various aspects of
842 interactive evaluation.
844 @table @code
846 @item $PACKAGE
847 The package in which user input is evaluated, determined automatically
848 when code is evaluated from a buffer.  Default: @code{main}.
850 @item $PRINTER
851 The function called to format interactive output, normally set with the
852 @code{printer} shortcut.
854 @item $COLUMNATE
855 If true, columnate simple arrays independent of the value of
856 @code{$PRINTER}.  Default: true.
858 @item $STRINGIFY
859 If true, stringify objects that overload the operation independent of
860 the value of @code{$PRINTER}.  Default: true.
862 @item $PS1
863 The trailing end of the prompt string, which should end with ``> ''.
864 Default: @code{"> "}.
866 @item $STOPDIE
867 If true, calls to @code{die} from interactive code will invoke the Sepia
868 debugger.  Default: true.
870 @item $STOPWARN
871 If true, calls to @code{warn} from interactive code will invoke the
872 Sepia debugger.  Default: false.
874 @item $WANTARRAY
875 If @code{@@}, evaluate interactive expressions in list context, if
876 @code{$}, scalar, otherwise, void.  Default: @code{@@}.
878 @end table
880 Additional REPL shortcuts can be defined as follows:
882 @table @code
884 @item Sepia::define_shortcut @var{name}, @var{function} [, @var{shortdoc} [, @var{longdoc}]]
886 Define a shortcut @var{name} to call @var{function}.  Also define a
887 short usage message @var{shortdoc} and documentation @var{longdoc}.  For
888 example,
890 @example
892 Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
893     'time', 'Display the current time.';
895 @end example
897 defines a shortcut ``time'' that displays the current time.  For more
898 examples, see the function @var{define_shortcuts} code in
899 @file{Sepia.pm}.
901 @item Sepia::alias_shortcut @var{new}, @var{old}
903 Make @var{new} an alias for @var{old}.
905 @end table
908 @c ============================================================
909 @node Internals, FAQ, Customization, Top
910 @chapter Internals
912 Many things remain unexplained except by the code itself, and some
913 details mentioned above should probably be given less prominence.  For
914 developer documentation, please see the POD for @code{Sepia} and
915 @code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.
917 @node FAQ, Credits, Internals, Top
918 @chapter FAQ
920 @table @asis
921 @item Can I use @code{Sepia} outside of Emacs?
922 Sepia comes with the @file{sepl} program, a command-line REPL using the
923 @code{Sepia::Readline} module, that provides many features of the
924 Emacs-based REPL.  It could be improved, though -- patches welcome!
926 @item Why is the documentation in TeXInfo format?!
927 TeXInfo is the worst form of documentation, except for all the others.
928 TeX and LaTeX produce beautiful printed output, and Info is the best way
929 to view documentation in Emacs for things that are not themselves part
930 of Emacs (i.e. ``can have docstrings'').
932 It's awful to edit, being both verbose and redundant -- just look at
933 AUCTeX's @code{texinfo-every-node-update} for desperate placation of the
934 suck, then try to figure out what's wrong when @file{makeinfo} complains
935 about @code{texinfo-every-node-update}'s output -- but it's what we
936 have.  At least it sucks less than @code{DocBook}, raw HTML, or
937 @file{troff}.
939 @end table
941 @node Credits, Function Index, FAQ, Top
942 @unnumbered Credits
944 @table @asis
945 @item Hilko Bengen
946 Found and motivated me to fix a bunch of bugs, created Debian packages.
948 @item Ævar Arnfjörð Bjarmason
949 Miscellaneous fixes.  Tested unicode support.
951 @item Ye Wenbin
952 Found and fixed numerous bugs.
954 @item Free Software
955 Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
956 B::Xref, all of which are Free software.
958 @end table
960 @c ============================================================
961 @node Function Index, Variable Index, Credits, Top
962 @unnumbered Function Index
963 @printindex fn
965 @node Variable Index,  , Function Index, Top
966 @unnumbered Variable Index
967 @printindex vr
969 @bye