initial
[sepia.git] / sepia.texi
blobcd1c79e42e6a9bd04d5f00911530c0f21b5834ab
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename sepia.info
4 @settitle Simple Emacs Perl Integration
5 @dircategory Emacs
6 @direntry
7 * Sepia: (sepia).    Simple Emacs Perl Integration.
8 @end direntry
9 @c %**end of header
11 @titlepage
12 @title Sepia: Simple Emacs Perl Integration
13 @author Sean O'Rourke
14 @end titlepage
16 @macro kbinding{key,cmd}
17 @item \key\ `\cmd\'
18 @kindex \key\
19 @end macro
21 @macro fitem{name}
22 @item \name\
23 @findex \name\
24 @end macro
26 @macro xxx{stuff}
27 @b{XXX: \stuff\}
28 @end macro
30 @node Top, Introduction, (dir), (dir)
32 @ifinfo
33 @top SEPIA
34 @end ifinfo
36 Sepia is a set of Perl development tools for Emacs supporting code
37 navigation and interactive evaluation.
39 @menu
40 * Introduction::                
41 * Editing::                     
42 * Interactive Perl::            
43 * Customization::               
44 * Internals::                   
45 * Credits::                     
46 * Function Index::              
47 @end menu
49 @c ============================================================
50 @node Introduction, Editing, Top, Top
51 @chapter Introduction
53 Sepia is a set of tools for Perl development in Emacs.  Its goal is to
54 extend CPerl mode with two contributions: fast code navigation and
55 interactive development.  It is inspired by Emacs' current support for a
56 number of other languages, including Lisp, Python, and Emacs Lisp.
58 @menu
59 * Getting Started::             
60 * Philosophy::                  
61 @end menu
63 @node Getting Started, Philosophy, Introduction, Introduction
64 @section Getting Started
66 To install Sepia, its Emacs Lisp files must be in Emacs'
67 @code{load-path}, and the @file{lib} directory must be in Perl's
68 @code{@@INC}.  Assuming that Sepia has been unpacked in
69 @file{~/sepia}, it can be installed by adding the following lines to
70 @file{~/.emacs}:
72 @example
73 (add-to-list 'load-path "~/sepia")
74 (setq sepia-perl5lib (expand-file-name "~/sepia/lib"))
75 (defalias 'perl-mode 'sepia-mode)
76 @end example
78 Then to bring up the interactive Perl prompt, type @kbd{M-x sepia-repl}.
80 @node Philosophy,  , Getting Started, Introduction
81 @section Philosophy
83 @xxx{There's a bit at the top of the README.  Expand on it.}
85 @c ============================================================
86 @node Editing, Interactive Perl, Introduction, Top
87 @chapter Editing
89 Sepia's first contribution is a set of commands to explore a Perl
90 codebase.  These include commands to browse and display documentation,
91 to find function definitions, and to query a cross-reference database of
92 function and variable uses.  Sepia also provides intelligent symbol
93 completion.
95 @menu
96 * Navigation::                  
97 * Documentation::               
98 * Evaluation::                  
99 * Completion::                  
100 * Mutilation::                  
101 @end menu
103 @node Navigation, Documentation, Editing, Editing
104 @section Navigation
106 Sepia provides several commands for navigating program source.  All of
107 them rely on information from the inferior Perl process, so it is
108 important both that it be running, and that its internal representation
109 of the program matches the program on disk.  The commands marked (Xref)
110 below also rely on a cross-reference database, which must be explicitly
111 rebuilt by calling @code{xref-rebuild} when the program changes.
113 There are two basic kinds of navigation commands.  The first kind jump
114 directly to the first matching location when possible, prompting only if
115 no such location is found.  These commands find only a single location,
116 and do not put their results on the found-location ring.
118 @c direct-jump commands
119 @table @kbd
121 @item M-. M-.
122 @itemx M-x sepia-dwim
123 @findex sepia-dwim
124 Guess what kind of identifier is at point, and try to do the right
125 thing: for a function, find its definition(s); for a variable, find its
126 uses; for a module, view its documentation; otherwise, prompt for the
127 name of a function to visit.  @code{sepia-dwim} automatically goes to
128 the first function definition or variable use found.
130 @item M-. l
131 @itemx M-x sepia-location
132 @findex sepia-location
133 Jump directly to the definition of the function at point, prompting if
134 point is not on a symbol.  If multiple definitions are found, choose one
135 arbitrarily.  This function is similar to @code{sepia-defs}, and the two
136 should probably be merged.
138 @item M-. j
139 @itemx M-x sepia-jump-to-symbol
140 @findex sepia-jump-to-symbol
141 Navigate to a function using ``ido'' interactive completion.  Within
142 interactive completion, press @key{:} to descend into a package,
143 @key{DEL} to ascend to a parent package, and @key{RET} to go to the
144 currently-selected function.
146 @end table
148 The second kind of navigation commands always prompt the user -- though
149 usually with a sensible default value -- and find multiple locations.
150 When called with a prefix argument, these commands present their results
151 in a @code{grep-mode} buffer.  When called @emph{without} a prefix
152 argument, these commands place all results on the found-location ring
153 and jump directly to the first.  The remaining locations can be cycled
154 through by calls to @code{sepia-next}.
156 @c prompt-and-go commands
157 @table @kbd
158 @item M-. f @var{name} @key{RET}
159 @itemx M-x sepia-defs
160 @findex sepia-defs
161 Find definition(s) of function @var{name}.
163 @item M-. m
164 @itemx M-x sepia-module-find @var{name} @key{RET}
165 @findex sepia-module-find
166 Find the source of module @var{name}.
168 @item M-. a @var{regexp} @key{RET}
169 @itemx M-x sepia-apropos
170 @findex sepia-apropos
171 Find definitions of all functions whose names match @var{regexp}.
173 @item M-. c @var{name} @key{RET}
174 @itemx M-x sepia-callers
175 @findex sepia-callers
176 (Xref) Find calls to function @var{name}.
178 @item M-. C @var{name} @key{RET}
179 @itemx M-x sepia-callees
180 @findex sepia-callees
181 (Xref) Find the definitions of functions called by @var{name}.
183 @item M-. v @var{name} @key{RET}
184 @itemx M-x sepia-var-uses
185 @findex sepia-var-uses
186 (Xref) Find uses of the global variable @var{name}.
188 @item M-. V @var{name} @key{RET}
189 @itemx M-x sepia-var-defs
190 @findex sepia-var-defs
191 (Xref) Find definitions of global variable @var{name}.  Since Perl's
192 global variables are not declared, this is rarely useful
194 @c XXX: broken, so don't mention it.
195 @c @item M-. A @var{regexp} @key{RET}
196 @c @itemx M-x sepia-var-apropos
197 @c @findex sepia-var-apropos
198 @c Find definitions of all variables whose names match @var{regexp}.  Since
199 @c this function does not handle lexical variables, and since Perl's global
200 @c variables are not declared, this is rarely useful.
202 @end table
204 Finally, there are several other navigation-related commands that do not
205 fit into either of the above categories.
207 @c other commands
208 @table @kbd
209 @item M-. n
210 @itemx M-x sepia-next
211 @findex sepia-next
212 Cycle through the definitions found by the previous @key{M-.} search.
214 @item M-. r
215 @itemx M-x sepia-rebuild
216 @findex sepia-rebuild
217 Rebuild the cross-reference database by walking the op-tree and
218 stashes.
220 @item M-. t
221 @itemx M-x find-tag
222 Execute the @code{find-tag} command typically bound to @key{M-.}.
224 @end table
226 @node Documentation, Evaluation, Navigation, Editing
227 @section Documentation
229 Sepia can be used to browse installed modules' documentation, to format
230 and display the current buffer's POD, and to browse the list of modules
231 installed on the system.
233 @table @kbd
234 @item M-. d @var{name} @key{RET}
235 @itemx M-x sepia-perldoc-this
236 @findex sepia-perldoc-this
237 View documentation for module @var{name} or Perl manpage @var{name}.
239 @item C-c C-d
240 @itemx M-x sepia-view-pod
241 @findex sepia-view-pod
242 Format and view the current buffer's documentation.
244 @item sepia-package-list
245 @findex sepia-package-list
246 Browse a tree of installed packages.  This lists only the top-level
247 packages from installed distributions, so if package @code{My::Stuff}
248 also provides @code{My::Stuff::Details}, it will not be displayed.  When
249 Emacs-w3m is available, each module is linked to its documentation.
251 @item sepia-module-list
252 @findex sepia-module-list
253 Browse a tree of both top-level and internal packages, like
254 @code{sepia-package-list}.
256 @end table
258 @findex sepia-install-eldoc
259 Sepia also integrates with Eldoc (at least in GNU Emacs >= 22).  To
260 toggle eldoc support, type @kbd{M-x sepia-install-eldoc}.  Documentation
261 for Perl builtins and control structures is taken from CPerl mode.
262 Sepia can also display documentation for user-defined functions if their
263 POD is formatted in the standard way, with functions described in a
264 ``=head2'' or ``=item'' entry.  To load user documentation, visit the
265 relevant file and type @kbd{M-x sepia-doc-update}.
267 If @code{Module::CoreList} is available Sepia's eldoc function will also
268 display the first version of Perl in which a module was shipped by
269 default.  This is intended to give the programmer a sense of when he is
270 creating external dependencies.
272 @c ============================================================
273 @node Interactive Perl, Customization, Editing, Top
274 @chapter Interactive Perl
276 Sepia's second main contribution is an interactive interface (REPL) to
277 an inferior Perl process in comint mode.  The interface is based on
278 comint-mode, and inherits many of its bindings; this chapter discusses
279 only the Sepia extensions.  In addition to the standard interactive
280 REPL, Sepia provides a number of other ways to evaluate pieces of code
281 in Perl, and commands to process buffer regions with Perl.
283 @findex sepia-repl
284 To start or switch to the repl, type @kbd{M-x sepia-repl}.  As in Perl
285 code, @key{TAB} in the REPL performs partial-word completion with
286 @code{sepia-complete-symbol}.  However, it also supports filename
287 completion like standard comint mode.
289 @menu
290 * Shortcuts::                   
291 * The Debugger::                
292 * Scratchpad::                  
293 @end menu
295 @node Shortcuts, The Debugger, Interactive Perl, Interactive Perl
296 @section Shortcuts
298 ``Shortcuts'' are commands handled specially by the REPL rather than
299 being evaluated as perl code.  They either communicate with the REPL
300 function, or provide a convenient interface to variables in the Sepia
301 package.  Shortcuts are prefixed by a comma (@key{,}), and may be
302 abbreviated to the shortest unique prefix.
304 @table @kbd
305 @item cd @var{dir}
306 Change perl's current directory to @var{dir}.
308 @item format @var{type}
309 Set the output format to @var{type}, either ``dumper'' (using
310 @code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
311 (@code{YAML}), or ``plain'' (stringification).  Default: ``dumper''.
313 @item help
314 Display a list of shortcuts.
316 @item methods @var{name} [@var{regexp}]
317 Display a list of functions defined in package @var{name} and its
318 @code{ISA}-ancestors matching optional pattern @var{regexp}.
320 @item package @var{name}
321 Set the default evaluation package to @var{name}.
323 @item quit
324 Exit the inferior Perl process.
326 @item reload
327 Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
328 mostly of interest when working on Sepia itself.
330 @item strict [@var{val}]
331 Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
332 given.  Note that turning strictness off and on clears the REPL's
333 lexical environment.
335 @item wantarray [@var{val}]
336 Set the evaluation context to @var{val}, or toggle between scalar and
337 array context.
339 @item who [@var{name} [@var{regexp}]]
340 List identifiers in package @var{name} (main by default) matching
341 optional pattern @var{regexp}.
343 @end table
345 @node The Debugger, Scratchpad, Shortcuts, Interactive Perl
346 @section Debugger
348 Unfortunately Sepia does @emph{not} use Perl's debugger hooks, so it
349 does not support a true debugger with breakpoints, single-stepping, etc.
350 However, the REPL overrides the @code{die()} and @code{warn()}
351 operators, allowing it to intercept failures while their context is
352 still available.  This makes it possible to produce a backtrace, inspect
353 and modify global variables, and continue execution.  If the PadWalker
354 module is available, Sepia also provides functions to inspect and modify
355 lexical variables.
357 The debugger has its own set of shortcuts, also prefixed by a comma.
359 @table @kbd
360 @item backtrace
361 Show a backtrace with @code{Carp::cluck}.
363 @item inspect @var{n}
364 Inspect lexicals in frame @var{n}, counting upward (requires PadWalker).
366 @item eval @var{n} @var{expr}
367 Evaluate @var{expr} in the lexical environment of frame @var{n}
368 (requires PadWalker).  @var{expr} should not transfer control out of
369 this environment, but is free to modify its lexicals.
371 @item return @var{expr}
372 Continue execution as if @code{die()} or @code{warn()} had returned the
373 value of @var{expr}, which is evaluated in the global environment.
375 @item die
376 @itemx warn
377 Continue dying or warning as the program would have done without
378 debugger intervention.
380 @end table
382 @node Evaluation, Completion, Documentation, Editing
383 @section Evaluation
385 When interactive Perl is running, Sepia can evaluate regions of code in
386 the inferior Perl process.  The following commands assume that this
387 process has already been started by calling @code{sepia-repl}.
389 @table @kbd
390 @item C-M-x
391 @itemx M-x sepia-eval-defun
392 @findex sepia-eval-defun
393 Evaluate the function around point in the inferior Perl process.
395 @item C-c C-l
396 @itemx M-x sepia-load-file
397 @findex sepia-load-file
398 Save the current buffer, then reload its file and if warnings or errors
399 occur, display an error buffer.  With a prefix argument, also rebuild
400 the cross-reference index.
402 @item C-c e
403 @itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
404 @findex sepia-eval-expression
405 Evaluate @var{expr} in scalar context and echo the result.  With a
406 prefix argument, evaluate in list context.
408 @end table
410 @node Completion, Mutilation, Evaluation, Editing
411 @section Completion
413 Sepia implements fairly sophisticated partial-word completion in
414 collaboration with the inferior Perl process.  For example,
415 @samp{%S:X:v_u} completes to @samp{%Sepia::Xref::var_use} when Sepia is
416 loaded.
418 @xxx{explain the rules for completion: packages, vars, subs, methods, ...}
420 @table @kbd
421 @item M-x sepia-complete-symbol
422 @findex sepia-complete-symbol
423 Complete the symbol before point as either a module, function, or global
424 variable.  Note that this does @emph{not} consider lexical scope.
426 @item TAB
427 @itemx M-x sepia-indent-or-complete
428 @findex sepia-indent-or-complete
429 First try to indent the current line.  If the indentation does not
430 change, then try to expand an abbrev at point (unless
431 @code{sepia-indent-expand-abbrev} is @code{NIL}).  If no abbrev is
432 expanded, then call @code{sepia-complete-symbol}.
434 @end table
436 @node Mutilation,  , Completion, Editing
437 @section Mutilation
439 Sepia contains several functions to operate on regions of text using the
440 interactive Perl process.  These functions can be used like standard
441 one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
442 the functions and variables in the interactive session are available.
444 @table @kbd
445 @item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
446 @findex sepia-perl-pe-region
447 Evaluate @var{code} on each line in the region with @code{$_} bound to
448 the line text, collecting the resulting values of @code{$_}.  With a
449 prefix argument, replace the region with the result.
451 @item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
452 @findex sepia-perl-ne-region
453 Evaluate @var{code} as above, but collect the @emph{results} of code.
455 @item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
456 @findex sepia-perlize-region
457 Evaluate @var{code} once with @code{$_} bound to the entire region,
458 collecting the final value of @code{$_}.  With a prefix argument,
459 replace the region.
461 @end table
463 @node Scratchpad,  , The Debugger, Interactive Perl
464 @section Scratchpad
466 @findex sepia-scratch
467 Sepia also supports a scratchpad, another form of interaction inspired
468 by Emacs' @code{*scratch*} buffer.  To create or switch to the
469 scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
470 like Sepia mode, except @key{C-j} evaluates the current line and prints
471 the result on the next line.
473 @c ============================================================
474 @node Customization, Internals, Interactive Perl, Top
475 @chapter Customization
477 While Sepia can be customized in both the Perl and Emacs Lisp, most of
478 the user-accessible configuration is in the latter.  The two variables
479 most likely to need customization are @kbd{sepia-program-name} and
480 @kbd{sepia-perl5lib}.  Since Sepia tries where possible to reuse
481 existing Emacs functionality, its behavior should already be covered by
482 existing customizations.
484 @menu
485 * Emacs Variables::             
486 * Perl Variables::              
487 @end menu
489 @node Emacs Variables, Perl Variables, Customization, Customization
490 @section Emacs Variables
492 @table @kbd
494 @item sepia-complete-methods
495 If non-@code{NIL}, @code{sepia-complete-symbol} will complete
496 simple method calls of the form @code{$x->} or @code{Module->}.  Since
497 the former requires evaluation of @code{$x}, this can be disabled.
498 Default: @code{T}.
500 @item sepia-eval-defun-include-decls
501 If non-@code{NIL}, attempt to generate a declaration list for
502 @code{sepia-eval-defun}.  This is necessary when evaluating some code,
503 such as that calling functions without paretheses, because the presence
504 of declarations affects the parsing of barewords.  Default: @code{T}.
506 @item sepia-indent-expand-abbrev
507 If non-@code{NIL}, @code{sepia-indent-or-complete} will, if
508 reindentation does not change the current line, expand an abbreviation
509 before point rather than performing completion.  Only if no abbreviation
510 is found will it perform completion.  Default: @code{T}.
512 @item sepia-module-list-function
513 The function to view a tree of installed modules.  Default:
514 @code{w3m-find-file} if Emacs-w3m is installed, or
515 @code{browse-url-of-buffer} otherwise.
517 @item sepia-perldoc-function
518 The function called to view installed modules' documentation.  Default:
519 @code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
520 otherwise.
522 @item sepia-perl5lib
523 A list of directories to include in @code{PERL5LIB} when starting
524 interactive Perl.  Default: @code{NIL}.
526 @item sepia-prefix-key
527 The prefix to use for for functions in @code{sepia-keymap}.  Default:
528 @key{M-.}.
530 @item sepia-program-name
531 The Perl program name for interactive Perl.  Default: ``perl''.
533 @item sepia-use-completion
534 If non-@code{NIL}, various Sepia functions will generate completion
535 candidates from interactive Perl when called interactively.  This may be
536 slow or undesirable in some situations.  Default: @code{T}.
538 @item sepia-view-pod-function
539 The function called to view the current buffer's documentation.
540 Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
541 @code{sepia-perldoc-buffer} otherwise.
543 @end table
545 @node Perl Variables,  , Emacs Variables, Customization
546 @section Perl Variables
548 The following variables in the Sepia package control various aspects of
549 interactive evaluation.
551 @table @code
553 @item $PACKAGE
554 The package in which user input is evaluated, determined automatically
555 when code is evaluated from a buffer.  Default: @code{main}.
557 @item $PRINTER
558 The function called to format interactive output, normally set with the
559 @code{printer} shortcut.
561 @item $PRINT_PRETTY
562 If true, format some values nicely independent of the value of
563 @code{$PRINTER}.  Currently, this means columnating lists of simple
564 scalars.  Default: true.
566 @item $PS1
567 The trailing end of the prompt string, which should end with ``> ''.
568 Default: @code{"> "}.
570 @item $STOPDIE
571 If true, calls to @code{die} from interactive code will invoke the Sepia
572 debugger.  Default: true.
574 @item $STOPWARN
575 If true, calls to @code{warn} from interactive code will invoke the
576 Sepia debugger.  Default: false.
578 @item $WANTARRAY
579 If true, evaluate interactive expressions in list context.  Default: true.
581 @end table
583 @c ============================================================
584 @node Internals, Credits, Customization, Top
585 @chapter Internals
587 @xxx{Many things remain unexplained except by the code itself, and some
588 details mentioned above should probably be given less prominence.}
590 @node Credits, Function Index, Internals, Top
591 @unnumbered Credits
593 I would like to thank Hilko Bengen for finding and motivating me to fix
594 a bunch of bugs, and for doing the Debian packaging.
596 I would also like to thank the authors of Emacs-w3m, SLIME, ido, and
597 B::Xref for the code I stole.
599 @c ============================================================
600 @node Function Index,  , Credits, Top
601 @unnumbered Function Index
602 @printindex fn
604 @bye