idlwave: Lesson II---Customization
3.2 Lesson II: Customization
============================
Emacs is probably the most customizable piece of software ever written,
and it would be a shame if you did not make use of this to adapt IDLWAVE
to your own preferences. Customizing Emacs or IDLWAVE is accomplished
by setting Lisp variables in the ‘.emacs’ file in your home
directory—but do not be dismayed; for the most part, you can just copy
and work from the examples given here.
Let’s first use a boolean variable. These are variables which you
turn on or off, much like a checkbox. A value of ‘t’ means on, a value
of ‘nil’ means off. Copy the following line into your ‘.emacs’ file,
exit and restart Emacs.
(setq idlwave-reserved-word-upcase t)
When this option is turned on, each reserved word you type into an
IDL source buffer will be converted to upper case when you press <SPC>
or <RET> right after the word. Try it out! ‘if’ changes to ‘IF’,
‘begin’ to ‘BEGIN’. If you don’t like this behavior, remove the option
again from your ‘.emacs’ file and restart Emacs.
You likely have your own indentation preferences for IDL code. For
example, some may prefer to indent the main block of an IDL program
slightly from the margin and use only 3 spaces as indentation between
‘BEGIN’ and ‘END’. Try the following lines in ‘.emacs’:
(setq idlwave-main-block-indent 1)
(setq idlwave-block-indent 3)
(setq idlwave-end-offset -3)
Restart Emacs, and re-indent the program we developed in the first
part of this tutorial with ‘C-c h’ and ‘C-M-\’. You may want to keep
these lines in ‘.emacs’, with values adjusted to your liking. If you
want to get more information about any of these variables, type, e.g.,
‘C-h v idlwave-main-block-indent <RET>’. To find which variables can be
customized, look for items marked ‘User Option:’ throughout this manual.
If you cannot seem to master this Lisp customization in ‘.emacs’,
there is another, more user-friendly way to customize all the IDLWAVE
variables. You can access it through the IDLWAVE menu in one of the
‘.pro’ buffers, menu item ‘Customize->Browse IDLWAVE Group’. Here
you’ll be presented with all the various variables grouped into
categories. You can navigate the hierarchy (e.g., ‘IDLWAVE Code
Formatting->Idlwave Abbrev And Indent Action->Idlwave Expand Generic
End’ to turn on ‘END’ expansion), read about the variables, change them,
and “Save for Future Sessions”. Few of these variables need
customization, but you can exercise considerable control over IDLWAVE’s
functionality with them.
You may also find the key bindings used for the debugging commands
too long and complicated. Often we have heard complaints along the
lines of, “Do I really have to go through the finger gymnastics of ‘C-c
C-d C-c’ to run a simple command?” Due to Emacs rules and conventions,
shorter bindings cannot be set by default, but you can easily enable
them. First, there is a way to assign all debugging commands in a
single sweep to another simpler combination. The only problem is that
we have to use something which Emacs does not need for other important
commands. One good option is to execute debugging commands by holding
down <CONTROL> and <SHIFT> while pressing a single character: ‘C-S-b’
for setting a breakpoint, ‘C-S-c’ for compiling the current source file,
‘C-S-a’ for deleting all breakpoints (try it, it’s easier). You can
enable this with:
(setq idlwave-shell-debug-modifiers '(shift control))
If you have a special keyboard with, for example, a <SUPER> key, you
could even shorten that:
(setq idlwave-shell-debug-modifiers '(super))
to get compilation on ‘S-c’. Often, a modifier key like <SUPER> or
<HYPER> is bound or can be bound to an otherwise unused key on your
keyboard; consult your system documentation.
You can also assign specific commands to keys. This you must do in
the _mode-hook_, a special function which is run when a new IDLWAVE
buffer gets set up. The possibilities for key customization are
endless. Here we set function keys f4-f8 to common debugging commands.
;; First for the source buffer
(add-hook 'idlwave-mode-hook
(lambda ()
(local-set-key [f4] 'idlwave-shell-retall)
(local-set-key [f5] 'idlwave-shell-break-here)
(local-set-key [f6] 'idlwave-shell-clear-current-bp)
(local-set-key [f7] 'idlwave-shell-cont)
(local-set-key [f8] 'idlwave-shell-clear-all-bp)))
;; Then for the shell buffer
(add-hook 'idlwave-shell-mode-hook
(lambda ()
(local-set-key [f4] 'idlwave-shell-retall)
(local-set-key [f5] 'idlwave-shell-break-here)
(local-set-key [f6] 'idlwave-shell-clear-current-bp)
(local-set-key [f7] 'idlwave-shell-cont)
(local-set-key [f8] 'idlwave-shell-clear-all-bp)))