This file documents IDLWAVE, a major mode for editing IDL and WAVE/CL files with Emacs.  It also implements a shell for running IDL as a subprocess.

This is edition 1.10 of the IDLWAVE User Manual for IDLWAVE 3.15

Copyright (c) 1999, 2000 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation.

IDLWAVE is a package to support editing command files for the Interactive Data Language (IDL), and for running IDL as an inferior shell.

Introduction
************

IDLWAVE is a package to support editing command files for the Interactive Data Language (IDL), and for running IDL as an inferior shell.  It also can be used for WAVE/CL command files, but the support for these is limited.  Note that this package has nothing to do with the Interface Definition Language as part of the Common Object Request Broker Architecture (CORBA).

IDLWAVE is the successor to the idl.el and idl-shell.el files written by Chris Chase.  The modes and files had to be renamed because of a name space conflict with CORBAs idl-mode, defined in Emacs in the file cc-mode.el.  If you have been using the old files, check Upgrading from idl.el for information on how to switch.

IDLWAVE consists of two parts: A major mode for editing command files (idlwave-mode) and a mode to allow running the IDL program as an inferior shell (idlwave-shell-mode).  Both modes work closely together and form a complete development environment.

Here is a brief summary of what IDLWAVE does.

  * Code indentation and formatting.

  * Font-lock support on three levels.

  * Display of calling sequence and keywords of more than 1000 IDL routines.

  * Context sensitive completion of routine names and keywords.

  * Insertion of code templates.

  * Actions to enforce coding standards during typing.

  * Block structure check.

  * Documentation support.

  * Running IDL as inferior process.

  * Shell with history search, command line editing and completion.

  * Compilation, execution and debugging of programs directly from the source buffer.

  * Examining expressions with a mouse click.

Here are a number of screenshots showing IDLWAVE in action.

  * XEmacs 21.1 with formatted and fontified code (http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave/font-lock.gif)

  * XEmacs 21.1 displaying routine info (http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave/rinfo.gif)

  * XEmacs 21.1 completing a keyword (http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave/complete.gif)

  * XEmacs 21.1 with debugging toolbar; execution stopped at a breakpoint (http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave/shell.gif)

In this manual, each section contains a list of user options related to the subject.  Don't be confused by the shear number of options available -- in most cases the default settings are just fine.  The variables are listed here to make sure you know where to look if you want to change things.  For a full description of what a particular variable does and how to configure it, see the documentation string of that variable. Some configuration examples are also given in the appendix.

IDLWAVE in a Nutshell
*********************

Editing IDL Programs
--------------------

TAB
Indent the current line relative to context.
M-C-\
Re-indent all lines in the current region.
M-RET
Start a continuation line.  Or split the current line at point.
M-q
Fill the current comment paragraph.
C-c ?
Display calling sequence, keywords of the procedure/function call
at point.
M-TAB
Complete a procedure name, function name or keyword in the buffer.
C-c C-i
Update IDLWAVE's knowledge about functions and procedures.
C-c C-v
Find the source code of a procedure/function.
C-c C-h
Insert a standard documentation header.
C-c C-m
Insert a new timestamp and history item in the documentation header.

Running the IDLWAVE Shell, Debugging Programs
---------------------------------------------

C-c C-s
Start IDL as a subprocess and/or switch to the interaction buffer.
C-u C-c C-s
Start the shell in a separate frame.
M-p
Cycle back through IDL command history matching command line input.
M-n
Cycle forward.
M-TAB
Complete a procedure name, function name or keyword in the shell buffer.
C-c C-d C-c
Save and compile the source file in the current buffer.
C-c C-d C-x
Goto next syntax error.
C-c C-d C-b
Set a breakpoint at the current source line.
C-c C-d C-d
Clear the current breakpoint.
C-c C-d C-p
Ask IDL to print the value of the expression near point.

Commonly used Settings in .emacs
--------------------------------

     ;; Change the indentation preferences
     (setq idlwave-main-block-indent 2         ; default  0
           idlwave-block-indent 2              ; default  4
           idlwave-end-offset -2)              ; default -4
     ;; Pad some operators with spaces
     (setq idlwave-do-actions t
           idlwave-surround-by-blank t)
     ;; Automatically expand END to ENDIF, ENDELSE, ...
     (setq idlwave-expand-generic-end t)
     ;; Syntax Highlighting
     (add-hook 'idlwave-mode-hook 'turn-on-font-lock)

     ;; Automatically start the shell when needed, in dedicated frame
     (setq idlwave-shell-automatic-start t
           idlwave-shell-use-dedicated-frame t)

     ;; Specify a file where library info can be stored.
     (setq idlwave-libinfo-file "~/idlinfo.el")

The IDLWAVE Major Mode
**********************

The IDLWAVE major mode supports editing IDL and WAVE/CL command files. In this chapter we describe the main features of the mode and how to customize them.

Code Formatting
===============

Code Indentation
----------------

Like all Emacs programming modes, IDLWAVE performs code indentation. The TAB key indents the current line relative to context. LFD insert a newline and indents the new line.  The indentation is governed by a number of variables.

To re-indent a larger portion of code (e.g. when working with foreign code written with different conventions), use M-C-\ (indent-region) after marking the relevant code.  Useful marking commands are C-x h (the entire file) or M-C-h (the current subprogram). See Actions, for information how to impose additional formatting conventions on foreign code.

 -- User Option: idlwave-main-block-indent (0)
     Extra indentation for the main block of code.  That is the block between the FUNCTION/PRO statement and the END statement for that program unit.

 -- User Option: idlwave-block-indent (4)
     Extra indentation applied to block lines.  If you change this, you probably also want to change idlwave-end-offset.

 -- User Option: idlwave-end-offset (-4)
     Extra indentation applied to block END lines.  A value equal to negative idlwave-block-indent will make END lines line up with the block BEGIN lines.

 -- User Option: idlwave-continuation-indent (2)
     Extra indentation applied to continuation lines and insided unbalanced parenthesis.

