Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 5d7b645a67
Fetching contributors…

Cannot retrieve contributors at this time

9398 lines (8550 sloc) 352.153 kB
;; idlwave.el --- IDL editing mode for GNU Emacs
;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
;; 2008, 2009, 2010 Free Software Foundation, Inc.
;; Authors: J.D. Smith <jdsmith _AT_ alum.mit.edu>
;; Carsten Dominik <dominik _AT_ science.uva.nl>
;; Chris Chase <chase _AT_ att.com>
;; Maintainer: J.D. Smith <jdsmith _AT_ alum.mit.edu>
;; Version: VERSIONTAG
;; Keywords: languages
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; IDLWAVE enables feature-rich development and interaction with IDL,
;; the Interactive Data Language, produced by Research Systems, Inc.
;; It provides a compelling, full-featured alternative to the IDLDE
;; development environment bundled with IDL.
;; In the remotely distant past, based on pascal.el, though bears
;; little resemblance to it now.
;;
;; Incorporates many ideas, such as abbrevs, action routines, and
;; continuation line indenting, from wave.el.
;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
;;
;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
;; for features, key bindings, and info.
;; Also, Info format documentation is available with `M-x idlwave-info'
;;
;; New versions of IDLWAVE, documentation, and more information
;; available from:
;; http://idlwave.org
;;
;; INSTALLATION
;; ============
;;
;; Follow the instructions in the INSTALL file of the distribution.
;; In short, put this file on your load path and add the following
;; lines to your .emacs file:
;;
;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
;;
;;
;; SOURCE
;; ======
;;
;; The newest version of this file is available from the maintainer's
;; Webpage:
;;
;; http://idlwave.org
;;
;; DOCUMENTATION
;; =============
;;
;; IDLWAVE is documented online in info format. A printable version
;; of the documentation is available from the maintainers webpage (see
;; SOURCE).
;;
;;
;; ACKNOWLEDGMENTS
;; ===============
;;
;; Thanks to the following people for their contributions and comments:
;;
;; Ulrik Dickow <dickow_at_nbi.dk>
;; Eric E. Dors <edors_at_lanl.gov>
;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
;; David Huenemoerder <dph_at_space.mit.edu>
;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
;; Dick Jackson <dick_at_d-jackson.com>
;; Xuyong Liu <liu_at_stsci.edu>
;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
;; Laurent Mugnier <mugnier_at_onera.fr>
;; Lubos Pochman <lubos_at_rsinc.com>
;; Bob Portmann <portmann_at_al.noaa.gov>
;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
;; Marty Ryba <ryba_at_ll.mit.edu>
;; Paul Sorenson <aardvark62_at_msn.com>
;; Phil Sterne <sterne_at_dublin.llnl.gov>
;; Phil Williams <williams_at_irc.chmcc.org>
;;
;; CUSTOMIZATION:
;; =============
;;
;; IDLWAVE has extensive customize support; to learn about the
;; variables which control the mode's behavior, use `M-x
;; idlwave-customize'.
;;
;; You can set your own preferred values with Customize, or with Lisp
;; code in .emacs. For an example of what to put into .emacs, check
;; the TexInfo documentation or see a complete .emacs available at the
;; website.
;;
;; KNOWN PROBLEMS:
;; ==============
;;
;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
;; Numerics, Inc. is growing less and less complete as the two
;; languages grow increasingly apart. The mode probably shouldn't
;; even have "WAVE" in its title, but it's catchy, and was required
;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
;;
;; Moving the point backwards in conjunction with abbrev expansion
;; does not work as I would like it, but this is a problem with
;; emacs abbrev expansion done by the self-insert-command. It ends
;; up inserting the character that expanded the abbrev after moving
;; point backward, e.g., "\cl" expanded with a space becomes
;; "LONG( )" with point before the close paren. This is solved by
;; using a temporary function in `post-command-hook' - not pretty,
;; but it works.
;;
;; Tabs and spaces are treated equally as whitespace when filling a
;; comment paragraph. To accomplish this, tabs are permanently
;; replaced by spaces in the text surrounding the paragraph, which
;; may be an undesirable side-effect. Replacing tabs with spaces is
;; limited to comments only and occurs only when a comment
;; paragraph is filled via `idlwave-fill-paragraph'.
;;
;; Muti-statement lines (using "&") on block begin and end lines can
;; ruin the formatting. For example, multiple end statements on a
;; line: endif & endif. Using "&" outside of block begin/end lines
;; should be okay.
;;
;; Determining the expression at point for printing and other
;; examination commands is somewhat rough: currently only fairly
;; simple entities are found. You can always drag-select or examine
;; a pre-selected region.
;;
;; When forcing completion of method keywords, the initial
;; query for a method has multiple entries for some methods. Would
;; be too difficult to fix this hardly used case.
;;
;;; Code:
(eval-when-compile (require 'cl))
(require 'idlw-help)
;; For XEmacs
(unless (fboundp 'line-beginning-position)
(defalias 'line-beginning-position 'point-at-bol))
(unless (fboundp 'line-end-position)
(defalias 'line-end-position 'point-at-eol))
(unless (fboundp 'char-valid-p)
(defalias 'char-valid-p 'characterp))
(unless (fboundp 'match-string-no-properties)
(defalias 'match-string-no-properties 'match-string))
(if (not (fboundp 'cancel-timer))
(condition-case nil
(require 'timer)
(error nil)))
(declare-function idlwave-shell-get-path-info "idlw-shell")
(declare-function idlwave-shell-temp-file "idlw-shell")
(declare-function idlwave-shell-is-running "idlw-shell")
(declare-function widget-value "wid-edit" (widget))
(declare-function comint-dynamic-complete-filename "comint" ())
(defgroup idlwave nil
"Major mode for editing IDL .pro files."
:tag "IDLWAVE"
:link '(url-link :tag "Home Page"
"http://idlwave.org")
:link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
"idlw-shell.el")
:link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
:link '(custom-manual "(idlwave)Top")
:prefix "idlwave"
:group 'languages)
;;; Variables for indentation behavior ---------------------------------------
(defgroup idlwave-code-formatting nil
"Indentation and formatting options for IDLWAVE mode."
:group 'idlwave)
(defcustom idlwave-main-block-indent 2
"*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."
:group 'idlwave-code-formatting
:type 'integer)
(defcustom idlwave-block-indent 3
"*Extra indentation applied to block lines.
If you change this, you probably also want to change `idlwave-end-offset'."
:group 'idlwave-code-formatting
:type 'integer)
(defcustom idlwave-end-offset -3
"*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."
:group 'idlwave-code-formatting
:type 'integer)
(defcustom idlwave-continuation-indent 3
"*Extra indentation applied to continuation lines.
This extra offset applies to the first of a set of continuation lines.
The following lines receive the same indentation as the first."
:group 'idlwave-code-formatting
:type 'integer)
(defcustom idlwave-max-extra-continuation-indent 40
"*Maximum additional indentation for special continuation indent.
Several special indentations are tried to help line up continuation
lines in routine calls or definitions, other statements with
parentheses, or assignment statements. This variable specifies a
maximum amount by which this special indentation can exceed the
standard continuation indentation, otherwise defaulting to a fixed
offset. Set to 0 to effectively disable all special continuation
indentation, or to a large number (like 100) to enable it in all
cases. See also `idlwave-indent-to-open-paren', which can override
this variable."
:group 'idlwave-code-formatting
:type 'integer)
(defcustom idlwave-indent-to-open-paren t
"*Non-nil means, indent continuation lines to innermost open parenthesis.
This indentation occurs even if otherwise disallowed by
`idlwave-max-extra-continuation-indent'. Matching parens and the
interleaving args are lined up. Example:
x = function_a(function_b(function_c( a, b, [1,2,3, $
4,5,6 $
], $
c, d $
)))
When this variable is nil, paren alignment may still occur, based on
the value of `idlwave-max-extra-continuation-indent', which, if zero,
would yield:
x = function_a(function_b(function_c( a, b, [1,2,3, $
4,5,6 $
], $
c, d $
)))"
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-indent-parens-nested nil
"*Non-nil means, indent continuation lines with parens by nesting
lines at consecutively deeper levels."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-hanging-indent t
"*If set non-nil then comment paragraphs are indented under the
hanging indent given by `idlwave-hang-indent-regexp' match in the first line
of the paragraph."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-hang-indent-regexp "- "
"*Regular expression matching the position of the hanging indent
in the first line of a comment paragraph. The size of the indent
extends to the end of the match for the regular expression."
:group 'idlwave-code-formatting
:type 'regexp)
(defcustom idlwave-use-last-hang-indent nil
"*If non-nil then use last match on line for `idlwave-indent-regexp'."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-fill-comment-line-only t
"*If non-nil then auto fill will only operate on comment lines."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-auto-fill-split-string t
"*If non-nil then auto fill will split strings with the IDL `+' operator.
When the line end falls within a string, string concatenation with the
'+' operator will be used to distribute a long string over lines.
If nil and a string is split then a terminal beep and warning are issued.
This variable is ignored when `idlwave-fill-comment-line-only' is
non-nil, since in this case code is not auto-filled."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-split-line-string t
"*If non-nil then `idlwave-split-line' will split strings with `+'.
When the splitting point of a line falls inside a string, split the string
using the `+' string concatenation operator. If nil and a string is
split then a terminal beep and warning are issued."
:group 'idlwave-code-formatting
:type 'boolean)
(defcustom idlwave-no-change-comment ";;;"
"*The indentation of a comment that starts with this regular
expression will not be changed. Note that the indentation of a comment
at the beginning of a line is never changed."
:group 'idlwave-code-formatting
:type 'string)
(defcustom idlwave-begin-line-comment nil
"*A comment anchored at the beginning of line.
A comment matching this regular expression will not have its
indentation changed. If nil the default is \"^;\", i.e., any line
beginning with a \";\". Expressions for comments at the beginning of
the line should begin with \"^\"."
:group 'idlwave-code-formatting
:type '(choice (const :tag "Any line beginning with `;'" nil)
'regexp))
(defcustom 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. As a result if
the comment is not preceded by whitespace it is unchanged."
:group 'idlwave-code-formatting
:type 'regexp)
;; Comments not matching any of the above will be indented as a
;; right-margin comment, i.e., to a minimum of `comment-column'.
;;; Routine Info and Completion ---------------------------------------
(defgroup idlwave-routine-info nil
"Routine Info options for IDLWAVE mode."
:group 'idlwave)
(defcustom idlwave-use-library-catalogs t
"*Non-nil means search the IDL path for library catalog files.
These files, named .idlwave_catalog, document routine information for
individual directories and libraries of IDL .pro files. Many popular
libraries come with catalog files by default, so leaving this on is
usually a good idea."
:group 'idlwave-routine-info
:type 'boolean)
(defcustom idlwave-init-rinfo-when-idle-after 10
"*Seconds of idle time before routine info is automatically initialized.
Initializing the routine info can take a long time, in particular if a
large number of library catalogs are involved. When Emacs is idle for
more than the number of seconds specified by this variable, it starts
the initialization. The process is split into five steps, in order to
keep work interruption as short as possible. If one of the steps
finishes, and no user input has arrived in the mean time, initialization
proceeds immediately to the next step. A good value for this variable
is about 1/3 of the time initialization take in your setup. So if you
have a fast machine and no problems with a slow network connection,
don't hesitate to set this to 2 seconds. A value of 0 means, don't
initialize automatically, but instead wait until routine information is
needed, and initialize then."
:group 'idlwave-routine-info
:type 'number)
(defcustom idlwave-scan-all-buffers-for-routine-info t
"*Non-nil means, scan buffers for IDL programs when updating info.
The scanning is done by the command `idlwave-update-routine-info'.
The following values are allowed:
nil Don't scan any buffers.
t Scan all `idlwave-mode' buffers in the current editing session.
current Scan only the current buffer, but no other buffers."
:group 'idlwave-routine-info
:type '(choice
(const :tag "No buffer" nil)
(const :tag "All buffers" t)
(const :tag "Current buffer only" 'current)))
(defcustom idlwave-query-shell-for-routine-info t
"*Non-nil means query the shell for info about compiled routines.
Querying the shell is useful to get information about compiled modules,
and it is turned on by default. However, when you have a complete library
scan, this is not necessary."
:group 'idlwave-routine-info
:type 'boolean)
(defcustom idlwave-auto-routine-info-updates
'(find-file save-buffer kill-buffer compile-buffer)
"*Controls under what circumstances routine info is updated automatically.
Possible values:
nil Never
t All available
\(...) A list of circumstances. Allowed members are:
find-file Add info for new IDLWAVE buffers.
save-buffer Update buffer info when buffer is saved
kill-buffer Remove buffer info when buffer gets killed
compile-buffer Update shell info after `idlwave-shell-save-and...'"
:group 'idlwave-routine-info
:type '(choice
(const :tag "Never" nil)
(const :tag "As often as possible" t)
(set :tag "Checklist" :greedy t
(const :tag "When visiting a file" find-file)
(const :tag "When saving a buffer" save-buffer)
(const :tag "After a buffer was killed" kill-buffer)
(const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
(defcustom idlwave-rinfo-max-source-lines 5
"*Maximum number of source files displayed in the Routine Info window.
When an integer, it is the maximum number of source files displayed.
A value of t means to show all source files."
:group 'idlwave-routine-info
:type 'integer)
(defcustom idlwave-library-path nil
"Library path for Windows and MacOS (OS9). Not needed under UNIX.
When selecting the directories to scan for IDL user catalog routine
info, IDLWAVE can, under UNIX, query the shell for the exact search
path \(the value of !PATH). However, under Windows and MacOS
\(pre-OSX), the IDLWAVE shell does not work. In this case, this
variable can be set to specify the paths where IDLWAVE can find PRO
files. The shell will only be asked for a list of paths when this
variable is nil. The value is a list of directories. A directory
preceeded by a `+' will be searched recursively. If you set this
variable on a UNIX system, the shell will not be queried. See also
`idlwave-system-directory'."
:group 'idlwave-routine-info
:type '(repeat (directory)))
(defcustom idlwave-system-directory ""
"The IDL system directory for Windows and MacOS. Not needed under
UNIX. Set this to the value of the `!DIR' system variable in IDL.
IDLWAVE uses this to find out which of the library routines belong to
the official system library. All files inside the `lib' subdirectory
are considered system library files - so don't install private stuff
in this directory. On UNIX systems, IDLWAVE queries the shell for the
value of `!DIR'. See also `idlwave-library-path'."
:group 'idlwave-routine-info
:type 'directory)
;; Configuration files
(defcustom idlwave-config-directory
(convert-standard-filename "~/.idlwave")
"*Directory for configuration files and user-library catalog."
:group 'idlwave-routine-info
:type 'file)
(defvar idlwave-user-catalog-file "idlusercat.el")
(defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
(defvar idlwave-path-file "idlpath.el")
(defvar idlwave-libinfo-file nil
"*Obsolete variable, no longer used.")
(defcustom idlwave-special-lib-alist nil
"Alist of regular expressions matching special library directories.
When listing routine source locations, IDLWAVE gives a short hint where
the file defining the routine is located. By default it lists `SystemLib'
for routines in the system library `!DIR/lib' and `Library' for anything
else. This variable can define additional types. The car of each entry
is a regular expression matching the file name (they normally will match
on the path). The cdr is the string to be used as identifier. Max 10
chars are allowed."
:group 'idlwave-routine-info
:type '(repeat
(cons regexp string)))
(defcustom idlwave-auto-write-paths t
"Write out path (!PATH) and system directory (!DIR) info automatically.
Path info is needed to locate library catalog files. If non-nil,
whenever the path-list changes as a result of shell-query, etc., it is
written to file. Otherwise, the menu option \"Write Paths\" can be
used to force a write."
:group 'idlwave-routine-info
:type 'boolean)
(defgroup idlwave-completion nil
"Completion options for IDLWAVE mode."
:prefix "idlwave"
:group 'idlwave)
(eval-and-compile
(defconst idlwave-tmp
'(choice :tag "by applying the function"
(const upcase)
(const downcase)
(const capitalize)
(const preserve)
(symbol :tag "Other"))))
(defcustom idlwave-completion-case '((routine . upcase)
(keyword . upcase)
(class . preserve)
(method . preserve))
"Association list setting the case of completed words.
This variable determines the case (UPPER/lower/Capitalized...) of
words inserted into the buffer by completion. The preferred case can
be specified separately for routine names, keywords, classes and
methods.
This alist should therefore have entries for `routine' (normal
functions and procedures, i.e. non-methods), `keyword', `class', and
`method'. Plausible values are
upcase upcase whole word, like `BOX_CURSOR'
downcase downcase whole word, like `read_ppm'
capitalize capitalize each part, like `Widget_Control'
preserve preserve case as is, like `IDLgrView'
The value can also be any Emacs Lisp function which transforms the
case of characters in a string.
A value of `preserve' means that the case of the completed word is
identical to the way it was written in the definition statement of the
routine. This was implemented to allow for mixed-case completion, in
particular of object classes and methods.
If a completable word is defined in multiple locations, the meaning of
`preserve' is not unique since the different definitions might be
cased differently. Therefore IDLWAVE always takes the case of the
*first* definition it encounters during routine info collection and
uses the case derived from it consistently.
Note that a lowercase-only string in the buffer will always be completed in
lower case (but see the variable `idlwave-completion-force-default-case').
After changing this variable, you need to either restart Emacs or press
`C-u C-c C-i' to update the internal lists."
:group 'idlwave-completion
:type `(repeat
(cons (symbol :tag "Derive completion case for")
,idlwave-tmp)))
(defcustom idlwave-completion-force-default-case nil
"*Non-nil means, completion will always honor `idlwave-completion-case'.
When nil, only the completion of a mixed case or upper case string
will honor the default settings in `idlwave-completion-case', while
the completion of lower case strings will be completed entirely in
lower case."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-complete-empty-string-as-lower-case nil
"*Non-nil means, the empty string is considered downcase for completion.
The case of what is already in the buffer determines the case of completions.
When this variable is non-nil, the empty string is considered to be downcase.
Completing on the empty string then offers downcase versions of the possible
completions."
:group 'idlwave-completion
:type 'boolean)
(defvar idlwave-default-completion-case-is-down nil
"Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
`idlwave-completion-case'.")
(defcustom idlwave-buffer-case-takes-precedence nil
"*Non-nil means, the case of tokens in buffers dominates over system stuff.
To make this possible, we need to re-case everything each time we update
the routine info from the buffers. This is slow.
The default is to consider the case given in the system and library files
first which makes updating much faster."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-highlight-help-links-in-completion t
"*Non-nil means, highlight completions for which system help is available.
Help can then be accessed with mouse-3.
This option is only effective when the online help system is installed."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-support-inheritance t
"Non-nil means, treat inheritance with completion, online help etc.
When nil, IDLWAVE only knows about the native methods and tags of a class,
not about inherited ones."
:group 'idlwave-routine-info
:type 'boolean)
(defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
"List of regular expressions for class-driven keyword inheritance.
Keyword inheritance is often tied to class inheritance by \"chaining\"
up the class tree. While it cannot be assumed that the presence of an
_EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
certain methods this assumption is almost always true. The methods
for which to assume this can be set here."
:group 'idlwave-routine-info
:type '(repeat (regexp :tag "Match method:")))
(defcustom idlwave-complete-structure-tags t
"Whether to complete structure tags in source and shell."
:group 'idlwave-routine-info
:type 'boolean)
(defcustom idlwave-completion-show-classes 1
"*Number of classes to show when completing object methods and keywords.
When completing methods or keywords for an object with unknown class,
the *Completions* buffer will show the valid classes for each completion
like this:
MyMethod <Class1,Class2,Class3>
The value of this variable may be nil to inhibit display, or an integer to
indicate the maximum number of classes to display.
On XEmacs, a full list of classes will also be placed into a `help-echo'
property on the competion items, so that the list of classes for the current
item is displayed in the echo area. If the value of this variable is a
negative integer, the `help-echo' property will be suppressed."
:group 'idlwave-completion
:type '(choice (const :tag "Don't show" nil)
(integer :tag "Number of classes shown" 1)))
(defcustom idlwave-completion-fontify-classes t
"*Non-nil means, fontify the classes in completions buffer.
This makes it easier to distinguish the completion items from the extra
class info listed. See `idlwave-completion-show-classes'."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-query-class '((method-default . nil)
(keyword-default . nil))
"Association list governing specification of object classes for completion.
When IDLWAVE tries to complete object-oriented methods, it usually
cannot determine the class of a given object from context. In order
to provide the user with a correct list of methods or keywords, it
needs to determine the appropriate class. IDLWAVE has two ways of
doing this (well, three ways if you count the shell... see
`idlwave-shell-query-for-class'):
1. Combine the items of all available classes which contain this
method for the purpose of completion. So when completing a method,
all methods of all known classes are available, and when completing
a keyword, all keywords allowed for this method in any class are
shown. This behavior is very much like normal completion and is
therefore the default. It works much better than one might think -
only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
become uncomfortably long. See also
`idlwave-completion-show-classes'.
2. The second possibility is to ask the user on each occasion. To
make this less interruptive, IDLWAVE can store the class as a text
property on the object operator `->'. For a given object in the
source code, class selection will then be needed only once
- for example to complete the method. Keywords to the method can
then be completed directly, because the class is already known.
You will have to turn on the storage of the selected class
explicitly with the variable `idlwave-store-inquired-class'.
This variable allows you to configure IDLWAVE's method and
method-keyword completion behavior. Its value is an alist, which
should contain at least two elements: (method-default . VALUE) and
\(keyword-default . VALUE), where VALUE is either t or nil. These
specify if the class should be found during method and keyword
completion, respectively.
The alist may have additional entries specifying exceptions from the
keyword completion rule for specific methods, like INIT or
GETPROPERTY. In order to turn on class specification for the INIT
method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
:group 'idlwave-completion
:type '(list
(cons (const method-default)
(boolean :tag "Determine class when completing METHODS "))
(cons (const keyword-default)
(boolean :tag "Determine class when completing KEYWORDS "))
(repeat
:tag "Exceptions to defaults"
:inline t
(cons (string :tag "MODULE" :value "")
(boolean :tag "Determine class for this method")))))
(defcustom idlwave-store-inquired-class t
"*Non-nil means, store class of a method call as text property on `->'.
IDLWAVE sometimes has to ask the user for the class associated with a
particular object method call. This happens during the commands
`idlwave-routine-info' and `idlwave-complete', depending upon the
value of the variable `idlwave-query-class'.
When you specify a class, this information can be stored as a text
property on the `->' arrow in the source code, so that during the same
editing session, IDLWAVE will not have to ask again. When this
variable is non-nil, IDLWAVE will store and reuse the class information.
The class stored can be checked and removed with `\\[idlwave-routine-info]'
on the arrow.
The default of this variable is nil, since the result of commands then
is more predictable. However, if you know what you are doing, it can
be nice to turn this on.
An arrow which knows the class will be highlighted with
`idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
displays (with prefix arg: deletes) the class stored on the arrow
at point."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-class-arrow-face 'bold
"*Face to highlight object operator arrows `->' which carry a class property.
When IDLWAVE stores a class name as text property on an object arrow
\(see variable `idlwave-store-inquired-class', it highlights the arrow
with this font in order to remind the user that this arrow is special."
:group 'idlwave-completion
:type 'symbol)
(defcustom idlwave-resize-routine-help-window t
"*Non-nil means, resize the Routine-info *Help* window to fit the content."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-keyword-completion-adds-equal t
"*Non-nil means, completion automatically adds `=' after completed keywords."
:group 'idlwave-completion
:type 'boolean)
(defcustom idlwave-function-completion-adds-paren t
"*Non-nil means, completion automatically adds `(' after completed function.
nil means, don't add anything.
A value of `2' means, also add the closing parenthesis and position cursor
between the two."
:group 'idlwave-completion
:type '(choice (const :tag "Nothing" nil)
(const :tag "(" t)
(const :tag "()" 2)))
(defcustom idlwave-completion-restore-window-configuration t
"*Non-nil means, try to restore the window configuration after completion.
When completion is not unique, Emacs displays a list of completions.
This messes up your window configuration. With this variable set, IDLWAVE
restores the old configuration after successful completion."
:group 'idlwave-completion
:type 'boolean)
;;; Variables for abbrev and action behavior -----------------------------
(defgroup idlwave-abbrev-and-indent-action nil
"IDLWAVE performs actions when expanding abbreviations or indenting lines.
The variables in this group govern this."
:group 'idlwave)
(defcustom idlwave-do-actions nil
"*Non-nil means performs actions when indenting.
The actions that can be performed are listed in `idlwave-indent-action-table'."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-abbrev-start-char "\\"
"*A single character string used to start abbreviations in abbrev mode.
Possible characters to chose from: ~`\%
or even '?'. '.' is not a good choice because it can make structure
field names act like abbrevs in certain circumstances.
Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
must set it directly using `setq' in the .emacs file before idlwave.el
is loaded."
:group 'idlwave-abbrev-and-indent-action
:type 'string)
(defcustom idlwave-surround-by-blank nil
"*Non-nil means, enable `idlwave-surround'.
If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
`idlwave-surround'.
See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
Also see the default key bindings for keys using `idlwave-surround'.
Keys are bound and made into actions calling `idlwave-surround' with
`idlwave-action-and-binding'.
See help for `idlwave-action-and-binding' for examples.
Also see help for `idlwave-surround'."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-pad-keyword t
"*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
Whenever `idlwave-surround' is non-nil then this affects how '=' is
padded for keywords and for variables. If t, pad the same as for
assignments. If nil then spaces are removed. With any other value,
spaces are left unchanged."
:group 'idlwave-abbrev-and-indent-action
:type '(choice
(const :tag "Pad like assignments" t)
(const :tag "Remove space near `='" nil)
(const :tag "Keep space near `='" 'keep)))
(defcustom idlwave-show-block t
"*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-expand-generic-end nil
"*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-reindent-end t
"*Non-nil means re-indent line after END was typed."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-abbrev-move t
"*Non-nil means the abbrev hook can move point.
Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
definitions, use the command `list-abbrevs', for abbrevs that move
point. Moving point is useful, for example, to place point between
parentheses of expanded functions.
See `idlwave-check-abbrev'."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-abbrev-change-case nil
"*Non-nil means all abbrevs will be forced to either upper or lower case.
If the value t, all expanded abbrevs will be upper case.
If the value is 'down then abbrevs will be forced to lower case.
If nil, the case will not change.
If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
upper case, regardless of this variable."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
(defcustom idlwave-reserved-word-upcase nil
"*Non-nil means, reserved words will be made upper case via abbrev expansion.
If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
Has effect only if in abbrev-mode."
:group 'idlwave-abbrev-and-indent-action
:type 'boolean)
;;; Action/Expand Tables.
;;
;; The average user may have difficulty modifying this directly. It
;; can be modified/set in idlwave-mode-hook, but it is easier to use
;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
;; examples of how to add an action.
;;
;; The action table is used by `idlwave-indent-line' whereas both the
;; action and expand tables are used by `idlwave-indent-and-action'. In
;; general, the expand table is only used when a line is explicitly
;; indented. Whereas, in addition to being used when the expand table
;; is used, the action table is used when a line is indirectly
;; indented via line splitting, auto-filling or a new line creation.
;;
;; Example actions:
;;
;; 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)
;; Capitalize label
;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
;; '(capitalize-word -1) t)
(defvar idlwave-indent-action-table nil
"*Associated array containing action lists of search string (car),
and function as a cdr. This table is used by `idlwave-indent-line'.
See documentation for `idlwave-do-action' for a complete description of
the action lists.
Additions to the table are made with `idlwave-action-and-binding' when a
binding is not requested.
See help on `idlwave-action-and-binding' for examples.")
(defvar idlwave-indent-expand-table nil
"*Associated array containing action lists of search string (car),
and function as a cdr. The table is used by the
`idlwave-indent-and-action' function. See documentation for
`idlwave-do-action' for a complete description of the action lists.
Additions to the table are made with `idlwave-action-and-binding' when a
binding is requested.
See help on `idlwave-action-and-binding' for examples.")
;;; Documentation header and history keyword ---------------------------------
(defgroup idlwave-documentation nil
"Options for documenting IDLWAVE files."
:group 'idlwave)
;; FIXME: make defcustom?
(defvar idlwave-file-header
(list nil
";+
; NAME:
;
;
;
; PURPOSE:
;
;
;
; CATEGORY:
;
;
;
; CALLING SEQUENCE:
;
;
;
; INPUTS:
;
;
;
; OPTIONAL INPUTS:
;
;
;
; KEYWORD PARAMETERS:
;
;
;
; OUTPUTS:
;
;
;
; OPTIONAL OUTPUTS:
;
;
;
; COMMON BLOCKS:
;
;
;
; SIDE EFFECTS:
;
;
;
; RESTRICTIONS:
;
;
;
; PROCEDURE:
;
;
;
; EXAMPLE:
;
;
;
; MODIFICATION HISTORY:
;
;-
")
"*A list (PATHNAME STRING) specifying the doc-header template to use for
summarizing a file. If PATHNAME is non-nil then this file will be included.
Otherwise STRING is used. If nil, the file summary will be omitted.
For example you might set PATHNAME to the path for the
lib_template.pro file included in the IDL distribution.")
(defcustom idlwave-header-to-beginning-of-file t
"*Non-nil means, the documentation header will always be at start of file.
When nil, the header is positioned between the PRO/FUNCTION line of
the current routine and the code, allowing several routine headers in
a file."
:group 'idlwave-documentation
:type 'boolean)
(defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
"*The hook function used to update the timestamp of a function."
:group 'idlwave-documentation
:type 'function)
(defcustom idlwave-doc-modifications-keyword "HISTORY"
"*The modifications keyword to use with the log documentation commands.
A ':' is added to the keyword end.
Inserted by doc-header and used to position logs by doc-modification.
If nil it will not be inserted."
:group 'idlwave-documentation
:type 'string)
(defcustom idlwave-doclib-start "^;+\\+"
"*Regexp matching the start of a document library header."
:group 'idlwave-documentation
:type 'regexp)
(defcustom idlwave-doclib-end "^;+-"
"*Regexp matching the end of a document library header."
:group 'idlwave-documentation
:type 'regexp)
;;; External Programs -------------------------------------------------------
(defgroup idlwave-external-programs nil
"Path locations of external commands used by IDLWAVE."
:group 'idlwave)
(defcustom idlwave-shell-explicit-file-name "idl"
"*If non-nil, this is the command to run IDL.
Should be an absolute file path or path relative to the current environment
execution search path. If you want to specify command line switches
for the IDL program, use `idlwave-shell-command-line-options'.
I know the name of this variable is badly chosen, but I cannot change
it without compromising backwards-compatibility."
:group 'idlwave-external-programs
:type 'string)
(defcustom idlwave-shell-command-line-options nil
"*A list of command line options for calling the IDL program.
Since IDL is executed directly without going through a shell like /bin/sh,
this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
string for each argument. But you may also give a single string which
contains the options whitespace-separated. Emacs will be kind enough to
split it for you."
:type '(choice
string
(repeat (string :value "")))
:group 'idlwave-external-programs)
(defcustom idlwave-help-application "idlhelp"
"*The external application providing reference help for programming.
Obsolete, if the IDL Assistant is being used for help."
:group 'idlwave-external-programs
:type 'string)
;;; Some Shell variables which must be defined here.-----------------------
(defcustom idlwave-shell-debug-modifiers '()
"List of modifiers to be used for the debugging commands.
Will be used to bind debugging commands in the shell buffer and in all
source buffers. These are additional convenience bindings, the debugging
commands are always available with the `C-c C-d' prefix.
If you set this to '(control shift), this means setting a breakpoint will
be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
are `control', `meta', `super', `hyper', `alt', and `shift'."
:group 'idlwave-shell-general-setup
:type '(set :tag "Specify modifiers"
(const control)
(const meta)
(const super)
(const hyper)
(const alt)
(const shift)))
(defcustom idlwave-shell-automatic-start nil
"*If non-nil attempt invoke `idlwave-shell' if not already running.
This is checked when an attempt to send a command to an
IDL process is made."
:group 'idlwave-shell-general-setup
:type 'boolean)
;;; Miscellaneous variables -------------------------------------------------
(defgroup idlwave-misc nil
"Miscellaneous options for IDLWAVE mode."
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
:group 'idlwave)
(defcustom idlwave-startup-message t
"*Non-nil displays a startup message when `idlwave-mode' is first called."
:group 'idlwave-misc
:type 'boolean)
(defcustom idlwave-default-font-lock-items
'(pros-and-functions batch-files idlwave-idl-keywords label goto
common-blocks class-arrows)
"Items which should be fontified on the default fontification level 2.
IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
is everything and level 2 is specified by this list.
This variable must be set before IDLWAVE gets loaded.
It is a list of symbols; the following symbols are allowed:
pros-and-functions Procedure and Function definitions
batch-files Batch Files
idlwave-idl-keywords IDL Keywords
label Statement Labels
goto Goto Statements
common-blocks Common Blocks
keyword-parameters Keyword Parameters in routine definitions and calls
system-variables System Variables
fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
class-arrows Object Arrows with class property"
:group 'idlwave-misc
:type '(set
:inline t :greedy t
(const :tag "Procedure and Function definitions" pros-and-functions)
(const :tag "Batch Files" batch-files)
(const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
(const :tag "Statement Labels" label)
(const :tag "Goto Statements" goto)
(const :tag "Tags in Structure Definition" structtag)
(const :tag "Structure Name" structname)
(const :tag "Common Blocks" common-blocks)
(const :tag "Keyword Parameters" keyword-parameters)
(const :tag "System Variables" system-variables)
(const :tag "FIXME: Warning" fixme)
(const :tag "Object Arrows with class property " class-arrows)))
(defcustom idlwave-mode-hook nil
"Normal hook. Executed when a buffer is put into `idlwave-mode'."
:group 'idlwave-misc
:type 'hook)
(defcustom idlwave-load-hook nil
"Normal hook. Executed when idlwave.el is loaded."
:group 'idlwave-misc
:type 'hook)
(defvar idlwave-experimental nil
"Non-nil means turn on a few experimental features.
This variable is only for the maintainer, to test difficult stuff,
while still distributing stable releases.
As a user, you should not set this to t.")
;;;
;;; End customization variables section
;;;
;;; Non customization variables
;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
;;; and Carsten Dominik...
;; The following are the reserved words in IDL. Maybe we should
;; highlight some more stuff as well?
;; Procedure declarations. Fontify keyword plus procedure name.
(defvar idlwave-idl-keywords
;; To update this regexp, update the list of keywords and
;; evaluate the form.
;; (insert
;; (prin1-to-string
;; (concat
;; "\\<\\("
;; (regexp-opt
;; '("||" "&&" "and" "or" "xor" "not"
;; "eq" "ge" "gt" "le" "lt" "ne"
;; "for" "do" "endfor"
;; "if" "then" "endif" "else" "endelse"
;; "case" "of" "endcase"
;; "switch" "break" "continue" "endswitch"
;; "begin" "end"
;; "repeat" "until" "endrep"
;; "while" "endwhile"
;; "goto" "return"
;; "inherits" "mod"
;; "compile_opt" "forward_function"
;; "on_error" "on_ioerror")) ; on_error is not officially reserved
;; "\\)\\>")))
"\\<\\(&&\\|and\\|b\\(egin\\|reak\\)\\|c\\(ase\\|o\\(mpile_opt\\|ntinue\\)\\)\\|do\\|e\\(lse\\|nd\\(case\\|else\\|for\\|if\\|rep\\|switch\\|while\\)?\\|q\\)\\|for\\(ward_function\\)?\\|g\\(oto\\|[et]\\)\\|i\\(f\\|nherits\\)\\|l[et]\\|mod\\|n\\(e\\|ot\\)\\|o\\(n_\\(error\\|ioerror\\)\\|[fr]\\)\\|re\\(peat\\|turn\\)\\|switch\\|then\\|until\\|while\\|xor\\|||\\)\\>")
(let* (;; Procedure declarations. Fontify keyword plus procedure name.
;; Function declarations. Fontify keyword plus function name.
(pros-and-functions
'("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t)))
;; Common blocks
(common-blocks
'("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
(1 font-lock-keyword-face) ; "common"
(2 font-lock-reference-face nil t) ; block name
("[ \t]*\\(\\sw+\\)[ ,]*"
;; Start with point after block name and comma
(goto-char (match-end 0)) ; needed for XEmacs, could be nil
nil
(1 font-lock-variable-name-face) ; variable names
)))
;; Batch files
(batch-files
'("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
;; FIXME warning.
(fixme
'("\\<FIXME:" (0 font-lock-warning-face t)))
;; Labels
(label
'("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
;; The goto statement and its label
(goto
'("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
(1 font-lock-keyword-face)
(2 font-lock-reference-face)))
;; Tags in structure definitions. Note that this definition
;; actually collides with labels, so we have to use the same
;; face. It also matches named subscript ranges,
;; e.g. vec{bottom:top]. No good way around this.
(structtag
'("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
;; Structure names
(structname
'("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
(2 font-lock-function-name-face)))
;; Keyword parameters, like /xlog or ,xrange=[]
;; This is anchored to the comma preceeding the keyword.
;; Treats continuation lines, works only during whole buffer
;; fontification. Slow, use it only in fancy fontification.
(keyword-parameters
'("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
(6 font-lock-reference-face)))
;; System variables start with a bang.
(system-variables
'("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
(1 font-lock-variable-name-face)))
;; Special and unusual operators (not used because too noisy)
;; (special-operators
;; '("[<>#]" (0 font-lock-keyword-face)))
;; All operators (not used because too noisy)
;; (all-operators
;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
;; Arrows with text property `idlwave-class'
(class-arrows
'(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
(defconst idlwave-font-lock-keywords-1
(list pros-and-functions batch-files)
"Subdued level highlighting for IDLWAVE mode.")
(defconst idlwave-font-lock-keywords-2
(mapcar 'symbol-value idlwave-default-font-lock-items)
"Medium level highlighting for IDLWAVE mode.")
(defconst idlwave-font-lock-keywords-3
(list pros-and-functions
batch-files
idlwave-idl-keywords
label goto
structtag
structname
common-blocks
keyword-parameters
system-variables
class-arrows)
"Gaudy level highlighting for IDLWAVE mode."))
(defun idlwave-match-class-arrows (limit)
;; Match an object arrow with class property
(and idlwave-store-inquired-class
(re-search-forward "->" limit 'limit)
(get-text-property (match-beginning 0) 'idlwave-class)))
(defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
"Default expressions to highlight in IDLWAVE mode.")
(defvar idlwave-font-lock-defaults
'((idlwave-font-lock-keywords
idlwave-font-lock-keywords-1
idlwave-font-lock-keywords-2
idlwave-font-lock-keywords-3)
nil t
((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
beginning-of-line))
(put 'idlwave-mode 'font-lock-defaults
idlwave-font-lock-defaults) ; XEmacs
(defconst idlwave-comment-line-start-skip "^[ \t]*;"
"Regexp to match the start of a full-line comment.
That is the _beginning_ of a line containing a comment delimiter `;' preceded
only by whitespace.")
(defconst idlwave-begin-block-reg
"\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
"Regular expression to find the beginning of a block.
The case does not matter. The search skips matches in comments.")
(defconst idlwave-profun-reg "^\\s-*\\(pro\\|function\\)\\>")
(defconst idlwave-begin-unit-reg (concat idlwave-profun-reg "\\|\\`")
"Regular expression to find the beginning of a unit.
The case does not matter.")
(defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
"Regular expression to find the line that indicates the end of unit.
This line is the end of buffer or the start of another unit. The
case does not matter. The search skips matches in comments.")
(defconst idlwave-continue-line-reg "\\<\\$"
"Regular expression to match a continued line.")
(defconst idlwave-end-block-reg
"\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
"Regular expression to find the end of a block.
The case does not matter. The search skips matches found in
comments.")
(defconst idlwave-block-matches
'(("pro" . "end")
("function" . "end")
("case" . "endcase")
("else" . "endelse")
("for" . "endfor")
("then" . "endif")
("repeat" . "endrep")
("switch" . "endswitch")
("while" . "endwhile"))
"Matches between statements and the corresponding END variant.
The cars are the reserved words starting a block. If the block really
begins with BEGIN, the cars are the reserved words before the begin
which can be used to identify the block type.
This is used to check for the correct END type, to close blocks and
to expand generic end statements to their detailed form.")
(defconst idlwave-block-match-regexp
"\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
"Regular expression matching reserved words which can stand before
blocks starting with a BEGIN statement. The matches must have associations
`idlwave-block-matches'.")
(defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
"Regular expression matching an IDL identifier.")
(defconst idlwave-sysvar (concat "!" idlwave-identifier)
"Regular expression matching IDL system variables.")
(defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
"Regular expression matching IDL variable names.")
(defconst idlwave-label (concat idlwave-identifier ":")
"Regular expression matching IDL labels.")
(defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
"\\(\\s *" idlwave-identifier "::\\)?"
))
(defconst idlwave-statement-match
(list
;; "endif else" is the only possible "end" that can be
;; followed by a statement on the same line.
'(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
;; all other "end"s can not be followed by a statement.
(cons 'end (list idlwave-end-block-reg nil))
'(if . ("if\\>" "then"))
'(for . ("for\\>" "do"))
'(begin . ("begin\\>" nil))
'(pdef . ("pro\\>\\|function\\>" nil))
'(while . ("while\\>" "do"))
'(repeat . ("repeat\\>" "repeat"))
'(goto . ("goto\\>" nil))
'(case . ("case\\>" nil))
'(switch . ("switch\\>" nil))
(cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
"\\(" idlwave-method-call "\\s *\\)?"
idlwave-identifier
"\\s *(") nil))
(cons 'call (list (concat
"\\(" idlwave-method-call "\\s *\\)?"
idlwave-identifier
"\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
(cons 'assign (list (concat
"\\(" idlwave-variable "\\) *=") nil)))
"Associated list of statement matching regular expressions.
Each regular expression matches the start of an IDL statement.
The first element of each association is a symbol giving the statement
type. The associated value is a list. The first element of this list
is a regular expression matching the start of an IDL statement for
identifying the statement type. The second element of this list is a
regular expression for finding a substatement for the type. The
substatement starts after the end of the found match modulo
whitespace. If it is nil then the statement has no substatement. The
list order matters since matching an assignment statement exactly is
not possible without parsing. Thus assignment statement become just
the leftover unidentified statements containing an equal sign.")
(defvar idlwave-fill-function 'auto-fill-function
"IDL mode auto fill function.")
(defvar idlwave-comment-indent-function 'comment-indent-function
"IDL mode comment indent function.")
;; Note that this is documented in the v18 manuals as being a string
;; of length one rather than a single character.
;; The code in this file accepts either format for compatibility.
(defvar idlwave-comment-indent-char ?\
"Character to be inserted for IDL comment indentation.
Normally a space.")
(defconst idlwave-continuation-char ?$
"Character which is inserted as a last character on previous line by
\\[idlwave-split-line] to begin a continuation line. Normally $.")
(defconst idlwave-mode-version "VERSIONTAG")
(defmacro idlwave-keyword-abbrev (&rest args)
"Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
`(quote (lambda ()
,(append '(idlwave-check-abbrev) args))))
;; If I take the time I can replace idlwave-keyword-abbrev with
;; idlwave-code-abbrev and remove the quoted abbrev check from
;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
(defmacro idlwave-code-abbrev (&rest args)
"Creates a function for abbrev hooks that ensures abbrevs are not quoted.
Specifically, if the abbrev is in a comment or string it is unexpanded.
Otherwise ARGS forms a list that is evaluated."
;; FIXME: it would probably be better to rely on the new :enable-function
;; to enforce the "don't expand in comments or strings".
`(lambda ()
,(prin1-to-string args) ;; Puts the code in the doc string
(if (idlwave-quoted)
(progn (unexpand-abbrev) nil)
,(append args))))
(autoload 'idlwave-shell "idlw-shell"
"Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
(autoload 'idlwave-shell-send-command "idlw-shell")
(autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
"Run `idlwave-shell' and switch back to current window" t)
(autoload 'idlwave-shell-save-and-run "idlw-shell"
"Save and run buffer under the shell." t)
(autoload 'idlwave-shell-break-here "idlw-shell"
"Set breakpoint in current line." t)
(autoload 'idlwave-shell-run-region "idlw-shell"
"Compile and run the region." t)
(fset 'idlwave-debug-map (make-sparse-keymap))
(defvar idlwave-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c " 'idlwave-hard-tab)
(define-key map [(control tab)] 'idlwave-hard-tab)
;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
(define-key map "'" 'idlwave-show-matching-quote)
(define-key map "\"" 'idlwave-show-matching-quote)
(define-key map "\C-g" 'idlwave-keyboard-quit)
(define-key map "\C-c;" 'idlwave-toggle-comment-region)
(define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
(define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
(define-key map "\C-c{" 'idlwave-beginning-of-block)
(define-key map "\C-c}" 'idlwave-end-of-block)
(define-key map "\C-c]" 'idlwave-close-block)
(define-key map [(meta control h)] 'idlwave-mark-subprogram)
(define-key map "\M-\C-n" 'idlwave-forward-block)
(define-key map "\M-\C-p" 'idlwave-backward-block)
(define-key map "\M-\C-d" 'idlwave-down-block)
(define-key map "\M-\C-u" 'idlwave-backward-up-block)
(define-key map "\M-\r" 'idlwave-split-line)
(define-key map "\M-\C-q" 'idlwave-indent-subprogram)
(define-key map "\C-c\C-p" 'idlwave-previous-statement)
(define-key map "\C-c\C-n" 'idlwave-next-statement)
;; (define-key map "\r" 'idlwave-newline)
;; (define-key map "\t" 'idlwave-indent-line)
(define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
(define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
(define-key map "\M-q" 'idlwave-fill-paragraph)
(define-key map "\M-s" 'idlwave-edit-in-idlde)
(define-key map "\C-c\C-h" 'idlwave-doc-header)
(define-key map "\C-c\C-m" 'idlwave-doc-modification)
(define-key map "\C-c\C-c" 'idlwave-case)
(define-key map "\C-c\C-d" 'idlwave-debug-map)
(when (and (listp idlwave-shell-debug-modifiers)
(not (equal idlwave-shell-debug-modifiers '())))
;; Bind the debug commands also with the special modifiers.
(let ((shift (memq 'shift idlwave-shell-debug-modifiers))
(mods-noshift
(delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
(define-key map
(vector (append mods-noshift (list (if shift ?C ?c))))
'idlwave-shell-save-and-run)
(define-key map
(vector (append mods-noshift (list (if shift ?B ?b))))
'idlwave-shell-break-here)
(define-key map
(vector (append mods-noshift (list (if shift ?E ?e))))
'idlwave-shell-run-region)))
(define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
(define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
(define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
(define-key map "\C-c\C-f" 'idlwave-for)
;; (define-key map "\C-c\C-f" 'idlwave-function)
;; (define-key map "\C-c\C-p" 'idlwave-procedure)
(define-key map "\C-c\C-r" 'idlwave-repeat)
(define-key map "\C-c\C-w" 'idlwave-while)
(define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
(define-key map "\C-c\C-s" 'idlwave-shell)
(define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
(define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
(define-key map "\C-c\C-v" 'idlwave-find-module)
(define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
(define-key map "\C-c?" 'idlwave-routine-info)
(define-key map "\M-?" 'idlwave-context-help)
(define-key map [(control meta ?\?)]
'idlwave-help-assistant-help-with-topic)
;; Pickup both forms of Esc/Meta binding
(define-key map [(meta tab)] 'idlwave-complete)
(define-key map [?\e?\t] 'idlwave-complete)
(define-key map "\M-\C-i" 'idlwave-complete)
(define-key map "\C-c\C-i" 'idlwave-update-routine-info)
(define-key map "\C-c=" 'idlwave-resolve)
(define-key map
(if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
'idlwave-mouse-context-help)
map)
"Keymap used in IDL mode.")
(defvar idlwave-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?+ "." st)
(modify-syntax-entry ?- "." st)
(modify-syntax-entry ?* "." st)
(modify-syntax-entry ?/ "." st)
(modify-syntax-entry ?^ "." st)
(modify-syntax-entry ?# "." st)
(modify-syntax-entry ?= "." st)
(modify-syntax-entry ?% "." st)
(modify-syntax-entry ?< "." st)
(modify-syntax-entry ?> "." st)
(modify-syntax-entry ?\' "\"" st)
(modify-syntax-entry ?\" "\"" st)
(modify-syntax-entry ?\\ "." st)
(modify-syntax-entry ?_ "_" st)
(modify-syntax-entry ?{ "(}" st)
(modify-syntax-entry ?} "){" st)
(modify-syntax-entry ?$ "_" st)
(modify-syntax-entry ?. "." st)
(modify-syntax-entry ?\; "<" st)
(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?\f ">" st)
st)
"Syntax table in use in `idlwave-mode' buffers.")
(defvar idlwave-find-symbol-syntax-table
(let ((st (copy-syntax-table idlwave-mode-syntax-table)))
(modify-syntax-entry ?$ "w" st)
(modify-syntax-entry ?_ "w" st)
(modify-syntax-entry ?! "w" st)
(modify-syntax-entry ?. "w" st)
st)
"Syntax table that treats symbol characters as word characters.")
(defmacro idlwave-with-special-syntax (&rest body)
"Execute BODY with a different syntax table."
`(let ((saved-syntax (syntax-table)))
(unwind-protect
(progn
(set-syntax-table idlwave-find-symbol-syntax-table)
,@body)
(set-syntax-table saved-syntax))))
;(defmacro idlwave-with-special-syntax1 (&rest body)
; "Execute BODY with a different syntax table."
; `(let ((saved-syntax (syntax-table)))
; (unwind-protect
; (progn
; (set-syntax-table idlwave-find-symbol-syntax-table)
; ,@body)
; (set-syntax-table saved-syntax))))
(defun idlwave-action-and-binding (key cmd &optional select)
"KEY and CMD are made into a key binding and an indent action.
KEY is a string - same as for the `define-key' function. CMD is a
function of no arguments or a list to be evaluated. CMD is bound to
KEY in `idlwave-mode-map' by defining an anonymous function calling
`self-insert-command' followed by CMD. If KEY contains more than one
character a binding will only be set if SELECT is 'both.
\(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
replacing any previous value for KEY. If a binding is not set then it
will instead be placed in `idlwave-indent-action-table'.
If the optional argument SELECT is nil then an action and binding are
created. If SELECT is 'noaction, then a binding is always set and no
action is created. If SELECT is 'both then an action and binding
will both be created even if KEY contains more than one character.
Otherwise, if SELECT is non-nil then only an action is created.
Some examples:
No spaces before and 1 after a comma
(idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
(idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
Capitalize system variables - action only
(idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
(if (not (equal select 'noaction))
;; Add action
(let* ((table (if select 'idlwave-indent-action-table
'idlwave-indent-expand-table))
(table-key (regexp-quote key))
(cell (assoc table-key (eval table))))
(if cell
;; Replace action command
(setcdr cell cmd)
;; New action
(set table (append (eval table) (list (cons table-key cmd)))))))
;; Make key binding for action
(if (or (and (null select) (= (length key) 1))
(equal select 'noaction)
(equal select 'both))
(define-key idlwave-mode-map key
`(lambda ()
(interactive)
(self-insert-command 1)
,(if (listp cmd) cmd (list cmd))))))
;; Set action and key bindings.
;; See description of the function `idlwave-action-and-binding'.
;; Automatically add spaces for the following characters
;; Actions for & are complicated by &&
(idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
;; Automatically add spaces to equal sign if not keyword. This needs
;; to go ahead of > and <, so >= and <= will be treated correctly
(idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
;; Actions for > and < are complicated by >=, <=, and ->...
(idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
(idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
(idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
;;;
;;; Abbrev Section
;;;
;;; When expanding abbrevs and the abbrev hook moves backward, an extra
;;; space is inserted (this is the space typed by the user to expanded
;;; the abbrev).
;;;
(defvar idlwave-mode-abbrev-table nil
"Abbreviation table used for IDLWAVE mode.")
(define-abbrev-table 'idlwave-mode-abbrev-table ())
(defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
"Define-abbrev with backward compatibility.
If NOPREFIX is non-nil, don't prepend prefix character. Installs into
`idlwave-mode-abbrev-table' unless TABLE is non-nil."
(let ((abbrevs-changed nil) ;; mask the current value to avoid save
(args (list (or table idlwave-mode-abbrev-table)
(if noprefix name (concat idlwave-abbrev-start-char name))
expansion
hook)))
(condition-case nil
(apply 'define-abbrev (append args '(0 t)))
(error (apply 'define-abbrev args)))))
(condition-case nil
(modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
"w" idlwave-mode-syntax-table)
(error nil))
;;
;; Templates
;;
(idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
(idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
(idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
(idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
(idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
(idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
(idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
(idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
(idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
;;
;; Keywords, system functions, conversion routines
;;
(idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
(idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
(idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
(idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
(idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
(idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
(idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
(idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
(idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
(idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
(idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
(idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
(idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
(idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
(idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
(idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
(idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
(idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
;; This section is reserved words only. (From IDL user manual)
;;
(idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
(idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
(idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
(defvar imenu-create-index-function)
(defvar extract-index-name-function)
(defvar prev-index-position-function)
(defvar imenu-extract-index-name-function)
(defvar imenu-prev-index-position-function)
;; defined later - so just make the compiler hush
(defvar idlwave-mode-menu)
(defvar idlwave-mode-debug-menu)
;;;###autoload
(defun idlwave-mode ()
"Major mode for editing IDL source files (version VERSIONTAG).
The main features of this mode are
1. Indentation and Formatting
--------------------------
Like other Emacs programming modes, C-j inserts a newline and indents.
TAB is used for explicit indentation of the current line.
To start a continuation line, use \\[idlwave-split-line]. This
function can also be used in the middle of a line to split the line
at that point. When used inside a long constant string, the string
is split at that point with the `+' concatenation operator.
Comments are indented as follows:
`;;;' Indentation remains unchanged.
`;;' Indent like the surrounding code
`;' Indent to a minimum column.
The indentation of comments starting in column 0 is never changed.
Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
comment. The indentation of the second line of the paragraph
relative to the first will be retained. Use
\\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
comments. When the variable `idlwave-fill-comment-line-only' is
nil, code can also be auto-filled and auto-indented.
To convert pre-existing IDL code to your formatting style, mark the
entire buffer with \\[mark-whole-buffer] and execute
\\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
again followed by \\[indent-region] (`indent-region').
2. Routine Info
------------
IDLWAVE displays information about the calling sequence and the
accepted keyword parameters of a procedure or function with
\\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
source file of a module. These commands know about system
routines, all routines in idlwave-mode buffers and (when the
idlwave-shell is active) about all modules currently compiled under
this shell. It also makes use of pre-compiled or custom-scanned
user and library catalogs many popular libraries ship with by
default. Use \\[idlwave-update-routine-info] to update this
information, which is also used for completion (see item 4).
3. Online IDL Help
---------------
\\[idlwave-context-help] displays the IDL documentation relevant
for the system variable, keyword, or routines at point. A single
key stroke gets you directly to the right place in the docs. See
the manual to configure where and how the HTML help is displayed.
4. Completion
----------
\\[idlwave-complete] completes the names of procedures, functions
class names, keyword parameters, system variables and tags, class
tags, structure tags, filenames and much more. It is context
sensitive and figures out what is expected at point. Lower case
strings are completed in lower case, other strings in mixed or
upper case.
5. Code Templates and Abbreviations
--------------------------------
Many Abbreviations are predefined to expand to code fragments and templates.
The abbreviations start generally with a `\\`. Some examples:
\\pr PROCEDURE template
\\fu FUNCTION template
\\c CASE statement template
\\sw SWITCH 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
For a full list, use \\[idlwave-list-abbrevs]. Some templates also
have direct keybindings - see the list of keybindings below.
\\[idlwave-doc-header] inserts a documentation header at the
beginning of the current program unit (pro, function or main).
Change log entries can be added to the current program unit with
\\[idlwave-doc-modification].
6. Automatic Case Conversion
-------------------------
The case of reserved words and some abbrevs is controlled by
`idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
7. Automatic END completion
------------------------
If the variable `idlwave-expand-generic-end' is non-nil, each END typed
will be converted to the specific version, like ENDIF, ENDFOR, etc.
8. Hooks
-----
Loading idlwave.el runs `idlwave-load-hook'.
Turning on `idlwave-mode' runs `idlwave-mode-hook'.
9. Documentation and Customization
-------------------------------
Info documentation for this package is available. Use
\\[idlwave-info] to display (complain to your sysadmin if that does
not work). For Postscript, PDF, and HTML versions of the
documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
IDLWAVE has customize support - see the group `idlwave'.
10.Keybindings
-----------
Here is a list of all keybindings of this mode.
If some of the key bindings below show with ??, use \\[describe-key]
followed by the key sequence to see what the key sequence does.
\\{idlwave-mode-map}"
(interactive)
(kill-all-local-variables)
(if idlwave-startup-message
(message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
(setq idlwave-startup-message nil)
(setq local-abbrev-table idlwave-mode-abbrev-table)
(set-syntax-table idlwave-mode-syntax-table)
(set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
(make-local-variable idlwave-comment-indent-function)
(set idlwave-comment-indent-function 'idlwave-comment-hook)
(set (make-local-variable 'comment-start-skip) ";+[ \t]*")
(set (make-local-variable 'comment-start) ";")
(set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
(set (make-local-variable 'require-final-newline) t)
(set (make-local-variable 'abbrev-all-caps) t)
(set (make-local-variable 'indent-tabs-mode) nil)
(set (make-local-variable 'completion-ignore-case) t)
(use-local-map idlwave-mode-map)
(when (featurep 'easymenu)
(easy-menu-add idlwave-mode-menu idlwave-mode-map)
(easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
(setq mode-name "IDLWAVE")
(setq major-mode 'idlwave-mode)
(setq abbrev-mode t)
(set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
(setq comment-end "")
(set (make-local-variable 'comment-multi-line) nil)
(set (make-local-variable 'paragraph-separate)
"[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
(set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
(set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
(set (make-local-variable 'parse-sexp-ignore-comments) t)
;; ChangeLog
(set (make-local-variable 'add-log-current-defun-function)
'idlwave-current-routine-fullname)
;; Set tag table list to use IDLTAGS as file name.
(if (boundp 'tag-table-alist)
(add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
;; Font-lock additions
;; Following line is for Emacs - XEmacs uses the corresponding property
;; on the `idlwave-mode' symbol.
(set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
(set (make-local-variable 'font-lock-mark-block-function)
'idlwave-mark-subprogram)
(set (make-local-variable 'font-lock-fontify-region-function)
'idlwave-font-lock-fontify-region)
;; Imenu setup
(set (make-local-variable 'imenu-create-index-function)
'imenu-default-create-index-function)
(set (make-local-variable 'imenu-extract-index-name-function)
'idlwave-unit-name)
(set (make-local-variable 'imenu-prev-index-position-function)
'idlwave-prev-index-position)
;; HideShow setup
(add-to-list 'hs-special-modes-alist
(list 'idlwave-mode
idlwave-begin-block-reg
idlwave-end-block-reg
";"
'idlwave-forward-block nil))
;; Make a local post-command-hook and add our hook to it
;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
(make-local-hook 'post-command-hook)
(add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
;; Make local hooks for buffer updates
;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
(make-local-hook 'kill-buffer-hook)
(add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
(make-local-hook 'after-save-hook)
(add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
(add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
;; Setup directories and file, if necessary
(idlwave-setup)
;; Update the routine info with info about current buffer?
(idlwave-new-buffer-update)
(if idlwave-complete-structure-tags
(add-hook 'idlwave-mode-hook
(lambda ()
(require 'idlw-complete-structtag))))
;; Run the mode hook
(run-mode-hooks 'idlwave-mode-hook))
(defvar idlwave-setup-done nil)
(defun idlwave-setup ()
(unless idlwave-setup-done
(if (not (file-directory-p idlwave-config-directory))
(make-directory idlwave-config-directory))
(setq
idlwave-user-catalog-file (expand-file-name
idlwave-user-catalog-file
idlwave-config-directory)
idlwave-xml-system-rinfo-converted-file
(expand-file-name
idlwave-xml-system-rinfo-converted-file
idlwave-config-directory)
idlwave-path-file (expand-file-name
idlwave-path-file
idlwave-config-directory))
;; Check and setup help location
(idlwave-read-paths) ; we may need these early
(idlwave-help-check-locations)
(setq idlwave-setup-done t)))
(defun idlwave-font-lock-fontify-region (beg end &optional verbose)
"Fontify continuation lines correctly."
(let (pos)
(save-excursion
(goto-char beg)
(forward-line -1)
(when (setq pos (idlwave-is-continuation-line))
(goto-char pos)
(idlwave-beginning-of-statement)
(setq beg (point)))))
(font-lock-default-fontify-region beg end verbose))
;;
;; Code Formatting ----------------------------------------------------
;;
(defun idlwave-hard-tab ()
"Insert TAB in buffer in current position."
(interactive)
(insert "\t"))
;;; This stuff is experimental
(defvar idlwave-command-hook nil
"If non-nil, a list that can be evaluated using `eval'.
It is evaluated in the lisp function `idlwave-command-hook' which is
placed in `post-command-hook'.")
(defun idlwave-command-hook ()
"Command run after every command.
Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
sets the variable to zero afterwards."
(and idlwave-command-hook
(listp idlwave-command-hook)
(condition-case nil
(eval idlwave-command-hook)
(error nil)))
(setq idlwave-command-hook nil))
;;; End experiment
;; It would be better to use expand.el for better abbrev handling and
;; versatility.
(defun idlwave-check-abbrev (arg &optional reserved)
"Reverse abbrev expansion if in comment or string.
Argument ARG is the number of characters to move point
backward if `idlwave-abbrev-move' is non-nil.
If optional argument RESERVED is non-nil then the expansion
consists of reserved words, which will be capitalized if
`idlwave-reserved-word-upcase' is non-nil.
Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
is non-nil, unless its value is \`down in which case the abbrev will be
made into all lowercase.
Returns non-nil if abbrev is left expanded."
(if (idlwave-quoted)
(progn (unexpand-abbrev)
nil)
(if (and reserved idlwave-reserved-word-upcase)
(upcase-region last-abbrev-location (point))
(cond
((equal idlwave-abbrev-change-case 'down)
(downcase-region last-abbrev-location (point)))
(idlwave-abbrev-change-case
(upcase-region last-abbrev-location (point)))))
(if (and idlwave-abbrev-move (> arg 0))
(if (boundp 'post-command-hook)
(setq idlwave-command-hook (list 'backward-char (1+ arg)))
(backward-char arg)))
t))
(defun idlwave-in-comment ()
"Return t if point is inside a comment, nil otherwise."
(save-excursion
(let ((here (point)))
(and (idlwave-goto-comment) (> here (point))))))
(defun idlwave-goto-comment ()
"Move to start of comment delimiter on current line.
Moves to end of line if there is no comment delimiter.
Ignores comment delimiters in strings.
Returns point if comment found and nil otherwise."
(let ((eos (progn (end-of-line) (point)))
(data (match-data))
found)
;; Look for first comment delimiter not in a string
(beginning-of-line)
(setq found (search-forward comment-start eos 'lim))
(while (and found (idlwave-in-quote))
(setq found (search-forward comment-start eos 'lim)))
(store-match-data data)
(and found (not (idlwave-in-quote))
(progn
(backward-char 1)
(point)))))
(defun idlwave-region-active-p ()
"Should we operate on an active region?"
(if (fboundp 'use-region-p)
(use-region-p)
(region-active-p)))
(defun idlwave-show-matching-quote ()
"Insert quote and show matching quote if this is end of a string."
(interactive)
(let ((bq (idlwave-in-quote))
(inq last-command-event))
(if (and bq (not (idlwave-in-comment)))
(let ((delim (char-after bq)))
(insert inq)
(if (eq inq delim)
(save-excursion
(goto-char bq)
(sit-for 1))))
;; Not the end of a string
(insert inq))))
(defun idlwave-show-begin-check ()
"Ensure that the previous word was a token before `idlwave-show-begin'.
An END token must be preceded by whitespace."
(if (not (idlwave-quoted))
(if
(save-excursion
(backward-word 1)
(backward-char 1)
(looking-at "[ \t\n\f]"))
(idlwave-show-begin))))
(defun idlwave-show-begin ()
"Find the start of current block and blinks to it for a second.
Also checks if the correct END statement has been used."
;; All end statements are reserved words
;; Re-indent end line
;;(insert-char ?\ 1) ;; So indent, etc. work well
;;(backward-char 1)
(let* ((pos (point-marker))
(last-abbrev-marker (copy-marker last-abbrev-location))
(eol-pos (save-excursion (end-of-line) (point)))
begin-pos end-pos end end1 )
(if idlwave-reindent-end (idlwave-indent-line))
(setq last-abbrev-location (marker-position last-abbrev-marker))
(when (and (idlwave-check-abbrev 0 t)
idlwave-show-block)
(save-excursion
;; Move inside current block
(goto-char last-abbrev-marker)
(idlwave-block-jump-out -1 'nomark)
(setq begin-pos (point))
(idlwave-block-jump-out 1 'nomark)
(setq end-pos (point))
(if (> end-pos eol-pos)
(setq end-pos pos))
(goto-char end-pos)
(setq end (buffer-substring
(progn
(skip-chars-backward "a-zA-Z")
(point))
end-pos))
(goto-char begin-pos)
(when (setq end1 (cdr (idlwave-block-master)))
(cond
((null end1)) ; no-operation
((string= (downcase end) (downcase end1))
(sit-for 1))
((string= (downcase end) "end")
;; A generic end
(if idlwave-expand-generic-end
(save-excursion
(goto-char pos)
(backward-char 3)
(insert (if (string= end "END") (upcase end1) end1))
(delete-char 3)))
(sit-for 1))
(t
(beep)
(message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
end1 end)
(sit-for 1))))))))
;;(delete-char 1))
(defun idlwave-block-master ()
(let ((case-fold-search t))
(save-excursion
(cond
((looking-at "pro\\|case\\|switch\\|function\\>")
(assoc (downcase (match-string 0)) idlwave-block-matches))
((looking-at "begin\\>")
(let ((limit (save-excursion
(idlwave-beginning-of-statement)
(point))))
(cond
((re-search-backward ":[ \t]*\\=" limit t)
;; seems to be a case thing
'("begin" . "end"))
((re-search-backward idlwave-block-match-regexp limit t)
(assoc (downcase (match-string 1))
idlwave-block-matches))
(t
;; Just a normal block
'("begin" . "end")))))
(t nil)))))
(defun idlwave-close-block ()
"Terminate the current block with the correct END statement."
(interactive)
;; Start new line if we are not in a new line
(unless (save-excursion
(skip-chars-backward " \t")
(bolp))
(let ((idlwave-show-block nil))
(newline-and-indent)))
(let ((last-abbrev-location (point))) ; for upcasing
(insert "end")
(idlwave-show-begin)))
(defun idlwave-custom-ampersand-surround (&optional is-action)
"Surround &, leaving room for && (which surround as well)."
(let* ((prev-char (char-after (- (point) 2)))
(next-char (char-after (point)))
(amp-left (eq prev-char ?&))
(amp-right (eq next-char ?&))
(len (if amp-left 2 1)))
(unless amp-right ;no need to do it twice, amp-left will catch it.
(idlwave-surround -1 (if (or is-action amp-left) -1) len))))
(defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
"Surround > and < by blanks, leaving room for >= and <=, and considering ->."
(let* ((prev-char (char-after (- (point) 2)))
(next-char (char-after (point)))
(method-invoke (and gtr (eq prev-char ?-)))
(len (if method-invoke 2 1)))
(unless (eq next-char ?=)
;; Key binding: pad only on left, to save for possible >=/<=
(idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
(defun idlwave-surround (&optional before after length is-action)
"Surround the LENGTH characters before point with blanks.
LENGTH defaults to 1.
Optional arguments BEFORE and AFTER affect the behavior before and
after the characters (see also description of `idlwave-make-space'):
nil do nothing
0 force no spaces
integer > 0 force exactly n spaces
integer < 0 at least |n| spaces
The function does nothing if any of the following conditions is true:
- `idlwave-surround-by-blank' is nil
- the character before point is inside a string or comment"
(when (and idlwave-surround-by-blank (not (idlwave-quoted)))
(let ((length (or length 1))) ; establish a default for LENGTH
(backward-char length)
(save-restriction
(let ((here (point)))
(skip-chars-backward " \t")
(if (bolp)
;; avoid clobbering indent
(progn
(move-to-column (idlwave-calculate-indent))
(if (<= (point) here)
(narrow-to-region (point) here))
(goto-char here)))
(idlwave-make-space before))
(skip-chars-forward " \t"))
(forward-char length)
(idlwave-make-space after)
;; Check to see if the line should auto wrap
(if (and (equal (char-after (1- (point))) ?\ )
(> (current-column) fill-column))
(funcall auto-fill-function)))))
(defun idlwave-make-space (n)
"Make space at point.
The space affected is all the spaces and tabs around point.
If n is non-nil then point is left abs(n) spaces from the beginning of
the contiguous space.
The amount of space at point is determined by N.
If the value of N is:
nil - do nothing.
> 0 - exactly N spaces.
< 0 - a minimum of -N spaces, i.e., do not change if there are
already -N spaces.
0 - no spaces (i.e. remove any existing space)."
(if (integerp n)
(let
((start-col (progn (skip-chars-backward " \t") (current-column)))
(left (point))
(end-col (progn (skip-chars-forward " \t") (current-column))))
(delete-horizontal-space)
(cond
((> n 0)
(idlwave-indent-to (+ start-col n))
(goto-char (+ left n)))
((< n 0)
(idlwave-indent-to end-col (- n))
(goto-char (- left n)))
;; n = 0, done
))))
(defun idlwave-newline ()
"Insert a newline and indent the current and previous line."
(interactive)
;;
;; Handle unterminated single and double quotes
;; If not in a comment and in a string then insertion of a newline
;; will mean unbalanced quotes.
;;
(if (and (not (idlwave-in-comment)) (idlwave-in-quote))
(progn (beep)
(message "Warning: unbalanced quotes?")))
(newline)
;;
;; The current line is being split, the cursor should be at the
;; beginning of the new line skipping the leading indentation.
;;
;; The reason we insert the new line before indenting is that the
;; indenting could be confused by keywords (e.g. END) on the line
;; after the split point. This prevents us from just using
;; `indent-for-tab-command' followed by `newline-and-indent'.
;;
(beginning-of-line 0)
(idlwave-indent-line)
(forward-line)
(idlwave-indent-line))
;;
;; Use global variable 'comment-column' to set parallel comment
;;
;; Modeled on lisp.el
;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
(defun idlwave-comment-hook ()
"Compute indent for the beginning of the IDL comment delimiter."
(if (or (looking-at idlwave-no-change-comment)
(looking-at (or idlwave-begin-line-comment "^;")))
(current-column)
(if (looking-at idlwave-code-comment)
(if (save-excursion (skip-chars-backward " \t") (bolp))
;; On line by itself, indent as code
(let ((tem (idlwave-calculate-indent)))
(if (listp tem) (car tem) tem))
;; after code - do not change
(current-column))
(skip-chars-backward " \t")
(max (if (bolp) 0 (1+ (current-column)))
comment-column))))
(defun idlwave-split-line (&optional noindent)
"Continue line by breaking line at point and indent the lines.
For a code line, insert continuation marker. Don't indent if
NOINDENT is passed. If the line is a line comment then the new
line will contain a comment with the same indentation. Splits
strings with the IDL operator `+' if `idlwave-split-line-string'
is non-nil."
(interactive)
;; Expand abbreviation, just like normal RET would.
(and abbrev-mode (expand-abbrev))
(let (beg)
(if (not (idlwave-in-comment))
;; For code line add continuation.
;; Check if splitting a string.
(progn
(if (setq beg (idlwave-in-quote))
(if idlwave-split-line-string
;; Split the string.
(progn (insert (setq beg (char-after beg)) " + "
idlwave-continuation-char beg)
(backward-char 1)
(newline-and-indent)
(forward-char 1))
;; Do not split the string.
(beep)
(message "Warning: continuation inside string!!")
(insert " " idlwave-continuation-char))
;; Not splitting a string.
(if (not (member (char-before) '(?\ ?\t)))
(insert " "))
(insert idlwave-continuation-char)
(if (null noindent)
(newline-and-indent)
(newline))))
(indent-new-comment-line))
;; Indent previous line
(when (null noindent)
(setq beg (- (point-max) (point)))
(forward-line -1)
(idlwave-indent-line)
(goto-char (- (point-max) beg))
;; Reindent new line
(idlwave-indent-line))))
(defun idlwave-beginning-of-subprogram (&optional nomark)
"Move point to the beginning of the current program unit.
If NOMARK is non-nil, do not push mark."
(interactive)
(idlwave-find-key idlwave-begin-unit-reg -1 nomark))
(defun idlwave-end-of-subprogram (&optional nomark)
"Move point to the start of the next program unit.
If NOMARK is non-nil, do not push mark."
(interactive)
(idlwave-end-of-statement)
(idlwave-find-key idlwave-end-unit-reg 1 nomark))
(defun idlwave-mark-statement ()
"Mark current IDL statement."
(interactive)
(idlwave-end-of-statement)
(let ((end (point)))
(idlwave-beginning-of-statement)
(push-mark end nil t)))
(defun idlwave-mark-block ()
"Mark containing block."
(interactive)
(idlwave-end-of-statement)
(idlwave-backward-up-block -1)
(idlwave-end-of-statement)
(let ((end (point)))
(idlwave-backward-block)
(idlwave-beginning-of-statement)
(push-mark end nil t)))
(defun idlwave-mark-subprogram ()
"Put mark at beginning of program, point at end.
The marks are pushed."
(interactive)
(idlwave-end-of-statement)
(idlwave-beginning-of-subprogram)
(let ((beg (point)))
(idlwave-forward-block)
(push-mark beg nil t))
(exchange-point-and-mark))
(defun idlwave-backward-up-block (&optional arg)
"Move to beginning of enclosing block if prefix ARG >= 0.
If prefix ARG < 0 then move forward to enclosing block end."
(interactive "p")
(idlwave-block-jump-out (- arg) 'nomark))
(defun idlwave-beginning-of-block ()
"Go to the beginning of the current block."
(interactive)
(idlwave-block-jump-out -1 'nomark)
(forward-word 1))
(defun idlwave-end-of-block ()
"Go to the beginning of the current block."
(interactive)
(idlwave-block-jump-out 1 'nomark)
(backward-word 1))
(defun idlwave-forward-block (&optional arg)
"Move across next nested block."
(interactive)
(let ((arg (or arg 1)))
(if (idlwave-down-block arg)
(idlwave-block-jump-out arg 'nomark))))
(defun idlwave-backward-block ()
"Move backward across previous nested block."
(interactive)
(if (idlwave-down-block -1)
(idlwave-block-jump-out -1 'nomark)))
(defun idlwave-down-block (&optional arg)
"Go down a block.
With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
Returns non-nil if successfull."
(interactive "p")
(let (status)
(if (< arg 0)
;; Backward
(let ((eos (save-excursion
(idlwave-block-jump-out -1 'nomark)
(point))))
(if (setq status (idlwave-find-key
idlwave-end-block-reg -1 'nomark eos))
(idlwave-beginning-of-statement)
(message "No nested block before beginning of containing block.")))
;; Forward
(let ((eos (save-excursion
(idlwave-block-jump-out 1 'nomark)
(point))))
(if (setq status (idlwave-find-key
idlwave-begin-block-reg 1 'nomark eos))
(idlwave-end-of-statement)
(message "No nested block before end of containing block."))))
status))
(defun idlwave-mark-doclib ()
"Put point at beginning of doc library header, mark at end.
The marks are pushed."
(interactive)
(let (beg
(here (point)))
(goto-char (point-max))
(if (re-search-backward idlwave-doclib-start nil t)
(progn
(setq beg (progn (beginning-of-line) (point)))
(if (re-search-forward idlwave-doclib-end nil t)
(progn
(forward-line 1)
(push-mark beg nil t)
(message "Could not find end of doc library header.")))
(message "Could not find doc library header start.")
(goto-char here)))))
(defun idlwave-current-routine-fullname ()
(let ((name (idlwave-current-routine)))
(idlwave-make-full-name (nth 2 name) (car name))))
(defun idlwave-current-routine ()
"Return (NAME TYPE CLASS) of current routine."
(idlwave-routines)
(save-excursion
(idlwave-beginning-of-subprogram 'nomark)
(if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
(let* ((type (if (string= (downcase (match-string 1)) "pro")
'pro 'function))
(class (idlwave-sintern-class (match-string 3)))
(name (idlwave-sintern-routine-or-method (match-string 4) class)))
(list name type class)))))
(defvar idlwave-shell-prompt-pattern)
(defun idlwave-beginning-of-statement ()
"Move to beginning of the current statement.
Skips back past statement continuations.
Point is placed at the beginning of the line whether or not this is an
actual statement."
(interactive)
(cond
((eq major-mode 'idlwave-shell-mode)
(if (re-search-backward idlwave-shell-prompt-pattern nil t)
(goto-char (match-end 0))))
(t
(if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
(idlwave-previous-statement)
(beginning-of-line)))))
(defun idlwave-previous-statement ()
"Move point to beginning of the previous statement.
Returns t if the current line before moving is the beginning of
the first non-comment statement in the file, and nil otherwise."
(interactive)
(let (first-statement)
(if (not (= (forward-line -1) 0))
;; first line in file
t
;; skip blank lines, label lines, include lines and line comments
(while (and
;; The current statement is the first statement until we
;; reach another statement.
(setq first-statement
(or
(looking-at idlwave-comment-line-start-skip)
(looking-at "[ \t]*$")
(looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
(looking-at "^@")))
(= (forward-line -1) 0)))
;; skip continuation lines
(while (and
(save-excursion
(forward-line -1)
(idlwave-is-continuation-line))
(= (forward-line -1) 0)))
first-statement)))
(defun idlwave-end-of-statement ()
"Move point to the end of the current IDL statement.
If not in a statement just moves to end of line. Returns position."
(interactive)
(while (and (idlwave-is-continuation-line)
(= (forward-line 1) 0))
(while (and (idlwave-is-comment-or-empty-line)
(= (forward-line 1) 0))))
(end-of-line)
(point))
(defun idlwave-end-of-statement0 ()
"Move point to the end of the current IDL statement.
If not in a statement just moves to end of line. Returns position."
(interactive)
(while (and (idlwave-is-continuation-line)
(= (forward-line 1) 0)))
(end-of-line)
(point))
(defun idlwave-next-statement (&optional eos)
"Move point to beginning of the next IDL statement.
Returns t if that statement is the last non-comment IDL statement
in the file, and nil otherwise."
(interactive)
(let (last-statement)
(if eos (goto-char eos) (idlwave-end-of-statement))
;; skip blank lines, label lines, include lines and line comments
(while (and (= (forward-line 1) 0)
;; The current statement is the last statement until
;; we reach a new statement.
(setq last-statement
(or
(looking-at idlwave-comment-line-start-skip)
(looking-at "[ \t]*$")
(looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
(looking-at "^@")))))
last-statement))
(defun idlwave-skip-multi-commands (&optional lim)
"Skip past multiple commands on a line (or multiple lines) (with `&')."
(let ((save-point (point)))
(while (re-search-forward "\\s-\\(&\\)[^&]" lim t)
(backward-char)
(if (and (not (idlwave-quoted))
(not (eq (char-before (- (point) 1)) ?&)))
(setq save-point (point))))
(goto-char save-point)
save-point))
(defun idlwave-skip-label-or-case (&optional eos)
"Skip label or case statement element.
Returns position after label.
If there is no label point is not moved and nil is returned."
;; Case expressions and labels are terminated by a colon.
;; So we find the first colon in the line and make sure
;; - no `?' is before it (might be a ? b : c)
;; - it is not in a comment
;; - not in a string constant
;; - not in parenthesis (like a[0:3])
;; - not followed by another ":" in explicit class, ala a->b::c
;; As many in this mode, this function is heuristic and not an exact
;; parser.
(let* ((start (point))
(eos (or eos (save-excursion (idlwave-end-of-statement) (point))))
(end (idlwave-find-key ":" 1 'nomark eos)))
(if (and end
(= (nth 0 (parse-partial-sexp start end)) 0)
(not (string-match "\\?" (buffer-substring start end)))
(not (string-match "^::" (buffer-substring end eos))))
(progn
(forward-char)
(point))
(goto-char start)
nil)))
(defun idlwave-start-of-substatement (&optional pre)
"Move to start of next IDL substatement after point.
Uses the type of the current IDL statement to determine if the next
statement is on a new line or is a subpart of the current statement.
Returns point at start of substatement modulo whitespace.
If optional argument is non-nil move to beginning of current
substatement."
(let ((orig (point))
(eos (save-excursion (idlwave-end-of-statement) (point)))
(ifnest 0)
st nst last)
(idlwave-beginning-of-statement)
(setq last (point))
(idlwave-skip-label-or-case eos)
(if (and pre (> (point) orig)) ;; Previous statement isn't beyond point!
(goto-char last))
(if (< (point) orig)
(idlwave-skip-multi-commands orig))
(setq last (point))
;; Continue looking for substatements until we are past orig
(while (and (<= (point) orig) (not (eobp)))
(setq last (point))
(setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
(if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
(cond ((and nst
(idlwave-find-key nst 1 'nomark eos))
(goto-char (match-end 0)))
((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
(setq ifnest (1- ifnest))
(goto-char (match-end 0)))
(t (setq ifnest 0)
(idlwave-next-statement eos))))
(if pre (goto-char last))
;; If a continuation line starts here, move to next line
(when (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
(beginning-of-line 2))
(while
(and (not (eobp))
(or (looking-at idlwave-comment-line-start-skip) ;comment only
(looking-at "[ \t]*$"))) ; blank
(beginning-of-line 2))
(point)))
(defun idlwave-statement-type ()
"Return the type of the current IDL statement.
Uses `idlwave-statement-match' to return a cons of (type . point) with
point the ending position where the type was determined. Type is the
association from `idlwave-statement-match', i.e. the cons cell from the
list not just the type symbol. Returns nil if not an identifiable
statement."
(save-excursion
;; Skip whitespace within a statement which is spaces, tabs, continuations
;; and possibly comments
(while (looking-at "[ \t]*\\$")
(forward-line 1))
(skip-chars-forward " \t")
(let ((st idlwave-statement-match)
(case-fold-search t))
(while (and (not (looking-at (nth 0 (cdr (car st)))))
(setq st (cdr st))))
(if st
(append st (match-end 0))))))
(defun idlwave-expand-equal (&optional before after is-action)
"Pad '=' with spaces.
Two cases: Assignment statement, and keyword assignment.
Which case is determined using `idlwave-start-of-substatement' and
`idlwave-statement-type'. The equal sign will be surrounded by BEFORE
and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
is treated just like assignment statements. When nil, spaces are
removed for keyword assignment. Any other value keeps the current space
around the `='. Limits in for loops are treated as keyword assignment.
Starting with IDL 6.0, a number of op= assignments are available.
Since ambiguities of the form:
r and= b
rand= b
can occur, alphanumeric operator assignment will never be pre-padded,
only post-padded. You must use a space before these to disambiguate
\(not just for padding, but for proper parsing by IDL too!). Other
operators, such as ##=, ^=, etc., will be pre-padded.
IS-ACTION is ignored.
See `idlwave-surround'."
(if idlwave-surround-by-blank
(let
((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
(an-ops
"\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
(len 1))
(save-excursion
(let ((case-fold-search t))
(backward-char)
(if (or
(re-search-backward non-an-ops nil t)
;; Why doesn't ##? work for both?
(re-search-backward "\\(#\\)\\=" nil t))
(setq len (1+ (length (match-string 1))))
(when (re-search-backward an-ops nil t)
;(setq begin nil) ; won't modify begin
(setq len (1+ (length (match-string 1))))))))
(if (eq t idlwave-pad-keyword)
;; Everything gets padded equally
(idlwave-surround before after len)
;; Treating keywords/for variables specially...
(let ((st (save-excursion ; To catch "for" variables
(idlwave-start-of-substatement t)
(idlwave-statement-type)))
(what (save-excursion ; To catch keywords
(skip-chars-backward "= \t")
(nth 2 (idlwave-where)))))
(cond ((or (memq what '(function-keyword procedure-keyword))
(memq (caar st) '(for pdef)))
(cond
((null idlwave-pad-keyword)
(idlwave-surround 0 0)
) ; remove space
(t))) ; leave any spaces alone
(t (idlwave-surround before after len))))))))
(defun idlwave-indent-and-action (&optional arg)
"Call `idlwave-indent-line' and do expand actions.
With prefix ARG non-nil, indent the entire sub-statement."
(interactive "p")
(save-excursion
(if (and idlwave-expand-generic-end
(re-search-backward "\\<\\(end\\)\\s-*\\="
(max 0 (- (point) 10)) t)
(looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
(progn (goto-char (match-end 1))
;;Expand the END abbreviation, just as RET or Space would have.
(if abbrev-mode (expand-abbrev)
(idlwave-show-begin)))))
(when (and (not arg) current-prefix-arg)
(setq arg current-prefix-arg)
(setq current-prefix-arg nil))
(if arg
(idlwave-indent-statement)
(idlwave-indent-line t)))
(defun idlwave-indent-line (&optional expand)
"Indent current IDL line as code or as a comment.
The actions in `idlwave-indent-action-table' are performed.
If the optional argument EXPAND is non-nil then the actions in
`idlwave-indent-expand-table' are performed."
(interactive)
;; Move point out of left margin.
(if (save-excursion
(skip-chars-backward " \t")
(bolp))
(skip-chars-forward " \t"))
(let ((mloc (point-marker)))
(save-excursion
(beginning-of-line)
(if (looking-at idlwave-comment-line-start-skip)
;; Indentation for a line comment
(progn
(skip-chars-forward " \t")
(idlwave-indent-left-margin (idlwave-comment-hook)))
;;
;; Code Line
;;
;; Before indenting, run action routines.
;;
(if (and expand idlwave-do-actions)
(mapc 'idlwave-do-action idlwave-indent-expand-table))
;;
(if idlwave-do-actions
(mapc 'idlwave-do-action idlwave-indent-action-table))
;;
;; No longer expand abbrevs on the line. The user can do this
;; manually using expand-region-abbrevs.
;;
;; Indent for code line
;;
(beginning-of-line)
(if (or
;; a label line
(looking-at (concat "^" idlwave-label "[ \t]*$"))
;; a batch command
(looking-at "^[ \t]*@"))
;; leave flush left
nil
;; indent the line
(idlwave-indent-left-margin (idlwave-calculate-indent)))
;; Adjust parallel comment
(end-of-line)
(if (idlwave-in-comment)
;; Emacs 21 is too smart with fill-column on comment indent
(let ((fill-column (if (fboundp 'comment-indent-new-line)
(1- (frame-width))
fill-column)))
(indent-for-comment)))))
(goto-char mloc)
;; Get rid of marker
(set-marker mloc nil)))
(defun idlwave-do-action (action)
"Perform an action repeatedly on a line.
ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
either a function name to be called with `funcall' or a list to be
evaluated with `eval'. The action performed by FUNC should leave
point after the match for REG - otherwise an infinite loop may be
entered. FUNC is always passed a final argument of 'is-action, so it
can discriminate between being run as an action, or a key binding."
(let ((action-key (car action))
(action-routine (cdr action)))
(beginning-of-line)
(while (idlwave-look-at action-key)
(if (listp action-routine)
(eval (append action-routine '('is-action)))
(funcall action-routine 'is-action)))))
(defun idlwave-indent-to (col &optional min)
"Indent from point with spaces until column COL.
Inserts space before markers at point."
(if (not min) (setq min 0))
(insert-before-markers
(make-string (max min (- col (current-column))) ?\ )))
(defun idlwave-indent-left-margin (col)
"Indent the current line to column COL.
Indents such that first non-whitespace character is at column COL
Inserts spaces before markers at point."
(save-excursion
(beginning-of-line)
(delete-horizontal-space)
(idlwave-indent-to col)))
(defun idlwave-indent-subprogram ()
"Indent program unit which contains point."
(interactive)
(save-excursion
(idlwave-end-of-statement)
(idlwave-beginning-of-subprogram)
(let ((beg (point)))
(idlwave-forward-block)
(message "Indenting subprogram...")
(indent-region beg (point) nil))
(message "Indenting subprogram...done.")))
(defun idlwave-indent-statement ()
"Indent current statement, including all continuation lines."
(interactive)
(save-excursion
(idlwave-beginning-of-statement)
(let ((beg (point)))
(idlwave-end-of-statement)
(indent-region beg (point) nil))))
(defun idlwave-calculate-indent ()
"Return appropriate indentation for current line as IDL code."
(save-excursion
(beginning-of-line)
(cond
;; Check for beginning of unit - main (beginning of buffer), pro, or
;; function
((idlwave-look-at idlwave-begin-unit-reg)
0)
;; Check for continuation line
((save-excursion
(and (= (forward-line -1) 0)
(idlwave-is-continuation-line)))
(idlwave-calculate-cont-indent))
;; calculate indent based on previous and current statements
(t (let* (beg-prev-pos
(the-indent
;; calculate indent based on previous statement
(save-excursion
(cond
;; Beginning of file
((prog1
(idlwave-previous-statement)
(setq beg-prev-pos (point)))
0)
;; Main block
((idlwave-look-at idlwave-profun-reg t)
(+ (idlwave-current-statement-indent)
idlwave-main-block-indent))
;; Begin block
((idlwave-look-at idlwave-begin-block-reg t)
(+ (idlwave-min-current-statement-indent)
idlwave-block-indent))
;; End Block
((idlwave-look-at idlwave-end-block-reg t)
(progn
;; Match to the *beginning* of the block opener
(goto-char beg-prev-pos)
(idlwave-block-jump-out -1 'nomark) ; go to begin block
(idlwave-min-current-statement-indent)))
;; idlwave-end-offset
;; idlwave-block-indent))
;; Default to current indent
((idlwave-current-statement-indent))))))
;; adjust the indentation based on the current statement
(cond
;; End block
((idlwave-look-at idlwave-end-block-reg)
(+ the-indent idlwave-end-offset))
(the-indent)))))))
;;
;; Parentheses indent
;;
(defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
"Calculate the continuation indent inside a paren group.
Returns a cons-cell with (open . indent), where open is the
location of the open paren."
(let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
;; Found an innermost open paren.
(when open
(goto-char open)
;; Line up with next word unless this is a closing paren.
(cons open
(cond
;; Plain Kernighan-style nested indent
(idlwave-indent-parens-nested
(+ idlwave-continuation-indent (idlwave-current-indent)))
;; This is a closed paren - line up under open paren.
(close-exp
(current-column))
;; Empty (or just comment) follows -- revert to basic indent
((progn
;; Skip paren
(forward-char 1)
(looking-at "[ \t$]*\\(;.*\\)?$"))
nil)
;; Line up with first word after any blank space
((progn
(skip-chars-forward " \t")
(current-column))))))))
(defun idlwave-calculate-cont-indent ()
"Calculates the IDL continuation indent column from the previous statement.
Note that here previous statement usually means the beginning of the
current statement if this statement is a continuation of the previous
line. Various special types of continuations, including assignments,
routine definitions, and parenthetical groupings, are treated separately."
(save-excursion
(let* ((case-fold-search t)
(end-reg (progn (beginning-of-line) (point)))
(beg-last-statement (save-excursion (idlwave-previous-statement)
(point)))
(beg-reg (progn (idlwave-start-of-substatement 'pre)
(if (eq (line-beginning-position) end-reg)
(goto-char beg-last-statement)
(point))))
(basic-indent (+ (idlwave-min-current-statement-indent end-reg)
idlwave-continuation-indent))
fancy-nonparen-indent fancy-paren-indent)
(cond
;; Align then with its matching if, etc.
((let ((matchers '(("\\<if\\>" . "[ \t]*then")
("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
"[ \t]*until")
("\\<case\\>" . "[ \t]*of")))
match cont-re)
(goto-char end-reg)
(and
(setq cont-re
(catch 'exit
(while (setq match (car matchers))
(if (looking-at (cdr match))
(throw 'exit (car match)))
(setq matchers (cdr matchers)))))
(idlwave-find-key cont-re -1 'nomark beg-last-statement)))
(if (looking-at "end") ;; that one's special
(- (idlwave-current-indent)
(+ idlwave-block-indent idlwave-end-offset))
(idlwave-current-indent)))
;; Indent in from the previous line for continuing statements
((let ((matchers '("\\<then\\>"
"\\<do\\>"
"\\<repeat\\>"
"\\<else\\>"))
match)
(catch 'exit
(goto-char end-reg)
(if (/= (forward-line -1) 0)
(throw 'exit nil))
(while (setq match (car matchers))
(if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
"\\(;.*\\)?$"))
(throw 'exit t))
(setq matchers (cdr matchers)))))
(+ idlwave-continuation-indent (idlwave-current-indent)))
;; Parenthetical indent, either traditional or Kernighan style
((setq fancy-paren-indent
(let* ((end-reg end-reg)
(close-exp (progn
(goto-char end-reg)
(skip-chars-forward " \t")
(looking-at "\\s)")))
indent-cons)
(catch 'loop
(while (setq indent-cons (idlwave-calculate-paren-indent
beg-reg end-reg close-exp))
;; First permitted containing paren
(if (or
idlwave-indent-to-open-paren
idlwave-indent-parens-nested
(null (cdr indent-cons))
(< (- (cdr indent-cons) basic-indent)
idlwave-max-extra-continuation-indent))
(throw 'loop (cdr indent-cons)))
(setq end-reg (car indent-cons))))))
fancy-paren-indent)
;; A continued assignment, or procedure call/definition
((and
(> idlwave-max-extra-continuation-indent 0)
(setq fancy-nonparen-indent
(progn
(goto-char beg-reg)
(while (idlwave-look-at "&")) ; skip continued statements
(cond
;; A continued Procedure call or definition
((progn
(idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
(looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
(goto-char (match-end 0))
;; Comment only, or blank line with "$"? Basic indent.
(if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
nil
(current-column)))
;; Continued assignment (with =):
((catch 'assign ;
(while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
(goto-char (match-end 0))
(if (null (idlwave-what-function beg-reg))
(throw 'assign t))))
(unless (or
(idlwave-in-quote)
(looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
(save-excursion
(goto-char beg-last-statement)
(eq (caar (idlwave-statement-type)) 'for)))
(current-column))))))
(< (- fancy-nonparen-indent basic-indent)
idlwave-max-extra-continuation-indent))
(if fancy-paren-indent ;calculated but disallowed paren indent
(+ fancy-nonparen-indent idlwave-continuation-indent)
fancy-nonparen-indent))
;; Basic indent, by default
(t basic-indent)))))
(defun idlwave-find-key (key-re &optional dir nomark limit)
"Move to next match of the regular expression KEY-RE.
Matches inside comments or string constants will be ignored.
If DIR is negative, the search will be backwards.
At a successful match, the mark is pushed unless NOMARK is non-nil.
Searches are limited to LIMIT.
Searches are case-insensitive and use a special syntax table which
treats `$' and `_' as word characters.
Return value is the beginning of the match or (in case of failure) nil."
(setq dir (or dir 0))
(let ((case-fold-search t)
(search-func (if (> dir 0) 're-search-forward 're-search-backward))
found)
(idlwave-with-special-syntax
(save-excursion
(catch 'exit
(while (funcall search-func key-re limit t)
(if (not (idlwave-quoted))
(throw 'exit (setq found (match-beginning 0)))
(if (or (and (> dir 0) (eobp))
(and (< dir 0) (bobp)))
(throw 'exit nil)))))))
(if found
(progn
(if (not nomark) (push-mark))
(goto-char found)
found)
nil)))
(defun idlwave-block-jump-out (&optional dir nomark)
"When optional argument DIR is non-negative, move forward to end of
current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
regular expressions. When DIR is negative, move backwards to block beginning.
Recursively calls itself to skip over nested blocks. DIR defaults to
forward. Calls `push-mark' unless the optional argument NOMARK is
non-nil. Movement is limited by the start of program units because of
possibility of unbalanced blocks."
(interactive "P")
(or dir (setq dir 0))
(let* ((here (point))
(case-fold-search t)
(limit (if (>= dir 0) (point-max) (point-min)))
(block-limit (if (>= dir 0)
idlwave-begin-block-reg
idlwave-end-block-reg))
found
(block-reg (concat idlwave-begin-block-reg "\\|"
idlwave-end-block-reg))
(unit-limit (or (save-excursion
(if (< dir 0)
(idlwave-find-key
idlwave-begin-unit-reg dir t limit)
(end-of-line)
(idlwave-find-key
idlwave-end-unit-reg dir t limit)))
limit)))
(if (>= dir 0) (end-of-line)) ;Make sure we are in current block
(if (setq found (idlwave-find-key block-reg dir t unit-limit))
(while (and found (looking-at block-limit))
(if (>= dir 0) (forward-word 1))
(idlwave-block-jump-out dir t)
(setq found (idlwave-find-key block-reg dir t unit-limit))))
(if (not nomark) (push-mark here))
(if (not found) (goto-char unit-limit)
(if (>= dir 0) (forward-word 1)))))
(defun idlwave-min-current-statement-indent (&optional end-reg)
"The minimum indent in the current statement."
(idlwave-beginning-of-statement)
(if (not (idlwave-is-continuation-line))
(idlwave-current-indent)
(let ((min (idlwave-current-indent)) comm-or-empty)
(while (and (= (forward-line 1) 0)
(or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
(idlwave-is-continuation-line))
(or (null end-reg) (< (point) end-reg)))
(unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
(if (or comm-or-empty (and end-reg (>= (point) end-reg)))
min
(min min (idlwave-current-indent))))))
(defun idlwave-current-statement-indent (&optional last-line)
"Return indentation of the current statement.
If in a statement, moves to beginning of statement before finding indent."
(if last-line
(idlwave-end-of-statement)
(idlwave-beginning-of-statement))
(idlwave-current-indent))
(defun idlwave-current-indent ()
"Return the column of the indentation of the current line.
Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
;; if we are at the end of blank line return 0
(cond ((eolp) 0)
((current-column)))))
(defun idlwave-is-continuation-line ()
"Test if current line is continuation line.
Blank or comment-only lines following regular continuation lines (with
`$') count as continuations too."
(let (p)
(save-excursion
(or
(idlwave-look-at "\\<\\$")
(catch 'loop
(while (and (looking-at "^[ \t]*\\(;.*\\)?$")
(eq (forward-line -1) 0))
(if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
(defun idlwave-is-comment-line ()
"Test if the current line is a comment line."
(save-excursion
(beginning-of-line 1)
(looking-at "[ \t]*;")))
(defun idlwave-is-comment-or-empty-line ()
"Test if the current line is a comment line."
(save-excursion
(beginning-of-line 1)
(looking-at "[ \t]*[;\n]")))
(defun idlwave-look-at (regexp &optional cont beg)
"Search current line from current point for REGEXP.
If optional argument CONT is non-nil, searches to the end of
the current statement.
If optional arg BEG is non-nil, search starts from the beginning of the
current statement.
Ignores matches that end in a comment or inside a string expression.
Returns point if successful, nil otherwise.
This function produces unexpected results if REGEXP contains quotes or
a comment delimiter. The search is case insensitive.
If successful, leaves point after the match, otherwise, does not move point."
(let ((here (point))
(case-fold-search t)
(eos (save-excursion
(if cont (idlwave-end-of-statement) (end-of-line))
(point)))
found)
(idlwave-with-special-syntax
(if beg (idlwave-beginning-of-statement))
(while (and (setq found (re-search-forward regexp eos t))
(idlwave-quoted))))
(if (not found) (goto-char here))
found))
(defun idlwave-fill-paragraph (&optional nohang)
"Fill paragraphs in comments.
A paragraph is made up of all contiguous lines having the same comment
leader (the leading whitespace before the comment delimiter and the
comment delimiter). In addition, paragraphs are separated by blank
line comments. The indentation is given by the hanging indent of the
first line, otherwise by the minimum indentation of the lines after
the first line. The indentation of the first line does not change.
Does not effect code lines. Does not fill comments on the same line
with code. The hanging indent is given by the end of the first match
matching `idlwave-hang-indent-regexp' on the paragraph's first line.
If the optional argument NOHANG is non-nil then the hanging indent is
ignored."
(interactive "P")
;; check if this is a line comment
(if (save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(looking-at comment-start))
(let
((indent 999)
pre here diff fill-prefix-reg bcl first-indent
hang start end)
;; Change tabs to spaces in the surrounding paragraph.
;; The surrounding paragraph will be the largest containing block of
;; contiguous line comments. Thus, we may be changing tabs in
;; a much larger area than is needed, but this is the easiest
;; brute force way to do it.
;;
;; This has the undesirable side effect of replacing the tabs
;; permanently without the user's request or knowledge.
(save-excursion
(backward-paragraph)
(setq start (point)))
(save-excursion
(forward-paragraph)
(setq end (point)))
(untabify start end)
;;
(setq here (point))
(beginning-of-line)
(setq bcl (point))
(re-search-forward
(concat "^[ \t]*" comment-start "+")
(save-excursion (end-of-line) (point))
t)
;; Get the comment leader on the line and its length
(setq pre (current-column))
;; the comment leader is the indentation plus exactly the
;; number of consecutive ";".
(setq fill-prefix-reg
(concat
(setq fill-prefix
(regexp-quote
(buffer-substring (save-excursion
(beginning-of-line) (point))
(point))))
"[^;]"))
;; Mark the beginning and end of the paragraph
(goto-char bcl)
(while (and (looking-at fill-prefix-reg)
(not (looking-at paragraph-separate))
(not (bobp)))
(forward-line -1))
;; Move to first line of paragraph
(if (/= (point) bcl)
(forward-line 1))
(setq start (point))
(goto-char bcl)
(while (and (looking-at fill-prefix-reg)
(not (looking-at paragraph-separate))
(not (eobp)))
(forward-line 1))
(beginning-of-line)
(if (or (not (looking-at fill-prefix-reg))
(looking-at paragraph-separate))
(forward-line -1))
(end-of-line)
;; if at end of buffer add a newline (need this because
;; fill-region needs END to be at the beginning of line after
;; the paragraph or it will add a line).
(if (eobp)
(progn (insert ?\n) (backward-char 1)))
;; Set END to the beginning of line after the paragraph
;; END is calculated as distance from end of buffer
(setq end (- (point-max) (point) 1))
;;
;; Calculate the indentation for the paragraph.
;;
;; In the following while statements, after one iteration
;; point will be at the beginning of a line in which case
;; the while will not be executed for the
;; the first paragraph line and thus will not affect the
;; indentation.
;;
;; First check to see if indentation is based on hanging indent.
(if (and (not nohang) idlwave-hanging-indent
(setq hang
(save-excursion
(goto-char start)
(idlwave-calc-hanging-indent))))
;; Adjust lines of paragraph by inserting spaces so that
;; each line's indent is at least as great as the hanging
;; indent. This is needed for fill-paragraph to work with
;; a fill-prefix.
(progn
(setq indent hang)
(beginning-of-line)
(while (> (point) start)
(re-search-forward comment-start-skip
(save-excursion (end-of-line) (point))
t)
(if (> (setq diff (- indent (current-column))) 0)
(progn
(if (>= here (point))
;; adjust the original location for the
;; inserted text.
(setq here (+ here diff)))
(insert (make-string diff ?\ ))))
(forward-line -1))
)
;; No hang. Instead find minimum indentation of paragraph
;; after first line.
;; For the following while statement, since START is at the
;; beginning of line and END is at the end of line
;; point is greater than START at least once (which would
;; be the case for a single line paragraph).
(while (> (point) start)
(beginning-of-line)
(setq indent
(min indent
(progn
(re-search-forward
comment-start-skip
(save-excursion (end-of-line) (point))
t)
(current-column))))
(forward-line -1))
)
(setq fill-prefix (concat fill-prefix
(make-string (- indent pre)
?\ )))
;; first-line indent
(setq first-indent
(max
(progn
(re-search-forward
comment-start-skip
(save-excursion (end-of-line) (point))
t)
(current-column))
indent))
;; try to keep point at its original place
(goto-char here)
;; In place of the more modern fill-region-as-paragraph, a hack
;; to keep whitespace untouched on the first line within the
;; indent length and to preserve any indent on the first line
;; (first indent).
(save-excursion
(setq diff
(buffer-substring start (+ start first-indent -1)))
(subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
(fill-region-as-paragraph
start
(- (point-max) end)
(current-justification)
nil)
(delete-region start (+ start first-indent -1))
(goto-char start)
(insert diff))
;; When we want the point at the beginning of the comment
;; body fill-region will put it at the beginning of the line.
(if (bolp) (skip-chars-forward (concat " \t" comment-start)))
(setq fill-prefix nil))))
(defun idlwave-calc-hanging-indent ()
"Calculate the position of the hanging indent for the comment paragraph.
The hanging indent position is given by the first match with the
`idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
on the line.
If not found returns nil."
(if idlwave-use-last-hang-indent
(save-excursion
(end-of-line)
(if (re-search-backward
idlwave-hang-indent-regexp
(save-excursion (beginning-of-line) (point))
t)
(+ (current-column) (length idlwave-hang-indent-regexp))))
(save-excursion
(beginning-of-line)
(if (re-search-forward
idlwave-hang-indent-regexp
(save-excursion (end-of-line) (point))
t)
(current-column)))))
(defun idlwave-auto-fill ()
"Called to break lines in auto fill mode.
Only fills non-comment lines if `idlwave-fill-comment-line-only'
is nil (it is t by default). Places a continuation character at
the end of the line if not in a comment. Splits strings with IDL
concatenation operator `+' if `idlwave-auto-fill-split-string' is
non-nil."
(if (<= (current-column) fill-column)
nil ; do not to fill
(if (or (not idlwave-fill-comment-line-only)
(save-excursion
;; Check for comment line
(beginning-of-line)
(looking-at idlwave-comment-line-start-skip)))
(let (beg)
(idlwave-indent-line)
;; Prevent actions do-auto-fill which calls indent-line-function.
(let (idlwave-do-actions
(fill-nobreak-predicate
(if (and (idlwave-in-quote)
idlwave-auto-fill-split-string)
(lambda () ;; We'll need 5 spaces for " ' + $"
(<= (- fill-column (current-column)) 5)
))))
(do-auto-fill))
(save-excursion
(end-of-line 0)
;; Indent the split line
(idlwave-indent-line))
(if (save-excursion
(beginning-of-line)
(looking-at idlwave-comment-line-start-skip))
;; A continued line comment
;; We treat continued line comments as part of a comment
;; paragraph. So we check for a hanging indent.
(if idlwave-hanging-indent
(let ((here (- (point-max) (point)))
(indent
(save-excursion
(forward-line -1)
(idlwave-calc-hanging-indent))))
(if indent
(progn
;; Remove whitespace between comment delimiter and
;; text, insert spaces for appropriate indentation.
(beginning-of-line)
(re-search-forward
comment-start-skip
(save-excursion (end-of-line) (point)) t)
(delete-horizontal-space)
(idlwave-indent-to indent)
(goto-char (- (point-max) here)))
)))
;; Split code or comment?
(if (save-excursion
(end-of-line 0)
(idlwave-in-comment))
;; Splitting a non-full-line comment.
;; Insert the comment delimiter from split line
(progn
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
;; Insert blank to keep off beginning of line
(insert " "
(save-excursion
(forward-line -1)
(buffer-substring (idlwave-goto-comment)
(progn
(skip-chars-forward "; ")
(point))))))
(idlwave-indent-line))
;; Split code line - add continuation character
(save-excursion
(end-of-line 0)
;; Check to see if we split a string
(if (and (setq beg (idlwave-in-quote))
idlwave-auto-fill-split-string)
;; Split the string and concatenate.
;; The first extra space is for the space
;; the line was split. That space was removed.
(insert " " (char-after beg) " +"))
(insert " $"))
(if beg
(if idlwave-auto-fill-split-string
;; Make the second part of continued string
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(insert (char-after beg)))
;; Warning
(beep)
(message "Warning: continuation inside a string.")))
;; Although do-auto-fill (via indent-new-comment-line) calls
;; idlwave-indent-line for the new line, re-indent again
;; because of the addition of the continuation character.
(idlwave-indent-line))
)))))
(defun idlwave-auto-fill-mode (arg)
"Toggle auto-fill mode for IDL mode.
With arg, turn auto-fill mode on if arg is positive.
In auto-fill mode, inserting a space at a column beyond `fill-column'
automatically breaks the line at a previous space."
(interactive "P")
(prog1 (set idlwave-fill-function
(if (if (null arg)
(not (symbol-value idlwave-fill-function))
(> (prefix-numeric-value arg) 0))
'idlwave-auto-fill
nil))
;; update mode-line
(set-buffer-modified-p (buffer-modified-p))))
;(defun idlwave-fill-routine-call ()
; "Fill a routine definition or statement, indenting appropriately."
; (let ((where (idlwave-where)))))
(defun idlwave-doc-header (&optional nomark)
"Insert a documentation header at the beginning of the unit.
Inserts the value of the variable `idlwave-file-header'. Sets mark
before moving to do insertion unless the optional prefix argument
NOMARK is non-nil."
(interactive "P")
(or nomark (push-mark))
;; make sure we catch the current line if it begins the unit
(if idlwave-header-to-beginning-of-file
(goto-char (point-min))
(end-of-line)
(idlwave-beginning-of-subprogram)
(beginning-of-line)
;; skip function or procedure line
(if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
(progn
(idlwave-end-of-statement)
(if (> (forward-line 1) 0) (insert "\n")))))
(let ((pos (point)))
(if idlwave-file-header
(cond ((car idlwave-file-header)
(insert-file-contents (car idlwave-file-header)))
((stringp (car (cdr idlwave-file-header)))
(insert (car (cdr idlwave-file-header))))))
(goto-char pos)))
(defun idlwave-default-insert-timestamp ()
"Default timestamp insertion function."
(insert (current-time-string))
(insert ", " (user-full-name))
(if (boundp 'user-mail-address)
(insert " <" user-mail-address ">")
(insert " <" (user-login-name) "@" (system-name) ">"))
;; Remove extra spaces from line
(idlwave-fill-paragraph)
;; Insert a blank line comment to separate from the date entry -
;; will keep the entry from flowing onto date line if re-filled.
(insert "\n;\n;\t\t"))
(defun idlwave-doc-modification ()
"Insert a brief modification log at the beginning of the current program.
Looks for an occurrence of the value of user variable
`idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
name and places the point for the user to add a log. Before moving, saves
location on mark ring so that the user can return to previous point."
(interactive)
(push-mark)
(let* (beg end)
(if (and (or (re-search-backward idlwave-doclib-start nil t)
(progn
(goto-char (point-min))
(re-search-forward idlwave-doclib-start nil t)))
(setq beg (match-beginning 0))
(re-search-forward idlwave-doclib-end nil t)
(setq end (match-end 0)))
(progn
(goto-char beg)
(if (re-search-forward
(concat idlwave-doc-modifications-keyword ":")
end t)
(end-of-line)
(goto-char end)
(end-of-line -1)
(insert "\n" comment-start "\n")
(insert comment-start " " idlwave-doc-modifications-keyword ":"))
(insert "\n;\n;\t")
(run-hooks 'idlwave-timestamp-hook))
(error "No valid DOCLIB header"))))
;; CJC 3/16/93
;; Interface to expand-region-abbrevs which did not work when the
;; abbrev hook associated with an abbrev moves point backwards
;; after abbrev expansion, e.g., as with the abbrev '.n'.
;; The original would enter an infinite loop in attempting to expand
;; .n (it would continually expand and unexpand the abbrev without expanding
;; because the point would keep going back to the beginning of the
;; abbrev instead of to the end of the abbrev). We now keep the
;; abbrev hook from moving backwards.
;;;
(defun idlwave-expand-region-abbrevs (start end)
"Expand each abbrev occurrence in the region.
Calling from a program, arguments are START END."
(interactive "r")
(save-excursion
(goto-char (min start end))
(let ((idlwave-show-block nil) ;Do not blink
(idlwave-abbrev-move nil)) ;Do not move
(expand-region-abbrevs start end 'noquery))))
(defun idlwave-quoted ()
"Return t if point is in a comment or quoted string.
Returns nil otherwise."
(or (idlwave-in-comment) (idlwave-in-quote)))
(defun idlwave-in-quote ()
"Return location of the opening quote
if point is in a IDL string constant, nil otherwise.
Ignores comment delimiters on the current line.
Properly handles nested quotation marks and octal
constants - a double quote followed by an octal digit."
;; Treat an octal inside an apostrophe to be a normal string. Treat a
;; double quote followed by an octal digit to be an octal constant
;; rather than a string. Therefore, there is no terminating double
;; quote.
(save-excursion
;; Because single and double quotes can quote each other we must
;; search for the string start from the beginning of line.
(let* ((start (point))
(eol (progn (end-of-line) (point)))
(bq (progn (beginning-of-line) (point)))
(endq (point))
(data (match-data))
delim
found)
(while (< endq start)
;; Find string start
;; Don't find an octal constant beginning with a double quote
(if (re-search-forward "[\"']" eol 'lim)
;; Find the string end.
;; In IDL, two consecutive delimiters after the start of a
;; string act as an
;; escape for the delimiter in the string.
;; Two consecutive delimiters alone (i.e., not after the
;; start of a string) is the null string.
(progn
;; Move to position after quote
(goto-char (1+ (match-beginning 0)))
(setq bq (1- (point)))
;; Get the string delimiter
(setq delim (char-to-string (preceding-char)))
;; Check for null string
(if (looking-at delim)
(progn (setq endq (point)) (forward-char 1))
;; Look for next unpaired delimiter
(setq found (search-forward delim eol 'lim))
(while (looking-at delim)
(forward-char 1)
(setq found (search-forward delim eol 'lim)))
(setq endq (if found (1- (point)) (point)))
))
(progn (setq bq (point)) (setq endq (point)))))
(store-match-data data)
;; return string beginning position or nil
(if (> start bq) bq))))
(defun idlwave-is-pointer-dereference (&optional limit)
"Determine if the character after point is a pointer dereference *."
(and
(eq (char-after) ?\*)
(not (idlwave-in-quote))
(save-excursion
(forward-char)
(re-search-backward (concat "\\(" idlwave-idl-keywords
"\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
;; Statement templates
;; Replace these with a general template function, something like
;; expand.el (I think there was also something with a name similar to
;; dmacro.el)
(defun idlwave-template (s1 s2 &optional prompt noindent)
"Build a template with optional prompt expression.
Opens a line if point is not followed by a newline modulo intervening
whitespace. S1 and S2 are strings. S1 is inserted at point followed
by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
adjusted according to `idlwave-abbrev-change-case'. If optional
argument PROMPT is a string then it is displayed as a message in the
minibuffer. The PROMPT serves as a reminder to the user of an
expression to enter.
The lines containing S1 and S2 are reindented using `indent-region'
unless the optional second argument NOINDENT is non-nil."
(if (eq major-mode 'idlwave-shell-mode)
;; This is a gross hack to avoit template abbrev expansion
;; in the shell. FIXME: This is a dirty hack.
(if (and (eq this-command 'self-insert-command)
(equal last-abbrev-location (point)))
(insert last-abbrev-text)
(error "No templates in idlwave-shell"))
(cond ((eq idlwave-abbrev-change-case 'down)
(setq s1 (downcase s1) s2 (downcase s2)))
(idlwave-abbrev-change-case
(setq s1 (upcase s1) s2 (upcase s2))))
(let ((beg (save-excursion (beginning-of-line) (point)))
end)
(if (not (looking-at "\\s-*\n"))
(open-line 1))
(insert s1)
(save-excursion
(insert s2)
(setq end (point)))
(if (not noindent)
(indent-region beg end nil))
(if (stringp prompt)
(message "%s" prompt)))))
(defun idlwave-rw-case (string)
"Make STRING have the case required by `idlwave-reserved-word-upcase'."
(if idlwave-reserved-word-upcase
(upcase string)
string))
(defun idlwave-elif ()
"Build skeleton IDL if-else block."
(interactive)
(idlwave-template
(idlwave-rw-case "if")
(idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
"Condition expression"))
(defun idlwave-case ()
"Build skeleton IDL case statement."
(interactive)
(idlwave-template
(idlwave-rw-case "case")
(idlwave-rw-case " of\n\nendcase")
"Selector expression"))
(defun idlwave-switch ()
"Build skeleton IDL switch statement."
(interactive)
(idlwave-template
(idlwave-rw-case "switch")
(idlwave-rw-case " of\n\nendswitch")
"Selector expression"))
(defun idlwave-for ()
"Build skeleton IDL for loop statement."
(interactive)
(idlwave-template
(idlwave-rw-case "for")
(idlwave-rw-case " do begin\n\nendfor")
"Loop expression"))
(defun idlwave-if ()
"Build skeleton IDL if statement."