\input texinfo   @c -*-texinfo-*-
@c %**start of header
@setfilename sepia.info
@settitle SEPIA: Simple Emacs Perl Integration
@dircategory Emacs
@direntry
* Sepia: (sepia).    Simple Emacs Perl Integration.
@end direntry
@copying
Copyright @copyright{} 2005-2010 Sean O'Rourke.  All rights reserved,
some wrongs reversed.  This module is distributed under the same terms
as Perl.
@end copying
@c %**end of header

@titlepage
@title Sepia: Simple Emacs Perl Integration
@author Sean O'Rourke
@end titlepage

@macro kbinding{key,cmd}
@item \key\ `\cmd\'
@kindex \key\
@end macro

@macro fitem{name}
@item \name\
@findex \name\
@end macro

@macro xxx{stuff}
@b{XXX: \stuff\}
@end macro

@node Top, Introduction, (dir), (dir)

@ifinfo
@top SEPIA
@end ifinfo

@ifhtml
@image{Sepia,,,,jpg}
@end ifhtml

Sepia is a set of Perl development tools for Emacs supporting code
navigation and interactive evaluation.

@menu
* Introduction::
* Editing::
* Interactive Perl::
* CPAN browsing::
* Customization::
* Internals::
* FAQ::
* Credits::                     
* Function Index::
* Variable Index::
@end menu

@c ============================================================
@node Introduction, Editing, Top, Top
@chapter Introduction

Sepia is a set of tools for Perl development in Emacs.  Its goal is to
extend CPerl mode to support fast code navigation and interactive
development.  It is inspired by Emacs' current support for a number of
other languages, including Lisp, Python, and Emacs Lisp.

@menu
* Getting Started::             
* Philosophy::                  
* Related Work::                
@end menu

@node Getting Started, Philosophy, Introduction, Introduction
@section Getting Started

To install Sepia, its Emacs Lisp files must be in Emacs'
@code{load-path}, and the @file{lib} directory must be in Perl's
@code{@@INC}.  Assuming that Sepia has been unpacked in
@file{~/sepia}, it can be installed by adding the following lines to
@file{~/.emacs}:

@example
(add-to-list 'load-path "~/sepia")
(setq sepia-perl5lib (list (expand-file-name "~/sepia/lib")))
(defalias 'perl-mode 'sepia-mode)
(require 'sepia)
@end example

Then to bring up the interactive Perl prompt, type @kbd{M-x sepia-repl}.

@node Philosophy, Related Work, Getting Started, Introduction
@section Philosophy

A development environment should support three activities: code
spelunking, interaction, and customization.  Emacs as an environment for
developing Emacs Lisp thoroughly supports all of them: It has commands
to visit individual functions' code and documentation, commands to
evaluate or step through expressions, and an architecture that
encourages customization in Emacs Lisp.  As an environment for Perl,
however, it is lacking: there is limited interactivity with the Perl
debugger, and reasonable documentation browsing, but no support for
navigating, editing, and re-evaluating code.  Sepia attempts to remedy
the situation.

Modern IDEs also support these three activities, but do so awkwardly.
Rather than having functions to visit definitions (@kbd{find-function})
and search for functions (@kbd{apropos}), they clutter the screen with
class and file trees.  Rather than supporting interactive evaluation of
small pieces of code, they perform background semantic checking on whole
projects and highlight errors.  Rather than allowing minor
customizations to grow organically into features, they support limited
configuration files and baroque plug-in APIs@footnote{In my brief
experience with Visual Studio, I was struck by the fact that I saw
several toolbars, a couple of navigation windows, and a tiny view of the
actual code.  Sometimes a tooltip would obscure part of that tiny
window.}.  Sepia tries to adhere to the apparent Emacs philosophy that
rich semantic information should be unobtrusive, and that the best way
to build working code is to start by experimenting with small pieces.

Language support packages for Emacs vary widely in the degree to which
they make use of or replace existing Emacs features.  Minimal modes
provide keyword-based syntax highlighting and an unadorned comint buffer
as an interpreter.  Others provide their own specialized equivalents of
comint, eldoc, completion, and other Emacs features.  Sepia takes a
third approach by trying to do as much as possible with existing Emacs
features, even when they are not optimal for Perl.  For example, it uses
comint to communicate with the subprocess, eldoc to display
documentation, and grep to list source locations.

This approach has three advantages: First, it maximizes the number of
features that can be supported with limited development time.  Second,
it respects users' settings.  A seasoned Emacs user may have changed
hundreds of settings, so a mode that reimplements features will have to
support equivalent settings, and will force the user to re-specify them.
Finally, this approach respects decades of development spent, as Neal
Stephenson put it, ``focused with maniacal intensity on the deceptively
simple-seeming problem of editing text.''  Many non-obvious choices go
into making a polished interface, and while a reimplementation gets rid
of accumulated cruft, it must rediscover these hidden trade-offs.

Anyways, I hope you enjoy using Sepia.  Its development style is strange
for someone used Perl's typical mix of one-liners and edit-save-run, but
once you are accustomed to it, you may find it very effective.

@node Related Work,  , Philosophy, Introduction
@comment  node-name,  next,  previous,  up
@section Related Work

A number of more-or-less related Emacs extensions are currently under
development.  Here is a list of the ones I have heard about, along with
my brief impression of how they differ from Sepia.  Since I use none of
them regularly, these impressions should be taken with a grain of salt.

@table @cite

@item Emacs::PDE

PDE is similar to Sepia in offering an interactive Lisp-like development
environment interfacing with a long-running Perl process.  It seems more
ambitious, and therefore a bit more invasive.

@url{http://search.cpan.org/dist/Emacs-PDE/}

@item Devel::PerlySense

Devel::PerlySense offers a more Eclipse-like development environment,
with offline code analysis via @acronym{PPI}.

@url{http://search.cpan.org/dist/Devel-PerlySense/}

@item Emacs::EPL

Emacs::EPL is a low-level IPC interface between Emacs and Perl.  Sepia
was originally based on Emacs::EPL, but the current
@command{comint}-based implementation proved more maintainable.

@url{http://search.cpan.org/dist/Emacs-EPL/}

@item Stylish

Stylish is a similar effort with a very different implementation
philosophy, requiring maximal rather than minimal dependencies in both
Perl and Emacs, and reimplementing @command{comint} in Emacs.

@url{http://github.com/jrockway/stylish.git}

@end table

@c ============================================================
@node Editing, Interactive Perl, Introduction, Top
@chapter Editing
@findex sepia-mode

Sepia's first contribution is a set of commands to explore a Perl
codebase.  These include commands to browse and display documentation,
to find function definitions, and to query a cross-reference database of
function and variable uses.  Sepia also provides intelligent symbol
completion.

@menu
* Completion::                  
* Navigation::                  
* Documentation::               
* Other commands::              
@end menu

@node Completion, Navigation, Editing, Editing
@section Completion

Sepia implements partial-word completion that communicates with the
inferior Perl process.  For example, @samp{%S:X:v_u} completes to
@samp{%Sepia::Xref::var_use} when Sepia is loaded.  This completion only
operates on functions and global variables known to the Perl
interpreter, so it works best when code and interpreter are in sync.

More precisely, completion examines the text before point and tries each
of the following in turn, using the first successful approach:

@enumerate
@item
If the text looks like a method call (e.g. @samp{$object->f} or
@samp{Class->f}), complete on methods.

@item
If it looks like a variable (e.g. @samp{%hash} or @samp{$scalar}),
complete first on lexical, then global variables.

@item
Complete on modules and functions.

@item
Otherwise, complete on Perl built-in operators.
@end enumerate

For each of the first three cases, completions candidates are first
generated by splitting the text on characters @code{[:_]} and matching
the resulting word parts.  For example, @samp{X:a_b} will complete to
all symbols matching @samp{^X[^:]*:+a[^:_]*_b} such as
@samp{Xref::a_bug} and @samp{X::always_bites_me}.  If the module parts
of the input match a module exactly and completions exist, they are not
expanded.  For example, @samp{X:a} will expand only to @samp{X::aa} when
@samp{X::aa} and @samp{Xx::aa} exist.  If no matches result, the text is
treated as an acronym.  For example, @samp{dry} will complete to
@samp{dont_repeat_yourself}.  @emph{Note: partial-word completion is not
currently supported for lexicals.}

Completion is performed by the following commands:
@table @kbd
@item M-x sepia-complete-symbol
@findex sepia-complete-symbol
Complete the symbol before point as described above.  This is always
case-sensitive, independent of @code{completion-ignore-case}.

@item TAB
@itemx M-x sepia-indent-or-complete
@findex sepia-indent-or-complete
First try to reindent the current line.  If its indentation does not
change, then try to expand an abbrev at point (unless
@code{sepia-indent-expand-abbrev} is @code{nil}).  If no abbrev is
expanded, then call @code{sepia-complete-symbol}.

@end table

@node Navigation, Documentation, Completion, Editing
@section Navigation

Sepia provides several commands for navigating program source.  All of
them rely on information from the inferior Perl process, so it is
important both that it be running, and that its internal representation
of the program match the program source.  The commands marked (Xref)
below also rely on a cross-reference database, which must be explicitly
rebuilt by calling @code{xref-rebuild} when the program changes.

There are two basic kinds of navigation commands.  The first kind jumps
directly to the first matching location when possible, prompting only if
no such location is found.  These commands find only a single location.

@c direct-jump commands
@table @kbd

@item M-. M-.
@itemx M-x sepia-dwim
@findex sepia-dwim
Guess what kind of identifier is at point, and try to do the right
thing: for a function, find its definition(s); for a variable, find its
uses; for a module, view its documentation; otherwise, prompt for the
name of a function to visit.  @code{sepia-dwim} automatically goes to
the first function definition or variable use found.

@item M-. d
@itemx M-x sepia-location
@findex sepia-location
Jump directly to the definition of the function at point, prompting if
point is not on a known function.  If multiple definitions are found,
choose one arbitrarily.  This function is similar to @code{sepia-defs},
and the two should probably be merged.

@item M-. j
@itemx M-x sepia-jump-to-symbol
@findex sepia-jump-to-symbol
Navigate to a function using ``ido'' interactive completion.  Within
interactive completion, press @key{:} to descend into a package,
@key{DEL} to ascend to a parent package, and @key{RET} to go to the
currently-selected function.

@item M-. l
@itemx M-x sepia-pod-follow-link-at-point
@findex sepia-pod-follow-link-at-point
Follow the POD link (@code{L<...>}) at point, or prompt for a link if
there is none.  Go to the appropriate location in the document source
or, with a prefix argument, in the rendered documentation.  This can be
especially useful when writing links in your own documentation.

@end table

The second kind of navigation commands always prompts the user -- though
usually with a sensible default value -- and finds multiple locations.
When called with a prefix argument, these commands present their results
in a @code{grep-mode} buffer.  When called @emph{without} a prefix
argument, they place all results on the found-location ring and jump
directly to the first.  The remaining locations can be cycled through by
calls to @code{sepia-next}.

@c prompt-and-go commands
@table @kbd
@item M-. f @var{name} @key{RET}
@itemx M-x sepia-defs
@findex sepia-defs
Find definition(s) of function @var{name}.

@item M-. m @var{name} @key{RET}
@itemx M-x sepia-module-find @var{name} @key{RET}
@findex sepia-module-find
Find the source of module @var{name}.

@item M-. a @var{regexp} @key{RET}
@itemx M-x sepia-apropos @var{regexp} @key{RET}
@findex sepia-apropos
Find definitions of all functions whose names match @var{regexp}.

@item M-x sepia-apropos-module @var{regexp} @key{RET}
@findex sepia-apropos-module
Find all installed modules matching @var{regexp}.  This function may be
slow the first time it is called, because it has to build a list of
installed modules.

@item M-. c @var{name} @key{RET}
@itemx M-x sepia-callers @var{name} @key{RET}
@findex sepia-callers
(Xref) Find calls to function @var{name}.

@item M-. C @var{name} @key{RET}
@itemx M-x sepia-callees @var{name} @key{RET}
@findex sepia-callees
(Xref) Find the definitions of functions called by @var{name}.

@item M-. v @var{name} @key{RET}
@itemx M-x sepia-var-uses @var{name} @key{RET}
@findex sepia-var-uses
(Xref) Find uses of the global variable @var{name}.

@item M-. V @var{name} @key{RET}
@itemx M-x sepia-var-defs @var{name} @key{RET}
@findex sepia-var-defs
(Xref) Find definitions of global variable @var{name}.  Since Perl's
global variables are not declared, this is rarely useful

@c XXX: broken, so don't mention it.
@c @item M-. A @var{regexp} @key{RET}
@c @itemx M-x sepia-var-apropos
@c @findex sepia-var-apropos
@c Find definitions of all variables whose names match @var{regexp}.  Since
@c this function does not handle lexical variables, and since Perl's global
@c variables are not declared, this is rarely useful.

@end table

Finally, there are several other navigation-related commands that do not
fit into either of the above categories.

@c other commands
@table @kbd
@item M-,
@itemx M-x sepia-next
@findex sepia-next
Cycle through the definitions found by the previous @key{M-.} search.

@item M-. r
@itemx M-x sepia-rebuild
@findex sepia-rebuild
Rebuild the cross-reference database by walking the op-tree and
stashes.

@item M-. t
@itemx M-x find-tag
Execute the @code{find-tag} command typically bound to @key{M-.}.

@end table

@node Documentation, Other commands, Navigation, Editing
@section Documentation

Sepia can be used to browse installed modules' documentation, to format
and display the current buffer's POD, and to browse the list of modules
installed on the system.

@table @kbd
@item M-. p @var{name} @key{RET}
@itemx M-x sepia-perldoc-this
@findex sepia-perldoc-this
View documentation for module @var{name} or Perl manual page @var{name}.

@item C-c C-d
@itemx M-x sepia-view-pod
@findex sepia-view-pod
Format and view the current buffer's documentation.

@item sepia-package-list
@findex sepia-package-list
Browse a tree of installed packages.  This lists only the top-level
packages from installed distributions, so if package @code{My::Stuff}
also provides @code{My::Stuff::Details}, it will not be displayed.  When
Emacs-w3m is available, each module is linked to its documentation.

@item sepia-module-list
@findex sepia-module-list
Browse a tree of both top-level and internal packages, like
@code{sepia-package-list}.

@end table

@findex sepia-install-eldoc
Sepia also integrates with eldoc (at least in GNU Emacs >= 22).
Documentation for Perl operators and control structures is taken from
CPerl mode.  Sepia will also display documentation for user-defined
functions if their POD is formatted in the standard way, with functions
described in a ``=head2'' or ``=item'' entry.  To load user
documentation, visit the relevant file and type @kbd{M-x
sepia-doc-update}.

If @code{Module::CoreList} is available, Sepia's eldoc function will
also display the first version of Perl with which a module was shipped.
This is intended to give the programmer a sense of when he is creating
external dependencies.

@node Other commands,  , Documentation, Editing
@section Other commands

@table @kbd
@item M-x sepia-rename-lexical
@findex sepia-rename-lexical
Rename a variable in the function at point, querying for each
replacement when called with a prefix argument.  Currently, this is only
a thin wrapper around @code{query-replace}.
@end table


@c ============================================================
@node Interactive Perl, CPAN browsing, Editing, Top
@chapter Interactive Perl

@findex sepia-repl
Sepia's second main contribution is an interactive interface (REPL) to
an inferior Perl process.  The interface is based on GUD mode, and
inherits many of its bindings; this chapter discusses only the Sepia
extensions.  To start or switch to the repl, type @kbd{M-x sepia-repl}.
As in Sepia mode, @key{TAB} in the REPL performs partial-word completion
with @code{sepia-complete-symbol}.

@c == REPL behavior ==
@c - $_/@_
@c - RET & eval/newline
@c - eval context

Sepia also provides a number of other ways to evaluate pieces of code in
Perl, and commands to process buffer text using the inferior process.

Finally, Sepia comes with the @kbd{sepl} program, a standalone REPL that
can be run from the command-line, and provides many features of the
Emacs-based REPL.

@menu
* Shortcuts::                   
* Debugger::                    
* Evaluation::                  
* Mutilation::                  
* Scratchpad::                  
@end menu

@node Shortcuts, Debugger, Interactive Perl, Interactive Perl
@section Shortcuts

``Shortcuts'' are commands handled specially by the REPL rather than
being evaluated as Perl code.  They either communicate with the REPL
function, or provide a convenient interface to Sepia variables and
functions.  Shortcuts are prefixed by a comma (@key{,}), and may be
abbreviated to the shortest unique prefix.  The debugger defines
additional shortcuts (@xref{Debugger}.).

@table @kbd
@item break @var{file}:@var{line} [@var{expr}]
Set a breakpoint in @var{file} at @var{line}.  If @var{expr} is
supplied, stop only if it evaluates to true.

@item cd @var{dir}
Change Perl's current directory to @var{dir}.

@item debug [@var{val}]
Turn Sepia debugger hook on or off, or toggle if @var{val} is missing.

@item define @var{name} ['@var{doc}'] @var{body...}
Define @var{name} as a shortcut for Perl code @var{body}, with optional
documentation @var{doc}, surrounded by single quotes.  @var{body} is
passed the raw command-line text as its first argument.

@item format @var{type}
Set the output format to @var{type}, either ``dumper'' (using
@code{Data::Dumper}), ``dump'' (@code{Data::Dump}), ``yaml''
(@code{YAML}), ``peek'' (@code{Devel::Peek}), ``dumpvar''
(@code{dumpvar.pl}, somewhat rough), or ``plain'' (stringification).
Default: ``dumper''.

Note that this setting is independent of @code{$COLUMNATE} and
@code{$STRINGIFY}.

@item help
Display a list of shortcuts.

@item load [@var{file}]
Reload saved variables from @var{file} (or @file{~/.sepia-save}),
created by @kbd{save}.

@item lsbreak
List breakpoints.

@item lsmod [@var{pattern}]
List currently-loaded modules matching optional @var{pattern}.

@item methods @var{name} [@var{regexp}]
Display a list of functions defined in package @var{name} and its
@code{ISA}-ancestors matching optional pattern @var{regexp}.

@item package @var{name}
Set the default evaluation package to @var{name}.

@item pwd
Show the process's current working directory.

@item quit
Exit the inferior Perl process.

@item reload [@var{module} | @var{/pattern/}]
Reload @var{module} (but not its dependencies), or all modules matching
@var{pattern}.

@item freload @var{module}
Reload @var{module} and all of its dependencies.

@item restart
Reload @file{Sepia.pm} and recursively invoke the REPL.  This command is
mostly of interest when working on Sepia itself, and will fail
catastrophically if @file{Sepia.pm} fails to compile.

@item save [@var{pattern} [@var{file}]]
Save variables matching @var{pattern} (or all variables) to @var{file}
(or @file{~/.sepia-save}) in @code{Storable} format.  Note that because
saving magic variables can have unpredictable results, using @kbd{save}
without a pattern argument is risky.  Sepia excludes common magic
variables and dangerous packages, but its list is not foolproof.

@item shell [@var{command}]
Execute shell command @var{command}, displaying its standard output and
standard error.

@item size @var{package} [@var{regexp}]
@item size [@var{regexp}]
List the variables in @var{package} (or the current package) along with
their total sizes.  This requires the @code{Devel::Size} module.  In
strict mode, list lexical variables if no @var{package} is given.

@item strict [@var{val}]
Set evaluation strictness to @var{val}, or toggle it if @var{val} is not
given.  Note that turning strictness off and on clears the REPL's
lexical environment.

@item test [@var{file}]
Run tests in the current directory.  If @var{file} is given, only run
test @var{file} or @file{t/@var{file}}

@item time [@var{val}]
Set time display to @var{val}, or toggle it if @var{val} is not given.
With time display enabled, Sepia will use @code{BSD::Resource} and/or
@code{Time::HiRes} to display wall clock time and CPU usage for the
previous command as part of the prompt.

@item undef @var{name}
Undefine shortcut @var{name}.  @strong{Warning}: this can equally be
used to remove built-in shortcuts.

@item wantarray [@var{val}]
Set the evaluation context to @var{val}: @code{@@} means array, @code{$}
means scalar, and anything else means void.

@item who @var{package} [@var{regexp}]
@itemx who [@var{regexp}]
List identifiers in @var{package} (main by default) matching optional
@var{regexp.}  In strict mode, list lexical variables if no
@var{package} is given.

@end table

@node Debugger, Evaluation, Shortcuts, Interactive Perl
@section Debugger

Sepia uses Perl's debugger hooks and GUD mode to support conditional
breakpoints and single-stepping, and overrides Perl's @code{die()} to
invoke the debugger rather than unwind the stack.  This makes it
possible to produce a backtrace, inspect and modify global variables,
and even continue execution when a program tries to kill itself.  If the
PadWalker module is available, Sepia also provides functions to inspect
and modify lexical variables.

The debugger has its own set of shortcuts, also prefixed by a comma.

@table @kbd
@item backtrace
Show a backtrace.

@item delete
Delete the current breakpoint.

@item down @var{n}
@itemx up @var{n}
Move the current stack frame up or down by @var{n} (or one) frames.

@item inspect [@var{n}]
Inspect lexicals in the current frame or frame @var{n}, counting upward
from 1.

@item next [@var{n}]
Advance @var{n} (or one) lines, skipping subroutine calls.

@item quit
@itemx die
@itemx warn
Continue as the program would have executed without debugger
intervention, dying if the debugger was called from @code{die()}.

@item return @var{expr}
Continue execution as if @code{die()} had returned the value of
@var{expr}, which is evaluated in the global environment.

@item step [@var{n}]
Step forward @var{n} (or one) lines, descending into subroutines.

@item xreturn @var{sub} @var{expr}
Return @var{expr} from the innermost call to @var{sub}.  This is a
somewhat dangerous and experimental feature, but is probably more useful
than returning a value from @code{die()}.

@end table

@node Evaluation, Mutilation, Debugger, Interactive Perl
@section Evaluation

When interactive Perl is running, Sepia can evaluate regions of code in
the inferior Perl process.  The following commands assume that this
process has already been started by calling @code{sepia-repl}.

@table @kbd
@item C-M-x
@itemx M-x sepia-eval-defun
@findex sepia-eval-defun
Evaluate the function around point in the inferior Perl process.  If it
contains errors, jump to the location of the first.

@item C-c C-l
@itemx M-x sepia-load-file
@findex sepia-load-file
Save the current buffer, then reload its file and if warnings or errors
occur, display an error buffer.  With a prefix argument, also rebuild
the cross-reference index.

@item C-c e
@itemx M-x sepia-eval-expression @key{RET} @var{expr} @key{RET}
@findex sepia-eval-expression
Evaluate @var{expr} in scalar context and echo the result.  With a
prefix argument, evaluate in list context.

@item C-c!
@itemx sepia-set-cwd
@findex sepia-set-cwd
Set the REPL's working directory to the current buffer's directory.

@end table

@node Mutilation, Scratchpad, Evaluation, Interactive Perl
@section Mutilation

Sepia contains several functions to operate on regions of text using the
interactive Perl process.  These functions can be used like standard
one-liners (e.g. @samp{perl -pe ...}), with the advantage that all of
the functions and variables in the interactive session are available.

@table @kbd
@item M-x sepia-perl-pe-region @key{RET} @var{code} @key{RET}
@findex sepia-perl-pe-region
Evaluate @var{code} on each line in the region with @code{$_} bound to
the line text, collecting the resulting values of @code{$_}.  With a
prefix argument, replace the region with the result.

@item M-x sepia-perl-ne-region @key{RET} @var{code} @key{RET}
@findex sepia-perl-ne-region
Evaluate @var{code} as above, but collect the results instead.

@item M-x sepia-perlize-region @key{RET} @var{code} @key{RET}
@findex sepia-perlize-region
Evaluate @var{code} once with @code{$_} bound to the entire region,
collecting the final value of @code{$_}.  With a prefix argument,
replace the region.

@end table

@node Scratchpad,  , Mutilation, Interactive Perl
@section Scratchpad

@findex sepia-scratch
Sepia also supports a scratchpad, another form of interaction inspired
by Emacs' @code{*scratch*} buffer.  To create or switch to the
scratchpad, type @kbd{M-x sepia-scratch}.  Scratchpad mode is exactly
like Sepia mode, except @key{C-j} evaluates the current line and prints
the result on the next line.

@c ============================================================
@node  CPAN browsing, Customization, Interactive Perl, Top
@chapter CPAN browsing

Sepia has rudimentary support for browsing documentation and installing
modules from CPAN.  Modules whose names, descriptions, or authors match
a query are displayed in a @code{*sepia-cpan*} buffer, in which the
following commands are available:

@table @kbd
@item s
@itemx M-x sepia-cpan-search @key{RET} @var{pattern} @key{RET}
@findex sepia-cpan-search
List modules whose names match @var{pattern}.

@item /
@itemx M-x sepia-cpan-desc @key{RET} @var{pattern} @key{RET}
@findex sepia-cpan-desc
List modules whose names or descriptions match @var{pattern}.

@item l
@itemx M-x sepia-cpan-list @key{RET} @var{name} @key{RET}
@findex sepia-cpan-list
List modules authored by @var{name}.

@item r
@itemx M-x sepia-cpan-readme @key{RET} @var{module} @key{RET}
@findex sepia-cpan-readme
Fetch and display @var{module}'s README file.

@item d
@itemx M-x sepia-cpan-doc @key{RET} @var{module} @key{RET}
@findex sepia-cpan-doc
Browse @var{module}'s documentation on @url{http://search.cpan.org}.

@item i
@itemx M-x sepia-cpan-install @key{RET} @var{module} @key{RET}
@findex sepia-cpan-install
Install @var{module} and its prerequisites.  This feature is not yet
well tested.

@end table

@c ============================================================
@node Customization, Internals, CPAN browsing, Top
@chapter Customization

While Sepia can be customized in both the Perl and Emacs Lisp, most of
the user-accessible configuration is in the latter.

@menu
* Emacs Customization::             
* Perl Customization::              
@end menu

@node Emacs Customization, Perl Customization, Customization, Customization
@section Emacs Customization

Since Sepia tries where possible to reuse existing Emacs functionality,
its behavior should already be covered by existing customizations.  The
two variables most likely to need customization are
@kbd{sepia-program-name} and @kbd{sepia-perl5lib}.  General Sepia mode
configuration can be done with @kbd{sepia-mode-hook}, while
REPL-specific configuration can be done with @kbd{sepia-repl-mode-hook}.

@vtable @kbd

@item sepia-complete-methods
If non-@code{nil}, @code{sepia-complete-symbol} will complete
simple method calls of the form @code{$x->} or @code{Module->}.  Since
the former requires evaluation of @code{$x}, this can be disabled.
Default: @code{t}.

@item sepia-eval-defun-include-decls
If non-@code{nil}, attempt to generate a declaration list for
@code{sepia-eval-defun}.  This is necessary when evaluating some code,
such as that calling functions without parentheses, because the presence
of declarations affects the parsing of barewords.  Default: @code{t}.

@item sepia-indent-expand-abbrev
If non-@code{nil}, @code{sepia-indent-or-complete} will, if
reindentation does not change the current line, expand an abbreviation
before point rather than performing completion.  Only if no abbreviation
is found will it perform completion.  Default: @code{t}.

@item sepia-module-list-function
The function to view a tree of installed modules.  Default:
@code{w3m-find-file} if Emacs-w3m is installed, or
@code{browse-url-of-buffer} otherwise.

@item sepia-perldoc-function
The function called to view installed modules' documentation.  Default:
@code{w3m-perldoc} if Emacs-w3m is installed, or @code{cperl-perldoc}
otherwise.

@item sepia-perl5lib
A list of directories to include in @code{PERL5LIB} when starting
interactive Perl.  Default: @code{nil}.

@item sepia-prefix-key
The prefix to use for for functions in @code{sepia-keymap}.  Default:
@key{M-.}.

@item sepia-program-name
The Perl program name for interactive Perl.  Default: ``perl''.

@item sepia-use-completion
If non-@code{nil}, various Sepia functions will generate completion
candidates from interactive Perl when called interactively.  This may be
slow or undesirable in some situations.  Default: @code{t}.

@item sepia-view-pod-function
The function called to view the current buffer's documentation.
Default: @code{sepia-w3m-view-pod} if Emacs-w3m is available, or
@code{sepia-perldoc-buffer} otherwise.

@end vtable

@node Perl Customization,  , Emacs Customization, Customization
@section Perl Customization

When Sepia starts up, it evaluates the Perl script in @file{~/.sepiarc}.

The following variables in the Sepia package control various aspects of
interactive evaluation.

@table @code

@item $PACKAGE
The package in which user input is evaluated, determined automatically
when code is evaluated from a buffer.  Default: @code{main}.

@item $PRINTER
The function called to format interactive output, normally set with the
@code{printer} shortcut.

@item $COLUMNATE
If true, columnate simple arrays independent of the value of
@code{$PRINTER}.  Default: true.

@item $STRINGIFY
If true, stringify objects that overload the operation independent of
the value of @code{$PRINTER}.  Default: true.

@item $PS1
The trailing end of the prompt string, which should end with ``> ''.
Default: @code{"> "}.

@item $STOPDIE
If true, calls to @code{die} from interactive code will invoke the Sepia
debugger.  Default: true.

@item $STOPWARN
If true, calls to @code{warn} from interactive code will invoke the
Sepia debugger.  Default: false.

@item $WANTARRAY
If @code{@@}, evaluate interactive expressions in list context, if
@code{$}, scalar, otherwise, void.  Default: @code{@@}.

@end table

Additional REPL shortcuts can be defined as follows:

@table @code

@item Sepia::define_shortcut @var{name}, @var{function} [, @var{shortdoc} [, @var{longdoc}]]

Define a shortcut @var{name} to call @var{function}.  Also define a
short usage message @var{shortdoc} and documentation @var{longdoc}.  For
example,

@example

Sepia::define_shortcut time => sub @{ print scalar localtime, "\n" @},
    'time', 'Display the current time.';

@end example

defines a shortcut ``time'' that displays the current time.  For more
examples, see the function @var{define_shortcuts} code in
@file{Sepia.pm}.

@item Sepia::alias_shortcut @var{new}, @var{old}

Make @var{new} an alias for @var{old}.

@end table


@c ============================================================
@node Internals, FAQ, Customization, Top
@chapter Internals

Many things remain unexplained except by the code itself, and some
details mentioned above should probably be given less prominence.  For
developer documentation, please see the POD for @code{Sepia} and
@code{Sepia::Xref}, and the doc-strings in @file{sepia.el}.

@node FAQ, Credits, Internals, Top
@chapter FAQ

@table @asis
@item Can I use @code{Sepia} outside of Emacs?
Sepia comes with the @file{sepl} program, a command-line REPL using the
@code{Sepia::Readline} module, that provides many features of the
Emacs-based REPL.  It could be improved, though -- patches welcome!

@file{sepl} currently provides completion for @code{Term::ReadLine::Gnu}
and @code{Term::ReadLine::Perl}.  If you have neither of these, using
@file{rlwrap} might be the best option.

@item Why is the documentation in TeXInfo format?!
TeXInfo is the worst form of documentation, except for all the others.
TeX and LaTeX produce beautiful printed output, and Info is the best way
to view documentation in Emacs for things that are not themselves part
of Emacs (i.e. ``can have docstrings'').

It's awful to edit, being both verbose and redundant -- just look at
AUCTeX's @code{texinfo-every-node-update} for desperate placation of the
suck, then try to figure out what's wrong when @file{makeinfo} complains
about @code{texinfo-every-node-update}'s output -- but it's what we
have.  At least it sucks less than @code{DocBook}, raw HTML, or
@file{troff}.

@end table

@node Credits, Function Index, FAQ, Top
@unnumbered Credits

@table @asis
@item Hilko Bengen
Found and motivated me to fix a bunch of bugs, created Debian packages.

@item Ævar Arnfjörð Bjarmason
Miscellaneous fixes.  Tested unicode support.

@item Ye Wenbin
Found and fixed numerous bugs.

@item Free Software
Portions of the code were lifted from Emacs-w3m, SLIME, ido, and
B::Xref, all of which are Free software.

@end table

@c ============================================================
@node Function Index, Variable Index, Credits, Top
@unnumbered Function Index
@printindex fn

@node Variable Index,  , Function Index, Top
@unnumbered Variable Index
@printindex vr

@bye