Comment Indentation
-------------------

In IDL, lines starting with a ; are called comment lines. Comment lines are indented as follows:

;;;
The indentation of lines starting with three semicolons remains
unchanged.
;;
Lines starting with two semicolons are indented like the surrounding code.
;
Lines starting with a single semicolon are indent to a minimum column.

The indentation of comments starting in column 0 is never changed.

 -- User Option: idlwave-no-change-comment
     The indentation of a comment that starts with this regular expression will not be changed.

 -- User Option: idlwave-begin-line-comment
     A comment anchored at the beginning of line.  A comment matched by this regular expression will not have its indentation changed.

 -- User Option: idlwave-code-comment
     A comment that starts with this regular expression on a line by itself is indented as if it is a part of IDL code.

Continuation Lines and Filling
------------------------------

In IDL, a newline character terminates a statement unless preceded by a $.  If you would like to start a continuation line, use M-RET which calls the command idlwave-split-line.  It inserts a $ to indicate that the following line is a continuation of the current line, terminates the line with a newline and indents the new line.  The command M-RET can also be used in the middle of a line to split the line at that point.  When used inside a long string constant, the string is split with the + concatenation operator.  You could even use auto-fill-mode to automatically break code lines into several lines while you type.  For this, set the variable idlwave-fill-comment-line-only to nil and turn on auto-fill-mode.  auto-fill-mode can be toggled with C-c C-a.

When filling comment paragraphs, IDLWAVE overloads the normal filling functions and uses a function which creates hanging paragraphs as they are customary in the IDL routine headers.  When auto-fill-mode is turned on, comments will be auto-filled.  If the first line of a paragraph is matched by idlwave-hang-indent-regexp, subsequent lines are indented to after the position of this match, as in the following example.

     ; INPUTS
     ; x - an array containing
     ;     lots of interesting numbers.
     ;
     ; y - another variable where
     ;     a hanging paragraph is used
     ;     to describe it.

You also refill a comment paragraph with M-q.

 -- User Option: idlwave-fill-comment-line-only (t)
     Non-nil means auto fill will only operate on comment lines.

 -- User Option: idlwave-auto-fill-split-string (t)
     Non-nil means auto fill will split strings with the IDL + operator.

 -- User Option: idlwave-split-line-string (t)
     Non-nil means idlwave-split-line will split strings with +.

 -- User Option: idlwave-hanging-indent
     Non-nil means comment paragraphs are indented under the hanging indent given by idlwave-hang-indent-regexp match in the first line of the paragraph.

 -- User Option: idlwave-hang-indent-regexp
     Regular expression matching the position of the hanging indent in the first line of a comment paragraph.

 -- User Option: idlwave-use-last-hang-indent (nil)
     Non-nil means use last match on line for idlwave-indent-regexp.

Syntax Highlighting
-------------------

Highlighting of keywords, comments, strings etc. can be accomplished with font-lock.  To enable font-lock for IDL files, place the following line into your .emacs (see Configuration Examples)

     (add-hook 'idlwave-mode-hook 'turn-on-font-lock)

IDLWAVE supports 3 levels of syntax highlighting.  The variable font-lock-maximum-decoration determines which level is selected.

 -- User Option: idlwave-default-font-lock-items
     Items which should be fontified on the default fontification level 2.

Routine Info
============

IDL defines more than one thousand procedures, functions and object methods.  This large command set makes it difficult to remember the calling sequence and keywords of a command.  IDLWAVE contains a list of all builtin routines with calling sequences and keywords (This list was created by scanning the IDL manual and might contain (very few) errors.  Please report any detected errors to the maintainer, so that they can be fixed.).  It also scans Emacs buffers and library files for routine definitions and queries the IDLWAVE-Shell for the properties of modules currently compiled under the shell.  When you have edited a buffer or compiled additional routines under the shell, use C-c C-i (idlwave-update-routine-info) to update IDLWAVE's idea about these routines.

To display the information about a routine, press C-c ? which calls the command idlwave-routine-info.  When the current cursor position is on the name or in the argument list of a procedure or function, information will be displayed about the routine.  For example, consider the cursor positions in the following line

     plot,x,alog(x+5*sin(x) + 2),
       1  2   3   4   5  6  7    8

On positions 1,2 and 8, information about the plot procedure will be shown.  On positions 3,4, and 7, the alog function will be described, while positions 5 and 6 will select the sin function. When you ask for routine information about an object method, and the method exists in several classes, IDLWAVE queries for the class of the object.

The description displayed contains the calling sequence, the list of keywords and the origin of this information (system routine, library routine, Emacs buffer, or compiled module).  It looks like this:

     Usage:    MAP_PROJ_INFO, iproj
     Keywords: CIRCLE CURRENT CYLINDRICAL NAME UV_LIMITS WIDTH
     Origin:   buffer visiting /soft1/idl/lib/map_set.pro

Some of the text in the *Help* buffer will be active (it highlights when you move the mouse over it).  Clicking with the middle mouse button on any of the active fields will try to find the source file of the routine and display it in another window.  Another click on the same line will switch back to the buffer from which C-c ? was called.  Clicking with the right mouse button on an active field will search the IDL online help for this item.

Another way to find the source file of a routine is the command C-c C-v (idlwave-find-module).  It asks for a module name, offering the same default as idlwave-routine-info would have used.  In the minibuffer, specify a complete routine name (including the class part). IDLWAVE will display the source file in another window.

