1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Carsten Dominik <dominik@science.uva.nl>
8 ;; Chris Chase <chase@att.com>
9 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
11 ;; Keywords: languages
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 3, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; IDLWAVE enables feature-rich development and interaction with IDL,
33 ;; the Interactive Data Language. It provides a compelling,
34 ;; full-featured alternative to the IDLDE development environment
37 ;; In the remotely distant past, based on pascal.el, though bears
38 ;; little resemblance to it now.
40 ;; Incorporates many ideas, such as abbrevs, action routines, and
41 ;; continuation line indenting, from wave.el.
42 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
44 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
45 ;; for features, key bindings, and info.
46 ;; Also, Info format documentation is available with `M-x idlwave-info'
48 ;; New versions of IDLWAVE, documentation, and more information
55 ;; Follow the instructions in the INSTALL file of the distribution.
56 ;; In short, put this file on your load path and add the following
57 ;; lines to your .emacs file:
59 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
60 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
61 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
67 ;; The newest version of this file is available from the maintainer's
75 ;; IDLWAVE is documented online in info format. A printable version
76 ;; of the documentation is available from the maintainers webpage (see
83 ;; Thanks to the following people for their contributions and comments:
85 ;; Ulrik Dickow <dickow_at_nbi.dk>
86 ;; Eric E. Dors <edors_at_lanl.gov>
87 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
88 ;; David Huenemoerder <dph_at_space.mit.edu>
89 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
90 ;; Dick Jackson <dick_at_d-jackson.com>
91 ;; Xuyong Liu <liu_at_stsci.edu>
92 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
93 ;; Laurent Mugnier <mugnier_at_onera.fr>
94 ;; Lubos Pochman <lubos_at_rsinc.com>
95 ;; Bob Portmann <portmann_at_al.noaa.gov>
96 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
97 ;; Marty Ryba <ryba_at_ll.mit.edu>
98 ;; Paul Sorenson <aardvark62_at_msn.com>
99 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
100 ;; Phil Williams <williams_at_irc.chmcc.org>
105 ;; IDLWAVE has extensive customize support; to learn about the
106 ;; variables which control the mode's behavior, use `M-x
107 ;; idlwave-customize'.
109 ;; You can set your own preferred values with Customize, or with Lisp
110 ;; code in .emacs. For an example of what to put into .emacs, check
111 ;; the TexInfo documentation or see a complete .emacs available at the
117 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
118 ;; Numerics, Inc. is growing less and less complete as the two
119 ;; languages grow increasingly apart. The mode probably shouldn't
120 ;; even have "WAVE" in its title, but it's catchy, and was required
121 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
123 ;; Moving the point backwards in conjunction with abbrev expansion
124 ;; does not work as I would like it, but this is a problem with
125 ;; emacs abbrev expansion done by the self-insert-command. It ends
126 ;; up inserting the character that expanded the abbrev after moving
127 ;; point backward, e.g., "\cl" expanded with a space becomes
128 ;; "LONG( )" with point before the close paren. This is solved by
129 ;; using a temporary function in `post-command-hook' - not pretty,
132 ;; Tabs and spaces are treated equally as whitespace when filling a
133 ;; comment paragraph. To accomplish this, tabs are permanently
134 ;; replaced by spaces in the text surrounding the paragraph, which
135 ;; may be an undesirable side-effect. Replacing tabs with spaces is
136 ;; limited to comments only and occurs only when a comment
137 ;; paragraph is filled via `idlwave-fill-paragraph'.
139 ;; Muti-statement lines (using "&") on block begin and end lines can
140 ;; ruin the formatting. For example, multiple end statements on a
141 ;; line: endif & endif. Using "&" outside of block begin/end lines
144 ;; Determining the expression at point for printing and other
145 ;; examination commands is somewhat rough: currently only fairly
146 ;; simple entities are found. You can always drag-select or examine
147 ;; a pre-selected region.
149 ;; When forcing completion of method keywords, the initial
150 ;; query for a method has multiple entries for some methods. Would
151 ;; be too difficult to fix this hardly used case.
157 (eval-when-compile (require 'cl
))
161 (unless (fboundp 'line-beginning-position
)
162 (defalias 'line-beginning-position
'point-at-bol
))
163 (unless (fboundp 'line-end-position
)
164 (defalias 'line-end-position
'point-at-eol
))
165 (unless (fboundp 'char-valid-p
)
166 (defalias 'char-valid-p
'characterp
))
167 (unless (fboundp 'match-string-no-properties
)
168 (defalias 'match-string-no-properties
'match-string
))
170 (if (not (fboundp 'cancel-timer
))
175 (declare-function idlwave-shell-get-path-info
"idlw-shell")
176 (declare-function idlwave-shell-temp-file
"idlw-shell")
177 (declare-function idlwave-shell-is-running
"idlw-shell")
178 (declare-function widget-value
"wid-edit" (widget))
179 (declare-function comint-dynamic-complete-filename
"comint" ())
180 (declare-function Info-goto-node
"info" (nodename &optional fork
))
182 (defgroup idlwave nil
183 "Major mode for editing IDL .pro files."
185 :link
'(url-link :tag
"Home Page"
186 "http://idlwave.org")
187 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
189 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
190 :link
'(custom-manual "(idlwave)Top")
195 ;;; Variables for indentation behavior ---------------------------------------
197 (defgroup idlwave-code-formatting nil
198 "Indentation and formatting options for IDLWAVE mode."
201 (defcustom idlwave-main-block-indent
2
202 "*Extra indentation for the main block of code.
203 That is the block between the FUNCTION/PRO statement and the END
204 statement for that program unit."
205 :group
'idlwave-code-formatting
208 (defcustom idlwave-block-indent
3
209 "*Extra indentation applied to block lines.
210 If you change this, you probably also want to change `idlwave-end-offset'."
211 :group
'idlwave-code-formatting
214 (defcustom idlwave-end-offset -
3
215 "*Extra indentation applied to block END lines.
216 A value equal to negative `idlwave-block-indent' will make END lines
217 line up with the block BEGIN lines."
218 :group
'idlwave-code-formatting
221 (defcustom idlwave-continuation-indent
3
222 "*Extra indentation applied to continuation lines.
223 This extra offset applies to the first of a set of continuation lines.
224 The following lines receive the same indentation as the first."
225 :group
'idlwave-code-formatting
228 (defcustom idlwave-max-extra-continuation-indent
40
229 "*Maximum additional indentation for special continuation indent.
230 Several special indentations are tried to help line up continuation
231 lines in routine calls or definitions, other statements with
232 parentheses, or assignment statements. This variable specifies a
233 maximum amount by which this special indentation can exceed the
234 standard continuation indentation, otherwise defaulting to a fixed
235 offset. Set to 0 to effectively disable all special continuation
236 indentation, or to a large number (like 100) to enable it in all
237 cases. See also `idlwave-indent-to-open-paren', which can override
239 :group
'idlwave-code-formatting
242 (defcustom idlwave-indent-to-open-paren t
243 "*Non-nil means, indent continuation lines to innermost open
244 parenthesis. This indentation occurs even if otherwise disallowed by
245 `idlwave-max-extra-continuation-indent'. Matching parens and the
246 interleaving args are lined up. Example:
248 x = function_a(function_b(function_c( a, b, [1,2,3, $
254 When this variable is nil, paren alignment may still occur, based on
255 the value of `max-extra-continuation-indent', which, if zero, would
258 x = function_a(function_b(function_c( a, b, [1,2,3, $
263 :group
'idlwave-code-formatting
266 (defcustom idlwave-indent-parens-nested nil
267 "*Non-nil means, indent continuation lines with parens by nesting
268 lines at consecutively deeper levels."
269 :group
'idlwave-code-formatting
273 (defcustom idlwave-hanging-indent t
274 "*If set non-nil then comment paragraphs are indented under the
275 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
277 :group
'idlwave-code-formatting
280 (defcustom idlwave-hang-indent-regexp
"- "
281 "*Regular expression matching the position of the hanging indent
282 in the first line of a comment paragraph. The size of the indent
283 extends to the end of the match for the regular expression."
284 :group
'idlwave-code-formatting
287 (defcustom idlwave-use-last-hang-indent nil
288 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
289 :group
'idlwave-code-formatting
292 (defcustom idlwave-fill-comment-line-only t
293 "*If non-nil then auto fill will only operate on comment lines."
294 :group
'idlwave-code-formatting
297 (defcustom idlwave-auto-fill-split-string t
298 "*If non-nil then auto fill will split strings with the IDL `+' operator.
299 When the line end falls within a string, string concatenation with the
300 '+' operator will be used to distribute a long string over lines.
301 If nil and a string is split then a terminal beep and warning are issued.
303 This variable is ignored when `idlwave-fill-comment-line-only' is
304 non-nil, since in this case code is not auto-filled."
305 :group
'idlwave-code-formatting
308 (defcustom idlwave-split-line-string t
309 "*If non-nil then `idlwave-split-line' will split strings with `+'.
310 When the splitting point of a line falls inside a string, split the string
311 using the `+' string concatenation operator. If nil and a string is
312 split then a terminal beep and warning are issued."
313 :group
'idlwave-code-formatting
316 (defcustom idlwave-no-change-comment
";;;"
317 "*The indentation of a comment that starts with this regular
318 expression will not be changed. Note that the indentation of a comment
319 at the beginning of a line is never changed."
320 :group
'idlwave-code-formatting
323 (defcustom idlwave-begin-line-comment nil
324 "*A comment anchored at the beginning of line.
325 A comment matching this regular expression will not have its
326 indentation changed. If nil the default is \"^;\", i.e., any line
327 beginning with a \";\". Expressions for comments at the beginning of
328 the line should begin with \"^\"."
329 :group
'idlwave-code-formatting
330 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
333 (defcustom idlwave-code-comment
";;[^;]"
334 "*A comment that starts with this regular expression on a line by
335 itself is indented as if it is a part of IDL code. As a result if
336 the comment is not preceded by whitespace it is unchanged."
337 :group
'idlwave-code-formatting
340 ;; Comments not matching any of the above will be indented as a
341 ;; right-margin comment, i.e., to a minimum of `comment-column'.
343 ;;; Routine Info and Completion ---------------------------------------
345 (defgroup idlwave-routine-info nil
346 "Routine Info options for IDLWAVE mode."
349 (defcustom idlwave-use-library-catalogs t
350 "*Non-nil means search the IDL path for library catalog files.
352 These files, named .idlwave_catalog, document routine information for
353 individual directories and libraries of IDL .pro files. Many popular
354 libraries come with catalog files by default, so leaving this on is a
355 usually a good idea.."
356 :group
'idlwave-routine-info
359 (defcustom idlwave-init-rinfo-when-idle-after
10
360 "*Seconds of idle time before routine info is automatically
361 initialized. Initializing the routine info can take a long time, in
362 particular if a large number of library catalogs are involved. When
363 Emacs is idle for more than the number of seconds specified by this
364 variable, it starts the initialization. The process is split into
365 five steps, in order to keep work interruption as short as possible.
366 If one of the steps finishes, and no user input has arrived in the
367 mean time, initialization proceeds immediately to the next step. A
368 good value for this variable is about 1/3 of the time initialization
369 take in your setup. So if you have a fast machine and no problems
370 with a slow network connection, don't hesitate to set this to 2
371 seconds. A Value of 0 means, don't initialize automatically, but
372 instead wait until routine information is needed, and initialize
374 :group
'idlwave-routine-info
377 (defcustom idlwave-scan-all-buffers-for-routine-info t
378 "*Non-nil means, scan buffers for IDL programs when updating info.
379 The scanning is done by the command `idlwave-update-routine-info'.
380 The following values are allowed:
382 nil Don't scan any buffers.
383 t Scan all idlwave-mode buffers in the current editing session.
384 current Scan only the current buffer, but no other buffers."
385 :group
'idlwave-routine-info
387 (const :tag
"No buffer" nil
)
388 (const :tag
"All buffers" t
)
389 (const :tag
"Current buffer only" 'current
)))
391 (defcustom idlwave-query-shell-for-routine-info t
392 "*Non-nil means query the shell for info about compiled routines.
393 Querying the shell is useful to get information about compiled modules,
394 and it is turned on by default. However, when you have a complete library
395 scan, this is not necessary."
396 :group
'idlwave-routine-info
399 (defcustom idlwave-auto-routine-info-updates
400 '(find-file save-buffer kill-buffer compile-buffer
)
401 "*Controls under what circumstances routine info is updated automatically.
405 \(...) A list of circumstances. Allowed members are:
406 find-file Add info for new IDLWAVE buffers.
407 save-buffer Update buffer info when buffer is saved
408 kill-buffer Remove buffer info when buffer gets killed
409 compile-buffer Update shell info after `idlwave-shell-save-and...'"
410 :group
'idlwave-routine-info
412 (const :tag
"Never" nil
)
413 (const :tag
"As often as possible" t
)
414 (set :tag
"Checklist" :greedy t
415 (const :tag
"When visiting a file" find-file
)
416 (const :tag
"When saving a buffer" save-buffer
)
417 (const :tag
"After a buffer was killed" kill-buffer
)
418 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
420 (defcustom idlwave-rinfo-max-source-lines
5
421 "*Maximum number of source files displayed in the Routine Info window.
422 When an integer, it is the maximum number of source files displayed.
423 t means to show all source files."
424 :group
'idlwave-routine-info
427 (defcustom idlwave-library-path nil
428 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
429 When selecting the directories to scan for IDL user catalog routine
430 info, IDLWAVE can, under UNIX, query the shell for the exact search
431 path \(the value of !PATH). However, under Windows and MacOS
432 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
433 variable can be set to specify the paths where IDLWAVE can find PRO
434 files. The shell will only be asked for a list of paths when this
435 variable is nil. The value is a list of directories. A directory
436 preceeded by a `+' will be searched recursively. If you set this
437 variable on a UNIX system, the shell will not be queried. See also
438 `idlwave-system-directory'."
439 :group
'idlwave-routine-info
440 :type
'(repeat (directory)))
442 (defcustom idlwave-system-directory
""
443 "The IDL system directory for Windows and MacOS. Not needed under
444 UNIX. Set this to the value of the `!DIR' system variable in IDL.
445 IDLWAVE uses this to find out which of the library routines belong to
446 the official system library. All files inside the `lib' subdirectory
447 are considered system library files - so don't install private stuff
448 in this directory. On UNIX systems, IDLWAVE queries the shell for the
449 value of `!DIR'. See also `idlwave-library-path'."
450 :group
'idlwave-routine-info
453 ;; Configuration files
454 (defcustom idlwave-config-directory
455 (convert-standard-filename "~/.idlwave")
456 "*Directory for configuration files and user-library catalog."
457 :group
'idlwave-routine-info
460 (defvar idlwave-user-catalog-file
"idlusercat.el")
461 (defvar idlwave-xml-system-rinfo-converted-file
"idl_xml_rinfo.el")
462 (defvar idlwave-path-file
"idlpath.el")
464 (defvar idlwave-libinfo-file nil
465 "*Obsolete variable, no longer used.")
467 (defcustom idlwave-special-lib-alist nil
468 "Alist of regular expressions matching special library directories.
469 When listing routine source locations, IDLWAVE gives a short hint where
470 the file defining the routine is located. By default it lists `SystemLib'
471 for routines in the system library `!DIR/lib' and `Library' for anything
472 else. This variable can define additional types. The car of each entry
473 is a regular expression matching the file name (they normally will match
474 on the path). The cdr is the string to be used as identifier. Max 10
476 :group
'idlwave-routine-info
478 (cons regexp string
)))
480 (defcustom idlwave-auto-write-paths t
481 "Write out path (!PATH) and system directory (!DIR) info automatically.
482 Path info is needed to locate library catalog files. If non-nil,
483 whenever the path-list changes as a result of shell-query, etc., it is
484 written to file. Otherwise, the menu option \"Write Paths\" can be
485 used to force a write."
486 :group
'idlwave-routine-info
489 (defgroup idlwave-completion nil
490 "Completion options for IDLWAVE mode."
495 (defconst idlwave-tmp
496 '(choice :tag
"by applying the function"
501 (symbol :tag
"Other"))))
503 (defcustom idlwave-completion-case
'((routine . upcase
)
507 "Association list setting the case of completed words.
509 This variable determines the case (UPPER/lower/Capitalized...) of
510 words inserted into the buffer by completion. The preferred case can
511 be specified separately for routine names, keywords, classes and
513 This alist should therefore have entries for `routine' (normal
514 functions and procedures, i.e. non-methods), `keyword', `class', and
515 `method'. Plausible values are
517 upcase upcase whole word, like `BOX_CURSOR'
518 downcase downcase whole word, like `read_ppm'
519 capitalize capitalize each part, like `Widget_Control'
520 preserve preserve case as is, like `IDLgrView'
522 The value can also be any Emacs Lisp function which transforms the
523 case of characters in a string.
525 A value of `preserve' means that the case of the completed word is
526 identical to the way it was written in the definition statement of the
527 routine. This was implemented to allow for mixed-case completion, in
528 particular of object classes and methods.
529 If a completable word is defined in multiple locations, the meaning of
530 `preserve' is not unique since the different definitions might be
531 cased differently. Therefore IDLWAVE always takes the case of the
532 *first* definition it encounters during routine info collection and
533 uses the case derived from it consistently.
535 Note that a lowercase-only string in the buffer will always be completed in
536 lower case (but see the variable `idlwave-completion-force-default-case').
538 After changing this variable, you need to either restart Emacs or press
539 `C-u C-c C-i' to update the internal lists."
540 :group
'idlwave-completion
542 (cons (symbol :tag
"Derive completion case for")
545 (defcustom idlwave-completion-force-default-case nil
546 "*Non-nil means, completion will always honor `idlwave-completion-case'.
547 When nil, only the completion of a mixed case or upper case string
548 will honor the default settings in `idlwave-completion-case', while
549 the completion of lower case strings will be completed entirely in
551 :group
'idlwave-completion
554 (defcustom idlwave-complete-empty-string-as-lower-case nil
555 "*Non-nil means, the empty string is considered downcase for completion.
556 The case of what is already in the buffer determines the case of completions.
557 When this variable is non-nil, the empty string is considered to be downcase.
558 Completing on the empty string then offers downcase versions of the possible
560 :group
'idlwave-completion
563 (defvar idlwave-default-completion-case-is-down nil
564 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
565 `idlwave-completion-case'.")
567 (defcustom idlwave-buffer-case-takes-precedence nil
568 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
569 To make this possible, we need to re-case everything each time we update
570 the routine info from the buffers. This is slow.
571 The default is to consider the case given in the system and library files
572 first which makes updating much faster."
573 :group
'idlwave-completion
576 (defcustom idlwave-highlight-help-links-in-completion t
577 "*Non-nil means, highlight completions for which system help is available.
578 Help can then be accessed with mouse-3.
579 This option is only effective when the online help system is installed."
580 :group
'idlwave-completion
583 (defcustom idlwave-support-inheritance t
584 "Non-nil means, treat inheritance with completion, online help etc.
585 When nil, IDLWAVE only knows about the native methods and tags of a class,
586 not about inherited ones."
587 :group
'idlwave-routine-info
590 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
591 "List of regular expressions for class-driven keyword inheritance.
592 Keyword inheritance is often tied to class inheritance by \"chaining\"
593 up the class tree. While it cannot be assumed that the presence of an
594 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
595 certain methods this assumption is almost always true. The methods
596 for which to assume this can be set here."
597 :group
'idlwave-routine-info
598 :type
'(repeat (regexp :tag
"Match method:")))
601 (defcustom idlwave-completion-show-classes
1
602 "*Number of classes to show when completing object methods and keywords.
603 When completing methods or keywords for an object with unknown class,
604 the *Completions* buffer will show the valid classes for each completion
607 MyMethod <Class1,Class2,Class3>
609 The value of this variable may be nil to inhibit display, or an integer to
610 indicate the maximum number of classes to display.
612 On XEmacs, a full list of classes will also be placed into a `help-echo'
613 property on the competion items, so that the list of classes for the current
614 item is displayed in the echo area. If the value of this variable is a
615 negative integer, the `help-echo' property will be suppressed."
616 :group
'idlwave-completion
617 :type
'(choice (const :tag
"Don't show" nil
)
618 (integer :tag
"Number of classes shown" 1)))
620 (defcustom idlwave-completion-fontify-classes t
621 "*Non-nil means, fontify the classes in completions buffer.
622 This makes it easier to distinguish the completion items from the extra
623 class info listed. See `idlwave-completion-show-classes'."
624 :group
'idlwave-completion
627 (defcustom idlwave-query-class
'((method-default . nil
)
628 (keyword-default . nil
))
629 "Association list governing specification of object classes for completion.
631 When IDLWAVE tries to complete object-oriented methods, it usually
632 cannot determine the class of a given object from context. In order
633 to provide the user with a correct list of methods or keywords, it
634 needs to determine the appropriate class. IDLWAVE has two ways of
635 doing this (well, three ways if you count the shell... see
636 `idlwave-shell-query-for-class'):
638 1. Combine the items of all available classes which contain this
639 method for the purpose of completion. So when completing a method,
640 all methods of all known classes are available, and when completing
641 a keyword, all keywords allowed for this method in any class are
642 shown. This behavior is very much like normal completion and is
643 therefore the default. It works much better than one might think -
644 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
645 become uncomfortably long. See also
646 `idlwave-completion-show-classes'.
648 2. The second possibility is to ask the user on each occasion. To
649 make this less interruptive, IDLWAVE can store the class as a text
650 property on the object operator `->'. For a given object in the
651 source code, class selection will then be needed only once
652 - for example to complete the method. Keywords to the method can
653 then be completed directly, because the class is already known.
654 You will have to turn on the storage of the selected class
655 explicitly with the variable `idlwave-store-inquired-class'.
657 This variable allows you to configure IDLWAVE's method and
658 method-keyword completion behavior. Its value is an alist, which
659 should contain at least two elements: (method-default . VALUE) and
660 \(keyword-default . VALUE), where VALUE is either t or nil. These
661 specify if the class should be found during method and keyword
662 completion, respectively.
664 The alist may have additional entries specifying exceptions from the
665 keyword completion rule for specific methods, like INIT or
666 GETPROPERTY. In order to turn on class specification for the INIT
667 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
668 :group
'idlwave-completion
670 (cons (const method-default
)
671 (boolean :tag
"Determine class when completing METHODS "))
672 (cons (const keyword-default
)
673 (boolean :tag
"Determine class when completing KEYWORDS "))
675 :tag
"Exceptions to defaults"
677 (cons (string :tag
"MODULE" :value
"")
678 (boolean :tag
"Determine class for this method")))))
680 (defcustom idlwave-store-inquired-class t
681 "*Non-nil means, store class of a method call as text property on `->'.
682 IDLWAVE sometimes has to ask the user for the class associated with a
683 particular object method call. This happens during the commands
684 `idlwave-routine-info' and `idlwave-complete', depending upon the
685 value of the variable `idlwave-query-class'.
687 When you specify a class, this information can be stored as a text
688 property on the `->' arrow in the source code, so that during the same
689 editing session, IDLWAVE will not have to ask again. When this
690 variable is non-nil, IDLWAVE will store and reuse the class information.
691 The class stored can be checked and removed with `\\[idlwave-routine-info]'
694 The default of this variable is nil, since the result of commands then
695 is more predictable. However, if you know what you are doing, it can
696 be nice to turn this on.
698 An arrow which knows the class will be highlighted with
699 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
700 displays (with prefix arg: deletes) the class stored on the arrow
702 :group
'idlwave-completion
705 (defcustom idlwave-class-arrow-face
'bold
706 "*Face to highlight object operator arrows `->' which carry a class property.
707 When IDLWAVE stores a class name as text property on an object arrow
708 \(see variable `idlwave-store-inquired-class', it highlights the arrow
709 with this font in order to remind the user that this arrow is special."
710 :group
'idlwave-completion
713 (defcustom idlwave-resize-routine-help-window t
714 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
715 :group
'idlwave-completion
718 (defcustom idlwave-keyword-completion-adds-equal t
719 "*Non-nil means, completion automatically adds `=' after completed keywords."
720 :group
'idlwave-completion
723 (defcustom idlwave-function-completion-adds-paren t
724 "*Non-nil means, completion automatically adds `(' after completed function.
725 nil means, don't add anything.
726 A value of `2' means, also add the closing parenthesis and position cursor
728 :group
'idlwave-completion
729 :type
'(choice (const :tag
"Nothing" nil
)
731 (const :tag
"()" 2)))
733 (defcustom idlwave-completion-restore-window-configuration t
734 "*Non-nil means, try to restore the window configuration after completion.
735 When completion is not unique, Emacs displays a list of completions.
736 This messes up your window configuration. With this variable set, IDLWAVE
737 restores the old configuration after successful completion."
738 :group
'idlwave-completion
741 ;;; Variables for abbrev and action behavior -----------------------------
743 (defgroup idlwave-abbrev-and-indent-action nil
744 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
745 The variables in this group govern this."
748 (defcustom idlwave-do-actions nil
749 "*Non-nil means performs actions when indenting.
750 The actions that can be performed are listed in `idlwave-indent-action-table'."
751 :group
'idlwave-abbrev-and-indent-action
754 (defcustom idlwave-abbrev-start-char
"\\"
755 "*A single character string used to start abbreviations in abbrev mode.
756 Possible characters to chose from: ~`\%
757 or even '?'. '.' is not a good choice because it can make structure
758 field names act like abbrevs in certain circumstances.
760 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
761 must set it directly using `setq' in the .emacs file before idlwave.el
763 :group
'idlwave-abbrev-and-indent-action
766 (defcustom idlwave-surround-by-blank nil
767 "*Non-nil means, enable `idlwave-surround'.
768 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
770 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
772 Also see the default key bindings for keys using `idlwave-surround'.
773 Keys are bound and made into actions calling `idlwave-surround' with
774 `idlwave-action-and-binding'.
775 See help for `idlwave-action-and-binding' for examples.
777 Also see help for `idlwave-surround'."
778 :group
'idlwave-abbrev-and-indent-action
781 (defcustom idlwave-pad-keyword t
782 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
783 Whenever `idlwave-surround' is non-nil then this affects how '=' is
784 padded for keywords and for variables. If t, pad the same as for
785 assignments. If nil then spaces are removed. With any other value,
786 spaces are left unchanged."
787 :group
'idlwave-abbrev-and-indent-action
789 (const :tag
"Pad like assignments" t
)
790 (const :tag
"Remove space near `='" nil
)
791 (const :tag
"Keep space near `='" 'keep
)))
793 (defcustom idlwave-show-block t
794 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
795 :group
'idlwave-abbrev-and-indent-action
798 (defcustom idlwave-expand-generic-end nil
799 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
800 :group
'idlwave-abbrev-and-indent-action
803 (defcustom idlwave-reindent-end t
804 "*Non-nil means re-indent line after END was typed."
805 :group
'idlwave-abbrev-and-indent-action
808 (defcustom idlwave-abbrev-move t
809 "*Non-nil means the abbrev hook can move point.
810 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
811 definitions, use the command `list-abbrevs', for abbrevs that move
812 point. Moving point is useful, for example, to place point between
813 parentheses of expanded functions.
815 See `idlwave-check-abbrev'."
816 :group
'idlwave-abbrev-and-indent-action
819 (defcustom idlwave-abbrev-change-case nil
820 "*Non-nil means all abbrevs will be forced to either upper or lower case.
821 If the value t, all expanded abbrevs will be upper case.
822 If the value is 'down then abbrevs will be forced to lower case.
823 If nil, the case will not change.
824 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
825 upper case, regardless of this variable."
826 :group
'idlwave-abbrev-and-indent-action
829 (defcustom idlwave-reserved-word-upcase nil
830 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
831 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
832 Has effect only if in abbrev-mode."
833 :group
'idlwave-abbrev-and-indent-action
836 ;;; Action/Expand Tables.
838 ;; The average user may have difficulty modifying this directly. It
839 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
840 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
841 ;; examples of how to add an action.
843 ;; The action table is used by `idlwave-indent-line' whereas both the
844 ;; action and expand tables are used by `idlwave-indent-and-action'. In
845 ;; general, the expand table is only used when a line is explicitly
846 ;; indented. Whereas, in addition to being used when the expand table
847 ;; is used, the action table is used when a line is indirectly
848 ;; indented via line splitting, auto-filling or a new line creation.
852 ;; Capitalize system vars
853 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
855 ;; Capitalize procedure name
856 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
857 ;; '(capitalize-word 1) t)
859 ;; Capitalize common block name
860 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
861 ;; '(capitalize-word 1) t)
863 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
864 ;; '(capitalize-word -1) t)
866 (defvar idlwave-indent-action-table nil
867 "*Associated array containing action lists of search string (car),
868 and function as a cdr. This table is used by `idlwave-indent-line'.
869 See documentation for `idlwave-do-action' for a complete description of
872 Additions to the table are made with `idlwave-action-and-binding' when a
873 binding is not requested.
874 See help on `idlwave-action-and-binding' for examples.")
876 (defvar idlwave-indent-expand-table nil
877 "*Associated array containing action lists of search string (car),
878 and function as a cdr. The table is used by the
879 `idlwave-indent-and-action' function. See documentation for
880 `idlwave-do-action' for a complete description of the action lists.
882 Additions to the table are made with `idlwave-action-and-binding' when a
883 binding is requested.
884 See help on `idlwave-action-and-binding' for examples.")
886 ;;; Documentation header and history keyword ---------------------------------
888 (defgroup idlwave-documentation nil
889 "Options for documenting IDLWAVE files."
892 ;; FIXME: make defcustom?
893 (defvar idlwave-file-header
920 ; KEYWORD PARAMETERS:
952 ; MODIFICATION HISTORY:
956 "*A list (PATHNAME STRING) specifying the doc-header template to use for
957 summarizing a file. If PATHNAME is non-nil then this file will be included.
958 Otherwise STRING is used. If nil, the file summary will be omitted.
959 For example you might set PATHNAME to the path for the
960 lib_template.pro file included in the IDL distribution.")
962 (defcustom idlwave-header-to-beginning-of-file t
963 "*Non-nil means, the documentation header will always be at start of file.
964 When nil, the header is positioned between the PRO/FUNCTION line of
965 the current routine and the code, allowing several routine headers in
967 :group
'idlwave-documentation
970 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
971 "*The hook function used to update the timestamp of a function."
972 :group
'idlwave-documentation
975 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
976 "*The modifications keyword to use with the log documentation commands.
977 A ':' is added to the keyword end.
978 Inserted by doc-header and used to position logs by doc-modification.
979 If nil it will not be inserted."
980 :group
'idlwave-documentation
983 (defcustom idlwave-doclib-start
"^;+\\+"
984 "*Regexp matching the start of a document library header."
985 :group
'idlwave-documentation
988 (defcustom idlwave-doclib-end
"^;+-"
989 "*Regexp matching the end of a document library header."
990 :group
'idlwave-documentation
993 ;;; External Programs -------------------------------------------------------
995 (defgroup idlwave-external-programs nil
996 "Path locations of external commands used by IDLWAVE."
999 (defcustom idlwave-shell-explicit-file-name
"idl"
1000 "*If non-nil, this is the command to run IDL.
1001 Should be an absolute file path or path relative to the current environment
1002 execution search path. If you want to specify command line switches
1003 for the idl program, use `idlwave-shell-command-line-options'.
1005 I know the name of this variable is badly chosen, but I cannot change
1006 it without compromizing backwards-compatibility."
1007 :group
'idlwave-external-programs
1010 (defcustom idlwave-shell-command-line-options nil
1011 "*A list of command line options for calling the IDL program.
1012 Since IDL is executed directly without going through a shell like /bin/sh,
1013 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1014 string for each argument. But you may also give a single string which
1015 contains the options whitespace-separated. Emacs will be kind enough to
1019 (repeat (string :value
"")))
1020 :group
'idlwave-external-programs
)
1022 (defcustom idlwave-help-application
"idlhelp"
1023 "*The external application providing reference help for programming.
1024 Obsolete, if the IDL Assistant is being used for help."
1025 :group
'idlwave-external-programs
1028 ;;; Some Shell variables which must be defined here.-----------------------
1030 (defcustom idlwave-shell-debug-modifiers
'()
1031 "List of modifiers to be used for the debugging commands.
1032 Will be used to bind debugging commands in the shell buffer and in all
1033 source buffers. These are additional convenience bindings, the debugging
1034 commands are always available with the `C-c C-d' prefix.
1035 If you set this to '(control shift), this means setting a breakpoint will
1036 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1037 are `control', `meta', `super', `hyper', `alt', and `shift'."
1038 :group
'idlwave-shell-general-setup
1039 :type
'(set :tag
"Specify modifiers"
1047 (defcustom idlwave-shell-automatic-start nil
1048 "*If non-nil attempt invoke idlwave-shell if not already running.
1049 This is checked when an attempt to send a command to an
1050 IDL process is made."
1051 :group
'idlwave-shell-general-setup
1054 ;;; Miscellaneous variables -------------------------------------------------
1056 (defgroup idlwave-misc nil
1057 "Miscellaneous options for IDLWAVE mode."
1058 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
1061 (defcustom idlwave-startup-message t
1062 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1063 :group
'idlwave-misc
1066 (defcustom idlwave-default-font-lock-items
1067 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1068 common-blocks class-arrows
)
1069 "Items which should be fontified on the default fontification level 2.
1070 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1071 is everything and level 2 is specified by this list.
1072 This variable must be set before IDLWAVE gets loaded. It is
1073 a list of symbols, the following symbols are allowed.
1075 pros-and-functions Procedure and Function definitions
1076 batch-files Batch Files
1077 idlwave-idl-keywords IDL Keywords
1078 label Statement Labels
1079 goto Goto Statements
1080 common-blocks Common Blocks
1081 keyword-parameters Keyword Parameters in routine definitions and calls
1082 system-variables System Variables
1083 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1084 class-arrows Object Arrows with class property"
1085 :group
'idlwave-misc
1088 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1089 (const :tag
"Batch Files" batch-files
)
1090 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1091 (const :tag
"Statement Labels" label
)
1092 (const :tag
"Goto Statements" goto
)
1093 (const :tag
"Tags in Structure Definition" structtag
)
1094 (const :tag
"Structure Name" structname
)
1095 (const :tag
"Common Blocks" common-blocks
)
1096 (const :tag
"Keyword Parameters" keyword-parameters
)
1097 (const :tag
"System Variables" system-variables
)
1098 (const :tag
"FIXME: Warning" fixme
)
1099 (const :tag
"Object Arrows with class property " class-arrows
)))
1101 (defcustom idlwave-mode-hook nil
1102 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1103 :group
'idlwave-misc
1106 (defcustom idlwave-load-hook nil
1107 "Normal hook. Executed when idlwave.el is loaded."
1108 :group
'idlwave-misc
1111 (defvar idlwave-experimental nil
1112 "Non-nil means turn on a few experimental features.
1113 This variable is only for the maintainer, to test difficult stuff,
1114 while still distributing stable releases.
1115 As a user, you should not set this to t.")
1118 ;;; End customization variables section
1121 ;;; Non customization variables
1123 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1124 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1125 ;;; and Carsten Dominik...
1127 ;; The following are the reserved words in IDL. Maybe we should
1128 ;; highlight some more stuff as well?
1129 ;; Procedure declarations. Fontify keyword plus procedure name.
1130 (defvar idlwave-idl-keywords
1131 ;; To update this regexp, update the list of keywords and
1132 ;; evaluate the form.
1138 ;; '("||" "&&" "and" "or" "xor" "not"
1139 ;; "eq" "ge" "gt" "le" "lt" "ne"
1140 ;; "for" "do" "endfor"
1141 ;; "if" "then" "endif" "else" "endelse"
1142 ;; "case" "of" "endcase"
1143 ;; "switch" "break" "continue" "endswitch"
1145 ;; "repeat" "until" "endrep"
1146 ;; "while" "endwhile"
1149 ;; "compile_opt" "forward_function"
1150 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1152 "\\<\\(&&\\|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\\|||\\)\\>")
1155 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1156 ;; Function declarations. Fontify keyword plus function name.
1158 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1159 (1 font-lock-keyword-face
)
1160 (2 font-lock-function-name-face nil t
)))
1164 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1165 (1 font-lock-keyword-face
) ; "common"
1166 (2 font-lock-reference-face nil t
) ; block name
1167 ("[ \t]*\\(\\sw+\\)[ ,]*"
1168 ;; Start with point after block name and comma
1169 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1171 (1 font-lock-variable-name-face
) ; variable names
1176 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1180 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1184 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1186 ;; The goto statement and its label
1188 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1189 (1 font-lock-keyword-face
)
1190 (2 font-lock-reference-face
)))
1192 ;; Tags in structure definitions. Note that this definition
1193 ;; actually collides with labels, so we have to use the same
1194 ;; face. It also matches named subscript ranges,
1195 ;; e.g. vec{bottom:top]. No good way around this.
1197 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1201 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1202 (2 font-lock-function-name-face
)))
1204 ;; Keyword parameters, like /xlog or ,xrange=[]
1205 ;; This is anchored to the comma preceeding the keyword.
1206 ;; Treats continuation lines, works only during whole buffer
1207 ;; fontification. Slow, use it only in fancy fontification.
1209 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1210 (6 font-lock-reference-face
)))
1212 ;; System variables start with a bang.
1214 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1215 (1 font-lock-variable-name-face
)))
1217 ;; Special and unusual operators (not used because too noisy)
1219 '("[<>#]" (0 font-lock-keyword-face
)))
1221 ;; All operators (not used because too noisy)
1223 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1225 ;; Arrows with text property `idlwave-class'
1227 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1229 (defconst idlwave-font-lock-keywords-1
1230 (list pros-and-functions batch-files
)
1231 "Subdued level highlighting for IDLWAVE mode.")
1233 (defconst idlwave-font-lock-keywords-2
1234 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1235 "Medium level highlighting for IDLWAVE mode.")
1237 (defconst idlwave-font-lock-keywords-3
1238 (list pros-and-functions
1240 idlwave-idl-keywords
1248 "Gaudy level highlighting for IDLWAVE mode."))
1250 (defun idlwave-match-class-arrows (limit)
1251 ;; Match an object arrow with class property
1252 (and idlwave-store-inquired-class
1253 (re-search-forward "->" limit
'limit
)
1254 (get-text-property (match-beginning 0) 'idlwave-class
)))
1256 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1257 "Default expressions to highlight in IDLWAVE mode.")
1259 (defvar idlwave-font-lock-defaults
1260 '((idlwave-font-lock-keywords
1261 idlwave-font-lock-keywords-1
1262 idlwave-font-lock-keywords-2
1263 idlwave-font-lock-keywords-3
)
1265 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1268 (put 'idlwave-mode
'font-lock-defaults
1269 idlwave-font-lock-defaults
) ; XEmacs
1271 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1272 "Regexp to match the start of a full-line comment.
1273 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1274 only by whitespace.")
1276 (defconst idlwave-begin-block-reg
1277 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1278 "Regular expression to find the beginning of a block. The case does
1279 not matter. The search skips matches in comments.")
1281 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1282 "Regular expression to find the beginning of a unit. The case does
1285 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1286 "Regular expression to find the line that indicates the end of unit.
1287 This line is the end of buffer or the start of another unit. The case does
1288 not matter. The search skips matches in comments.")
1290 (defconst idlwave-continue-line-reg
"\\<\\$"
1291 "Regular expression to match a continued line.")
1293 (defconst idlwave-end-block-reg
1294 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1295 "Regular expression to find the end of a block. The case does
1296 not matter. The search skips matches found in comments.")
1298 (defconst idlwave-block-matches
1300 ("function" .
"end")
1301 ("case" .
"endcase")
1302 ("else" .
"endelse")
1305 ("repeat" .
"endrep")
1306 ("switch" .
"endswitch")
1307 ("while" .
"endwhile"))
1308 "Matches between statements and the corresponding END variant.
1309 The cars are the reserved words starting a block. If the block really
1310 begins with BEGIN, the cars are the reserved words before the begin
1311 which can be used to identify the block type.
1312 This is used to check for the correct END type, to close blocks and
1313 to expand generic end statements to their detailed form.")
1315 (defconst idlwave-block-match-regexp
1316 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1317 "Regular expression matching reserved words which can stand before
1318 blocks starting with a BEGIN statement. The matches must have associations
1319 `idlwave-block-matches'")
1321 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1322 "Regular expression matching an IDL identifier.")
1324 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1325 "Regular expression matching IDL system variables.")
1327 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1328 "Regular expression matching IDL variable names.")
1330 (defconst idlwave-label
(concat idlwave-identifier
":")
1331 "Regular expression matching IDL labels.")
1333 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1334 "\\(\\s *" idlwave-identifier
"::\\)?"
1337 (defconst idlwave-statement-match
1339 ;; "endif else" is the only possible "end" that can be
1340 ;; followed by a statement on the same line.
1341 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1342 ;; all other "end"s can not be followed by a statement.
1343 (cons 'end
(list idlwave-end-block-reg nil
))
1344 '(if .
("if\\>" "then"))
1345 '(for .
("for\\>" "do"))
1346 '(begin .
("begin\\>" nil
))
1347 '(pdef .
("pro\\>\\|function\\>" nil
))
1348 '(while .
("while\\>" "do"))
1349 '(repeat .
("repeat\\>" "repeat"))
1350 '(goto .
("goto\\>" nil
))
1351 '(case .
("case\\>" nil
))
1352 '(switch .
("switch\\>" nil
))
1353 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1354 "\\(" idlwave-method-call
"\\s *\\)?"
1357 (cons 'call
(list (concat
1358 "\\(" idlwave-method-call
"\\s *\\)?"
1360 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1361 (cons 'assign
(list (concat
1362 "\\(" idlwave-variable
"\\) *=") nil
)))
1364 "Associated list of statement matching regular expressions.
1365 Each regular expression matches the start of an IDL statement. The
1366 first element of each association is a symbol giving the statement
1367 type. The associated value is a list. The first element of this list
1368 is a regular expression matching the start of an IDL statement for
1369 identifying the statement type. The second element of this list is a
1370 regular expression for finding a substatement for the type. The
1371 substatement starts after the end of the found match modulo
1372 whitespace. If it is nil then the statement has no substatement. The
1373 list order matters since matching an assignment statement exactly is
1374 not possible without parsing. Thus assignment statement become just
1375 the leftover unidentified statements containing an equal sign." )
1377 (defvar idlwave-fill-function
'auto-fill-function
1378 "IDL mode auto fill function.")
1380 (defvar idlwave-comment-indent-function
'comment-indent-function
1381 "IDL mode comment indent function.")
1383 ;; Note that this is documented in the v18 manuals as being a string
1384 ;; of length one rather than a single character.
1385 ;; The code in this file accepts either format for compatibility.
1386 (defvar idlwave-comment-indent-char ?\
1387 "Character to be inserted for IDL comment indentation.
1390 (defconst idlwave-continuation-char ?$
1391 "Character which is inserted as a last character on previous line by
1392 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1394 (defconst idlwave-mode-version
"6.1_em22")
1396 (defmacro idlwave-keyword-abbrev
(&rest args
)
1397 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1399 ,(append '(idlwave-check-abbrev) args
))))
1401 ;; If I take the time I can replace idlwave-keyword-abbrev with
1402 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1403 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1404 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1405 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1407 (defmacro idlwave-code-abbrev
(&rest args
)
1408 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1409 Specifically, if the abbrev is in a comment or string it is unexpanded.
1410 Otherwise ARGS forms a list that is evaluated."
1412 ,(prin1-to-string args
) ;; Puts the code in the doc string
1413 (if (idlwave-quoted)
1414 (progn (unexpand-abbrev) nil
)
1417 (defvar idlwave-mode-map
(make-sparse-keymap)
1418 "Keymap used in IDL mode.")
1420 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1421 "Syntax table in use in `idlwave-mode' buffers.")
1423 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
1424 (modify-syntax-entry ?-
"." idlwave-mode-syntax-table
)
1425 (modify-syntax-entry ?
* "." idlwave-mode-syntax-table
)
1426 (modify-syntax-entry ?
/ "." idlwave-mode-syntax-table
)
1427 (modify-syntax-entry ?^
"." idlwave-mode-syntax-table
)
1428 (modify-syntax-entry ?
# "." idlwave-mode-syntax-table
)
1429 (modify-syntax-entry ?
= "." idlwave-mode-syntax-table
)
1430 (modify-syntax-entry ?%
"." idlwave-mode-syntax-table
)
1431 (modify-syntax-entry ?
< "." idlwave-mode-syntax-table
)
1432 (modify-syntax-entry ?
> "." idlwave-mode-syntax-table
)
1433 (modify-syntax-entry ?
\' "\"" idlwave-mode-syntax-table
)
1434 (modify-syntax-entry ?
\" "\"" idlwave-mode-syntax-table
)
1435 (modify-syntax-entry ?
\\ "." idlwave-mode-syntax-table
)
1436 (modify-syntax-entry ?_
"_" idlwave-mode-syntax-table
)
1437 (modify-syntax-entry ?
{ "(}" idlwave-mode-syntax-table
)
1438 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1439 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1440 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1441 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1442 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1443 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1445 (defvar idlwave-find-symbol-syntax-table
1446 (copy-syntax-table idlwave-mode-syntax-table
)
1447 "Syntax table that treats symbol characters as word characters.")
1449 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1450 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1451 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1452 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1454 (defmacro idlwave-with-special-syntax
(&rest body
)
1455 "Execute BODY with a different syntax table."
1456 `(let ((saved-syntax (syntax-table)))
1459 (set-syntax-table idlwave-find-symbol-syntax-table
)
1461 (set-syntax-table saved-syntax
))))
1463 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1464 ; "Execute BODY with a different syntax table."
1465 ; `(let ((saved-syntax (syntax-table)))
1468 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1470 ; (set-syntax-table saved-syntax))))
1472 (defun idlwave-action-and-binding (key cmd
&optional select
)
1473 "KEY and CMD are made into a key binding and an indent action.
1474 KEY is a string - same as for the `define-key' function. CMD is a
1475 function of no arguments or a list to be evaluated. CMD is bound to
1476 KEY in `idlwave-mode-map' by defining an anonymous function calling
1477 `self-insert-command' followed by CMD. If KEY contains more than one
1478 character a binding will only be set if SELECT is 'both.
1480 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1481 replacing any previous value for KEY. If a binding is not set then it
1482 will instead be placed in `idlwave-indent-action-table'.
1484 If the optional argument SELECT is nil then an action and binding are
1485 created. If SELECT is 'noaction, then a binding is always set and no
1486 action is created. If SELECT is 'both then an action and binding
1487 will both be created even if KEY contains more than one character.
1488 Otherwise, if SELECT is non-nil then only an action is created.
1491 No spaces before and 1 after a comma
1492 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1493 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1494 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1495 Capitalize system variables - action only
1496 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1497 (if (not (equal select
'noaction
))
1499 (let* ((table (if select
'idlwave-indent-action-table
1500 'idlwave-indent-expand-table
))
1501 (table-key (regexp-quote key
))
1502 (cell (assoc table-key
(eval table
))))
1504 ;; Replace action command
1507 (set table
(append (eval table
) (list (cons table-key cmd
)))))))
1508 ;; Make key binding for action
1509 (if (or (and (null select
) (= (length key
) 1))
1510 (equal select
'noaction
)
1511 (equal select
'both
))
1512 (define-key idlwave-mode-map key
1515 (self-insert-command 1))
1516 (list (if (listp cmd
)
1520 (fset 'idlwave-debug-map
(make-sparse-keymap))
1522 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1523 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1524 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1525 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1526 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1527 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1528 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1529 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1530 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1531 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1532 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1533 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1534 (define-key idlwave-mode-map
[(meta control h
)] 'idlwave-mark-subprogram
)
1535 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1536 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1537 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1538 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1539 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1540 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1541 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1542 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1543 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1544 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1545 (define-key idlwave-mode-map
[(shift iso-lefttab
)] 'idlwave-indent-statement
)
1546 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1547 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1548 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1549 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1550 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1551 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1552 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1553 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1554 (listp idlwave-shell-debug-modifiers
)
1555 (not (equal idlwave-shell-debug-modifiers
'())))
1556 ;; Bind the debug commands also with the special modifiers.
1557 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1558 (mods-noshift (delq 'shift
1559 (copy-sequence idlwave-shell-debug-modifiers
))))
1560 (define-key idlwave-mode-map
1561 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1562 'idlwave-shell-save-and-run
)
1563 (define-key idlwave-mode-map
1564 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1565 'idlwave-shell-break-here
)
1566 (define-key idlwave-mode-map
1567 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1568 'idlwave-shell-run-region
)))
1569 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1570 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1571 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1572 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1573 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1574 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1575 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1576 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1577 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1578 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1579 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1580 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1581 (autoload 'idlwave-shell
"idlw-shell"
1582 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1583 (autoload 'idlwave-shell-send-command
"idlw-shell")
1584 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1585 "Run `idlwave-shell' and switch back to current window" t
)
1586 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1587 "Save and run buffer under the shell." t
)
1588 (autoload 'idlwave-shell-break-here
"idlw-shell"
1589 "Set breakpoint in current line." t
)
1590 (autoload 'idlwave-shell-run-region
"idlw-shell"
1591 "Compile and run the region." t
)
1592 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1593 (define-key idlwave-mode-map
"\C-c\C-t" 'idlwave-find-module-this-file
)
1594 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1595 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1596 (define-key idlwave-mode-map
[(control meta ?
\?)]
1597 'idlwave-help-assistant-help-with-topic
)
1598 ;; Pickup both forms of Esc/Meta binding
1599 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1600 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1601 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1602 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1603 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1604 (define-key idlwave-mode-map
1605 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1606 'idlwave-mouse-context-help
)
1608 ;; Set action and key bindings.
1609 ;; See description of the function `idlwave-action-and-binding'.
1610 ;; Automatically add spaces for the following characters
1612 ;; Actions for & are complicated by &&
1613 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround
)
1615 ;; Automatically add spaces to equal sign if not keyword. This needs
1616 ;; to go ahead of > and <, so >= and <= will be treated correctly
1617 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1619 ;; Actions for > and < are complicated by >=, <=, and ->...
1620 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil
))
1621 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr
))
1623 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1 1))
1629 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1630 ;;; space is inserted (this is the space typed by the user to expanded
1633 (defvar idlwave-mode-abbrev-table nil
1634 "Abbreviation table used for IDLWAVE mode")
1635 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1637 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1638 "Define-abbrev with backward compatibility.
1640 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1641 idlwave-mode-abbrev-table unless TABLE is non-nil."
1642 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1643 (args (list (or table idlwave-mode-abbrev-table
)
1644 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1648 (apply 'define-abbrev
(append args
'(0 t
)))
1649 (error (apply 'define-abbrev args
)))))
1652 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1653 "w" idlwave-mode-syntax-table
)
1659 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1660 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1661 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1662 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1663 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1664 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1665 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1666 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1667 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1669 ;; Keywords, system functions, conversion routines
1671 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1672 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1673 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1674 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1680 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1681 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1682 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1683 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1684 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1685 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1686 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1687 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1688 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1689 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1690 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1691 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1692 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1693 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1695 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1697 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1705 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1706 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1714 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1715 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1716 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1717 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1718 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1719 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1720 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1721 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1722 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1723 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1724 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1725 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1726 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1728 ;; This section is reserved words only. (From IDL user manual)
1730 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1735 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1736 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1737 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1738 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1739 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1740 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1741 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1742 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1743 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1744 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1745 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1746 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1747 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1748 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1749 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1750 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1751 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1752 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1753 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1754 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1755 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1756 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1757 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1758 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1759 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1760 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1761 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1762 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1763 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1764 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1765 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1766 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1767 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1768 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1770 (defvar imenu-create-index-function
)
1771 (defvar extract-index-name-function
)
1772 (defvar prev-index-position-function
)
1773 (defvar imenu-extract-index-name-function
)
1774 (defvar imenu-prev-index-position-function
)
1775 ;; defined later - so just make the compiler hush
1776 (defvar idlwave-mode-menu
)
1777 (defvar idlwave-mode-debug-menu
)
1780 (defun idlwave-mode ()
1781 "Major mode for editing IDL source files (version 6.1_em22).
1783 The main features of this mode are
1785 1. Indentation and Formatting
1786 --------------------------
1787 Like other Emacs programming modes, C-j inserts a newline and indents.
1788 TAB is used for explicit indentation of the current line.
1790 To start a continuation line, use \\[idlwave-split-line]. This
1791 function can also be used in the middle of a line to split the line
1792 at that point. When used inside a long constant string, the string
1793 is split at that point with the `+' concatenation operator.
1795 Comments are indented as follows:
1797 `;;;' Indentation remains unchanged.
1798 `;;' Indent like the surrounding code
1799 `;' Indent to a minimum column.
1801 The indentation of comments starting in column 0 is never changed.
1803 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1804 comment. The indentation of the second line of the paragraph
1805 relative to the first will be retained. Use
1806 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1807 comments. When the variable `idlwave-fill-comment-line-only' is
1808 nil, code can also be auto-filled and auto-indented.
1810 To convert pre-existing IDL code to your formatting style, mark the
1811 entire buffer with \\[mark-whole-buffer] and execute
1812 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1813 again followed by \\[indent-region] (`indent-region').
1817 IDLWAVE displays information about the calling sequence and the
1818 accepted keyword parameters of a procedure or function with
1819 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1820 source file of a module. These commands know about system
1821 routines, all routines in idlwave-mode buffers and (when the
1822 idlwave-shell is active) about all modules currently compiled under
1823 this shell. It also makes use of pre-compiled or custom-scanned
1824 user and library catalogs many popular libraries ship with by
1825 default. Use \\[idlwave-update-routine-info] to update this
1826 information, which is also used for completion (see item 4).
1831 \\[idlwave-context-help] displays the IDL documentation relevant
1832 for the system variable, keyword, or routines at point. A single
1833 key stroke gets you directly to the right place in the docs. See
1834 the manual to configure where and how the HTML help is displayed.
1838 \\[idlwave-complete] completes the names of procedures, functions
1839 class names, keyword parameters, system variables and tags, class
1840 tags, structure tags, filenames and much more. It is context
1841 sensitive and figures out what is expected at point. Lower case
1842 strings are completed in lower case, other strings in mixed or
1845 5. Code Templates and Abbreviations
1846 --------------------------------
1847 Many Abbreviations are predefined to expand to code fragments and templates.
1848 The abbreviations start generally with a `\\`. Some examples
1850 \\pr PROCEDURE template
1851 \\fu FUNCTION template
1852 \\c CASE statement template
1853 \\sw SWITCH statement template
1854 \\f FOR loop template
1855 \\r REPEAT Loop template
1856 \\w WHILE loop template
1857 \\i IF statement template
1858 \\elif IF-ELSE statement template
1861 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1862 have direct keybindings - see the list of keybindings below.
1864 \\[idlwave-doc-header] inserts a documentation header at the
1865 beginning of the current program unit (pro, function or main).
1866 Change log entries can be added to the current program unit with
1867 \\[idlwave-doc-modification].
1869 6. Automatic Case Conversion
1870 -------------------------
1871 The case of reserved words and some abbrevs is controlled by
1872 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1874 7. Automatic END completion
1875 ------------------------
1876 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1877 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1881 Loading idlwave.el runs `idlwave-load-hook'.
1882 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1884 9. Documentation and Customization
1885 -------------------------------
1886 Info documentation for this package is available. Use
1887 \\[idlwave-info] to display (complain to your sysadmin if that does
1888 not work). For Postscript, PDF, and HTML versions of the
1889 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1890 IDLWAVE has customize support - see the group `idlwave'.
1894 Here is a list of all keybindings of this mode.
1895 If some of the key bindings below show with ??, use \\[describe-key]
1896 followed by the key sequence to see what the key sequence does.
1898 \\{idlwave-mode-map}"
1901 (kill-all-local-variables)
1903 (if idlwave-startup-message
1904 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1905 (setq idlwave-startup-message nil
)
1907 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1908 (set-syntax-table idlwave-mode-syntax-table
)
1910 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1912 (make-local-variable idlwave-comment-indent-function
)
1913 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1915 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1916 (set (make-local-variable 'comment-start
) ";")
1917 (set (make-local-variable 'comment-add
) 1) ; ";;" for new and regions
1918 (set (make-local-variable 'require-final-newline
) t
)
1919 (set (make-local-variable 'abbrev-all-caps
) t
)
1920 (set (make-local-variable 'indent-tabs-mode
) nil
)
1921 (set (make-local-variable 'completion-ignore-case
) t
)
1923 (use-local-map idlwave-mode-map
)
1925 (when (featurep 'easymenu
)
1926 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1927 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1929 (setq mode-name
"IDLWAVE")
1930 (setq major-mode
'idlwave-mode
)
1931 (setq abbrev-mode t
)
1933 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1934 (setq comment-end
"")
1935 (set (make-local-variable 'comment-multi-line
) nil
)
1936 (set (make-local-variable 'paragraph-separate
)
1937 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1938 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1939 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1940 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1943 (set (make-local-variable 'add-log-current-defun-function
)
1944 'idlwave-current-routine-fullname
)
1946 ;; Set tag table list to use IDLTAGS as file name.
1947 (if (boundp 'tag-table-alist
)
1948 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1950 ;; Font-lock additions
1951 ;; Following line is for Emacs - XEmacs uses the corresponding property
1952 ;; on the `idlwave-mode' symbol.
1953 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1954 (set (make-local-variable 'font-lock-mark-block-function
)
1955 'idlwave-mark-subprogram
)
1956 (set (make-local-variable 'font-lock-fontify-region-function
)
1957 'idlwave-font-lock-fontify-region
)
1960 (set (make-local-variable 'imenu-create-index-function
)
1961 'imenu-default-create-index-function
)
1962 (set (make-local-variable 'imenu-extract-index-name-function
)
1964 (set (make-local-variable 'imenu-prev-index-position-function
)
1965 'idlwave-prev-index-position
)
1968 (add-to-list 'hs-special-modes-alist
1970 idlwave-begin-block-reg
1971 idlwave-end-block-reg
1973 'idlwave-forward-block nil
))
1975 ;; Make a local post-command-hook and add our hook to it
1976 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1977 ;; (make-local-hook 'post-command-hook)
1978 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1980 ;; Make local hooks for buffer updates
1981 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1982 ;; (make-local-hook 'kill-buffer-hook)
1983 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1984 ;; (make-local-hook 'after-save-hook)
1985 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1986 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1988 ;; Setup directories and file, if necessary
1991 ;; Update the routine info with info about current buffer?
1992 (idlwave-new-buffer-update)
1994 ;; Check help location
1995 (idlwave-help-check-locations)
1997 ;; Run the mode hook
1998 (run-mode-hooks 'idlwave-mode-hook
))
2000 (defvar idlwave-setup-done nil
)
2001 (defun idlwave-setup ()
2002 (unless idlwave-setup-done
2003 (if (not (file-directory-p idlwave-config-directory
))
2004 (make-directory idlwave-config-directory
))
2006 idlwave-user-catalog-file
(expand-file-name
2007 idlwave-user-catalog-file
2008 idlwave-config-directory
)
2009 idlwave-xml-system-rinfo-converted-file
2011 idlwave-xml-system-rinfo-converted-file
2012 idlwave-config-directory
)
2013 idlwave-path-file
(expand-file-name
2015 idlwave-config-directory
))
2016 (idlwave-read-paths) ; we may need these early
2017 (setq idlwave-setup-done t
)))
2019 (defun idlwave-font-lock-fontify-region (beg end
&optional verbose
)
2020 "Fontify continuation lines correctly."
2025 (when (setq pos
(idlwave-is-continuation-line))
2027 (idlwave-beginning-of-statement)
2028 (setq beg
(point)))))
2029 (font-lock-default-fontify-region beg end verbose
))
2032 ;; Code Formatting ----------------------------------------------------
2035 (defun idlwave-hard-tab ()
2036 "Inserts TAB in buffer in current position."
2040 ;;; This stuff is experimental
2042 (defvar idlwave-command-hook nil
2043 "If non-nil, a list that can be evaluated using `eval'.
2044 It is evaluated in the lisp function `idlwave-command-hook' which is
2045 placed in `post-command-hook'.")
2047 (defun idlwave-command-hook ()
2048 "Command run after every command.
2049 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2050 sets the variable to zero afterwards."
2051 (and idlwave-command-hook
2052 (listp idlwave-command-hook
)
2054 (eval idlwave-command-hook
)
2056 (setq idlwave-command-hook nil
))
2060 ;; It would be better to use expand.el for better abbrev handling and
2063 (defun idlwave-check-abbrev (arg &optional reserved
)
2064 "Reverses abbrev expansion if in comment or string.
2065 Argument ARG is the number of characters to move point
2066 backward if `idlwave-abbrev-move' is non-nil.
2067 If optional argument RESERVED is non-nil then the expansion
2068 consists of reserved words, which will be capitalized if
2069 `idlwave-reserved-word-upcase' is non-nil.
2070 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2071 is non-nil, unless its value is \`down in which case the abbrev will be
2072 made into all lowercase.
2073 Returns non-nil if abbrev is left expanded."
2074 (if (idlwave-quoted)
2075 (progn (unexpand-abbrev)
2077 (if (and reserved idlwave-reserved-word-upcase
)
2078 (upcase-region last-abbrev-location
(point))
2080 ((equal idlwave-abbrev-change-case
'down
)
2081 (downcase-region last-abbrev-location
(point)))
2082 (idlwave-abbrev-change-case
2083 (upcase-region last-abbrev-location
(point)))))
2084 (if (and idlwave-abbrev-move
(> arg
0))
2085 (if (boundp 'post-command-hook
)
2086 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2087 (backward-char arg
)))
2090 (defun idlwave-in-comment ()
2091 "Returns t if point is inside a comment, nil otherwise."
2093 (let ((here (point)))
2094 (and (idlwave-goto-comment) (> here
(point))))))
2096 (defun idlwave-goto-comment ()
2097 "Move to start of comment delimiter on current line.
2098 Moves to end of line if there is no comment delimiter.
2099 Ignores comment delimiters in strings.
2100 Returns point if comment found and nil otherwise."
2101 (let ((eos (progn (end-of-line) (point)))
2104 ;; Look for first comment delimiter not in a string
2106 (setq found
(search-forward comment-start eos
'lim
))
2107 (while (and found
(idlwave-in-quote))
2108 (setq found
(search-forward comment-start eos
'lim
)))
2109 (store-match-data data
)
2110 (and found
(not (idlwave-in-quote))
2115 (defun idlwave-region-active-p ()
2116 "Should we operate on an active region?"
2117 (if (fboundp 'use-region-p
)
2121 (defun idlwave-show-matching-quote ()
2122 "Insert quote and show matching quote if this is end of a string."
2124 (let ((bq (idlwave-in-quote))
2125 (inq last-command-char
))
2126 (if (and bq
(not (idlwave-in-comment)))
2127 (let ((delim (char-after bq
)))
2133 ;; Not the end of a string
2136 (defun idlwave-show-begin-check ()
2137 "Ensure that the previous word was a token before `idlwave-show-begin'.
2138 An END token must be preceded by whitespace."
2139 (if (not (idlwave-quoted))
2144 (looking-at "[ \t\n\f]"))
2145 (idlwave-show-begin))))
2147 (defun idlwave-show-begin ()
2148 "Finds the start of current block and blinks to it for a second.
2149 Also checks if the correct end statement has been used."
2150 ;; All end statements are reserved words
2151 ;; Re-indent end line
2152 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2154 (let* ((pos (point-marker))
2155 (last-abbrev-marker (copy-marker last-abbrev-location
))
2156 (eol-pos (save-excursion (end-of-line) (point)))
2157 begin-pos end-pos end end1
)
2158 (if idlwave-reindent-end
(idlwave-indent-line))
2159 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2160 (when (and (idlwave-check-abbrev 0 t
)
2163 ;; Move inside current block
2164 (goto-char last-abbrev-marker
)
2165 (idlwave-block-jump-out -
1 'nomark
)
2166 (setq begin-pos
(point))
2167 (idlwave-block-jump-out 1 'nomark
)
2168 (setq end-pos
(point))
2169 (if (> end-pos eol-pos
)
2172 (setq end
(buffer-substring
2174 (skip-chars-backward "a-zA-Z")
2177 (goto-char begin-pos
)
2178 (when (setq end1
(cdr (idlwave-block-master)))
2180 ((null end1
)) ; no-operation
2181 ((string= (downcase end
) (downcase end1
))
2183 ((string= (downcase end
) "end")
2185 (if idlwave-expand-generic-end
2189 (insert (if (string= end
"END") (upcase end1
) end1
))
2194 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2199 (defun idlwave-block-master ()
2200 (let ((case-fold-search t
))
2203 ((looking-at "pro\\|case\\|switch\\|function\\>")
2204 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2205 ((looking-at "begin\\>")
2206 (let ((limit (save-excursion
2207 (idlwave-beginning-of-statement)
2210 ((re-search-backward ":[ \t]*\\=" limit t
)
2211 ;; seems to be a case thing
2213 ((re-search-backward idlwave-block-match-regexp limit t
)
2214 (assoc (downcase (match-string 1))
2215 idlwave-block-matches
))
2217 ;; Just a normal block
2218 '("begin" .
"end")))))
2221 (defun idlwave-close-block ()
2222 "Terminate the current block with the correct END statement."
2224 ;; Start new line if we are not in a new line
2225 (unless (save-excursion
2226 (skip-chars-backward " \t")
2228 (let ((idlwave-show-block nil
))
2229 (newline-and-indent)))
2230 (let ((last-abbrev-location (point))) ; for upcasing
2232 (idlwave-show-begin)))
2234 (defun idlwave-custom-ampersand-surround (&optional is-action
)
2235 "Surround &, leaving room for && (which surrround as well)."
2236 (let* ((prev-char (char-after (- (point) 2)))
2237 (next-char (char-after (point)))
2238 (amp-left (eq prev-char ?
&))
2239 (amp-right (eq next-char ?
&))
2240 (len (if amp-left
2 1)))
2241 (unless amp-right
;no need to do it twice, amp-left will catch it.
2242 (idlwave-surround -
1 (if (or is-action amp-left
) -
1) len
))))
2244 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action
)
2245 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2246 (let* ((prev-char (char-after (- (point) 2)))
2247 (next-char (char-after (point)))
2248 (method-invoke (and gtr
(eq prev-char ?-
)))
2249 (len (if method-invoke
2 1)))
2250 (unless (eq next-char ?
=)
2251 ;; Key binding: pad only on left, to save for possible >=/<=
2252 (idlwave-surround -
1 (if (or is-action method-invoke
) -
1) len
))))
2254 (defun idlwave-surround (&optional before after length is-action
)
2255 "Surround the LENGTH characters before point with blanks.
2256 LENGTH defaults to 1.
2257 Optional arguments BEFORE and AFTER affect the behavior before and
2258 after the characters (see also description of `idlwave-make-space'):
2262 integer > 0 force exactly n spaces
2263 integer < 0 at least |n| spaces
2265 The function does nothing if any of the following conditions is true:
2266 - `idlwave-surround-by-blank' is nil
2267 - the character before point is inside a string or comment"
2268 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2269 (let ((length (or length
1))) ; establish a default for LENGTH
2270 (backward-char length
)
2272 (let ((here (point)))
2273 (skip-chars-backward " \t")
2275 ;; avoid clobbering indent
2277 (move-to-column (idlwave-calculate-indent))
2278 (if (<= (point) here
)
2279 (narrow-to-region (point) here
))
2281 (idlwave-make-space before
))
2282 (skip-chars-forward " \t"))
2283 (forward-char length
)
2284 (idlwave-make-space after
)
2285 ;; Check to see if the line should auto wrap
2286 (if (and (equal (char-after (1- (point))) ?\
)
2287 (> (current-column) fill-column
))
2288 (funcall auto-fill-function
)))))
2290 (defun idlwave-make-space (n)
2291 "Make space at point.
2292 The space affected is all the spaces and tabs around point.
2293 If n is non-nil then point is left abs(n) spaces from the beginning of
2294 the contiguous space.
2295 The amount of space at point is determined by N.
2296 If the value of N is:
2298 > 0 - exactly N spaces.
2299 < 0 - a minimum of -N spaces, i.e., do not change if there are
2301 0 - no spaces (i.e. remove any existing space)."
2304 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2306 (end-col (progn (skip-chars-forward " \t") (current-column))))
2307 (delete-horizontal-space)
2310 (idlwave-indent-to (+ start-col n
))
2311 (goto-char (+ left n
)))
2313 (idlwave-indent-to end-col
(- n
))
2314 (goto-char (- left n
)))
2318 (defun idlwave-newline ()
2319 "Inserts a newline and indents the current and previous line."
2322 ;; Handle unterminated single and double quotes
2323 ;; If not in a comment and in a string then insertion of a newline
2324 ;; will mean unbalanced quotes.
2326 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2328 (message "Warning: unbalanced quotes?")))
2331 ;; The current line is being split, the cursor should be at the
2332 ;; beginning of the new line skipping the leading indentation.
2334 ;; The reason we insert the new line before indenting is that the
2335 ;; indenting could be confused by keywords (e.g. END) on the line
2336 ;; after the split point. This prevents us from just using
2337 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2339 (beginning-of-line 0)
2340 (idlwave-indent-line)
2342 (idlwave-indent-line))
2345 ;; Use global variable 'comment-column' to set parallel comment
2347 ;; Modeled on lisp.el
2348 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2349 (defun idlwave-comment-hook ()
2350 "Compute indent for the beginning of the IDL comment delimiter."
2351 (if (or (looking-at idlwave-no-change-comment
)
2352 (if idlwave-begin-line-comment
2353 (looking-at idlwave-begin-line-comment
)
2356 (if (looking-at idlwave-code-comment
)
2357 (if (save-excursion (skip-chars-backward " \t") (bolp))
2358 ;; On line by itself, indent as code
2359 (let ((tem (idlwave-calculate-indent)))
2360 (if (listp tem
) (car tem
) tem
))
2361 ;; after code - do not change
2363 (skip-chars-backward " \t")
2364 (max (if (bolp) 0 (1+ (current-column)))
2367 (defun idlwave-split-line ()
2368 "Continue line by breaking line at point and indent the lines.
2369 For a code line insert continuation marker. If the line is a line comment
2370 then the new line will contain a comment with the same indentation.
2371 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2374 ;; Expand abbreviation, just like normal RET would.
2375 (and abbrev-mode
(expand-abbrev))
2377 (if (not (idlwave-in-comment))
2378 ;; For code line add continuation.
2379 ;; Check if splitting a string.
2381 (if (setq beg
(idlwave-in-quote))
2382 (if idlwave-split-line-string
2383 ;; Split the string.
2384 (progn (insert (setq beg
(char-after beg
)) " + "
2385 idlwave-continuation-char beg
)
2387 (newline-and-indent)
2389 ;; Do not split the string.
2391 (message "Warning: continuation inside string!!")
2392 (insert " " idlwave-continuation-char
))
2393 ;; Not splitting a string.
2394 (if (not (member (char-before) '(?\ ?
\t)))
2396 (insert idlwave-continuation-char
)
2397 (newline-and-indent)))
2398 (indent-new-comment-line))
2399 ;; Indent previous line
2400 (setq beg
(- (point-max) (point)))
2402 (idlwave-indent-line)
2403 (goto-char (- (point-max) beg
))
2404 ;; Reindent new line
2405 (idlwave-indent-line)))
2407 (defun idlwave-beginning-of-subprogram (&optional nomark
)
2408 "Moves point to the beginning of the current program unit.
2409 If NOMARK is non-nil, do not push mark."
2411 (idlwave-find-key idlwave-begin-unit-reg -
1 nomark
))
2413 (defun idlwave-end-of-subprogram (&optional nomark
)
2414 "Moves point to the start of the next program unit.
2415 If NOMARK is non-nil, do not push mark."
2417 (idlwave-end-of-statement)
2418 (idlwave-find-key idlwave-end-unit-reg
1 nomark
))
2420 (defun idlwave-mark-statement ()
2421 "Mark current IDL statement."
2423 (idlwave-end-of-statement)
2424 (let ((end (point)))
2425 (idlwave-beginning-of-statement)
2426 (push-mark end nil t
)))
2428 (defun idlwave-mark-block ()
2429 "Mark containing block."
2431 (idlwave-end-of-statement)
2432 (idlwave-backward-up-block -
1)
2433 (idlwave-end-of-statement)
2434 (let ((end (point)))
2435 (idlwave-backward-block)
2436 (idlwave-beginning-of-statement)
2437 (push-mark end nil t
)))
2440 (defun idlwave-mark-subprogram ()
2441 "Put mark at beginning of program, point at end.
2442 The marks are pushed."
2444 (idlwave-end-of-statement)
2445 (idlwave-beginning-of-subprogram)
2446 (let ((beg (point)))
2447 (idlwave-forward-block)
2448 (push-mark beg nil t
))
2449 (exchange-point-and-mark))
2451 (defun idlwave-backward-up-block (&optional arg
)
2452 "Move to beginning of enclosing block if prefix ARG >= 0.
2453 If prefix ARG < 0 then move forward to enclosing block end."
2455 (idlwave-block-jump-out (- arg
) 'nomark
))
2457 (defun idlwave-beginning-of-block ()
2458 "Go to the beginning of the current block."
2460 (idlwave-block-jump-out -
1 'nomark
)
2463 (defun idlwave-end-of-block ()
2464 "Go to the beginning of the current block."
2466 (idlwave-block-jump-out 1 'nomark
)
2469 (defun idlwave-forward-block (&optional arg
)
2470 "Move across next nested block."
2472 (let ((arg (or arg
1)))
2473 (if (idlwave-down-block arg
)
2474 (idlwave-block-jump-out arg
'nomark
))))
2476 (defun idlwave-backward-block ()
2477 "Move backward across previous nested block."
2479 (if (idlwave-down-block -
1)
2480 (idlwave-block-jump-out -
1 'nomark
)))
2482 (defun idlwave-down-block (&optional arg
)
2484 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2485 Returns non-nil if successfull."
2490 (let ((eos (save-excursion
2491 (idlwave-block-jump-out -
1 'nomark
)
2493 (if (setq status
(idlwave-find-key
2494 idlwave-end-block-reg -
1 'nomark eos
))
2495 (idlwave-beginning-of-statement)
2496 (message "No nested block before beginning of containing block.")))
2498 (let ((eos (save-excursion
2499 (idlwave-block-jump-out 1 'nomark
)
2501 (if (setq status
(idlwave-find-key
2502 idlwave-begin-block-reg
1 'nomark eos
))
2503 (idlwave-end-of-statement)
2504 (message "No nested block before end of containing block."))))
2507 (defun idlwave-mark-doclib ()
2508 "Put point at beginning of doc library header, mark at end.
2509 The marks are pushed."
2513 (goto-char (point-max))
2514 (if (re-search-backward idlwave-doclib-start nil t
)
2516 (setq beg
(progn (beginning-of-line) (point)))
2517 (if (re-search-forward idlwave-doclib-end nil t
)
2520 (push-mark beg nil t
)
2521 (message "Could not find end of doc library header.")))
2522 (message "Could not find doc library header start.")
2523 (goto-char here
)))))
2525 (defun idlwave-current-routine-fullname ()
2526 (let ((name (idlwave-current-routine)))
2527 (idlwave-make-full-name (nth 2 name
) (car name
))))
2529 (defun idlwave-current-routine ()
2530 "Return (NAME TYPE CLASS) of current routine."
2533 (idlwave-beginning-of-subprogram 'nomark
)
2534 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2535 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2537 (class (idlwave-sintern-class (match-string 3)))
2538 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2539 (list name type class
)))))
2541 (defvar idlwave-shell-prompt-pattern
)
2542 (defun idlwave-beginning-of-statement ()
2543 "Move to beginning of the current statement.
2544 Skips back past statement continuations.
2545 Point is placed at the beginning of the line whether or not this is an
2549 ((eq major-mode
'idlwave-shell-mode
)
2550 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2551 (goto-char (match-end 0))))
2553 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2554 (idlwave-previous-statement)
2555 (beginning-of-line)))))
2557 (defun idlwave-previous-statement ()
2558 "Moves point to beginning of the previous statement.
2559 Returns t if the current line before moving is the beginning of
2560 the first non-comment statement in the file, and nil otherwise."
2562 (let (first-statement)
2563 (if (not (= (forward-line -
1) 0))
2564 ;; first line in file
2566 ;; skip blank lines, label lines, include lines and line comments
2568 ;; The current statement is the first statement until we
2569 ;; reach another statement.
2570 (setq first-statement
2572 (looking-at idlwave-comment-line-start-skip
)
2573 (looking-at "[ \t]*$")
2574 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2576 (= (forward-line -
1) 0)))
2577 ;; skip continuation lines
2581 (idlwave-is-continuation-line))
2582 (= (forward-line -
1) 0)))
2585 (defun idlwave-end-of-statement ()
2586 "Moves point to the end of the current IDL statement.
2587 If not in a statement just moves to end of line. Returns position."
2589 (while (and (idlwave-is-continuation-line)
2590 (= (forward-line 1) 0))
2591 (while (and (idlwave-is-comment-or-empty-line)
2592 (= (forward-line 1) 0))))
2596 (defun idlwave-end-of-statement0 ()
2597 "Moves point to the end of the current IDL statement.
2598 If not in a statement just moves to end of line. Returns position."
2600 (while (and (idlwave-is-continuation-line)
2601 (= (forward-line 1) 0)))
2605 (defun idlwave-next-statement ()
2606 "Moves point to beginning of the next IDL statement.
2607 Returns t if that statement is the last
2608 non-comment IDL statement in the file, and nil otherwise."
2610 (let (last-statement)
2611 (idlwave-end-of-statement)
2612 ;; skip blank lines, label lines, include lines and line comments
2613 (while (and (= (forward-line 1) 0)
2614 ;; The current statement is the last statement until
2615 ;; we reach a new statement.
2616 (setq last-statement
2618 (looking-at idlwave-comment-line-start-skip
)
2619 (looking-at "[ \t]*$")
2620 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2621 (looking-at "^@")))))
2624 (defun idlwave-skip-multi-commands (&optional lim
)
2625 "Skip past multiple commands on a line (with `&')."
2626 (let ((save-point (point)))
2627 (when (re-search-forward ".*&" lim t
)
2628 (goto-char (match-end 0))
2629 (if (idlwave-quoted)
2630 (goto-char save-point
)
2631 (if (eq (char-after (- (point) 2)) ?
&) (goto-char save-point
))))
2634 (defun idlwave-skip-label-or-case ()
2635 "Skip label or case statement element.
2636 Returns position after label.
2637 If there is no label point is not moved and nil is returned."
2638 ;; Case expressions and labels are terminated by a colon.
2639 ;; So we find the first colon in the line and make sure
2640 ;; - no `?' is before it (might be a ? b : c)
2641 ;; - it is not in a comment
2642 ;; - not in a string constant
2643 ;; - not in parenthesis (like a[0:3])
2644 ;; - not followed by another ":" in explicit class, ala a->b::c
2645 ;; As many in this mode, this function is heuristic and not an exact
2647 (let* ((start (point))
2648 (eos (save-excursion (idlwave-end-of-statement) (point)))
2649 (end (idlwave-find-key ":" 1 'nomark eos
)))
2651 (= (nth 0 (parse-partial-sexp start end
)) 0)
2652 (not (string-match "\\?" (buffer-substring start end
)))
2653 (not (string-match "^::" (buffer-substring end eos
))))
2660 (defun idlwave-start-of-substatement (&optional pre
)
2661 "Move to start of next IDL substatement after point.
2662 Uses the type of the current IDL statement to determine if the next
2663 statement is on a new line or is a subpart of the current statement.
2664 Returns point at start of substatement modulo whitespace.
2665 If optional argument is non-nil move to beginning of current
2667 (let ((orig (point))
2668 (eos (idlwave-end-of-statement))
2671 (idlwave-beginning-of-statement)
2672 (idlwave-skip-label-or-case)
2673 (if (< (point) orig
)
2674 (idlwave-skip-multi-commands orig
))
2676 ;; Continue looking for substatements until we are past orig
2677 (while (and (<= (point) orig
) (not (eobp)))
2679 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2680 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2682 (idlwave-find-key nst
1 'nomark eos
))
2683 (goto-char (match-end 0)))
2684 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2685 (setq ifnest
(1- ifnest
))
2686 (goto-char (match-end 0)))
2688 (idlwave-next-statement))))
2689 (if pre
(goto-char last
))
2690 ;; If a continuation line starts here, move to next line
2691 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2692 (beginning-of-line 2))
2695 (defun idlwave-statement-type ()
2696 "Return the type of the current IDL statement.
2697 Uses `idlwave-statement-match' to return a cons of (type . point) with
2698 point the ending position where the type was determined. Type is the
2699 association from `idlwave-statement-match', i.e. the cons cell from the
2700 list not just the type symbol. Returns nil if not an identifiable
2703 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2704 ;; and possibly comments
2705 (while (looking-at "[ \t]*\\$")
2707 (skip-chars-forward " \t")
2708 (let ((st idlwave-statement-match
)
2709 (case-fold-search t
))
2710 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2711 (setq st
(cdr st
))))
2713 (append st
(match-end 0))))))
2715 (defun idlwave-expand-equal (&optional before after is-action
)
2716 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2717 assignment. Which case is determined using
2718 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2719 equal sign will be surrounded by BEFORE and AFTER blanks. If
2720 `idlwave-pad-keyword' is t then keyword assignment is treated just
2721 like assignment statements. When nil, spaces are removed for keyword
2722 assignment. Any other value keeps the current space around the `='.
2723 Limits in for loops are treated as keyword assignment.
2725 Starting with IDL 6.0, a number of op= assignments are available.
2726 Since ambiguities of the form:
2731 can occur, alphanumeric operator assignment will never be pre-padded,
2732 only post-padded. You must use a space before these to disambiguate
2733 \(not just for padding, but for proper parsing by IDL too!). Other
2734 operators, such as ##=, ^=, etc., will be pre-padded.
2736 IS-ACTION is ignored.
2738 See `idlwave-surround'."
2739 (if idlwave-surround-by-blank
2741 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2743 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2747 (let ((case-fold-search t
))
2750 (re-search-backward non-an-ops nil t
)
2751 ;; Why doesn't ##? work for both?
2752 (re-search-backward "\\(#\\)\\=" nil t
))
2753 (setq len
(1+ (length (match-string 1))))
2754 (when (re-search-backward an-ops nil t
)
2755 ;(setq begin nil) ; won't modify begin
2756 (setq len
(1+ (length (match-string 1))))))))
2758 (if (eq t idlwave-pad-keyword
)
2759 ;; Everything gets padded equally
2760 (idlwave-surround before after len
)
2761 ;; Treating keywords/for variables specially...
2762 (let ((st (save-excursion ; To catch "for" variables
2763 (idlwave-start-of-substatement t
)
2764 (idlwave-statement-type)))
2765 (what (save-excursion ; To catch keywords
2766 (skip-chars-backward "= \t")
2767 (nth 2 (idlwave-where)))))
2768 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2769 (memq (caar st
) '(for pdef
)))
2771 ((null idlwave-pad-keyword
)
2772 (idlwave-surround 0 0)
2774 (t))) ; leave any spaces alone
2775 (t (idlwave-surround before after len
))))))))
2778 (defun idlwave-indent-and-action (&optional arg
)
2779 "Call `idlwave-indent-line' and do expand actions.
2780 With prefix ARG non-nil, indent the entire sub-statement."
2783 (if (and idlwave-expand-generic-end
2784 (re-search-backward "\\<\\(end\\)\\s-*\\="
2785 (max 0 (- (point) 10)) t
)
2786 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2787 (progn (goto-char (match-end 1))
2788 ;;Expand the END abbreviation, just as RET or Space would have.
2789 (if abbrev-mode
(expand-abbrev)
2790 (idlwave-show-begin)))))
2791 (when (and (not arg
) current-prefix-arg
)
2792 (setq arg current-prefix-arg
)
2793 (setq current-prefix-arg nil
))
2795 (idlwave-indent-statement)
2796 (idlwave-indent-line t
)))
2798 (defun idlwave-indent-line (&optional expand
)
2799 "Indents current IDL line as code or as a comment.
2800 The actions in `idlwave-indent-action-table' are performed.
2801 If the optional argument EXPAND is non-nil then the actions in
2802 `idlwave-indent-expand-table' are performed."
2804 ;; Move point out of left margin.
2806 (skip-chars-backward " \t")
2808 (skip-chars-forward " \t"))
2809 (let ((mloc (point-marker)))
2812 (if (looking-at idlwave-comment-line-start-skip
)
2813 ;; Indentation for a line comment
2815 (skip-chars-forward " \t")
2816 (idlwave-indent-left-margin (idlwave-comment-hook)))
2820 ;; Before indenting, run action routines.
2822 (if (and expand idlwave-do-actions
)
2823 (mapc 'idlwave-do-action idlwave-indent-expand-table
))
2825 (if idlwave-do-actions
2826 (mapc 'idlwave-do-action idlwave-indent-action-table
))
2828 ;; No longer expand abbrevs on the line. The user can do this
2829 ;; manually using expand-region-abbrevs.
2831 ;; Indent for code line
2836 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2838 (looking-at "^[ \t]*@"))
2842 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2843 ;; Adjust parallel comment
2845 (if (idlwave-in-comment)
2846 ;; Emacs 21 is too smart with fill-column on comment indent
2847 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2850 (indent-for-comment)))))
2852 ;; Get rid of marker
2853 (set-marker mloc nil
)))
2855 (defun idlwave-do-action (action)
2856 "Perform an action repeatedly on a line. ACTION is a list (REG
2857 . FUNC). REG is a regular expression. FUNC is either a function name
2858 to be called with `funcall' or a list to be evaluated with `eval'.
2859 The action performed by FUNC should leave point after the match for
2860 REG - otherwise an infinite loop may be entered. FUNC is always
2861 passed a final argument of 'is-action, so it can discriminate between
2862 being run as an action, or a key binding"
2863 (let ((action-key (car action
))
2864 (action-routine (cdr action
)))
2866 (while (idlwave-look-at action-key
)
2867 (if (listp action-routine
)
2868 (eval (append action-routine
'('is-action
)))
2869 (funcall action-routine
'is-action
)))))
2871 (defun idlwave-indent-to (col &optional min
)
2872 "Indent from point with spaces until column COL.
2873 Inserts space before markers at point."
2874 (if (not min
) (setq min
0))
2875 (insert-before-markers
2876 (make-string (max min
(- col
(current-column))) ?\
)))
2878 (defun idlwave-indent-left-margin (col)
2879 "Indent the current line to column COL.
2880 Indents such that first non-whitespace character is at column COL
2881 Inserts spaces before markers at point."
2884 (delete-horizontal-space)
2885 (idlwave-indent-to col
)))
2887 (defun idlwave-indent-subprogram ()
2888 "Indents program unit which contains point."
2891 (idlwave-end-of-statement)
2892 (idlwave-beginning-of-subprogram)
2893 (let ((beg (point)))
2894 (idlwave-forward-block)
2895 (message "Indenting subprogram...")
2896 (indent-region beg
(point) nil
))
2897 (message "Indenting subprogram...done.")))
2899 (defun idlwave-indent-statement ()
2900 "Indent current statement, including all continuation lines."
2903 (idlwave-beginning-of-statement)
2904 (let ((beg (point)))
2905 (idlwave-end-of-statement)
2906 (indent-region beg
(point) nil
))))
2908 (defun idlwave-calculate-indent ()
2909 "Return appropriate indentation for current line as IDL code."
2913 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2915 ((idlwave-look-at idlwave-begin-unit-reg
)
2917 ;; Check for continuation line
2919 (and (= (forward-line -
1) 0)
2920 (idlwave-is-continuation-line)))
2921 (idlwave-calculate-cont-indent))
2922 ;; calculate indent based on previous and current statements
2923 (t (let* (beg-prev-pos
2925 ;; calculate indent based on previous statement
2928 ;; Beginning of file
2930 (idlwave-previous-statement)
2931 (setq beg-prev-pos
(point)))
2934 ((idlwave-look-at idlwave-begin-unit-reg t
)
2935 (+ (idlwave-current-statement-indent)
2936 idlwave-main-block-indent
))
2938 ((idlwave-look-at idlwave-begin-block-reg t
)
2939 (+ (idlwave-min-current-statement-indent)
2940 idlwave-block-indent
))
2942 ((idlwave-look-at idlwave-end-block-reg t
)
2944 ;; Match to the *beginning* of the block opener
2945 (goto-char beg-prev-pos
)
2946 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2947 (idlwave-min-current-statement-indent)))
2948 ;; idlwave-end-offset
2949 ;; idlwave-block-indent))
2951 ;; Default to current indent
2952 ((idlwave-current-statement-indent))))))
2953 ;; adjust the indentation based on the current statement
2956 ((idlwave-look-at idlwave-end-block-reg
)
2957 (+ the-indent idlwave-end-offset
))
2961 ;; Parentheses indent
2964 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2965 "Calculate the continuation indent inside a paren group.
2966 Returns a cons-cell with (open . indent), where open is the
2967 location of the open paren"
2968 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2969 ;; Found an innermost open paren.
2972 ;; Line up with next word unless this is a closing paren.
2975 ;; Plain Kernighan-style nested indent
2976 (idlwave-indent-parens-nested
2977 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2979 ;; This is a closed paren - line up under open paren.
2983 ;; Empty (or just comment) follows -- revert to basic indent
2987 (looking-at "[ \t$]*\\(;.*\\)?$"))
2990 ;; Line up with first word after any blank space
2992 (skip-chars-forward " \t")
2993 (current-column))))))))
2995 (defun idlwave-calculate-cont-indent ()
2996 "Calculates the IDL continuation indent column from the previous
2997 statement. Note that here previous statement usually means the
2998 beginning of the current statement if this statement is a continuation
2999 of the previous line. Various special types of continuations,
3000 including assignments, routine definitions, and parenthetical
3001 groupings, are treated separately."
3003 (let* ((case-fold-search t
)
3004 (end-reg (progn (beginning-of-line) (point)))
3005 (beg-last-statement (save-excursion (idlwave-previous-statement)
3007 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
3008 (if (eq (line-beginning-position) end-reg
)
3009 (goto-char beg-last-statement
)
3011 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
3012 idlwave-continuation-indent
))
3013 fancy-nonparen-indent fancy-paren-indent
)
3015 ;; Align then with its matching if, etc.
3016 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
3017 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
3018 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
3019 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3021 ("\\<case\\>" .
"[ \t]*of")))
3027 (while (setq match
(car matchers
))
3028 (if (looking-at (cdr match
))
3029 (throw 'exit
(car match
)))
3030 (setq matchers
(cdr matchers
)))))
3031 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
3032 (if (looking-at "end") ;; that one's special
3033 (- (idlwave-current-indent)
3034 (+ idlwave-block-indent idlwave-end-offset
))
3035 (idlwave-current-indent)))
3037 ;; Indent in from the previous line for continuing statements
3038 ((let ((matchers '("\\<then\\>"
3045 (if (/= (forward-line -
1) 0)
3047 (while (setq match
(car matchers
))
3048 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
3051 (setq matchers
(cdr matchers
)))))
3052 (+ idlwave-continuation-indent
(idlwave-current-indent)))
3054 ;; Parenthetical indent, either traditional or Kernighan style
3055 ((setq fancy-paren-indent
3056 (let* ((end-reg end-reg
)
3059 (skip-chars-forward " \t")
3060 (looking-at "\\s)")))
3063 (while (setq indent-cons
(idlwave-calculate-paren-indent
3064 beg-reg end-reg close-exp
))
3065 ;; First permitted containing paren
3067 idlwave-indent-to-open-paren
3068 idlwave-indent-parens-nested
3069 (null (cdr indent-cons
))
3070 (< (- (cdr indent-cons
) basic-indent
)
3071 idlwave-max-extra-continuation-indent
))
3072 (throw 'loop
(cdr indent-cons
)))
3073 (setq end-reg
(car indent-cons
))))))
3076 ;; A continued assignment, or procedure call/definition
3078 (> idlwave-max-extra-continuation-indent
0)
3079 (setq fancy-nonparen-indent
3082 (while (idlwave-look-at "&")) ; skip continued statements
3084 ;; A continued Procedure call or definition
3086 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3087 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3088 (goto-char (match-end 0))
3089 ;; Comment only, or blank line with "$"? Basic indent.
3090 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3094 ;; Continued assignment (with =):
3096 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3097 (goto-char (match-end 0))
3098 (if (null (idlwave-what-function beg-reg
))
3099 (throw 'assign t
))))
3102 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3104 (goto-char beg-last-statement
)
3105 (eq (caar (idlwave-statement-type)) 'for
)))
3106 (current-column))))))
3107 (< (- fancy-nonparen-indent basic-indent
)
3108 idlwave-max-extra-continuation-indent
))
3109 (if fancy-paren-indent
;calculated but disallowed paren indent
3110 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3111 fancy-nonparen-indent
))
3113 ;; Basic indent, by default
3114 (t basic-indent
)))))
3118 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3119 "Move to next match of the regular expression KEY-RE.
3120 Matches inside comments or string constants will be ignored.
3121 If DIR is negative, the search will be backwards.
3122 At a successful match, the mark is pushed unless NOMARK is non-nil.
3123 Searches are limited to LIMIT.
3124 Searches are case-insensitive and use a special syntax table which
3125 treats `$' and `_' as word characters.
3126 Return value is the beginning of the match or (in case of failure) nil."
3127 (setq dir
(or dir
0))
3128 (let ((case-fold-search t
)
3129 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3131 (idlwave-with-special-syntax
3134 (while (funcall search-func key-re limit t
)
3135 (if (not (idlwave-quoted))
3136 (throw 'exit
(setq found
(match-beginning 0)))
3137 (if (or (and (> dir
0) (eobp))
3138 (and (< dir
0) (bobp)))
3139 (throw 'exit nil
)))))))
3142 (if (not nomark
) (push-mark))
3147 (defun idlwave-block-jump-out (&optional dir nomark
)
3148 "When optional argument DIR is non-negative, move forward to end of
3149 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3150 regular expressions. When DIR is negative, move backwards to block beginning.
3151 Recursively calls itself to skip over nested blocks. DIR defaults to
3152 forward. Calls `push-mark' unless the optional argument NOMARK is
3153 non-nil. Movement is limited by the start of program units because of
3154 possibility of unbalanced blocks."
3156 (or dir
(setq dir
0))
3157 (let* ((here (point))
3158 (case-fold-search t
)
3159 (limit (if (>= dir
0) (point-max) (point-min)))
3160 (block-limit (if (>= dir
0)
3161 idlwave-begin-block-reg
3162 idlwave-end-block-reg
))
3164 (block-reg (concat idlwave-begin-block-reg
"\\|"
3165 idlwave-end-block-reg
))
3166 (unit-limit (or (save-excursion
3169 idlwave-begin-unit-reg dir t limit
)
3172 idlwave-end-unit-reg dir t limit
)))
3174 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3175 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3176 (while (and found
(looking-at block-limit
))
3177 (if (>= dir
0) (forward-word 1))
3178 (idlwave-block-jump-out dir t
)
3179 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3180 (if (not nomark
) (push-mark here
))
3181 (if (not found
) (goto-char unit-limit
)
3182 (if (>= dir
0) (forward-word 1)))))
3184 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3185 "The minimum indent in the current statement."
3186 (idlwave-beginning-of-statement)
3187 (if (not (idlwave-is-continuation-line))
3188 (idlwave-current-indent)
3189 (let ((min (idlwave-current-indent)) comm-or-empty
)
3190 (while (and (= (forward-line 1) 0)
3191 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3192 (idlwave-is-continuation-line))
3193 (or (null end-reg
) (< (point) end-reg
)))
3194 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3195 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3197 (min min
(idlwave-current-indent))))))
3199 (defun idlwave-current-statement-indent (&optional last-line
)
3200 "Return indentation of the current statement.
3201 If in a statement, moves to beginning of statement before finding indent."
3203 (idlwave-end-of-statement)
3204 (idlwave-beginning-of-statement))
3205 (idlwave-current-indent))
3207 (defun idlwave-current-indent ()
3208 "Return the column of the indentation of the current line.
3209 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3212 (skip-chars-forward " \t")
3213 ;; if we are at the end of blank line return 0
3215 ((current-column)))))
3217 (defun idlwave-is-continuation-line ()
3218 "Tests if current line is continuation line.
3219 Blank or comment-only lines following regular continuation lines (with
3220 `$') count as continuations too."
3224 (idlwave-look-at "\\<\\$")
3226 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3227 (eq (forward-line -
1) 0))
3228 (if (setq p
(idlwave-look-at "\\<\\$")) (throw 'loop p
))))))))
3230 (defun idlwave-is-comment-line ()
3231 "Tests if the current line is a comment line."
3233 (beginning-of-line 1)
3234 (looking-at "[ \t]*;")))
3236 (defun idlwave-is-comment-or-empty-line ()
3237 "Tests if the current line is a comment line."
3239 (beginning-of-line 1)
3240 (looking-at "[ \t]*[;\n]")))
3242 (defun idlwave-look-at (regexp &optional cont beg
)
3243 "Searches current line from current point for REGEXP.
3244 If optional argument CONT is non-nil, searches to the end of
3245 the current statement.
3246 If optional arg BEG is non-nil, search starts from the beginning of the
3248 Ignores matches that end in a comment or inside a string expression.
3249 Returns point if successful, nil otherwise.
3250 This function produces unexpected results if REGEXP contains quotes or
3251 a comment delimiter. The search is case insensitive.
3252 If successful leaves point after the match, otherwise, does not move point."
3253 (let ((here (point))
3254 (case-fold-search t
)
3255 (eos (save-excursion
3256 (if cont
(idlwave-end-of-statement) (end-of-line))
3259 (idlwave-with-special-syntax
3260 (if beg
(idlwave-beginning-of-statement))
3261 (while (and (setq found
(re-search-forward regexp eos t
))
3263 (if (not found
) (goto-char here
))
3266 (defun idlwave-fill-paragraph (&optional nohang
)
3267 "Fills paragraphs in comments.
3268 A paragraph is made up of all contiguous lines having the same comment
3269 leader (the leading whitespace before the comment delimiter and the
3270 comment delimiter). In addition, paragraphs are separated by blank
3271 line comments. The indentation is given by the hanging indent of the
3272 first line, otherwise by the minimum indentation of the lines after
3273 the first line. The indentation of the first line does not change.
3274 Does not effect code lines. Does not fill comments on the same line
3275 with code. The hanging indent is given by the end of the first match
3276 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3277 optional argument NOHANG is non-nil then the hanging indent is
3280 ;; check if this is a line comment
3283 (skip-chars-forward " \t")
3284 (looking-at comment-start
))
3287 pre here diff fill-prefix-reg bcl first-indent
3289 ;; Change tabs to spaces in the surrounding paragraph.
3290 ;; The surrounding paragraph will be the largest containing block of
3291 ;; contiguous line comments. Thus, we may be changing tabs in
3292 ;; a much larger area than is needed, but this is the easiest
3293 ;; brute force way to do it.
3295 ;; This has the undesirable side effect of replacing the tabs
3296 ;; permanently without the user's request or knowledge.
3298 (backward-paragraph)
3299 (setq start
(point)))
3303 (untabify start end
)
3309 (concat "^[ \t]*" comment-start
"+")
3310 (save-excursion (end-of-line) (point))
3312 ;; Get the comment leader on the line and its length
3313 (setq pre
(current-column))
3314 ;; the comment leader is the indentation plus exactly the
3315 ;; number of consecutive ";".
3316 (setq fill-prefix-reg
3320 (buffer-substring (save-excursion
3321 (beginning-of-line) (point))
3325 ;; Mark the beginning and end of the paragraph
3327 (while (and (looking-at fill-prefix-reg
)
3328 (not (looking-at paragraph-separate
))
3331 ;; Move to first line of paragraph
3332 (if (/= (point) bcl
)
3334 (setq start
(point))
3336 (while (and (looking-at fill-prefix-reg
)
3337 (not (looking-at paragraph-separate
))
3341 (if (or (not (looking-at fill-prefix-reg
))
3342 (looking-at paragraph-separate
))
3345 ;; if at end of buffer add a newline (need this because
3346 ;; fill-region needs END to be at the beginning of line after
3347 ;; the paragraph or it will add a line).
3349 (progn (insert ?
\n) (backward-char 1)))
3350 ;; Set END to the beginning of line after the paragraph
3351 ;; END is calculated as distance from end of buffer
3352 (setq end
(- (point-max) (point) 1))
3354 ;; Calculate the indentation for the paragraph.
3356 ;; In the following while statements, after one iteration
3357 ;; point will be at the beginning of a line in which case
3358 ;; the while will not be executed for the
3359 ;; the first paragraph line and thus will not affect the
3362 ;; First check to see if indentation is based on hanging indent.
3363 (if (and (not nohang
) idlwave-hanging-indent
3367 (idlwave-calc-hanging-indent))))
3368 ;; Adjust lines of paragraph by inserting spaces so that
3369 ;; each line's indent is at least as great as the hanging
3370 ;; indent. This is needed for fill-paragraph to work with
3375 (while (> (point) start
)
3376 (re-search-forward comment-start-skip
3377 (save-excursion (end-of-line) (point))
3379 (if (> (setq diff
(- indent
(current-column))) 0)
3381 (if (>= here
(point))
3382 ;; adjust the original location for the
3384 (setq here
(+ here diff
)))
3385 (insert (make-string diff ?\
))))
3389 ;; No hang. Instead find minimum indentation of paragraph
3390 ;; after first line.
3391 ;; For the following while statement, since START is at the
3392 ;; beginning of line and END is at the end of line
3393 ;; point is greater than START at least once (which would
3394 ;; be the case for a single line paragraph).
3395 (while (> (point) start
)
3402 (save-excursion (end-of-line) (point))
3407 (setq fill-prefix
(concat fill-prefix
3408 (make-string (- indent pre
)
3410 ;; first-line indent
3416 (save-excursion (end-of-line) (point))
3421 ;; try to keep point at its original place
3424 ;; In place of the more modern fill-region-as-paragraph, a hack
3425 ;; to keep whitespace untouched on the first line within the
3426 ;; indent length and to preserve any indent on the first line
3430 (buffer-substring start
(+ start first-indent -
1)))
3431 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3432 (fill-region-as-paragraph
3435 (current-justification)
3437 (delete-region start
(+ start first-indent -
1))
3440 ;; When we want the point at the beginning of the comment
3441 ;; body fill-region will put it at the beginning of the line.
3442 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3443 (setq fill-prefix nil
))))
3445 (defun idlwave-calc-hanging-indent ()
3446 "Calculate the position of the hanging indent for the comment
3447 paragraph. The hanging indent position is given by the first match
3448 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3449 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3451 If not found returns nil."
3452 (if idlwave-use-last-hang-indent
3455 (if (re-search-backward
3456 idlwave-hang-indent-regexp
3457 (save-excursion (beginning-of-line) (point))
3459 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3462 (if (re-search-forward
3463 idlwave-hang-indent-regexp
3464 (save-excursion (end-of-line) (point))
3466 (current-column)))))
3468 (defun idlwave-auto-fill ()
3469 "Called to break lines in auto fill mode.
3470 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3471 non-nil. Places a continuation character at the end of the line if
3472 not in a comment. Splits strings with IDL concatenation operator `+'
3473 if `idlwave-auto-fill-split-string' is non-nil."
3474 (if (<= (current-column) fill-column
)
3475 nil
; do not to fill
3476 (if (or (not idlwave-fill-comment-line-only
)
3478 ;; Check for comment line
3480 (looking-at idlwave-comment-line-start-skip
)))
3482 (idlwave-indent-line)
3483 ;; Prevent actions do-auto-fill which calls indent-line-function.
3484 (let (idlwave-do-actions
3485 (paragraph-separate ".")
3486 (fill-nobreak-predicate
3487 (if (and (idlwave-in-quote)
3488 idlwave-auto-fill-split-string
)
3489 (lambda () ;; We'll need 5 spaces for " ' + $"
3490 (<= (- fill-column
(current-column)) 5)
3495 ;; Indent the split line
3496 (idlwave-indent-line))
3499 (looking-at idlwave-comment-line-start-skip
))
3500 ;; A continued line comment
3501 ;; We treat continued line comments as part of a comment
3502 ;; paragraph. So we check for a hanging indent.
3503 (if idlwave-hanging-indent
3504 (let ((here (- (point-max) (point)))
3508 (idlwave-calc-hanging-indent))))
3511 ;; Remove whitespace between comment delimiter and
3512 ;; text, insert spaces for appropriate indentation.
3516 (save-excursion (end-of-line) (point)) t
)
3517 (delete-horizontal-space)
3518 (idlwave-indent-to indent
)
3519 (goto-char (- (point-max) here
)))
3521 ;; Split code or comment?
3524 (idlwave-in-comment))
3525 ;; Splitting a non-full-line comment.
3526 ;; Insert the comment delimiter from split line
3530 (skip-chars-forward " \t")
3531 ;; Insert blank to keep off beginning of line
3535 (buffer-substring (idlwave-goto-comment)
3537 (skip-chars-forward "; ")
3539 (idlwave-indent-line))
3540 ;; Split code line - add continuation character
3543 ;; Check to see if we split a string
3544 (if (and (setq beg
(idlwave-in-quote))
3545 idlwave-auto-fill-split-string
)
3546 ;; Split the string and concatenate.
3547 ;; The first extra space is for the space
3548 ;; the line was split. That space was removed.
3549 (insert " " (char-after beg
) " +"))
3552 (if idlwave-auto-fill-split-string
3553 ;; Make the second part of continued string
3556 (skip-chars-forward " \t")
3557 (insert (char-after beg
)))
3560 (message "Warning: continuation inside a string.")))
3561 ;; Although do-auto-fill (via indent-new-comment-line) calls
3562 ;; idlwave-indent-line for the new line, re-indent again
3563 ;; because of the addition of the continuation character.
3564 (idlwave-indent-line))
3567 (defun idlwave-auto-fill-mode (arg)
3568 "Toggle auto-fill mode for IDL mode.
3569 With arg, turn auto-fill mode on if arg is positive.
3570 In auto-fill mode, inserting a space at a column beyond `fill-column'
3571 automatically breaks the line at a previous space."
3573 (prog1 (set idlwave-fill-function
3575 (not (symbol-value idlwave-fill-function
))
3576 (> (prefix-numeric-value arg
) 0))
3580 (set-buffer-modified-p (buffer-modified-p))))
3582 ;(defun idlwave-fill-routine-call ()
3583 ; "Fill a routine definition or statement, indenting appropriately."
3584 ; (let ((where (idlwave-where)))))
3587 (defun idlwave-doc-header (&optional nomark
)
3588 "Insert a documentation header at the beginning of the unit.
3589 Inserts the value of the variable idlwave-file-header. Sets mark before
3590 moving to do insertion unless the optional prefix argument NOMARK
3593 (or nomark
(push-mark))
3594 ;; make sure we catch the current line if it begins the unit
3595 (if idlwave-header-to-beginning-of-file
3596 (goto-char (point-min))
3598 (idlwave-beginning-of-subprogram)
3600 ;; skip function or procedure line
3601 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3603 (idlwave-end-of-statement)
3604 (if (> (forward-line 1) 0) (insert "\n")))))
3605 (let ((pos (point)))
3606 (if idlwave-file-header
3607 (cond ((car idlwave-file-header
)
3608 (insert-file-contents (car idlwave-file-header
)))
3609 ((stringp (car (cdr idlwave-file-header
)))
3610 (insert (car (cdr idlwave-file-header
))))))
3613 (defun idlwave-default-insert-timestamp ()
3614 "Default timestamp insertion function"
3615 (insert (current-time-string))
3616 (insert ", " (user-full-name))
3617 (if (boundp 'user-mail-address
)
3618 (insert " <" user-mail-address
">")
3619 (insert " <" (user-login-name) "@" (system-name) ">"))
3620 ;; Remove extra spaces from line
3621 (idlwave-fill-paragraph)
3622 ;; Insert a blank line comment to separate from the date entry -
3623 ;; will keep the entry from flowing onto date line if re-filled.
3624 (insert "\n;\n;\t\t"))
3626 (defun idlwave-doc-modification ()
3627 "Insert a brief modification log at the beginning of the current program.
3628 Looks for an occurrence of the value of user variable
3629 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3630 and places the point for the user to add a log. Before moving, saves
3631 location on mark ring so that the user can return to previous point."
3635 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3637 (goto-char (point-min))
3638 (re-search-forward idlwave-doclib-start nil t
)))
3639 (setq beg
(match-beginning 0))
3640 (re-search-forward idlwave-doclib-end nil t
)
3641 (setq end
(match-end 0)))
3644 (if (re-search-forward
3645 (concat idlwave-doc-modifications-keyword
":")
3650 (insert "\n" comment-start
"\n")
3651 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3653 (run-hooks 'idlwave-timestamp-hook
))
3654 (error "No valid DOCLIB header"))))
3658 ;;; Interface to expand-region-abbrevs which did not work when the
3659 ;;; abbrev hook associated with an abbrev moves point backwards
3660 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3661 ;;; The original would enter an infinite loop in attempting to expand
3662 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3663 ;;; because the point would keep going back to the beginning of the
3664 ;;; abbrev instead of to the end of the abbrev). We now keep the
3665 ;;; abbrev hook from moving backwards.
3667 (defun idlwave-expand-region-abbrevs (start end
)
3668 "Expand each abbrev occurrence in the region.
3669 Calling from a program, arguments are START END."
3672 (goto-char (min start end
))
3673 (let ((idlwave-show-block nil
) ;Do not blink
3674 (idlwave-abbrev-move nil
)) ;Do not move
3675 (expand-region-abbrevs start end
'noquery
))))
3677 (defun idlwave-quoted ()
3678 "Returns t if point is in a comment or quoted string.
3680 (or (idlwave-in-comment) (idlwave-in-quote)))
3682 (defun idlwave-in-quote ()
3683 "Returns location of the opening quote
3684 if point is in a IDL string constant, nil otherwise.
3685 Ignores comment delimiters on the current line.
3686 Properly handles nested quotation marks and octal
3687 constants - a double quote followed by an octal digit."
3688 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3689 ;;; double quote followed by an octal digit to be an octal constant
3690 ;;; rather than a string. Therefore, there is no terminating double
3693 ;; Because single and double quotes can quote each other we must
3694 ;; search for the string start from the beginning of line.
3695 (let* ((start (point))
3696 (eol (progn (end-of-line) (point)))
3697 (bq (progn (beginning-of-line) (point)))
3702 (while (< endq start
)
3703 ;; Find string start
3704 ;; Don't find an octal constant beginning with a double quote
3705 (if (re-search-forward "[\"']" eol
'lim
)
3706 ;; Find the string end.
3707 ;; In IDL, two consecutive delimiters after the start of a
3709 ;; escape for the delimiter in the string.
3710 ;; Two consecutive delimiters alone (i.e., not after the
3711 ;; start of a string) is the null string.
3713 ;; Move to position after quote
3714 (goto-char (1+ (match-beginning 0)))
3715 (setq bq
(1- (point)))
3716 ;; Get the string delimiter
3717 (setq delim
(char-to-string (preceding-char)))
3718 ;; Check for null string
3719 (if (looking-at delim
)
3720 (progn (setq endq
(point)) (forward-char 1))
3721 ;; Look for next unpaired delimiter
3722 (setq found
(search-forward delim eol
'lim
))
3723 (while (looking-at delim
)
3725 (setq found
(search-forward delim eol
'lim
)))
3727 (setq endq
(- (point) 1))
3728 (setq endq
(point)))
3730 (progn (setq bq
(point)) (setq endq
(point)))))
3731 (store-match-data data
)
3732 ;; return string beginning position or nil
3733 (if (> start bq
) bq
))))
3735 (defun idlwave-is-pointer-dereference (&optional limit
)
3736 "Determines if the character after point is a pointer dereference *."
3737 (let ((pos (point)))
3739 (eq (char-after) ?\
*)
3740 (not (idlwave-in-quote))
3743 (re-search-backward (concat "\\(" idlwave-idl-keywords
3744 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3747 ;; Statement templates
3749 ;; Replace these with a general template function, something like
3750 ;; expand.el (I think there was also something with a name similar to
3753 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3754 "Build a template with optional prompt expression.
3756 Opens a line if point is not followed by a newline modulo intervening
3757 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3758 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3759 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3760 PROMPT is a string then it is displayed as a message in the
3761 minibuffer. The PROMPT serves as a reminder to the user of an
3762 expression to enter.
3764 The lines containing S1 and S2 are reindented using `indent-region'
3765 unless the optional second argument NOINDENT is non-nil."
3766 (if (eq major-mode
'idlwave-shell-mode
)
3767 ;; This is a gross hack to avoit template abbrev expansion
3768 ;; in the shell. FIXME: This is a dirty hack.
3769 (if (and (eq this-command
'self-insert-command
)
3770 (equal last-abbrev-location
(point)))
3771 (insert last-abbrev-text
)
3772 (error "No templates in idlwave-shell"))
3773 (cond ((eq idlwave-abbrev-change-case
'down
)
3774 (setq s1
(downcase s1
) s2
(downcase s2
)))
3775 (idlwave-abbrev-change-case
3776 (setq s1
(upcase s1
) s2
(upcase s2
))))
3777 (let ((beg (save-excursion (beginning-of-line) (point)))
3779 (if (not (looking-at "\\s-*\n"))
3786 (indent-region beg end nil
))
3787 (if (stringp prompt
)
3788 (message "%s" prompt
)))))
3790 (defun idlwave-rw-case (string)
3791 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3792 (if idlwave-reserved-word-upcase
3796 (defun idlwave-elif ()
3797 "Build skeleton IDL if-else block."
3800 (idlwave-rw-case "if")
3801 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3802 "Condition expression"))
3804 (defun idlwave-case ()
3805 "Build skeleton IDL case statement."
3808 (idlwave-rw-case "case")
3809 (idlwave-rw-case " of\n\nendcase")
3810 "Selector expression"))
3812 (defun idlwave-switch ()
3813 "Build skeleton IDL switch statement."
3816 (idlwave-rw-case "switch")
3817 (idlwave-rw-case " of\n\nendswitch")
3818 "Selector expression"))
3820 (defun idlwave-for ()
3821 "Build skeleton for loop statment."
3824 (idlwave-rw-case "for")
3825 (idlwave-rw-case " do begin\n\nendfor")
3828 (defun idlwave-if ()
3829 "Build skeleton for loop statment."
3832 (idlwave-rw-case "if")
3833 (idlwave-rw-case " then begin\n\nendif")
3834 "Scalar logical expression"))
3836 (defun idlwave-procedure ()
3839 (idlwave-rw-case "pro")
3840 (idlwave-rw-case "\n\nreturn\nend")
3843 (defun idlwave-function ()
3846 (idlwave-rw-case "function")
3847 (idlwave-rw-case "\n\nreturn\nend")
3850 (defun idlwave-repeat ()
3853 (idlwave-rw-case "repeat begin\n\nendrep until")
3854 (idlwave-rw-case "")
3857 (defun idlwave-while ()
3860 (idlwave-rw-case "while")
3861 (idlwave-rw-case " do begin\n\nendwhile")
3864 (defun idlwave-split-string (string &optional pattern
)
3865 "Return a list of substrings of STRING which are separated by PATTERN.
3866 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3868 (setq pattern
"[ \f\t\n\r\v]+"))
3869 (let (parts (start 0))
3870 (while (string-match pattern string start
)
3871 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3872 start
(match-end 0)))
3873 (nreverse (cons (substring string start
) parts
))))
3875 (defun idlwave-replace-string (string replace_string replace_with
)
3877 (last (length string
))
3880 (while (setq end
(string-match replace_string string start
))
3882 (concat ret_string
(substring string start end
) replace_with
))
3883 (setq start
(match-end 0)))
3884 (setq ret_string
(concat ret_string
(substring string start last
)))))
3886 (defun idlwave-get-buffer-visiting (file)
3887 ;; Return the buffer currently visiting FILE
3889 ((boundp 'find-file-compare-truenames
) ; XEmacs
3890 (let ((find-file-compare-truenames t
))
3891 (get-file-buffer file
)))
3892 ((fboundp 'find-buffer-visiting
) ; Emacs
3893 (find-buffer-visiting file
))
3894 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3896 (defvar idlwave-outlawed-buffers nil
3897 "List of buffer pulled up by idlwave for special reasons.
3898 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3900 (defun idlwave-find-file-noselect (file &optional why
)
3901 ;; Return a buffer visiting file.
3902 (or (idlwave-get-buffer-visiting file
)
3903 (let ((buf (find-file-noselect file
)))
3904 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3907 (defun idlwave-kill-autoloaded-buffers ()
3908 "Kill buffers created automatically by IDLWAVE.
3909 Function prompts for a letter to identify the buffers to kill.
3910 Possible letters are:
3912 f Buffers created by the command \\[idlwave-find-module] or mouse
3913 clicks in the routine info window.
3914 s Buffers created by the IDLWAVE Shell to display where execution
3915 stopped or an error was found.
3916 a Both of the above.
3918 Buffer containing unsaved changes require confirmation before they are killed."
3920 (if (null idlwave-outlawed-buffers
)
3921 (error "No IDLWAVE-created buffers available")
3922 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3923 (idlwave-count-outlawed-buffers 'find
)
3924 (idlwave-count-outlawed-buffers 'shell
)))
3925 (let ((c (read-char)))
3927 ((member c
'(?f ?\C-f
))
3928 (idlwave-do-kill-autoloaded-buffers 'find
))
3929 ((member c
'(?s ?\C-s
))
3930 (idlwave-do-kill-autoloaded-buffers 'shell
))
3931 ((member c
'(?a ?\C-a
))
3932 (idlwave-do-kill-autoloaded-buffers t
))
3933 (t (error "Abort"))))))
3935 (defun idlwave-count-outlawed-buffers (tag)
3936 "How many outlawed buffers have tag TAG?"
3939 (lambda (x) (eq (cdr x
) tag
))
3940 idlwave-outlawed-buffers
))))
3942 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3943 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3944 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3947 (while (setq entry
(pop list
))
3948 (if (buffer-live-p (car entry
))
3949 (and (or (memq t reasons
)
3950 (memq (cdr entry
) reasons
))
3951 (kill-buffer (car entry
))
3953 (setq idlwave-outlawed-buffers
3954 (delq entry idlwave-outlawed-buffers
)))
3955 (setq idlwave-outlawed-buffers
3956 (delq entry idlwave-outlawed-buffers
))))
3957 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3959 (defun idlwave-revoke-license-to-kill ()
3960 "Remove BUFFER from the buffers which may be killed.
3961 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3962 Intended for `after-save-hook'."
3963 (let* ((buf (current-buffer))
3964 (entry (assq buf idlwave-outlawed-buffers
)))
3967 (setq idlwave-outlawed-buffers
3968 (delq entry idlwave-outlawed-buffers
)))
3969 ;; Remove this function from the hook.
3970 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3972 (defvar idlwave-path-alist
)
3973 (defun idlwave-locate-lib-file (file)
3974 ;; Find FILE on the scanned lib path and return a buffer visiting it
3975 (let* ((dirs idlwave-path-alist
)
3978 (while (setq dir
(car (pop dirs
)))
3980 (setq efile
(expand-file-name file dir
)))
3981 (throw 'exit efile
))))))
3983 (defun idlwave-expand-lib-file-name (file)
3984 ;; Find FILE on the scanned lib path and return a buffer visiting it
3985 ;; This is for, e.g., finding source with no user catalog
3988 ((file-name-absolute-p file
) file
)
3989 (t (idlwave-locate-lib-file file
))))
3991 (defun idlwave-make-tags ()
3992 "Creates the IDL tags file IDLTAGS in the current directory from
3993 the list of directories specified in the minibuffer. Directories may be
3994 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3995 specified top directories are searched if the directory name is prefixed
3996 by @. Specify @ directories with care, it may take a long, long time if
3999 (let (directory directories cmd append status numdirs dir getsubdirs
4000 buffer save_buffer files numfiles item errbuf
)
4003 ;; Read list of directories
4004 (setq directory
(read-string "Tag Directories: " "."))
4005 (setq directories
(idlwave-split-string directory
"[ \t]+"))
4007 ;; Set etags command, vars
4008 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
4009 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4010 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4014 ;; For each directory
4016 (setq dir
(nth numdirs directories
))
4019 ;; Find the subdirectories
4020 (if (string-match "^[@]\\(.+\\)$" dir
)
4021 (setq getsubdirs t
) (setq getsubdirs nil
))
4022 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
4023 (setq dir
(expand-file-name dir
))
4024 (if (file-directory-p dir
)
4026 (if (and getsubdirs
)
4028 (setq buffer
(get-buffer-create "*idltags*"))
4029 (call-process "sh" nil buffer nil
"-c"
4030 (concat "find " dir
" -type d -print"))
4031 (setq save_buffer
(current-buffer))
4033 (setq files
(idlwave-split-string
4034 (idlwave-replace-string
4035 (buffer-substring 1 (point-max))
4038 (set-buffer save_buffer
)
4039 (kill-buffer buffer
))
4040 (setq files
(list (concat dir
"/*.pro"))))
4042 ;; For each subdirectory
4044 (setq item
(nth numfiles files
))
4048 (if (not (string-match "^[ \\t]*$" item
))
4050 (message "%s" (concat "Tagging " item
"..."))
4051 (setq errbuf
(get-buffer-create "*idltags-error*"))
4052 (setq status
(+ status
4053 (if (eq 0 (call-process
4054 "sh" nil errbuf nil
"-c"
4055 (concat cmd append item
)))
4059 ;; Append additional tags
4060 (setq append
" --append ")
4061 (setq numfiles
(1+ numfiles
))
4062 (setq item
(nth numfiles files
)))
4064 (setq numfiles
(1+ numfiles
))
4065 (setq item
(nth numfiles files
))
4068 (setq numdirs
(1+ numdirs
))
4069 (setq dir
(nth numdirs directories
)))
4071 (setq numdirs
(1+ numdirs
))
4072 (setq dir
(nth numdirs directories
)))))
4074 (setq errbuf
(get-buffer-create "*idltags-error*"))
4076 (kill-buffer errbuf
))
4080 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4081 "Comment the lines in the region if the first non-blank line is
4082 commented, and conversely, uncomment region. If optional prefix arg
4083 N is non-nil, then for N positive, add N comment delimiters or for N
4084 negative, remove N comment delimiters.
4085 Uses `comment-region' which does not place comment delimiters on
4087 (interactive "r\nP")
4089 (comment-region beg end
(prefix-numeric-value n
))
4094 (skip-chars-forward " \t\n")
4095 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4096 (if (fboundp 'uncomment-region
)
4097 (uncomment-region beg end
)
4098 (comment-region beg end
4099 (- (length (buffer-substring
4102 (comment-region beg end
)))))
4105 ;; ----------------------------------------------------------------------------
4106 ;; ----------------------------------------------------------------------------
4107 ;; ----------------------------------------------------------------------------
4108 ;; ----------------------------------------------------------------------------
4110 ;; Completion and Routine Info
4113 ;; String "intern" functions
4115 ;; For the completion and routine info function, we want to normalize
4116 ;; the case of procedure names etc. We do this by "interning" these
4117 ;; string is a hand-crafted way. Hashes are used to map the downcase
4118 ;; version of the strings to the cased versions. Most *-sint-*
4119 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4120 ;; system hash. The former is re-scanned, and the latter takes case
4123 ;; Since these cased versions are really lisp objects, we can use `eq'
4124 ;; to search, which is a large performance boost. All new strings
4125 ;; need to be "sinterned". We do this as early as possible after
4126 ;; getting these strings from completion or buffer substrings. So
4127 ;; most of the code can simply assume to deal with "sinterned"
4128 ;; strings. The only exception is that the functions which scan whole
4129 ;; buffers for routine information do not intern the grabbed strings.
4130 ;; This is only done afterwards. Therefore in these functions it is
4131 ;; *not* safe to assume the strings can be compared with `eq' and be
4132 ;; fed into the routine assq functions.
4134 ;; Here we define the hashing functions.
4136 ;; The variables which hold the hashes.
4137 (defvar idlwave-sint-routines
'(nil))
4138 (defvar idlwave-sint-keywords
'(nil))
4139 (defvar idlwave-sint-methods
'(nil))
4140 (defvar idlwave-sint-classes
'(nil))
4141 (defvar idlwave-sint-dirs
'(nil))
4142 (defvar idlwave-sint-libnames
'(nil))
4144 (defun idlwave-reset-sintern (&optional what
)
4145 "Reset all sintern hashes."
4146 ;; Make sure the hash functions are accessible.
4147 (if (or (not (fboundp 'gethash
))
4148 (not (fboundp 'puthash
)))
4151 (or (fboundp 'puthash
)
4152 (defalias 'puthash
'cl-puthash
))))
4153 (let ((entries '((idlwave-sint-routines 1000 10)
4154 (idlwave-sint-keywords 1000 10)
4155 (idlwave-sint-methods 100 10)
4156 (idlwave-sint-classes 10 10))))
4158 ;; Make sure these are lists
4159 (loop for entry in entries
4160 for var
= (car entry
)
4161 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4163 ;; Reset the system & library hash
4164 (when (or (eq what t
) (eq what
'syslib
)
4165 (null (cdr idlwave-sint-routines
)))
4166 (loop for entry in entries
4167 for var
= (car entry
) for size
= (nth 1 entry
)
4168 do
(setcdr (symbol-value var
)
4169 (make-hash-table ':size size
':test
'equal
)))
4170 (setq idlwave-sint-dirs nil
4171 idlwave-sint-libnames nil
))
4173 ;; Reset the buffer & shell hash
4174 (when (or (eq what t
) (eq what
'bufsh
)
4175 (null (car idlwave-sint-routines
)))
4176 (loop for entry in entries
4177 for var
= (car entry
) for size
= (nth 1 entry
)
4178 do
(setcar (symbol-value var
)
4179 (make-hash-table ':size size
':test
'equal
))))))
4181 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4183 (idlwave-sintern-method name set
)
4184 (idlwave-sintern-routine name set
)))
4186 (defun idlwave-sintern (stype &rest args
)
4187 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4189 ;;(defmacro idlwave-sintern (type var)
4190 ;; `(cond ((not (stringp name)) name)
4191 ;; ((gethash (downcase name) (cdr ,var)))
4192 ;; ((gethash (downcase name) (car ,var)))
4193 ;; (set (idlwave-sintern-set name ,type ,var set))
4196 (defun idlwave-sintern-routine (name &optional set
)
4197 (cond ((not (stringp name
)) name
)
4198 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4199 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4200 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4202 (defun idlwave-sintern-keyword (name &optional set
)
4203 (cond ((not (stringp name
)) name
)
4204 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4205 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4206 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4208 (defun idlwave-sintern-method (name &optional set
)
4209 (cond ((not (stringp name
)) name
)
4210 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4211 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4212 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4214 (defun idlwave-sintern-class (name &optional set
)
4215 (cond ((not (stringp name
)) name
)
4216 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4217 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4218 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4221 (defun idlwave-sintern-dir (dir &optional set
)
4222 (car (or (member dir idlwave-sint-dirs
)
4223 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4224 (defun idlwave-sintern-libname (name &optional set
)
4225 (car (or (member name idlwave-sint-libnames
)
4226 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4228 (defun idlwave-sintern-set (name type tables set
)
4229 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4231 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4232 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4233 (puthash (downcase name
) iname table
)
4236 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4237 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4239 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4243 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4244 "Sintern all strings in the rinfo LIST. With optional parameter
4245 SET: also set new patterns. Probably this will always have to be t.
4246 If DEFAULT-DIR is passed, it is used as the base of the directory"
4247 (let (entry name type class kwds res source call new
)
4249 (setq entry
(car list
)
4254 source
(nth 3 entry
)
4256 kwds
(nthcdr 5 entry
))
4258 ;; The class and name
4261 (if (symbolp class
) (setq class
(symbol-name class
)))
4262 (setq class
(idlwave-sintern-class class set
))
4263 (setq name
(idlwave-sintern-method name set
)))
4264 (setq name
(idlwave-sintern-routine name set
)))
4267 (let ((source-type (car source
))
4268 (source-file (nth 1 source
))
4269 (source-dir (if default-dir
4270 (file-name-as-directory default-dir
)
4272 (source-lib (nth 3 source
)))
4273 (if (stringp source-dir
)
4274 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4275 (if (stringp source-lib
)
4276 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4277 (setq source
(list source-type source-file source-dir source-lib
)))
4280 (setq kwds
(mapcar (lambda (x)
4281 (idlwave-sintern-keyword-list x set
))
4284 ;; Build a canonicalized list
4285 (setq new
(nconc (list name type class source call
) kwds
)
4286 res
(cons new res
)))
4289 ;; Creating new sintern tables
4291 (defun idlwave-new-sintern-type (tag)
4292 "Define a variable and a function to sintern the new type TAG.
4293 This defines the function `idlwave-sintern-TAG' and the variable
4294 `idlwave-sint-TAGs'."
4295 (let* ((name (symbol-name tag
))
4296 (names (concat name
"s"))
4297 (var (intern (concat "idlwave-sint-" names
)))
4298 (func (intern (concat "idlwave-sintern-" name
))))
4299 (set var nil
) ; initial value of the association list
4300 (fset func
; set the function
4301 `(lambda (name &optional set
)
4302 (cond ((not (stringp name
)) name
)
4303 ((cdr (assoc (downcase name
) ,var
)))
4305 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4309 (defun idlwave-reset-sintern-type (tag)
4310 "Reset the sintern variable associated with TAG."
4311 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4313 ;;---------------------------------------------------------------------------
4316 ;; The variables which hold the information
4317 (defvar idlwave-system-routines nil
4318 "Holds the routine-info obtained by scanning buffers.")
4319 (defvar idlwave-buffer-routines nil
4320 "Holds the routine-info obtained by scanning buffers.")
4321 (defvar idlwave-compiled-routines nil
4322 "Holds the routine-info obtained by asking the shell.")
4323 (defvar idlwave-unresolved-routines nil
4324 "Holds the unresolved routine-info obtained by asking the shell.")
4325 (defvar idlwave-user-catalog-routines nil
4326 "Holds the procedure routine-info from the user scan.")
4327 (defvar idlwave-library-catalog-routines nil
4328 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4329 (defvar idlwave-library-catalog-libname nil
4330 "Name of library catalog loaded from .idlwave_catalog files.")
4331 (defvar idlwave-path-alist nil
4332 "Alist with !PATH directories and zero or more flags if the dir has
4333 been scanned in a user catalog ('user) or discovered in a library
4335 (defvar idlwave-true-path-alist nil
4336 "Like `idlwave-path-alist', but with true filenames.")
4337 (defvar idlwave-routines nil
4338 "Holds the combined procedure/function/method routine-info.")
4339 (defvar idlwave-class-alist nil
4340 "Holds the class names known to IDLWAVE.")
4341 (defvar idlwave-class-history nil
4342 "The history of classes selected with the minibuffer.")
4343 (defvar idlwave-force-class-query nil
)
4344 (defvar idlwave-before-completion-wconf nil
4345 "The window configuration just before the completion buffer was displayed.")
4346 (defvar idlwave-last-system-routine-info-cons-cell nil
4347 "The last cons cell in the system routine info.")
4350 ;; The code to get routine info from different sources.
4352 (defvar idlwave-system-routines
)
4353 (defvar idlwave-catalog-process nil
4354 "The background process currently updating the catalog.")
4356 (defun idlwave-routines ()
4357 "Provide a list of IDL routines.
4358 This routine loads the builtin routines on the first call. Later it
4359 only returns the value of the variable."
4360 (if (and idlwave-catalog-process
4361 (processp idlwave-catalog-process
))
4364 ((equal (process-status idlwave-catalog-process
) 'exit
)
4365 (message "updating........")
4366 (setq idlwave-catalog-process nil
)
4367 (idlwave-update-routine-info '(4)))
4368 ((equal (process-status idlwave-catalog-process
) 'run
)
4369 ;; Keep it running...
4372 ;; Something is wrong, get rid of the process
4373 (message "Problem with catalog process") (beep)
4375 (kill-process idlwave-catalog-process
)
4377 (setq idlwave-catalog-process nil
)))))
4378 (or idlwave-routines
4380 (idlwave-update-routine-info)
4381 ;; return the current value
4384 (defvar idlwave-update-rinfo-hook nil
4385 "List of functions which should run after a global rinfo update.
4386 Does not run after automatic updates of buffer or the shell.")
4388 (defun idlwave-rescan-catalog-directories ()
4389 "Rescan the previously selected directories. For batch processing."
4390 (idlwave-update-routine-info '(16)))
4392 (defun idlwave-rescan-asynchronously ()
4393 "Dispatch another Emacs instance to update the idlwave catalog.
4394 After the process finishes normally, the first access to routine info
4395 will re-read the catalog."
4397 (if (processp idlwave-catalog-process
)
4398 (if (eq (process-status idlwave-catalog-process
) 'run
)
4399 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4402 (kill-process idlwave-catalog-process
)
4404 (error "Process killed, no new process started"))
4407 (kill-process idlwave-catalog-process
)
4409 (if (or (not idlwave-user-catalog-file
)
4410 (not (stringp idlwave-user-catalog-file
))
4411 (not (file-regular-p idlwave-user-catalog-file
)))
4412 (error "No catalog has been produced yet"))
4413 (let* ((emacs (concat invocation-directory invocation-name
))
4414 (args (list "-batch"
4415 "-l" (expand-file-name "~/.emacs")
4417 "-f" "idlwave-rescan-catalog-directories"))
4418 (process (apply 'start-process
"idlcat"
4420 (setq idlwave-catalog-process process
)
4421 (set-process-sentinel
4424 (when (string-match "finished" why
)
4425 (setq idlwave-routines nil
4426 idlwave-system-routines nil
4427 idlwave-catalog-process nil
)
4428 (or (idlwave-start-load-rinfo-timer)
4429 (idlwave-update-routine-info '(4))))))
4430 (message "Background job started to update catalog file")))
4433 ;; Format for all routine info user catalog, library catalogs, etc.:
4435 ;; ("ROUTINE" type class
4436 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4437 ;; (buffer pro_file dir) | (compiled pro_file dir)
4438 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4439 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4441 ;; DIR will be supplied dynamically while loading library catalogs,
4442 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4443 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4444 ;; be nil, as can LINK1, etc., if no HTML help is available.
4447 (defvar idlwave-load-rinfo-idle-timer
)
4448 (defvar idlwave-shell-path-query
)
4450 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4451 "Update the internal routine-info lists.
4452 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4453 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4454 about individual routines.
4456 The information can come from 4 sources:
4457 1. IDL programs in the current editing session
4458 2. Compiled modules in an IDL shell running as Emacs subprocess
4459 3. A list which covers the IDL system routines.
4460 4. A list which covers the prescanned library files.
4462 Scans all IDLWAVE-mode buffers of the current editing session (see
4463 `idlwave-scan-all-buffers-for-routine-info').
4464 When an IDL shell is running, this command also queries the IDL program
4465 for currently compiled routines.
4467 With prefix ARG, also reload the system and library lists.
4468 With two prefix ARG's, also rescans the chosen user catalog tree.
4469 With three prefix args, dispatch asynchronous process to do the update.
4471 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4472 lists, but instead wait for the shell query to complete and
4473 asynchronously finish updating routine info. This is set
4474 automatically when called interactively. When you need routine
4475 information updated immediately, leave NO-CONCATENATE nil."
4476 (interactive "P\np")
4477 ;; Stop any idle processing
4478 (if (or (and (fboundp 'itimerp
)
4479 (itimerp idlwave-load-rinfo-idle-timer
))
4480 (and (fboundp 'timerp
)
4481 (timerp idlwave-load-rinfo-idle-timer
)))
4482 (cancel-timer idlwave-load-rinfo-idle-timer
))
4485 ;; Start a background process which updates the catalog.
4486 (idlwave-rescan-asynchronously))
4488 ;; Update the user catalog now, and wait for them.
4489 (idlwave-create-user-catalog-file t
))
4491 (let* ((load (or arg
4492 idlwave-buffer-case-takes-precedence
4493 (null idlwave-routines
)))
4494 ;; The override-idle means, even if the idle timer has done some
4495 ;; preparing work, load and renormalize everything anyway.
4496 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4498 (setq idlwave-buffer-routines nil
4499 idlwave-compiled-routines nil
4500 idlwave-unresolved-routines nil
)
4501 ;; Reset the appropriate hashes
4502 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4503 ;; reset was already done in idle time, so skip this step now once
4504 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4505 (idlwave-reset-sintern (cond (load t
)
4506 ((null idlwave-system-routines
) t
)
4509 (if idlwave-buffer-case-takes-precedence
4510 ;; We can safely scan the buffer stuff first
4512 (idlwave-update-buffer-routine-info)
4513 (and load
(idlwave-load-all-rinfo override-idle
)))
4514 ;; We first do the system info, and then the buffers
4515 (and load
(idlwave-load-all-rinfo override-idle
))
4516 (idlwave-update-buffer-routine-info))
4518 ;; Let's see if there is a shell
4519 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4520 (idlwave-shell-is-running)))
4521 (ask-shell (and shell-is-running
4522 idlwave-query-shell-for-routine-info
)))
4524 ;; Load the library catalogs again, first re-scanning the path
4526 (if shell-is-running
4527 (idlwave-shell-send-command idlwave-shell-path-query
4529 (idlwave-shell-get-path-info)
4530 (idlwave-scan-library-catalogs))
4532 (idlwave-scan-library-catalogs)))
4534 (if (or (not ask-shell
)
4535 (not no-concatenate
))
4536 ;; 1. If we are not going to ask the shell, we need to do the
4537 ;; concatenation now.
4538 ;; 2. When this function is called non-interactively, it
4539 ;; means that someone needs routine info *now*. The
4540 ;; shell update causes the concatenation to be
4541 ;; *delayed*, so not in time for the current command.
4542 ;; Therefore, we do a concatenation now, even though
4543 ;; the shell might do it again.
4544 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4547 ;; Ask the shell about the routines it knows of.
4548 (message "Querying the shell")
4549 (idlwave-shell-update-routine-info nil t
)))))))
4552 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4553 (defvar idlwave-load-rinfo-idle-timer nil
)
4554 (defun idlwave-start-load-rinfo-timer ()
4555 (if (or (and (fboundp 'itimerp
)
4556 (itimerp idlwave-load-rinfo-idle-timer
))
4557 (and (fboundp 'timerp
)
4558 (timerp idlwave-load-rinfo-idle-timer
)))
4559 (cancel-timer idlwave-load-rinfo-idle-timer
))
4560 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4561 (setq idlwave-load-rinfo-idle-timer nil
)
4562 (if (and idlwave-init-rinfo-when-idle-after
4563 (numberp idlwave-init-rinfo-when-idle-after
)
4564 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4565 (not idlwave-routines
))
4568 (setq idlwave-load-rinfo-idle-timer
4569 (run-with-idle-timer
4570 idlwave-init-rinfo-when-idle-after
4571 nil
'idlwave-load-rinfo-next-step
)))
4574 (defvar idlwave-library-routines nil
"Obsolete variable.")
4576 ;;------ XML Help routine info system
4577 (defun idlwave-load-system-routine-info ()
4578 ;; Load the system routine info from the cached routine info file,
4579 ;; which, if necessary, will be re-created from the XML file on
4580 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4581 ;; file distributed with older IDLWAVE versions (<6.0)
4582 (unless (and (load idlwave-xml-system-rinfo-converted-file
4583 'noerror
'nomessage
)
4584 (idlwave-xml-system-routine-info-up-to-date))
4585 ;; See if we can create it from XML source
4587 (idlwave-convert-xml-system-routine-info)
4589 (unless (load idlwave-xml-system-rinfo-converted-file
4590 'noerror
'nomessage
)
4591 (if idlwave-system-routines
4593 "Failed to load converted routine info, using old conversion.")
4595 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4596 (if (not (load "idlw-rinfo" 'noerror
'nomessage
))
4598 "Could not locate any system routine information."))))))))
4600 (defun idlwave-xml-system-routine-info-up-to-date()
4601 (let* ((dir (file-name-as-directory
4602 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4603 (catalog-file (expand-file-name "idl_catalog.xml" dir
)))
4604 (file-newer-than-file-p ;converted file is newer than catalog
4605 idlwave-xml-system-rinfo-converted-file
4608 (defvar idlwave-system-class-info nil
) ; Gathered from idlw-rinfo
4609 (defvar idlwave-system-variables-alist nil
4610 "Alist of system variables and the associated structure tags.
4611 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4612 (defvar idlwave-executive-commands-alist nil
4613 "Alist of system variables and their help files.")
4614 (defvar idlwave-help-special-topic-words nil
)
4617 (defun idlwave-shorten-syntax (syntax name
&optional class
)
4618 ;; From a list of syntax statments, shorten with %s and group with "or"
4619 (let ((case-fold-search t
))
4622 (while (string-match name x
)
4623 (setq x
(replace-match "%s" t t x
)))
4625 (while (string-match class x
)
4626 (setq x
(replace-match "%s" t t x
))))
4631 (defun idlwave-xml-create-class-method-lists (xml-entry)
4632 ;; Create a class list entry from the xml parsed list., returning a
4633 ;; cons of form (class-entry method-entries).
4634 (let* ((nameblock (nth 1 xml-entry
))
4635 (class (cdr (assq 'name nameblock
)))
4636 (link (cdr (assq 'link nameblock
)))
4637 (params (cddr xml-entry
))
4638 (case-fold-search t
)
4640 method methods-entry extra-kwds
4641 props get-props set-props init-props inherits
4644 (setq pelem
(car params
))
4646 (setq ptype
(car pelem
)
4647 props
(car (cdr pelem
)))
4649 ((eq ptype
'SUPERCLASS
)
4650 (let ((pname (cdr (assq 'name props
)))
4651 (plink (cdr (assq 'link props
))))
4652 (unless (and (string= pname
"None")
4653 (string= plink
"None"))
4654 (push pname inherits
))))
4656 ((eq ptype
'PROPERTY
)
4657 (let ((pname (cdr (assq 'name props
)))
4658 (plink (cdr (assq 'link props
)))
4659 (get (string= (cdr (assq 'get props
)) "Yes"))
4660 (set (string= (cdr (assq 'set props
)) "Yes"))
4661 (init (string= (cdr (assq 'init props
)) "Yes")))
4662 (if get
(push (list pname plink
) get-props
))
4663 (if set
(push (list pname plink
) set-props
))
4664 (if init
(push (list pname plink
) init-props
))))
4667 (setq method
(cdr (assq 'name props
)))
4668 (setq extra-kwds
;;Assume all property keywords are gathered already
4670 ((string-match (concat class
"::Init") method
)
4671 (put 'init-props
'matched t
)
4673 ((string-match (concat class
"::GetProperty") method
)
4674 (put 'get-props
'matched t
)
4676 ((string-match (concat class
"::SetProperty") method
)
4677 (put 'set-props
'matched t
)
4681 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds
)
4684 (setq params
(cdr params
)))
4685 ;(unless (get 'init-props 'matched)
4686 ; (message "Failed to match Init in class %s" class))
4687 ;(unless (get 'get-props 'matched)
4688 ; (message "Failed to match GetProperty in class %s" class))
4689 ;(unless (get 'set-props 'matched)
4690 ; (message "Failed to match SetProperty in class %s" class))
4693 (list class
(append '(inherits) inherits
) (list 'link link
))
4694 (list class
(list 'link link
))))
4695 (cons class-entry methods-entry
)))
4697 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws
)
4698 ;; Create correctly structured list elements from ROUTINE or METHOD
4699 ;; XML list structures. Return a list of list elements, with more
4700 ;; than one sub-list possible if a routine can serve as both
4701 ;; procedure and function (e.g. call_method).
4702 (let* ((nameblock (nth 1 xml-entry
))
4703 (name (cdr (assq 'name nameblock
)))
4704 (link (cdr (assq 'link nameblock
)))
4705 (params (cddr xml-entry
))
4706 (syntax-vec (make-vector 3 nil
)) ; procedure, function, exec command
4707 (case-fold-search t
)
4708 syntax kwd klink pref-list kwds pelem ptype entry props result type
)
4709 (if class
;; strip out class name from class method name string
4710 (if (string-match (concat class
"::") name
)
4711 (setq name
(substring name
(match-end 0)))))
4713 (setq pelem
(car params
))
4715 (setq ptype
(car pelem
)
4716 props
(car (cdr pelem
)))
4719 (setq syntax
(cdr (assq 'name props
)))
4720 (if (string-match "->" syntax
)
4721 (setq syntax
(replace-match "->" t nil syntax
)))
4722 (setq type
(cdr (assq 'type props
)))
4724 (aref syntax-vec
(cond
4725 ((string-match "^pro" type
) 0)
4726 ((string-match "^fun" type
) 1)
4727 ((string-match "^exec" type
) 2)))))
4728 ((eq ptype
'KEYWORD
)
4729 (setq kwd
(cdr (assq 'name props
))
4730 klink
(cdr (assq 'link props
)))
4731 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd
)
4734 (if (match-string 1 kwd
) '("X" "Y" "Z") '("X" "Y"))
4735 kwd
(substring kwd
(match-end 0)))
4736 (loop for x in pref-list do
4737 (push (list (concat x kwd
) klink
) kwds
)))
4738 (push (list kwd klink
) kwds
)))
4740 (t))); Do nothing for the others
4741 (setq params
(cdr params
)))
4744 ; (if (and (null (aref syntax-vec 0))
4745 ; (null (aref syntax-vec 1))
4746 ; (null (aref syntax-vec 2)))
4747 ; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4749 ; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4750 ; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4752 ;; Executive commands are treated specially
4753 (if (aref syntax-vec
2)
4754 (cons (substring name
1) link
)
4755 (if extra-kws
(setq kwds
(nconc kwds extra-kws
)))
4756 (setq kwds
(idlwave-rinfo-group-keywords kwds link
))
4757 (loop for idx from
0 to
1 do
4758 (if (aref syntax-vec idx
)
4759 (push (append (list name
(if (eq idx
0) 'pro
'fun
)
4761 (idlwave-shorten-syntax
4762 (aref syntax-vec idx
) name class
))
4767 (defun idlwave-rinfo-group-keywords (kwds master-link
)
4768 ;; Group keywords by link file, as a list with elements
4769 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4770 (let (kwd link anchor linkfiles block master-elt
)
4772 (setq kwd
(car kwds
)
4773 link
(idlwave-split-link-target (nth 1 kwd
))
4777 (if (setq block
(assoc link linkfiles
))
4778 (push (cons kwd anchor
) (cdr block
))
4779 (push (list link
(cons kwd anchor
)) linkfiles
))
4780 (setq kwds
(cdr kwds
)))
4781 ;; Ensure the master link is there
4782 (if (setq master-elt
(assoc master-link linkfiles
))
4783 (if (eq (car linkfiles
) master-elt
)
4785 (cons master-elt
(delq master-elt linkfiles
)))
4786 (push (list master-link
) linkfiles
))))
4788 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4789 ;; Clean up the syntax of routines which are actually aliases by
4790 ;; removing the "OR" from the statements
4792 (loop for x in aliases do
4793 (setq entry
(assoc x idlwave-system-routines
))
4795 (while (string-match " +or +" (setq syntax
(nth 4 entry
)))
4796 (setf (nth 4 entry
) (replace-match ", " t t syntax
)))))))
4798 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4799 ;; Duplicate and trim original routine aliases from rinfo list
4800 ;; This if for, e.g. OPENR/OPENW/OPENU
4801 (let (alias remove-list new parts all-parts
)
4802 (loop for x in aliases do
4803 (when (setq parts
(split-string (cdr x
) "/"))
4804 (setq new
(assoc (cdr x
) all-parts
))
4806 (setq new
(cons (cdr x
) parts
))
4807 (push new all-parts
))
4808 (setcdr new
(delete (car x
) (cdr new
)))))
4810 ;; Add any missing aliases (separate by slashes)
4811 (loop for x in all-parts do
4813 (push (cons (nth 1 x
) (car x
)) aliases
)))
4815 (loop for x in aliases do
4816 (when (setq alias
(assoc (cdr x
) idlwave-system-routines
))
4817 (unless (memq alias remove-list
) (push alias remove-list
))
4818 (setq alias
(copy-sequence alias
))
4819 (setcar alias
(car x
))
4820 (push alias idlwave-system-routines
)))
4821 (loop for x in remove-list do
4822 (delq x idlwave-system-routines
))))
4824 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4825 ;; Duplicate and trim original routine aliases from rinfo list
4826 ;; This if for, e.g. !X, !Y, !Z.
4827 (let (alias remove-list new parts all-parts
)
4828 (loop for x in aliases do
4829 (when (setq alias
(assoc (cdr x
) idlwave-system-variables-alist
))
4830 (unless (memq alias remove-list
) (push alias remove-list
))
4831 (setq alias
(copy-sequence alias
))
4832 (setcar alias
(car x
))
4833 (push alias idlwave-system-variables-alist
)))
4834 (loop for x in remove-list do
4835 (delq x idlwave-system-variables-alist
))))
4838 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4839 ;; Create a sysvar list entry from the xml parsed list.
4840 (let* ((nameblock (nth 1 xml-entry
))
4841 (name (cdr (assq 'name nameblock
)))
4842 (sysvar (substring name
(progn (string-match "^ *!" name
)
4844 (link (cdr (assq 'link nameblock
)))
4845 (params (cddr xml-entry
))
4846 (case-fold-search t
)
4847 pelem ptype props fields tags
)
4849 (setq pelem
(car params
))
4851 (setq ptype
(car pelem
)
4852 props
(car (cdr pelem
)))
4855 (push (cons (cdr (assq 'name props
))
4857 (idlwave-split-link-target (cdr (assq 'link props
)))))
4859 (setq params
(cdr params
)))
4861 (list sysvar
(if tags
(cons 'tags tags
)) (list 'link link
)))))
4864 (defvar idlwave-xml-routine-info-file nil
)
4866 (defun idlwave-save-routine-info ()
4867 (if idlwave-xml-routine-info-file
4868 (with-temp-file idlwave-xml-system-rinfo-converted-file
4870 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4871 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version
")
4872 ;; Automatically generated from source file:
4873 ;; " idlwave-xml-routine-info-file
"
4874 ;; on " (current-time-string) "
4876 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4877 idlwave-xml-routine-info-file
))
4878 (insert "\n(setq idlwave-system-routines\n '")
4879 (prin1 idlwave-system-routines
(current-buffer))
4881 (insert "\n(setq idlwave-system-variables-alist\n '")
4882 (prin1 idlwave-system-variables-alist
(current-buffer))
4884 (insert "\n(setq idlwave-system-class-info\n '")
4885 (prin1 idlwave-system-class-info
(current-buffer))
4887 (insert "\n(setq idlwave-executive-commands-alist\n '")
4888 (prin1 idlwave-executive-commands-alist
(current-buffer))
4890 (insert "\n(setq idlwave-help-special-topic-words\n '")
4891 (prin1 idlwave-help-special-topic-words
(current-buffer))
4894 (defun idlwave-convert-xml-system-routine-info ()
4895 "Convert XML supplied IDL routine info into internal form.
4896 Cache to disk for quick recovery."
4898 (let* ((dir (file-name-as-directory
4899 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4900 (catalog-file (expand-file-name "idl_catalog.xml" dir
))
4902 props rinfo msg-cnt elem type nelem class-result alias
4903 routines routine-aliases statement-aliases sysvar-aliases
4905 (if (not (file-exists-p catalog-file
))
4906 (error "No such XML routine info file: %s" catalog-file
)
4907 (if (not (file-readable-p catalog-file
))
4908 (error "Cannot read XML routine info file: %s" catalog-file
)))
4910 (message "Reading XML routine info...")
4911 (setq rinfo
(xml-parse-file catalog-file
))
4912 (message "Reading XML routine info...done")
4913 (setq rinfo
(assq 'CATALOG rinfo
))
4914 (unless rinfo
(error "Failed to parse XML routine info"))
4915 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4917 (setq version-string
(cdr (assq 'version
(nth 1 rinfo
)))
4920 (setq nelem
(length rinfo
)
4921 msg-cnt
(/ nelem
20))
4923 (setq idlwave-xml-routine-info-file nil
)
4924 (message "Converting XML routine info...")
4925 (setq idlwave-system-routines nil
4926 idlwave-system-variables-alist nil
4927 idlwave-system-class-info nil
4928 idlwave-executive-commands-alist nil
4929 idlwave-help-special-topic-words nil
)
4932 (setq elem
(car rinfo
)
4936 (setq type
(car elem
)
4937 props
(car (cdr elem
)))
4938 (if (= (mod elem-cnt msg-cnt
) 0)
4939 (message "Converting XML routine info...%2d%%"
4940 (/ (* elem-cnt
100) nelem
)))
4943 (if (setq alias
(assq 'alias_to props
))
4944 (push (cons (cdr (assq 'name props
)) (cdr alias
))
4946 (setq routines
(idlwave-xml-create-rinfo-list elem
))
4947 (if (listp (cdr routines
))
4948 (setq idlwave-system-routines
4949 (nconc idlwave-system-routines routines
))
4950 ;; a cons cell is an executive commands
4951 (push routines idlwave-executive-commands-alist
))))
4954 (setq class-result
(idlwave-xml-create-class-method-lists elem
))
4955 (push (car class-result
) idlwave-system-class-info
)
4956 (setq idlwave-system-routines
4957 (nconc idlwave-system-routines
(cdr class-result
))))
4959 ((eq type
'STATEMENT
)
4960 (push (cons (cdr (assq 'name props
))
4961 (cdr (assq 'link props
)))
4962 idlwave-help-special-topic-words
)
4963 ;; Save the links to those which are statement aliases (not routines)
4964 (if (setq alias
(assq 'alias_to props
))
4965 (unless (member (cdr alias
) statement-aliases
)
4966 (push (cdr alias
) statement-aliases
))))
4969 (if (setq alias
(cdr (assq 'alias_to props
)))
4970 (push (cons (substring (cdr (assq 'name props
)) 1)
4971 (substring alias
1))
4973 (push (idlwave-xml-create-sysvar-alist elem
)
4974 idlwave-system-variables-alist
)))
4976 (idlwave-convert-xml-clean-routine-aliases routine-aliases
)
4977 (idlwave-convert-xml-clean-statement-aliases statement-aliases
)
4978 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases
)
4980 (setq idlwave-xml-routine-info-file catalog-file
)
4981 (idlwave-save-routine-info)
4982 (message "Converting XML routine info...done")))
4985 ;; ("ROUTINE" type class
4986 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4987 ;; (buffer pro_file dir) | (compiled pro_file dir)
4988 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4989 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4992 (defun idlwave-load-rinfo-next-step ()
4993 (let ((inhibit-quit t
)
4994 (arr idlwave-load-rinfo-steps-done
))
4996 (when (not (aref arr
0))
4997 (message "Loading system routine info in idle time...")
4998 (idlwave-load-system-routine-info)
4999 ;;(load "idlw-rinfo" 'noerror 'nomessage)
5000 (message "Loading system routine info in idle time...done")
5004 (when (not (aref arr
1))
5005 (message "Normalizing idlwave-system-routines in idle time...")
5006 (idlwave-reset-sintern t
)
5007 (put 'idlwave-reset-sintern
'done-by-idle t
)
5008 (setq idlwave-system-routines
5009 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5010 (message "Normalizing idlwave-system-routines in idle time...done")
5014 (when (not (aref arr
2))
5015 (when (and (stringp idlwave-user-catalog-file
)
5016 (file-regular-p idlwave-user-catalog-file
))
5017 (message "Loading user catalog in idle time...")
5019 (load-file idlwave-user-catalog-file
)
5020 (error (throw 'exit nil
)))
5021 ;; Check for the old style catalog and warn
5023 (boundp 'idlwave-library-routines
)
5024 idlwave-library-routines
)
5026 (setq idlwave-library-routines nil
)
5028 (message "Outdated user catalog: %s... recreate"
5029 idlwave-user-catalog-file
))
5030 (message "Loading user catalog in idle time...done")))
5034 (when (not (aref arr
3))
5035 (when idlwave-user-catalog-routines
5036 (message "Normalizing user catalog routines in idle time...")
5037 (setq idlwave-user-catalog-routines
5038 (idlwave-sintern-rinfo-list
5039 idlwave-user-catalog-routines
'sys
))
5041 "Normalizing user catalog routines in idle time...done"))
5045 (when (not (aref arr
4))
5046 (idlwave-scan-library-catalogs
5047 "Loading and normalizing library catalogs in idle time...")
5050 (when (not (aref arr
5))
5051 (message "Finishing initialization in idle time...")
5053 (message "Finishing initialization in idle time...done")
5056 ;; restart the timer
5058 (idlwave-load-rinfo-next-step)
5059 (setq idlwave-load-rinfo-idle-timer
5060 (run-with-idle-timer
5061 idlwave-init-rinfo-when-idle-after
5062 nil
'idlwave-load-rinfo-next-step
))))))
5064 (defun idlwave-load-all-rinfo (&optional force
)
5065 ;; Load and case-treat the system, user catalog, and library routine
5069 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
5070 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5071 (idlwave-load-system-routine-info))
5072 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
5073 (message "Normalizing idlwave-system-routines...")
5074 (setq idlwave-system-routines
5075 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5076 (message "Normalizing idlwave-system-routines...done"))
5077 (when idlwave-system-routines
5078 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
5079 (setq idlwave-last-system-routine-info-cons-cell
5080 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
)))
5083 (when (and (stringp idlwave-user-catalog-file
)
5084 (file-regular-p idlwave-user-catalog-file
))
5086 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
5087 (load-file idlwave-user-catalog-file
))
5090 (boundp 'idlwave-library-routines
)
5091 idlwave-library-routines
)
5092 (setq idlwave-library-routines nil
)
5093 (error "Outdated user catalog: %s... recreate"
5094 idlwave-user-catalog-file
))
5095 (setq idlwave-true-path-alist nil
)
5096 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
5097 (message "Normalizing user catalog routines...")
5098 (setq idlwave-user-catalog-routines
5099 (idlwave-sintern-rinfo-list
5100 idlwave-user-catalog-routines
'sys
))
5101 (message "Normalizing user catalog routines...done")))
5104 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
5105 (idlwave-scan-library-catalogs
5106 "Loading and normalizing library catalogs..."))
5107 (run-hooks 'idlwave-after-load-rinfo-hook
))
5110 (defun idlwave-update-buffer-routine-info ()
5113 ((eq idlwave-scan-all-buffers-for-routine-info t
)
5114 ;; Scan all buffers, current buffer last
5115 (message "Scanning all buffers...")
5116 (setq res
(idlwave-get-routine-info-from-buffers
5117 (reverse (buffer-list)))))
5118 ((null idlwave-scan-all-buffers-for-routine-info
)
5119 ;; Don't scan any buffers
5122 ;; Just scan this buffer
5123 (if (eq major-mode
'idlwave-mode
)
5125 (message "Scanning current buffer...")
5126 (setq res
(idlwave-get-routine-info-from-buffers
5127 (list (current-buffer))))))))
5128 ;; Put the result into the correct variable
5129 (setq idlwave-buffer-routines
5130 (idlwave-sintern-rinfo-list res
'set
))))
5132 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
5133 "Put the different sources for routine information together."
5134 ;; The sequence here is important because earlier definitions shadow
5135 ;; later ones. We assume that if things in the buffers are newer
5136 ;; then in the shell of the system, they are meant to be different.
5137 (setcdr idlwave-last-system-routine-info-cons-cell
5138 (append idlwave-buffer-routines
5139 idlwave-compiled-routines
5140 idlwave-library-catalog-routines
5141 idlwave-user-catalog-routines
))
5142 (setq idlwave-class-alist nil
)
5144 ;; Give a message with information about the number of routines we have.
5147 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5148 (length idlwave-buffer-routines
)
5149 (length idlwave-compiled-routines
)
5150 (length idlwave-library-catalog-routines
)
5151 (length idlwave-user-catalog-routines
)
5152 (length idlwave-system-routines
)))
5154 (run-hooks 'idlwave-update-rinfo-hook
)))
5156 (defun idlwave-class-alist ()
5157 "Return the class alist - make it if necessary."
5158 (or idlwave-class-alist
5160 (loop for x in idlwave-routines do
5161 (when (and (setq class
(nth 2 x
))
5162 (not (assq class idlwave-class-alist
)))
5163 (push (list class
) idlwave-class-alist
)))
5164 idlwave-class-alist
)))
5166 ;; Three functions for the hooks
5167 (defun idlwave-save-buffer-update ()
5168 (idlwave-update-current-buffer-info 'save-buffer
))
5169 (defun idlwave-kill-buffer-update ()
5170 (idlwave-update-current-buffer-info 'kill-buffer
))
5171 (defun idlwave-new-buffer-update ()
5172 (idlwave-update-current-buffer-info 'find-file
))
5174 (defun idlwave-update-current-buffer-info (why)
5175 "Update idlwave-routines for current buffer. Can run from after-save-hook."
5176 (when (and (eq major-mode
'idlwave-mode
)
5177 (or (eq t idlwave-auto-routine-info-updates
)
5178 (memq why idlwave-auto-routine-info-updates
))
5179 idlwave-scan-all-buffers-for-routine-info
5183 (idlwave-replace-buffer-routine-info
5185 (if (eq why
'kill-buffer
)
5188 (idlwave-sintern-rinfo-list
5189 (idlwave-get-routine-info-from-buffers
5190 (list (current-buffer))) 'set
))))
5191 (idlwave-concatenate-rinfo-lists 'quiet
)
5195 (defun idlwave-replace-buffer-routine-info (file new
)
5196 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5197 (let ((list idlwave-buffer-routines
)
5200 ;; The following test uses eq to make sure it works correctly
5201 ;; when two buffers visit the same file. Then the file names
5202 ;; will be equal, but not eq.
5203 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
5208 ;; End of that section reached. Jump.
5210 (setq list
(cdr list
)))
5211 (setq idlwave-buffer-routines
5212 (append new
(delq nil idlwave-buffer-routines
)))))
5214 ;;----- Scanning buffers -------------------
5216 (defun idlwave-get-routine-info-from-buffers (buffers)
5217 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5218 (let (buf routine-lists res
)
5220 (while (setq buf
(pop buffers
))
5222 (if (and (eq major-mode
'idlwave-mode
)
5224 ;; yes, this buffer has the right mode.
5225 (progn (setq res
(condition-case nil
5226 (idlwave-get-buffer-routine-info)
5228 (push res routine-lists
)))))
5229 ;; Concatenate the individual lists and return the result
5230 (apply 'nconc routine-lists
)))
5232 (defun idlwave-get-buffer-routine-info ()
5233 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5234 (let* ((case-fold-search t
)
5235 routine-list string entry
)
5239 (goto-char (point-min))
5240 (while (re-search-forward
5241 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
5242 (setq string
(buffer-substring-no-properties
5245 (idlwave-end-of-statement)
5247 (setq entry
(idlwave-parse-definition string
))
5248 (push entry routine-list
))))
5251 (defvar idlwave-scanning-lib-dir
)
5252 (defun idlwave-parse-definition (string)
5253 "Parse a module definition."
5254 (let ((case-fold-search t
)
5255 start name args type keywords class
)
5257 (while (string-match ";.*" string
)
5258 (setq string
(replace-match "" t t string
)))
5259 ;; Remove the continuation line stuff
5260 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
5261 (setq string
(replace-match "\\1 " t nil string
)))
5262 (while (string-match "\n" string
)
5263 (setq string
(replace-match " " t nil string
)))
5264 ;; Match the name and type.
5266 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
5267 (setq start
(match-end 0))
5268 (setq type
(downcase (match-string 1 string
)))
5269 (if (match-beginning 3)
5270 (setq class
(match-string 3 string
)))
5271 (setq name
(match-string 4 string
)))
5272 ;; Match normal args and keyword args
5273 (while (string-match
5274 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5276 (setq start
(match-end 0))
5277 (if (match-beginning 3)
5278 (push (match-string 1 string
) keywords
)
5279 (push (match-string 1 string
) args
)))
5280 ;; Normalize and sort.
5281 (setq args
(nreverse args
))
5282 (setq keywords
(sort keywords
(lambda (a b
)
5283 (string< (downcase a
) (downcase b
)))))
5284 ;; Make and return the entry
5285 ;; We don't know which argument are optional, so this information
5286 ;; will not be contained in the calling sequence.
5288 (if (equal type
"pro") 'pro
'fun
)
5290 (cond ((not (boundp 'idlwave-scanning-lib
))
5291 (list 'buffer
(buffer-file-name)))
5292 ; ((string= (downcase
5293 ; (file-name-sans-extension
5294 ; (file-name-nondirectory (buffer-file-name))))
5297 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5298 (t (list 'user
(file-name-nondirectory (buffer-file-name))
5299 idlwave-scanning-lib-dir
"UserLib")))
5301 (if (string= type
"function") "Result = " "")
5302 (if class
"Obj ->[%s::]" "")
5306 (if (string= type
"function") "(" ", ")
5307 (mapconcat 'identity args
", ")
5308 (if (string= type
"function") ")" ""))))
5310 (cons nil
(mapcar 'list keywords
)) ;No help file
5314 ;;----- Scanning the user catalog -------------------
5316 (defun idlwave-sys-dir ()
5317 "Return the syslib directory, or a dummy that never matches."
5319 ((and idlwave-system-directory
5320 (not (string= idlwave-system-directory
"")))
5321 idlwave-system-directory
)
5322 ((getenv "IDL_DIR"))
5326 (defun idlwave-create-user-catalog-file (&optional arg
)
5327 "Scan all files on selected dirs of IDL search path for routine information.
5329 A widget checklist will allow you to choose the directories. Write
5330 the result as a file `idlwave-user-catalog-file'. When this file
5331 exists, will be automatically loaded to give routine information about
5332 library routines. With ARG, just rescan the same directories as last
5333 time - so no widget will pop up."
5335 ;; Make sure the file is loaded if it exists.
5336 (if (and (stringp idlwave-user-catalog-file
)
5337 (file-regular-p idlwave-user-catalog-file
))
5339 (load-file idlwave-user-catalog-file
)
5341 ;; Make sure the file name makes sense
5342 (unless (and (stringp idlwave-user-catalog-file
)
5343 (> (length idlwave-user-catalog-file
) 0)
5344 (file-accessible-directory-p
5345 (file-name-directory idlwave-user-catalog-file
))
5346 (not (string= "" (file-name-nondirectory
5347 idlwave-user-catalog-file
))))
5348 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5351 ;; Rescan the known directories
5352 ((and arg idlwave-path-alist
5353 (consp (car idlwave-path-alist
)))
5354 (idlwave-scan-user-lib-files idlwave-path-alist
))
5356 ;; Expand the directories from library-path and run the widget
5357 (idlwave-library-path
5358 (idlwave-display-user-catalog-widget
5359 (if idlwave-true-path-alist
5360 ;; Propagate any flags on the existing path-alist
5362 (let ((path-entry (assoc (file-truename x
)
5363 idlwave-true-path-alist
)))
5365 (cons x
(cdr path-entry
))
5367 (idlwave-expand-path idlwave-library-path
))
5368 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
5370 ;; Ask the shell for the path and then run the widget
5372 (message "Asking the shell for IDL path...")
5373 (require 'idlw-shell
)
5374 (idlwave-shell-send-command idlwave-shell-path-query
5375 '(idlwave-user-catalog-command-hook nil
)
5379 ;; Parse shell path information and select among it.
5380 (defun idlwave-user-catalog-command-hook (&optional arg
)
5381 ;; Command hook used by `idlwave-create-user-catalog-file'.
5384 (idlwave-scan-user-lib-files idlwave-path-alist
)
5385 ;; Set the path and display the widget
5386 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
5387 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
5388 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
5390 (defconst idlwave-user-catalog-widget-help-string
5391 "This is the front-end to the creation of the IDLWAVE user catalog.
5392 Please select the directories on IDL's search path from which you
5393 would like to extract routine information, to be stored in the file:
5397 If this is not the correct file, first set variable
5398 `idlwave-user-catalog-file', and call this command again.
5400 N.B. Many libraries include pre-scanned catalog files
5401 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5402 not be scanned. You can scan your own libraries off-line using the
5403 perl script `idlwave_catalog'.
5405 After selecting the directories, choose [Scan & Save] to scan the library
5406 directories and save the routine info.
5409 (defvar idlwave-widget
)
5410 (defvar widget-keymap
)
5411 (defun idlwave-display-user-catalog-widget (dirs-list)
5412 "Create the widget to select IDL search path directories for scanning."
5417 (error "Don't know IDL's search path"))
5419 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5420 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5421 (kill-all-local-variables)
5422 (make-local-variable 'idlwave-widget
)
5423 (widget-insert (format idlwave-user-catalog-widget-help-string
5424 idlwave-user-catalog-file
))
5426 (widget-create 'push-button
5427 :notify
'idlwave-widget-scan-user-lib-files
5430 (widget-create 'push-button
5431 :notify
'idlwave-delete-user-catalog-file
5434 (widget-create 'push-button
5436 '(lambda (&rest ignore
)
5437 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5439 (unless (memq 'lib
(cdr x
))
5440 (idlwave-path-alist-add-flag x
'user
)))
5442 (idlwave-display-user-catalog-widget path-list
)))
5443 "Select All Non-Lib")
5445 (widget-create 'push-button
5447 '(lambda (&rest ignore
)
5448 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5450 (idlwave-path-alist-remove-flag x
'user
))
5452 (idlwave-display-user-catalog-widget path-list
)))
5455 (widget-create 'push-button
5456 :notify
(lambda (&rest ignore
)
5457 (kill-buffer (current-buffer)))
5459 (widget-insert "\n\n")
5461 (widget-insert "Select Directories: \n")
5463 (setq idlwave-widget
5464 (apply 'widget-create
5466 :value
(delq nil
(mapcar (lambda (x)
5467 (if (memq 'user
(cdr x
))
5471 :tag
"List of directories"
5474 (if (memq 'lib
(cdr x
))
5475 (concat "[LIB] " (car x
) )
5476 (car x
)))) dirs-list
)))
5477 (widget-put idlwave-widget
:path-dirs dirs-list
)
5478 (widget-insert "\n")
5479 (use-local-map widget-keymap
)
5481 (goto-char (point-min))
5482 (delete-other-windows))
5484 (defun idlwave-delete-user-catalog-file (&rest ignore
)
5486 (format "Delete file %s " idlwave-user-catalog-file
))
5488 (delete-file idlwave-user-catalog-file
)
5489 (message "%s has been deleted" idlwave-user-catalog-file
))))
5491 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
5492 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5493 (let* ((widget idlwave-widget
)
5494 (selected-dirs (widget-value widget
))
5495 (path-alist (widget-get widget
:path-dirs
))
5496 (this-path-alist path-alist
)
5498 (while (setq dir-entry
(pop this-path-alist
))
5500 (if (memq 'lib
(cdr dir-entry
))
5501 (concat "[LIB] " (car dir-entry
))
5504 (idlwave-path-alist-add-flag dir-entry
'user
)
5505 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5506 (idlwave-scan-user-lib-files path-alist
)))
5508 (defvar font-lock-mode
)
5509 (defun idlwave-scan-user-lib-files (path-alist)
5510 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5511 (let* ((idlwave-scanning-lib t
)
5512 (idlwave-scanning-lib-dir "")
5513 (idlwave-completion-case nil
)
5514 dirs-alist dir files file
)
5515 (setq idlwave-user-catalog-routines nil
5516 idlwave-path-alist path-alist
; for library-path instead
5517 idlwave-true-path-alist nil
)
5518 (if idlwave-auto-write-paths
(idlwave-write-paths))
5520 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5522 (setq dirs-alist
(reverse path-alist
))
5523 (while (setq dir
(pop dirs-alist
))
5524 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5525 (setq dir
(car dir
))
5526 (setq idlwave-scanning-lib-dir dir
)
5527 (when (file-directory-p dir
)
5528 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5529 (while (setq file
(pop files
))
5530 (when (file-regular-p file
)
5531 (if (not (file-readable-p file
))
5532 (message "Skipping %s (no read permission)" file
)
5533 (message "Scanning %s..." file
)
5535 (insert-file-contents file
'visit
)
5536 (setq idlwave-user-catalog-routines
5537 (append (idlwave-get-routine-info-from-buffers
5538 (list (current-buffer)))
5539 idlwave-user-catalog-routines
)))))))))
5540 (message "Creating user catalog file...")
5541 (kill-buffer "*idlwave-scan.pro*")
5542 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5543 (let ((font-lock-maximum-size 0)
5544 (auto-mode-alist nil
))
5545 (find-file idlwave-user-catalog-file
))
5546 (if (and (boundp 'font-lock-mode
)
5550 (insert ";; IDLWAVE user catalog file\n")
5551 (insert (format ";; Created %s\n\n" (current-time-string)))
5553 ;; Define the routine info list
5554 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5555 (let ((standard-output (current-buffer)))
5559 (goto-char (point-max)))
5560 idlwave-user-catalog-routines
))
5561 (insert (format "))\n\n;;; %s ends here\n"
5562 (file-name-nondirectory idlwave-user-catalog-file
)))
5563 (goto-char (point-min))
5566 (kill-buffer (current-buffer)))
5567 (message "Creating user catalog file...done")
5568 (message "Info for %d routines saved in %s"
5569 (length idlwave-user-catalog-routines
)
5570 idlwave-user-catalog-file
)
5572 (idlwave-update-routine-info t
))
5574 (defun idlwave-read-paths ()
5575 (if (and (stringp idlwave-path-file
)
5576 (file-regular-p idlwave-path-file
))
5578 (load idlwave-path-file t t t
)
5581 (defun idlwave-write-paths ()
5583 (when (and idlwave-path-alist idlwave-system-directory
)
5584 (let ((font-lock-maximum-size 0)
5585 (auto-mode-alist nil
))
5586 (find-file idlwave-path-file
))
5587 (if (and (boundp 'font-lock-mode
)
5591 (insert ";; IDLWAVE paths\n")
5592 (insert (format ";; Created %s\n\n" (current-time-string)))
5593 ;; Define the variable which knows the value of "!DIR"
5594 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5595 idlwave-system-directory
))
5597 ;; Define the variable which contains a list of all scanned directories
5598 (insert "\n(setq idlwave-path-alist\n '(")
5599 (let ((standard-output (current-buffer)))
5603 (goto-char (point-max)))
5604 idlwave-path-alist
))
5607 (kill-buffer (current-buffer))))
5610 (defun idlwave-expand-path (path &optional default-dir
)
5611 ;; Expand parts of path starting with '+' recursively into directory list.
5612 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5613 (message "Expanding path...")
5614 (let (path1 dir recursive
)
5615 (while (setq dir
(pop path
))
5616 (if (setq recursive
(string= (substring dir
0 1) "+"))
5617 (setq dir
(substring dir
1)))
5619 (not (file-name-absolute-p dir
)))
5620 (setq dir
(expand-file-name dir default-dir
)))
5622 ;; Expand recursively
5623 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5626 (message "Expanding path...done")
5629 (defun idlwave-recursive-directory-list (dir)
5630 ;; Return a list of all directories below DIR, including DIR itself
5631 (let ((path (list dir
)) path1 file files
)
5632 (while (setq dir
(pop path
))
5633 (when (file-directory-p dir
)
5634 (setq files
(nreverse (directory-files dir t
"[^.]")))
5635 (while (setq file
(pop files
))
5636 (if (file-directory-p file
)
5637 (push (file-name-as-directory file
) path
)))
5642 ;;----- Scanning the library catalogs ------------------
5647 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5648 "Scan for library catalog files (.idlwave_catalog) and ingest.
5650 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5651 instead, if present) are searched. Print MESSAGE-BASE along with the
5652 libraries being loaded, if passed, and skip loading/normalizing if
5653 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5654 be set to nil to disable library catalog scanning."
5655 (when idlwave-use-library-catalogs
5657 (if idlwave-library-path
5658 (idlwave-expand-path idlwave-library-path
)
5659 (mapcar 'car idlwave-path-alist
)))
5661 dir-entry dir flags catalog all-routines
)
5662 (if message-base
(message message-base
))
5663 (while (setq dir
(pop dirs
))
5665 (when (file-readable-p
5666 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5668 (setq idlwave-library-catalog-routines nil
)
5669 ;; Load the catalog file
5671 (load catalog t t t
)
5672 (error (throw 'continue t
)))
5675 (not (string= idlwave-library-catalog-libname
5677 (message "%s" (concat message-base
5678 idlwave-library-catalog-libname
))
5679 (setq old-libname idlwave-library-catalog-libname
))
5680 (when idlwave-library-catalog-routines
5683 (idlwave-sintern-rinfo-list
5684 idlwave-library-catalog-routines
'sys dir
)
5687 ;; Add a 'lib flag if on path-alist
5688 (when (and idlwave-path-alist
5689 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5690 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5691 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5692 (if message-base
(message (concat message-base
"done"))))))
5694 ;;----- Communicating with the Shell -------------------
5696 ;; First, here is the idl program which can be used to query IDL for
5697 ;; defined routines.
5698 (defconst idlwave-routine-info.pro
5700 ;; START OF IDLWAVE SUPPORT ROUTINES
5701 pro idlwave_print_safe,item,limit
5703 if err ne 0 then begin
5704 print,'Could not print item.'
5707 if n_elements(item) gt limit then $
5708 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5712 pro idlwave_print_info_entry,name,func=func,separator=sep
5713 ;; See if it's an object method
5714 if name eq '' then return
5715 func = keyword_set(func)
5716 methsep = strpos(name,'::')
5717 meth = methsep ne -1
5720 pars = routine_info(name,/parameters,functions=func)
5721 source = routine_info(name,/source,functions=func)
5722 nargs = pars.num_args
5723 nkw = pars.num_kw_args
5724 if nargs gt 0 then args = pars.args
5725 if nkw gt 0 then kwargs = pars.kw_args
5727 ;; Trim the class, and make the name
5729 class = strmid(name,0,methsep)
5730 name = strmid(name,methsep+2,strlen(name)-1)
5731 if nargs gt 0 then begin
5732 ;; remove the self argument
5733 wh = where(args ne 'SELF',nargs)
5734 if nargs gt 0 then args = args[wh]
5737 ;; No class, just a normal routine.
5743 if func then cs = 'Result = '
5744 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5746 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5747 if nargs gt 0 then begin
5748 for j=0,nargs-1 do begin
5750 if j lt nargs-1 then cs = cs + ', '
5753 if func then cs = cs + ')'
5754 ;; Keyword arguments
5756 if nkw gt 0 then begin
5757 for j=0,nkw-1 do begin
5758 kwstring = kwstring + ' ' + kwargs[j]
5762 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5764 print,ret + ': ' + name + sep + class + sep + source[0].path $
5765 + sep + cs + sep + kwstring
5768 pro idlwave_routine_info,file
5771 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5772 all = routine_info()
5773 fileQ=n_elements(file) ne 0
5774 if fileQ then file=strtrim(file,2)
5775 for i=0L,n_elements(all)-1L do begin
5777 if (routine_info(all[i],/SOURCE)).path eq file then $
5778 idlwave_print_info_entry,all[i],separator=sep
5779 endif else idlwave_print_info_entry,all[i],separator=sep
5781 all = routine_info(/functions)
5782 for i=0L,n_elements(all)-1L do begin
5784 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5785 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5786 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5788 print,'>>>END OF IDLWAVE ROUTINE INFO'
5791 pro idlwave_get_sysvars
5794 if error_status ne 0 then begin
5795 print, 'Cannot get info about system variables'
5797 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5798 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5799 v = strsplit(s,' +',/regex,/extract) ; get variables
5800 for i=0L,n_elements(v)-1 do begin
5801 t = [''] ; get tag list
5802 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5803 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5808 pro idlwave_get_class_tags, class
5809 res = execute('tags=tag_names({'+class+'})')
5810 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5812 ;; END OF IDLWAVE SUPPORT ROUTINES
5814 "The idl programs to get info from the shell.")
5816 (defvar idlwave-idlwave_routine_info-compiled nil
5817 "Remembers if the routine info procedure is already compiled.")
5819 (defvar idlwave-shell-temp-pro-file
)
5820 (defvar idlwave-shell-temp-rinfo-save-file
)
5822 (defun idlwave-shell-compile-helper-routines (&optional wait
)
5823 (unless (and idlwave-idlwave_routine_info-compiled
5824 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5826 (set-buffer (idlwave-find-file-noselect
5827 (idlwave-shell-temp-file 'pro
)))
5829 (insert idlwave-routine-info.pro
)
5831 (idlwave-shell-send-command
5832 (concat ".run \"" idlwave-shell-temp-pro-file
"\"")
5834 (idlwave-shell-send-command
5835 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5836 (idlwave-shell-temp-file 'rinfo
))
5838 (setq idlwave-idlwave_routine_info-compiled t
))
5840 ;; Restore if necessary. Must use execute to hide lame routine_info
5841 ;; errors on undefinded routine
5842 (idlwave-shell-send-command
5843 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5844 idlwave-shell-temp-rinfo-save-file
5845 idlwave-shell-temp-rinfo-save-file
)
5849 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file
)
5850 "Query the shell for routine_info of compiled modules and update the lists."
5851 ;; Save and compile the procedure. The compiled procedure is then
5852 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5853 ;; need to test for and possibly RESTORE the procedure each time we
5854 ;; use it, since the user may have killed or redefined it. In
5855 ;; particular, .RESET_SESSION will kill all user procedures. If
5856 ;; FILE is set, only update routine info for routines in that file.
5858 (idlwave-shell-compile-helper-routines wait
)
5859 ; execute the routine_info procedure, and analyze the output
5860 (idlwave-shell-send-command
5861 (format "idlwave_routine_info%s" (if file
(concat ",'" file
"'") ""))
5863 (idlwave-shell-routine-info-filter)
5864 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5867 ;; ---------------------------------------------------------------------------
5869 ;; Completion and displaying routine calling sequences
5871 (defvar idlwave-completion-help-info nil
)
5872 (defvar idlwave-completion-help-links nil
)
5873 (defvar idlwave-current-obj_new-class nil
)
5874 (defvar idlwave-complete-special nil
)
5876 (defun idlwave-complete (&optional arg module class
)
5877 "Complete a function, procedure or keyword name at point.
5878 This function is smart and figures out what can be completed
5880 - At the beginning of a statement it completes procedure names.
5881 - In the middle of a statement it completes function names.
5882 - after a `(' or `,' in the argument list of a function or procedure,
5883 it completes a keyword of the relevant function or procedure.
5884 - In the first arg of `OBJ_NEW', it completes a class name.
5886 When several completions are possible, a list will be displayed in the
5887 *Completions* buffer. If this list is too long to fit into the
5888 window, scrolling can be achieved by repeatedly pressing
5889 \\[idlwave-complete].
5891 The function also knows about object methods. When it needs a class
5892 name, the action depends upon `idlwave-query-class', which see. You
5893 can force IDLWAVE to ask you for a class name with a
5894 \\[universal-argument] prefix argument to this command.
5896 See also the variables `idlwave-keyword-completion-adds-equal' and
5897 `idlwave-function-completion-adds-paren'.
5899 The optional ARG can be used to specify the completion type in order
5900 to override IDLWAVE's idea of what should be completed at point.
5901 Possible values are:
5903 0 <=> query for the completion type
5905 2 <=> 'procedure-keyword
5907 4 <=> 'function-keyword
5908 5 <=> 'procedure-method
5909 6 <=> 'procedure-method-keyword
5910 7 <=> 'function-method
5911 8 <=> 'function-method-keyword
5914 As a special case, the universal argument C-u forces completion of
5915 function names in places where the default would be a keyword.
5917 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5920 For Lisp programmers only:
5921 When we force a keyword, optional argument MODULE can contain the module name.
5922 When we force a method or a method keyword, CLASS can specify the class."
5927 (or (and (integerp arg
) (not (equal arg
'(16))))
5929 (idlwave-make-force-complete-where-list arg module class
)
5931 (what (nth 2 where-list
))
5932 (idlwave-force-class-query (equal arg
'(4)))
5933 (completion-regexp-list
5934 (if (equal arg
'(16))
5935 (list (read-string (concat "Completion Regexp: "))))))
5937 (if (and module
(string-match "::" module
))
5938 (setq class
(substring module
0 (match-beginning 0))
5939 module
(substring module
(match-end 0))))
5944 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5945 (get-buffer-window "*Completions*"))
5946 (setq this-command last-command
)
5947 (idlwave-scroll-completions))
5949 ;; Complete a filename in quotes
5950 ((and (idlwave-in-quote)
5951 (not (eq what
'class
)))
5952 (idlwave-complete-filename))
5954 ;; Check for any special completion functions
5955 ((and idlwave-complete-special
5956 (idlwave-call-special idlwave-complete-special
)))
5959 (error "Nothing to complete here"))
5963 (setq idlwave-completion-help-info
'(class))
5964 (idlwave-complete-class))
5966 ((eq what
'procedure
)
5967 ;; Complete a procedure name
5968 (let* ((cw-list (nth 3 where-list
))
5969 (class-selector (idlwave-determine-class cw-list
'pro
))
5970 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5971 (idlwave-all-class-inherits class-selector
)))
5972 (isa (concat "procedure" (if class-selector
"-method" "")))
5973 (type-selector 'pro
))
5974 (setq idlwave-completion-help-info
5975 (list 'routine nil type-selector class-selector nil super-classes
))
5976 (idlwave-complete-in-buffer
5977 'procedure
(if class-selector
'method
'routine
)
5978 (idlwave-routines) 'idlwave-selector
5979 (format "Select a %s name%s"
5982 (format " (class is %s)"
5983 (if (eq class-selector t
)
5984 "unknown" class-selector
))
5987 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5989 ((eq what
'function
)
5990 ;; Complete a function name
5991 (let* ((cw-list (nth 3 where-list
))
5992 (class-selector (idlwave-determine-class cw-list
'fun
))
5993 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5994 (idlwave-all-class-inherits class-selector
)))
5995 (isa (concat "function" (if class-selector
"-method" "")))
5996 (type-selector 'fun
))
5997 (setq idlwave-completion-help-info
5998 (list 'routine nil type-selector class-selector nil super-classes
))
5999 (idlwave-complete-in-buffer
6000 'function
(if class-selector
'method
'routine
)
6001 (idlwave-routines) 'idlwave-selector
6002 (format "Select a %s name%s"
6005 (format " (class is %s)"
6006 (if (eq class-selector t
)
6007 "unknown" class-selector
))
6010 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
6012 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
6014 (idlwave-complete 3))
6016 ((eq what
'procedure-keyword
)
6017 ;; Complete a procedure keyword
6018 (let* ((where (nth 3 where-list
))
6020 (method-selector name
)
6021 (type-selector 'pro
)
6022 (class (idlwave-determine-class where
'pro
))
6023 (class-selector class
)
6024 (super-classes (idlwave-all-class-inherits class-selector
))
6025 (isa (format "procedure%s-keyword" (if class
"-method" "")))
6026 (entry (idlwave-best-rinfo-assq
6027 name
'pro class
(idlwave-routines)))
6028 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6029 (list (idlwave-entry-keywords entry
'do-link
)))
6030 (unless (or entry
(eq class t
))
6031 (error "Nothing known about procedure %s"
6032 (idlwave-make-full-name class name
)))
6033 (setq list
(idlwave-fix-keywords name
'pro class list
6034 super-classes system
))
6035 (unless list
(error "No keywords available for procedure %s"
6036 (idlwave-make-full-name class name
)))
6037 (setq idlwave-completion-help-info
6038 (list 'keyword name type-selector class-selector entry super-classes
))
6039 (idlwave-complete-in-buffer
6040 'keyword
'keyword list nil
6041 (format "Select keyword for procedure %s%s"
6042 (idlwave-make-full-name class name
)
6043 (if (or (member '("_EXTRA") list
)
6044 (member '("_REF_EXTRA") list
))
6045 " (note _EXTRA)" ""))
6047 'idlwave-attach-keyword-classes
)))
6049 ((eq what
'function-keyword
)
6050 ;; Complete a function keyword
6051 (let* ((where (nth 3 where-list
))
6053 (method-selector name
)
6054 (type-selector 'fun
)
6055 (class (idlwave-determine-class where
'fun
))
6056 (class-selector class
)
6057 (super-classes (idlwave-all-class-inherits class-selector
))
6058 (isa (format "function%s-keyword" (if class
"-method" "")))
6059 (entry (idlwave-best-rinfo-assq
6060 name
'fun class
(idlwave-routines)))
6061 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6062 (list (idlwave-entry-keywords entry
'do-link
))
6064 (unless (or entry
(eq class t
))
6065 (error "Nothing known about function %s"
6066 (idlwave-make-full-name class name
)))
6067 (setq list
(idlwave-fix-keywords name
'fun class list
6068 super-classes system
))
6069 ;; OBJ_NEW: Messages mention the proper Init method
6070 (setq msg-name
(if (and (null class
)
6071 (string= (upcase name
) "OBJ_NEW"))
6072 (concat idlwave-current-obj_new-class
6073 "::Init (via OBJ_NEW)")
6074 (idlwave-make-full-name class name
)))
6075 (unless list
(error "No keywords available for function %s"
6077 (setq idlwave-completion-help-info
6078 (list 'keyword name type-selector class-selector nil super-classes
))
6079 (idlwave-complete-in-buffer
6080 'keyword
'keyword list nil
6081 (format "Select keyword for function %s%s" msg-name
6082 (if (or (member '("_EXTRA") list
)
6083 (member '("_REF_EXTRA") list
))
6084 " (note _EXTRA)" ""))
6086 'idlwave-attach-keyword-classes
)))
6088 (t (error "This should not happen (idlwave-complete)")))))
6090 (defvar idlwave-complete-special nil
6091 "List of special completion functions.
6092 These functions are called for each completion. Each function must
6093 check if its own special completion context is present. If yes, it
6094 should use `idlwave-complete-in-buffer' to do some completion and
6095 return t. If such a function returns t, *no further* attempts to
6096 complete other contexts will be done. If the function returns nil,
6097 other completions will be tried.")
6099 (defun idlwave-call-special (functions &rest args
)
6100 (let ((funcs functions
)
6103 (while (setq fun
(pop funcs
))
6104 (if (setq ret
(apply fun args
))
6108 (defun idlwave-make-force-complete-where-list (what &optional module class
)
6109 ;; Return an artificial WHERE specification to force the completion
6110 ;; routine to complete a specific item independent of context.
6111 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6112 ;; MODULE and CLASS can be used to specify the routine name and class.
6113 ;; The class name will also be found in MODULE if that is like "class::mod".
6114 (let* ((what-list '(("procedure") ("procedure-keyword")
6115 ("function") ("function-keyword")
6116 ("procedure-method") ("procedure-method-keyword")
6117 ("function-method") ("function-method-keyword")
6119 (module (idlwave-sintern-routine-or-method module class
))
6120 (class (idlwave-sintern-class class
))
6124 (intern (completing-read
6125 "Complete what? " what-list nil t
))))
6127 (setq what
(intern (car (nth (1- what
) what-list
)))))
6130 (assoc (symbol-name what
) what-list
))
6132 (t (error "Invalid WHAT"))))
6133 (nil-list '(nil nil nil nil
))
6134 (class-list (list nil nil
(or class t
) nil
)))
6138 ((eq what
'procedure
)
6139 (list nil-list nil-list
'procedure nil-list nil
))
6141 ((eq what
'procedure-keyword
)
6142 (let* ((class-selector nil
)
6144 (type-selector 'pro
)
6146 (idlwave-completing-read
6147 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
6148 (setq pro
(idlwave-sintern-routine pro
))
6149 (list nil-list nil-list
'procedure-keyword
6150 (list pro nil nil nil
) nil
)))
6152 ((eq what
'function
)
6153 (list nil-list nil-list
'function nil-list nil
))
6155 ((eq what
'function-keyword
)
6156 (let* ((class-selector nil
)
6158 (type-selector 'fun
)
6160 (idlwave-completing-read
6161 "Function: " (idlwave-routines) 'idlwave-selector
))))
6162 (setq func
(idlwave-sintern-routine func
))
6163 (list nil-list nil-list
'function-keyword
6164 (list func nil nil nil
) nil
)))
6166 ((eq what
'procedure-method
)
6167 (list nil-list nil-list
'procedure class-list nil
))
6169 ((eq what
'procedure-method-keyword
)
6170 (let* ((class (idlwave-determine-class class-list
'pro
))
6171 (class-selector class
)
6172 (super-classes (idlwave-all-class-inherits class-selector
))
6173 (type-selector 'pro
)
6175 (idlwave-completing-read
6176 (format "Procedure in %s class: " class-selector
)
6177 (idlwave-routines) 'idlwave-selector
))))
6178 (setq pro
(idlwave-sintern-method pro
))
6179 (list nil-list nil-list
'procedure-keyword
6180 (list pro nil class nil
) nil
)))
6182 ((eq what
'function-method
)
6183 (list nil-list nil-list
'function class-list nil
))
6185 ((eq what
'function-method-keyword
)
6186 (let* ((class (idlwave-determine-class class-list
'fun
))
6187 (class-selector class
)
6188 (super-classes (idlwave-all-class-inherits class-selector
))
6189 (type-selector 'fun
)
6191 (idlwave-completing-read
6192 (format "Function in %s class: " class-selector
)
6193 (idlwave-routines) 'idlwave-selector
))))
6194 (setq func
(idlwave-sintern-method func
))
6195 (list nil-list nil-list
'function-keyword
6196 (list func nil class nil
) nil
)))
6199 (list nil-list nil-list
'class nil-list nil
))
6201 (t (error "Invalid value for WHAT")))))
6203 (defun idlwave-completing-read (&rest args
)
6204 ;; Completing read, case insensitive
6205 (let ((old-value (default-value 'completion-ignore-case
)))
6208 (setq-default completion-ignore-case t
)
6209 (apply 'completing-read args
))
6210 (setq-default completion-ignore-case old-value
))))
6212 (defvar idlwave-shell-default-directory
)
6213 (defun idlwave-complete-filename ()
6214 "Use the comint stuff to complete a file name."
6216 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6217 (comint-completion-addsuffix nil
)
6219 (if (and (boundp 'idlwave-shell-default-directory
)
6220 (stringp idlwave-shell-default-directory
)
6221 (file-directory-p idlwave-shell-default-directory
))
6222 idlwave-shell-default-directory
6223 default-directory
)))
6224 (comint-dynamic-complete-filename)))
6226 (defun idlwave-make-full-name (class name
)
6227 ;; Make a fully qualified module name including the class name
6228 (concat (if class
(format "%s::" class
) "") name
))
6230 (defun idlwave-rinfo-assoc (name type class list
)
6231 "Like `idlwave-rinfo-assq', but sintern strings first."
6233 (idlwave-sintern-routine-or-method name class
)
6234 type
(idlwave-sintern-class class
) list
))
6236 (defun idlwave-rinfo-assq (name type class list
)
6237 ;; Works like assq, but also checks type and class
6240 (while (setq match
(assq name list
))
6241 (and (or (eq type t
)
6242 (eq (nth 1 match
) type
))
6243 (eq (nth 2 match
) class
)
6244 (throw 'exit match
))
6245 (setq list
(cdr (memq match list
)))))))
6247 (defun idlwave-rinfo-assq-any-class (name type class list
)
6248 ;; Return the first matching method on the inheritance list
6249 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
6252 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
6253 (setq classes nil
)))
6256 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
6258 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6259 If WITH-FILE is passed, find the best rinfo entry with a file
6260 included. If KEEP-SYSTEM is set, don't prune system for compiled
6262 (let ((twins (idlwave-routine-twins
6263 (idlwave-rinfo-assq-any-class name type class list
)
6266 (when (> (length twins
) 1)
6267 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
6268 (if (and (null keep-system
)
6269 (eq 'system
(car (nth 3 (car twins
))))
6270 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
6271 (not (equal 1 syslibp
)))
6272 ;; Its a compiled syslib, so we need to remove the system entry
6273 (setq twins
(cdr twins
)))
6275 (setq twins
(delq nil
6277 (if (nth 1 (nth 3 x
)) x
))
6281 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
6283 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6284 (idlwave-best-rinfo-assq
6285 (idlwave-sintern-routine-or-method name class
)
6286 type
(idlwave-sintern-class class
) list with-file keep-system
))
6288 (defun idlwave-any-syslib (entries)
6289 "Does the entry list ENTRIES contain a syslib entry?
6290 If yes, return the index (>=1)."
6295 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
6296 (if (and file
(idlwave-syslib-p file
))
6298 (setq entries
(cdr entries
))))
6301 (defun idlwave-all-assq (key list
)
6302 "Return a list of all associations of Key in LIST."
6304 (while (setq elt
(assq key list
))
6306 (setq list
(cdr (memq elt list
))))
6309 (defun idlwave-all-method-classes (method &optional type
)
6310 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
6311 When TYPE is not specified, both procedures and functions will be considered."
6313 (mapcar 'car
(idlwave-class-alist))
6318 (eq type
(nth 1 x
)))
6319 (push (nth 2 x
) rtn
)))
6320 (idlwave-all-assq method
(idlwave-routines)))
6321 (idlwave-uniquify rtn
))))
6323 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
6324 "Return all classes which have a method METHOD with keyword KEYWORD.
6325 TYPE is 'fun or 'pro.
6326 When TYPE is not specified, both procedures and functions will be considered."
6327 (if (or (null method
)
6332 (and (nth 2 x
) ; non-nil class
6333 (or (not type
) ; correct or unspecified type
6334 (eq type
(nth 1 x
)))
6335 (assoc keyword
(idlwave-entry-keywords x
))
6336 (push (nth 2 x
) rtn
)))
6337 (idlwave-all-assq method
(idlwave-routines)))
6338 (idlwave-uniquify rtn
))))
6340 (defun idlwave-members-only (list club
)
6341 "Return list of all elements in LIST which are also in CLUB."
6344 (if (member (car list
) club
)
6345 (setq rtn
(cons (car list
) rtn
)))
6346 (setq list
(cdr list
)))
6349 (defun idlwave-nonmembers-only (list club
)
6350 "Return list of all elements in LIST which are not in CLUB."
6353 (if (member (car list
) club
)
6355 (setq rtn
(cons (car list
) rtn
)))
6356 (setq list
(cdr list
)))
6359 (defun idlwave-explicit-class-listed (info)
6360 "Return whether or not the class is listed explicitly, ala a->b::c.
6361 INFO is as returned by idlwave-what-function or -procedure."
6362 (let ((apos (nth 3 info
)))
6364 (save-excursion (goto-char apos
)
6365 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6367 (defvar idlwave-determine-class-special nil
6368 "List of special functions for determining class.
6369 Must accept two arguments: `apos' and `info'")
6371 (defun idlwave-determine-class (info type
)
6372 ;; Determine the class of a routine call.
6373 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6374 ;; The second element in this structure is the class. When nil, we
6375 ;; return nil. When t, try to get the class from text properties at
6376 ;; the arrow. When the object is "self", we use the class of the
6377 ;; current routine. otherwise prompt the user for a class name.
6378 ;; Also stores the selected class as a text property at the arrow.
6379 ;; TYPE is 'fun or 'pro.
6380 (let* ((class (nth 2 info
))
6382 (nassoc (assoc (if (stringp (car info
))
6385 idlwave-query-class
))
6386 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
6387 idlwave-query-class
))
6388 (query (cond (nassoc (cdr nassoc
))
6389 (dassoc (cdr dassoc
))
6391 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
6394 (save-excursion (goto-char apos
)
6396 (let ((case-fold-search t
))
6397 (looking-at "self\\>")))))
6398 (force-query idlwave-force-class-query
)
6399 store special-class class-alist
)
6403 ;; There is an object which would like to know its class
6404 (if (and arrow
(get-text-property apos
'idlwave-class
)
6405 idlwave-store-inquired-class
6407 (setq class
(get-text-property apos
'idlwave-class
)
6408 class
(idlwave-sintern-class class
)))
6409 (if (and (eq t class
) is-self
)
6410 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
6412 ;; Before prompting, try any special class determination routines
6413 (when (and (eq t class
)
6414 idlwave-determine-class-special
6417 (idlwave-call-special idlwave-determine-class-special apos
))
6419 (setq class
(idlwave-sintern-class special-class
)
6420 store idlwave-store-inquired-class
)))
6422 ;; Prompt for a class, if we need to
6423 (when (and (eq class t
)
6424 (or force-query query
))
6426 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
6428 (idlwave-sintern-class
6430 ((and (= (length class-alist
) 0) (not force-query
))
6431 (error "No classes available with method %s" (car info
)))
6432 ((and (= (length class-alist
) 1) (not force-query
))
6433 (car (car class-alist
)))
6435 (setq store idlwave-store-inquired-class
)
6436 (idlwave-completing-read
6437 (format "Class%s: " (if (stringp (car info
))
6438 (format " for %s method %s"
6441 class-alist nil nil nil
'idlwave-class-history
))))))
6443 ;; Store it, if requested
6444 (when (and class
(not (eq t class
)))
6445 ;; We have a real class here
6446 (when (and store arrow
)
6448 (add-text-properties
6450 `(idlwave-class ,class face
,idlwave-class-arrow-face
6453 (setf (nth 2 info
) class
))
6456 ;; Default as fallback
6459 (defvar type-selector
)
6460 (defvar class-selector
)
6461 (defvar method-selector
)
6462 (defvar super-classes
)
6463 (defun idlwave-selector (a)
6464 (and (eq (nth 1 a
) type-selector
)
6465 (or (and (nth 2 a
) (eq class-selector t
))
6466 (eq (nth 2 a
) class-selector
)
6467 (memq (nth 2 a
) super-classes
))))
6469 (defun idlwave-add-file-link-selector (a)
6470 ;; Record a file link, if any, for the tested names during selection.
6471 (let ((sel (idlwave-selector a
)) file
)
6472 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
6473 (push (cons (car a
) file
) idlwave-completion-help-links
))
6477 (defun idlwave-where ()
6478 "Find out where we are.
6479 The return value is a list with the following stuff:
6480 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6482 PRO-LIST (PRO POINT CLASS ARROW)
6483 FUNC-LIST (FUNC POINT CLASS ARROW)
6484 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6485 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6487 LAST-CHAR last relevant character before point (non-white non-comment,
6488 not part of current identifier or leading slash).
6490 In the lists, we have these meanings:
6493 POINT: Where is this
6494 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6495 ARROW: Location of the arrow"
6497 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6498 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
6499 (func-entry (idlwave-what-function bos
))
6500 (func (car func-entry
))
6501 (func-class (nth 1 func-entry
))
6502 (func-arrow (nth 2 func-entry
))
6503 (func-point (or (nth 3 func-entry
) 0))
6504 (func-level (or (nth 4 func-entry
) 0))
6505 (pro-entry (idlwave-what-procedure bos
))
6506 (pro (car pro-entry
))
6507 (pro-class (nth 1 pro-entry
))
6508 (pro-arrow (nth 2 pro-entry
))
6509 (pro-point (or (nth 3 pro-entry
) 0))
6510 (last-char (idlwave-last-valid-char))
6511 (case-fold-search t
)
6512 (match-string (buffer-substring bos
(point)))
6513 cw cw-mod cw-arrow cw-class cw-point
)
6514 (if (< func-point pro-point
) (setq func nil
))
6516 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6520 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6522 (buffer-substring pro-point
(point))
6524 (setq cw
'procedure cw-class pro-class cw-point pro-point
6525 cw-arrow pro-arrow
))
6526 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6529 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6532 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6536 (> func-point pro-point
)
6538 (memq last-char
'(?\
( ?
,)))
6539 (setq cw
'function-keyword cw-mod func cw-point func-point
6540 cw-class func-class cw-arrow func-arrow
))
6541 ((and pro
(eq last-char ?
,))
6542 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
6543 cw-class pro-class cw-arrow pro-arrow
))
6544 ; ((member last-char '(?\' ?\) ?\] ?!))
6545 ; ;; after these chars, a function makes no sense
6546 ; ;; FIXME: I am sure there can be more in this list
6547 ; ;; FIXME: Do we want to do this at all?
6549 ;; Everywhere else we try a function.
6553 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6554 (setq cw-arrow
(copy-marker (match-beginning 0))
6555 cw-class
(if (match-end 4)
6556 (idlwave-sintern-class (match-string 4))
6558 (list (list pro pro-point pro-class pro-arrow
)
6559 (list func func-point func-class func-arrow
)
6561 (list cw-mod cw-point cw-class cw-arrow
)
6564 (defun idlwave-this-word (&optional class
)
6565 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6566 (setq class
(or class
"a-zA-Z0-9$_."))
6569 (progn (skip-chars-backward class
) (point))
6570 (progn (skip-chars-forward class
) (point)))))
6572 (defun idlwave-what-function (&optional bound
)
6573 ;; Find out if point is within the argument list of a function.
6574 ;; The return value is ("function-name" class arrow-start (point) level).
6575 ;; Level is 1 on the top level parentheses, higher further down.
6577 ;; If the optional BOUND is an integer, bound backwards directed
6578 ;; searches to this point.
6584 func arrow-start class
)
6585 (idlwave-with-special-syntax
6588 (narrow-to-region (max 1 (or bound
0)) (point-max))
6589 ;; move back out of the current parenthesis
6590 (while (condition-case nil
6591 (progn (up-list -
1) t
)
6595 (when (and (= (following-char) ?\
()
6597 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6599 (setq func
(match-string 2)
6600 func-point
(goto-char (match-beginning 2))
6602 (if (re-search-backward
6603 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6604 (setq arrow-start
(copy-marker (match-beginning 0))
6605 class
(or (match-string 2) t
)))
6609 (idlwave-sintern-routine-or-method func class
)
6610 (idlwave-sintern-class class
)
6611 arrow-start func-point cnt
)))
6613 (throw 'exit nil
)))))))
6615 (defun idlwave-what-procedure (&optional bound
)
6616 ;; Find out if point is within the argument list of a procedure.
6617 ;; The return value is ("procedure-name" class arrow-pos (point)).
6619 ;; If the optional BOUND is an integer, bound backwards directed
6620 ;; searches to this point.
6621 (let ((pos (point)) pro-point
6622 pro class arrow-start string
)
6624 ;;(idlwave-beginning-of-statement)
6625 (idlwave-start-of-substatement 'pre
)
6626 (setq string
(buffer-substring (point) pos
))
6628 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6629 (setq pro
(match-string 1 string
)
6630 pro-point
(+ (point) (match-beginning 1)))
6631 (if (and (idlwave-skip-object)
6632 (setq string
(buffer-substring (point) pos
))
6634 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6636 (setq pro
(if (match-beginning 4)
6637 (match-string 4 string
))
6638 pro-point
(if (match-beginning 4)
6639 (+ (point) (match-beginning 4))
6641 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6642 class
(or (match-string 3 string
) t
)))))
6643 (list (idlwave-sintern-routine-or-method pro class
)
6644 (idlwave-sintern-class class
)
6648 (defun idlwave-skip-object ()
6649 ;; If there is an object at point, move over it and return t.
6650 (let ((pos (point)))
6653 (skip-chars-forward " ") ; white space
6654 (skip-chars-forward "*") ; de-reference
6656 ((looking-at idlwave-identifier
)
6657 (goto-char (match-end 0)))
6658 ((eq (following-char) ?\
()
6660 (t (throw 'exit nil
)))
6663 (cond ((eq (following-char) ?.
)
6665 (if (not (looking-at idlwave-identifier
))
6667 (goto-char (match-end 0)))
6668 ((memq (following-char) '(?\
( ?\
[))
6671 (error (throw 'exit nil
))))
6672 (t (throw 'endwhile t
)))))
6673 (if (looking-at "[ \t]*->")
6674 (throw 'exit
(setq pos
(match-beginning 0)))
6675 (throw 'exit nil
))))
6679 (defun idlwave-last-valid-char ()
6680 "Return the last character before point which is not white or a comment
6681 and also not part of the current identifier. Since we do this in
6682 order to identify places where keywords are, we consider the initial
6683 `/' of a keyword as part of the identifier.
6684 This function is not general, can only be used for completion stuff."
6687 ;; skip the current identifier
6688 (skip-chars-backward "a-zA-Z0-9_$")
6689 ;; also skip a leading slash which might be belong to the keyword
6690 (if (eq (preceding-char) ?
/)
6692 ;; FIXME: does not check if this is a valid identifier
6694 (skip-chars-backward " \t")
6696 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6697 ((eq (preceding-char) ?
\n)
6698 (beginning-of-line 0)
6699 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6700 ;; continuation line
6701 (goto-char (match-end 1))
6703 (t (throw 'exit
(preceding-char))))))))
6705 (defvar idlwave-complete-after-success-form nil
6706 "A form to evaluate after successful completion.")
6707 (defvar idlwave-complete-after-success-form-force nil
6708 "A form to evaluate after completion selection in *Completions* buffer.")
6709 (defconst idlwave-completion-mark
(make-marker)
6710 "A mark pointing to the beginning of the completion string.")
6712 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6713 &optional prepare-display-function
6715 "Perform TYPE completion of word before point against LIST.
6716 SELECTOR is the PREDICATE argument for the completion function. Show
6717 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6718 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6719 used only once, for `all-completions', and can be used to, e.g.,
6720 accumulate information on matching completions."
6721 (let* ((completion-ignore-case t
)
6722 beg
(end (point)) slash part spart completion all-completions
6726 (error (concat prompt
": No completions available")))
6728 ;; What is already in the buffer?
6730 (skip-chars-backward "a-zA-Z0-9_$")
6731 (setq slash
(eq (preceding-char) ?
/)
6733 idlwave-complete-after-success-form
6734 (list 'idlwave-after-successful-completion
6735 (list 'quote type
) slash beg
)
6736 idlwave-complete-after-success-form-force
6737 (list 'idlwave-after-successful-completion
6738 (list 'quote type
) slash
(list 'quote
'force
))))
6741 (setq part
(buffer-substring beg end
)
6742 dpart
(downcase part
)
6743 spart
(idlwave-sintern stype part
)
6744 completion
(try-completion part list selector
)
6745 dcompletion
(if (stringp completion
) (downcase completion
))
6746 idlwave-completion-help-links nil
)
6749 ;; nothing available.
6750 (error (concat prompt
": no completion for \"%s\"") part
))
6751 ((and (not (equal dpart dcompletion
))
6752 (not (eq t completion
)))
6753 ;; We can add something
6754 (delete-region beg end
)
6755 (if (and (string= part dpart
)
6756 (or (not (string= part
""))
6757 idlwave-complete-empty-string-as-lower-case
)
6758 (not idlwave-completion-force-default-case
))
6759 (insert dcompletion
)
6760 (insert completion
))
6761 (if (eq t
(try-completion completion list selector
))
6762 ;; Now this is a unique match
6763 (idlwave-after-successful-completion type slash beg
))
6765 ((or (eq completion t
)
6766 (and (= 1 (length (setq all-completions
6768 (all-completions part list
6769 (or special-selector
6771 (equal dpart dcompletion
)))
6772 ;; This is already complete
6773 (idlwave-after-successful-completion type slash beg
)
6774 (message "%s is already the complete %s" part isa
)
6777 ;; We cannot add something - offer a list.
6778 (message "Making completion list...")
6780 (unless idlwave-completion-help-links
; already set somewhere?
6781 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6782 (let ((link (get-text-property 0 'link
(car x
))))
6784 (push (cons (car x
) link
)
6785 idlwave-completion-help-links
))))
6787 (let* ((list all-completions
)
6788 ;; "complete" means, this is already a valid completion
6789 (complete (memq spart all-completions
))
6790 (completion-highlight-first-word-only t
)) ; XEmacs
6791 ; (completion-fixup-function ; Emacs
6792 ; (lambda () (and (eq (preceding-char) ?>)
6793 ; (re-search-backward " <" beg t)))))
6795 (setq list
(sort list
(lambda (a b
)
6796 (string< (downcase a
) (downcase b
)))))
6797 (if prepare-display-function
6798 (setq list
(funcall prepare-display-function list
)))
6799 (if (and (string= part dpart
)
6800 (or (not (string= part
""))
6801 idlwave-complete-empty-string-as-lower-case
)
6802 (not idlwave-completion-force-default-case
))
6803 (setq list
(mapcar (lambda (x)
6805 (setcar x
(downcase (car x
)))
6806 (setq x
(downcase x
)))
6809 (idlwave-display-completion-list list prompt beg complete
))
6812 (defun idlwave-complete-class ()
6813 "Complete a class at point."
6815 ;; Call `idlwave-routines' to make sure the class list will be available
6817 ;; Check for the special case of completing empty string after pro/function
6818 (if (let ((case-fold-search t
))
6821 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6823 (goto-char (point-min))
6825 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6826 ;; Yank the full class specification
6827 (insert (match-string 2))
6828 ;; Do the completion, using list gathered from `idlwave-routines'
6829 (idlwave-complete-in-buffer
6830 'class
'class
(idlwave-class-alist) nil
6831 "Select a class" "class"
6832 '(lambda (list) ;; Push it to help-links if system help available
6834 (let* ((entry (idlwave-class-info x
))
6835 (link (nth 1 (assq 'link entry
))))
6836 (if link
(push (cons x link
)
6837 idlwave-completion-help-links
))
6841 (defun idlwave-attach-classes (list type show-classes
)
6842 ;; Attach the proper class list to a LIST of completion items.
6843 ;; TYPE, when 'kwd, shows classes for method keywords, when
6844 ;; 'class-tag, for class tags, and otherwise for methods.
6845 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6846 (if (or (null show-classes
) ; don't want to see classes
6847 (null class-selector
) ; not a method call
6849 (stringp class-selector
) ; the class is already known
6850 (not super-classes
))) ; no possibilities for inheritance
6851 ;; In these cases, we do not have to do anything
6853 (let* ((do-prop (and (>= show-classes
0)
6854 (>= emacs-major-version
21)))
6855 (do-buf (not (= show-classes
0)))
6856 ;; (do-dots (featurep 'xemacs))
6858 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6859 (cons class-selector super-classes
)))
6860 (max (abs show-classes
))
6861 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6862 classes nclasses class-info space
)
6866 (if (eq type
'class-tag
)
6867 ;; Just one class for tags
6870 (idlwave-class-or-superclass-with-tag class-selector x
)))
6871 ;; Multiple classes for method or method-keyword
6874 (idlwave-all-method-keyword-classes
6875 method-selector x type-selector
)
6876 (idlwave-all-method-classes x type-selector
)))
6880 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6882 (setq nclasses
(length classes
))
6883 ;; Make the separator between item and class-info
6885 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6888 ;; We do want info in the buffer
6889 (if (<= nclasses max
)
6890 (setq class-info
(concat
6892 "<" (mapconcat 'identity classes
",") ">"))
6893 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6894 (setq class-info nil
))
6896 ;; We do want properties
6897 (setq x
(copy-sequence x
))
6898 (put-text-property 0 (length x
)
6899 'help-echo
(mapconcat 'identity classes
" ")
6906 (defun idlwave-attach-method-classes (list)
6907 ;; Call idlwave-attach-classes with method parameters
6908 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6909 (defun idlwave-attach-keyword-classes (list)
6910 ;; Call idlwave-attach-classes with keyword parameters
6911 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6912 (defun idlwave-attach-class-tag-classes (list)
6913 ;; Call idlwave-attach-classes with class structure tags
6914 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6917 ;;----------------------------------------------------------------------
6918 ;;----------------------------------------------------------------------
6919 ;;----------------------------------------------------------------------
6920 ;;----------------------------------------------------------------------
6921 ;;----------------------------------------------------------------------
6923 (defun idlwave-pset (item)
6926 (defun idlwave-popup-select (ev list title
&optional sort
)
6927 "Select an item in LIST with a popup menu.
6928 TITLE is the title to put atop the popup. If SORT is non-nil,
6929 sort the list before displaying"
6930 (let ((maxpopup idlwave-max-popup-menu-items
)
6933 ((= 1 (length list
))
6934 (setq rtn
(car list
)))
6936 (if sort
(setq list
(sort list
(lambda (a b
)
6937 (string< (upcase a
) (upcase b
))))))
6939 (append (list title
)
6940 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6943 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6944 (setq resp
(get-popup-menu-response menu
))
6945 (funcall (event-function resp
) (event-object resp
)))
6947 (if sort
(setq list
(sort list
(lambda (a b
)
6948 (string< (upcase a
) (upcase b
))))))
6949 (setq menu
(cons title
6952 (mapcar (lambda(x) (cons x x
)) list
)))))
6953 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6954 (setq rtn
(x-popup-menu ev menu
))))
6957 (defun idlwave-split-menu-xemacs (menu N
)
6958 "Split the MENU into submenus of maximum length N."
6959 (if (<= (length menu
) (1+ N
))
6960 ;; No splitting needed
6962 (let* ((title (car menu
))
6963 (entries (cdr menu
))
6968 (while (and entries
(< cnt N
))
6970 nextmenu
(cons (car entries
) nextmenu
)
6971 entries
(cdr entries
)))
6972 (setq nextmenu
(nreverse nextmenu
))
6973 (setq nextmenu
(cons (format "%s...%s"
6974 (aref (car nextmenu
) 0)
6975 (aref (nth (1- cnt
) nextmenu
) 0))
6977 (setq menu
(cons nextmenu menu
)
6982 (defun idlwave-split-menu-emacs (menu N
)
6983 "Split the MENU into submenus of maximum length N."
6984 (if (<= (length (nth 1 menu
)) (1+ N
))
6985 ;; No splitting needed
6987 (let* ((title (car menu
))
6988 (entries (cdr (nth 1 menu
)))
6993 (while (and entries
(< cnt N
))
6995 nextmenu
(cons (car entries
) nextmenu
)
6996 entries
(cdr entries
)))
6997 (setq nextmenu
(nreverse nextmenu
))
6999 (setq nextmenu
(cons (format "%s...%s"
7000 (car (car nextmenu
))
7001 (car (nth (1- cnt
) nextmenu
)))
7003 (setq menu
(cons nextmenu menu
)
7006 (setq menu
(nreverse menu
))
7007 (setq menu
(cons title menu
))
7010 (defvar idlwave-completion-setup-hook nil
)
7012 (defun idlwave-scroll-completions (&optional message
)
7013 "Scroll the completion window on this frame."
7014 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
7015 (win (selected-window)))
7018 (select-window cwin
)
7021 (error (if (and (listp last-command
)
7022 (nth 2 last-command
))
7025 (eval idlwave-complete-after-success-form
))
7026 (set-window-start cwin
(point-min)))))
7027 (and message
(message "%s" message
)))
7028 (select-window win
))))
7030 (defun idlwave-display-completion-list (list &optional message beg complete
)
7031 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7032 (unless (and (get-buffer-window "*Completions*")
7033 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
7034 (move-marker idlwave-completion-mark beg
)
7035 (setq idlwave-before-completion-wconf
(current-window-configuration)))
7037 (if (featurep 'xemacs
)
7038 (idlwave-display-completion-list-xemacs
7040 (idlwave-display-completion-list-emacs list
))
7042 ;; Store a special value in `this-command'. When `idlwave-complete'
7043 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7044 (setq this-command
(list 'idlwave-display-completion-list message complete
))
7046 ;; Mark the completions buffer as created by cib
7047 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
7049 ;; Fontify the classes
7050 (if (and idlwave-completion-fontify-classes
7052 (idlwave-completion-fontify-classes))
7055 (run-hooks 'idlwave-completion-setup-hook
)
7057 ;; Display the message
7058 (message "%s" (or message
"Making completion list...done")))
7060 (defun idlwave-choose (function &rest args
)
7061 "Call FUNCTION as a completion chooser and pass ARGS to it."
7062 (let ((completion-ignore-case t
)) ; install correct value
7063 (apply function args
))
7064 (if (and (eq major-mode
'idlwave-shell-mode
)
7065 (boundp 'font-lock-mode
)
7066 (not font-lock-mode
))
7067 ;; For the shell, remove the fontification of the word before point
7068 (let ((beg (save-excursion
7069 (skip-chars-backward "a-zA-Z0-9_")
7071 (remove-text-properties beg
(point) '(face nil
))))
7072 (eval idlwave-complete-after-success-form-force
))
7074 (defun idlwave-keyboard-quit ()
7077 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
7078 (idlwave-restore-wconf-after-completion))
7081 (defun idlwave-restore-wconf-after-completion ()
7082 "Restore the old (before completion) window configuration."
7083 (and idlwave-completion-restore-window-configuration
7084 idlwave-before-completion-wconf
7085 (set-window-configuration idlwave-before-completion-wconf
)))
7087 (defun idlwave-one-key-select (sym prompt delay
)
7088 "Make the user select an element from the alist in the variable SYM.
7089 The keys of the alist are expected to be strings. The function returns the
7090 car of the selected association.
7091 To do this, PROMPT is displayed and the user must hit a letter key to
7092 select an entry. If the user does not reply within DELAY seconds, a help
7093 window with the options is displayed automatically.
7094 The key which is associated with each option is generated automatically.
7095 First, the strings are checked for preselected keys, like in \"[P]rint\".
7096 If these don't exist, a letter in the string is automatically selected."
7097 (let* ((alist (symbol-value sym
))
7098 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
7099 '(fit-window-to-buffer)))
7101 ;; First check the cache
7102 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
7103 (setq keys-alist
(get sym
:one-key-alist-cache
))
7104 ;; Need to make new list
7105 (setq keys-alist
(idlwave-make-one-key-alist alist
))
7106 (put sym
:one-key-alist-cache keys-alist
)
7107 (put sym
:one-key-alist-last alist
))
7108 ;; Display prompt and wait for quick reply
7109 (message "%s[%s]" prompt
7110 (mapconcat (lambda(x) (char-to-string (car x
)))
7113 ;; No quick reply: Show help
7114 (save-window-excursion
7115 (with-output-to-temp-buffer "*Completions*"
7120 (setq char
(read-char)))
7121 (setq char
(read-char)))
7123 ;; Return the selected result
7124 (nth 2 (assoc char keys-alist
))))
7126 ;; Used for, e.g., electric debug super-examine.
7127 (defun idlwave-make-one-key-alist (alist)
7128 "Make an alist for single key selection."
7129 (let ((l alist
) keys-alist name start char help
7131 (case-fold-search nil
))
7133 (setq name
(car (car l
))
7136 ;; First check if the configuration predetermined a key
7137 (if (string-match "\\[\\(.\\)\\]" name
)
7139 (setq char
(string-to-char (downcase (match-string 1 name
)))
7140 help
(format "%c: %s" char name
)
7141 keys-alist
(cons (list char help name
) keys-alist
))
7143 ;; Then check for capital letters
7145 (while (string-match "[A-Z]" name start
)
7146 (setq start
(match-end 0)
7147 char
(string-to-char (downcase (match-string 0 name
))))
7148 (if (not (assoc char keys-alist
))
7150 (setq help
(format "%c: %s" char
7152 (concat "[" (match-string 0 name
) "]")
7154 keys-alist
(cons (list char help name
) keys-alist
))
7156 ;; Now check for lowercase letters
7158 (while (string-match "[a-z]" name start
)
7159 (setq start
(match-end 0)
7160 char
(string-to-char (match-string 0 name
)))
7161 (if (not (assoc char keys-alist
))
7163 (setq help
(format "%c: %s" char
7165 (concat "[" (match-string 0 name
) "]")
7167 keys-alist
(cons (list char help name
) keys-alist
))
7169 ;; Bummer, nothing found! Use a stupid number
7170 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
7171 help
(format "%c: %s" char name
)
7172 keys-alist
(cons (list char help name
) keys-alist
))))
7173 (nreverse keys-alist
)))
7175 (defun idlwave-set-local (var value
&optional buffer
)
7176 "Set the buffer-local value of VAR in BUFFER to VALUE."
7178 (set-buffer (or buffer
(current-buffer)))
7179 (set (make-local-variable var
) value
)))
7181 (defun idlwave-local-value (var &optional buffer
)
7182 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7184 (set-buffer (or buffer
(current-buffer)))
7185 (and (local-variable-p var
(current-buffer))
7186 (symbol-value var
))))
7188 ;; In XEmacs, we can use :activate-callback directly to advice the
7189 ;; choose functions. We use the private keymap only for the online
7192 (defvar idlwave-completion-map nil
7193 "Keymap for completion-list-mode with idlwave-complete.")
7195 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
7196 (with-output-to-temp-buffer "*Completions*"
7197 (apply 'display-completion-list list
7198 ':activate-callback
'idlwave-default-choose-completion
7201 (set-buffer "*Completions*")
7203 (or idlwave-completion-map
7204 (setq idlwave-completion-map
7205 (idlwave-make-modified-completion-map-xemacs
7206 (current-local-map)))))))
7208 (defun idlwave-default-choose-completion (&rest args
)
7209 "Execute `default-choose-completion' and then restore the win-conf."
7210 (apply 'idlwave-choose
'default-choose-completion args
))
7212 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7213 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7214 (let ((new-map (copy-keymap old-map
)))
7215 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
7216 (define-key new-map [button3] (lambda ()
7218 (setq this-command last-command)))
7221 ;; In Emacs we also replace keybindings in the completion
7222 ;; map in order to install our wrappers.
7224 (defun idlwave-display-completion-list-emacs (list)
7225 "Display completion list and install the choose wrappers."
7226 (with-output-to-temp-buffer "*Completions*"
7227 (display-completion-list list))
7229 (set-buffer "*Completions*")
7231 (or idlwave-completion-map
7232 (setq idlwave-completion-map
7233 (idlwave-make-modified-completion-map-emacs
7234 (current-local-map)))))))
7236 (defun idlwave-make-modified-completion-map-emacs (old-map)
7237 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7238 (let ((new-map (copy-keymap old-map)))
7239 (substitute-key-definition
7240 'choose-completion 'idlwave-choose-completion new-map)
7241 (substitute-key-definition
7242 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7243 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7246 (defun idlwave-choose-completion (&rest args)
7247 "Choose the completion that point is in or next to."
7249 (apply 'idlwave-choose 'choose-completion args))
7251 (defun idlwave-mouse-choose-completion (&rest args)
7252 "Click on an alternative in the `*Completions*' buffer to choose it."
7254 (apply 'idlwave-choose 'mouse-choose-completion args))
7256 ;;----------------------------------------------------------------------
7257 ;;----------------------------------------------------------------------
7259 ;;; ------------------------------------------------------------------------
7260 ;;; Stucture parsing code, and code to manage class info
7263 ;; - Go again over the documentation how to write a completion
7264 ;; plugin. It is in self.el, but currently still very bad.
7265 ;; This could be in a separate file in the distribution, or
7266 ;; in an appendix for the manual.
7268 (defvar idlwave-struct-skip
7269 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7270 "Regexp for skipping continued blank or comment-only lines in
7273 (defvar idlwave-struct-tag-regexp
7274 (concat "[{,]" ;leading comma/brace
7275 idlwave-struct-skip ; 4 groups
7276 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7277 "[ \t]*:") ; the final colon
7278 "Regexp for structure tags.")
7280 (defun idlwave-struct-tags ()
7281 "Return a list of all tags in the structure defined at point.
7282 Point is expected just before the opening `{' of the struct definition."
7284 (let* ((borders (idlwave-struct-borders))
7290 (narrow-to-region beg end)
7291 (while (re-search-forward idlwave-struct-tag-regexp end t)
7292 ;; Check if we are still on the top level of the structure.
7293 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7295 (push (match-string-no-properties 5) tags))
7296 (goto-char (match-end 0))))
7299 (defun idlwave-find-struct-tag (tag)
7300 "Find a given TAG in the structure defined at point."
7301 (let* ((borders (idlwave-struct-borders))
7304 (case-fold-search t))
7305 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7308 (defun idlwave-struct-inherits ()
7309 "Return a list of all `inherits' names in the struct at point.
7310 Point is expected just before the opening `{' of the struct definition."
7312 (let* ((borders (idlwave-struct-borders))
7315 (case-fold-search t)
7319 (narrow-to-region beg end)
7320 (while (re-search-forward
7321 (concat "[{,]" ;leading comma/brace
7322 idlwave-struct-skip ; 4 groups
7323 "inherits" ; The INHERITS tag
7324 idlwave-struct-skip ; 4 more
7325 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7327 ;; Check if we are still on the top level of the structure.
7328 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7330 (push (match-string-no-properties 9) names))
7331 (goto-char (match-end 0))))
7334 (defun idlwave-in-structure ()
7335 "Return t if point is inside an IDL structure definition."
7336 (let ((beg (point)))
7338 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7339 (if (idlwave-find-structure-definition nil nil 'back)
7340 (let ((borders (idlwave-struct-borders)))
7341 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7342 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7344 (defun idlwave-struct-borders ()
7345 "Return the borders of the {...} after point as a cons cell."
7348 (skip-chars-forward "^{")
7350 (condition-case nil (forward-list 1)
7351 (error (goto-char beg)))
7352 (cons beg (point)))))
7354 (defun idlwave-find-structure-definition (&optional var name bound)
7355 "Search forward for a structure definition. If VAR is non-nil,
7356 search for a structure assigned to variable VAR. If NAME is non-nil,
7357 search for a named structure NAME, if a string, or a generic named
7358 structure otherwise. If BOUND is an integer, limit the search. If
7359 BOUND is the symbol `all', we search first back and then forward
7360 through the entire file. If BOUND is the symbol `back' we search only
7362 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7363 (case-fold-search t)
7364 (lim (if (integerp bound) bound nil))
7367 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7372 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7373 ;; Just a generic name
7374 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7376 (if (or (and (or (eq bound 'all) (eq bound 'back))
7377 (re-search-backward re nil t))
7378 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7380 (goto-char (match-beginning 3))
7381 (match-string-no-properties 5)))))
7383 (defvar idlwave-class-info nil)
7384 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7386 (add-hook 'idlwave-update-rinfo-hook
7387 (lambda () (setq idlwave-class-reset t)))
7388 (add-hook 'idlwave-after-load-rinfo-hook
7389 (lambda () (setq idlwave-class-info nil)))
7391 (defun idlwave-class-info (class)
7393 (if idlwave-class-info
7394 (if idlwave-class-reset
7396 idlwave-class-reset nil
7397 idlwave-class-info ; Remove any visited in a buffer
7401 (idlwave-class-file-or-buffer
7402 (or (cdr (assq 'found-in x)) (car x)))))
7406 idlwave-class-info))))
7407 ;; Info is nil, put in the system stuff to start.
7408 (setq idlwave-class-info idlwave-system-class-info)
7409 (setq list idlwave-class-info)
7410 (while (setq entry (pop list))
7411 (idlwave-sintern-class-info entry)))
7412 (setq class (idlwave-sintern-class class))
7413 (or (assq class idlwave-class-info)
7414 (progn (idlwave-scan-class-info class)
7415 (assq class idlwave-class-info)))))
7417 (defun idlwave-sintern-class-info (entry)
7418 "Sintern the class names in a class-info entry."
7419 (let ((taglist (assq 'tags entry))
7420 (inherits (assq 'inherits entry)))
7421 (setcar entry (idlwave-sintern-class (car entry) 'set))
7423 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7426 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7427 "Find class structure definition(s)
7428 If ALL-HOOK is set, find all named structure definitions in a given
7429 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7430 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7431 class/struct definition"
7432 (let ((case-fold-search t) end-lim list name)
7433 (when (re-search-forward
7434 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7437 ;; For everything there
7438 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7440 (idlwave-find-structure-definition nil t end-lim))
7441 (funcall all-hook name)))
7442 (idlwave-find-structure-definition nil (or alt-class class))))))
7445 (defun idlwave-class-file-or-buffer (class)
7446 "Find buffer visiting CLASS definition"
7447 (let* ((pro (concat (downcase class) "__define"))
7448 (file (idlwave-routine-source-file
7449 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7450 (idlwave-routines))))))
7451 (cons file (if file (idlwave-get-buffer-visiting file)))))
7454 (defun idlwave-scan-class-info (class)
7455 "Scan all class and named structure info in the class__define pro"
7456 (let* ((idlwave-auto-routine-info-updates nil)
7457 (filebuf (idlwave-class-file-or-buffer class))
7458 (file (car filebuf))
7460 (class (idlwave-sintern-class class)))
7463 (and ;; neither a regular file nor a visited buffer
7465 (not (file-regular-p file))))
7466 nil ; Cannot find the file/buffer to get any info
7468 (if buf (set-buffer buf)
7469 ;; Read the file in temporarily
7470 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7472 (unless (eq major-mode 'idlwave-mode)
7474 (insert-file-contents file))
7477 (idlwave-find-class-definition class
7478 ;; Scan all of the structures found there
7480 (let* ((this-class (idlwave-sintern-class name))
7483 (cons 'tags (idlwave-struct-tags))
7484 (cons 'inherits (idlwave-struct-inherits)))))
7485 (if (not (eq this-class class))
7486 (setq entry (nconc entry (list (cons 'found-in class)))))
7487 (idlwave-sintern-class-info entry)
7488 (push entry idlwave-class-info)))))))))
7490 (defun idlwave-class-found-in (class)
7491 "Return the FOUND-IN property of the class."
7492 (cdr (assq 'found-in (idlwave-class-info class))))
7493 (defun idlwave-class-tags (class)
7494 "Return the native tags in CLASS."
7495 (cdr (assq 'tags (idlwave-class-info class))))
7496 (defun idlwave-class-inherits (class)
7497 "Return the direct superclasses of CLASS."
7498 (cdr (assq 'inherits (idlwave-class-info class))))
7501 (defun idlwave-all-class-tags (class)
7502 "Return a list of native and inherited tags in CLASS."
7504 (apply 'append (mapcar 'idlwave-class-tags
7505 (cons class (idlwave-all-class-inherits class))))
7507 (idlwave-class-tag-reset)
7508 (error "%s" (error-message-string err)))))
7511 (defun idlwave-all-class-inherits (class)
7512 "Return a list of all superclasses of CLASS (recursively expanded).
7513 The list is cached in `idlwave-class-info' for faster access."
7515 ((not idlwave-support-inheritance) nil)
7516 ((eq class nil) nil)
7519 (let ((info (idlwave-class-info class))
7521 (if (setq entry (assq 'all-inherits info))
7523 ;; Save the depth of inheritance scan to check for circular references
7524 (let ((inherits (mapcar (lambda (x) (cons x 0))
7525 (idlwave-class-inherits class)))
7526 rtn all-inherits cl)
7528 (setq cl (pop inherits)
7529 rtn (cons (car cl) rtn)
7530 inherits (append (mapcar (lambda (x)
7531 (cons x (1+ (cdr cl))))
7532 (idlwave-class-inherits (car cl)))
7534 (if (> (cdr cl) 999)
7536 "Class scan: inheritance depth exceeded. Circular inheritance?")
7538 (setq all-inherits (nreverse rtn))
7539 (nconc info (list (cons 'all-inherits all-inherits)))
7542 (defun idlwave-entry-keywords (entry &optional record-link)
7543 "Return the flat entry keywords alist from routine-info entry.
7544 If RECORD-LINK is non-nil, the keyword text is copied and a text
7545 property indicating the link is added."
7549 (let ((file (car key-list)))
7550 (mapcar (lambda (key-cons)
7551 (let ((key (car key-cons))
7552 (link (cdr key-cons)))
7553 (when (and record-link file)
7554 (setq key (copy-sequence key))
7561 (concat idlwave-html-link-sep
7562 (number-to-string link))))
7564 (push (list key) kwds)))
7569 (defun idlwave-entry-find-keyword (entry keyword)
7570 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7574 (let ((file (car key-list))
7575 (kwd (assoc keyword (cdr key-list))))
7577 (setq kwd (cons (car kwd)
7578 (if (and file (cdr kwd))
7580 idlwave-html-link-sep
7581 (number-to-string (cdr kwd)))
7583 (throw 'exit kwd))))
7586 ;;==========================================================================
7588 ;; Completing class structure tags. This is a completion plugin.
7589 ;; The necessary taglist is constructed dynamically
7591 (defvar idlwave-current-tags-class nil)
7592 (defvar idlwave-current-class-tags nil)
7593 (defvar idlwave-current-native-class-tags nil)
7594 (defvar idlwave-sint-class-tags nil)
7595 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7596 (idlwave-new-sintern-type 'class-tag)
7597 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7598 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7600 (defun idlwave-complete-class-structure-tag ()
7601 "Complete a structure tag on a `self' argument in an object method."
7604 (case-fold-search t))
7606 ;; Check if the context is right
7607 (skip-chars-backward "a-zA-Z0-9._$")
7608 (and (< (point) (- pos 4))
7609 (looking-at "self\\.")))
7610 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7611 (super-classes (idlwave-all-class-inherits class-selector)))
7612 ;; Check if we are in a class routine
7613 (unless class-selector
7614 (error "Not in a method procedure or function"))
7615 ;; Check if we need to update the "current" class
7616 (if (not (equal class-selector idlwave-current-tags-class))
7617 (idlwave-prepare-class-tag-completion class-selector))
7618 (setq idlwave-completion-help-info
7619 (list 'idlwave-complete-class-structure-tag-help
7620 (idlwave-sintern-routine
7621 (concat class-selector "__define"))
7623 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7624 (idlwave-complete-in-buffer
7625 'class-tag 'class-tag
7626 idlwave-current-class-tags nil
7627 (format "Select a tag of class %s" class-selector)
7629 'idlwave-attach-class-tag-classes))
7630 t) ; return t to skip other completions
7633 (defun idlwave-class-tag-reset ()
7634 (setq idlwave-current-tags-class nil))
7636 (defun idlwave-prepare-class-tag-completion (class)
7637 "Find and parse the necessary class definitions for class structure tags."
7638 (setq idlwave-sint-class-tags nil)
7639 (setq idlwave-current-tags-class class)
7640 (setq idlwave-current-class-tags
7642 (list (idlwave-sintern-class-tag x 'set)))
7643 (idlwave-all-class-tags class)))
7644 (setq idlwave-current-native-class-tags
7645 (mapcar 'downcase (idlwave-class-tags class))))
7647 ;===========================================================================
7649 ;; Completing system variables and their structure fields
7650 ;; This is also a plugin.
7652 (defvar idlwave-sint-sysvars nil)
7653 (defvar idlwave-sint-sysvartags nil)
7654 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7655 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7656 (idlwave-new-sintern-type 'sysvar)
7657 (idlwave-new-sintern-type 'sysvartag)
7658 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7659 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7660 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7663 (defun idlwave-complete-sysvar-or-tag ()
7664 "Complete a system variable."
7667 (case-fold-search t))
7668 (cond ((save-excursion
7669 ;; Check if the context is right for system variable
7670 (skip-chars-backward "[a-zA-Z0-9_$]")
7671 (equal (char-before) ?!))
7672 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7673 (idlwave-complete-in-buffer 'sysvar 'sysvar
7674 idlwave-system-variables-alist nil
7675 "Select a system variable"
7677 t) ; return t to skip other completions
7679 ;; Check if the context is right for sysvar tag
7680 (skip-chars-backward "a-zA-Z0-9_$.")
7681 (and (equal (char-before) ?!)
7682 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7683 (<= (match-end 0) pos)))
7684 ;; Complete a system variable tag
7685 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7686 (entry (assq var idlwave-system-variables-alist))
7687 (tags (cdr (assq 'tags entry))))
7688 (or entry (error "!%s is not a known system variable" var))
7689 (or tags (error "System variable !%s is not a structure" var))
7690 (setq idlwave-completion-help-info
7691 (list 'idlwave-complete-sysvar-tag-help var))
7692 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7694 "Select a system variable tag"
7695 "system variable tag")
7696 t)) ; return t to skip other completions
7699 (defvar link) ;dynamic variables set by help callback
7701 (defun idlwave-complete-sysvar-help (mode word)
7702 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7703 (entry (assoc word idlwave-system-variables-alist)))
7706 (and (stringp word) entry (nth 1 (assq 'link entry))))
7708 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7709 (t (error "This should not happen")))))
7711 (defun idlwave-complete-sysvar-tag-help (mode word)
7712 (let* ((var (nth 1 idlwave-completion-help-info))
7713 (entry (assoc var idlwave-system-variables-alist))
7714 (tags (cdr (assq 'tags entry)))
7715 (main (nth 1 (assq 'link entry)))
7718 ((eq mode 'test) ; we can at least link the main
7719 (and (stringp word) entry main))
7723 (if (setq target (cdr (assoc-string word tags t)))
7724 (idlwave-substitute-link-target main target)
7725 main)))) ;; setting dynamic!!!
7726 (t (error "This should not happen")))))
7728 (defun idlwave-split-link-target (link)
7729 "Split a given link into link file and anchor."
7730 (if (string-match idlwave-html-link-sep link)
7731 (cons (substring link 0 (match-beginning 0))
7732 (string-to-number (substring link (match-end 0))))))
7734 (defun idlwave-substitute-link-target (link target)
7735 "Substitute the target anchor for the given link."
7737 (setq main-base (if (string-match "#" link)
7738 (substring link 0 (match-beginning 0))
7741 (concat main-base idlwave-html-link-sep (number-to-string target))
7744 ;; Fake help in the source buffer for class structure tags.
7745 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7748 (defvar idlwave-help-do-class-struct-tag nil)
7749 (defun idlwave-complete-class-structure-tag-help (mode word)
7751 ((eq mode 'test) ; nothing gets fontified for class tags
7754 (let (class-with found-in)
7755 (when (setq class-with
7756 (idlwave-class-or-superclass-with-tag
7757 idlwave-current-tags-class
7759 (if (assq (idlwave-sintern-class class-with)
7760 idlwave-system-class-info)
7761 (error "No help available for system class tags"))
7762 (if (setq found-in (idlwave-class-found-in class-with))
7763 (setq name (cons (concat found-in "__define") class-with))
7764 (setq name (concat class-with "__define")))))
7766 idlwave-help-do-class-struct-tag t))
7767 (t (error "This should not happen"))))
7769 (defun idlwave-class-or-superclass-with-tag (class tag)
7770 "Find and return the CLASS or one of its superclass with the
7771 associated TAG, if any."
7772 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7776 (setq cl (pop sclasses))
7777 (let ((tags (idlwave-class-tags cl)))
7779 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7781 (setq tags (cdr tags))))))))
7784 (defun idlwave-sysvars-reset ()
7785 (if (and (fboundp 'idlwave-shell-is-running)
7786 (idlwave-shell-is-running)
7787 idlwave-idlwave_routine_info-compiled)
7788 (idlwave-shell-send-command "idlwave_get_sysvars"
7789 'idlwave-process-sysvars 'hide)))
7791 (defun idlwave-process-sysvars ()
7792 (idlwave-shell-filter-sysvars)
7793 (setq idlwave-sint-sysvars nil
7794 idlwave-sint-sysvartags nil)
7795 (idlwave-sintern-sysvar-alist))
7797 (defun idlwave-sintern-sysvar-alist ()
7798 (let ((list idlwave-system-variables-alist) entry tags)
7799 (while (setq entry (pop list))
7800 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7801 (setq tags (assq 'tags entry))
7805 (cons (idlwave-sintern-sysvartag (car x) 'set)
7809 (defvar idlwave-shell-command-output)
7810 (defun idlwave-shell-filter-sysvars ()
7811 "Get any new system variables and tags."
7812 (let ((text idlwave-shell-command-output)
7814 (old idlwave-system-variables-alist)
7815 var tags type name class link old-entry)
7816 (setq idlwave-system-variables-alist nil)
7817 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7819 (setq start (match-end 0)
7820 var (match-string 1 text)
7821 tags (if (match-end 3)
7822 (idlwave-split-string (match-string 3 text))))
7823 ;; Maintain old links, if present
7824 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7825 (setq link (assq 'link old-entry))
7826 (setq idlwave-system-variables-alist
7833 (idlwave-sintern-sysvartag x)
7834 (cdr (assq 'tags old-entry))))))
7836 idlwave-system-variables-alist)))
7837 ;; Keep the old value if query was not successful
7838 (setq idlwave-system-variables-alist
7839 (or idlwave-system-variables-alist old))))
7841 (defun idlwave-completion-fontify-classes ()
7842 "Goto the *Completions* buffer and fontify the class info."
7843 (when (featurep 'font-lock)
7845 (set-buffer "*Completions*")
7847 (goto-char (point-min))
7848 (let ((buffer-read-only nil))
7849 (while (re-search-forward "\\.*<[^>]+>" nil t)
7850 (put-text-property (match-beginning 0) (match-end 0)
7851 'face 'font-lock-string-face)))))))
7853 (defun idlwave-uniquify (list)
7854 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7857 (unless (gethash x ht)
7862 (defun idlwave-after-successful-completion (type slash &optional verify)
7863 "Add `=' or `(' after successful completion of keyword and function.
7864 Restore the pre-completion window configuration if possible."
7866 ((eq type 'procedure)
7868 ((eq type 'function)
7870 ((equal idlwave-function-completion-adds-paren nil) nil)
7871 ((or (equal idlwave-function-completion-adds-paren t)
7872 (equal idlwave-function-completion-adds-paren 1))
7874 ((equal idlwave-function-completion-adds-paren 2)
7879 (if (and idlwave-keyword-completion-adds-equal
7881 (progn (insert "=") t)
7884 ;; Restore the pre-completion window configuration if this is safe.
7886 (if (or (eq verify 'force) ; force
7888 (get-buffer-window "*Completions*") ; visible
7889 (idlwave-local-value 'idlwave-completion-p
7890 "*Completions*") ; cib-buffer
7891 (eq (marker-buffer idlwave-completion-mark)
7892 (current-buffer)) ; buffer OK
7893 (equal (marker-position idlwave-completion-mark)
7895 (idlwave-restore-wconf-after-completion))
7896 (move-marker idlwave-completion-mark nil)
7897 (setq idlwave-before-completion-wconf nil))
7899 (defun idlwave-mouse-context-help (ev &optional arg)
7900 "Call `idlwave-context-help' on the clicked location."
7902 (mouse-set-point ev)
7903 (idlwave-context-help arg))
7905 (defvar idlwave-last-context-help-pos nil)
7906 (defun idlwave-context-help (&optional arg)
7907 "Display IDL Online Help on context.
7908 If point is on a keyword, help for that keyword will be shown. If
7909 point is on a routine name or in the argument list of a routine, help
7910 for that routine will be displayed. Works for system routines and
7911 keywords, it pulls up text help. For other routies and keywords,
7912 visits the source file, finding help in the header (if
7913 `idlwave-help-source-try-header' is non-nil) or the routine definition
7916 (idlwave-do-context-help arg))
7918 (defun idlwave-mouse-completion-help (ev)
7919 "Display online help about the completion at point."
7921 ;; Restore last-command for next command, to make
7922 ;; scrolling/cancelling of completions work.
7923 (setq this-command last-command)
7924 (idlwave-do-mouse-completion-help ev))
7926 (defun idlwave-routine-info (&optional arg external)
7927 "Display a routines calling sequence and list of keywords. When
7928 point is on the name a function or procedure, or in the argument list
7929 of a function or procedure, this command displays a help buffer with
7930 the information. When called with prefix arg, enforce class query.
7932 When point is on an object operator `->', display the class stored in
7933 this arrow, if any (see `idlwave-store-inquired-class'). With a
7934 prefix arg, the class property is cleared out."
7938 (if (string-match "->" (buffer-substring
7939 (max (point-min) (1- (point)))
7940 (min (+ 2 (point)) (point-max))))
7941 ;; Cursor is on an arrow
7942 (if (get-text-property (point) 'idlwave-class)
7943 ;; arrow has class property
7948 (when (looking-at ".?\\(->\\)")
7949 (remove-text-properties (match-beginning 1) (match-end 1)
7950 '(idlwave-class nil face nil))
7951 (message "Class property removed from arrow")))
7952 ;; Echo class property
7953 (message "Arrow has text property identifying object to be class %s"
7954 (get-text-property (point) 'idlwave-class)))
7955 ;; No property found
7956 (message "Arrow has no class text property"))
7958 ;; Not on an arrow...
7959 (let* ((idlwave-query-class nil)
7960 (idlwave-force-class-query (equal arg '(4)))
7961 (module (idlwave-what-module)))
7963 (apply 'idlwave-display-calling-sequence
7964 (idlwave-fix-module-if-obj_new module))
7965 (error "Don't know which calling sequence to show")))))
7967 (defun idlwave-resolve (&optional arg)
7968 "Call RESOLVE_ROUTINE on the module name at point.
7969 Like `idlwave-routine-info', this looks for a routine call at point.
7970 After confirmation in the minibuffer, it will use the shell to issue
7971 a RESOLVE call for this routine, to attempt to make it defined and its
7972 routine info available for IDLWAVE. If the routine is a method call,
7973 both `class__method' and `class__define' will be tried.
7974 With ARG, enforce query for the class of object methods."
7976 (let* ((idlwave-query-class nil)
7977 (idlwave-force-class-query (equal arg '(4)))
7978 (module (idlwave-what-module))
7979 (name (idlwave-make-full-name (nth 2 module) (car module)))
7980 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7981 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7984 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7986 (setq type (match-string 1 resolve)
7987 class (if (match-beginning 2)
7988 (match-string 3 resolve)
7990 name (match-string 4 resolve)))
7991 (if (string= (downcase type) "function")
7992 (setq kwd ",/is_function"))
7996 (idlwave-shell-send-command
7997 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7998 'idlwave-update-routine-info
8001 (idlwave-shell-send-command
8002 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
8003 (list 'idlwave-shell-send-command
8004 (format "resolve_routine,'%s__%s'%s"
8005 (downcase class) (downcase name) kwd)
8006 '(idlwave-update-routine-info)
8009 (defun idlwave-find-module-this-file ()
8011 (idlwave-find-module '(4)))
8013 (defun idlwave-find-module (&optional arg)
8014 "Find the source code of an IDL module.
8015 Works for modules for which IDLWAVE has routine info available. The
8016 function offers as default the module name `idlwave-routine-info'
8017 would use. With ARG limit to this buffer. With two prefix ARG's
8018 force class query for object methods."
8020 (let* ((idlwave-query-class nil)
8021 (idlwave-force-class-query (equal arg '(16)))
8022 (this-buffer (equal arg '(4)))
8023 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
8025 (concat (idlwave-make-full-name
8026 (nth 2 module) (car module))
8027 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8033 (if (eq 'system (car-safe (nth 3 x)))
8034 ;; Take out system routines with no source.
8037 (concat (idlwave-make-full-name
8039 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8041 (idlwave-save-buffer-update)
8042 (idlwave-routines))))))
8043 (name (idlwave-completing-read
8044 (if (or (not this-buffer)
8045 (assoc default list))
8046 (format "Module (Default %s): " default)
8047 (format "Module in this file: "))
8050 (if (string-match "\\`\\s-*\\'" name)
8051 ;; Nothing, use the default.
8052 (setq name default))
8053 (if (string-match "<[fp]>" name)
8054 (setq type (substring name -2 -1)
8055 name (substring name 0 -3)))
8056 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8057 (setq class (match-string 1 name)
8058 name (match-string 2 name)))
8059 (setq name (idlwave-sintern-routine-or-method name class)
8060 class (idlwave-sintern-class class)
8061 type (cond ((equal type "f") 'fun)
8062 ((equal type "p") 'pro)
8064 (idlwave-do-find-module name type class nil this-buffer)))
8066 (defun idlwave-do-find-module (name type class
8067 &optional force-source this-buffer)
8068 (let ((name1 (idlwave-make-full-name class name))
8070 (buf (current-buffer))
8073 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8075 source (or force-source (nth 3 entry))
8076 name2 (if (nth 2 entry)
8077 (idlwave-make-full-name (nth 2 entry) name)
8080 (setq file (idlwave-routine-source-file source)))
8081 (unless file ; Try to find it on the path.
8083 (idlwave-expand-lib-file-name
8085 (format "%s__define.pro" (downcase class))
8086 (format "%s.pro" (downcase name))))))
8088 ((or (null name) (equal name ""))
8090 ((eq (car source) 'system)
8091 (error "Source code for system routine %s is not available"
8093 ((or (not file) (not (file-regular-p file)))
8094 (error "Source code for routine %s is not available"
8097 (when (not this-buffer)
8099 (idlwave-find-file-noselect file 'find))
8100 (pop-to-buffer buf1 t))
8101 (goto-char (point-max))
8102 (let ((case-fold-search t))
8103 (if (re-search-backward
8104 (concat "^[ \t]*\\<"
8105 (cond ((eq type 'fun) "function")
8106 ((eq type 'pro) "pro")
8107 (t "\\(pro\\|function\\)"))
8109 (regexp-quote (downcase name2))
8112 (goto-char (match-beginning 0))
8115 (error "Could not find routine %s" name2)))))))
8117 (defun idlwave-what-module ()
8118 "Return a default module for stuff near point.
8119 Used by `idlwave-routine-info' and `idlwave-find-module'."
8121 (if (let ((case-fold-search t))
8123 (idlwave-beginning-of-statement)
8124 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8125 ;; This is a function or procedure definition statement
8126 ;; We return the defined routine as module.
8128 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8129 (match-string-no-properties 2))
8130 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8131 (idlwave-sintern-class (match-string 3)))
8133 ;; Not a definition statement - analyze precise position.
8134 (let* ((where (idlwave-where))
8136 (pro (car (nth 0 where)))
8137 (func (car (nth 1 where)))
8138 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8139 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8143 ((and (eq cw 'procedure)
8144 (not (equal this-word "")))
8145 (setq this-word (idlwave-sintern-routine-or-method
8146 this-word (nth 2 (nth 3 where))))
8147 (list this-word 'pro
8148 (idlwave-determine-class
8149 (cons this-word (cdr (nth 3 where)))
8151 ((and (eq cw 'function)
8152 (not (equal this-word ""))
8153 (or (eq next-char ?\() ; exclude arrays, vars.
8154 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8155 (setq this-word (idlwave-sintern-routine-or-method
8156 this-word (nth 2 (nth 3 where))))
8157 (list this-word 'fun
8158 (idlwave-determine-class
8159 (cons this-word (cdr (nth 3 where)))
8161 ((and (memq cw '(function-keyword procedure-keyword))
8162 (not (equal this-word ""))
8163 (eq next-char ?\()) ; A function!
8164 (setq this-word (idlwave-sintern-routine this-word))
8165 (list this-word 'fun nil))
8167 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8169 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8172 (defun idlwave-what-module-find-class ()
8173 "Call idlwave-what-module and find the inherited class if necessary."
8174 (let* ((module (idlwave-what-module))
8175 (class (nth 2 module))
8177 (if (and (= (length module) 3)
8181 (apply 'idlwave-find-inherited-class module))
8184 (defun idlwave-find-inherited-class (name type class)
8185 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8186 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8191 (defun idlwave-fix-module-if-obj_new (module)
8192 "Check if MODULE points to obj_new.
8193 If yes, and if the cursor is in the keyword region, change to the
8194 appropriate Init method."
8195 (let* ((name (car module))
8197 (case-fold-search t)
8199 (if (and (stringp name)
8200 (equal (downcase name) "obj_new")
8202 (idlwave-beginning-of-statement)
8203 (setq string (buffer-substring (point) pos))
8204 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8207 (class (match-string 1 string)))
8208 (setq module (list (idlwave-sintern-method "Init")
8210 (idlwave-sintern-class class)))))
8213 (defun idlwave-fix-keywords (name type class keywords
8214 &optional super-classes system)
8215 "Update a list of keywords.
8216 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8217 from all classes if class equals t. If SYSTEM is non-nil, don't
8218 demand _EXTRA in the keyword list."
8219 (let ((case-fold-search t))
8221 ;; If this is the OBJ_NEW function, try to figure out the class and use
8222 ;; the keywords from the corresponding INIT method.
8223 (if (and (equal (upcase name) "OBJ_NEW")
8224 (or (eq major-mode 'idlwave-mode)
8225 (eq major-mode 'idlwave-shell-mode)))
8226 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8227 (string (buffer-substring bos (point)))
8228 (case-fold-search t)
8230 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8232 (setq class (idlwave-sintern-class (match-string 1 string)))
8233 (setq idlwave-current-obj_new-class class)
8236 (idlwave-entry-keywords
8238 (idlwave-sintern-method "INIT")
8241 (idlwave-routines)) 'do-link))))))
8243 ;; If the class is `t', combine all keywords of all methods NAME
8245 (mapc (lambda (entry)
8247 (nth 2 entry) ; non-nil class
8248 (eq (nth 1 entry) type) ; correct type
8251 (idlwave-entry-keywords entry 'do-link)))))
8252 (idlwave-all-assq name (idlwave-routines)))
8253 (setq keywords (idlwave-uniquify keywords)))
8255 ;; If we have inheritance, add all keywords from superclasses, if
8256 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8259 idlwave-keyword-class-inheritance
8263 (assq (idlwave-sintern-keyword "_extra") keywords)
8264 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8265 ;; Check if one of the keyword-class regexps matches the name
8266 (let ((regexps idlwave-keyword-class-inheritance) re)
8268 (while (setq re (pop regexps))
8269 (if (string-match re name) (throw 'exit t))))))
8271 (loop for entry in (idlwave-routines) do
8272 (and (nth 2 entry) ; non-nil class
8273 (memq (nth 2 entry) super-classes) ; an inherited class
8274 (eq (nth 1 entry) type) ; correct type
8275 (eq (car entry) name) ; correct name
8276 (mapc (lambda (k) (add-to-list 'keywords k))
8277 (idlwave-entry-keywords entry 'do-link))))
8278 (setq keywords (idlwave-uniquify keywords)))
8280 ;; Return the final list
8283 (defun idlwave-expand-keyword (keyword module)
8284 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8285 KEYWORD may be an exact match or an abbreviation of a keyword.
8286 If the match is exact, KEYWORD itself is returned, even if there may be other
8287 keywords of which KEYWORD is an abbreviation. This is necessary because some
8288 system routines have keywords which are prefixes of other keywords.
8289 If KEYWORD is an abbreviation of several keywords, a list of all possible
8290 completions is returned.
8291 If the abbreviation was unique, the correct keyword is returned.
8292 If it cannot be a keyword, the function return nil.
8293 If we do not know about MODULE, just return KEYWORD literally."
8294 (let* ((name (car module))
8295 (type (nth 1 module))
8296 (class (nth 2 module))
8297 (kwd (idlwave-sintern-keyword keyword))
8298 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8299 (kwd-alist (idlwave-entry-keywords entry))
8300 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8301 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8302 (completion-ignore-case t)
8304 (cond ((assq kwd kwd-alist)
8306 ((setq candidates (all-completions kwd kwd-alist))
8307 (if (= (length candidates) 1)
8311 ;; Inheritance may cause this keyword to be correct
8314 ;; We do know the function, which does not have the keyword.
8317 ;; We do not know the function, so this just might be a correct
8318 ;; keyword - return it as it is.
8321 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8322 (defvar idlwave-rinfo-map (make-sparse-keymap))
8323 (define-key idlwave-rinfo-mouse-map
8324 (if (featurep 'xemacs) [button2] [mouse-2])
8325 'idlwave-mouse-active-rinfo)
8326 (define-key idlwave-rinfo-mouse-map
8327 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8328 'idlwave-mouse-active-rinfo-shift)
8329 (define-key idlwave-rinfo-mouse-map
8330 (if (featurep 'xemacs) [button3] [mouse-3])
8331 'idlwave-mouse-active-rinfo-right)
8332 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8333 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8334 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8335 (defvar idlwave-popup-source nil)
8336 (defvar idlwave-rinfo-marker (make-marker))
8338 (defun idlwave-quit-help ()
8340 (let ((ri-window (get-buffer-window "*Help*"))
8341 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8342 (when (and olh-window
8343 (fboundp 'idlwave-help-quit))
8344 (select-window olh-window)
8345 (idlwave-help-quit))
8346 (when (window-live-p ri-window)
8347 (delete-window ri-window))))
8349 (defun idlwave-display-calling-sequence (name type class
8350 &optional initial-class)
8351 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8352 (let* ((initial-class (or initial-class class))
8353 (entry (or (idlwave-best-rinfo-assq name type class
8355 (idlwave-rinfo-assq name type class
8356 idlwave-unresolved-routines)))
8357 (name (or (car entry) name))
8358 (class (or (nth 2 entry) class))
8359 (superclasses (idlwave-all-class-inherits initial-class))
8360 (twins (idlwave-routine-twins entry))
8361 (dtwins (idlwave-study-twins twins))
8363 (system (eq (car (nth 3 entry)) 'system))
8364 (calling-seq (nth 4 entry))
8365 (keywords (idlwave-entry-keywords entry 'do-link))
8366 (html-file (car (nth 5 entry)))
8368 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8370 "Button2/3: Online Help")
8372 "Button2: Jump to source and back | Button3: Source in Help window.")
8374 "Button2: Display info about same method in superclass")
8376 (data (list name type class (current-buffer) nil initial-class))
8377 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8378 (face 'idlwave-help-link)
8379 beg props win cnt total)
8380 ;; Fix keywords, but don't add chained super-classes, since these
8381 ;; are shown separately for that super-class
8382 (setq keywords (idlwave-fix-keywords name type class keywords))
8385 (error "No %s %s known %s" type name
8386 (if initial-class (concat "in class " initial-class) "")))
8387 ((or (null name) (equal name ""))
8388 (error "No function or procedure call at point"))
8390 (error "Calling sequence of %s %s not available" type name))
8393 (move-marker idlwave-rinfo-marker (point))
8394 (set-buffer (get-buffer-create "*Help*"))
8395 (use-local-map idlwave-rinfo-map)
8396 (setq buffer-read-only nil)
8398 (set (make-local-variable 'idlwave-popup-source) nil)
8399 (set (make-local-variable 'idlwave-current-obj_new-class)
8400 idlwave-current-obj_new-class)
8402 (setq props (list 'mouse-face 'highlight
8403 km-prop idlwave-rinfo-mouse-map
8404 'help-echo help-echo-class
8405 'data (cons 'class data)))
8406 (let ((classes (cons initial-class superclasses)) c)
8407 (insert "Classes: ")
8408 (while (setq c (pop classes))
8412 (if (equal (downcase c) (downcase class))
8413 (add-text-properties beg (point) (list 'face 'bold))
8414 ;; If Method exists in a different class link it
8415 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8416 (add-text-properties beg (point) props))))
8418 (setq props (list 'mouse-face 'highlight
8419 km-prop idlwave-rinfo-mouse-map
8420 'help-echo help-echo-use
8421 'data (cons 'usage data)))
8422 (if html-file (setq props (append (list 'face face 'link html-file)
8427 (format calling-seq class name class name class name)
8428 (format calling-seq name name name name))
8430 (add-text-properties beg (point) props)
8432 (insert "Keywords:")
8434 (insert " No keywords accepted.")
8438 (if (>= (+ col 1 (length (car x)))
8445 ;; Relevant keywords already have link property attached
8446 props (list 'mouse-face 'highlight
8447 km-prop idlwave-rinfo-mouse-map
8448 'data (cons 'keyword data)
8449 'help-echo help-echo-kwd
8451 (if system (setq props (append (list 'face face) props)))
8453 (add-text-properties beg (point) props)
8454 (setq col (+ col 1 (length (car x)))))
8457 (setq cnt 1 total (length all))
8458 ;; Here entry is (key file (list of type-conses))
8459 (while (setq entry (pop all))
8460 (setq props (list 'mouse-face 'highlight
8461 km-prop idlwave-rinfo-mouse-map
8462 'help-echo help-echo-src
8463 'source (list (car (car (nth 2 entry))) ;type
8466 (cdr (car (nth 2 entry))))
8467 'data (cons 'source data)))
8468 (idlwave-insert-source-location
8471 (if (> total 1) "Sources:" "Source:")
8473 (if (> total 1) "- " ""))
8476 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8477 ;; No more source lines, please
8479 "\n Source information truncated to %d entries."
8480 idlwave-rinfo-max-source-lines))
8482 (goto-char (point-min))
8483 (setq buffer-read-only t))
8484 (display-buffer "*Help*")
8485 (if (and (setq win (get-buffer-window "*Help*"))
8486 idlwave-resize-routine-help-window)
8488 (let ((ww (selected-window)))
8492 (enlarge-window (- (/ (frame-height) 2)
8494 (shrink-window-if-larger-than-buffer))
8495 (select-window ww)))))))))
8497 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8498 "Insert a source location into the routine info buffer.
8499 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
8501 (let* ((key (car entry))
8502 (file (nth 1 entry))
8503 (types (nth 2 entry))
8504 (shell-flag (assq 'compiled types))
8505 (buffer-flag (assq 'buffer types))
8506 (user-flag (assq 'user types))
8507 (lib-flag (assq 'lib types))
8508 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8509 (and user-flag (idlwave-count-memq 'user types))
8510 (and lib-flag (idlwave-count-memq 'lib types))
8524 (insert "Builtin "))
8526 ((and (not file) shell-flag)
8527 (insert "Unresolved"))
8532 ((idlwave-syslib-p file)
8533 (if (string-match "obsolete" (file-name-directory file))
8534 (insert "Obsolete ")
8535 (insert "SystemLib ")))
8537 ;; New special syntax: taken directly from routine-info for
8538 ;; library catalog routines
8539 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8540 (insert (format "%-10s" special)))
8542 ;; Old special syntax: a matching regexp
8543 ((setq special (idlwave-special-lib-test file))
8544 (insert (format "%-10s" special)))
8546 ;; Catch-all with file
8547 ((idlwave-lib-p file) (insert "Library "))
8550 (t (insert "Other ")))
8555 (if lib-flag "L" "-")
8556 (if user-flag "C" "-")
8557 (if shell-flag "S" "-")
8558 (if buffer-flag "B" "-")
8562 (insert (format "(%dx) " ndupl))
8563 (add-text-properties beg (point) (list 'face 'bold)))
8564 (when (and file (not (equal file "")))
8566 (insert (apply 'abbreviate-file-name
8567 (if (featurep 'xemacs) (list file t) (list file))))
8569 (add-text-properties beg (point) file-props)))))
8571 (defun idlwave-special-lib-test (file)
8572 "Check the path of FILE against the regexps which define special libs.
8573 Return the name of the special lib if there is a match."
8574 (let ((alist idlwave-special-lib-alist)
8578 (while (setq entry (pop alist))
8579 (if (string-match (car entry) file)
8580 (setq rtn (cdr entry)
8585 (defun idlwave-mouse-active-rinfo-right (ev)
8587 (idlwave-mouse-active-rinfo ev 'right))
8589 (defun idlwave-mouse-active-rinfo-shift (ev)
8591 (idlwave-mouse-active-rinfo ev nil 'shift))
8593 (defun idlwave-active-rinfo-space ()
8595 (idlwave-mouse-active-rinfo nil 'right))
8597 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8598 "Does the mouse actions in the routine info buffer.
8599 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8602 (if ev (mouse-set-point ev))
8603 (let (data id name type class buf bufwin source link keyword
8605 (setq data (get-text-property (point) 'data)
8606 source (get-text-property (point) 'source)
8607 keyword (get-text-property (point) 'keyword)
8608 link (get-text-property (point) 'link)
8610 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8612 initial-class (nth 6 data)
8613 word (idlwave-this-word)
8614 bufwin (get-buffer-window buf t))
8616 (cond ((eq id 'class) ; Switch class being displayed
8617 (if (window-live-p bufwin) (select-window bufwin))
8618 (idlwave-display-calling-sequence
8619 (idlwave-sintern-method name)
8620 type (idlwave-sintern-class word)
8622 ((eq id 'usage) ; Online help on this routine
8623 (idlwave-online-help link name type class))
8624 ((eq id 'source) ; Source in help or buffer
8626 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8627 (idlwave-help-source-try-header nil)
8628 ;; Fake idlwave-routines so help will find the right entry
8630 (list (list name type class source ""))))
8631 (idlwave-help-get-special-help name type class nil))
8632 ;; Otherwise just pop to the source
8633 (setq idlwave-popup-source (not idlwave-popup-source))
8634 (if idlwave-popup-source
8636 (idlwave-do-find-module name type class source)
8638 (setq idlwave-popup-source nil)
8639 (if (window-live-p bufwin) (select-window bufwin))
8640 (error (nth 1 err))))
8642 (select-window bufwin)
8643 (pop-to-buffer buf))
8644 (goto-char (marker-position idlwave-rinfo-marker)))))
8647 (idlwave-online-help link name type class keyword)
8648 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8650 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8651 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8652 (let ((bwin (get-buffer-window buffer)))
8653 (if idlwave-complete-empty-string-as-lower-case
8654 (setq keyword (downcase keyword)))
8656 (select-window bwin)
8657 (pop-to-buffer buffer)
8658 (setq bwin (get-buffer-window buffer)))
8659 (if (eq (preceding-char) ?/)
8661 (unless (save-excursion
8663 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8664 (min (- (point) 100) (point-min)) t))
8666 (if shift (insert "/"))
8668 (if (and (not shift)
8669 idlwave-keyword-completion-adds-equal)
8672 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8673 "List the load path shadows of all routines defined in current buffer."
8676 (if (eq major-mode 'idlwave-mode)
8677 (idlwave-list-load-path-shadows
8678 nil (idlwave-update-current-buffer-info 'save-buffer)
8679 "in current buffer")
8680 (error "Current buffer is not in idlwave-mode")))
8682 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8683 "List the load path shadows of all routines compiled under the shell.
8684 This is very useful for checking an IDL application. Just compile the
8685 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8686 routines and update IDLWAVE internal info. Then check for shadowing
8690 ((or (not (fboundp 'idlwave-shell-is-running))
8691 (not (idlwave-shell-is-running)))
8692 (error "Shell is not running"))
8693 ((null idlwave-compiled-routines)
8694 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8696 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8699 (defun idlwave-list-all-load-path-shadows (&optional arg)
8700 "List the load path shadows of all routines known to IDLWAVE."
8702 (idlwave-list-load-path-shadows nil nil "globally"))
8704 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8705 "List the routines which are defined multiple times.
8706 Search the information IDLWAVE has about IDL routines for multiple
8708 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8710 When IDL hits a routine call which is not defined, it will search on
8711 the load path in order to find a definition. The output of this
8712 command can be used to detect possible name clashes during this process."
8713 (idlwave-routines) ; Make sure everything is loaded.
8714 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8716 "You don't have any user or library catalogs. Continue anyway? ")
8718 (let* ((routines (append idlwave-system-routines
8719 idlwave-compiled-routines
8720 idlwave-library-catalog-routines
8721 idlwave-user-catalog-routines
8722 idlwave-buffer-routines
8724 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8725 (keymap (make-sparse-keymap))
8726 (props (list 'mouse-face 'highlight
8728 'help-echo "Mouse2: Find source"))
8729 (nroutines (length (or special-routines routines)))
8730 (step (/ nroutines 100))
8733 (idlwave-sort-prefer-buffer-info nil)
8734 routine twins dtwins twin done props1 lroutines)
8736 (if special-routines
8737 ;; Just looking for shadows of a few special routines
8738 (setq lroutines routines
8739 routines special-routines))
8741 (message "Sorting routines...")
8742 (setq routines (sort routines
8744 (string< (downcase (idlwave-make-full-name
8746 (downcase (idlwave-make-full-name
8747 (nth 2 b) (car b)))))))
8748 (message "Sorting routines...done")
8750 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8753 (mouse-set-point ev)
8754 (apply 'idlwave-do-find-module
8755 (get-text-property (point) 'find-args))))
8756 (define-key keymap [(return)]
8759 (apply 'idlwave-do-find-module
8760 (get-text-property (point) 'find-args))))
8761 (message "Compiling list...( 0%%)")
8763 (set-buffer (get-buffer-create "*Shadows*"))
8764 (setq buffer-read-only nil)
8766 (while (setq routine (pop routines))
8767 (if (= (mod (setq n (1+ n)) step) 0)
8768 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8770 ;; Get a list of all twins
8771 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8772 (if (memq routine done)
8774 (setq dtwins (idlwave-study-twins twins)))
8775 ;; Mark all twins as dealt with
8776 (setq done (append twins done))
8777 (when (or (> (length dtwins) 1)
8778 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8779 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8780 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8782 (insert (format "\n%s%s"
8783 (idlwave-make-full-name (nth 2 routine)
8785 (if (eq (nth 1 routine) 'fun) "()" "")))
8786 (while (setq twin (pop dtwins))
8787 (setq props1 (append (list 'find-args
8788 (list (nth 0 routine)
8792 (idlwave-insert-source-location "\n - " twin props1))))
8793 (goto-char (point-min))
8794 (setq buffer-read-only t))
8795 (setq loc (or loc ""))
8798 (display-buffer (get-buffer "*Shadows*"))
8799 (message "%d case%s of shadowing found %s"
8800 cnt (if (= cnt 1) "" "s") loc))
8801 (message "No shadowing conflicts found %s" loc))))
8803 (defun idlwave-print-source (routine)
8804 (let* ((source (nth 3 routine))
8805 (stype (car source))
8806 (sfile (idlwave-routine-source-file source)))
8807 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8808 (if (and (eq stype 'compiled)
8809 (or (not (stringp sfile))
8810 (not (string-match "\\S-" sfile))))
8811 (setq stype 'unresolved))
8812 (princ (format " %-10s %s\n"
8814 (if sfile sfile "No source code available")))))
8816 (defun idlwave-routine-twins (entry &optional list)
8817 "Return all twin entries of ENTRY in LIST.
8818 LIST defaults to `idlwave-routines'.
8819 Twin entries are those which have the same name, type, and class.
8820 ENTRY will also be returned, as the first item of this list."
8821 (let* ((name (car entry))
8822 (type (nth 1 entry))
8823 (class (nth 2 entry))
8824 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8826 (while (setq candidate (pop candidates))
8827 (if (and (not (eq candidate entry))
8828 (eq type (nth 1 candidate))
8829 (eq class (nth 2 candidate)))
8830 (push candidate twins)))
8831 (if (setq candidate (idlwave-rinfo-assq name type class
8832 idlwave-unresolved-routines))
8833 (push candidate twins))
8834 (cons entry (nreverse twins))))
8836 (defun idlwave-study-twins (entries)
8837 "Return dangerous twins of first entry in ENTRIES.
8838 Dangerous twins are routines with same name, but in different files on
8839 the load path. If a file is in the system library and has an entry in
8840 the `idlwave-system-routines' list, we omit the latter as
8841 non-dangerous because many IDL routines are implemented as library
8842 routines, and may have been scanned."
8843 (let* ((entry (car entries))
8844 (name (car entry)) ;
8845 (type (nth 1 entry)) ; Must be bound for
8846 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8848 source type type-cons file alist syslibp key)
8849 (while (setq entry (pop entries))
8851 (setq source (nth 3 entry)
8853 type-cons (cons type (nth 3 source))
8854 file (idlwave-routine-source-file source))
8856 ;; Make KEY to index entry properly
8857 (setq key (cond ((eq type 'system) type)
8858 (file (file-truename file))
8861 ;; Check for an entry in the system library
8864 (idlwave-syslib-p file))
8867 ;; If there's more than one matching entry for the same file, just
8868 ;; append the type-cons to the type list.
8869 (if (setq entry (assoc key alist))
8870 (push type-cons (nth 2 entry))
8871 (push (list key file (list type-cons)) alist)))
8873 (setq alist (nreverse alist))
8876 ;; File is in system *library* - remove any 'system entry
8877 (setq alist (delq (assq 'system alist) alist)))
8879 ;; If 'system remains and we've scanned the syslib, it's a builtin
8880 ;; (rather than a !DIR/lib/.pro file bundled as source).
8881 (when (and (idlwave-syslib-scanned-p)
8882 (setq entry (assoc 'system alist)))
8883 (setcar entry 'builtin))
8884 (sort alist 'idlwave-routine-twin-compare)))
8888 (defvar idlwave-sort-prefer-buffer-info t
8889 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8891 (defmacro idlwave-xor (a b)
8895 (defun idlwave-routine-entry-compare (a b)
8896 "Compare two routine info entries for sortiung. This is the general case.
8897 It first compates class, names, and type. If it turns out that A and B
8898 are twins (same name, class, and type), calls another routine which
8899 compares twins on the basis of their file names and path locations."
8900 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8902 ((not (equal (idlwave-downcase-safe class)
8903 (idlwave-downcase-safe (nth 2 b))))
8905 (cond ((null (nth 2 b)) nil)
8907 (t (string< (downcase class) (downcase (nth 2 b))))))
8908 ((not (equal (downcase name) (downcase (car b))))
8910 (string< (downcase name) (downcase (car b))))
8911 ((not (eq type (nth 1 b)))
8913 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8915 ;; A and B are twins - so the decision is more complicated.
8916 ;; Call twin-compare with the proper arguments.
8917 (idlwave-routine-entry-compare-twins a b)))))
8919 (defun idlwave-routine-entry-compare-twins (a b)
8920 "Compare two routine entries, under the assumption that they are
8921 twins. This basically calls `idlwave-routine-twin-compare' with the
8923 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8928 (afile (idlwave-routine-source-file asrc))
8929 (bfile (idlwave-routine-source-file bsrc)))
8930 (idlwave-routine-twin-compare
8932 (list (file-truename afile) afile (list atype))
8933 (list atype afile (list atype)))
8935 (list (file-truename bfile) bfile (list btype))
8936 (list btype bfile (list btype))))
8939 (defun idlwave-routine-twin-compare (a b)
8940 "Compare two routine twin entries for sorting.
8941 In here, A and B are not normal routine info entries, but special
8942 lists (KEY FILENAME (TYPES...)).
8943 This expects NAME TYPE CLASS to be bound to the right values."
8944 (let* (;; Dis-assemble entries
8945 (akey (car a)) (bkey (car b))
8946 (afile (nth 1 a)) (bfile (nth 1 b))
8947 (atypes (nth 2 a)) (btypes (nth 2 b))
8949 (asysp (memq akey '(builtin system)))
8950 (bsysp (memq bkey '(builtin system)))
8951 ;; Compiled routines?
8952 (acompp (memq 'compiled atypes))
8953 (bcompp (memq 'compiled btypes))
8955 (aunresp (or (eq akey 'unresolved)
8956 (and acompp (not afile))))
8957 (bunresp (or (eq bkey 'unresolved)
8958 (and bcompp (not bfile))))
8959 ;; Buffer info available?
8960 (abufp (memq 'buffer atypes))
8961 (bbufp (memq 'buffer btypes))
8963 (tpath-alist (idlwave-true-path-alist))
8964 (apathp (and (stringp akey)
8965 (assoc (file-name-directory akey) tpath-alist)))
8966 (bpathp (and (stringp bkey)
8967 (assoc (file-name-directory bkey) tpath-alist)))
8968 ;; How early on search path? High number means early since we
8969 ;; measure the tail of the path list
8970 (anpath (length (memq apathp tpath-alist)))
8971 (bnpath (length (memq bpathp tpath-alist)))
8972 ;; Look at file names
8973 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8974 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8975 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8976 (regexp-quote (downcase class))
8977 (regexp-quote (downcase name)))
8978 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8979 ;; Is file name derived from the routine name?
8980 ;; Method file or class definition file?
8981 (anamep (string-match fname-re aname))
8982 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8983 (bnamep (string-match fname-re bname))
8984 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8986 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8987 ;; doesn't it? The difficult stuff is hidden above...
8989 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8990 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8991 ((and idlwave-sort-prefer-buffer-info
8992 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8993 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8994 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8995 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8996 ((and class anamep bnamep ; both file names match ->
8997 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8998 ((> anpath bnpath) t) ; Who is first on path?
8999 (t nil)))) ; Default
9001 (defun idlwave-routine-source-file (source)
9003 (expand-file-name (nth 1 source) (nth 2 source))
9006 (defun idlwave-downcase-safe (string)
9007 "Donwcase if string, else return unchanged."
9008 (if (stringp string)
9012 (defun idlwave-count-eq (elt list)
9013 "How often is ELT in LIST?"
9014 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9016 (defun idlwave-count-memq (elt alist)
9017 "How often is ELT a key in ALIST?"
9018 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9020 (defun idlwave-syslib-p (file)
9021 "Non-nil if FILE is in the system library."
9022 (let* ((true-syslib (file-name-as-directory
9024 (expand-file-name "lib" (idlwave-sys-dir)))))
9025 (true-file (file-truename file)))
9026 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9028 (defun idlwave-lib-p (file)
9029 "Non-nil if file is in the library"
9030 (let ((true-dir (file-name-directory (file-truename file))))
9031 (assoc true-dir (idlwave-true-path-alist))))
9033 (defun idlwave-path-alist-add-flag (list-entry flag)
9034 "Add a flag to the path list entry, if not set."
9035 (let ((flags (cdr list-entry)))
9036 (add-to-list 'flags flag)
9037 (setcdr list-entry flags)))
9039 (defun idlwave-path-alist-remove-flag (list-entry flag)
9040 "Remove a flag to the path list entry, if set."
9041 (let ((flags (delq flag (cdr list-entry))))
9042 (setcdr list-entry flags)))
9044 (defun idlwave-true-path-alist ()
9045 "Return `idlwave-path-alist' alist with true-names.
9046 Info is cached, but relies on the functions setting `idlwave-path-alist'
9047 to reset the variable `idlwave-true-path-alist' to nil."
9048 (or idlwave-true-path-alist
9049 (setq idlwave-true-path-alist
9050 (mapcar (lambda(x) (cons
9051 (file-name-as-directory
9053 (directory-file-name
9056 idlwave-path-alist))))
9058 (defun idlwave-syslib-scanned-p ()
9059 "Non-nil if the system lib file !DIR/lib has been scanned."
9060 (let* ((true-syslib (file-name-as-directory
9062 (expand-file-name "lib" (idlwave-sys-dir))))))
9063 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9065 ;; ----------------------------------------------------------------------------
9067 ;; Online Help display
9070 ;; ----------------------------------------------------------------------------
9072 ;; Additions for use with imenu.el and func-menu.el
9073 ;; (pop-up a list of IDL units in the current file).
9076 (defun idlwave-prev-index-position ()
9077 "Search for the previous procedure or function.
9078 Return nil if not found. For use with imenu.el."
9081 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9082 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9085 (defun idlwave-unit-name ()
9086 "Return the unit name.
9087 Assumes that point is at the beginning of the unit as found by
9088 `idlwave-prev-index-position'."
9091 (let ((begin (point)))
9093 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9094 (if (fboundp 'buffer-substring-no-properties)
9095 (buffer-substring-no-properties begin (point))
9096 (buffer-substring begin (point)))))
9098 (defalias 'idlwave-function-menu
9101 (require 'func-menu)
9103 (error (condition-case nil
9109 ;; Here we hack func-menu.el in order to support this new mode.
9110 ;; The latest versions of func-menu.el already have this stuff in, so
9111 ;; we hack only if it is not already there.
9112 (when (fboundp 'eval-after-load)
9113 (eval-after-load "func-menu"
9115 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9116 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9117 (setq fume-function-name-regexp-alist
9118 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9119 fume-function-name-regexp-alist)))
9120 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9121 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9122 (setq fume-find-function-name-method-alist
9123 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9124 fume-find-function-name-method-alist))))))
9126 (defun idlwave-edit-in-idlde ()
9127 "Edit the current file in IDL Development environment."
9129 (start-process "idldeclient" nil
9130 idlwave-shell-explicit-file-name "-c" "-e"
9131 (buffer-file-name)))
9133 (defvar idlwave-help-use-assistant)
9134 (defun idlwave-launch-idlhelp ()
9135 "Start the IDLhelp application."
9137 (if idlwave-help-use-assistant
9138 (idlwave-help-assistant-raise)
9139 (start-process "idlhelp" nil idlwave-help-application)))
9141 ;; Menus - using easymenu.el
9142 (defvar idlwave-mode-menu-def
9144 ["PRO/FUNC menu" idlwave-function-menu t]
9146 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9147 ["Subprogram End" idlwave-end-of-subprogram t]
9148 ["Block Start" idlwave-beginning-of-block t]
9149 ["Block End" idlwave-end-of-block t]
9150 ["Up Block" idlwave-backward-up-block t]
9151 ["Down Block" idlwave-down-block t]
9152 ["Skip Block Backward" idlwave-backward-block t]
9153 ["Skip Block Forward" idlwave-forward-block t])
9155 ["Subprogram" idlwave-mark-subprogram t]
9156 ["Block" idlwave-mark-block t]
9157 ["Header" idlwave-mark-doclib t])
9159 ["Indent Entire Statement" idlwave-indent-statement
9160 :active t :keys "C-u \\[indent-for-tab-command]" ]
9161 ["Indent Subprogram" idlwave-indent-subprogram t]
9162 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9163 ["Continue/Split line" idlwave-split-line t]
9165 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9166 :selected (symbol-value idlwave-fill-function)])
9168 ["Procedure" idlwave-procedure t]
9169 ["Function" idlwave-function t]
9170 ["Doc Header" idlwave-doc-header t]
9171 ["Log" idlwave-doc-modification t]
9173 ["Case" idlwave-case t]
9174 ["For" idlwave-for t]
9175 ["Repeat" idlwave-repeat t]
9176 ["While" idlwave-while t]
9178 ["Close Block" idlwave-close-block t])
9180 ["Complete" idlwave-complete t]
9181 ("Complete Specific"
9182 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9183 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9185 ["3 Function Name" (idlwave-complete 'function) t]
9186 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9188 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9189 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9191 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9192 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9194 ["9 Class Name" idlwave-complete-class t]))
9196 ["Show Routine Info" idlwave-routine-info t]
9197 ["Online Context Help" idlwave-context-help t]
9199 ["Find Routine Source" idlwave-find-module t]
9200 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9202 ["Update Routine Info" idlwave-update-routine-info t]
9203 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9206 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9207 ["Scan Directories" (idlwave-update-routine-info '(16))
9208 (and idlwave-path-alist (not idlwave-catalog-process))]
9209 ["Scan Directories &" (idlwave-update-routine-info '(64))
9210 (and idlwave-path-alist (not idlwave-catalog-process))]
9213 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9214 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9215 ["Check Everything" idlwave-list-all-load-path-shadows t])
9217 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9219 ["Insert TAB character" idlwave-hard-tab t])
9222 ["Start IDL shell" idlwave-shell t]
9223 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9224 ["Launch IDL Help" idlwave-launch-idlhelp t])
9227 ["Browse IDLWAVE Group" idlwave-customize t]
9229 ["Build Full Customize Menu" idlwave-create-customize-menu
9230 (fboundp 'customize-menu-create)])
9232 ["Describe Mode" describe-mode t]
9233 ["Abbreviation List" idlwave-list-abbrevs t]
9235 ["Commentary in idlwave.el" idlwave-show-commentary t]
9236 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9238 ["Info" idlwave-info t]
9240 ["Help with Topic" idlwave-help-assistant-help-with-topic
9241 idlwave-help-use-assistant]
9242 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9244 (defvar idlwave-mode-debug-menu-def
9246 ["Start IDL shell" idlwave-shell t]
9247 ["Save and .RUN buffer" idlwave-shell-save-and-run
9248 (and (boundp 'idlwave-shell-automatic-start)
9249 idlwave-shell-automatic-start)]))
9251 (if (or (featurep 'easymenu) (load "easymenu" t))
9253 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9254 "IDL and WAVE CL editing menu"
9255 idlwave-mode-menu-def)
9256 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9257 "IDL and WAVE CL editing menu"
9258 idlwave-mode-debug-menu-def)))
9260 (defun idlwave-customize ()
9261 "Call the customize function with idlwave as argument."
9263 ;; Try to load the code for the shell, so that we can customize it
9265 (or (featurep 'idlw-shell)
9266 (load "idlw-shell" t))
9267 (customize-browse 'idlwave))
9269 (defun idlwave-create-customize-menu ()
9270 "Create a full customization menu for IDLWAVE, insert it into the menu."
9272 (if (fboundp 'customize-menu-create)
9274 ;; Try to load the code for the shell, so that we can customize it
9276 (or (featurep 'idlw-shell)
9277 (load "idlw-shell" t))
9279 '("IDLWAVE") "Customize"
9280 `(["Browse IDLWAVE group" idlwave-customize t]
9282 ,(customize-menu-create 'idlwave)
9283 ["Set" Custom-set t]
9284 ["Save" Custom-save t]
9285 ["Reset to Current" Custom-reset-current t]
9286 ["Reset to Saved" Custom-reset-saved t]
9287 ["Reset to Standard Settings" Custom-reset-standard t]))
9288 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9289 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9291 (defun idlwave-show-commentary ()
9292 "Use the finder to view the file documentation from `idlwave.el'."
9295 (finder-commentary "idlwave.el"))
9297 (defun idlwave-shell-show-commentary ()
9298 "Use the finder to view the file documentation from `idlw-shell.el'."
9301 (finder-commentary "idlw-shell.el"))
9303 (defun idlwave-info ()
9304 "Read documentation for IDLWAVE in the info system."
9307 (Info-goto-node "(idlwave)"))
9309 (defun idlwave-list-abbrevs (arg)
9310 "Show the code abbreviations define in IDLWAVE mode.
9311 This lists all abbrevs where the replacement text differs from the input text.
9312 These are the ones the users want to learn to speed up their writing.
9314 The function does *not* list abbrevs which replace a word with itself
9315 to call a hook. These hooks are used to change the case of words or
9316 to blink the matching `begin', and the user does not need to know them.
9318 With arg, list all abbrevs with the corresponding hook.
9320 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9323 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9325 str rpl func fmt (len-str 0) (len-rpl 0))
9328 (if (symbol-value sym)
9330 (setq str (symbol-name sym)
9331 rpl (symbol-value sym)
9332 func (symbol-function sym))
9334 (setq func (prin1-to-string func))
9335 (if (and (listp func) (stringp (nth 2 func)))
9336 (setq rpl (concat "EVAL: " (nth 2 func))
9339 (if (or arg (not (string= rpl str)))
9341 (setq len-str (max len-str (length str)))
9342 (setq len-rpl (max len-rpl (length rpl)))
9343 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9346 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9348 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9349 (with-output-to-temp-buffer "*Help*"
9352 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9353 (princ "=========================================\n\n")
9354 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9355 (princ (format fmt "---" "-------" "----")))
9356 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9357 (princ "================================================\n\n")
9358 (princ (format fmt "KEY" "ACTION" ""))
9359 (princ (format fmt "---" "------" "")))
9362 (setq str (car list)
9365 (princ (format fmt str rpl func)))
9367 ;; Make sure each abbreviation uses only one display line
9369 (set-buffer "*Help*")
9370 (setq truncate-lines t)))
9372 ;; Add .pro files to speedbar for support, if it's loaded
9373 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9375 ;; Set an idle timer to load the routine info.
9376 ;; Will only work on systems which support this.
9377 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9379 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
9382 (run-hooks 'idlwave-load-hook)
9386 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
9387 ;;; idlwave.el ends here