PDE

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License".

1 A introduction to PDE

PDE is a collection of emacs lisp extensions to facilitate perl
programming. cperl-mode has provided a excellent environment for
coding, here PDE provides other common tools, such as creating file
using template, smart compiling, perldoc, perltidy, debugger, tags
tree view and so on. PDE also provides an easy configuration for perl
programing, and a tutorial for novice to start using emacs.

This manual tries to describe the feature of each emacs lisp file
provided and to be the guide for those who want to use them.

2 Installation

Installing PDE is quit easy. When you download the archive of the PDE
distribution, uncompress the archive to a folder, for example,
~/elisp/pde, then put this to your ~/.emacs:

(add-to-list 'load-path "~/elisp/pde/lisp")
(load "pde-load")

That is all what you need to do for a typical installation.

You can also use perl style installation:

./Build.PL
./Build test
./Build
./Build install

Note that test before build, so perl can test whether have emacs in
PATH. The default place to install lisp files is
“$ENV{HOME}/.emacs.d/pde”. You can use option —elispdir tell
perl where to put the lisp files. Note that using this way to install,
you should put ~/elisp/pde to load-path. So you should add
following to .emacs:

3 Default configuration for PDE

pde-load.el try to provide a default configuration for all
extension included in PDE. The configuration can be sorted by PDE core
features and some recommend personal setting. To disable addtional
features if you don't like, you can set pde-extra-setting to
nil.

— User Option: pde-extra-setting

When set to nil, don't load something you don't like

The minimal enable features after load `pde-load' are:

make perl script associate with cperl-mode not perl-mode

setup new indent style “PDE”

turn on abbrev mode

search document with M-x perldoc or using M-x perldoc-tree

show imenu with M-x imenu-tree

auto chmod when saving perl script

create new file with template

call perltidy when editing

start interactive perl shell using M-x inf-perl

improved perldb using M-x perldb-ui

smart compile and run command using M-x compile-dwim-compile
and compile-dwim-run.

find perl module in cperl-mode using M-x ffap

enable show brief info of buildin function under point in minibuffer

The extra feature including:

turn on ido-mode and using ido completion read imenu tag

automatic update imenu-tree and make tree always visible

complete read ingore case

turn on partial-completion-mode, and you can find perl module using
M-x find-file by add prefix char '<'.

multiple compilation buffers

useful global key bindings

show perldoc-tree and imenu-tree with tabbar

set tags-table-list, hippie-expand-try-functions-list,
comint-completion-addsuffix to make the command handy

some fixup to cperl-mode

The configuration is optimized so that most libraries are loaded when
needed.

cperl-next-interpolated-REx - Move point to next REx which has
interpolated parts.

C-x

cperl-next-interpolated-REx-0 - Move point to next REx which
has interpolated parts without //o.

C-y

cperl-next-interpolated-REx-1 - Move point to next REx which
has interpolated parts without //o.

— User Option: pde-view-prefix

Prefix key for view commands. Default is C-c C-v

— Variable: pde-view-map

Keymap for view commands.

C-i

pde-imenu-tree - Display tree view of imenu.

C-m

pde-pod-to-manpage - View pod in current buffer using woman.

C-p

pde-perldoc-tree - Display pod tree.

— User Option: pde-perltidy-prefix

Prefix key for perltidy commands. Default is C-c C-t.

— Variable: pde-perltidy-map

Keymap for perltidy commands.

C-b

perltidy-buffer - Call perltidy for whole buffer.

C-r

perltidy-region - Tidy perl code in the region.

C-s

perltidy-subroutine - Call perltidy for subroutine at point.

C-t

perltidy-dwim - Perltidy Do What I Mean.
If with prefix argument, just show the result of perltidy.
You can use C-x C-s to save the tidy result.
If region is active call perltidy on the region. If inside
subroutine, call perltidy on the subroutine, otherwise call
perltidy for whole buffer.

tabbar-mode can make a tabbar for all buffers. I prefer using ido-mode
to switch between buffers. But here I want add a tabbar for a few
buffers to group them and make emacs looks like IDE. So that why
tabbar-x. See tabbar-x.

— Function: pde-tabbar-register

Add tabbar and register current buffer to group Perl.

ffap is a good command. To use it in cperl-mode to find perl module,
need some hack.

— Function: pde-ffap-locate

Return cperl module for ffap.

indent-region need to mark a region. Not very convenient. So I
write a dwim command.

— Function: pde-indent-dwim

Indent the region between paren.
If region selected, indent the region.
If character before is a parenthesis(such as "]})>"), indent the
region between the parentheses. Useful when you finish a subroutine or
a block.
Otherwise indent current subroutine. Selected by beginning-of-defun
and end-of-defun.

Settings after cperl-mode is loaded or only for buffer that major-mode
is cperl-mode are defined in pde-perl-mode-hook

— Function: pde-perl-mode-hook

Hooks to run when enter cperl-mode. It define a new style “PDE”,
turn on display information of function on echo area, turn abbrev-mode
on, activate perldoc, auto chmod when save perl script but not module
or pod, and bind keys.

This key bindings are added:

C-c C-f

flymake-mode - Minor mode to do on-the-fly syntax checking.

C-c C-d

perldb-ui - Debugger with perldb-ui.

C-c C-k

perlcritic - Call perlcritic with current file

C-c C-z

run-perl - Start or switch to interactive perl shell.

The old C-c C-h commands are removed, and make
describe-prefix-bindings work. If you realy need them,
define them in pde-cperl-map.

Recursive read file name in DIR.
Like `directory-files', this function can return a list of files in
the directory and the subdirectories, but often there are too many files
in the directory, so need a parament to limit the number of files to
search and a flag to indicate whether all files are read. So instead
of return a list of files, this function return a cons cell which car
indicate whether all files read and cdr part is the real file list.

if FULL is non-nil, return absolute file names, if match is non-nil,
mention only file names match the regexp MATCH. If PREDICATE is non-nil
and is a function with one argument, the file name relative to DIR,
mention only file when PREDICATE function return non-nil value. If LIMIT
is non-nil, when the files execeed the number will stop. The function is
search in wide-first manner.

— Command: pde-project-find-file

Find file in the project.
This command is will read all file in current project recursively.
With prefix argument, to rebuild the cache.
I suggest bind this command to C-x C-p, which original command is
mark-page seldom used by me.

— User Option: pde-file-list-regexp

Filenames matching this regexp will not be read when `pde-project-find-file'.

— User Option: pde-file-list-predicate-function

Predicate function to filter file to be read when `pde-project-find-file'

9 New file with template

template.el is exists, why template-simple? First of all, it is
simple, the there is only one core function template-compile.

— Function: template-compile

Parse current buffer to parsed template.

The parsed template contains a list of strings, symbols or lisp forms.
The strings is inserted directly.
The symbol can be a predefined value in template-default-alist,
or can be translate by template-expand-function. The lisp forms
is handled by template-expand-function.

— User Option: template-expand-function

Functions to expand parsed template. There are two candicate functions
available in template-simple: template-skeleton-expand and
template-tempo-expand. Default function is
template-tempo-expand, because I think tempo provide more
fetures and flexibility than skeleton.

— Function: define-template-expander name alist &rest body

Define a new type of template-expand-function. NAME is used to
create a function template-<NAME>-expand. ALIST can be a symbol or a
form to return a list of symbol table add to template-default-alist.
BODY is the code to expand and insert the template. the value of
variable TEMPLATE is the translated template. The element of parsed
template is translated by template-expansion

— Function: template-simple-expand-template file

Expand template in file.
Parse the template to parsed templates with template-compile.
Use template-expand-function to expand the parsed template.

— Function: template-simple-expand template

Expand string template.
template can be a string or a parsed template. If it is string,
parse the template to parsed templates with template-compile.
Use template-expand-function to expand the parsed template.

template-simple is designed to compatible to template.el, so the
default open and close parentheses is “(>>>” and “<<<)”. Note that
global value of template-expand-function is saved in
template-simple-expand. The same case happened to
template-parens in template-compile. So If you need
change them temporary for certain template, you can set
template-parens and template-expand-function like file
variable, for example:

This will expand by template-tempo-expand but not default
expand function. Luckily in most case, template of tempo and skeleton
can be the same, so you don't have to set
template-expand-function. If your template uses element that
only exists in tempo or skeleton, you'd better set it in template to
make sure the template-simple-expand select the correct one.

The major purpose of template-simple is used for fill empty file using
predefined template.

— User Option: template-directory-list

A list of directories for lookup template files. Default is
“~/.templates/” and auto-insert-directory.

— Function: template-derive-template

Find proper template for current file. The template file is a file
with name “TEMPLATE” and the same extension of current file under
template-directory. You can add a suffix “.tpl” to the
template file name too, just for compatible with templates provide by
template.el. If the file didn't have extension, the template file's
extension is current file name, for example, “TEMPLATE.Makefile” is
template file for “Makefile”.

— User Option: template-default-alist

Predefined symbol for template file. Symbols to lookup in this table
is case insensitive.

Here is a list of predefined symbol:

dir default directory of current file

file basename(without directory) of current file

file-sans file name without extension and directory

file-ext file extension

file-upcase upcased file-sans

date formated time string using template-date-format

cdate formated time string using template-cdate-format
with system-time-locale value is “C”

iso-date “%Y-%m-%d” time string

vc-date “%Y/%m/%d %T” time string with time-zone “UTC”

year “%Y”

time formated time string using template-time-format

author user-mail-address

user-name user-full-name

login-name user-login-name

host-addr mail-host-address

A neat function provided by template.el is the file name in
the header can automatic update when the file is renamed.
template-simple also provide this feature.

— Function: template-simple-update-header

update file header when needed. The file header is a line match
template-header-regexp at first 3 lines in current file.

10 Tabbar for particular buffers

Sometimes, make tabbar for particular buffers maybe cool. For example,
I add tabbar for only perl related buffers, *Perldoc*, *PDE Imenu*,
and I am planning to group perldb-ui buffers as the same way. tabbar-x
exists for this purpose.

11 Additional elements for tempo

tempo.el is a extensible library for abbrevs. It provide more
features than skeleton.el, such as move between marks,
names for prompt, user elements and so on. tempo-x.el provides
some commands and additional elements that may helpful.

— Command: tempo-x-space

A simple command to enable expand tempo like abbrev. The command
tempo-space given by the author of tempo.el is not
compatiable for abbrev-mode.

— Command: tempo-x-rebuild

Reinstall new tempo template for all buffer. If you defined a new
tempo-template in certain tag-list, you can't use it intermediately.
Call the commands to force build connections for all buffer again.

— Function: tempo-x-test-template

A macro to test tempo template before define it.

Here is a list of new elements:

pi

Pi

“pi” and “Pi” like standard tempo element “p” except they can
have a default value and can be completing read.

The beta version of tempo.el also implement new prompt element, but I
still an element that can accept default value.
PROMPT can be a string or a list. When it is a string, it is like
standard tempo element p, but you can give a DEFAULT string.
If it is a list, the prompt will be the parameters of
completing-read. But you should give the default value in
DEFAULT not in PROMPT.

skeleton has some handy elements to control recursive expanding. “R”
is such tempo elements to do this job. The syntax of the element is:

(R before-test-elements
(& condition
final-form)
after-test-elements)

First it insert BEFORE-TEST-ELEMENTS to buffer. then test the
CONDITION, if the CONDITION is null, eval FINAL-FORM and quit the
loop. Otherwise insert AFTER-TEST-ELEMENTS and back to start. The
CONDITION can be a name saved in BEFORE-TEST-ELEMENTS, it will
automatic clean after test, so you will be prompt again. If you want
use it after test, backup it by yourself. The CONDITION also can be a
list, which CAR is a list of names will be used and will be clean
after test.
A special variable recursion-start is available is FINAL-FORM,
you can use it to clean up recent insertion in BEFORE-TEST-ELEMENTS.

If you want use this only, you can try tempo-snippets.el,
tempo-x.el borrow most of functions from there to implement a
new element instead of new template style.

“snippet” enable visualize the template field, and can update form when
editing. The syntax of “snippet” is:

(snippet (S name &optional display insert)
(F (vars) forms))

“S” insert a field, the first NAME will be the source and other
field with the same NAME become mirrors. Change the source will also
change mirrors. DISPLAY is the text to insert to the field, default is
the `symbol-name' of NAME. INSERT is non-nil means the DISPLAY is the
default text, you can make change to the text. Otherwise the text will
be erase after any changes in front of field.

“F” insert an form. The VARS is a list of NAME used in fields. the
evaled result will insert into the buffer. When any fields in VARS
changed, the text of form will change too.

the text inside “[]” indicate as a field, and text inside “{}”
indicate as a form, the when text inside the field changes, the
assicated form will update too. For example if you change open mode
from “<” to “>”, the form “open” will change to “create”. If
change “$file” to “"file"” the form will change to “file” with
quote removed.

12 Regexp building and testing tool

If you have not use re-builder, please try it. The tool is
quite simple and useful, you just input regexp in the *RE-Builder*
buffer, the matched part in the buffer where the command is called will
be highlighted.

re-builder-x.el extend the regexp syntax to perl or any other
languages. To enable perl regexp syntax, you have to change the syntax
to perl first. The command is reb-change-syntax, which is
bound to C-c TAB.

In consideration of efficiency, if you make some changes in the buffer,
the regexp will not apply in the new text unless you send current buffer
to perl process again. You can do that by using command
reb-perl-send-buffer which bound to C-c C-a.

13 Smart compile commands

cperl-mode recommend using mode-compile, but I don't like
mode-compile. Instead, smart-compile+.el does a good job. But I found
it is not easy to customize smart-compile+, because the user variables
are separated for a language. So I rewrite it to
compile-dwim(again, I like dwim).

— User Option: compile-dwim-alist

Settings for certain file type.
A list like which has form
(TYPE CONDITION COMPILE-COMMAND RUN-COMMAND EXE-FILE).

TYPE is the language type to distinguish from others.

CONDITION is a list of predicates constituted by operator “or”.
The predicates can be (name . REGEXP) or (mode . MAJOR-MODE) to test
the file name match REGEXP or major-mode eq MAJOR-MODE.

In COMPILE-COMMAND and RUN-COMMAND, these format specifications
are available:

%i interpreter name
%F absolute pathname
%f file name without directory
%n file name without extention
%e extention of file name

The interpreter is the program in the shebang line. If the
program is valid(test with `executable-find'), then use this program,
otherwise, use interpreter in `interpreter-mode-alist' according
to the major mode.

EXE-FILE control whether should run compile command before actual run
or should recompile again because EXE-FILE is older than source file.
Usually, script language don't need to set EXE-FILE.

— User Option: compile-dwim-check-tools

Whether checking makefile or ant or else. Default is turn on. You can
also change the value locally by make-local-variable in
mode-hook for certain files.

14 Find documents using help-dwim

A big obstacle for novice to used to emacs is that there are so many
keys to remember. I like dwim commands. help-dwim.el provide a single
command as interface for several kinds of document commands, such as
describe-function, describe-variable,
woman. And you can add more if you follow the rules.

A type of help-dwim commands should provide:

a functions or a character sets to find which symbol under point

an obarray to search whether the symbol belong to this type

an optional predicate function to filter unwanted symbol

a handler to show the document of the symbol

— Function: help-dwim-register type activate &optional body

Register a new type of help command. An new type has a form (TYPE .
[FINDER OBARRAY PREDICATE HANDLER]). If ACTIVATE is non-nil, the type
will add to help-dwim-active-type, and BODY will eval
intermediately. BODY is the code to eval when the type is activated.
If the type is register without activated, the BODY will add to
help-dwim-autoloads. When you use help-dwim-active-type
or help-dwim-customize-type add the type, the code will also
eval then.

— Command: help-dwim-customize-type

Customize which type of help command should activate.

— Function: help-dwim-active-type type &optional append

Active a type for current buffer *ONLY*.
The TYPE will gain a highest prority unless APPEND is non-nil.

15 Run perldoc using woman

I like “woman”(that is WithOut MAN). perldoc.el make it possible to
view perl document without man. To use it with help-dwim, a
list of modules is build automatic using a perl script
perldoc-cache.pl. The cache can be update automaticly. It is
configured in pde-load. See pde-load.

— Function: perldoc-recache-everyday &optional days

If the cache file is expired DAYS, force caches update.

With the perldoc-obarray, a lot of things can be done.
perldoc-tree use this obarray to build a tree view.

— Function: perldoc-read-module prompt &optional require-match init

Read a perl module name.
When a module name at point, the module become the default input.
Don't add ": " in PROMPT.

— Command: perldoc-find-module &optional module other-window

Find the file of perl module. With prefix argument open the file in
other window.

— Command: perldoc-find-module-ap &optional other-window

Find the module under point without prompt. With prefix argument open
the file in other window.

17 Window configuration to list

Emacs can save window configuration when it is running. The
configuration can be persisted between different sessions.
windata provide a way to save window configuration.

— Function: windata-current-winconf

Convert window configurate to a list. The CAR part of the list
describe how to restore the window, the CDR part of the list determine
which window is selected.

— Function: windata-restore-winconf &optional inside-p

Restore window configuration from `windata-current-winconf'.
When INSIDE-P is non-nil, that mean the window configuration
is restore in current window, that is to say don't delete other
windows before restore the configuration.

— User Option: windata-data-function

A function to extract data for future restore window. Default is save
the window buffer name. Accept one parameter, the window, and should
return a lisp object that has print syntax.

— User Option: windata-data-restore-function

A function to restore window buffer from saved data. Default is set
window buffer to the buffer with saved name. Accept two parameters,
the window and a saved lisp object by windata-data-function.

Display buffer more precisely.
FRAME-P is non-nil and not window, the displayed buffer affect
the whole frame, that is to say, if DIR is right or left, the
displayed buffer will show on the right or left in the frame. If
it is nil, the buf will share space with current window.

DIR can be one of member of (right left top bottom).

SIZE is the displayed windowed size in width(if DIR is left or
right) or height(DIR is top or bottom). It can be a decimal which
will stand for percentage of window(frame) width(heigth)

DELETE-P is non-nil, the other window will be deleted before
display the BUF.

The behavior of windata-display-buffer is better show as
following pictures:

The start window is as picture 1, the selected window is indicated by
“P”, and new appear window indicated by “N”. The simplest
sitiation is when DELETE-P is non-nil, after calling the function,
there are only two window left. When FRAME-P is 'window or nil, the
new window will only take the space from the selected window. When
FRAME-P is non-nil except 'window, the original window still has
the same configuration.

tree-mode-expand-level - Expand tree to LEVEL. With prefix
argument 0 or negative, will expand all leaves of the tree.

s

tree-mode-sort-by-tag - Sort children node by tag.

/

tree-mode-keep-match - Keep node which tag match REGEXP

!

tree-mode-collapse-other-except - Collapse other trees. If the
tree at point is contract, expand it.

D

tree-mode-delete-tree - Delete a tree from buffer.

The icon for push-button in tree-widget is limited 4 types: open,
close, empty and leaf. tree-mode provide a method to settup icon of
push-button by put an addition attribute :button-icon in tree-widget
node.

21 Calling perltidy

22 Calling perlcritic

“perlcritic” is a Perl source code analyzer. See
perldoc perlcritic for detail document of the program.
perlcritic.el provide an interface to use “perlcritic” in
Emacs. It invoke the program using compile, highlight
severity and add hyperlink to the error.

perlcritic is known run a little slow. You can use this command to
analyze only a part of file.

perlcritic provide a lot of options in command line.
perlcritic.el only support a few of options. Additional options
can be input in the minibuffer or write your profile, default is
.perlcriticrc.

— User Option: perlcritic-profile

Specify an alternate .perlcriticrc file.
If value is nil, use -noprofile,
If value is t, use the default profile .perlcriticrc,
If non-nil, and the profile exists, use the profile.

— User Option: perlcritic-severity

Default severity level is 5 and perlcritic-severity value is nil.

— User Option: perlcritic-top

Report only the top N Policy violations in each file.
If the -severity option is not explicitly given, the -top option
implies that the minimum severity level is 1. Users can redefine
the severity for any Policy in their .perlcriticrc file.

23 Perl Debugger

perldb provide the minimal debugger interface in emacs. perldb-ui.el try
to extend it more like gdb-ui. Not finished yet. But all interface
will not change too much in future.

The main idea to communicate with perldb process is using .perldb to
add a batch of subroutines to call in emacs. With those subroutines,
it is easier to get information from the process.

— User Option: perldb-many-windows

If non-nil, display layout in `perldb-window-configuration'.

— User Option: perldb-use-separate-io-buffer

Non-nil means display output from the debugged program in a separate buffer.

— Command: perldb-many-windows

Toggle the number of windows in the basic arrangement.
With arg, display additional buffers iff arg is positive.

— Command: perldb-restore-windows

Restore the basic arrangement of windows used by perldb-ui.
This arrangement depends on the value of `perldb-many-windows'.

— Command: perldb-save-window-configuration

Save current window configuration as default.
With prefix argument, just setup for current session.

perl5db provides a convenient command line interface. Most case, it is
more quick using command than calling an emacs command. If you want
control debugger in source buffer, maybe turn on
perldb-gud-mode is a good choice.

n

gud-next - Step one line (skip functions).

SPC

gud-next - Step one line (skip functions).

s

gud-step - Step one source line with display.

u

gud-until - Continue to current line.

r

gud-return - Return from current subroutine.

c

gud-cont - Continue with display.

b

gud-break - Set breakpoint at current line.

d

gud-remove - Remove breakpoint at current line

p

gud-print - Evaluate perl expression at point.

x

gud-dump - Dumper data

l

gud-refresh - Fix up a possibly garbled display, and redraw the
arrow.

q

perldb-gud-mode - quit perldb-gud-mode.

Know Bugs

You cannot run two or more debugger at the same time. The global
variables may conflict.