The two other commands that work with the routine at point need a running IDLWAVE shell.  The key sequence M-? calls the command idlwave-routine-info-from-idlhelp.  This sends the command line ONLINE_HELP, 'ROUTINE_NAME' to IDL in order to display the documentation of the routine in the IDL online documentation.  The key sequence C-c = calls the command idlwave-resolve and sends the line RESOLVE_ROUTINE, 'ROUTINE_NAME' to IDL in order to resolve (compile) it.

idlwave-resolve is one way to get a library module within reach of IDLWAVE's routine info collecting functions.  A better way is to prescan (parts of) the library (see Library Scan).  Routine info on library modules will then be available without the need to compile the modules first, and even without a running shell.

See Sources of Routine Info, for in-depth information where IDLWAVE collects data about routines, and how to update this information.

 -- User Option: idlwave-scan-all-buffers-for-routine-info (t)
     Non-nil means, scan all buffers for IDL programs when updating info.  When this variable is nil, it only parses the current buffer.

 -- User Option: idlwave-query-shell-for-routine-info (t)
     Non-nil means query the shell for info about compiled routines.

 -- User Option: idlwave-resize-routine-help-window (t)
     Non-nil means, resize the Routine-info *Help* window to fit the content.

Completion
==========

IDLWAVE offers completion for routine names and keywords.  As in many programming modes, completion is bound to M-TAB. Completion uses the same internal information as routine info, so in order to update IDLWAVE's idea about your own routines after you have edited or compiled them, press C-c C-i (idlwave-update-routine-info).

The completion function is context sensitive and figures out what to complete at point.  Here are example lines and what M-TAB would try to complete when the cursor is on the position marked with a *.

     plo*                    Procedure
     x = a*                  Function
     plot,xra*               Keyword of plot procedure
     plot,x,y,/x*            Keyword of plot procedure
     plot,min(*              Keyword of min function
     obj -> a*               Object method (procedure)
     a(2,3) = obj -> a*      Object method (function)
     x = obj_new('IDL*       Class name
     x = obj_new('MyCl',a*   Keyword to Init method in class MyCl

If the list of completions is too long to fit in the *Completions* window, the window can be scrolled by pressing M-TAB repeatedly.

The case of the completed words is determined by what is already in the buffer.  When the partial word being completed is all lower case, the completion will be lower case as well.  If at least one character is upper case, the string will be completed in upper case or mixed case. The default is to use upper case for procedures, functions and keywords, and mixed case for object class names and methods, similar to the conventions in the IDL manuals.  These defaults can be changed with the variable idlwave-completion-case.

 -- User Option: idlwave-completion-case
     Association list setting the case (UPPER/lower/Capitalized/...) of completed words.

 -- User Option: idlwave-completion-force-default-case (nil)
     Non-nil means, completion will always honor the settings in idlwave-completion-case.  When nil (the default), lower case strings will be completed to lower case.

 -- User Option: idlwave-complete-empty-string-as-lower-case (nil)
     Non-nil means, the empty string is considered lower case for completion.

 -- User Option: idlwave-keyword-completion-adds-equal (t)
     Non-nil means, completion automatically adds = after completed keywords.

 -- User Option: idlwave-function-completion-adds-paren (t)
     Non-nil means, completion automatically adds ( after completed function.  A value of `2' means, also add the closing parenthesis and position cursor between the two.

 -- User Option: idlwave-completion-restore-window-configuration (t)
     Non-nil means, restore window configuration after successful completion.

Object Method Completion and Class Ambiguity
............................................

An object method is not uniquely determined without the object's class. Since the class part is usually omitted in the source code, IDLWAVE considers all available methods in all classes as possible completions of an object method name.  For keywords, the combined keywords of the current method in all available classes will be considered.  In the *Completions* buffer, the classes allowed for each completion will be shown next to the item (see option idlwave-completion-show-classes).

You can also call idlwave-complete with a prefix arg: C-u M-TAB.  IDLWAVE will then prompt you for the class in order to narrow down the number of possible completions.  The variable idlwave-query-class can be configured to make this behavior the default (not really recommended).  After you have specified the class for a particular statement (e.g. when completing the method), IDLWAVE can remember it for the rest of the editing session.  Subsequent completions in the same statement (e.g. keywords) can then reuse this class information.  Remembering the class works by placing a text property in the object operator ->.  This is not enabled by default - the variable idlwave-store-inquired-class can be used to turn it on.

 -- User Option: idlwave-completion-show-classes (1)
     Non-nil means, show classes in *Completions* buffer when completing object methods and keywords.

 -- User Option: idlwave-completion-fontify-classes (t)
     Non-nil means, fontify the classes in completions buffer.

 -- User Option: idlwave-query-class (nil)
     Association list governing query for object classes during completion.

 -- User Option: idlwave-store-inquired-class (nil)
     Non-nil means, store class of a method call as text property on ->.

 -- User Option: idlwave-class-arrow-face
     Face to highlight object operator arrows -> which carry a class property.

Code Templates
==============

IDLWAVE can insert IDL code templates into the buffer.  For a few templates, this is done with direct keybindings:

C-c C-c
CASE statement template
C-c C-f
FOR loop template
C-c C-r
REPEAT loop template
C-c C-w
WHILE loop template

Otherwise, special abbreviations are used.  Emacs abbreviations are expanded by typing text into the buffer and pressing SPC or RET.  The special abbreviations used to insert code templates all start with a \ (the backslash).  Here are a few examples of predefined abbreviations.   For a full list, use M-x idlwave-list-abbrevs.

\pr
PROCEDURE template
\fu
FUNCTION template
\c
CASE statement template
\f
FOR loop template
\r
REPEAT loop template
\w
WHILE loop template
\i
IF statement template
\elif
IF-ELSE statement template
\b
BEGIN

The templates are expanded in upper or lower case, depending upon the variables idlwave-abbrev-change-case and idlwave-reserved-word-upcase.

 -- User Option: idlwave-abbrev-start-char
     A single character string used to start abbreviations in abbrev mode.

 -- User Option: idlwave-abbrev-move (t)
     Non-nil means the abbrev hook can move point, e.g. to end up between the parenthesis of a function call.

Actions
=======

Actions are special commands which are executed automatically while you write code in order to check the structure of the program or to enforce coding standards.  Most actions which have been implemented in IDLWAVE are turned off by default, assuming that the average user wants her code the way she writes it.  But if you are a lazy typist and want your code to adhere to certain standards, they can be helpful.

Action can be applied in three ways:

  * Some actions are applied directly while typing.  For example, pressing = can run a check to make sure that this operator is surrounded by spaces and insert these spaces if necessary.  Pressing SPC after a reserved word can call a command to change the word to upper case.

  * When a line is re-indented with TAB, actions can be applied to the entire line.  To enable this, the variable idlwave-do-actions must be non-nil.

  * Action can also be applied to a larger piece of code, e.g. in order to convert foreign code to your own style.  To do this, mark the relevant part of the code and execute M-x expand-region-abbrevs.  Useful marking commands are C-x h (the entire file) or M-C-h (the current subprogram). See Code Indentation, for information how to ajust the indentation of the code.

 -- User Option: idlwave-do-actions (nil)
     Non-nil means performs actions when indenting.

Block Boundary Check
--------------------

Whenever you type an END statement, IDLWAVE finds the corresponding start of the block and the cursor blinks back to that location for a second.  If you have typed a specific END, like ENDIF or ENDCASE, you get a warning if that kind of END does not match the type of block it terminates.

Set the variable idlwave-expand-generic-end in order to have all generic END statements automatically expanded to a specific type. You can also type C-c ] to close the current block by inserting the appropriate END statement.

 -- User Option: idlwave-show-block (t)
     Non-nil means point blinks to block beginning for idlwave-show-begin.

 -- User Option: idlwave-expand-generic-end (nil)
     Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc.

Padding Operators
-----------------

Some operators can be automatically surrounded by spaces.  This can happen when the operator is typed, or also later when the line is indented.  IDLWAVE contains this setting for the operators &, <, >, ,, =, and -> (operators longer than one character can only be padded during line indentation.), but the feature is turned off by default.  If you want to turn it on, customize the variables idlwave-surround-by-blank and idlwave-do-actions.  You can also define similar actions for other operators by using the function idlwave-action-and-binding in the mode hook.  For example, to enforce space padding of the + and * operators, try this in .emacs

     (add-hook 'idlwave-mode-hook
       (lambda ()
          (setq idlwave-surround-by-blank t)  ; Turn this type of actions on
          (idlwave-action-and-binding "*" '(idlwave-surround 1 1))
          (idlwave-action-and-binding "+" '(idlwave-surround 1 1))))

 -- User Option: idlwave-surround-by-blank (nil)
     Non-nil means, enable idlwave-surround.  If non-nil, =, <, >, &, ,, -> are surrounded with spaces by idlwave-surround.

 -- User Option: idlwave-pad-keyword (t)
     Non-nil means pad = for keywords like assignments.

Case Changes
------------

Actions can be used to change the case of reserved words or expanded abbreviations by customizing the variables idlwave-abbrev-change-case and idlwave-reserved-word-upcase.  If you want to change the case of additional words automatically, put something like the following into your .emacs file:

     (add-hook 'idlwave-mode-hook
       (lambda ()
          ;;  Capitalize system vars
          (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
          ;;  Capitalize procedure name
          (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
                                      '(capitalize-word 1) t)
          ;;  Capitalize common block name
          (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
                                      '(capitalize-word 1) t)))

For more information, see the documentation string for the function idlwave-action-and-binding.

 -- User Option: idlwave-abbrev-change-case (nil)
     Non-nil means all abbrevs will be forced to either upper or lower case.  Legal values are nil, t, and down.

 -- User Option: idlwave-reserved-word-upcase (nil)
     Non-nil means, reserved words will be made upper case via abbrev expansion.

Documentation Header
====================

The command C-c C-h inserts a standard routine header into the buffer, with the usual fields for documentation.  One of the keywords is MODIFICATION HISTORY under which the changes to a routine can be recorded.  The command C-c C-m jumps to the MODIFICATION HISTORY of the current routine or file and inserts the user name with a timestamp.

 -- User Option: idlwave-file-header
     The doc-header template or a path to a file containing it.

 -- User Option: idlwave-timestamp-hook
     The hook function used to update the timestamp of a function.

 -- User Option: idlwave-doc-modifications-keyword
     The modifications keyword to use with the log documentation commands.

 -- User Option: idlwave-doclib-start
     Regexp matching the start of a document library header.

 -- User Option: idlwave-doclib-end
     Regexp matching the start of a document library header.

Motion Commands
===============

Several commands allow to move quickly through the structure of an IDL program.  These are

C-M-a
Beginning of subprogram
C-M-e
End of subprogram
C-c {
Beginning of block (stay inside the block)
C-c }
End of block (stay inside the block)
M-C-n
Forward block (on same level)
M-C-p
Backward block (on same level)
M-C-d
Down block (enters a block)
M-C-u
Backward up block (leaves a block)
C-c C-n
Next Statement

Miscellaneous Options
=====================

 -- User Option: idlwave-help-application
     The external application providing reference help for programming.

 -- User Option: idlwave-startup-message (t)
     Non-nil means display a startup message when idlwave-mode' is first called.

 -- User Option: idlwave-mode-hook
     Normal hook.  Executed when a buffer is put into idlwave-mode.

 -- User Option: idlwave-load-hook
     Normal hook.  Executed when idlwave.el is loaded.

The IDLWAVE Shell
*****************

The IDLWAVE shell is an Emacs major mode which allows to run the IDL program as an inferior process of Emacs.  It can be used to work with IDL interactively, to compile and run IDL programs in Emacs buffers and to debug these programs.  The IDLWAVE shell uses comint, an Emacs packages which handles the communication with the IDL program. Unfortunately IDL for Windows and MacOS does not allow the interaction with Emacs (Please inform the maintainer if you come up with a way to make the IDLWAVE shell work on these systems.) - so the IDLWAVE shell only works under Unix.

Starting the Shell
==================

The IDLWAVE shell can be started with the command M-x idlwave-shell.  In idlwave-mode the function is bound to C-c C-s.  It creates a buffer *idl* which is used to interact with the shell.  If the shell is already running, C-c C-s will simple switch to the shell buffer.  The command C-c C-l (idlwave-shell-recenter-shell-window) displays the shell window without selecting it.

In order to create a separate frame for the IDLWAVE shell buffer, call idlwave-shell with a prefix argument: C-u C-c C-s or C-u C-c C-l.  If you always want a dedicated frame for the shell window, configure the variable idlwave-shell-use-dedicated-frame.

The shell can also be started automatically when another command tries to send a command to it.  To enable auto start, set the variable idlwave-shell-automatic-start to t.

 -- User Option: idlwave-shell-explicit-file-name
     This is the command to run IDL.

 -- User Option: idlwave-shell-command-line-options
     A list of command line options for calling the IDL program.

 -- User Option: idlwave-shell-prompt-pattern
     Regexp to match IDL prompt at beginning of a line.

 -- User Option: idlwave-shell-process-name
     Name to be associated with the IDL process.

 -- User Option: idlwave-shell-automatic-start
     Non-nil means attempt to invoke idlwave-shell if not already running.

 -- User Option: idlwave-shell-initial-commands
     Initial commands, separated by newlines, to send to IDL.

 -- User Option: idlwave-shell-use-dedicated-frame (nil)
     Non-nil means, IDLWAVE should use a special frame to display shell buffer.

 -- User Option: idlwave-shell-frame-parameters
     The frame parameters for a dedicated idlwave-shell frame.

 -- User Option: idlwave-shell-temp-pro-prefix
     The prefix for temporary IDL files used when compiling regions.

 -- User Option: idlwave-shell-mode-hook
     Hook for customizing idlwave-shell-mode.

Using the Shell
===============

The IDLWAVE shell works in the same fashion as other shell modes in Emacs.  It provides command history, command line editing and job control.  Here is a list of commonly used commands, see the Emacs documentation on comint for additional information.

M-p
Cycle backwards in input history matching input
M-n
Cycle forwards
M-r
Previous input matching a regexp
M-s
Next input that matches a regexp
return
Send input or copy line to current prompt
C-c C-a
Beginning of line; skip prompt
C-c C-u
Kill input to beginning of line
C-c C-w
Kill word before cursor
C-c C-c
Send ^C
C-c C-z
Send ^Z
C-c C-\
Send ^\
C-c C-o
Delete last batch of process output
C-c C-r
Show last batch of process output
C-c C-l
List input history

In addition to these standard comint commands, idlwave-shell-mode has some bindings which correspond to similar commands in idlwave-mode.  See Routine Info and Completion for more information on these commands.

TAB
Completion of file names, routine names and keywords
(idlwave-shell-complete)
M-TAB
Same as TAB
C-c ?
Routine Info display (idlwave-routine-info)
M-?
IDL online help on routine (idlwave-routine-info-from-idlhelp)
C-c C-i
Update routine info from buffers and shell
(idlwave-update-routine-info)
C-c C-v
Find the source file of a routine (idlwave-find-module)
C-c =
Compile a library routine (idlwave-resolve)

 -- User Option: idlwave-shell-file-name-chars
     The characters allowed in file names, as a string.  Used for file name completion.

Debugging IDL Programs
======================

Programs can be compiled, run, and debugged directly from the source buffer in Emacs.  The IDLWAVE shell installs keybindings both in the shell buffer and in all IDL code buffers of the current Emacs session. On Emacs versions which support this, it also installs a debugging toolbar.  The display of the toolbar can be toggled with C-c C-d C-t (idlwave-shell-toggle-toolbar).

The debugging keybindings are by default on the prefix key C-c C-d, so for example setting a breakpoint is done with C-c C-d C-b.  If you find this too much work and your ALT key is still available, turn on the variable idlwave-shell-activate-alt-keybindings in order to get breakpoint setting on A-b.  In the remainder of this chapter we will assume that the C-c C-d bindings are active.

 -- User Option: idlwave-shell-prefix-key
     The prefix key for the debugging map idlwave-shell-mode-prefix-map.

 -- User Option: idlwave-shell-activate-prefix-keybindings (t)
     Non-nil means, debug commands will be bound to the prefix key, like C-c C-d C-b.

 -- User Option: idlwave-shell-activate-alt-keybindings (nil)
     Non-nil means, debug commands will be bound to alternate keys, like A-b.

 -- User Option: idlwave-shell-use-toolbar (t)
     Non-nil means, use the debugging toolbar in all IDL related buffers.

Compiling Programs
------------------

In order to compile the current buffer under the IDLWAVE shell, press C-c C-d C-c (idlwave-save-and-run).  This first saves the current buffer and then send the command .run path/to/file to the shell.  You can laso execute C-c C-d C-c from the shell buffer, in which case the most recently compiled buffer will be saved and re-compiled.

When developing or debugging a program, it is often necessary to execute the same command line many times.  A convenient way to do this is C-c C-d C-y (idlwave-shell-execute-default-command-line). This command first resets IDL from a state of interrupted execution by closing all files and returning to the main interpreter level.  Then a default command line is send to the shell.  To edit the default command line, call idlwave-shell-execute-default-command-line with a prefix argument: C-u C-c C-d C-y.

 -- User Option: idlwave-shell-mark-stop-line (t)
     Non-nil means, mark the source code line where IDL is currently stopped.  The value decides about the preferred method.  Legal values are nil, t, arrow, and face.

 -- User Option: idlwave-shell-overlay-arrow
     The overlay arrow to display at source lines where execution halts.

 -- User Option: idlwave-shell-stop-line-face
     The face which highlights the source line where IDL is stopped.

Breakpoints and Stepping
------------------------

You can set breakpoints and step through a program with IDLWAVE. Setting a breakpoint in the current line of the source buffer is done with C-c C-d C-b (idlwave-shell-break-here).  With a prefix arg of 1, the breakpoint gets a /ONCE keyword, meaning that it will be deleted after first use.  With a numeric prefix greater than one, the breakpoint will only be active the nth time it is hit. To clear the breakpoint in the current line, use C-c C-d C-d (idlwave-clear-current-bp).  To clear all breakpoints, use C-c C-d C-a (idlwave-clear-all-bp).  Breakpoint lines are highlighted in the source code.

Once the program has stopped somewhere, you can step through it.  Here is a summary of the breakpoint and stepping commands:

C-c C-d C-b
Set breakpoint (idlwave-shell-break-here)
C-c C-d C-i
Set breakpoint in function named here (idlwave-shell-break-in)
C-c C-d C-d
Clear current breakpoint (idlwave-shell-clear-current-bp)
C-c C-d C-a
Clear all breakpoints (idlwave-shell-clear-all-bp)
C-c C-d C-s
Step, into function calls (idlwave-shell-step)
C-c C-d C-n
Step, over function calls (idlwave-shell-stepover)
C-c C-d C-k
Skip one statement (idlwave-shell-skip)
C-c C-d C-u
Continue to end of block (idlwave-shell-up)
C-c C-d C-m
Continue to end of function (idlwave-shell-return)
C-c C-d C-o
Continue past end of function (idlwave-shell-out)
C-c C-d C-h
Continue to line at cursor position (idlwave-shell-to-here)
C-c C-d C-r
Continue execution to next breakpoint (idlwave-shell-cont)
C-c C-d C-up
Show higher level in calling stack (idlwave-shell-stack-up)
C-c C-d C-down
Show lower level in calling stack (idlwave-shell-stack-down)

 -- User Option: idlwave-shell-mark-breakpoints (t)
     Non-nil means, mark breakpoints in the source file buffers.  The value indicates the preferred method.  Legal values are nil, t, face, and glyph.

 -- User Option: idlwave-shell-breakpoint-face
     The face for breakpoint lines in the source code if idlwave-shell-mark-breakpoints has the value face.

Examining Variables
-------------------

When execution is stopped you can examine the values of variables.  The command C-c C-d C-p prints the expression at point, while C-c C-d ? shows help on this expression.  The expression at point is an array expression or a function call, or the contents of a pair of parenthesis.  The selected expression becomes highlighted in the source code for a short time.  Calling the above commands with a prefix argument will prompt for an expression instead of using the one at point.

I find it very convenient to bind these functions to a mouse event, so that simply clicking on an expression prints its value.  The following code binds printing an expression to a click with mouse button 2 while holding down the SHIFT key:

     (add-hook 'idlwave-shell-mode-hook
     	  (lambda()
     	    (define-key idlwave-mode-map [(shift mouse-2)]
     	      'idlwave-shell-mouse-print)))

Printing of expressions also works on higher levels of the calling stack.  This means that you can examine the values of variables and expressions inside the routine which called the current routine etc. Use the commands C-c C-d C-UP (idlwave-shell-stack-up) and C-c C-d C-DOWN (idlwave-shell-stack-down) or the corresponding toolbar buttons to move through the calling stack.  The mode line will indicate the routine and the calling stack level which define the context for printing expressions.  The following restrictions apply for all levels except the current:

  * Array expressions must use the [ ] index delimiters.  Identifiers with a ( ) will be interpreted as function calls.

  * Variable names in the expression may not start with an underscore _.

  * Printing values of expressions on higher levels of the calling stack uses the unsupported IDL routine ROUTINE_NAMES, which may or may not be available in future versions of IDL.

 -- User Option: idlwave-shell-expression-face
     The face for idlwave-shell-expression-overlay. Allows you to choose the font, color and other properties for the expression printed by IDL.

 -- User Option: idlwave-shell-print-expression-function (nil)
     A function to handle special display of evaluated expressions.

Installation
************

Installing IDLWAVE
==================

IDLWAVE is part of Emacs 21.1 and later.  It is also an XEmacs packages and can be installed from the XEmacs ftp site (ftp://ftp.xemacs.org/pub/xemacs/packages/) with the normal package management system on XEmacs 21.

You can also download IDLWAVE and install it yourself from the maintainers webpage (http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave).  Follow the instructions in the INSTALL file.

Upgrading from the old idl.el file
==================================

If you have been using the old idl.el and idl-shell.el files and would like to use IDLWAVE, you need to update your customization in .emacs.

 1. Change all variable and function prefixes from idl- to idlwave-.

 2. Remove the now invalid autoload and auto-mode-alist forms pointing to the idl.el and idl-shell.el files.

 3. If you have been using the hook function recommended in earlier versions to get a separate frame for the IDL shell, remove that command from your idlwave-shell-mode-hook.  Instead, set the variable idlwave-shell-use-dedicated-frame with

          (setq idlwave-shell-use-dedicated-frame t)

 4. The key sequence M-TAB no longer inserts a TAB character, but (as in many other Emacs modes) does completion.  Inserting a TAB is now bound to C-c SPC.

Acknowledgement
***************

idl.el and idl-shell.el were written by Chris Chase (mailto:chase@att.com).  The package was extended and renamed to IDLWAVE by the current maintainer Carsten Dominik (mailto:dominik@strw.leidenuniv.nl).

Thanks to the following people who have contributed to the development of IDLWAVE with patches, ideas, bug reports and suggestions.

  - Ulrik Dickow <dickow@nbi.dk>

  - Eric E. Dors <edors@lanl.gov>

  - Stein Vidar H. Haugan <s.v.h.haugan@astro.uio.no>

  - David Huenemoerder <dph@space.mit.edu>

  - Kevin Ivory <Kevin.Ivory@linmpi.mpg.de>

  - Xuyong Liu <liu@stsci.edu>

  - Simon Marshall <Simon.Marshall@esrin.esa.it>

  - Laurent Mugnier <mugnier@onera.fr>

  - Lubos Pochman <lubos@rsinc.com>

  - Patrick M. Ryan <pat@jaameri.gsfc.nasa.gov>

  - Marty Ryba <ryba@ll.mit.edu>

  - Phil Williams <williams@irc.chmcc.org>

  - J.D. Smith <jdsmith@astrosun.tn.cornell.edu>

  - Phil Sterne <sterne@dublin.llnl.gov>

Sources of Routine Info
***********************

In Routine Info and Completion it was shown how IDLWAVE displays the calling sequence and keywords of routines, and how it completes routine names and keywords.  For these features to work, IDLWAVE must know about the accessible routines.

Routine Definitions
===================

Routines which can be used in an IDL program can be defined in several places:

 1. System routines are defined inside IDL itself.  The source code of such routines is not accessible to the user.

 2. Routines part of the current program are defined in a file which is explicitly compiled by the user.  This file may be located on the IDL search path, but this is not certain.

 3. Library routines are defined in special files which are located somewhere on IDL's search path.  When a library routine is called for the first time, IDL will find the source file and compile it dynamically.

 4. External routines written in other languages (like Fortran or C) can be called with CALL_EXTERNAL, linked into IDL via LINKIMAGE, or included as dynamically loaded modules (DLMs).  Currently IDLWAVE cannot provide routine info and completion for external routines.

Routine Information Sources
===========================

In oder to know about as many routines as possible, IDLWAVE will do the following to collect information:

 1. It has a builtin list with the properties of the builtin IDL routines.  IDLWAVE 3.15 is distributed with a list of 1226 routines and 5229 keywords, reflecting IDL version 5.3.  This list has been created by scanning the IDL manuals and is stored in the file idlw-rinfo.el.  See Updating idlw-rinfo.el, for information how to regenerate this file for new versions of IDL.

 2. It scans all buffers of the current Emacs session for routine definitions.  This is done automatically when routine information or completion is first requested by the user.  The command C-c C-i (idlwave-update-routine-info) can be used at any time to rescan all buffers.

 3. If you have an IDLWAVE-Shell running as inferior process of the current Emacs session, IDLWAVE will query the shell for compiled routines and their arguments.  This happens automatically when routine information or completion is first requested by the user.  The command C-c C-i (idlwave-update-routine-info) can be used to ask the shell again at any time.

 4. IDLWAVE can scan all or selected library files and store the result in a file which will be automatically loaded just like idlw-rinfo.el. See Library Scan, for information how to scan library files.

 -- User Option: idlwave-scan-all-buffers-for-routine-info (t)
     Non-nil means, scan all buffers for IDL programs when updating info.  When this variable is nil, it only parses the current buffer.

 -- User Option: idlwave-query-shell-for-routine-info (t)
     Non-nil means query the shell for info about compiled routines.

Library Scan
============

IDLWAVE can extract routine information from library modules and store that information in a file.  To do this, the variable idlwave-libinfo-file needs to contain the path to a file in an existing directory (e.g. "~/idlwave_libinfo.el").  Since the file will contain lisp code, it should end in .el.  Under Windows and MacOS, you also need to specify the search path for IDL library files in the variable idlwave-library-path.  Under UNIX, this path will be automatically inferred from an IDLWAVE shell.

The command M-x idlwave-create-libinfo-file can then be used to scan library files.  It brings up a widget in which you can select some or all directories on the search path.  Pressing the [Scan & Save] button in the widget will scan all files in the selected directories and write the resulting routine information into the file idlwave-libinfo-file.  In order to update the library information from the same directories, call the command idlwave-update-routine-info with a double prefix argument: C-u C-u C-c C-i.  This will rescan files in the previously selected directories, write an updated version of the libinfo file and rebuild IDLWAVEs internal lists.

A note of caution:  Depending on your local installation, the IDL library can be very large.  Parsing it for routine information will take time and loading this information into Emacs can require a significant amount of memory.

A routine which is both in the library listing and compiled under the shell will show up twice in the *Completions* listing.  This is usually not a serious problem.  However, if you have scanned the part of the library relevant for you, and if you are not compiling files which are not on the library search path, the information about compiled routines is in fact unnecessary.  In this case, you can turn off the shell query for compiled routines with the variable idlwave-query-shell-for-routine-info.

 -- User Option: idlwave-libinfo-file
     File for routine information of the IDL library.

 -- User Option: idlwave-library-path
     IDL library path for Windows and MacOS.  Not needed under Unix.

Updating idlw-rinfo.el
======================

The file idlw-rinfo.el contains the routine information for the routines build into IDL.  This constant depends upon the version of IDL.  If you are lucky, the maintainer of IDLWAVE will always have access to the newest version of IDL and provide updates of idlw-rinfo.el reflecting the currently released version of IDL.  The IDLWAVE package also contains a Perl program get_rinfo which constructs this file by scanning selected files from the IDL documentation.  The program needs pdftotext by Derek B. Noonburg. Instructions on how to use get_rinfo are in the program itself.

Configuration Examples
**********************

Question: So now you have all these complicated configuration options in your package, but which ones do you as the maintainer actually set in your own configuration?

Answer: Hardly any.  As the maintainer, I set the default of most options to what I think is best.  However, the default settings do not turn on features which

  - are not self-evident (i.e. too magic) when used by an unsuspecting user

  - are too intrusive

  - will not work properly on all Emacs installations out there

  - break with what I think are widely used standards.

To see what I mean, here is the entire configuration I have in my .emacs:

     (setq idlwave-shell-activate-alt-keybindings t
           idlwave-expand-generic-end t
           idlwave-store-inquired-class t
           idlwave-shell-automatic-start t
           idlwave-libinfo-file "~/lib/idl/libinfo.el"
           idlwave-main-block-indent 2)
     (add-hook 'idlwave-shell-mode-hook
               (lambda()
                 (define-key idlwave-mode-map [(shift button1)]
                   'idlwave-shell-mouse-print)
                 (define-key idlwave-mode-map [(shift button2)]
                   'idlwave-shell-mouse-help)))

However, if you are an Emacs power-user and want IDLWAVE to work completely differently, the options allow you to change almost every aspect of it.  Here is an example of a much more extensive configuration of IDLWAVE.  To say it again - this is not what I recommend, but the user is King!

     ;;; Settings for IDLWAVE mode

     (setq idlwave-block-indent 3)           ; Indentation settings
     (setq idlwave-main-block-indent 3)
     (setq idlwave-end-offset -3)
     (setq idlwave-continuation-indent 1)
     (setq idlwave-begin-line-comment "^;[^;]")  ; Leave ";" but not ";;"
                                                 ; anchored at start of line.
     (setq idlwave-surround-by-blank t)      ; Turn on padding ops =,<,>
     (setq idlwave-pad-keyword nil)          ; Remove spaces for keyword '='
     (setq idlwave-expand-generic-end t)     ; convert END to ENDIF etc...
     (setq idlwave-reserved-word-upcase t)   ; Make reserved words upper case
                                             ; (with abbrevs only)
     (setq idlwave-abbrev-change-case nil)   ; Don't force case of expansions
     (setq idlwave-hang-indent-regexp ": ")  ; Change from "- " for auto-fill
     (setq idlwave-show-block nil)           ; Turn off blinking to begin
     (setq idlwave-abbrev-move t)            ; Allow abbrevs to move point

     ;; Some setting can only be done from a mode hook.  Here is an example:

     (add-hook 'idlwave-mode-hook
       (lambda ()
         (setq abbrev-mode 1)                 ; Turn on abbrevs (-1 for off)
         (setq case-fold-search nil)          ; Make searches case sensitive
         ;; Run other functions here
         (font-lock-mode 1)                   ; Turn on font-lock mode
         (idlwave-auto-fill-mode 0)           ; Turn off auto filling
         ;;
         ;; Pad with with 1 space (if -n is used then make the
         ;; padding a minimum of n spaces.)  The defaults use -1
         ;; instead of 1.
         (idlwave-action-and-binding "=" '(idlwave-expand-equal 1 1))
         (idlwave-action-and-binding "<" '(idlwave-surround 1 1))
         (idlwave-action-and-binding ">" '(idlwave-surround 1 1 '(?-)))
         (idlwave-action-and-binding "&" '(idlwave-surround 1 1))
         ;;
         ;; Only pad after comma and with exactly 1 space
         (idlwave-action-and-binding "," '(idlwave-surround nil 1))
         (idlwave-action-and-binding "&" '(idlwave-surround 1 1))
         ;;
         ;; Pad only after `->', remove any space before the arrow
         (idlwave-action-and-binding "->"  '(idlwave-surround 0 -1 nil 2))
         ;;;
         ;; Set some personal bindings
         ;; (In this case, makes `,' have the normal self-insert behavior.)
         (local-set-key "," 'self-insert-command)
         ;; Create a newline, indenting the original and new line.
         ;; A similar function that does _not_ reindent the original
         ;; line is on "\C-j" (The default for emacs programming modes).
         (local-set-key "\n" 'idlwave-newline)
         ;; (local-set-key "\C-j" 'idlwave-newline) ; My preference.
         ))

     ;;; Settings for IDLWAVE SHELL mode

     (setq idlwave-shell-overlay-arrow "=>")        ; default is ">"
     (setq idlwave-shell-use-dedicated-frame t)     ; Make a dedicated frame
     (setq idlwave-shell-prompt-pattern "^WAVE> ")  ; default is "^IDL> "
     (setq idlwave-shell-explicit-file-name "wave")
     (setq idlwave-shell-process-name "wave")
     (setq idlwave-shell-use-toolbar nil)           ; No toolbar