1 ;;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001,2002 Free Software Foundation
4 ;; Author: Carsten Dominik <dominik@astro.uva.nl>
5 ;; Chris Chase <chase@att.com>
6 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; In distant past, based on pascal.el. Though bears little
30 ;; resemblance to that now.
32 ;; Incorporates many ideas, such as abbrevs, action routines, and
33 ;; continuation line indenting, from wave.el.
34 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
36 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
37 ;; for features, key bindings, and info.
38 ;; Also, Info format documentation is available with `M-x idlwave-info'
40 ;; New versions of IDLWAVE, documentation, and more information
47 ;; Follow the instructions in the INSTALL file of the distribution.
48 ;; In short, put this file on your load path and add the following
49 ;; lines to your .emacs file:
51 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
52 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
53 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
59 ;; The newest version of this file is available from the maintainer's
67 ;; IDLWAVE is documented online in info format.
68 ;; A printable version of the documentation is available from the
69 ;; maintainers webpage (see under SOURCE)
75 ;; Thanks to the following people for their contributions and comments:
77 ;; Ulrik Dickow <dickow@nbi.dk>
78 ;; Eric E. Dors <edors@lanl.gov>
79 ;; Stein Vidar H. Haugan <s.v.h.haugan@astro.uio.no>
80 ;; David Huenemoerder <dph@space.mit.edu>
81 ;; Kevin Ivory <Kevin.Ivory@linmpi.mpg.de>
82 ;; Xuyong Liu <liu@stsci.edu>
83 ;; Simon Marshall <Simon.Marshall@esrin.esa.it>
84 ;; Laurent Mugnier <mugnier@onera.fr>
85 ;; Lubos Pochman <lubos@rsinc.com>
86 ;; Bob Portmann <portmann@al.noaa.gov>
87 ;; Patrick M. Ryan <pat@jaameri.gsfc.nasa.gov>
88 ;; Marty Ryba <ryba@ll.mit.edu>
89 ;; Phil Williams <williams@irc.chmcc.org>
90 ;; Phil Sterne <sterne@dublin.llnl.gov>
95 ;; IDLWAVE has extensive customize support - so if you want to learn
96 ;; about the variables which control the behavior of the mode, use
97 ;; `M-x idlwave-customize'.
99 ;; You can set your own preferred values with Customize, or with Lisp
100 ;; code in .emacs. For an example of what to put into .emacs, check
101 ;; the TexInfo documentation or see a complete .emacs at
102 ;; http://idlwave.org.
107 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
108 ;; Numerics, Inc. is growing less and less complete as the two
109 ;; languages grow increasingly apart. The mode probably shouldn't
110 ;; even have "WAVE" in it's title, but it's catchy, and required to
111 ;; avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
113 ;; Moving the point backwards in conjunction with abbrev expansion
114 ;; does not work as I would like it, but this is a problem with
115 ;; emacs abbrev expansion done by the self-insert-command. It ends
116 ;; up inserting the character that expanded the abbrev after moving
117 ;; point backward, e.g., "\cl" expanded with a space becomes
118 ;; "LONG( )" with point before the close paren. This is solved by
119 ;; using a temporary function in `post-command-hook' - not pretty,
122 ;; Tabs and spaces are treated equally as whitespace when filling a
123 ;; comment paragraph. To accomplish this, tabs are permanently
124 ;; replaced by spaces in the text surrounding the paragraph, which
125 ;; may be an undesirable side-effect. Replacing tabs with spaces is
126 ;; limited to comments only and occurs only when a comment
127 ;; paragraph is filled via `idlwave-fill-paragraph'.
129 ;; Avoid muti-statement lines (using "&") on block begin and end
130 ;; lines. Multi-statement lines can mess up the formatting, for
131 ;; example, multiple end statements on a line: endif & endif.
132 ;; Using "&" outside of block begin/end lines should be okay.
134 ;; Determining the expression at point for printing and other
135 ;; examination commands is somewhat rough: currently only fairly
136 ;; simple entities are found. You can always drag-select or examine
139 ;; When forcing completion of method keywords, the initial
140 ;; query for a method has multiple entries for some methods. Would
141 ;; be too difficult to fix this hardly used case.
146 (eval-when-compile (require 'cl))
149 ;; Kludge to allow `defcustom' for Emacs 19.
150 (condition-case () (require 'custom) (error nil))
151 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
152 nil ;; We've got what we needed
153 ;; We have the old or no custom-library, hack around it!
154 (defmacro defgroup (&rest args) nil)
155 (defmacro defcustom (var value doc &rest args)
156 `(defvar ,var ,value ,doc))))
158 (defgroup idlwave nil
159 "Major mode for editing IDL .pro files"
161 :link '(url-link :tag "Home Page"
162 "http://idlwave.org")
163 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
165 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
166 :link '(custom-manual "(idlwave)Top")
170 ;;; Variables for indentation behavior ---------------------------------------
172 (defgroup idlwave-code-formatting nil
173 "Indentation and formatting options for IDLWAVE mode."
176 (defcustom idlwave-main-block-indent 0
177 "*Extra indentation for the main block of code.
178 That is the block between the FUNCTION/PRO statement and the END
179 statement for that program unit."
180 :group 'idlwave-code-formatting
183 (defcustom idlwave-block-indent 4
184 "*Extra indentation applied to block lines.
185 If you change this, you probably also want to change `idlwave-end-offset'."
186 :group 'idlwave-code-formatting
189 (defcustom idlwave-end-offset -4
190 "*Extra indentation applied to block END lines.
191 A value equal to negative `idlwave-block-indent' will make END lines
192 line up with the block BEGIN lines."
193 :group 'idlwave-code-formatting
196 (defcustom idlwave-continuation-indent 2
197 "*Extra indentation applied to continuation lines.
198 This extra offset applies to the first of a set of continuation lines.
199 The following lines receive the same indentation as the first."
200 :group 'idlwave-code-formatting
203 (defcustom idlwave-max-extra-continuation-indent 20
204 "*Maximum additional indentation for special continuation indent.
205 Several special indentations are tried to help line up continuation
206 lines in routine calls or definitions, other statements with
207 parentheses, or assignment statements. This variable specifies a
208 maximum amount by which this special indentation can exceed the
209 standard continuation indentation, otherwise defaulting to a fixed
210 offset. Set to 0 to effectively disable all special continuation
211 indentation, or to a large number (like 100) to enable it in all
212 cases. See also `idlwave-indent-top-open-paren', which can override
214 :group 'idlwave-code-formatting
217 (defcustom idlwave-indent-to-open-paren t
218 "*Non-nil means, indent continuation lines to innermost open
219 parenthesis. This indentation occurs even if otherwise disallowed by
220 `idlwave-max-extra-continuation-indent'. Matching parens and the
221 interleaving args are lined up. Example:
223 x = function_a(function_b(function_c( a, b, [1,2,3, $
229 When this variable is nil, paren alignment may still occur, based on
230 the value of `max-extra-continuation-indent', which, if zero, would
233 x = function_a(function_b(function_c( a, b, [1,2,3, $
238 :group 'idlwave-code-formatting
241 (defcustom idlwave-hanging-indent t
242 "*If set non-nil then comment paragraphs are indented under the
243 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
245 :group 'idlwave-code-formatting
248 (defcustom idlwave-hang-indent-regexp "- "
249 "*Regular expression matching the position of the hanging indent
250 in the first line of a comment paragraph. The size of the indent
251 extends to the end of the match for the regular expression."
252 :group 'idlwave-code-formatting
255 (defcustom idlwave-use-last-hang-indent nil
256 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
257 :group 'idlwave-code-formatting
260 (defcustom idlwave-fill-comment-line-only t
261 "*If non-nil then auto fill will only operate on comment lines."
262 :group 'idlwave-code-formatting
265 (defcustom idlwave-auto-fill-split-string t
266 "*If non-nil then auto fill will split strings with the IDL `+' operator.
267 When the line end falls within a string, string concatenation with the
268 '+' operator will be used to distribute a long string over lines.
269 If nil and a string is split then a terminal beep and warning are issued.
271 This variable is ignored when `idlwave-fill-comment-line-only' is
272 non-nil, since in this case code is not auto-filled."
273 :group 'idlwave-code-formatting
276 (defcustom idlwave-split-line-string t
277 "*If non-nil then `idlwave-split-line' will split strings with `+'.
278 When the splitting point of a line falls inside a string, split the string
279 using the `+' string concatenation operator. If nil and a string is
280 split then a terminal beep and warning are issued."
281 :group 'idlwave-code-formatting
284 (defcustom idlwave-no-change-comment ";;;"
285 "*The indentation of a comment that starts with this regular
286 expression will not be changed. Note that the indentation of a comment
287 at the beginning of a line is never changed."
288 :group 'idlwave-code-formatting
291 (defcustom idlwave-begin-line-comment nil
292 "*A comment anchored at the beginning of line.
293 A comment matching this regular expression will not have its
294 indentation changed. If nil the default is \"^;\", i.e., any line
295 beginning with a \";\". Expressions for comments at the beginning of
296 the line should begin with \"^\"."
297 :group 'idlwave-code-formatting
298 :type '(choice (const :tag "Any line beginning with `;'" nil)
301 (defcustom idlwave-code-comment ";;[^;]"
302 "*A comment that starts with this regular expression on a line by
303 itself is indented as if it is a part of IDL code. As a result if
304 the comment is not preceded by whitespace it is unchanged."
305 :group 'idlwave-code-formatting
308 ;; Comments not matching any of the above will be indented as a
309 ;; right-margin comment, i.e., to a minimum of `comment-column'.
312 ;;; Routine Info and Completion ---------------------------------------
314 (defgroup idlwave-routine-info nil
315 "Routine Info options for IDLWAVE mode."
319 (defcustom idlwave-init-rinfo-when-idle-after 10
320 "*Seconds of idle time before routine info is automatically initialized.
321 Initializing the routine info can take long, in particular if a large
322 library catalog is involved. When Emacs is idle for more than the number
323 of seconds specified by this variable, it starts the initialization.
324 The process is split into five steps, in order to keep possible work
325 interruption as short as possible. If one of the steps finishes, and no
326 user input has arrived in the mean time, initialization proceeds immediately
328 A good value for this variable is about 1/3 of the time initialization
329 take in you setup. So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
330 A Value of 0 means, don't initialize automatically."
331 :group 'idlwave-routine-info
334 (defcustom idlwave-scan-all-buffers-for-routine-info t
335 "*Non-nil means, scan buffers for IDL programs when updating info.
336 The scanning is done by the command `idlwave-update-routine-info'.
337 The following values are allowed:
339 nil Don't scan any buffers.
340 t Scan all idlwave-mode buffers in the current editing session.
341 current Scan only the current buffer, but no other buffers."
342 :group 'idlwave-routine-info
344 (const :tag "No buffer" nil)
345 (const :tag "All buffers" t)
346 (const :tag "Current buffer only" 'current)))
348 (defcustom idlwave-query-shell-for-routine-info t
349 "*Non-nil means query the shell for info about compiled routines.
350 Querying the shell is useful to get information about compiled modules,
351 and it is turned on by default. However, when you have a complete library
352 scan, this is not necessary."
353 :group 'idlwave-routine-info
356 (defcustom idlwave-auto-routine-info-updates
357 '(find-file save-buffer kill-buffer compile-buffer)
358 "*Controls under what circumstances routine info is updated automatically.
362 \(...) A list of circumstances. Allowed members are:
363 find-file Add info for new IDLWAVE buffers.
364 save-buffer Update buffer info when buffer is saved
365 kill-buffer Remove buffer info when buffer gets killed
366 compile-buffer Update shell info after `idlwave-shell-save-and...'"
367 :group 'idlwave-routine-info
369 (const :tag "Never" nil)
370 (const :tag "As often as possible" t)
371 (set :tag "Checklist" :greedy t
372 (const :tag "When visiting a file" find-file)
373 (const :tag "When saving a buffer" save-buffer)
374 (const :tag "After a buffer was killed" kill-buffer)
375 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
377 (defcustom idlwave-rinfo-max-source-lines 5
378 "*Maximum number of source files displayed in the Routine Info window.
379 When an integer, it is the maximum number of source files displayed.
380 t means to show all source files."
381 :group 'idlwave-routine-info
384 (defcustom idlwave-library-path nil
385 "Library path for Windows and MacOS. Not needed under Unix.
386 When selecting the directories to scan for IDL library routine info,
387 IDLWAVE can under UNIX query the shell for the exact search path.
388 However, under Windows and MacOS, the IDLWAVE shell does not work. In this
389 case, this variable specifies the path where IDLWAVE can find library files.
390 The shell will only be asked when this variable is nil.
391 The value is a list of directories. A directory preceeded by a `+' will
392 be searched recursively. If you set this variable on a UNIX system, the shell
394 See also `idlwave-system-directory'."
395 :group 'idlwave-routine-info
396 :type '(repeat (directory)))
398 (defcustom idlwave-system-directory ""
399 "The IDL system directory for Windows and MacOS. Not needed under UNIX.
400 Set this to the value of the `!DIR' system variable in IDL. IDLWAVE uses
401 this to find out which of the library routines belong to the official system
402 library. All files inside the `lib' subdirectory are considered system
403 library files - so don't install private stuff in this directory.
404 On UNIX systems, IDLWAVE queries the shell for the value of `!DIR'.
405 See also `idlwave-library-path'."
406 :group 'idlwave-routine-info
409 (defcustom idlwave-libinfo-file "~/.idlcat.el"
410 "*File for routine information of the IDL library.
411 When this points to a file, the file will be loaded when IDLWAVE first
412 accesses routine info (or does completion).
413 When you scan the library with `idlwave-create-libinfo-file', this file
414 will be used to store the result."
415 :group 'idlwave-routine-info
418 (defcustom idlwave-special-lib-alist nil
419 "Alist of regular expressions matching special library directories.
420 When listing routine source locations, IDLWAVE gives a short hint where
421 the file defining the routine is located. By default it lists `SystemLib'
422 for routines in the system library `!DIR/lib' and `Library' for anything
423 else. This variable can define additional types. The car of each entry
424 is a regular expression matching the file name (they normally will match
425 on the path). The cdr is the string to be used as identifier. Max 10
427 :group 'idlwave-routine-info
429 (cons regexp string)))
431 (defgroup idlwave-online-help nil
432 "Online Help options for IDLWAVE mode."
435 (defcustom idlwave-help-directory ""
436 "The directory where idlw-help.txt and idlw-help.el are stored."
437 :group 'idlwave-online-help
440 (defcustom idlwave-help-use-dedicated-frame t
441 "*Non-nil means, use a separate frame for Online Help if possible."
442 :group 'idlwave-online-help
445 (defcustom idlwave-help-frame-parameters
446 '((height . 20) (unsplittable . t))
447 "The frame parameters for the special Online Help frame.
448 See also `idlwave-help-use-dedicated-frame'.
449 If you do not set the frame width here, the value specified in
450 `idlw-help.el' will be used."
451 :group 'idlwave-online-help
455 (defcustom idlwave-max-popup-menu-items 20
456 "Maximum number of items per pane in popup menus.
457 Currently only used for class selection during completion help."
458 :group 'idlwave-online-help
461 (defcustom idlwave-extra-help-function 'idlwave-help-with-source
462 "The function to call for online help if the normal help fails.
463 Online help works only for system routines which are described in the
464 IDL manuals. A function may be specified to access help from other sources.
466 The function must accept four arguments: NAME, TYPE, CLASS, KEYWORD.
467 The Help buffer is current when this function is called, and the help
468 text should be loaded into this buffer. If help is found, the function
469 should return the buffer position which should be used as `window-start'
470 in the help window. Also, the variable `idlwave-help-mode-line-indicator'
471 should be set to a useful string, which will be displayed in the mode line
472 of the help window. If should also set the variable `idlwave-min-frame-width'
473 to a positive integer. IDLWAVE will ensure that the help frame is at
474 least that many columns wide.
475 Failure to find help should be indicated by throwing an error.
477 When this variable is non-nil, IDLWAVE will allow the mouse-3 help click
478 for every routine and keyword, even though the item may not be highlighted
479 in blue (indicating the availability of system documentation).
481 The default value for this function is `idlwave-help-with-source' which
482 loads the routine source file into the help buffer. If you try to write
483 a different function which accesses a special help file or so, it is
484 probably a good idea to still call this function as a fallback."
485 :group 'idlwave-online-help
488 (defcustom idlwave-help-fontify-source-code nil
489 "*Non-nil means, fontify source code displayed as help like normal code."
490 :group 'idlwave-online-help
493 (defcustom idlwave-help-source-try-header t
494 "*Non-nil means, try to find help in routine header when displaying source.
495 Routines which are not documented in the system manual use their source as
496 help text. When this variable is non-nil, we try to find a description of
497 the help item in the first routine doclib header above the routine definition.
498 If the variable is nil, or if we cannot find/parse the header, the routine
499 definition is displayed instead."
500 :group 'idlwave-online-help
503 (defface idlwave-help-link-face
504 '((((class color)) (:foreground "Blue"))
506 "Face for highlighting links into IDLWAVE online help."
507 :group 'idlwave-online-help)
509 (defcustom idlwave-help-activate-links-aggressively t
510 "*Non-nil means, make all possible links in help active.
511 This just activates all words which are also a help topic - some links may
513 :group 'idlwave-online-help
517 (defgroup idlwave-completion nil
518 "Completion options for IDLWAVE mode."
523 (defconst idlwave-tmp
524 '(choice :tag "by applying the function"
529 (symbol :tag "Other"))))
531 (defcustom idlwave-completion-case '((routine . upcase)
535 "Association list setting the case of completed words.
537 This variable determines the case (UPPER/lower/Capitalized...) of
538 words inserted into the buffer by completion. The preferred case can
539 be specified separately for routine names, keywords, classes and
541 This alist should therefore have entries for `routine' (normal
542 functions and procedures, i.e. non-methods), `keyword', `class', and
543 `method'. Plausible values are
545 upcase upcase whole word, like `BOX_CURSOR'
546 downcase downcase whole word, like `read_ppm'
547 capitalize capitalize each part, like `Widget_Control'
548 preserve preserve case as is, like `IDLgrView'
550 The value can also be any Emacs Lisp function which transforms the
551 case of characters in a string.
553 A value of `preserve' means that the case of the completed word is
554 identical to the way it was written in the definition statement of the
555 routine. This was implemented to allow for mixed-case completion, in
556 particular of object classes and methods.
557 If a completable word is defined in multiple locations, the meaning of
558 `preserve' is not unique since the different definitions might be
559 cased differently. Therefore IDLWAVE always takes the case of the
560 *first* definition it encounters during routine info collection and
561 uses the case derived from it consistently.
563 Note that a lowercase-only string in the buffer will always be completed in
564 lower case (but see the variable `idlwave-completion-force-default-case').
566 After changing this variable, you need to either restart Emacs or press
567 `C-u C-c C-i' to update the internal lists."
568 :group 'idlwave-completion
570 (cons (symbol :tag "Derive completion case for")
573 (defcustom idlwave-completion-force-default-case nil
574 "*Non-nil means, completion will always honor `idlwave-completion-case'.
575 When nil, only the completion of a mixed case or upper case string
576 will honor the default settings in `idlwave-completion-case', while
577 the completion of lower case strings will be completed entirely in
579 :group 'idlwave-completion
582 (defcustom idlwave-complete-empty-string-as-lower-case nil
583 "*Non-nil means, the empty string is considered downcase for completion.
584 The case of what is already in the buffer determines the case of completions.
585 When this variable is non-nil, the empty string is considered to be downcase.
586 Completing on the empty string then offers downcase versions of the possible
588 :group 'idlwave-completion
591 (defvar idlwave-default-completion-case-is-down nil
592 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
593 `idlwave-completion-case'.")
595 (defcustom idlwave-buffer-case-takes-precedence nil
596 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
597 To make this possible, we need to re-case everything each time we update
598 the routine info from the buffers. This is slow.
599 The default is to consider the case given in the system and library files
600 first which makes updating much faster."
601 :group 'idlwave-completion
604 (defcustom idlwave-highlight-help-links-in-completion t
605 "*Non-nil means, highlight completions for which system help is available.
606 Help can then be accessed with mouse-3.
607 This option is only effective when the online help system is installed."
608 :group 'idlwave-completion
611 (defcustom idlwave-support-inheritance t
612 "Non-nil means, treat inheritance with completion, online help etc.
613 When nil, IDLWAVE only knows about the native methods and tags of a class,
614 not about inherited ones."
615 :group 'idlwave-routine-info
618 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
619 "List of regular expressions for class-driven keyword inheritance.
620 Keyword inheritance is often tied to class inheritance by \"chaining\"
621 up the class tree. While it cannot be assumed that the presence of an
622 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
623 certain methods this assumption is almost always true. The methods
624 for which to assume this can be set here."
625 :group 'idlwave-routine-info
626 :type '(repeat (regexp :tag "Match method:")))
629 (defcustom idlwave-completion-show-classes 1
630 "*Number of classes to show when completing object methods and keywords.
631 When completing methods or keywords for an object with unknown class,
632 the *Completions* buffer will show the legal classes for each completion
635 MyMethod <Class1,Class2,Class3>
637 The value of this variable may be nil to inhibit display, or an integer to
638 indicate the maximum number of classes to display.
640 On XEmacs, a full list of classes will also be placed into a `help-echo'
641 property on the competion items, so that the list of classes for the current
642 item is displayed in the echo area. If the value of this variable is a
643 negative integer, the `help-echo' property will be suppressed."
644 :group 'idlwave-completion
645 :type '(choice (const :tag "Don't show" nil)
646 (integer :tag "Number of classes shown" 1)))
648 (defcustom idlwave-completion-fontify-classes t
649 "*Non-nil means, fontify the classes in completions buffer.
650 This makes it easier to distinguish the completion items from the extra
651 class info listed. See `idlwave-completion-show-classes'."
652 :group 'idlwave-completion
655 (defcustom idlwave-query-class '((method-default . nil)
656 (keyword-default . nil))
657 "Association list governing specification of object classes for completion.
659 When IDLWAVE tries to complete object-oriented methods, it usually
660 cannot determine the class of a given object from context. In order
661 to provide the user with a correct list of methods or keywords, it
662 needs to determine the appropriate class. IDLWAVE has two ways of
663 doing this (well, three ways if you count the shell... see
664 `idlwave-shell-query-for-class'):
666 1. Combine the items of all available classes which contain this
667 method for the purpose of completion. So when completing a method,
668 all methods of all known classes are available, and when completing
669 a keyword, all keywords allowed for this method in any class are
670 shown. This behavior is very much like normal completion and is
671 therefore the default. It works much better than one might think -
672 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
673 become uncomfortably long. See also
674 `idlwave-completion-show-classes'.
676 2. The second possibility is to ask the user on each occasion. To
677 make this less interruptive, IDLWAVE can store the class as a text
678 property on the object operator `->'. For a given object in the
679 source code, class selection will then be needed only once
680 - for example to complete the method. Keywords to the method can
681 then be completed directly, because the class is already known.
682 You will have to turn on the storage of the selected class
683 explicitly with the variable `idlwave-store-inquired-class'.
685 This variable allows you to configure IDLWAVE's method and
686 method-keyword completion behavior. Its value is an alist, which
687 should contain at least two elements: (method-default . VALUE) and
688 \(keyword-default . VALUE), where VALUE is either t or nil. These
689 specify if the class should be found during method and keyword
690 completion, respectively.
692 The alist may have additional entries specifying exceptions from the
693 keyword completion rule for specific methods, like INIT or
694 GETPROPERTY. In order to turn on class specification for the INIT
695 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
696 :group 'idlwave-completion
698 (cons (const method-default)
699 (boolean :tag "Determine class when completing METHODS "))
700 (cons (const keyword-default)
701 (boolean :tag "Determine class when completing KEYWORDS "))
703 :tag "Exceptions to defaults"
705 (cons (string :tag "MODULE" :value "")
706 (boolean :tag "Determine class for this method")))))
708 (defcustom idlwave-store-inquired-class nil
709 "*Non-nil means, store class of a method call as text property on `->'.
710 IDLWAVE sometimes has to ask the user for the class associated with a
711 particular object method call. This happens during the commands
712 `idlwave-routine-info' and `idlwave-complete', depending upon the
713 value of the variable `idlwave-query-class'.
715 When you specify a class, this information can be stored as a text
716 property on the `->' arrow in the source code, so that during the same
717 editing session, IDLWAVE will not have to ask again. When this
718 variable is non-nil, IDLWAVE will store and reuse the class information.
719 The class stored can be checked and removed with `\\[idlwave-routine-info]'
722 The default of this variable is nil, since the result of commands then
723 is more predictable. However, if you know what you are doing, it can
724 be nice to turn this on.
726 An arrow which knows the class will be highlighted with
727 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
728 displays (with prefix arg: deletes) the class stored on the arrow
730 :group 'idlwave-completion
733 (defcustom idlwave-class-arrow-face 'bold
734 "*Face to highlight object operator arrows `->' which carry a class property.
735 When IDLWAVE stores a class name as text property on an object arrow
736 \(see variable `idlwave-store-inquired-class', it highlights the arrow
737 with this font in order to remind the user that this arrow is special."
738 :group 'idlwave-completion
741 (defcustom idlwave-resize-routine-help-window t
742 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
743 :group 'idlwave-completion
746 (defcustom idlwave-keyword-completion-adds-equal t
747 "*Non-nil means, completion automatically adds `=' after completed keywords."
748 :group 'idlwave-completion
751 (defcustom idlwave-function-completion-adds-paren t
752 "*Non-nil means, completion automatically adds `(' after completed function.
753 nil means, don't add anything.
754 A value of `2' means, also add the closing parenthesis and position cursor
756 :group 'idlwave-completion
757 :type '(choice (const :tag "Nothing" nil)
759 (const :tag "()" 2)))
761 (defcustom idlwave-completion-restore-window-configuration t
762 "*Non-nil means, try to restore the window configuration after completion.
763 When completion is not unique, Emacs displays a list of completions.
764 This messes up your window configuration. With this variable set, IDLWAVE
765 restores the old configuration after successful completion."
766 :group 'idlwave-completion
769 ;;; Variables for abbrev and action behavior -----------------------------
771 (defgroup idlwave-abbrev-and-indent-action nil
772 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
773 The variables in this group govern this."
776 (defcustom idlwave-do-actions nil
777 "*Non-nil means performs actions when indenting.
778 The actions that can be performed are listed in `idlwave-indent-action-table'."
779 :group 'idlwave-abbrev-and-indent-action
782 (defcustom idlwave-abbrev-start-char "\\"
783 "*A single character string used to start abbreviations in abbrev mode.
784 Possible characters to chose from: ~`\%
785 or even '?'. '.' is not a good choice because it can make structure
786 field names act like abbrevs in certain circumstances.
788 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
789 must set it directly using `setq' in the .emacs file before idlwave.el
791 :group 'idlwave-abbrev-and-indent-action
794 (defcustom idlwave-surround-by-blank nil
795 "*Non-nil means, enable `idlwave-surround'.
796 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
798 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
800 Also see the default key bindings for keys using `idlwave-surround'.
801 Keys are bound and made into actions calling `idlwave-surround' with
802 `idlwave-action-and-binding'.
803 See help for `idlwave-action-and-binding' for examples.
805 Also see help for `idlwave-surround'."
806 :group 'idlwave-abbrev-and-indent-action
809 (defcustom idlwave-pad-keyword t
810 "*Non-nil means pad '=' for keywords like assignments.
811 Whenever `idlwave-surround' is non-nil then this affects how '=' is padded
812 for keywords. If t, it is padded the same as for assignments.
813 If nil then spaces are removed. With any other value, spaces are left
815 :group 'idlwave-abbrev-and-indent-action
817 (const :tag "Pad like assignments" t)
818 (const :tag "Remove space near `='" nil)
819 (const :tag "Keep space near `='" 'keep)))
821 (defcustom idlwave-show-block t
822 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
823 :group 'idlwave-abbrev-and-indent-action
826 (defcustom idlwave-expand-generic-end nil
827 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
828 :group 'idlwave-abbrev-and-indent-action
831 (defcustom idlwave-reindent-end t
832 "*Non-nil means re-indent line after END was typed."
833 :group 'idlwave-abbrev-and-indent-action
836 (defcustom idlwave-abbrev-move t
837 "*Non-nil means the abbrev hook can move point.
838 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
839 definitions, use the command `list-abbrevs', for abbrevs that move
840 point. Moving point is useful, for example, to place point between
841 parentheses of expanded functions.
843 See `idlwave-check-abbrev'."
844 :group 'idlwave-abbrev-and-indent-action
847 (defcustom idlwave-abbrev-change-case nil
848 "*Non-nil means all abbrevs will be forced to either upper or lower case.
849 If the value t, all expanded abbrevs will be upper case.
850 If the value is 'down then abbrevs will be forced to lower case.
851 If nil, the case will not change.
852 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
853 upper case, regardless of this variable."
854 :group 'idlwave-abbrev-and-indent-action
857 (defcustom idlwave-reserved-word-upcase nil
858 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
859 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
860 Has effect only if in abbrev-mode."
861 :group 'idlwave-abbrev-and-indent-action
864 ;;; Action/Expand Tables.
866 ;; The average user may have difficulty modifying this directly. It
867 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
868 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
869 ;; examples of how to add an action.
871 ;; The action table is used by `idlwave-indent-line' whereas both the
872 ;; action and expand tables are used by `idlwave-indent-and-action'. In
873 ;; general, the expand table is only used when a line is explicitly
874 ;; indented. Whereas, in addition to being used when the expand table
875 ;; is used, the action table is used when a line is indirectly
876 ;; indented via line splitting, auto-filling or a new line creation.
880 ;; Capitalize system vars
881 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
883 ;; Capitalize procedure name
884 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
885 ;; '(capitalize-word 1) t)
887 ;; Capitalize common block name
888 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
889 ;; '(capitalize-word 1) t)
891 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
892 ;; '(capitalize-word -1) t)
894 (defvar idlwave-indent-action-table nil
895 "*Associated array containing action lists of search string (car),
896 and function as a cdr. This table is used by `idlwave-indent-line'.
897 See documentation for `idlwave-do-action' for a complete description of
900 Additions to the table are made with `idlwave-action-and-binding' when a
901 binding is not requested.
902 See help on `idlwave-action-and-binding' for examples.")
904 (defvar idlwave-indent-expand-table nil
905 "*Associated array containing action lists of search string (car),
906 and function as a cdr. The table is used by the
907 `idlwave-indent-and-action' function. See documentation for
908 `idlwave-do-action' for a complete description of the action lists.
910 Additions to the table are made with `idlwave-action-and-binding' when a
911 binding is requested.
912 See help on `idlwave-action-and-binding' for examples.")
914 ;;; Documentation header and history keyword ---------------------------------
916 (defgroup idlwave-documentation nil
917 "Options for documenting IDLWAVE files."
920 ;; FIXME: make defcustom?
921 (defvar idlwave-file-header
948 ; KEYWORD PARAMETERS:
980 ; MODIFICATION HISTORY:
984 "*A list (PATHNAME STRING) specifying the doc-header template to use for
985 summarizing a file. If PATHNAME is non-nil then this file will be included.
986 Otherwise STRING is used. If nil, the file summary will be omitted.
987 For example you might set PATHNAME to the path for the
988 lib_template.pro file included in the IDL distribution.")
990 (defcustom idlwave-header-to-beginning-of-file nil
991 "*Non-nil means, the documentation header will always be at start of file.
992 When nil, the header is positioned between the PRO/FUNCTION line of
993 the current routine and the code, allowing several routine headers in
995 :group 'idlwave-documentation
998 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
999 "*The hook function used to update the timestamp of a function."
1000 :group 'idlwave-documentation
1003 (defcustom idlwave-doc-modifications-keyword "HISTORY"
1004 "*The modifications keyword to use with the log documentation commands.
1005 A ':' is added to the keyword end.
1006 Inserted by doc-header and used to position logs by doc-modification.
1007 If nil it will not be inserted."
1008 :group 'idlwave-documentation
1011 (defcustom idlwave-doclib-start "^;+\\+"
1012 "*Regexp matching the start of a document library header."
1013 :group 'idlwave-documentation
1016 (defcustom idlwave-doclib-end "^;+-"
1017 "*Regexp matching the end of a document library header."
1018 :group 'idlwave-documentation
1021 ;;; External Programs -------------------------------------------------------
1023 (defgroup idlwave-external-programs nil
1024 "Path locations of external commands used by IDLWAVE."
1027 ;; WARNING: The following variable has recently been moved from
1028 ;; idlw-shell.el to this file. I hope this does not break
1031 (defcustom idlwave-shell-explicit-file-name "idl"
1032 "*If non-nil, this is the command to run IDL.
1033 Should be an absolute file path or path relative to the current environment
1034 execution search path. If you want to specify command line switches
1035 for the idl program, use `idlwave-shell-command-line-options'.
1037 I know the name of this variable is badly chosen, but I cannot change
1038 it without compromizing backwards-compatibility."
1039 :group 'idlwave-external-programs
1042 (defcustom idlwave-shell-command-line-options nil
1043 "*A list of command line options for calling the IDL program.
1044 Since IDL is executed directly without going through a shell like /bin/sh,
1045 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1046 string for each argument. But you may also give a single string which
1047 contains the options whitespace-separated. Emacs will be kind enough to
1051 (repeat (string :value "")))
1052 :group 'idlwave-external-programs)
1054 (defcustom idlwave-help-application "idlhelp"
1055 "*The external application providing reference help for programming."
1056 :group 'idlwave-external-programs
1059 ;;; Some Shell variables which must be defined here.-----------------------
1061 (defcustom idlwave-shell-debug-modifiers '()
1062 "List of modifiers to be used for the debugging commands.
1063 Will be used to bind debugging commands in the shell buffer and in all
1064 source buffers. These are additional convenience bindings, the debugging
1065 commands are always available with the `C-c C-d' prefix.
1066 If you set this to '(control shift), this means setting a breakpoint will
1067 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1068 are `control', `meta', `super', `hyper', `alt', and `shift'."
1069 :group 'idlwave-shell-general-setup
1070 :type '(set :tag "Specify modifiers"
1078 (defcustom idlwave-shell-automatic-start nil
1079 "*If non-nil attempt invoke idlwave-shell if not already running.
1080 This is checked when an attempt to send a command to an
1081 IDL process is made."
1082 :group 'idlwave-shell-general-setup
1085 ;;; Miscellaneous variables -------------------------------------------------
1087 (defgroup idlwave-misc nil
1088 "Miscellaneous options for IDLWAVE mode."
1091 (defcustom idlwave-startup-message t
1092 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1093 :group 'idlwave-misc
1096 (defcustom idlwave-default-font-lock-items
1097 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1098 common-blocks class-arrows)
1099 "Items which should be fontified on the default fontification level 2.
1100 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1101 is everything and level 2 is specified by this list.
1102 This variable must be set before IDLWAVE gets loaded. It is
1103 a list of symbols, the following symbols are allowed.
1105 pros-and-functions Procedure and Function definitions
1106 batch-files Batch Files
1107 idlwave-idl-keywords IDL Keywords
1108 label Statement Labels
1109 goto Goto Statements
1110 common-blocks Common Blocks
1111 keyword-parameters Keyword Parameters in routine definitions and calls
1112 system-variables System Variables
1113 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1114 class-arrows Object Arrows with class property"
1115 :group 'idlwave-misc
1118 (const :tag "Procedure and Function definitions" pros-and-functions)
1119 (const :tag "Batch Files" batch-files)
1120 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1121 (const :tag "Statement Labels" label)
1122 (const :tag "Goto Statements" goto)
1123 (const :tag "Tags in Structure Definition" structtag)
1124 (const :tag "Structure Name" structname)
1125 (const :tag "Common Blocks" common-blocks)
1126 (const :tag "Keyword Parameters" keyword-parameters)
1127 (const :tag "System Variables" system-variables)
1128 (const :tag "FIXME: Warning" fixme)
1129 (const :tag "Object Arrows with class property " class-arrows)))
1131 (defcustom idlwave-mode-hook nil
1132 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1133 :group 'idlwave-misc
1136 (defcustom idlwave-load-hook nil
1137 "Normal hook. Executed when idlwave.el is loaded."
1138 :group 'idlwave-misc
1141 (defvar idlwave-experimental nil
1142 "Non-nil means turn on a few experimental features.
1143 This variable is only for the maintainer, to test difficult stuff,
1144 while still distributing stable releases.
1145 As a user, you should not set this to t.")
1148 ;;; End customization variables section
1151 ;;; Non customization variables
1153 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1154 ;;; Simon Marshall <simon@gnu.ai.mit.edu>
1155 ;;; and Carsten Dominik...
1157 ;; The following are the reserved words in IDL. Maybe we should
1158 ;; highlight some more stuff as well?
1159 ;; Procedure declarations. Fontify keyword plus procedure name.
1160 (defvar idlwave-idl-keywords
1161 ;; To update this regexp, update the list of keywords and
1162 ;; evaluate the form.
1168 ;; '("and" "or" "xor" "not"
1169 ;; "eq" "ge" "gt" "le" "lt" "ne"
1170 ;; "for" "do" "endfor"
1171 ;; "if" "then" "endif" "else" "endelse"
1172 ;; "case" "of" "endcase"
1173 ;; "switch" "break" "continue" "endswitch"
1175 ;; "repeat" "until" "endrep"
1176 ;; "while" "endwhile"
1179 ;; "compile_opt" "forward_function"
1180 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1182 "\\<\\(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\\)\\>")
1184 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1185 ;; Function declarations. Fontify keyword plus function name.
1187 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1188 (1 font-lock-keyword-face)
1189 (2 font-lock-function-name-face nil t)))
1193 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1194 (1 font-lock-keyword-face) ; "common"
1195 (2 font-lock-reference-face nil t) ; block name
1196 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1197 ;; Start with point after block name and comma
1198 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1200 (1 font-lock-variable-name-face) ; variable names
1205 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1209 '("\\<FIXME:" (0 font-lock-warning-face t)))
1213 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1215 ;; The goto statement and its label
1217 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1218 (1 font-lock-keyword-face)
1219 (2 font-lock-reference-face)))
1221 ;; Tags in structure definitions. Note that this definition actually
1222 ;; collides with labels, so we have to use the same face.
1224 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1228 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1229 (2 font-lock-function-name-face)))
1231 ;; Named parameters, like /xlog or ,xrange=[]
1232 ;; This is anchored to the comma preceeding the keyword.
1233 ;; Treats continuation lines, works only during whole buffer
1234 ;; fontification. Slow, use it only in fancy fontification.
1236 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1237 (5 font-lock-reference-face)))
1239 ;; System variables start with a bang.
1241 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1242 (1 font-lock-variable-name-face)))
1244 ;; Special and unusual operators (not used because too noisy)
1246 '("[<>#]" (0 font-lock-keyword-face)))
1248 ;; All operators (not used because too noisy)
1250 '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1252 ;; Arrows with text property `idlwave-class'
1254 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1256 (defconst idlwave-font-lock-keywords-1
1257 (list pros-and-functions batch-files)
1258 "Subdued level highlighting for IDLWAVE mode.")
1260 (defconst idlwave-font-lock-keywords-2
1261 (mapcar 'symbol-value idlwave-default-font-lock-items)
1262 "Medium level highlighting for IDLWAVE mode.")
1264 (defconst idlwave-font-lock-keywords-3
1265 (list pros-and-functions
1267 idlwave-idl-keywords
1275 "Gaudy level highlighting for IDLWAVE mode."))
1277 (defun idlwave-match-class-arrows (limit)
1278 ;; Match an object arrow with class property
1279 (and idlwave-store-inquired-class
1280 (re-search-forward "->" limit 'limit)
1281 (get-text-property (match-beginning 0) 'idlwave-class)))
1283 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1284 "Default expressions to highlight in IDLWAVE mode.")
1286 (defvar idlwave-font-lock-defaults
1287 '((idlwave-font-lock-keywords
1288 idlwave-font-lock-keywords-1
1289 idlwave-font-lock-keywords-2
1290 idlwave-font-lock-keywords-3)
1292 ((?$ . "w") (?_ . "w") (?. . "w"))
1295 (put 'idlwave-mode 'font-lock-defaults
1296 idlwave-font-lock-defaults) ; XEmacs
1298 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1299 "Regexp to match the start of a full-line comment.
1300 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1301 only by whitespace.")
1303 (defconst idlwave-begin-block-reg
1304 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1305 "Regular expression to find the beginning of a block. The case does
1306 not matter. The search skips matches in comments.")
1308 (defconst idlwave-begin-unit-reg "\\<\\(pro\\|function\\)\\>\\|\\`"
1309 "Regular expression to find the beginning of a unit. The case does
1312 (defconst idlwave-end-unit-reg "\\<\\(pro\\|function\\)\\>\\|\\'"
1313 "Regular expression to find the line that indicates the end of unit.
1314 This line is the end of buffer or the start of another unit. The case does
1315 not matter. The search skips matches in comments.")
1317 (defconst idlwave-continue-line-reg "\\<\\$"
1318 "Regular expression to match a continued line.")
1320 (defconst idlwave-end-block-reg
1321 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1322 "Regular expression to find the end of a block. The case does
1323 not matter. The search skips matches found in comments.")
1325 (defconst idlwave-block-matches
1327 ("function" . "end")
1328 ("case" . "endcase")
1329 ("else" . "endelse")
1332 ("repeat" . "endrep")
1333 ("switch" . "endswitch")
1334 ("while" . "endwhile"))
1335 "Matches between statements and the corresponding END variant.
1336 The cars are the reserved words starting a block. If the block really
1337 begins with BEGIN, the cars are the reserved words before the begin
1338 which can be used to identify the block type.
1339 This is used to check for the correct END type, to close blocks and
1340 to expand generic end statements to their detailed form.")
1342 (defconst idlwave-block-match-regexp
1343 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1344 "Regular expression matching reserved words which can stand before
1345 blocks starting with a BEGIN statement. The matches must have associations
1346 `idlwave-block-matches'")
1348 (defconst idlwave-identifier "[a-zA-Z][a-zA-Z0-9$_]*"
1349 "Regular expression matching an IDL identifier.")
1351 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1352 "Regular expression matching IDL system variables.")
1354 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1355 "Regular expression matching IDL variable names.")
1357 (defconst idlwave-label (concat idlwave-identifier ":")
1358 "Regular expression matching IDL labels.")
1360 (defconst idlwave-statement-match
1362 ;; "endif else" is the only possible "end" that can be
1363 ;; followed by a statement on the same line.
1364 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1365 ;; all other "end"s can not be followed by a statement.
1366 (cons 'end (list idlwave-end-block-reg nil))
1367 '(if . ("if\\>" "then"))
1368 '(for . ("for\\>" "do"))
1369 '(begin . ("begin\\>" nil))
1370 '(pdef . ("pro\\>\\|function\\>" nil))
1371 '(while . ("while\\>" "do"))
1372 '(repeat . ("repeat\\>" "repeat"))
1373 '(goto . ("goto\\>" nil))
1374 '(case . ("case\\>" nil))
1375 '(switch . ("switch\\>" nil))
1376 (cons 'call (list (concat idlwave-identifier "\\(\\s *$\\|\\s *,\\)") nil))
1377 '(assign . ("[^=>\n]*=" nil)))
1379 "Associated list of statement matching regular expressions.
1380 Each regular expression matches the start of an IDL statement. The
1381 first element of each association is a symbol giving the statement
1382 type. The associated value is a list. The first element of this list
1383 is a regular expression matching the start of an IDL statement for
1384 identifying the statement type. The second element of this list is a
1385 regular expression for finding a substatement for the type. The
1386 substatement starts after the end of the found match modulo
1387 whitespace. If it is nil then the statement has no substatement. The
1388 list order matters since matching an assignment statement exactly is
1389 not possible without parsing. Thus assignment statement become just
1390 the leftover unidentified statements containing an equal sign." )
1392 (defvar idlwave-fill-function 'auto-fill-function
1393 "IDL mode auto fill function.")
1395 (defvar idlwave-comment-indent-function 'comment-indent-function
1396 "IDL mode comment indent function.")
1398 ;; Note that this is documented in the v18 manuals as being a string
1399 ;; of length one rather than a single character.
1400 ;; The code in this file accepts either format for compatibility.
1401 (defvar idlwave-comment-indent-char ?\s
1402 "Character to be inserted for IDL comment indentation.
1405 (defconst idlwave-continuation-char ?$
1406 "Character which is inserted as a last character on previous line by
1407 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1409 (defconst idlwave-mode-version " 4.15")
1411 (defmacro idlwave-keyword-abbrev (&rest args)
1412 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1414 ,(append '(idlwave-check-abbrev) args))))
1416 ;; If I take the time I can replace idlwave-keyword-abbrev with
1417 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1418 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1419 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1420 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1422 (defmacro idlwave-code-abbrev (&rest args)
1423 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1424 Specifically, if the abbrev is in a comment or string it is unexpanded.
1425 Otherwise ARGS forms a list that is evaluated."
1427 ,(prin1-to-string args) ;; Puts the code in the doc string
1428 (if (idlwave-quoted)
1429 (progn (unexpand-abbrev) nil)
1432 (defvar idlwave-mode-map (make-sparse-keymap)
1433 "Keymap used in IDL mode.")
1435 (defvar idlwave-mode-syntax-table (make-syntax-table)
1436 "Syntax table in use in `idlwave-mode' buffers.")
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 ?^ "." idlwave-mode-syntax-table)
1443 (modify-syntax-entry ?# "." idlwave-mode-syntax-table)
1444 (modify-syntax-entry ?= "." idlwave-mode-syntax-table)
1445 (modify-syntax-entry ?% "." idlwave-mode-syntax-table)
1446 (modify-syntax-entry ?< "." idlwave-mode-syntax-table)
1447 (modify-syntax-entry ?> "." idlwave-mode-syntax-table)
1448 (modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table)
1449 (modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table)
1450 (modify-syntax-entry ?\\ "." idlwave-mode-syntax-table)
1451 (modify-syntax-entry ?_ "_" idlwave-mode-syntax-table)
1452 (modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table)
1453 (modify-syntax-entry ?} "){" idlwave-mode-syntax-table)
1454 (modify-syntax-entry ?$ "_" idlwave-mode-syntax-table)
1455 (modify-syntax-entry ?. "." idlwave-mode-syntax-table)
1456 (modify-syntax-entry ?\; "<" idlwave-mode-syntax-table)
1457 (modify-syntax-entry ?\n ">" idlwave-mode-syntax-table)
1458 (modify-syntax-entry ?\f ">" idlwave-mode-syntax-table)
1460 (defvar idlwave-find-symbol-syntax-table
1461 (copy-syntax-table idlwave-mode-syntax-table)
1462 "Syntax table that treats symbol characters as word characters.")
1464 (modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1465 (modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1466 (modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table)
1467 (modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table)
1469 (defmacro idlwave-with-special-syntax (&rest body)
1470 "Execute BODY with a different syntax table."
1471 `(let ((saved-syntax (syntax-table)))
1474 (set-syntax-table idlwave-find-symbol-syntax-table)
1476 (set-syntax-table saved-syntax))))
1478 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1479 ; "Execute BODY with a different syntax table."
1480 ; `(let ((saved-syntax (syntax-table)))
1483 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1485 ; (set-syntax-table saved-syntax))))
1487 (defun idlwave-action-and-binding (key cmd &optional select)
1488 "KEY and CMD are made into a key binding and an indent action.
1489 KEY is a string - same as for the `define-key' function. CMD is a
1490 function of no arguments or a list to be evaluated. CMD is bound to
1491 KEY in `idlwave-mode-map' by defining an anonymous function calling
1492 `self-insert-command' followed by CMD. If KEY contains more than one
1493 character a binding will only be set if SELECT is 'both.
1495 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1496 replacing any previous value for KEY. If a binding is not set then it
1497 will instead be placed in `idlwave-indent-action-table'.
1499 If the optional argument SELECT is nil then an action and binding are
1500 created. If SELECT is 'noaction, then a binding is always set and no
1501 action is created. If SELECT is 'both then an action and binding
1502 will both be created even if KEY contains more than one character.
1503 Otherwise, if SELECT is non-nil then only an action is created.
1506 No spaces before and 1 after a comma
1507 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1508 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1509 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1510 Capitalize system variables - action only
1511 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1512 (if (not (equal select 'noaction))
1514 (let* ((table (if select 'idlwave-indent-action-table
1515 'idlwave-indent-expand-table))
1516 (cell (assoc key (eval table))))
1518 ;; Replace action command
1521 (set table (append (eval table) (list (cons key cmd)))))))
1522 ;; Make key binding for action
1523 (if (or (and (null select) (= (length key) 1))
1524 (equal select 'noaction)
1525 (equal select 'both))
1526 (define-key idlwave-mode-map key
1529 (self-insert-command 1))
1530 (list (if (listp cmd)
1534 (fset 'idlwave-debug-map (make-sparse-keymap))
1536 (define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab)
1537 (define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab)
1538 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1539 (define-key idlwave-mode-map "'" 'idlwave-show-matching-quote)
1540 (define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote)
1541 (define-key idlwave-mode-map "\C-g" 'idlwave-keyboard-quit)
1542 (define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region)
1543 (define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1544 (define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram)
1545 (define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block)
1546 (define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block)
1547 (define-key idlwave-mode-map "\C-c]" 'idlwave-close-block)
1548 (define-key idlwave-mode-map "\M-\C-h" 'idlwave-mark-subprogram)
1549 (define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block)
1550 (define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block)
1551 (define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block)
1552 (define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block)
1553 (define-key idlwave-mode-map "\M-\r" 'idlwave-split-line)
1554 (define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram)
1555 (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement)
1556 (define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
1557 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1558 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1559 (define-key idlwave-mode-map [(shift tab)] 'idlwave-indent-statement)
1560 (define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
1561 (define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph)
1562 (define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde)
1563 (define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header)
1564 (define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification)
1565 (define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case)
1566 (define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map)
1567 (define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1568 (define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1569 (when (and (boundp 'idlwave-shell-debug-modifiers)
1570 (listp idlwave-shell-debug-modifiers)
1571 (not (equal idlwave-shell-debug-modifiers '())))
1572 ;; Bind the debug commands also with the special modifiers.
1573 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1574 (mods-noshift (delq 'shift
1575 (copy-sequence idlwave-shell-debug-modifiers))))
1576 (define-key idlwave-mode-map
1577 (vector (append mods-noshift (list (if shift ?C ?c))))
1578 'idlwave-shell-save-and-run)
1579 (define-key idlwave-mode-map
1580 (vector (append mods-noshift (list (if shift ?B ?b))))
1581 'idlwave-shell-break-here)))
1582 (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for)
1583 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1584 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1585 (define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat)
1586 (define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while)
1587 (define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1588 (define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell)
1589 (define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1590 (define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1591 (autoload 'idlwave-shell "idlw-shell"
1592 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1593 (autoload 'idlwave-shell-send-command "idlw-shell")
1594 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1595 "Run `idlwave-shell' and switch back to current window" t)
1596 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1597 "Save and run buffer under the shell." t)
1598 (autoload 'idlwave-shell-break-here "idlw-shell"
1599 "Set breakpoint in current line." t)
1600 (define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module)
1601 (define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info)
1602 (define-key idlwave-mode-map "\M-?" 'idlwave-context-help)
1603 (define-key idlwave-mode-map [(control meta ?\?)] 'idlwave-online-help)
1604 (define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
1605 (define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
1606 (define-key idlwave-mode-map "\C-c=" 'idlwave-resolve)
1607 (define-key idlwave-mode-map
1608 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1609 'idlwave-mouse-context-help)
1611 ;; Set action and key bindings.
1612 ;; See description of the function `idlwave-action-and-binding'.
1613 ;; Automatically add spaces for the following characters
1614 (idlwave-action-and-binding "&" '(idlwave-surround -1 -1))
1615 (idlwave-action-and-binding "<" '(idlwave-surround -1 -1))
1616 ;; Binding works for both > and ->, by changing the length of the token.
1617 (idlwave-action-and-binding ">" '(idlwave-surround -1 -1 '(?-) 1
1618 'idlwave-gtr-pad-hook))
1619 (idlwave-action-and-binding "->" '(idlwave-surround -1 -1 nil 2) t)
1620 (idlwave-action-and-binding "," '(idlwave-surround 0 -1))
1621 ;; Automatically add spaces to equal sign if not keyword
1622 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1627 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1628 ;;; space is inserted (this is the space typed by the user to expanded
1631 (defvar idlwave-mode-abbrev-table nil
1632 "Abbreviation table used for IDLWAVE mode")
1633 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1635 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1636 "Define-abbrev with backward compatibility.
1638 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1639 idlwave-mode-abbrev-table unless TABLE is non-nil."
1640 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1641 (args (list (or table idlwave-mode-abbrev-table)
1642 (if noprefix name (concat idlwave-abbrev-start-char name))
1646 (apply 'define-abbrev (append args '(0 t)))
1647 (error (apply 'define-abbrev args)))))
1650 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1651 "w" idlwave-mode-syntax-table)
1657 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1658 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1659 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1660 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1661 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1662 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1663 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1664 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1665 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1667 ;; Keywords, system functions, conversion routines
1669 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1671 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1672 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1673 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1680 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1681 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1683 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1684 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1685 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1686 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1687 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1688 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1689 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1690 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1692 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1695 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1705 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1713 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1714 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1715 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1716 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1718 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1720 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1721 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1724 ;; This section is reserved words only. (From IDL user manual)
1726 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1727 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1728 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1729 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1730 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1731 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1732 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1733 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1734 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1735 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1736 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1737 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1739 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1740 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1741 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1742 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1743 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1744 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1745 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1746 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1760 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1761 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1762 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1763 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1764 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1766 (defvar imenu-create-index-function)
1767 (defvar extract-index-name-function)
1768 (defvar prev-index-position-function)
1769 (defvar imenu-extract-index-name-function)
1770 (defvar imenu-prev-index-position-function)
1771 ;; defined later - so just make the compiler hush
1772 (defvar idlwave-mode-menu)
1773 (defvar idlwave-mode-debug-menu)
1776 (defun idlwave-mode ()
1777 "Major mode for editing IDL and WAVE CL .pro files.
1779 The main features of this mode are
1781 1. Indentation and Formatting
1782 --------------------------
1783 Like other Emacs programming modes, C-j inserts a newline and indents.
1784 TAB is used for explicit indentation of the current line.
1786 To start a continuation line, use \\[idlwave-split-line]. This
1787 function can also be used in the middle of a line to split the line
1788 at that point. When used inside a long constant string, the string
1789 is split at that point with the `+' concatenation operator.
1791 Comments are indented as follows:
1793 `;;;' Indentation remains unchanged.
1794 `;;' Indent like the surrounding code
1795 `;' Indent to a minimum column.
1797 The indentation of comments starting in column 0 is never changed.
1799 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1800 comment. The indentation of the second line of the paragraph
1801 relative to the first will be retained. Use
1802 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1803 comments. When the variable `idlwave-fill-comment-line-only' is
1804 nil, code can also be auto-filled and auto-indented (not
1807 To convert pre-existing IDL code to your formatting style, mark the
1808 entire buffer with \\[mark-whole-buffer] and execute
1809 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1810 again followed by \\[indent-region] (`indent-region').
1814 IDLWAVE displays information about the calling sequence and the
1815 accepted keyword parameters of a procedure or function with
1816 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1817 source file of a module. These commands know about system
1818 routines, all routines in idlwave-mode buffers and (when the
1819 idlwave-shell is active) about all modules currently compiled under
1820 this shell. Use \\[idlwave-update-routine-info] to update this
1821 information, which is also used for completion (see item 4).
1825 \\[idlwave-context-help] displays the IDL documentation relevant
1826 for the system variable, keyword, or routine at point. A single key
1827 stroke gets you directly to the right place in the docs. Two additional
1828 files (an ASCII version of the IDL documentation and a topics file) must
1829 be installed for this - check the IDLWAVE webpage for these files.
1833 \\[idlwave-complete] completes the names of procedures, functions
1834 class names and keyword parameters. It is context sensitive and
1835 figures out what is expected at point (procedure/function/keyword).
1836 Lower case strings are completed in lower case, other strings in
1837 mixed or upper case.
1839 5. Code Templates and Abbreviations
1840 --------------------------------
1841 Many Abbreviations are predefined to expand to code fragments and templates.
1842 The abbreviations start generally with a `\\`. Some examples
1844 \\pr PROCEDURE template
1845 \\fu FUNCTION template
1846 \\c CASE statement template
1847 \\sw SWITCH statement template
1848 \\f FOR loop template
1849 \\r REPEAT Loop template
1850 \\w WHILE loop template
1851 \\i IF statement template
1852 \\elif IF-ELSE statement template
1855 For a full list, use \\[idlwave-list-abbrevs]. Some templates also have
1856 direct keybindings - see the list of keybindings below.
1858 \\[idlwave-doc-header] inserts a documentation header at the beginning of the
1859 current program unit (pro, function or main). Change log entries
1860 can be added to the current program unit with \\[idlwave-doc-modification].
1862 6. Automatic Case Conversion
1863 -------------------------
1864 The case of reserved words and some abbrevs is controlled by
1865 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1867 7. Automatic END completion
1868 ------------------------
1869 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1870 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1874 Loading idlwave.el runs `idlwave-load-hook'.
1875 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1877 9. Documentation and Customization
1878 -------------------------------
1879 Info documentation for this package is available. Use
1880 \\[idlwave-info] to display (complain to your sysadmin if that does
1881 not work). For Postscript, PDF, and HTML versions of the
1882 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1883 IDLWAVE has customize support - see the group `idlwave'.
1887 Here is a list of all keybindings of this mode.
1888 If some of the key bindings below show with ??, use \\[describe-key]
1889 followed by the key sequence to see what the key sequence does.
1891 \\{idlwave-mode-map}"
1894 (kill-all-local-variables)
1896 (if idlwave-startup-message
1897 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1898 (setq idlwave-startup-message nil)
1900 (setq local-abbrev-table idlwave-mode-abbrev-table)
1901 (set-syntax-table idlwave-mode-syntax-table)
1903 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1905 (make-local-variable idlwave-comment-indent-function)
1906 (set idlwave-comment-indent-function 'idlwave-comment-hook)
1908 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1909 (set (make-local-variable 'comment-start) ";")
1910 (set (make-local-variable 'require-final-newline) t)
1911 (set (make-local-variable 'abbrev-all-caps) t)
1912 (set (make-local-variable 'indent-tabs-mode) nil)
1913 (set (make-local-variable 'completion-ignore-case) t)
1915 (use-local-map idlwave-mode-map)
1917 (when (featurep 'easymenu)
1918 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1919 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1921 (setq mode-name "IDLWAVE")
1922 (setq major-mode 'idlwave-mode)
1923 (setq abbrev-mode t)
1925 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1926 (setq comment-end "")
1927 (set (make-local-variable 'comment-multi-line) nil)
1928 (set (make-local-variable 'paragraph-separate)
1929 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1930 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1931 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1932 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1934 ;; Set tag table list to use IDLTAGS as file name.
1935 (if (boundp 'tag-table-alist)
1936 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1938 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1939 ;; Following line is for Emacs - XEmacs uses the corresponding porperty
1940 ;; on the `idlwave-mode' symbol.
1941 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1944 (set (make-local-variable 'imenu-create-index-function)
1945 'imenu-default-create-index-function)
1946 (set (make-local-variable 'imenu-extract-index-name-function)
1948 (set (make-local-variable 'imenu-prev-index-position-function)
1949 'idlwave-prev-index-position)
1951 ;; Make a local post-command-hook and add our hook to it
1952 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1953 (make-local-hook 'post-command-hook)
1954 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1956 ;; Make local hooks for buffer updates
1957 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1958 (make-local-hook 'kill-buffer-hook)
1959 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1960 (make-local-hook 'after-save-hook)
1961 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1962 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1964 ;; Update the routine info with info about current buffer?
1965 (idlwave-new-buffer-update)
1967 ;; Run the mode hook
1968 (run-hooks 'idlwave-mode-hook))
1971 ;; Done with start up and initialization code.
1972 ;; The remaining routines are the code formatting functions.
1975 (defun idlwave-push-mark (&rest rest)
1976 "Push mark for compatibility with Emacs 18/19."
1977 (if (fboundp 'iconify-frame)
1978 (apply 'push-mark rest)
1981 (defun idlwave-hard-tab ()
1982 "Inserts TAB in buffer in current position."
1986 ;;; This stuff is experimental
1988 (defvar idlwave-command-hook nil
1989 "If non-nil, a list that can be evaluated using `eval'.
1990 It is evaluated in the lisp function `idlwave-command-hook' which is
1991 placed in `post-command-hook'.")
1993 (defun idlwave-command-hook ()
1994 "Command run after every command.
1995 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
1996 sets the variable to zero afterwards."
1997 (and idlwave-command-hook
1998 (listp idlwave-command-hook)
2000 (eval idlwave-command-hook)
2002 (setq idlwave-command-hook nil))
2006 ;; It would be better to use expand.el for better abbrev handling and
2009 (defun idlwave-check-abbrev (arg &optional reserved)
2010 "Reverses abbrev expansion if in comment or string.
2011 Argument ARG is the number of characters to move point
2012 backward if `idlwave-abbrev-move' is non-nil.
2013 If optional argument RESERVED is non-nil then the expansion
2014 consists of reserved words, which will be capitalized if
2015 `idlwave-reserved-word-upcase' is non-nil.
2016 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2017 is non-nil, unless its value is \`down in which case the abbrev will be
2018 made into all lowercase.
2019 Returns non-nil if abbrev is left expanded."
2020 (if (idlwave-quoted)
2021 (progn (unexpand-abbrev)
2023 (if (and reserved idlwave-reserved-word-upcase)
2024 (upcase-region last-abbrev-location (point))
2026 ((equal idlwave-abbrev-change-case 'down)
2027 (downcase-region last-abbrev-location (point)))
2028 (idlwave-abbrev-change-case
2029 (upcase-region last-abbrev-location (point)))))
2030 (if (and idlwave-abbrev-move (> arg 0))
2031 (if (boundp 'post-command-hook)
2032 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2033 (backward-char arg)))
2036 (defun idlwave-in-comment ()
2037 "Returns t if point is inside a comment, nil otherwise."
2039 (let ((here (point)))
2040 (and (idlwave-goto-comment) (> here (point))))))
2042 (defun idlwave-goto-comment ()
2043 "Move to start of comment delimiter on current line.
2044 Moves to end of line if there is no comment delimiter.
2045 Ignores comment delimiters in strings.
2046 Returns point if comment found and nil otherwise."
2047 (let ((eos (progn (end-of-line) (point)))
2050 ;; Look for first comment delimiter not in a string
2052 (setq found (search-forward comment-start eos 'lim))
2053 (while (and found (idlwave-in-quote))
2054 (setq found (search-forward comment-start eos 'lim)))
2055 (store-match-data data)
2056 (and found (not (idlwave-in-quote))
2061 (defvar transient-mark-mode)
2062 (defvar zmacs-regions)
2063 (defvar mark-active)
2064 (defun idlwave-region-active-p ()
2065 "Is transien-mark-mode on and the region active?
2066 Works on both Emacs and XEmacs."
2067 (if (featurep 'xemacs)
2068 (and zmacs-regions (region-active-p))
2069 (and transient-mark-mode mark-active)))
2071 (defun idlwave-show-matching-quote ()
2072 "Insert quote and show matching quote if this is end of a string."
2074 (let ((bq (idlwave-in-quote))
2075 (inq last-command-char))
2076 (if (and bq (not (idlwave-in-comment)))
2077 (let ((delim (char-after bq)))
2083 ;; Not the end of a string
2086 (defun idlwave-show-begin-check ()
2087 "Ensure that the previous word was a token before `idlwave-show-begin'.
2088 An END token must be preceded by whitespace."
2089 (if (not (idlwave-quoted))
2094 (looking-at "[ \t\n\f]"))
2095 (idlwave-show-begin))))
2097 (defun idlwave-show-begin ()
2098 "Finds the start of current block and blinks to it for a second.
2099 Also checks if the correct end statement has been used."
2100 ;; All end statements are reserved words
2101 ;; Re-indent end line
2102 (insert-char ?\ 1) ;; So indent, etc. work well
2104 (let* ((pos (point-marker))
2105 (last-abbrev-marker (copy-marker last-abbrev-location))
2106 (eol-pos (save-excursion (end-of-line) (point)))
2107 begin-pos end-pos end end1 )
2108 (if idlwave-reindent-end (idlwave-indent-line))
2110 (when (and (idlwave-check-abbrev 0 t)
2113 ;; Move inside current block
2114 (goto-char last-abbrev-marker)
2115 (idlwave-block-jump-out -1 'nomark)
2116 (setq begin-pos (point))
2117 (idlwave-block-jump-out 1 'nomark)
2118 (setq end-pos (point))
2119 (if (> end-pos eol-pos)
2122 (setq end (buffer-substring
2124 (skip-chars-backward "a-zA-Z")
2127 (goto-char begin-pos)
2128 (when (setq end1 (cdr (idlwave-block-master)))
2130 ((null end1)) ; no-operation
2131 ((string= (downcase end) (downcase end1))
2133 ((string= (downcase end) "end")
2135 (if idlwave-expand-generic-end
2139 (insert (if (string= end "END") (upcase end1) end1))
2144 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2149 (defun idlwave-block-master ()
2150 (let ((case-fold-search t))
2153 ((looking-at "pro\\|case\\|switch\\|function\\>")
2154 (assoc (downcase (match-string 0)) idlwave-block-matches))
2155 ((looking-at "begin\\>")
2156 (let ((limit (save-excursion
2157 (idlwave-beginning-of-statement)
2160 ((re-search-backward idlwave-block-match-regexp limit t)
2161 (assoc (downcase (match-string 1))
2162 idlwave-block-matches))
2163 ;;((re-search-backward ":[ \t]*\\=" limit t)
2164 ;; ;; seems to be a case thing
2165 ;; '("begin" . "end"))
2167 ;; Just a nromal block
2168 '("begin" . "end")))))
2171 (defun idlwave-close-block ()
2172 "Terminate the current block with the correct END statement."
2175 ;; Start new line if we are not in a new line
2176 (unless (save-excursion
2177 (skip-chars-backward " \t")
2179 (let ((idlwave-show-block nil))
2180 (newline-and-indent)))
2181 (let ((last-abbrev-location (point))) ; for upcasing
2183 (idlwave-show-begin)))
2185 (defun idlwave-gtr-pad-hook (char)
2186 "Let the > symbol expand around -> if present. The new token length
2190 (defun idlwave-surround (&optional before after escape-chars length ec-hook)
2191 "Surround the LENGTH characters before point with blanks.
2192 LENGTH defaults to 1.
2193 Optional arguments BEFORE and AFTER affect the behavior before and
2194 after the characters (see also description of `idlwave-make-space'):
2198 integer > 0 force exactly n spaces
2199 integer < 0 at least |n| spaces
2201 The function does nothing if any of the following conditions is true:
2202 - `idlwave-surround-by-blank' is nil
2203 - the character before point is inside a string or comment
2204 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2205 This hack is used to avoid padding of `>' when it is part of
2206 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2208 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2209 the named function will be called with a single argument of the
2210 preceeding character. Then idlwave-surround will run as usual if
2211 EC-HOOK returns non-nil, and a new length will be taken from the
2213 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2214 (let* ((length (or length 1)) ; establish a default for LENGTH
2215 (prev-char (char-after (- (point) (1+ length)))))
2216 (when (or (not (memq prev-char escape-chars))
2217 (and (fboundp ec-hook)
2219 (save-excursion (funcall ec-hook prev-char)))))
2220 (backward-char length)
2222 (let ((here (point)))
2223 (skip-chars-backward " \t")
2225 ;; avoid clobbering indent
2227 (move-to-column (idlwave-calculate-indent))
2228 (if (<= (point) here)
2229 (narrow-to-region (point) here))
2231 (idlwave-make-space before))
2232 (skip-chars-forward " \t"))
2233 (forward-char length)
2234 (idlwave-make-space after)
2235 ;; Check to see if the line should auto wrap
2236 (if (and (equal (char-after (1- (point))) ?\ )
2237 (> (current-column) fill-column))
2238 (funcall auto-fill-function))))))
2240 (defun idlwave-make-space (n)
2241 "Make space at point.
2242 The space affected is all the spaces and tabs around point.
2243 If n is non-nil then point is left abs(n) spaces from the beginning of
2244 the contiguous space.
2245 The amount of space at point is determined by N.
2246 If the value of N is:
2248 > 0 - exactly N spaces.
2249 < 0 - a minimum of -N spaces, i.e., do not change if there are
2251 0 - no spaces (i.e. remove any existing space)."
2254 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2256 (end-col (progn (skip-chars-forward " \t") (current-column))))
2257 (delete-horizontal-space)
2260 (idlwave-indent-to (+ start-col n))
2261 (goto-char (+ left n)))
2263 (idlwave-indent-to end-col (- n))
2264 (goto-char (- left n)))
2268 (defun idlwave-newline ()
2269 "Inserts a newline and indents the current and previous line."
2272 ;; Handle unterminated single and double quotes
2273 ;; If not in a comment and in a string then insertion of a newline
2274 ;; will mean unbalanced quotes.
2276 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2278 (message "Warning: unbalanced quotes?")))
2281 ;; The current line is being split, the cursor should be at the
2282 ;; beginning of the new line skipping the leading indentation.
2284 ;; The reason we insert the new line before indenting is that the
2285 ;; indenting could be confused by keywords (e.g. END) on the line
2286 ;; after the split point. This prevents us from just using
2287 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2289 (beginning-of-line 0)
2290 (idlwave-indent-line)
2292 (idlwave-indent-line))
2295 ;; Use global variable 'comment-column' to set parallel comment
2297 ;; Modeled on lisp.el
2298 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2299 (defun idlwave-comment-hook ()
2300 "Compute indent for the beginning of the IDL comment delimiter."
2301 (if (or (looking-at idlwave-no-change-comment)
2302 (if idlwave-begin-line-comment
2303 (looking-at idlwave-begin-line-comment)
2306 (if (looking-at idlwave-code-comment)
2307 (if (save-excursion (skip-chars-backward " \t") (bolp))
2308 ;; On line by itself, indent as code
2309 (let ((tem (idlwave-calculate-indent)))
2310 (if (listp tem) (car tem) tem))
2311 ;; after code - do not change
2313 (skip-chars-backward " \t")
2314 (max (if (bolp) 0 (1+ (current-column)))
2317 (defun idlwave-split-line ()
2318 "Continue line by breaking line at point and indent the lines.
2319 For a code line insert continuation marker. If the line is a line comment
2320 then the new line will contain a comment with the same indentation.
2321 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2324 ;; Expand abbreviation, just like normal RET would.
2325 (and abbrev-mode (expand-abbrev))
2327 (if (not (idlwave-in-comment))
2328 ;; For code line add continuation.
2329 ;; Check if splitting a string.
2331 (if (setq beg (idlwave-in-quote))
2332 (if idlwave-split-line-string
2333 ;; Split the string.
2334 (progn (insert (setq beg (char-after beg)) " + "
2335 idlwave-continuation-char beg)
2337 (newline-and-indent)
2339 ;; Do not split the string.
2341 (message "Warning: continuation inside string!!")
2342 (insert " " idlwave-continuation-char))
2343 ;; Not splitting a string.
2344 (if (not (member (char-before) '(?\ ?\t)))
2346 (insert idlwave-continuation-char)
2347 (newline-and-indent)))
2348 (indent-new-comment-line))
2349 ;; Indent previous line
2350 (setq beg (- (point-max) (point)))
2352 (idlwave-indent-line)
2353 (goto-char (- (point-max) beg))
2354 ;; Reindent new line
2355 (idlwave-indent-line)))
2357 (defun idlwave-beginning-of-subprogram ()
2358 "Moves point to the beginning of the current program unit."
2360 (idlwave-find-key idlwave-begin-unit-reg -1))
2362 (defun idlwave-end-of-subprogram ()
2363 "Moves point to the start of the next program unit."
2365 (idlwave-end-of-statement)
2366 (idlwave-find-key idlwave-end-unit-reg 1))
2368 (defun idlwave-mark-statement ()
2369 "Mark current IDL statement."
2371 (idlwave-end-of-statement)
2372 (let ((end (point)))
2373 (idlwave-beginning-of-statement)
2374 (idlwave-push-mark end nil t)))
2376 (defun idlwave-mark-block ()
2377 "Mark containing block."
2379 (idlwave-end-of-statement)
2380 (idlwave-backward-up-block -1)
2381 (idlwave-end-of-statement)
2382 (let ((end (point)))
2383 (idlwave-backward-block)
2384 (idlwave-beginning-of-statement)
2385 (idlwave-push-mark end nil t)))
2388 (defun idlwave-mark-subprogram ()
2389 "Put mark at beginning of program, point at end.
2390 The marks are pushed."
2392 (idlwave-end-of-statement)
2393 (idlwave-beginning-of-subprogram)
2394 (let ((beg (point)))
2395 (idlwave-forward-block)
2396 (idlwave-push-mark beg nil t))
2397 (exchange-point-and-mark))
2399 (defun idlwave-backward-up-block (&optional arg)
2400 "Move to beginning of enclosing block if prefix ARG >= 0.
2401 If prefix ARG < 0 then move forward to enclosing block end."
2403 (idlwave-block-jump-out (- arg) 'nomark))
2405 (defun idlwave-beginning-of-block ()
2406 "Go to the beginning of the current block."
2408 (idlwave-block-jump-out -1 'nomark)
2411 (defun idlwave-end-of-block ()
2412 "Go to the beginning of the current block."
2414 (idlwave-block-jump-out 1 'nomark)
2417 (defun idlwave-forward-block ()
2418 "Move across next nested block."
2420 (if (idlwave-down-block 1)
2421 (idlwave-block-jump-out 1 'nomark)))
2423 (defun idlwave-backward-block ()
2424 "Move backward across previous nested block."
2426 (if (idlwave-down-block -1)
2427 (idlwave-block-jump-out -1 'nomark)))
2429 (defun idlwave-down-block (&optional arg)
2431 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2432 Returns non-nil if successfull."
2437 (let ((eos (save-excursion
2438 (idlwave-block-jump-out -1 'nomark)
2440 (if (setq status (idlwave-find-key
2441 idlwave-end-block-reg -1 'nomark eos))
2442 (idlwave-beginning-of-statement)
2443 (message "No nested block before beginning of containing block.")))
2445 (let ((eos (save-excursion
2446 (idlwave-block-jump-out 1 'nomark)
2448 (if (setq status (idlwave-find-key
2449 idlwave-begin-block-reg 1 'nomark eos))
2450 (idlwave-end-of-statement)
2451 (message "No nested block before end of containing block."))))
2454 (defun idlwave-mark-doclib ()
2455 "Put point at beginning of doc library header, mark at end.
2456 The marks are pushed."
2460 (goto-char (point-max))
2461 (if (re-search-backward idlwave-doclib-start nil t)
2463 (setq beg (progn (beginning-of-line) (point)))
2464 (if (re-search-forward idlwave-doclib-end nil t)
2467 (idlwave-push-mark beg nil t)
2468 (message "Could not find end of doc library header.")))
2469 (message "Could not find doc library header start.")
2470 (goto-char here)))))
2473 (defun idlwave-current-routine ()
2474 "Return (NAME TYPE CLASS) of current routine."
2477 (idlwave-beginning-of-subprogram)
2478 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2479 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2481 (class (idlwave-sintern-class (match-string 3)))
2482 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2483 (list name type class)))))
2485 (defvar idlwave-shell-prompt-pattern)
2486 (defun idlwave-beginning-of-statement ()
2487 "Move to beginning of the current statement.
2488 Skips back past statement continuations.
2489 Point is placed at the beginning of the line whether or not this is an
2493 ((eq major-mode 'idlwave-shell-mode)
2494 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2495 (goto-char (match-end 0))))
2497 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2498 (idlwave-previous-statement)
2499 (beginning-of-line)))))
2501 (defun idlwave-previous-statement ()
2502 "Moves point to beginning of the previous statement.
2503 Returns t if the current line before moving is the beginning of
2504 the first non-comment statement in the file, and nil otherwise."
2506 (let (first-statement)
2507 (if (not (= (forward-line -1) 0))
2508 ;; first line in file
2510 ;; skip blank lines, label lines, include lines and line comments
2512 ;; The current statement is the first statement until we
2513 ;; reach another statement.
2514 (setq first-statement
2516 (looking-at idlwave-comment-line-start-skip)
2517 (looking-at "[ \t]*$")
2518 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2520 (= (forward-line -1) 0)))
2521 ;; skip continuation lines
2525 (idlwave-is-continuation-line))
2526 (= (forward-line -1) 0)))
2529 (defun idlwave-end-of-statement ()
2530 "Moves point to the end of the current IDL statement.
2531 If not in a statement just moves to end of line. Returns position."
2533 (while (and (idlwave-is-continuation-line)
2534 (= (forward-line 1) 0))
2535 (while (and (idlwave-is-comment-or-empty-line)
2536 (= (forward-line 1) 0))))
2540 (defun idlwave-end-of-statement0 ()
2541 "Moves point to the end of the current IDL statement.
2542 If not in a statement just moves to end of line. Returns position."
2544 (while (and (idlwave-is-continuation-line)
2545 (= (forward-line 1) 0)))
2549 (defun idlwave-next-statement ()
2550 "Moves point to beginning of the next IDL statement.
2551 Returns t if that statement is the last
2552 non-comment IDL statement in the file, and nil otherwise."
2554 (let (last-statement)
2555 (idlwave-end-of-statement)
2556 ;; skip blank lines, label lines, include lines and line comments
2557 (while (and (= (forward-line 1) 0)
2558 ;; The current statement is the last statement until
2559 ;; we reach a new statement.
2560 (setq last-statement
2562 (looking-at idlwave-comment-line-start-skip)
2563 (looking-at "[ \t]*$")
2564 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2565 (looking-at "^@")))))
2568 (defun idlwave-skip-multi-commands (&optional lim)
2569 "Skip past multiple commands on a line (with `&')."
2570 (let ((save-point (point)))
2571 (when (re-search-forward ".*&" lim t)
2572 (goto-char (match-end 0))
2573 (if (idlwave-in-quote) (goto-char save-point)))
2576 (defun idlwave-skip-label-or-case ()
2577 "Skip label or case statement element.
2578 Returns position after label.
2579 If there is no label point is not moved and nil is returned."
2580 ;; Case expressions and labels are terminated by a colon.
2581 ;; So we find the first colon in the line and make sure
2582 ;; - no `?' is before it (might be a ? b : c)
2583 ;; - it is not in a comment
2584 ;; - not in a string constant
2585 ;; - not in parenthesis (like a[0:3])
2586 ;; - not followed by another ":" in explicit class, ala a->b::c
2587 ;; As many in this mode, this function is heuristic and not an exact
2589 (let* ((start (point))
2590 (eos (save-excursion (idlwave-end-of-statement) (point)))
2591 (end (idlwave-find-key ":" 1 'nomark eos)))
2593 (= (nth 0 (parse-partial-sexp start end)) 0)
2594 (not (string-match "\\?" (buffer-substring start end)))
2595 (not (string-match "^::" (buffer-substring end eos))))
2602 (defun idlwave-start-of-substatement (&optional pre)
2603 "Move to start of next IDL substatement after point.
2604 Uses the type of the current IDL statement to determine if the next
2605 statement is on a new line or is a subpart of the current statement.
2606 Returns point at start of substatement modulo whitespace.
2607 If optional argument is non-nil move to beginning of current
2609 (let ((orig (point))
2610 (eos (idlwave-end-of-statement))
2613 (idlwave-beginning-of-statement)
2614 (idlwave-skip-label-or-case)
2615 (idlwave-skip-multi-commands orig)
2617 ;; Continue looking for substatements until we are past orig
2618 (while (and (<= (point) orig) (not (eobp)))
2620 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2621 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2623 (idlwave-find-key nst 1 'nomark eos))
2624 (goto-char (match-end 0)))
2625 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2626 (setq ifnest (1- ifnest))
2627 (goto-char (match-end 0)))
2629 (idlwave-next-statement))))
2630 (if pre (goto-char last))
2631 ;; If a continuation line starts here, move to next line
2632 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2633 (beginning-of-line 2))
2636 (defun idlwave-statement-type ()
2637 "Return the type of the current IDL statement.
2638 Uses `idlwave-statement-match' to return a cons of (type . point) with
2639 point the ending position where the type was determined. Type is the
2640 association from `idlwave-statement-match', i.e. the cons cell from the
2641 list not just the type symbol. Returns nil if not an identifiable
2644 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2645 ;; and possibly comments
2646 (while (looking-at "[ \t]*\\$")
2648 (skip-chars-forward " \t")
2649 (let ((st idlwave-statement-match)
2650 (case-fold-search t))
2651 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2652 (setq st (cdr st))))
2654 (append st (match-end 0))))))
2656 (defun idlwave-expand-equal (&optional before after)
2657 "Pad '=' with spaces.
2658 Two cases: Assignment statement, and keyword assignment.
2659 The case is determined using `idlwave-start-of-substatement' and
2660 `idlwave-statement-type'.
2661 The equal sign will be surrounded by BEFORE and AFTER blanks.
2662 If `idlwave-pad-keyword' is t then keyword assignment is treated just
2663 like assignment statements. When nil, spaces are removed for keyword
2664 assignment. Any other value keeps the current space around the `='.
2665 Limits in for loops are treated as keyword assignment.
2666 See `idlwave-surround'. "
2667 ;; Even though idlwave-surround checks `idlwave-surround-by-blank' this
2668 ;; check saves the time of finding the statement type.
2669 (if idlwave-surround-by-blank
2670 (let ((st (save-excursion
2671 (idlwave-start-of-substatement t)
2672 (idlwave-statement-type))))
2674 (cond ((or (and (equal (car (car st)) 'assign)
2675 (equal (cdr st) (point)))
2676 (eq t idlwave-pad-keyword))
2677 ;; An assignment statement or keywor and we need padding
2678 (idlwave-surround before after))
2679 ((null idlwave-pad-keyword)
2680 ;; Spaces should be removed at a keyword
2681 (idlwave-surround 0 0))
2684 (defun idlwave-indent-and-action (&optional arg)
2685 "Call `idlwave-indent-line' and do expand actions.
2686 With prefix ARG non-nil, indent the entire sub-statement."
2689 (if (and idlwave-expand-generic-end
2690 (re-search-backward "\\<\\(end\\)\\s-*\\="
2691 (max 0 (- (point) 10)) t)
2692 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2693 (progn (goto-char (match-end 1))
2694 ;;Expand the END abbreviation, just as RET or Space would have.
2695 (if abbrev-mode (expand-abbrev)
2696 (idlwave-show-begin)))))
2698 (idlwave-indent-statement)
2699 (idlwave-indent-line t)))
2701 (defun idlwave-indent-line (&optional expand)
2702 "Indents current IDL line as code or as a comment.
2703 The actions in `idlwave-indent-action-table' are performed.
2704 If the optional argument EXPAND is non-nil then the actions in
2705 `idlwave-indent-expand-table' are performed."
2707 ;; Move point out of left margin.
2709 (skip-chars-backward " \t")
2711 (skip-chars-forward " \t"))
2712 (let ((mloc (point-marker)))
2715 (if (looking-at idlwave-comment-line-start-skip)
2716 ;; Indentation for a line comment
2718 (skip-chars-forward " \t")
2719 (idlwave-indent-left-margin (idlwave-comment-hook)))
2723 ;; Before indenting, run action routines.
2725 (if (and expand idlwave-do-actions)
2726 (mapcar 'idlwave-do-action idlwave-indent-expand-table))
2728 (if idlwave-do-actions
2729 (mapcar 'idlwave-do-action idlwave-indent-action-table))
2731 ;; No longer expand abbrevs on the line. The user can do this
2732 ;; manually using expand-region-abbrevs.
2734 ;; Indent for code line
2739 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2741 (looking-at "^[ \t]*@"))
2745 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2746 ;; Adjust parallel comment
2748 (if (idlwave-in-comment)
2749 ;; Emacs 21 is too smart with fill-column on comment indent
2750 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2753 (indent-for-comment)))))
2755 ;; Get rid of marker
2756 (set-marker mloc nil)))
2758 (defun idlwave-do-action (action)
2759 "Perform an action repeatedly on a line.
2760 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2761 either a function name to be called with `funcall' or a list to be
2762 evaluated with `eval'. The action performed by FUNC should leave point
2763 after the match for REG - otherwise an infinite loop may be entered."
2764 (let ((action-key (car action))
2765 (action-routine (cdr action)))
2767 (while (idlwave-look-at action-key)
2768 (if (listp action-routine)
2769 (eval action-routine)
2770 (funcall action-routine)))))
2772 (defun idlwave-indent-to (col &optional min)
2773 "Indent from point with spaces until column COL.
2774 Inserts space before markers at point."
2775 (if (not min) (setq min 0))
2776 (insert-before-markers
2777 (make-string (max min (- col (current-column))) ?\ )))
2779 (defun idlwave-indent-left-margin (col)
2780 "Indent the current line to column COL.
2781 Indents such that first non-whitespace character is at column COL
2782 Inserts spaces before markers at point."
2785 (delete-horizontal-space)
2786 (idlwave-indent-to col)))
2788 (defun idlwave-indent-subprogram ()
2789 "Indents program unit which contains point."
2792 (idlwave-end-of-statement)
2793 (idlwave-beginning-of-subprogram)
2794 (let ((beg (point)))
2795 (idlwave-forward-block)
2796 (message "Indenting subprogram...")
2797 (indent-region beg (point) nil))
2798 (message "Indenting subprogram...done.")))
2800 (defun idlwave-indent-statement ()
2801 "Indent current statement, including all continuation lines."
2804 (idlwave-beginning-of-statement)
2805 (let ((beg (point)))
2806 (idlwave-end-of-statement)
2807 (indent-region beg (point) nil))))
2809 (defun idlwave-calculate-indent ()
2810 "Return appropriate indentation for current line as IDL code."
2814 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2816 ((idlwave-look-at idlwave-begin-unit-reg)
2818 ;; Check for continuation line
2820 (and (= (forward-line -1) 0)
2821 (idlwave-is-continuation-line)))
2822 (idlwave-calculate-cont-indent))
2823 ;; calculate indent based on previous and current statements
2824 (t (let ((the-indent
2825 ;; calculate indent based on previous statement
2828 ((idlwave-previous-statement)
2831 ((idlwave-look-at idlwave-begin-unit-reg t)
2832 (+ (idlwave-current-statement-indent)
2833 idlwave-main-block-indent))
2835 ((idlwave-look-at idlwave-begin-block-reg t)
2836 (+ (idlwave-current-statement-indent)
2837 idlwave-block-indent))
2838 ((idlwave-look-at idlwave-end-block-reg t)
2839 (- (idlwave-current-statement-indent)
2841 idlwave-block-indent))
2842 ((idlwave-current-statement-indent))))))
2843 ;; adjust the indentation based on the current statement
2846 ((idlwave-look-at idlwave-end-block-reg)
2847 (+ the-indent idlwave-end-offset))
2851 ;; Parentheses balacing/indent
2854 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2855 "Calculate the continuation indent inside a paren group.
2856 Returns a cons-cell with (open . indent), where open is the
2857 location of the open paren"
2858 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2859 ;; Found an innermost open paren.
2862 ;; Line up with next word unless this is a closing paren.
2865 ;; This is a closed paren - line up under open paren.
2868 ;; Empty (or just comment) - just line up next to paren
2872 (looking-at "[ \t$]*\\(;.*\\)?$"))
2874 ;; Line up with first word after blank space
2876 (skip-chars-forward " \t")
2877 (current-column))))))))
2879 (defun idlwave-calculate-cont-indent ()
2880 "Calculates the IDL continuation indent column from the previous statement.
2881 Note that here previous statement means the beginning of the current
2882 statement if this statement is a continuation of the previous line."
2885 (case-fold-search t)
2886 (end-reg (progn (beginning-of-line) (point)))
2887 (close-exp (progn (skip-chars-forward " \t") (looking-at "\\s)")))
2888 ; (beg-reg (progn (idlwave-previous-statement) (point)))
2889 (beg-reg (progn ;; Use substatement indent unless it's this line
2890 (idlwave-start-of-substatement 'pre)
2891 (if (eq (line-beginning-position) end-reg)
2892 (idlwave-previous-statement))
2894 (cur-indent (idlwave-current-indent))
2895 (else-cont (and (goto-char end-reg) (looking-at "[ \t]*else")))
2896 (basic-indent ;; The basic, non-fancy indent
2897 (+ cur-indent idlwave-continuation-indent))
2898 (fancy-nonparen-indent ;; A smarter indent for routine/assignments
2899 ;; Try without parens first:
2902 (while (idlwave-look-at "&")) ; skip over continued statements
2904 ;; A continued Procedure call or definition
2906 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
2907 (looking-at "[ \t]*\\([a-zA-Z0-9$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
2908 (goto-char (match-end 0))
2909 ;; Comment only, or blank line with "$"? Align with ,
2910 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2911 (goto-char (match-end 2)))
2914 ;; Continued assignment (with =),
2915 ((looking-at "[ \t]*[][().a-zA-Z0-9$_]+[ \t]*\\(=\\)[ \t]*")
2916 (goto-char (match-end 0))
2917 ;; Comment only? Align with =
2918 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2920 (goto-char (match-end 1))
2921 (if idlwave-surround-by-blank
2922 (1+ (current-column))
2924 (current-column))))))
2925 (fancy-nonparen-indent-allowed
2926 (and fancy-nonparen-indent
2927 (< (- fancy-nonparen-indent basic-indent)
2928 idlwave-max-extra-continuation-indent)))
2929 (fancy-paren-indent-cons ;; A smarter indent for paren groups
2930 ;; Look for any enclosing parens
2931 (idlwave-calculate-paren-indent beg-reg end-reg close-exp))
2932 (fancy-paren-open (car fancy-paren-indent-cons))
2933 (fancy-paren-indent (cdr fancy-paren-indent-cons))
2934 (fancy-paren-indent-allowed
2935 (and fancy-paren-indent
2936 (or idlwave-indent-to-open-paren ;; override
2937 (< (- fancy-paren-indent basic-indent)
2938 idlwave-max-extra-continuation-indent))))
2939 fancy-enclosing-paren-indent)
2941 ;; else continuations are always standard
2945 ;; an allowed parenthesis-indent
2946 (fancy-paren-indent-allowed
2949 ;; a disallowed paren indent nested inside one or more other
2950 ;; parens: indent relative to the first allowed enclosing paren
2951 ;; set, if any... if it's actually a greater indent, just use
2952 ;; the fancy-paren-indent anyway.
2953 ((and fancy-paren-indent
2954 (not fancy-paren-indent-allowed)
2955 (setq fancy-enclosing-paren-indent
2956 (let ((enclose-open fancy-paren-open)
2960 (while (setq enclose-indent-cons
2961 (idlwave-calculate-paren-indent
2962 beg-reg (max (1- enclose-open) beg-reg)
2964 enclose-open (car enclose-indent-cons)
2965 enclose-indent (cdr enclose-indent-cons))
2966 (if (< (- enclose-indent basic-indent)
2967 idlwave-max-extra-continuation-indent)
2968 (throw 'loop enclose-indent)))))))
2969 (min fancy-paren-indent
2970 (+ fancy-enclosing-paren-indent idlwave-continuation-indent)))
2972 ;; a disallowed paren indent inside another type: indent relative
2973 ((and fancy-paren-indent
2974 (not fancy-paren-indent-allowed)
2975 fancy-nonparen-indent-allowed )
2976 (+ fancy-nonparen-indent idlwave-continuation-indent))
2978 ;; an allowed nonparen-only indent
2979 (fancy-nonparen-indent-allowed
2980 fancy-nonparen-indent)
2986 (defun idlwave-find-key (key-re &optional dir nomark limit)
2987 "Move to next match of the regular expression KEY-RE.
2988 Matches inside comments or string constants will be ignored.
2989 If DIR is negative, the search will be backwards.
2990 At a successful match, the mark is pushed unless NOMARK is non-nil.
2991 Searches are limited to LIMIT.
2992 Searches are case-insensitive and use a special syntax table which
2993 treats `$' and `_' as word characters.
2994 Return value is the beginning of the match or (in case of failure) nil."
2995 (setq dir (or dir 0))
2996 (let ((case-fold-search t)
2997 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
2999 (idlwave-with-special-syntax
3002 (while (funcall search-func key-re limit t)
3003 (if (not (idlwave-quoted))
3004 (throw 'exit (setq found (match-beginning 0))))))))
3007 (if (not nomark) (push-mark))
3012 (defun idlwave-block-jump-out (&optional dir nomark)
3013 "When optional argument DIR is non-negative, move forward to end of
3014 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3015 regular expressions. When DIR is negative, move backwards to block beginning.
3016 Recursively calls itself to skip over nested blocks. DIR defaults to
3017 forward. Calls `push-mark' unless the optional argument NOMARK is
3018 non-nil. Movement is limited by the start of program units because of
3019 possibility of unbalanced blocks."
3021 (or dir (setq dir 0))
3022 (let* ((here (point))
3023 (case-fold-search t)
3024 (limit (if (>= dir 0) (point-max) (point-min)))
3025 (block-limit (if (>= dir 0)
3026 idlwave-begin-block-reg
3027 idlwave-end-block-reg))
3029 (block-reg (concat idlwave-begin-block-reg "\\|"
3030 idlwave-end-block-reg))
3031 (unit-limit (or (save-excursion
3034 idlwave-begin-unit-reg dir t limit)
3037 idlwave-end-unit-reg dir t limit)))
3039 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3040 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3041 (while (and found (looking-at block-limit))
3042 (if (>= dir 0) (forward-word 1))
3043 (idlwave-block-jump-out dir t)
3044 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3045 (if (not nomark) (push-mark here))
3046 (if (not found) (goto-char unit-limit)
3047 (if (>= dir 0) (forward-word 1)))))
3049 (defun idlwave-current-statement-indent ()
3050 "Return indentation of the current statement.
3051 If in a statement, moves to beginning of statement before finding indent."
3052 (idlwave-beginning-of-statement)
3053 (idlwave-current-indent))
3055 (defun idlwave-current-indent ()
3056 "Return the column of the indentation of the current line.
3057 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3060 (skip-chars-forward " \t")
3061 ;; if we are at the end of blank line return 0
3063 ((current-column)))))
3065 (defun idlwave-is-continuation-line ()
3066 "Tests if current line is continuation line.
3067 Blank or comment-only lines following regular continuation lines (with
3068 `$') count as continuations too."
3071 (idlwave-look-at "\\<\\$")
3073 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3074 (eq (forward-line -1) 0))
3075 (if (idlwave-look-at "\\<\\$") (throw 'loop t)))))))
3077 (defun idlwave-is-comment-line ()
3078 "Tests if the current line is a comment line."
3080 (beginning-of-line 1)
3081 (looking-at "[ \t]*;")))
3083 (defun idlwave-is-comment-or-empty-line ()
3084 "Tests if the current line is a comment line."
3086 (beginning-of-line 1)
3087 (looking-at "[ \t]*[;\n]")))
3089 (defun idlwave-look-at (regexp &optional cont beg)
3090 "Searches current line from current point for REGEXP.
3091 If optional argument CONT is non-nil, searches to the end of
3092 the current statement.
3093 If optional arg BEG is non-nil, search starts from the beginning of the
3095 Ignores matches that end in a comment or inside a string expression.
3096 Returns point if successful, nil otherwise.
3097 This function produces unexpected results if REGEXP contains quotes or
3098 a comment delimiter. The search is case insensitive.
3099 If successful leaves point after the match, otherwise, does not move point."
3100 (let ((here (point))
3101 (case-fold-search t)
3102 (eos (save-excursion
3103 (if cont (idlwave-end-of-statement) (end-of-line))
3106 (idlwave-with-special-syntax
3107 (if beg (idlwave-beginning-of-statement))
3108 (while (and (setq found (re-search-forward regexp eos t))
3110 (if (not found) (goto-char here))
3113 (defun idlwave-fill-paragraph (&optional nohang)
3114 "Fills paragraphs in comments.
3115 A paragraph is made up of all contiguous lines having the same comment
3116 leader (the leading whitespace before the comment delimiter and the
3117 comment delimiter). In addition, paragraphs are separated by blank
3118 line comments. The indentation is given by the hanging indent of the
3119 first line, otherwise by the minimum indentation of the lines after
3120 the first line. The indentation of the first line does not change.
3121 Does not effect code lines. Does not fill comments on the same line
3122 with code. The hanging indent is given by the end of the first match
3123 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3124 optional argument NOHANG is non-nil then the hanging indent is
3127 ;; check if this is a line comment
3130 (skip-chars-forward " \t")
3131 (looking-at comment-start))
3134 pre here diff fill-prefix-reg bcl first-indent
3136 ;; Change tabs to spaces in the surrounding paragraph.
3137 ;; The surrounding paragraph will be the largest containing block of
3138 ;; contiguous line comments. Thus, we may be changing tabs in
3139 ;; a much larger area than is needed, but this is the easiest
3140 ;; brute force way to do it.
3142 ;; This has the undesirable side effect of replacing the tabs
3143 ;; permanently without the user's request or knowledge.
3145 (backward-paragraph)
3146 (setq start (point)))
3150 (untabify start end)
3156 (concat "^[ \t]*" comment-start "+")
3157 (save-excursion (end-of-line) (point))
3159 ;; Get the comment leader on the line and its length
3160 (setq pre (current-column))
3161 ;; the comment leader is the indentation plus exactly the
3162 ;; number of consecutive ";".
3163 (setq fill-prefix-reg
3167 (buffer-substring (save-excursion
3168 (beginning-of-line) (point))
3172 ;; Mark the beginning and end of the paragraph
3174 (while (and (looking-at fill-prefix-reg)
3175 (not (looking-at paragraph-separate))
3178 ;; Move to first line of paragraph
3179 (if (/= (point) bcl)
3181 (setq start (point))
3183 (while (and (looking-at fill-prefix-reg)
3184 (not (looking-at paragraph-separate))
3188 (if (or (not (looking-at fill-prefix-reg))
3189 (looking-at paragraph-separate))
3192 ;; if at end of buffer add a newline (need this because
3193 ;; fill-region needs END to be at the beginning of line after
3194 ;; the paragraph or it will add a line).
3196 (progn (insert ?\n) (backward-char 1)))
3197 ;; Set END to the beginning of line after the paragraph
3198 ;; END is calculated as distance from end of buffer
3199 (setq end (- (point-max) (point) 1))
3201 ;; Calculate the indentation for the paragraph.
3203 ;; In the following while statements, after one iteration
3204 ;; point will be at the beginning of a line in which case
3205 ;; the while will not be executed for the
3206 ;; the first paragraph line and thus will not affect the
3209 ;; First check to see if indentation is based on hanging indent.
3210 (if (and (not nohang) idlwave-hanging-indent
3214 (idlwave-calc-hanging-indent))))
3215 ;; Adjust lines of paragraph by inserting spaces so that
3216 ;; each line's indent is at least as great as the hanging
3217 ;; indent. This is needed for fill-paragraph to work with
3222 (while (> (point) start)
3223 (re-search-forward comment-start-skip
3224 (save-excursion (end-of-line) (point))
3226 (if (> (setq diff (- indent (current-column))) 0)
3228 (if (>= here (point))
3229 ;; adjust the original location for the
3231 (setq here (+ here diff)))
3232 (insert (make-string diff ?\ ))))
3236 ;; No hang. Instead find minimum indentation of paragraph
3237 ;; after first line.
3238 ;; For the following while statement, since START is at the
3239 ;; beginning of line and END is at the end of line
3240 ;; point is greater than START at least once (which would
3241 ;; be the case for a single line paragraph).
3242 (while (> (point) start)
3249 (save-excursion (end-of-line) (point))
3254 (setq fill-prefix (concat fill-prefix
3255 (make-string (- indent pre)
3257 ;; first-line indent
3263 (save-excursion (end-of-line) (point))
3268 ;; try to keep point at its original place
3271 ;; In place of the more modern fill-region-as-paragraph, a hack
3272 ;; to keep whitespace untouched on the first line within the
3273 ;; indent length and to preserve any indent on the first line
3277 (buffer-substring start (+ start first-indent -1)))
3278 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3279 (fill-region-as-paragraph
3282 (current-justification)
3284 (delete-region start (+ start first-indent -1))
3287 ;; When we want the point at the beginning of the comment
3288 ;; body fill-region will put it at the beginning of the line.
3289 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3290 (setq fill-prefix nil))))
3292 (defun idlwave-calc-hanging-indent ()
3293 "Calculate the position of the hanging indent for the comment
3294 paragraph. The hanging indent position is given by the first match
3295 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3296 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3298 If not found returns nil."
3299 (if idlwave-use-last-hang-indent
3302 (if (re-search-backward
3303 idlwave-hang-indent-regexp
3304 (save-excursion (beginning-of-line) (point))
3306 (+ (current-column) (length idlwave-hang-indent-regexp))))
3309 (if (re-search-forward
3310 idlwave-hang-indent-regexp
3311 (save-excursion (end-of-line) (point))
3313 (current-column)))))
3315 (defun idlwave-auto-fill ()
3316 "Called to break lines in auto fill mode.
3317 Only fills comment lines if `idlwave-fill-comment-line-only' is non-nil.
3318 Places a continuation character at the end of the line
3319 if not in a comment. Splits strings with IDL concatenation operator
3320 `+' if `idlwave-auto-fill-split-string is non-nil."
3321 (if (<= (current-column) fill-column)
3322 nil ; do not to fill
3323 (if (or (not idlwave-fill-comment-line-only)
3325 ;; Check for comment line
3327 (looking-at idlwave-comment-line-start-skip)))
3329 (idlwave-indent-line)
3330 ;; Prevent actions do-auto-fill which calls indent-line-function.
3331 (let (idlwave-do-actions
3332 (paragraph-start ".")
3333 (paragraph-separate "."))
3337 ;; Indent the split line
3338 (idlwave-indent-line)
3342 (looking-at idlwave-comment-line-start-skip))
3343 ;; A continued line comment
3344 ;; We treat continued line comments as part of a comment
3345 ;; paragraph. So we check for a hanging indent.
3346 (if idlwave-hanging-indent
3347 (let ((here (- (point-max) (point)))
3351 (idlwave-calc-hanging-indent))))
3354 ;; Remove whitespace between comment delimiter and
3355 ;; text, insert spaces for appropriate indentation.
3359 (save-excursion (end-of-line) (point)) t)
3360 (delete-horizontal-space)
3361 (idlwave-indent-to indent)
3362 (goto-char (- (point-max) here)))
3364 ;; Split code or comment?
3367 (idlwave-in-comment))
3368 ;; Splitting a non-line comment.
3369 ;; Insert the comment delimiter from split line
3373 (skip-chars-forward " \t")
3374 ;; Insert blank to keep off beginning of line
3378 (buffer-substring (idlwave-goto-comment)
3380 (skip-chars-forward "; ")
3382 (idlwave-indent-line))
3383 ;; Split code line - add continuation character
3386 ;; Check to see if we split a string
3387 (if (and (setq beg (idlwave-in-quote))
3388 idlwave-auto-fill-split-string)
3389 ;; Split the string and concatenate.
3390 ;; The first extra space is for the space
3391 ;; the line was split. That space was removed.
3392 (insert " " (char-after beg) " +"))
3395 (if idlwave-auto-fill-split-string
3396 ;; Make the second part of continued string
3399 (skip-chars-forward " \t")
3400 (insert (char-after beg)))
3403 (message "Warning: continuation inside a string.")))
3404 ;; Although do-auto-fill (via indent-new-comment-line) calls
3405 ;; idlwave-indent-line for the new line, re-indent again
3406 ;; because of the addition of the continuation character.
3407 (idlwave-indent-line))
3410 (defun idlwave-auto-fill-mode (arg)
3411 "Toggle auto-fill mode for IDL mode.
3412 With arg, turn auto-fill mode on if arg is positive.
3413 In auto-fill mode, inserting a space at a column beyond `fill-column'
3414 automatically breaks the line at a previous space."
3416 (prog1 (set idlwave-fill-function
3418 (not (symbol-value idlwave-fill-function))
3419 (> (prefix-numeric-value arg) 0))
3423 (set-buffer-modified-p (buffer-modified-p))))
3425 (defun idlwave-doc-header (&optional nomark )
3426 "Insert a documentation header at the beginning of the unit.
3427 Inserts the value of the variable idlwave-file-header. Sets mark before
3428 moving to do insertion unless the optional prefix argument NOMARK
3431 (or nomark (push-mark))
3432 ;; make sure we catch the current line if it begins the unit
3433 (if idlwave-header-to-beginning-of-file
3434 (goto-char (point-min))
3436 (idlwave-beginning-of-subprogram)
3438 ;; skip function or procedure line
3439 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3441 (idlwave-end-of-statement)
3442 (if (> (forward-line 1) 0) (insert "\n")))))
3443 (let ((pos (point)))
3444 (if idlwave-file-header
3445 (cond ((car idlwave-file-header)
3446 (insert-file (car idlwave-file-header)))
3447 ((stringp (car (cdr idlwave-file-header)))
3448 (insert (car (cdr idlwave-file-header))))))
3451 (defun idlwave-default-insert-timestamp ()
3452 "Default timestamp insertion function"
3453 (insert (current-time-string))
3454 (insert ", " (user-full-name))
3455 (if (boundp 'user-mail-address)
3456 (insert " <" user-mail-address ">")
3457 (insert " <" (user-login-name) "@" (system-name) ">"))
3458 ;; Remove extra spaces from line
3459 (idlwave-fill-paragraph)
3460 ;; Insert a blank line comment to separate from the date entry -
3461 ;; will keep the entry from flowing onto date line if re-filled.
3462 (insert "\n;\n;\t\t"))
3464 (defun idlwave-doc-modification ()
3465 "Insert a brief modification log at the beginning of the current program.
3466 Looks for an occurrence of the value of user variable
3467 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3468 and places the point for the user to add a log. Before moving, saves
3469 location on mark ring so that the user can return to previous point."
3473 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3475 (goto-char (point-min))
3476 (re-search-forward idlwave-doclib-start nil t)))
3477 (setq beg (match-beginning 0))
3478 (re-search-forward idlwave-doclib-end nil t)
3479 (setq end (match-end 0)))
3482 (if (re-search-forward
3483 (concat idlwave-doc-modifications-keyword ":")
3488 (insert "\n" comment-start "\n")
3489 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3491 (run-hooks 'idlwave-timestamp-hook))
3492 (error "No valid DOCLIB header"))))
3495 ;;; Interface to expand-region-abbrevs which did not work when the
3496 ;;; abbrev hook associated with an abbrev moves point backwards
3497 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3498 ;;; The original would enter an infinite loop in attempting to expand
3499 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3500 ;;; because the point would keep going back to the beginning of the
3501 ;;; abbrev instead of to the end of the abbrev). We now keep the
3502 ;;; abbrev hook from moving backwards.
3504 (defun idlwave-expand-region-abbrevs (start end)
3505 "Expand each abbrev occurrence in the region.
3506 Calling from a program, arguments are START END."
3509 (goto-char (min start end))
3510 (let ((idlwave-show-block nil) ;Do not blink
3511 (idlwave-abbrev-move nil)) ;Do not move
3512 (expand-region-abbrevs start end 'noquery))))
3514 (defun idlwave-quoted ()
3515 "Returns t if point is in a comment or quoted string.
3517 (or (idlwave-in-comment) (idlwave-in-quote)))
3519 (defun idlwave-in-quote ()
3520 "Returns location of the opening quote
3521 if point is in a IDL string constant, nil otherwise.
3522 Ignores comment delimiters on the current line.
3523 Properly handles nested quotation marks and octal
3524 constants - a double quote followed by an octal digit."
3525 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3526 ;;; double quote followed by an octal digit to be an octal constant
3527 ;;; rather than a string. Therefore, there is no terminating double
3530 ;; Because single and double quotes can quote each other we must
3531 ;; search for the string start from the beginning of line.
3532 (let* ((start (point))
3533 (eol (progn (end-of-line) (point)))
3534 (bq (progn (beginning-of-line) (point)))
3539 (while (< endq start)
3540 ;; Find string start
3541 ;; Don't find an octal constant beginning with a double quote
3542 (if (re-search-forward "\"[^0-7]\\|'\\|\"$" eol 'lim)
3543 ;; Find the string end.
3544 ;; In IDL, two consecutive delimiters after the start of a
3546 ;; escape for the delimiter in the string.
3547 ;; Two consecutive delimiters alone (i.e., not after the
3548 ;; start of a string) is the null string.
3550 ;; Move to position after quote
3551 (goto-char (1+ (match-beginning 0)))
3552 (setq bq (1- (point)))
3553 ;; Get the string delimiter
3554 (setq delim (char-to-string (preceding-char)))
3555 ;; Check for null string
3556 (if (looking-at delim)
3557 (progn (setq endq (point)) (forward-char 1))
3558 ;; Look for next unpaired delimiter
3559 (setq found (search-forward delim eol 'lim))
3560 (while (looking-at delim)
3562 (setq found (search-forward delim eol 'lim)))
3564 (setq endq (- (point) 1))
3565 (setq endq (point)))
3567 (progn (setq bq (point)) (setq endq (point)))))
3568 (store-match-data data)
3569 ;; return string beginning position or nil
3570 (if (> start bq) bq))))
3572 (defun idlwave-is-pointer-dereference (&optional limit)
3573 "Determines if the character after point is a pointer dereference *."
3574 (let ((pos (point)))
3576 (eq (char-after) ?\*)
3577 (not (idlwave-in-quote))
3580 (re-search-backward (concat "\\(" idlwave-idl-keywords
3581 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t)))))
3584 ;; Statement templates
3586 ;; Replace these with a general template function, something like
3587 ;; expand.el (I think there was also something with a name similar to
3590 (defun idlwave-template (s1 s2 &optional prompt noindent)
3591 "Build a template with optional prompt expression.
3593 Opens a line if point is not followed by a newline modulo intervening
3594 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3595 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3596 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3597 PROMPT is a string then it is displayed as a message in the
3598 minibuffer. The PROMPT serves as a reminder to the user of an
3599 expression to enter.
3601 The lines containing S1 and S2 are reindented using `indent-region'
3602 unless the optional second argument NOINDENT is non-nil."
3603 (if (eq major-mode 'idlwave-shell-mode)
3604 ;; This is a gross hack to avoit template abbrev expansion
3605 ;; in the shell. FIXME: This is a dirty hack.
3606 (if (and (eq this-command 'self-insert-command)
3607 (equal last-abbrev-location (point)))
3608 (insert last-abbrev-text)
3609 (error "No templates in idlwave-shell"))
3610 (cond ((eq idlwave-abbrev-change-case 'down)
3611 (setq s1 (downcase s1) s2 (downcase s2)))
3612 (idlwave-abbrev-change-case
3613 (setq s1 (upcase s1) s2 (upcase s2))))
3614 (let ((beg (save-excursion (beginning-of-line) (point)))
3616 (if (not (looking-at "\\s-*\n"))
3623 (indent-region beg end nil))
3624 (if (stringp prompt)
3625 (message prompt)))))
3627 (defun idlwave-rw-case (string)
3628 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3629 (if idlwave-reserved-word-upcase
3633 (defun idlwave-elif ()
3634 "Build skeleton IDL if-else block."
3637 (idlwave-rw-case "if")
3638 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3639 "Condition expression"))
3641 (defun idlwave-case ()
3642 "Build skeleton IDL case statement."
3645 (idlwave-rw-case "case")
3646 (idlwave-rw-case " of\n\nendcase")
3647 "Selector expression"))
3649 (defun idlwave-switch ()
3650 "Build skeleton IDL switch statement."
3653 (idlwave-rw-case "switch")
3654 (idlwave-rw-case " of\n\nendswitch")
3655 "Selector expression"))
3657 (defun idlwave-for ()
3658 "Build skeleton for loop statment."
3661 (idlwave-rw-case "for")
3662 (idlwave-rw-case " do begin\n\nendfor")
3665 (defun idlwave-if ()
3666 "Build skeleton for loop statment."
3669 (idlwave-rw-case "if")
3670 (idlwave-rw-case " then begin\n\nendif")
3671 "Scalar logical expression"))
3673 (defun idlwave-procedure ()
3676 (idlwave-rw-case "pro")
3677 (idlwave-rw-case "\n\nreturn\nend")
3680 (defun idlwave-function ()
3683 (idlwave-rw-case "function")
3684 (idlwave-rw-case "\n\nreturn\nend")
3687 (defun idlwave-repeat ()
3690 (idlwave-rw-case "repeat begin\n\nendrep until")
3691 (idlwave-rw-case "")
3694 (defun idlwave-while ()
3697 (idlwave-rw-case "while")
3698 (idlwave-rw-case " do begin\n\nendwhile")
3701 (defun idlwave-split-string (string &optional pattern)
3702 "Return a list of substrings of STRING which are separated by PATTERN.
3703 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3705 (setq pattern "[ \f\t\n\r\v]+"))
3706 (let (parts (start 0))
3707 (while (string-match pattern string start)
3708 (setq parts (cons (substring string start (match-beginning 0)) parts)
3709 start (match-end 0)))
3710 (nreverse (cons (substring string start) parts))))
3712 (defun idlwave-replace-string (string replace_string replace_with)
3714 (last (length string))
3717 (while (setq end (string-match replace_string string start))
3719 (concat ret_string (substring string start end) replace_with))
3720 (setq start (match-end 0)))
3721 (setq ret_string (concat ret_string (substring string start last)))))
3723 (defun idlwave-get-buffer-visiting (file)
3724 ;; Return the buffer currently visiting FILE
3726 ((boundp 'find-file-compare-truenames) ; XEmacs
3727 (let ((find-file-compare-truenames t))
3728 (get-file-buffer file)))
3729 ((fboundp 'find-buffer-visiting) ; Emacs
3730 (find-buffer-visiting file))
3731 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3733 (defvar idlwave-outlawed-buffers nil
3734 "List of buffer pulled up by idlwave for special reasons.
3735 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3737 (defun idlwave-find-file-noselect (file &optional why)
3738 ;; Return a buffer visiting file.
3739 (or (idlwave-get-buffer-visiting file)
3740 (let ((buf (find-file-noselect file)))
3741 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3744 (defun idlwave-kill-autoloaded-buffers ()
3745 "Cleanup by killing buffers created automatically by IDLWAVE.
3746 Function prompts for a letter to identify the buffers to kill.
3747 Possible letters are:
3749 f Buffers created by the command \\[idlwave-find-module] or mouse
3750 clicks in the routine info window.
3751 s Buffers created by the IDLWAVE Shell to display where execution
3752 stopped or an error was found.
3753 a Both of the above.
3755 Buffer containing unsaved changes require confirmation before they are killed."
3757 (if (null idlwave-outlawed-buffers)
3758 (error "No IDLWAVE-created buffers available")
3759 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3760 (idlwave-count-outlawed-buffers 'find)
3761 (idlwave-count-outlawed-buffers 'shell)))
3762 (let ((c (read-char)))
3764 ((member c '(?f ?\C-f))
3765 (idlwave-do-kill-autoloaded-buffers 'find))
3766 ((member c '(?s ?\C-s))
3767 (idlwave-do-kill-autoloaded-buffers 'shell))
3768 ((member c '(?a ?\C-a))
3769 (idlwave-do-kill-autoloaded-buffers t))
3770 (t (error "Abort"))))))
3772 (defun idlwave-count-outlawed-buffers (tag)
3773 "How many outlawed buffers have tag TAG?"
3776 (lambda (x) (eq (cdr x) tag))
3777 idlwave-outlawed-buffers))))
3779 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3780 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3781 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3784 (while (setq entry (pop list))
3785 (if (buffer-live-p (car entry))
3786 (and (or (memq t reasons)
3787 (memq (cdr entry) reasons))
3788 (kill-buffer (car entry))
3790 (setq idlwave-outlawed-buffers
3791 (delq entry idlwave-outlawed-buffers)))
3792 (setq idlwave-outlawed-buffers
3793 (delq entry idlwave-outlawed-buffers))))
3794 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3796 (defun idlwave-revoke-license-to-kill ()
3797 "Remove BUFFER from the buffers which may be killed.
3798 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3799 Intended for `after-save-hook'."
3800 (let* ((buf (current-buffer))
3801 (entry (assq buf idlwave-outlawed-buffers)))
3804 (setq idlwave-outlawed-buffers
3805 (delq entry idlwave-outlawed-buffers)))
3806 ;; Remove this function from the hook.
3807 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3809 (defvar idlwave-path-alist)
3810 (defun idlwave-locate-lib-file (file)
3811 ;; Find FILE on the scanned lib path and return a buffer visiting it
3812 (let* ((dirs idlwave-path-alist)
3815 (while (setq dir (car (pop dirs)))
3817 (setq efile (expand-file-name file dir)))
3818 (throw 'exit efile))))))
3819 (defun idlwave-expand-lib-file-name (file)
3820 ;; Find FILE on the scanned lib path and return a buffer visiting it
3823 ((string-match "\\`\\({\\([0-9]+\\)}/\\)\\(.*\\)" file)
3824 (expand-file-name (match-string 3 file)
3825 (car (nth (1- (string-to-int (match-string 2 file)))
3826 idlwave-path-alist))))
3827 ((file-name-absolute-p file) file)
3828 (t (idlwave-locate-lib-file file))))
3830 (defun idlwave-make-tags ()
3831 "Creates the IDL tags file IDLTAGS in the current directory from
3832 the list of directories specified in the minibuffer. Directories may be
3833 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3834 specified top directories are searched if the directory name is prefixed
3835 by @. Specify @ directories with care, it may take a long, long time if
3838 (let (directory directories cmd append status numdirs dir getsubdirs
3839 buffer save_buffer files numfiles item errbuf)
3842 ;; Read list of directories
3843 (setq directory (read-string "Tag Directories: " "."))
3844 (setq directories (idlwave-split-string directory "[ \t]+"))
3846 ;; Set etags command, vars
3847 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3848 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3849 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3853 ;; For each directory
3855 (setq dir (nth numdirs directories))
3858 ;; Find the subdirectories
3859 (if (string-match "^[@]\\(.+\\)$" dir)
3860 (setq getsubdirs t) (setq getsubdirs nil))
3861 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3862 (setq dir (expand-file-name dir))
3863 (if (file-directory-p dir)
3865 (if (and getsubdirs)
3867 (setq buffer (get-buffer-create "*idltags*"))
3868 (call-process "sh" nil buffer nil "-c"
3869 (concat "find " dir " -type d -print"))
3870 (setq save_buffer (current-buffer))
3872 (setq files (idlwave-split-string
3873 (idlwave-replace-string
3874 (buffer-substring 1 (point-max))
3877 (set-buffer save_buffer)
3878 (kill-buffer buffer))
3879 (setq files (list (concat dir "/*.pro"))))
3881 ;; For each subdirectory
3883 (setq item (nth numfiles files))
3887 (if (not (string-match "^[ \\t]*$" item))
3889 (message (concat "Tagging " item "..."))
3890 (setq errbuf (get-buffer-create "*idltags-error*"))
3893 (if (eq 0 (call-process "sh" nil errbuf nil "-c"
3894 (concat cmd append item)))
3898 ;; Append additional tags
3899 (setq append " --append ")
3900 (setq numfiles (1+ numfiles))
3901 (setq item (nth numfiles files)))
3903 (setq numfiles (1+ numfiles))
3904 (setq item (nth numfiles files))
3907 (setq numdirs (1+ numdirs))
3908 (setq dir (nth numdirs directories)))
3910 (setq numdirs (1+ numdirs))
3911 (setq dir (nth numdirs directories)))))
3913 (setq errbuf (get-buffer-create "*idltags-error*"))
3915 (kill-buffer errbuf))
3919 (defun idlwave-toggle-comment-region (beg end &optional n)
3920 "Comment the lines in the region if the first non-blank line is
3921 commented, and conversely, uncomment region. If optional prefix arg
3922 N is non-nil, then for N positive, add N comment delimiters or for N
3923 negative, remove N comment delimiters.
3924 Uses `comment-region' which does not place comment delimiters on
3926 (interactive "r\nP")
3928 (comment-region beg end (prefix-numeric-value n))
3933 (skip-chars-forward " \t\n")
3934 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
3935 (comment-region beg end
3936 (- (length (buffer-substring
3939 (comment-region beg end)))))
3942 ;; ----------------------------------------------------------------------------
3943 ;; ----------------------------------------------------------------------------
3944 ;; ----------------------------------------------------------------------------
3945 ;; ----------------------------------------------------------------------------
3947 ;; Completion and Routine Info
3950 ;; String "intern" functions
3952 ;; For the completion and routine info function, we want to normalize
3953 ;; the case of procedure names etc. We do this by "interning" these
3954 ;; string is a hand-crafted way. Hashes are used to map the downcase
3955 ;; version of the strings to the cased versions. Since these cased
3956 ;; versions are really lisp objects, we can use `eq' to search, which
3957 ;; is a large performance boost.
3958 ;; All new strings need to be "sinterned". We do this as early as
3959 ;; possible after getting these strings from completion or buffer
3960 ;; substrings. So most of the code can simply assume to deal with
3961 ;; "sinterned" strings. The only exception is that the functions
3962 ;; which scan whole buffers for routine information do not intern the
3963 ;; grabbed strings. This is only done afterwards. Therefore in these
3964 ;; functions it is *not* safe to assume the strings can be compared
3965 ;; with `eq' and be fed into the routine assq functions.
3967 ;; Here we define the hashing functions.
3969 ;; The variables which hold the hashes.
3970 (defvar idlwave-sint-routines '(nil))
3971 (defvar idlwave-sint-keywords '(nil))
3972 (defvar idlwave-sint-methods '(nil))
3973 (defvar idlwave-sint-classes '(nil))
3974 (defvar idlwave-sint-files '(nil))
3976 (defun idlwave-reset-sintern (&optional what)
3977 "Reset all sintern hashes."
3978 ;; Make sure the hash functions are accessible.
3979 (if (or (not (fboundp 'gethash))
3980 (not (fboundp 'puthash)))
3983 (or (fboundp 'puthash)
3984 (defalias 'puthash 'cl-puthash))))
3985 (let ((entries '((idlwave-sint-routines 1000 10)
3986 (idlwave-sint-keywords 1000 10)
3987 (idlwave-sint-methods 100 10)
3988 (idlwave-sint-classes 10 10))))
3990 ;; Make sure these are lists
3991 (loop for entry in entries
3992 for var = (car entry)
3993 do (if (not (consp (symbol-value var))) (set var (list nil))))
3995 (when (or (eq what t) (eq what 'syslib)
3996 (null (cdr idlwave-sint-routines)))
3997 ;; Reset the system & library hash
3998 (loop for entry in entries
3999 for var = (car entry) for size = (nth 1 entry)
4000 do (setcdr (symbol-value var)
4001 (make-hash-table ':size size ':test 'equal)))
4002 (setq idlwave-sint-files nil))
4004 (when (or (eq what t) (eq what 'bufsh)
4005 (null (car idlwave-sint-routines)))
4006 ;; Reset the buffer & shell hash
4007 (loop for entry in entries
4008 for var = (car entry) for size = (nth 1 entry)
4009 do (setcar (symbol-value var)
4010 (make-hash-table ':size size ':test 'equal))))))
4012 (defun idlwave-sintern-routine-or-method (name &optional class set)
4014 (idlwave-sintern-method name set)
4015 (idlwave-sintern-routine name set)))
4017 (defun idlwave-sintern (stype &rest args)
4018 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4020 ;;(defmacro idlwave-sintern (type var)
4021 ;; `(cond ((not (stringp name)) name)
4022 ;; ((gethash (downcase name) (cdr ,var)))
4023 ;; ((gethash (downcase name) (car ,var)))
4024 ;; (set (idlwave-sintern-set name ,type ,var set))
4027 (defun idlwave-sintern-routine (name &optional set)
4028 (cond ((not (stringp name)) name)
4029 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4030 ((gethash (downcase name) (car idlwave-sint-routines)))
4031 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4033 (defun idlwave-sintern-keyword (name &optional set)
4034 (cond ((not (stringp name)) name)
4035 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4036 ((gethash (downcase name) (car idlwave-sint-keywords)))
4037 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4039 (defun idlwave-sintern-method (name &optional set)
4040 (cond ((not (stringp name)) name)
4041 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4042 ((gethash (downcase name) (car idlwave-sint-methods)))
4043 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4045 (defun idlwave-sintern-class (name &optional set)
4046 (cond ((not (stringp name)) name)
4047 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4048 ((gethash (downcase name) (car idlwave-sint-classes)))
4049 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4052 (defun idlwave-sintern-file (name &optional set)
4053 (car (or (member name idlwave-sint-files)
4054 (setq idlwave-sint-files (cons name idlwave-sint-files)))))
4056 (defun idlwave-sintern-set (name type tables set)
4057 (let* ((func (or (cdr (assq type idlwave-completion-case))
4059 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4060 (table (if (eq set 'sys) (cdr tables) (car tables))))
4061 (puthash (downcase name) iname table)
4064 (defun idlwave-sintern-rinfo-list (list &optional set)
4065 "Sintern all strings in the rinfo LIST. With optional parameter SET:
4066 also set new patterns. Probably this will always have to be t."
4067 (let (entry name type class kwds res source call olh new)
4069 (setq entry (car list)
4074 source (nth 3 entry)
4078 (setq kwds (mapcar (lambda (x)
4079 (list (idlwave-sintern-keyword (car x) set)))
4083 (if (symbolp class) (setq class (symbol-name class)))
4084 (setq class (idlwave-sintern-class class set))
4085 (setq name (idlwave-sintern-method name set)))
4086 (setq name (idlwave-sintern-routine name set)))
4087 (if (stringp (cdr source))
4088 (setcdr source (idlwave-sintern-file (cdr source) t)))
4090 (list name type class source call kwds olh)
4091 (list name type class source call kwds)))
4092 (setq res (cons new res)))
4095 ;; Creating new sintern tables
4097 (defun idlwave-new-sintern-type (tag)
4098 "Define a variable and a function to sintern the new type TAG.
4099 This defines the function `idlwave-sintern-TAG' and the variable
4100 `idlwave-sint-TAGs'."
4101 (let* ((name (symbol-name tag))
4102 (names (concat name "s"))
4103 (var (intern (concat "idlwave-sint-" names)))
4104 (func (intern (concat "idlwave-sintern-" name))))
4105 (set var nil) ; initial value of the association list
4106 (fset func ; set the function
4107 `(lambda (name &optional set)
4108 (cond ((not (stringp name)) name)
4109 ((cdr (assoc (downcase name) ,var)))
4111 (setq ,var (cons (cons (downcase name) name) ,var))
4115 (defun idlwave-reset-sintern-type (tag)
4116 "Reset the sintern variable associated with TAG."
4117 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4119 ;;---------------------------------------------------------------------------
4122 ;; The variables which hold the information
4123 (defvar idlwave-system-routines nil
4124 "Holds the routine-info obtained by scanning buffers.")
4125 (defvar idlwave-buffer-routines nil
4126 "Holds the routine-info obtained by scanning buffers.")
4127 (defvar idlwave-compiled-routines nil
4128 "Holds the routine-info obtained by asking the shell.")
4129 (defvar idlwave-unresolved-routines nil
4130 "Holds the unresolved routine-info obtained by asking the shell.")
4131 (defvar idlwave-library-routines nil
4132 "Holds the procedure routine-info from the library scan.")
4133 (defvar idlwave-path-alist nil
4134 "Alist with !PATH directories and a flag if the dir has been scanned.")
4135 (defvar idlwave-true-path-alist nil
4136 "Like `idlwave-path-alist', but with true filenames.")
4137 (defvar idlwave-routines nil
4138 "Holds the combinded procedure routine-info.")
4139 (defvar idlwave-class-alist nil
4140 "Holds the class names known to IDLWAVE.")
4141 (defvar idlwave-class-history nil
4142 "The history of classes selected with the minibuffer.")
4143 (defvar idlwave-force-class-query nil)
4144 (defvar idlwave-before-completion-wconf nil
4145 "The window configuration just before the completion buffer was displayed.")
4146 (defvar idlwave-last-system-routine-info-cons-cell nil
4147 "The last cons cell in the system routine info.")
4150 ;; The code to get routine info from different sources.
4152 (defvar idlwave-system-routines)
4153 (defvar idlwave-catalog-process nil
4154 "The background process currently updating the catalog.")
4156 (defun idlwave-routines ()
4157 "Provide a list of IDL routines.
4158 This routine loads the builtin routines on the first call. Later it
4159 only returns the value of the variable."
4160 (if (and idlwave-catalog-process
4161 (processp idlwave-catalog-process))
4164 ((equal (process-status idlwave-catalog-process) 'exit)
4165 (message "updating........")
4166 (setq idlwave-catalog-process nil)
4167 (idlwave-update-routine-info '(4)))
4168 ((equal (process-status idlwave-catalog-process) 'run)
4169 ;; Keep it running...
4172 ;; Something is wrong, get rid of the process
4173 (message "Problem with catalog process") (beep)
4175 (kill-process idlwave-catalog-process)
4177 (setq idlwave-catalog-process nil)))))
4178 (or idlwave-routines
4180 (idlwave-update-routine-info)
4181 ;; return the current value
4184 (defvar idlwave-update-rinfo-hook nil
4185 "List of functions which should run after a global rinfo update.
4186 Does not run after automatic updates of buffer or the shell.")
4188 (defun idlwave-rescan-catalog-directories ()
4189 "Rescan the previously selected directories. For batch processing."
4190 (idlwave-update-routine-info '(16)))
4192 (defun idlwave-rescan-asynchronously ()
4193 "Dispatch another emacs instance to update the idlwave catalog.
4194 After the process finishes normally, the first access to routine info
4195 will re-read the catalog."
4197 (if (processp idlwave-catalog-process)
4198 (if (eq (process-status idlwave-catalog-process) 'run)
4199 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4202 (kill-process idlwave-catalog-process)
4204 (error "Process killed, no new process started"))
4207 (kill-process idlwave-catalog-process)
4209 (if (or (not idlwave-libinfo-file)
4210 (not (stringp idlwave-libinfo-file))
4211 (not (file-regular-p idlwave-libinfo-file)))
4212 (error "No catalog has been produced yet"))
4213 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4214 (args (list "-batch"
4215 "-l" (expand-file-name "~/.emacs")
4217 "-f" "idlwave-rescan-catalog-directories"))
4218 (process (apply 'start-process "idlcat"
4220 (setq idlwave-catalog-process process)
4221 (set-process-sentinel
4224 (when (string-match "finished" why)
4225 (setq idlwave-routines nil
4226 idlwave-system-routines nil
4227 idlwave-catalog-process nil)
4228 (or (idlwave-start-load-rinfo-timer)
4229 (idlwave-update-routine-info '(4))))))
4230 (message "Background job started to update catalog file")))
4233 (defvar idlwave-load-rinfo-idle-timer)
4234 (defun idlwave-update-routine-info (&optional arg)
4235 "Update the internal routine-info lists.
4236 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4237 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4238 about individual routines.
4240 The information can come from 4 sources:
4241 1. IDL programs in the current editing session
4242 2. Compiled modules in an IDL shell running as Emacs subprocess
4243 3. A list which covers the IDL system routines.
4244 4. A list which covers the prescanned library files.
4246 Scans all IDLWAVE-mode buffers of the current editing session (see
4247 `idlwave-scan-all-buffers-for-routine-info').
4248 When an IDL shell is running, this command also queries the IDL program
4249 for currently compiled routines.
4251 With prefix ARG, also reload the system and library lists.
4252 With two prefix ARG's, also rescans the library tree.
4253 With three prefix args, dispatch asynchronous process to do the update."
4255 ;; Stop any idle processing
4256 (if (or (and (fboundp 'itimerp)
4257 (itimerp idlwave-load-rinfo-idle-timer))
4258 (and (fboundp 'timerp)
4259 (timerp idlwave-load-rinfo-idle-timer)))
4260 (cancel-timer idlwave-load-rinfo-idle-timer))
4263 ;; Start a background process which updates the catalog.
4264 (idlwave-rescan-asynchronously))
4266 ;; Update the catalog now, and wait for it.
4267 (idlwave-create-libinfo-file t))
4269 (let* ((load (or arg
4270 idlwave-buffer-case-takes-precedence
4271 (null idlwave-routines)))
4272 ;; The override-idle means, even if the idle timer has done some
4273 ;; preparing work, load and renormalize everything anyway.
4274 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4276 (setq idlwave-buffer-routines nil
4277 idlwave-compiled-routines nil
4278 idlwave-unresolved-routines nil)
4279 ;; Reset the appropriate hashes
4280 (if (get 'idlwave-reset-sintern 'done-by-idle)
4281 ;; reset was already done in idle time, so skip this step now once
4282 (put 'idlwave-reset-sintern 'done-by-idle nil)
4283 (idlwave-reset-sintern (cond (load t)
4284 ((null idlwave-system-routines) t)
4287 (if idlwave-buffer-case-takes-precedence
4288 ;; We can safely scan the buffer stuff first
4290 (idlwave-update-buffer-routine-info)
4291 (and load (idlwave-load-system-rinfo override-idle)))
4292 ;; We first do the system info, and then the buffers
4293 (and load (idlwave-load-system-rinfo override-idle))
4294 (idlwave-update-buffer-routine-info))
4296 ;; Let's see if there is a shell
4297 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4298 (idlwave-shell-is-running)))
4299 (ask-shell (and shell-is-running
4300 idlwave-query-shell-for-routine-info)))
4302 (if (or (not ask-shell)
4303 (not (interactive-p)))
4304 ;; 1. If we are not going to ask the shell, we need to do the
4305 ;; concatenation now.
4306 ;; 2. When this function is called non-interactively, it means
4307 ;; that someone needs routine info *now*. The shell update
4308 ;; causes the concatenation *delayed*, so not in time for
4309 ;; the current command. Therefore, we do a concatenation
4310 ;; now, even though the shell might do it again.
4311 (idlwave-concatenate-rinfo-lists nil t))
4314 ;; Ask the shell about the routines it knows.
4315 (message "Querying the shell")
4316 (idlwave-shell-update-routine-info nil t)))))))
4318 (defvar idlwave-load-rinfo-steps-done (make-vector 5 nil))
4319 (defvar idlwave-load-rinfo-idle-timer nil)
4320 (defun idlwave-start-load-rinfo-timer ()
4321 (if (or (and (fboundp 'itimerp)
4322 (itimerp idlwave-load-rinfo-idle-timer))
4323 (and (fboundp 'timerp)
4324 (timerp idlwave-load-rinfo-idle-timer)))
4325 (cancel-timer idlwave-load-rinfo-idle-timer))
4326 (setq idlwave-load-rinfo-steps-done (make-vector 5 nil))
4327 (setq idlwave-load-rinfo-idle-timer nil)
4328 (if (and idlwave-init-rinfo-when-idle-after
4329 (numberp idlwave-init-rinfo-when-idle-after)
4330 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4331 (not idlwave-routines))
4334 (setq idlwave-load-rinfo-idle-timer
4335 (run-with-idle-timer
4336 idlwave-init-rinfo-when-idle-after
4337 nil 'idlwave-load-rinfo-next-step)))
4342 (defun idlwave-load-rinfo-next-step ()
4343 (let ((inhibit-quit t)
4344 (arr idlwave-load-rinfo-steps-done))
4346 (when (not (aref arr 0))
4347 (message "Loading idlw-rinfo.el in idle time...")
4348 (load "idlw-rinfo" 'noerror 'nomessage)
4349 (message "Loading idlw-rinfo.el in idle time...done")
4352 (when (not (aref arr 1))
4353 (message "Normalizing idlwave-system-routines in idle time...")
4354 (idlwave-reset-sintern t)
4355 (put 'idlwave-reset-sintern 'done-by-idle t)
4356 (setq idlwave-system-routines
4357 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4358 (message "Normalizing idlwave-system-routines in idle time...done")
4361 (when (not (aref arr 2))
4362 (when (and (stringp idlwave-libinfo-file)
4363 (file-regular-p idlwave-libinfo-file))
4366 (message "Loading library catalog in idle time...")
4367 (load-file idlwave-libinfo-file)
4368 (message "Loading library catalog in idle time...done")
4371 (error (throw 'exit nil)))))
4372 (when (not (aref arr 3))
4373 (when idlwave-library-routines
4374 (message "Normalizing idlwave-library-routines in idle time...")
4375 (setq idlwave-library-routines (idlwave-sintern-rinfo-list
4376 idlwave-library-routines 'sys))
4377 (message "Normalizing idlwave-library-routines in idle time...done"))
4380 (when (not (aref arr 4))
4381 (message "Finishing initialization in idle time...")
4383 (message "Finishing initialization in idle time...done")
4386 ;; restart the timer
4388 (idlwave-load-rinfo-next-step)
4389 (setq idlwave-load-rinfo-idle-timer
4390 (run-with-idle-timer
4391 idlwave-init-rinfo-when-idle-after
4392 nil 'idlwave-load-rinfo-next-step)))
4395 (defun idlwave-load-system-rinfo (&optional force)
4396 ;; Load and case-treat the system and lib info files.
4397 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
4398 (load "idlw-rinfo" 'noerror 'nomessage))
4399 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
4400 (message "Normalizing idlwave-system-routines...")
4401 (setq idlwave-system-routines
4402 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4403 (message "Normalizing idlwave-system-routines...done"))
4404 (setq idlwave-routines (copy-sequence idlwave-system-routines))
4405 (setq idlwave-last-system-routine-info-cons-cell
4406 (nthcdr (1- (length idlwave-routines)) idlwave-routines))
4407 (when (and (stringp idlwave-libinfo-file)
4408 (file-regular-p idlwave-libinfo-file))
4411 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
4412 (load-file idlwave-libinfo-file))
4413 (setq idlwave-true-path-alist nil)
4414 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
4415 (message "Normalizing idlwave-library-routines...")
4416 (setq idlwave-library-routines (idlwave-sintern-rinfo-list
4417 idlwave-library-routines 'sys))
4418 (message "Normalizing idlwave-library-routines...done")))
4421 (run-hooks 'idlwave-after-load-rinfo-hook))
4424 (defun idlwave-update-buffer-routine-info ()
4427 ((eq idlwave-scan-all-buffers-for-routine-info t)
4428 ;; Scan all buffers, current buffer last
4429 (message "Scanning all buffers...")
4430 (setq res (idlwave-get-routine-info-from-buffers
4431 (reverse (buffer-list)))))
4432 ((null idlwave-scan-all-buffers-for-routine-info)
4433 ;; Don't scan any buffers
4436 ;; Just scan this buffer
4437 (if (eq major-mode 'idlwave-mode)
4439 (message "Scanning current buffer...")
4440 (setq res (idlwave-get-routine-info-from-buffers
4441 (list (current-buffer))))))))
4442 ;; Put the result into the correct variable
4443 (setq idlwave-buffer-routines
4444 (idlwave-sintern-rinfo-list res t))))
4446 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
4447 "Put the different sources for routine information together."
4448 ;; The sequence here is important because earlier definitions shadow
4449 ;; later ones. We assume that if things in the buffers are newer
4450 ;; then in the shell of the system, it is meant to be different.
4452 (setcdr idlwave-last-system-routine-info-cons-cell
4453 (append idlwave-buffer-routines
4454 idlwave-compiled-routines
4455 idlwave-library-routines))
4456 (setq idlwave-class-alist nil)
4458 ;; Give a message with information about the number of routines we have.
4461 "Routine info updated: buffer(%d) compiled(%d) catalog(%d) system(%d)"
4462 (length idlwave-buffer-routines)
4463 (length idlwave-compiled-routines)
4464 (length idlwave-library-routines)
4465 (length idlwave-system-routines)))
4467 (run-hooks 'idlwave-update-rinfo-hook)))
4469 (defun idlwave-class-alist ()
4470 "Return the class alist - make it if necessary."
4471 (or idlwave-class-alist
4473 (loop for x in idlwave-routines do
4474 (when (and (setq class (nth 2 x))
4475 (not (assq class idlwave-class-alist)))
4476 (push (list class) idlwave-class-alist)))
4477 idlwave-class-alist)))
4479 ;; Three functions for the hooks
4480 (defun idlwave-save-buffer-update ()
4481 (idlwave-update-current-buffer-info 'save-buffer))
4482 (defun idlwave-kill-buffer-update ()
4483 (idlwave-update-current-buffer-info 'kill-buffer))
4484 (defun idlwave-new-buffer-update ()
4485 (idlwave-update-current-buffer-info 'find-file))
4487 (defun idlwave-update-current-buffer-info (why)
4488 "Undate idlwave-routines for current buffer. Can run from after-save-hook."
4489 (when (and (eq major-mode 'idlwave-mode)
4490 (or (eq t idlwave-auto-routine-info-updates)
4491 (memq why idlwave-auto-routine-info-updates))
4492 idlwave-scan-all-buffers-for-routine-info
4496 (idlwave-replace-buffer-routine-info
4498 (if (eq why 'kill-buffer)
4501 (idlwave-sintern-rinfo-list
4502 (idlwave-get-routine-info-from-buffers
4503 (list (current-buffer))) 'set))))
4504 (idlwave-concatenate-rinfo-lists 'quiet)
4508 (defun idlwave-replace-buffer-routine-info (file new)
4509 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4510 (let ((list idlwave-buffer-routines)
4513 ;; The following test uses eq to make sure it works correctly
4514 ;; when two buffers visit the same file. Then the file names
4515 ;; will be equal, but not eq.
4516 (if (eq (cdr (nth 3 (car list))) file)
4521 ;; End of that section reached. Jump.
4523 (setq list (cdr list)))
4524 (setq idlwave-buffer-routines
4525 (append new (delq nil idlwave-buffer-routines)))))
4527 ;;----- Scanning buffers -------------------
4529 (defun idlwave-get-routine-info-from-buffers (buffers)
4530 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4531 (let (buf routine-lists res)
4533 (while (setq buf (pop buffers))
4535 (if (and (eq major-mode 'idlwave-mode)
4537 ;; yes, this buffer has the right mode.
4538 (progn (setq res (condition-case nil
4539 (idlwave-get-buffer-routine-info)
4541 (push res routine-lists)))))
4542 ;; Concatenate the individual lists and return the result
4543 (apply 'nconc routine-lists)))
4545 (defun idlwave-get-buffer-routine-info ()
4546 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4547 (let* ((case-fold-search t)
4548 routine-list string entry)
4552 (goto-char (point-min))
4553 (while (re-search-forward
4554 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
4555 (setq string (buffer-substring-no-properties
4558 (idlwave-end-of-statement)
4560 (setq entry (idlwave-parse-definition string))
4561 (push entry routine-list))))
4564 (defvar idlwave-scanning-lib-dir)
4565 (defun idlwave-parse-definition (string)
4566 "Parse a module definition."
4567 (let ((case-fold-search t)
4568 start name args type keywords class)
4570 (while (string-match ";.*" string)
4571 (setq string (replace-match "" t t string)))
4572 ;; Remove the continuation line stuff
4573 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
4574 (setq string (replace-match "\\1 " t nil string)))
4575 (while (string-match "\n" string)
4576 (setq string (replace-match " " t nil string)))
4577 ;; Match the name and type.
4579 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
4580 (setq start (match-end 0))
4581 (setq type (downcase (match-string 1 string)))
4582 (if (match-beginning 3)
4583 (setq class (match-string 3 string)))
4584 (setq name (match-string 4 string)))
4585 ;; Match normal args and keyword args
4586 (while (string-match
4587 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4589 (setq start (match-end 0))
4590 (if (match-beginning 3)
4591 (push (match-string 1 string) keywords)
4592 (push (match-string 1 string) args)))
4593 ;; Normalize and sort.
4594 (setq args (nreverse args))
4595 (setq keywords (sort keywords (lambda (a b)
4596 (string< (downcase a) (downcase b)))))
4597 ;; Make and return the entry
4598 ;; We don't know which argument are optional, so this information
4599 ;; will not be contained in the calling sequence.
4601 (if (equal type "pro") 'pro 'fun)
4603 (cond ((not (boundp 'idlwave-scanning-lib))
4604 (cons 'buffer (buffer-file-name)))
4605 ; ((string= (downcase
4606 ; (file-name-sans-extension
4607 ; (file-name-nondirectory (buffer-file-name))))
4610 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4611 (t (cons 'lib (concat idlwave-scanning-lib-dir
4612 (file-name-nondirectory (buffer-file-name))))))
4614 (if (string= type "function") "Result = " "")
4615 (if class "Obj ->[%s::]" "")
4619 (if (string= type "function") "(" ", ")
4620 (mapconcat 'identity args ", ")
4621 (if (string= type "function") ")" ""))))
4623 (mapcar 'list keywords)
4626 ;;----- Scanning the library -------------------
4628 (defvar idlwave-sys-dir nil
4629 "Internal variable.")
4631 (defun idlwave-sys-dir ()
4632 "Return the syslib directory, or a dummy that never matches."
4636 (defvar idlwave-shell-path-query)
4637 (defun idlwave-create-libinfo-file (&optional arg)
4638 "Scan all files on selected dirs of IDL search path for routine information.
4639 A widget checklist will allow you to choose the directories.
4640 Write the result as a file `idlwave-libinfo-file'. When this file exists,
4641 will be automatically loaded to give routine information about library
4643 With ARG, just rescan the same directories as last time - so no widget
4646 ;; Make sure the file is loaded if it exists.
4647 (if (and (stringp idlwave-libinfo-file)
4648 (file-regular-p idlwave-libinfo-file))
4650 (load-file idlwave-libinfo-file)
4652 ;; Make sure the file name makes sense
4653 (unless (and (stringp idlwave-libinfo-file)
4654 (> (length idlwave-libinfo-file) 0)
4655 (file-accessible-directory-p
4656 (file-name-directory idlwave-libinfo-file))
4657 (not (string= "" (file-name-nondirectory
4658 idlwave-libinfo-file))))
4659 (error "`idlwave-libinfo-file' does not point to file in accessible directory"))
4662 ((and arg idlwave-path-alist
4663 (consp (car idlwave-path-alist))
4665 ;; Rescan the known directories
4666 (idlwave-scan-lib-files
4668 idlwave-path-alist))
4669 (idlwave-library-path
4670 ;; Get the directories from that variable
4671 (idlwave-display-libinfo-widget
4672 idlwave-system-directory
4673 (idlwave-expand-path idlwave-library-path)
4674 (delq nil (mapcar (lambda (x) (if (consp x) (if (cdr x) (car x) nil) x))
4675 idlwave-path-alist))))
4677 ;; Ask the shell for the path and run the widget
4678 (message "Asking the shell for IDL path...")
4679 (require 'idlw-shell)
4680 (idlwave-shell-send-command idlwave-shell-path-query
4681 '(idlwave-libinfo-command-hook nil)
4684 (defun idlwave-libinfo-command-hook (&optional arg)
4685 ;; Command hook used by `idlwave-create-libinfo-file'.
4688 (idlwave-scan-lib-files
4691 ;; Display the widget
4692 (let* ((rpl (idlwave-shell-path-filter))
4695 (idlwave-display-libinfo-widget
4697 (delq nil (mapcar (lambda (x) (if (cdr x) (car x) nil))
4698 idlwave-path-alist))))))
4700 (defconst idlwave-libinfo-widget-help-string
4701 "This is the front-end to the creation of IDLWAVE library catalog.
4702 Please select below the directories on IDL's search path from which you
4703 would like to extract routine information, which will be stored in the file
4707 If this is not the correct file, first set variable `idlwave-libinfo-file'.
4708 Then call this command again.
4710 For writing code, you need to include the directories which contain the
4711 routines you use. If IDLWAVE should be able to analyse routine shadowing
4712 it is best to scan all directories.
4714 After selecting the directories, choose [Scan & Save] to scan the library
4715 directories and save the routine info.
4718 (defvar idlwave-widget)
4719 (defvar widget-keymap)
4720 (defun idlwave-display-libinfo-widget (sysdir dirs selected-dirs)
4721 "Create the widget to select IDL search path directories for scanning."
4726 (error "Don't know IDL's search path"))
4728 ;; Allow only those directories to be selected which are in the path.
4729 (setq selected-dirs (delq nil (mapcar (lambda (x)
4730 (if (member x dirs) x nil))
4732 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4733 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4734 (kill-all-local-variables)
4735 (make-local-variable 'idlwave-widget)
4736 (widget-insert (format idlwave-libinfo-widget-help-string
4737 idlwave-libinfo-file))
4739 (widget-create 'push-button
4740 :notify 'idlwave-widget-scan-lib-files
4743 (widget-create 'push-button
4744 :notify (lambda (&rest ignore)
4745 (kill-buffer (current-buffer)))
4748 (widget-create 'push-button
4749 :notify 'idlwave-delete-libinfo-file
4752 (widget-create 'push-button
4753 :notify '(lambda (&rest ignore)
4754 (idlwave-display-libinfo-widget
4755 (widget-get idlwave-widget :sysdir)
4756 (widget-get idlwave-widget :path-dirs)
4757 (widget-get idlwave-widget :path-dirs)))
4760 (widget-create 'push-button
4761 :notify '(lambda (&rest ignore)
4762 (idlwave-display-libinfo-widget
4763 (widget-get idlwave-widget :sysdir)
4764 (widget-get idlwave-widget :path-dirs)
4767 (widget-insert "\n\n")
4769 (widget-insert "Select Directories\n")
4771 (setq idlwave-widget
4772 (apply 'widget-create
4774 :value selected-dirs
4776 :tag "List of directories"
4777 (mapcar (lambda (x) (list 'item x)) dirs)))
4778 (widget-put idlwave-widget :path-dirs dirs)
4779 (widget-put idlwave-widget :sysdir sysdir)
4780 (widget-insert "\n")
4781 (use-local-map widget-keymap)
4783 (goto-char (point-min))
4784 (delete-other-windows))
4786 (defun idlwave-delete-libinfo-file (&rest ignore)
4788 (format "Delete file %s " idlwave-libinfo-file))
4790 (delete-file idlwave-libinfo-file)
4791 (message "%s has been deleted" idlwave-libinfo-file))))
4793 (defun idlwave-widget-scan-lib-files (&rest ignore)
4794 ;; Call `idlwave-scan-lib-files' with data taken from the widget.
4795 (let* ((widget idlwave-widget)
4796 (selected-dirs (widget-value widget))
4797 (sysdir (widget-get widget :sysdir))
4798 (path-dirs (widget-get widget :path-dirs))
4800 (mapcar (lambda (x) (cons x (if (member x selected-dirs) t nil)))
4802 (idlwave-scan-lib-files sysdir path-dir-alist)))
4804 (defvar font-lock-mode)
4805 (defun idlwave-scan-lib-files (sysdir path-alist)
4806 ;; Scan the files in PATH-ALIST and store the info in a file
4807 (let* ((idlwave-scanning-lib t)
4808 (idlwave-scanning-lib-dir "")
4809 (dircnt (1+ (length path-alist)))
4810 (idlwave-completion-case nil)
4811 dirs-alist dir files file)
4812 (setq idlwave-library-routines nil)
4813 (setq idlwave-path-alist path-alist)
4814 (setq idlwave-true-path-alist nil)
4815 (setq idlwave-sys-dir sysdir)
4817 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
4819 (setq dirs-alist (reverse path-alist))
4820 (while (setq dir (pop dirs-alist))
4823 ;; Has the flag of scanned directories
4824 (setq dir (car dir))
4825 (setq idlwave-scanning-lib-dir (format "{%d}/" dircnt))
4826 (when (file-directory-p dir)
4827 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
4828 (while (setq file (pop files))
4829 (when (file-regular-p file)
4830 (if (not (file-readable-p file))
4831 (message "Skipping %s (no read permission)" file)
4832 (message "Scanning %s..." file)
4834 (insert-file-contents file 'visit)
4835 (setq idlwave-library-routines
4836 (append (idlwave-get-routine-info-from-buffers
4837 (list (current-buffer)))
4838 idlwave-library-routines)))
4840 ;; Sorting is not necessary since we sort each time before a routine
4841 ;; is used. So we don't do it here - the catalog file looks nicer
4842 ;; when it is unsorted.
4843 ;;(message "Sorting...")
4844 ;;(setq idlwave-library-routines
4845 ;;(sort idlwave-library-routines 'idlwave-routine-entry-compare))
4846 ;;(message "Sorting...done")
4847 (message "Creating libinfo file...")
4848 (kill-buffer "*idlwave-scan.pro*")
4849 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4850 (let ((font-lock-maximum-size 0)
4851 (auto-mode-alist nil))
4852 (find-file idlwave-libinfo-file))
4853 (if (and (boundp 'font-lock-mode)
4857 (insert ";; IDLWAVE libinfo file\n")
4858 (insert (format ";; Created %s\n\n" (current-time-string)))
4860 ;; Define the variable which knows the value of "!DIR"
4861 (insert (format "\n(setq idlwave-sys-dir \"%s\")\n"
4864 ;; Define the variable which contains a list of all scanned directories
4865 (insert "\n(setq idlwave-path-alist\n '(")
4867 (insert (format "\n (\"%s\" . %s)" (car x) (cdr x))))
4871 ;; Define the routine info list
4872 (insert "\n(setq idlwave-library-routines\n '(")
4873 (let ((standard-output (current-buffer)))
4877 (goto-char (point-max)))
4878 ; (insert (with-output-to-string (prin1 x))))
4879 idlwave-library-routines))
4880 (insert (format "))\n\n;;; %s ends here\n"
4881 (file-name-nondirectory idlwave-libinfo-file)))
4882 (goto-char (point-min))
4885 (kill-buffer (current-buffer)))
4886 (message "Creating libinfo file...done")
4887 (message "Info for %d routines saved in %s"
4888 (length idlwave-library-routines)
4889 idlwave-libinfo-file)
4891 (idlwave-update-routine-info t))
4893 (defun idlwave-expand-path (path &optional default-dir)
4894 ;; Expand parts of path starting with '+' recursively into directory list.
4895 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
4896 (message "Expanding path...")
4897 (let (path1 dir recursive)
4898 (while (setq dir (pop path))
4899 (if (setq recursive (string= (substring dir 0 1) "+"))
4900 (setq dir (substring dir 1)))
4902 (not (file-name-absolute-p dir)))
4903 (setq dir (expand-file-name dir default-dir)))
4905 ;; Expand recursively
4906 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
4909 (message "Expanding path...done")
4912 (defun idlwave-recursive-directory-list (dir)
4913 ;; Return a list of all directories below DIR, including DIR itself
4914 (let ((path (list dir)) path1 file files)
4915 (while (setq dir (pop path))
4916 (when (file-directory-p dir)
4917 (setq files (nreverse (directory-files dir t "[^.]")))
4918 (while (setq file (pop files))
4919 (if (file-directory-p file)
4920 (push (file-name-as-directory file) path)))
4924 ;;----- Asking the shell -------------------
4926 ;; First, here is the idl program which can be used to query IDL for
4927 ;; defined routines.
4928 (defconst idlwave-routine-info.pro
4930 ;; START OF IDLWAVE SUPPORT ROUTINES
4931 pro idlwave_print_info_entry,name,func=func,separator=sep
4932 ;; See if it's an object method
4933 if name eq '' then return
4934 func = keyword_set(func)
4935 methsep = strpos(name,'::')
4936 meth = methsep ne -1
4939 pars = routine_info(name,/parameters,functions=func)
4940 source = routine_info(name,/source,functions=func)
4941 nargs = pars.num_args
4942 nkw = pars.num_kw_args
4943 if nargs gt 0 then args = pars.args
4944 if nkw gt 0 then kwargs = pars.kw_args
4946 ;; Trim the class, and make the name
4948 class = strmid(name,0,methsep)
4949 name = strmid(name,methsep+2,strlen(name)-1)
4950 if nargs gt 0 then begin
4951 ;; remove the self argument
4952 wh = where(args ne 'SELF',nargs)
4953 if nargs gt 0 then args = args(wh)
4956 ;; No class, just a normal routine.
4962 if func then cs = 'Result = '
4963 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
4965 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
4966 if nargs gt 0 then begin
4967 for j=0,nargs-1 do begin
4969 if j lt nargs-1 then cs = cs + ', '
4972 if func then cs = cs + ')'
4973 ;; Keyword arguments
4975 if nkw gt 0 then begin
4976 for j=0,nkw-1 do begin
4977 kwstring = kwstring + ' ' + kwargs(j)
4981 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])(func)
4983 print,ret + ': ' + name + sep + class + sep + source(0).path $
4984 + sep + cs + sep + kwstring
4987 pro idlwave_routine_info
4989 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
4990 all = routine_info()
4991 for i=0,n_elements(all)-1 do $
4992 idlwave_print_info_entry,all(i),separator=sep
4993 all = routine_info(/functions)
4994 for i=0,n_elements(all)-1 do $
4995 idlwave_print_info_entry,all(i),/func,separator=sep
4996 print,'>>>END OF IDLWAVE ROUTINE INFO'
4999 pro idlwave_get_sysvars
5000 forward_function strjoin,strtrim,strsplit
5002 if error_status ne 0 then begin
5003 print, 'Cannot get info about system variables'
5005 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5006 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5007 v = strsplit(s,' +',/regex,/extract) ; get variables
5008 for i=0,n_elements(v)-1 do begin
5009 t = [''] ; get tag list
5010 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5011 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5016 pro idlwave_get_class_tags, class
5017 res = execute('tags=tag_names({'+class+'})')
5018 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5020 ;; END OF IDLWAVE SUPPORT ROUTINES
5022 "The idl programs to get info from the shell.")
5024 (defvar idlwave-idlwave_routine_info-compiled nil
5025 "Remembers if the routine info procedure is already compiled.")
5027 (defvar idlwave-shell-temp-pro-file)
5028 (defvar idlwave-shell-temp-rinfo-save-file)
5029 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks preempt)
5030 "Query the shell for routine_info of compiled modules and update the lists."
5031 ;; Save and compile the procedure. The compiled procedure is then
5032 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5033 ;; We need to RESTORE the procedure each time we use it, since
5034 ;; the user may have killed or redefined it. In particular,
5035 ;; .RESET_SESSION will kill all user procedures.
5036 (unless (and idlwave-idlwave_routine_info-compiled
5037 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5039 (set-buffer (idlwave-find-file-noselect
5040 (idlwave-shell-temp-file 'pro)))
5042 (insert idlwave-routine-info.pro)
5044 (idlwave-shell-send-command
5045 (concat ".run " idlwave-shell-temp-pro-file)
5047 ; (message "SENDING SAVE") ; ????????????????????????
5048 (idlwave-shell-send-command
5049 (format "save,'idlwave_routine_info','idlwave_print_info_entry',FILE='%s',/ROUTINES"
5050 (idlwave-shell-temp-file 'rinfo))
5053 ;; Restore and execute the procedure, analyze the output
5054 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5055 (idlwave-shell-send-command
5056 (format "RESTORE, '%s' & idlwave_routine_info"
5057 idlwave-shell-temp-rinfo-save-file)
5059 (idlwave-shell-routine-info-filter)
5060 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5063 ;; ---------------------------------------------------------------------------
5065 ;; Completion and displaying routine calling sequences
5067 (defvar idlwave-completion-help-info nil)
5068 (defvar idlwave-current-obj_new-class nil)
5069 (defvar idlwave-complete-special nil)
5071 (defun idlwave-complete (&optional arg module class)
5072 "Complete a function, procedure or keyword name at point.
5073 This function is smart and figures out what can be legally completed
5075 - At the beginning of a statement it completes procedure names.
5076 - In the middle of a statement it completes function names.
5077 - after a `(' or `,' in the argument list of a function or procedure,
5078 it completes a keyword of the relevant function or procedure.
5079 - In the first arg of `OBJ_NEW', it completes a class name.
5081 When several completions are possible, a list will be displayed in the
5082 *Completions* buffer. If this list is too long to fit into the
5083 window, scrolling can be achieved by repeatedly pressing
5084 \\[idlwave-complete].
5086 The function also knows about object methods. When it needs a class
5087 name, the action depends upon `idlwave-query-class', which see. You
5088 can force IDLWAVE to ask you for a class name with a
5089 \\[universal-argument] prefix argument to this command.
5091 See also the variables `idlwave-keyword-completion-adds-equal' and
5092 `idlwave-function-completion-adds-paren'.
5094 The optional ARG can be used to specify the completion type in order
5095 to override IDLWAVE's idea of what should be completed at point.
5096 Possible values are:
5098 0 <=> query for the completion type
5100 2 <=> 'procedure-keyword
5102 4 <=> 'function-keyword
5103 5 <=> 'procedure-method
5104 6 <=> 'procedure-method-keyword
5105 7 <=> 'function-method
5106 8 <=> 'function-method-keyword
5109 As a special case, the universal argument C-u forces completion of
5110 function names in places where the default would be a keyword.
5112 For Lisp programmers only:
5113 When we force a keyword, optional argument MODULE can contain the module name.
5114 When we force a method or a method keyword, CLASS can specify the class."
5121 (idlwave-make-force-complete-where-list arg module class)
5123 (what (nth 2 where-list))
5124 (idlwave-force-class-query (equal arg '(4))))
5126 (if (and module (string-match "::" module))
5127 (setq class (substring module 0 (match-beginning 0))
5128 module (substring module (match-end 0))))
5133 (eq (car-safe last-command) 'idlwave-display-completion-list)
5134 (get-buffer-window "*Completions*"))
5135 (setq this-command last-command)
5136 (idlwave-scroll-completions))
5138 ;; Check for any special completion functions
5139 ((and idlwave-complete-special
5140 (idlwave-call-special idlwave-complete-special)))
5142 ((and (idlwave-in-quote)
5143 (not (eq what 'class)))
5144 (idlwave-complete-filename))
5147 (error "Nothing to complete here"))
5150 (setq idlwave-completion-help-info '(class))
5151 (idlwave-complete-class))
5153 ((eq what 'procedure)
5154 ;; Complete a procedure name
5155 (let* ((cw-list (nth 3 where-list))
5156 (class-selector (idlwave-determine-class cw-list 'pro))
5157 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5158 (idlwave-all-class-inherits class-selector)))
5159 (isa (concat "procedure" (if class-selector "-method" "")))
5160 (type-selector 'pro))
5161 (setq idlwave-completion-help-info
5162 (list 'routine nil type-selector class-selector nil super-classes))
5163 (idlwave-complete-in-buffer
5164 'procedure (if class-selector 'method 'routine)
5165 (idlwave-routines) 'idlwave-selector
5166 (format "Select a %s name%s"
5169 (format " (class is %s)"
5170 (if (eq class-selector t)
5171 "unknown" class-selector))
5174 'idlwave-attach-method-classes)))
5176 ((eq what 'function)
5177 ;; Complete a function name
5178 (let* ((cw-list (nth 3 where-list))
5179 (class-selector (idlwave-determine-class cw-list 'fun))
5180 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5181 (idlwave-all-class-inherits class-selector)))
5182 (isa (concat "function" (if class-selector "-method" "")))
5183 (type-selector 'fun))
5184 (setq idlwave-completion-help-info
5185 (list 'routine nil type-selector class-selector nil super-classes))
5186 (idlwave-complete-in-buffer
5187 'function (if class-selector 'method 'routine)
5188 (idlwave-routines) 'idlwave-selector
5189 (format "Select a %s name%s"
5192 (format " (class is %s)"
5193 (if (eq class-selector t)
5194 "unknown" class-selector))
5197 'idlwave-attach-method-classes)))
5199 ((and (memq what '(procedure-keyword function-keyword))
5201 (idlwave-complete 3))
5203 ((eq what 'procedure-keyword)
5204 ;; Complete a procedure keyword
5205 (let* ((where (nth 3 where-list))
5207 (method-selector name)
5208 (type-selector 'pro)
5209 (class (idlwave-determine-class where 'pro))
5210 (class-selector class)
5211 (super-classes (idlwave-all-class-inherits class-selector))
5212 (isa (format "procedure%s-keyword" (if class "-method" "")))
5213 (entry (idlwave-best-rinfo-assq
5214 name 'pro class (idlwave-routines)))
5215 (list (nth 5 entry)))
5216 (unless (or entry (eq class t))
5217 (error "Nothing known about procedure %s"
5218 (idlwave-make-full-name class name)))
5219 (setq list (idlwave-fix-keywords name 'pro class list))
5220 (unless list (error (format "No keywords available for procedure %s"
5221 (idlwave-make-full-name class name))))
5222 (setq idlwave-completion-help-info
5223 (list 'keyword name type-selector class-selector nil super-classes))
5224 (idlwave-complete-in-buffer
5225 'keyword 'keyword list nil
5226 (format "Select keyword for procedure %s%s"
5227 (idlwave-make-full-name class name)
5228 (if (or (member '("_EXTRA") list)
5229 (member '("_REF_EXTRA") list))
5230 " (note _EXTRA)" ""))
5232 'idlwave-attach-keyword-classes)))
5234 ((eq what 'function-keyword)
5235 ;; Complete a function keyword
5236 (let* ((where (nth 3 where-list))
5238 (method-selector name)
5239 (type-selector 'fun)
5240 (class (idlwave-determine-class where 'fun))
5241 (class-selector class)
5242 (super-classes (idlwave-all-class-inherits class-selector))
5243 (isa (format "function%s-keyword" (if class "-method" "")))
5244 (entry (idlwave-best-rinfo-assq
5245 name 'fun class (idlwave-routines)))
5246 (list (nth 5 entry))
5248 (unless (or entry (eq class t))
5249 (error "Nothing known about function %s"
5250 (idlwave-make-full-name class name)))
5251 (setq list (idlwave-fix-keywords name 'fun class list))
5252 ;; OBJ_NEW: Messages mention the proper Init method
5253 (setq msg-name (if (and (null class)
5254 (string= (upcase name) "OBJ_NEW"))
5255 (concat idlwave-current-obj_new-class
5256 "::Init (via OBJ_NEW)")
5257 (idlwave-make-full-name class name)))
5258 (unless list (error (format "No keywords available for function %s"
5260 (setq idlwave-completion-help-info
5261 (list 'keyword name type-selector class-selector nil super-classes))
5262 (idlwave-complete-in-buffer
5263 'keyword 'keyword list nil
5264 (format "Select keyword for function %s%s" msg-name
5265 (if (or (member '("_EXTRA") list)
5266 (member '("_REF_EXTRA") list))
5267 " (note _EXTRA)" ""))
5269 'idlwave-attach-keyword-classes)))
5271 (t (error "This should not happen (idlwave-complete)")))))
5273 (defvar idlwave-complete-special nil
5274 "List of special completion functions.
5275 These functions are called for each completion. Each function must check
5276 if its own special completion context is present. If yes, it should
5277 use `idlwave-complete-in-buffer' to do some completion and return t.
5278 If such a function returns t, *no further* attempts to complete
5279 other contexts will be done. If the function returns nil, other completions
5282 (defun idlwave-call-special (functions &rest args)
5283 (let ((funcs functions)
5286 (while (setq fun (pop funcs))
5287 (if (setq ret (apply fun args))
5291 (defun idlwave-make-force-complete-where-list (what &optional module class)
5292 ;; Return an artificial WHERE specification to force the completion
5293 ;; routine to complete a specific item independent of context.
5294 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5295 ;; MODULE and CLASS can be used to specify the routine name and class.
5296 ;; The class name will also be found in MODULE if that is like "class::mod".
5297 (let* ((what-list '(("procedure") ("procedure-keyword")
5298 ("function") ("function-keyword")
5299 ("procedure-method") ("procedure-method-keyword")
5300 ("function-method") ("function-method-keyword")
5302 (module (idlwave-sintern-routine-or-method module class))
5303 (class (idlwave-sintern-class class))
5307 (intern (completing-read
5308 "Complete what? " what-list nil t))))
5310 (setq what (intern (car (nth (1- what) what-list)))))
5313 (assoc (symbol-name what) what-list))
5315 (t (error "Illegal WHAT"))))
5316 (nil-list '(nil nil nil nil))
5317 (class-list (list nil nil (or class t) nil)))
5321 ((eq what 'procedure)
5322 (list nil-list nil-list 'procedure nil-list nil))
5324 ((eq what 'procedure-keyword)
5325 (let* ((class-selector nil)
5327 (type-selector 'pro)
5329 (idlwave-completing-read
5330 "Procedure: " (idlwave-routines) 'idlwave-selector))))
5331 (setq pro (idlwave-sintern-routine pro))
5332 (list nil-list nil-list 'procedure-keyword
5333 (list pro nil nil nil) nil)))
5335 ((eq what 'function)
5336 (list nil-list nil-list 'function nil-list nil))
5338 ((eq what 'function-keyword)
5339 (let* ((class-selector nil)
5341 (type-selector 'fun)
5343 (idlwave-completing-read
5344 "Function: " (idlwave-routines) 'idlwave-selector))))
5345 (setq func (idlwave-sintern-routine func))
5346 (list nil-list nil-list 'function-keyword
5347 (list func nil nil nil) nil)))
5349 ((eq what 'procedure-method)
5350 (list nil-list nil-list 'procedure class-list nil))
5352 ((eq what 'procedure-method-keyword)
5353 (let* ((class (idlwave-determine-class class-list 'pro))
5354 (class-selector class)
5355 (super-classes (idlwave-all-class-inherits class-selector))
5356 (type-selector 'pro)
5358 (idlwave-completing-read
5359 (format "Procedure in %s class: " class-selector)
5360 (idlwave-routines) 'idlwave-selector))))
5361 (setq pro (idlwave-sintern-method pro))
5362 (list nil-list nil-list 'procedure-keyword
5363 (list pro nil class nil) nil)))
5365 ((eq what 'function-method)
5366 (list nil-list nil-list 'function class-list nil))
5368 ((eq what 'function-method-keyword)
5369 (let* ((class (idlwave-determine-class class-list 'fun))
5370 (class-selector class)
5371 (super-classes (idlwave-all-class-inherits class-selector))
5372 (type-selector 'fun)
5374 (idlwave-completing-read
5375 (format "Function in %s class: " class-selector)
5376 (idlwave-routines) 'idlwave-selector))))
5377 (setq func (idlwave-sintern-method func))
5378 (list nil-list nil-list 'function-keyword
5379 (list func nil class nil) nil)))
5382 (list nil-list nil-list 'class nil-list nil))
5384 (t (error "Illegal value for WHAT")))))
5386 (defun idlwave-completing-read (&rest args)
5387 ;; Completing read, case insensitive
5388 (let ((old-value (default-value 'completion-ignore-case)))
5391 (setq-default completion-ignore-case t)
5392 (apply 'completing-read args))
5393 (setq-default completion-ignore-case old-value))))
5395 (defvar idlwave-shell-default-directory)
5396 (defun idlwave-complete-filename ()
5397 "Use the comint stuff to complete a file name."
5399 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5400 (comint-completion-addsuffix nil)
5402 (if (and (boundp 'idlwave-shell-default-directory)
5403 (stringp idlwave-shell-default-directory)
5404 (file-directory-p idlwave-shell-default-directory))
5405 idlwave-shell-default-directory
5406 default-directory)))
5407 (comint-dynamic-complete-filename)))
5409 (defun idlwave-make-full-name (class name)
5410 ;; Make a fully qualified module name including the class name
5411 (concat (if class (format "%s::" class) "") name))
5413 (defun idlwave-rinfo-assoc (name type class list)
5414 "Like `idlwave-rinfo-assq', but sintern strings first."
5416 (idlwave-sintern-routine-or-method name class)
5417 type (idlwave-sintern-class class) list))
5419 (defun idlwave-rinfo-assq (name type class list)
5420 ;; Works like assq, but also checks type and class
5423 (while (setq match (assq name list))
5424 (and (or (eq type t)
5425 (eq (nth 1 match) type))
5426 (eq (nth 2 match) class)
5427 (throw 'exit match))
5428 (setq list (cdr (memq match list)))))))
5430 (defun idlwave-rinfo-assq-any-class (name type class list)
5431 (let* ((classes (cons class (idlwave-all-class-inherits class)))
5434 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
5435 (setq classes nil)))
5438 (defun idlwave-best-rinfo-assq (name type class list)
5439 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first."
5440 (let ((twins (idlwave-routine-twins
5441 (idlwave-rinfo-assq-any-class name type class list)
5444 (when (> (length twins) 1)
5445 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
5446 (if (and (eq 'system (car (nth 3 (car twins))))
5447 (setq syslibp (idlwave-any-syslib (cdr twins)))
5448 (not (equal 1 syslibp)))
5449 ;; Its a syslib, so we need to remove the system entry
5450 (setq twins (cdr twins))))
5453 (defun idlwave-best-rinfo-assoc (name type class list)
5454 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5455 (idlwave-best-rinfo-assq
5456 (idlwave-sintern-routine-or-method name class)
5457 type (idlwave-sintern-class class) list))
5459 (defun idlwave-any-syslib (entries)
5460 "Does the entry list ENTRIES contain a syslib entry?
5461 If yes, return the index (>=1)."
5466 (setq file (cdr (nth 3 (car entries))))
5469 (idlwave-expand-lib-file-name file)))
5471 (setq entries (cdr entries))))
5474 (defun idlwave-all-assq (key list)
5475 "Return a list of all associations of Key in LIST."
5477 (while (setq elt (assq key list))
5479 (setq list (cdr (memq elt list))))
5482 (defun idlwave-all-method-classes (method &optional type)
5483 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5484 When TYPE is not specified, both procedures and functions will be considered."
5486 (mapcar 'car (idlwave-class-alist))
5491 (eq type (nth 1 x)))
5492 (push (nth 2 x) rtn)))
5493 (idlwave-all-assq method (idlwave-routines)))
5494 (idlwave-uniquify rtn))))
5496 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
5497 "Return all classes which have a method METHOD with keyword KEYWORD.
5498 TYPE is 'fun or 'pro.
5499 When TYPE is not specified, both procedures and functions will be considered."
5500 (if (or (null method)
5507 (eq type (nth 1 x)))
5508 (assoc keyword (nth 5 x))
5509 (push (nth 2 x) rtn)))
5510 (idlwave-all-assq method (idlwave-routines)))
5511 (idlwave-uniquify rtn))))
5513 (defun idlwave-members-only (list club)
5514 "Return list of all elements in LIST which are also in CLUB."
5517 (if (member (car list) club)
5518 (setq rtn (cons (car list) rtn)))
5519 (setq list (cdr list)))
5522 (defun idlwave-nonmembers-only (list club)
5523 "Return list of all elements in LIST which are not in CLUB."
5526 (if (member (car list) club)
5528 (setq rtn (cons (car list) rtn)))
5529 (setq list (cdr list)))
5532 (defun idlwave-explicit-class-listed (info)
5533 "Return whether or not the class is listed explicitly, ala a->b::c.
5534 INFO is as returned by idlwave-what-function or -procedure."
5535 (let ((apos (nth 3 info)))
5537 (save-excursion (goto-char apos)
5538 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5540 (defvar idlwave-determine-class-special nil
5541 "List of special functions for determining class.
5542 Must accept two arguments: `apos' and `info'")
5544 (defun idlwave-determine-class (info type)
5545 ;; Determine the class of a routine call.
5546 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5547 ;; The second element in this structure is the class. When nil, we
5548 ;; return nil. When t, try to get the class from text properties at
5549 ;; the arrow. When the object is "self", we use the class of the
5550 ;; current routine. otherwise prompt the user for a class name.
5551 ;; Also stores the selected class as a text property at the arrow.
5552 ;; TYPE is 'fun or 'pro.
5553 (let* ((class (nth 2 info))
5555 (nassoc (assoc (if (stringp (car info))
5558 idlwave-query-class))
5559 (dassoc (assq (if (car info) 'keyword-default 'method-default)
5560 idlwave-query-class))
5561 (query (cond (nassoc (cdr nassoc))
5562 (dassoc (cdr dassoc))
5564 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
5567 (save-excursion (goto-char apos)
5569 (let ((case-fold-search t))
5570 (looking-at "self\\>")))))
5571 (force-query idlwave-force-class-query)
5572 store special-class class-alist)
5576 ;; There is an object which would like to know its class
5577 (if (and arrow (get-text-property apos 'idlwave-class)
5578 idlwave-store-inquired-class
5580 (setq class (get-text-property apos 'idlwave-class)
5581 class (idlwave-sintern-class class)))
5582 (if (and (eq t class) is-self)
5583 (setq class (or (nth 2 (idlwave-current-routine)) class)))
5585 ;; Before prompting, try any special class determination routines
5586 (when (and (eq t class)
5587 idlwave-determine-class-special
5590 (idlwave-call-special idlwave-determine-class-special apos))
5592 (setq class (idlwave-sintern-class special-class)
5593 store idlwave-store-inquired-class)))
5595 ;; Prompt for a class, if we need to
5596 (when (and (eq class t)
5597 (or force-query query))
5599 (mapcar 'list (idlwave-all-method-classes (car info) type)))
5601 (idlwave-sintern-class
5603 ((and (= (length class-alist) 0) (not force-query))
5604 (error "No classes available with method %s" (car info)))
5605 ((and (= (length class-alist) 1) (not force-query))
5606 (car (car class-alist)))
5608 (setq store idlwave-store-inquired-class)
5609 (idlwave-completing-read
5610 (format "Class%s: " (if (stringp (car info))
5611 (format " for %s method %s"
5614 class-alist nil nil nil 'idlwave-class-history))))))
5616 ;; Store it, if requested
5617 (when (and class (not (eq t class)))
5618 ;; We have a real class here
5619 (when (and store arrow)
5621 (add-text-properties
5623 `(idlwave-class ,class face ,idlwave-class-arrow-face
5626 (setf (nth 2 info) class))
5629 ;; Default as fallback
5632 (defvar type-selector)
5633 (defvar class-selector)
5634 (defvar method-selector)
5635 (defvar super-classes)
5636 (defun idlwave-selector (a)
5637 (and (eq (nth 1 a) type-selector)
5638 (or (and (nth 2 a) (eq class-selector t))
5639 (eq (nth 2 a) class-selector)
5640 (memq (nth 2 a) super-classes)
5643 (defun idlwave-where ()
5644 "Find out where we are.
5645 The return value is a list with the following stuff:
5646 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5648 PRO-LIST (PRO POINT CLASS ARROW)
5649 FUNC-LIST (FUNC POINT CLASS ARROW)
5650 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5651 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5653 LAST-CHAR last relevant character before point (non-white non-comment,
5654 not part of current identifier or leading slash).
5656 In the lists, we have these meanings:
5659 POINT: Where is this
5660 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5661 ARROW: Location of the arrow"
5663 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5664 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
5665 (func-entry (idlwave-what-function bos))
5666 (func (car func-entry))
5667 (func-class (nth 1 func-entry))
5668 (func-arrow (nth 2 func-entry))
5669 (func-point (or (nth 3 func-entry) 0))
5670 (func-level (or (nth 4 func-entry) 0))
5671 (pro-entry (idlwave-what-procedure bos))
5672 (pro (car pro-entry))
5673 (pro-class (nth 1 pro-entry))
5674 (pro-arrow (nth 2 pro-entry))
5675 (pro-point (or (nth 3 pro-entry) 0))
5676 (last-char (idlwave-last-valid-char))
5677 (case-fold-search t)
5678 cw cw-mod cw-arrow cw-class cw-point)
5679 (if (< func-point pro-point) (setq func nil))
5681 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
5682 (buffer-substring bos (point)))
5685 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
5686 (buffer-substring (if (> pro-point 0) pro-point bos) (point)))
5687 (setq cw 'procedure cw-class pro-class cw-point pro-point
5688 cw-arrow pro-arrow))
5689 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
5690 (buffer-substring bos (point)))
5692 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
5693 (buffer-substring bos (point)))
5695 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
5696 (buffer-substring bos (point)))
5699 (> func-point pro-point)
5701 (memq last-char '(?\( ?,)))
5702 (setq cw 'function-keyword cw-mod func cw-point func-point
5703 cw-class func-class cw-arrow func-arrow))
5704 ((and pro (eq last-char ?,))
5705 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
5706 cw-class pro-class cw-arrow pro-arrow))
5707 ; ((member last-char '(?\' ?\) ?\] ?!))
5708 ; ;; after these chars, a function makes no sense
5709 ; ;; FIXME: I am sure there can be more in this list
5710 ; ;; FIXME: Do we want to do this at all?
5712 ;; Everywhere else we try a function.
5716 (if (re-search-backward "->[ \t]*\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
5717 (setq cw-arrow (copy-marker (match-beginning 0))
5718 cw-class (if (match-end 2)
5719 (idlwave-sintern-class (match-string 2))
5721 (list (list pro pro-point pro-class pro-arrow)
5722 (list func func-point func-class func-arrow)
5724 (list cw-mod cw-point cw-class cw-arrow)
5727 (defun idlwave-this-word (&optional class)
5728 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
5729 (setq class (or class "a-zA-Z0-9$_"))
5731 (buffer-substring-no-properties
5732 (progn (skip-chars-backward class) (point))
5733 (progn (skip-chars-forward class) (point)))))
5735 (defun idlwave-what-function (&optional bound)
5736 ;; Find out if point is within the argument list of a function.
5737 ;; The return value is ("function-name" class arrow-start (point) level).
5738 ;; Level is 1 on the top level parentheses, higher further down.
5740 ;; If the optional BOUND is an integer, bound backwards directed
5741 ;; searches to this point.
5747 func arrow-start class)
5748 (idlwave-with-special-syntax
5751 (narrow-to-region (max 1 (or bound 0)) (point-max))
5752 ;; move back out of the current parenthesis
5753 (while (condition-case nil
5754 (progn (up-list -1) t)
5758 (when (and (= (following-char) ?\()
5760 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
5762 (setq func (match-string 2)
5763 func-point (goto-char (match-beginning 2))
5765 (if (re-search-backward
5766 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
5767 (setq arrow-start (copy-marker (match-beginning 0))
5768 class (or (match-string 2) t)))
5772 (idlwave-sintern-routine-or-method func class)
5773 (idlwave-sintern-class class)
5774 arrow-start func-point cnt)))
5776 (throw 'exit nil)))))))
5778 (defun idlwave-what-procedure (&optional bound)
5779 ;; Find out if point is within the argument list of a procedure.
5780 ;; The return value is ("procedure-name" class arrow-pos (point)).
5782 ;; If the optional BOUND is an integer, bound backwards directed
5783 ;; searches to this point.
5784 (let ((pos (point)) pro-point
5785 pro class arrow-start string)
5787 ;;(idlwave-beginning-of-statement)
5788 (idlwave-start-of-substatement 'pre)
5789 (setq string (buffer-substring (point) pos))
5791 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
5792 (setq pro (match-string 1 string)
5793 pro-point (+ (point) (match-beginning 1)))
5794 (if (and (idlwave-skip-object)
5795 (setq string (buffer-substring (point) pos))
5797 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\'\\)" string))
5798 (setq pro (if (match-beginning 4)
5799 (match-string 4 string))
5800 pro-point (if (match-beginning 4)
5801 (+ (point) (match-beginning 4))
5803 arrow-start (copy-marker (+ (point) (match-beginning 1)))
5804 class (or (match-string 3 string) t)))))
5805 (list (idlwave-sintern-routine-or-method pro class)
5806 (idlwave-sintern-class class)
5810 (defun idlwave-skip-object ()
5811 ;; If there is an object at point, move over it and return t.
5812 (let ((pos (point)))
5815 (skip-chars-forward " ") ; white space
5816 (skip-chars-forward "*") ; de-reference
5818 ((looking-at idlwave-identifier)
5819 (goto-char (match-end 0)))
5820 ((eq (following-char) ?\()
5822 (t (throw 'exit nil)))
5825 (cond ((eq (following-char) ?.)
5827 (if (not (looking-at idlwave-identifier))
5829 (goto-char (match-end 0)))
5830 ((memq (following-char) '(?\( ?\[))
5833 (error (throw 'exit nil))))
5834 (t (throw 'endwhile t)))))
5835 (if (looking-at "[ \t]*->")
5836 (throw 'exit (setq pos (match-beginning 0)))
5837 (throw 'exit nil))))
5841 (defun idlwave-last-valid-char ()
5842 "Return the last character before point which is not white or a comment
5843 and also not part of the current identifier. Since we do this in
5844 order to identify places where keywords are, we consider the initial
5845 `/' of a keyword as part of the identifier.
5846 This function is not general, can only be used for completion stuff."
5849 ;; skip the current identifier
5850 (skip-chars-backward "a-zA-Z0-9_$")
5851 ;; also skip a leading slash which might be belong to the keyword
5852 (if (eq (preceding-char) ?/)
5854 ;; FIXME: does not check if this is a valid identifier
5856 (skip-chars-backward " \t")
5858 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
5859 ((eq (preceding-char) ?\n)
5860 (beginning-of-line 0)
5861 (if (looking-at "\\([^;\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
5862 ;; continuation line
5863 (goto-char (match-end 1))
5865 (t (throw 'exit (preceding-char))))))))
5867 (defvar idlwave-complete-after-success-form nil
5868 "A form to evaluate after successful completion.")
5869 (defvar idlwave-complete-after-success-form-force nil
5870 "A form to evaluate after completion selection in *Completions* buffer.")
5871 (defconst idlwave-completion-mark (make-marker)
5872 "A mark pointing to the beginning of the completion string.")
5874 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
5875 &optional prepare-display-function)
5876 "Perform TYPE completion of word before point against LIST.
5877 SELECTOR is the PREDICATE argument for the completion function. Show
5878 PROMPT in echo area. TYPE is one of 'function, 'procedure,
5879 'class-tag, or 'keyword."
5880 (let* ((completion-ignore-case t)
5881 beg (end (point)) slash part spart completion all-completions
5885 (error (concat prompt ": No completions available")))
5887 ;; What is already in the buffer?
5889 (skip-chars-backward "a-zA-Z0-9_$")
5890 (setq slash (eq (preceding-char) ?/)
5892 idlwave-complete-after-success-form
5893 (list 'idlwave-after-successful-completion
5894 (list 'quote type) slash beg)
5895 idlwave-complete-after-success-form-force
5896 (list 'idlwave-after-successful-completion
5897 (list 'quote type) slash (list 'quote 'force))))
5900 (setq part (buffer-substring beg end)
5901 dpart (downcase part)
5902 spart (idlwave-sintern stype part)
5903 completion (try-completion part list selector)
5904 dcompletion (if (stringp completion) (downcase completion)))
5907 ;; nothing available.
5908 (error (concat prompt ": no completion for \"%s\"") part))
5909 ((and (not (equal dpart dcompletion))
5910 (not (eq t completion)))
5911 ;; We can add something
5912 (delete-region beg end)
5913 (if (and (string= part dpart)
5914 (or (not (string= part ""))
5915 idlwave-complete-empty-string-as-lower-case)
5916 (not idlwave-completion-force-default-case))
5917 (insert dcompletion)
5918 (insert completion))
5919 (if (eq t (try-completion completion list selector))
5920 ;; Now this is a unique match
5921 (idlwave-after-successful-completion type slash beg))
5923 ((or (eq completion t)
5924 (and (equal dpart dcompletion)
5925 (= 1 (length (setq all-completions
5927 (all-completions part list selector)))))))
5928 ;; This is already complete
5929 (idlwave-after-successful-completion type slash beg)
5930 (message "%s is already the complete %s" part isa)
5933 ;; We cannot add something - offer a list.
5934 (message "Making completion list...")
5935 (let* ((list all-completions)
5936 ;; "complete" means, this is already a valid completion
5937 (complete (memq spart all-completions))
5938 (completion-highlight-first-word-only t) ; XEmacs
5939 (completion-fixup-function ; Emacs
5940 (lambda () (and (eq (preceding-char) ?>)
5941 (re-search-backward " <" beg t)))))
5942 (setq list (sort list (lambda (a b)
5943 (string< (downcase a) (downcase b)))))
5944 (if prepare-display-function
5945 (setq list (funcall prepare-display-function list)))
5946 (if (and (string= part dpart)
5947 (or (not (string= part ""))
5948 idlwave-complete-empty-string-as-lower-case)
5949 (not idlwave-completion-force-default-case))
5950 (setq list (mapcar (lambda (x)
5952 (setcar x (downcase (car x)))
5953 (setq x (downcase x)))
5956 (idlwave-display-completion-list list prompt beg complete))
5959 (defun idlwave-complete-class ()
5960 "Complete a class at point."
5962 ;; Call `idlwave-routines' to make sure the class list will be available
5964 ;; Check for the special case of completing empty string after pro/function
5965 (if (let ((case-fold-search t))
5968 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
5970 (goto-char (point-min))
5972 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
5973 ;; Yank the full class specification
5974 (insert (match-string 2))
5975 ;; Do the completion
5976 (idlwave-complete-in-buffer 'class 'class (idlwave-class-alist) nil
5977 "Select a class" "class")))
5979 (defun idlwave-attach-classes (list type show-classes)
5980 ;; Attach the proper class list to a LIST of completion items.
5981 ;; TYPE, when 'kwd, shows classes for method keywords, when
5982 ;; 'class-tag, for class tags, and otherwise for methods.
5983 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
5984 (if (or (null show-classes) ; don't want to see classes
5985 (null class-selector) ; not a method call
5987 (stringp class-selector) ; the class is already known
5988 (not super-classes))) ; no possibilities for inheritance
5989 ;; In these cases, we do not have to do anything
5991 (let* ((do-prop (and (>= show-classes 0)
5992 (>= emacs-major-version 21)))
5993 (do-buf (not (= show-classes 0)))
5994 ;; (do-dots (featurep 'xemacs))
5996 (inherit (if (and (not (eq type 'class-tag)) super-classes)
5997 (cons class-selector super-classes)))
5998 (max (abs show-classes))
5999 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6000 classes nclasses class-info space)
6004 (if (eq type 'class-tag)
6005 ;; Just one class for tags
6008 (idlwave-class-or-superclass-with-tag class-selector x)))
6009 ;; Multiple classes for method of method-keyword
6012 (idlwave-all-method-keyword-classes
6013 method-selector x type-selector)
6014 (idlwave-all-method-classes x type-selector)))
6018 (mapcar (lambda (x) (if (memq x inherit) x nil))
6020 (setq nclasses (length classes))
6021 ;; Make the separator between item and class-info
6023 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6026 ;; We do want info in the buffer
6027 (if (<= nclasses max)
6028 (setq class-info (concat
6030 "<" (mapconcat 'identity classes ",") ">"))
6031 (setq class-info (format "%s<%d classes>" space nclasses)))
6032 (setq class-info nil))
6034 ;; We do want properties
6035 (setq x (copy-sequence x))
6036 (put-text-property 0 (length x)
6037 'help-echo (mapconcat 'identity classes " ")
6044 (defun idlwave-attach-method-classes (list)
6045 ;; Call idlwave-attach-classes with method parameters
6046 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6047 (defun idlwave-attach-keyword-classes (list)
6048 ;; Call idlwave-attach-classes with keyword parameters
6049 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6050 (defun idlwave-attach-class-tag-classes (list)
6051 ;; Call idlwave-attach-classes with class structure tags
6052 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6055 ;;----------------------------------------------------------------------
6056 ;;----------------------------------------------------------------------
6057 ;;----------------------------------------------------------------------
6058 ;;----------------------------------------------------------------------
6059 ;;----------------------------------------------------------------------
6061 (defun idlwave-pset (item)
6064 (defun idlwave-popup-select (ev list title &optional sort)
6065 "Select an item in LIST with a popup menu.
6066 TITLE is the title to put atop the popup. If SORT is non-nil,
6067 sort the list before displaying"
6068 (let ((maxpopup idlwave-max-popup-menu-items)
6071 ((= 1 (length list))
6072 (setq rtn (car list)))
6074 (if sort (setq list (sort list (lambda (a b)
6075 (string< (upcase a) (upcase b))))))
6077 (append (list title)
6078 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6081 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6082 (setq resp (get-popup-menu-response menu))
6083 (funcall (event-function resp) (event-object resp)))
6085 (if sort (setq list (sort list (lambda (a b)
6086 (string< (upcase a) (upcase b))))))
6087 (setq menu (cons title
6090 (mapcar (lambda(x) (cons x x)) list)))))
6091 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6092 (setq rtn (x-popup-menu ev menu))))
6095 (defun idlwave-split-menu-xemacs (menu N)
6096 "Split the MENU into submenus of maximum length N."
6097 (if (<= (length menu) (1+ N))
6098 ;; No splitting needed
6100 (let* ((title (car menu))
6101 (entries (cdr menu))
6106 (while (and entries (< cnt N))
6108 nextmenu (cons (car entries) nextmenu)
6109 entries (cdr entries)))
6110 (setq nextmenu (nreverse nextmenu))
6111 (setq nextmenu (cons (format "%s...%s"
6112 (aref (car nextmenu) 0)
6113 (aref (nth (1- cnt) nextmenu) 0))
6115 (setq menu (cons nextmenu menu)
6120 (defun idlwave-split-menu-emacs (menu N)
6121 "Split the MENU into submenus of maximum length N."
6122 (if (<= (length (nth 1 menu)) (1+ N))
6123 ;; No splitting needed
6125 (let* ((title (car menu))
6126 (entries (cdr (nth 1 menu)))
6131 (while (and entries (< cnt N))
6133 nextmenu (cons (car entries) nextmenu)
6134 entries (cdr entries)))
6135 (setq nextmenu (nreverse nextmenu))
6137 (setq nextmenu (cons (format "%s...%s"
6138 (car (car nextmenu))
6139 (car (nth (1- cnt) nextmenu)))
6141 (setq menu (cons nextmenu menu)
6144 (setq menu (nreverse menu))
6145 (setq menu (cons title menu))
6148 (defvar idlwave-completion-setup-hook nil)
6150 (defun idlwave-scroll-completions (&optional message)
6151 "Scroll the completion window on this frame."
6152 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6153 (win (selected-window)))
6156 (select-window cwin)
6159 (error (if (and (listp last-command)
6160 (nth 2 last-command))
6163 (eval idlwave-complete-after-success-form))
6164 (set-window-start cwin (point-min)))))
6165 (and message (message message)))
6166 (select-window win))))
6168 (defun idlwave-display-completion-list (list &optional message beg complete)
6169 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6170 (unless (and (get-buffer-window "*Completions*")
6171 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6172 (move-marker idlwave-completion-mark beg)
6173 (setq idlwave-before-completion-wconf (current-window-configuration)))
6175 (if (featurep 'xemacs)
6176 (idlwave-display-completion-list-xemacs
6178 (idlwave-display-completion-list-emacs list))
6180 ;; Store a special value in `this-command'. When `idlwave-complete'
6181 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6182 (setq this-command (list 'idlwave-display-completion-list message complete))
6184 ;; Mark the completions buffer as created by cib
6185 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6187 ;; Fontify the classes
6188 (if (and idlwave-completion-fontify-classes
6190 (idlwave-completion-fontify-classes))
6193 (run-hooks 'idlwave-completion-setup-hook)
6195 ;; Display the message
6196 (message (or message "Making completion list...done")))
6198 (defun idlwave-choose (function &rest args)
6199 "Call FUNCTION as a completion chooser and pass ARGS to it."
6200 (let ((completion-ignore-case t)) ; install correct value
6201 (apply function args))
6202 (if (and (eq major-mode 'idlwave-shell-mode)
6203 (boundp 'font-lock-mode)
6204 (not font-lock-mode))
6205 ;; Remove the fontification of the word before point
6206 (let ((beg (save-excursion
6207 (skip-chars-backward "a-zA-Z0-9_")
6209 (remove-text-properties beg (point) '(face nil))))
6210 (eval idlwave-complete-after-success-form-force))
6212 (defun idlwave-keyboard-quit ()
6215 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
6216 (idlwave-restore-wconf-after-completion))
6219 (defun idlwave-restore-wconf-after-completion ()
6220 "Restore the old (before completion) window configuration."
6221 (and idlwave-completion-restore-window-configuration
6222 idlwave-before-completion-wconf
6223 (set-window-configuration idlwave-before-completion-wconf)))
6225 (defun idlwave-set-local (var value &optional buffer)
6226 "Set the buffer-local value of VAR in BUFFER to VALUE."
6228 (set-buffer (or buffer (current-buffer)))
6229 (set (make-local-variable var) value)))
6231 (defun idlwave-local-value (var &optional buffer)
6232 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6234 (set-buffer (or buffer (current-buffer)))
6235 (and (local-variable-p var (current-buffer))
6236 (symbol-value var))))
6238 ;; In XEmacs, we can use :activate-callback directly to advice the
6239 ;; choose functions. We use the private keymap only for the online
6242 (defvar idlwave-completion-map nil
6243 "Keymap for completion-list-mode with idlwave-complete.")
6245 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
6246 (with-output-to-temp-buffer "*Completions*"
6247 (apply 'display-completion-list list
6248 ':activate-callback 'idlwave-default-choose-completion
6251 (set-buffer "*Completions*")
6253 (or idlwave-completion-map
6254 (setq idlwave-completion-map
6255 (idlwave-make-modified-completion-map-xemacs
6256 (current-local-map)))))))
6258 (defun idlwave-default-choose-completion (&rest args)
6259 "Execute `default-choose-completion' and then restore the win-conf."
6260 (apply 'idlwave-choose 'default-choose-completion args))
6262 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6263 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6264 (let ((new-map (copy-keymap old-map)))
6265 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
6266 (define-key new-map [button3] (lambda ()
6268 (setq this-command last-command)))
6271 ;; In Emacs we also replace keybindings in the completion
6272 ;; map in order to install our wrappers.
6274 (defun idlwave-display-completion-list-emacs (list)
6275 "Display completion list and install the choose wrappers."
6276 (with-output-to-temp-buffer "*Completions*"
6277 (display-completion-list list))
6279 (set-buffer "*Completions*")
6281 (or idlwave-completion-map
6282 (setq idlwave-completion-map
6283 (idlwave-make-modified-completion-map-emacs
6284 (current-local-map)))))))
6286 (defun idlwave-make-modified-completion-map-emacs (old-map)
6287 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6288 (let ((new-map (copy-keymap old-map)))
6289 (substitute-key-definition
6290 'choose-completion 'idlwave-choose-completion new-map)
6291 (substitute-key-definition
6292 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6293 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6296 (defun idlwave-choose-completion (&rest args)
6297 "Choose the completion that point is in or next to."
6299 (apply 'idlwave-choose 'choose-completion args))
6301 (defun idlwave-mouse-choose-completion (&rest args)
6302 "Click on an alternative in the `*Completions*' buffer to choose it."
6304 (apply 'idlwave-choose 'mouse-choose-completion args))
6306 ;;----------------------------------------------------------------------
6307 ;;----------------------------------------------------------------------
6309 ;;; ------------------------------------------------------------------------
6310 ;;; Sturucture parsing code, and code to manage class info
6313 ;; - Go again over the documentation how to write a completion
6314 ;; plugin. It is in self.el, but currently still very bad.
6315 ;; This could be in a separate file in the distribution, or
6316 ;; in an appendix for the manual.
6318 (defun idlwave-struct-tags ()
6319 "Return a list of all tags in the structure defined at point.
6320 Point is expected just before the opening `{' of the struct definition."
6322 (let* ((borders (idlwave-struct-borders))
6327 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)[ \t]*:" end t)
6328 ;; Check if we are still on the top level of the structure.
6329 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6331 (push (match-string 5) tags))
6332 (goto-char (match-end 0)))
6335 (defun idlwave-find-struct-tag (tag)
6336 "Find a given TAG in the structure defined at point."
6337 (let* ((borders (idlwave-struct-borders))
6340 (case-fold-search t))
6341 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6344 (defun idlwave-struct-inherits ()
6345 "Return a list of all `inherits' names in the struct at point.
6346 Point is expected just before the opening `{' of the struct definition."
6348 (let* ((borders (idlwave-struct-borders))
6351 (case-fold-search t)
6354 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n[ \t]*\\)?inherits[ \t]*\\(\\$.*\n[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)" end t)
6355 ;; Check if we are still on the top level of the structure.
6356 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6358 (push (match-string 3) names))
6359 (goto-char (match-end 0)))
6362 (defun idlwave-in-structure ()
6363 "Return t if point is inside an IDL structure."
6364 (let ((beg (point)))
6366 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6367 (if (idlwave-find-structure-definition nil nil 'back)
6368 (let ((borders (idlwave-struct-borders)))
6369 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6370 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6372 (defun idlwave-struct-borders ()
6373 "Return the borders of the {...} after point as a cons cell."
6376 (skip-chars-forward "^{")
6378 (condition-case nil (forward-list 1)
6379 (error (goto-char beg)))
6380 (cons beg (point)))))
6382 (defun idlwave-find-structure-definition (&optional var name bound)
6383 "Search forward for a structure definition.
6384 If VAR is non-nil, search for a structure assigned to variable VAR.
6385 If NAME is non-nil, search for a named structure NAME. If BOUND is an
6386 integer, limit the search. If BOUND is the symbol `all', we search
6387 first back and then forward through the entire file. If BOUND is the
6388 symbol `back' we search only backward."
6389 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6390 (case-fold-search t)
6391 (lim (if (integerp bound) bound nil))
6394 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6397 (if name (concat ws "\\<" (downcase name) "[^a-zA-Z0-9_$]") ""))))
6398 (if (or (and (or (eq bound 'all) (eq bound 'back))
6399 (re-search-backward re nil t))
6400 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6401 (goto-char (match-beginning 3)))))
6403 (defvar idlwave-class-info nil)
6404 (defvar idlwave-system-class-info nil)
6405 (add-hook 'idlwave-update-rinfo-hook
6406 (lambda () (setq idlwave-class-info nil)))
6407 (add-hook 'idlwave-after-load-rinfo-hook
6408 (lambda () (setq idlwave-class-info nil)))
6410 (defun idlwave-class-info (class)
6412 (unless idlwave-class-info
6413 ;; Info is nil, put in the system stuff.
6414 (setq idlwave-class-info idlwave-system-class-info)
6415 (setq list idlwave-class-info)
6416 (while (setq entry (pop list))
6417 (idlwave-sintern-class-info entry)))
6418 (setq class (idlwave-sintern-class class))
6419 (setq entry (assq class idlwave-class-info))
6421 (setq entry (idlwave-find-class-info class))
6423 ;; Sintern and cache the info
6424 (idlwave-sintern-class-info entry)
6425 (push entry idlwave-class-info)))
6428 (defun idlwave-sintern-class-info (entry)
6429 "Sintern the class names in a class-info entry."
6430 (let ((taglist (assq 'tags entry))
6431 (inherits (assq 'inherits entry)))
6432 (setcar entry (idlwave-sintern-class (car entry) 'set))
6434 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6437 (defun idlwave-find-class-definition (class)
6438 (let ((case-fold-search t))
6439 (if (re-search-forward
6440 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6441 ;; FIXME: should we limit to end of pro here?
6442 (idlwave-find-structure-definition nil class))))
6444 (defun idlwave-find-class-info (class)
6445 "Find the __define procedure for a class structure and return info entry."
6446 (let* ((pro (concat (downcase class) "__define"))
6447 (class (idlwave-sintern-class class))
6448 (idlwave-auto-routine-info-updates nil)
6449 (file (cdr (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6450 (idlwave-routines)))))
6453 (not (file-regular-p
6454 (setq file (idlwave-expand-lib-file-name file)))))
6455 nil ; Cannot get info
6457 (if (setq buf (idlwave-get-buffer-visiting file))
6459 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6461 (unless (eq major-mode 'idlwave-mode)
6463 (insert-file-contents file))
6466 (if (idlwave-find-class-definition class)
6468 (cons 'tags (idlwave-struct-tags))
6469 (cons 'inherits (idlwave-struct-inherits)))))))))
6471 (defun idlwave-class-tags (class)
6472 "Return the native tags in CLASS."
6473 (cdr (assq 'tags (idlwave-class-info class))))
6474 (defun idlwave-class-inherits (class)
6475 "Return the direct superclasses of CLASS."
6476 (cdr (assq 'inherits (idlwave-class-info class))))
6478 (defun idlwave-all-class-tags (class)
6479 "Return a list of native and inherited tags in CLASS."
6481 (apply 'append (mapcar 'idlwave-class-tags
6482 (cons class (idlwave-all-class-inherits class))))
6484 (idlwave-class-tag-reset)
6485 (error "%s" (error-message-string err)))))
6488 (defun idlwave-all-class-inherits (class)
6489 "Return a list of all superclasses of CLASS (recursively expanded).
6490 The list is cached in `idlwave-class-info' for faster access."
6492 ((not idlwave-support-inheritance) nil)
6493 ((eq class nil) nil)
6496 (let ((info (idlwave-class-info class))
6498 (if (setq entry (assq 'all-inherits info))
6500 ;; Save the depth of inheritance scan to check for circular references
6501 (let ((inherits (mapcar (lambda (x) (cons x 0))
6502 (idlwave-class-inherits class)))
6503 rtn all-inherits cl)
6505 (setq cl (pop inherits)
6506 rtn (cons (car cl) rtn)
6507 inherits (append (mapcar (lambda (x)
6508 (cons x (1+ (cdr cl))))
6509 (idlwave-class-inherits (car cl)))
6511 (if (> (cdr cl) 999)
6513 "Class scan: inheritance depth exceeded. Circular inheritance?")
6515 (setq all-inherits (nreverse rtn))
6516 (nconc info (list (cons 'all-inherits all-inherits)))
6520 ;;==========================================================================
6522 ;; Completing class structure tags. This is a completion plugin.
6523 ;; The necessary taglist is constructed dynamically
6525 (defvar idlwave-current-tags-class nil)
6526 (defvar idlwave-current-class-tags nil)
6527 (defvar idlwave-current-native-class-tags nil)
6528 (defvar idlwave-sint-class-tags nil)
6529 (idlwave-new-sintern-type 'class-tag)
6530 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
6531 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
6533 (defun idlwave-complete-class-structure-tag ()
6534 "Complete a structure tag on a `self' argument in an object method."
6537 (case-fold-search t))
6539 ;; Check if the context is right
6540 (skip-chars-backward "[a-zA-Z0-9._$]")
6541 (and (< (point) (- pos 4))
6542 (looking-at "self\\.")))
6543 (let* ((class-selector (nth 2 (idlwave-current-routine)))
6544 (super-classes (idlwave-all-class-inherits class-selector)))
6545 ;; Check if we are in a class routine
6546 (unless class-selector
6547 (error "Not in a method procedure or function"))
6548 ;; Check if we need to update the "current" class
6549 (if (not (equal class-selector idlwave-current-tags-class))
6550 (idlwave-prepare-class-tag-completion class-selector))
6551 (setq idlwave-completion-help-info
6552 (list 'idlwave-complete-class-structure-tag-help
6553 (idlwave-sintern-routine
6554 (concat class-selector "__define"))
6556 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
6557 (idlwave-complete-in-buffer
6558 'class-tag 'class-tag
6559 idlwave-current-class-tags nil
6560 (format "Select a tag of class %s" class-selector)
6562 'idlwave-attach-class-tag-classes))
6563 t) ; return t to skip other completions
6566 (defun idlwave-class-tag-reset ()
6567 (setq idlwave-current-tags-class nil))
6569 (defun idlwave-prepare-class-tag-completion (class)
6570 "Find and parse the necessary class definitions for class structure tags."
6571 (setq idlwave-sint-class-tags nil)
6572 (setq idlwave-current-tags-class class)
6573 (setq idlwave-current-class-tags
6575 (list (idlwave-sintern-class-tag x 'set)))
6576 (idlwave-all-class-tags class)))
6577 (setq idlwave-current-native-class-tags
6578 (mapcar 'downcase (idlwave-class-tags class))))
6580 ;===========================================================================
6582 ;; Completing system variables and their structure fields
6583 ;; This is also a plugin. It is a bit bigger since we support loading
6584 ;; current system variables from the shell and highlighting in the
6585 ;; completions buffer.
6587 (defvar idlwave-sint-sysvars nil)
6588 (defvar idlwave-sint-sysvartags nil)
6589 (idlwave-new-sintern-type 'sysvar)
6590 (idlwave-new-sintern-type 'sysvartag)
6591 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
6592 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
6593 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-remember-builtin-sysvars)
6594 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
6596 (defvar idlwave-system-variables-alist nil
6597 "Alist of system variables and the associated structure tags.
6598 Gets set in `idlw-rinfo.el'.")
6599 (defvar idlwave-builtin-system-variables nil)
6601 (defun idlwave-complete-sysvar-or-tag ()
6602 "Complete a system variable."
6605 (case-fold-search t))
6606 (cond ((save-excursion
6607 ;; Check if the context is right for system variable
6608 (skip-chars-backward "[a-zA-Z0-9_$]")
6609 (equal (char-before) ?!))
6610 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
6611 (idlwave-complete-in-buffer 'sysvar 'sysvar
6612 idlwave-system-variables-alist nil
6613 "Select a system variable"
6615 t) ; return t to skip other completions
6617 ;; Check if the context is right for sysvar tag
6618 (skip-chars-backward "[a-zA-Z0-9_$.]")
6619 (and (equal (char-before) ?!)
6620 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
6621 (<= (match-end 0) pos)))
6622 ;; Complete a system variable tag
6623 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
6624 (entry (assq var idlwave-system-variables-alist))
6626 (or entry (error "!%s is not know to be a system variable" var))
6627 (or tags (error "System variable !%s is not a structure" var))
6628 (setq idlwave-completion-help-info
6629 (list 'idlwave-complete-sysvar-help var))
6630 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
6632 "Select a system variable tag"
6633 "system variable tag")
6634 t)) ; return t to skip other completions
6637 ;; Here we fake help using the routine "system variables" with keyword
6638 ;; set to the sysvar. Name and kwd are global variables here.
6641 (defun idlwave-complete-sysvar-help (mode word)
6644 (or (and (eq nil (nth 1 idlwave-completion-help-info))
6645 (member (downcase word) idlwave-builtin-system-variables))
6646 (and (stringp (nth 1 idlwave-completion-help-info))
6647 (member (downcase (nth 1 idlwave-completion-help-info))
6648 idlwave-builtin-system-variables))))
6650 (setq name "system variables"
6652 (if (stringp (nth 1 idlwave-completion-help-info))
6653 (nth 1 idlwave-completion-help-info)
6655 (t (error "This should not happen"))))
6657 ;; Fake help in the source buffer for class structure tags.
6658 ;; kwd and name are global-variables here.
6659 (defvar idlwave-help-do-class-struct-tag nil)
6660 (defun idlwave-complete-class-structure-tag-help (mode word)
6662 ((eq mode 'test) ; nothing gets fontified for class tags
6666 (when (setq class-with
6667 (idlwave-class-or-superclass-with-tag
6668 idlwave-current-tags-class
6670 (if (assq (idlwave-sintern-class class-with)
6671 idlwave-system-class-info)
6672 (error "No help available for system class tags."))
6673 (setq name (concat class-with "__define"))))
6675 idlwave-help-do-class-struct-tag t))
6676 (t (error "This should not happen"))))
6678 (defun idlwave-class-or-superclass-with-tag (class tag)
6679 "Find and return the CLASS or one of its superclass with the
6680 associated TAG, if any."
6681 (let ((sclasses (cons class (cdr (assq 'all-inherits
6682 (idlwave-class-info class)))))
6686 (setq cl (pop sclasses))
6687 (let ((tags (idlwave-class-tags cl)))
6689 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
6691 (setq tags (cdr tags))))))))
6694 (defun idlwave-sysvars-reset ()
6695 (if (and (fboundp 'idlwave-shell-is-running)
6696 (idlwave-shell-is-running))
6697 (idlwave-shell-send-command "idlwave_get_sysvars"
6698 'idlwave-process-sysvars 'hide)))
6700 (defun idlwave-process-sysvars ()
6701 (idlwave-shell-filter-sysvars)
6702 (setq idlwave-sint-sysvars nil
6703 idlwave-sint-sysvartags nil)
6704 (idlwave-sintern-sysvar-alist))
6706 (defun idlwave-remember-builtin-sysvars ()
6707 (setq idlwave-builtin-system-variables
6709 (mapcar 'car idlwave-system-variables-alist))))
6711 (defun idlwave-sintern-sysvar-alist ()
6712 (let ((list idlwave-system-variables-alist) entry)
6713 (while (setq entry (pop list))
6714 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
6715 (setcdr entry (mapcar (lambda (x)
6716 (list (idlwave-sintern-sysvartag (car x) 'set)))
6719 (defvar idlwave-shell-command-output)
6720 (defun idlwave-shell-filter-sysvars ()
6721 "Get the system variables and structure tags."
6722 (let ((text idlwave-shell-command-output)
6724 (old idlwave-system-variables-alist)
6725 var tags type name class)
6726 (setq idlwave-system-variables-alist nil)
6727 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
6729 (setq start (match-end 0)
6730 var (match-string 1 text)
6731 tags (if (match-end 3) (idlwave-split-string (match-string 3 text))))
6732 (setq idlwave-system-variables-alist
6733 (cons (cons var (mapcar 'list tags))
6734 idlwave-system-variables-alist)))
6735 ;; Keep the old value if query was not successful
6736 (setq idlwave-system-variables-alist
6737 (or idlwave-system-variables-alist old))))
6739 (defun idlwave-completion-fontify-classes ()
6740 "Goto the *Completions* buffer and fontify the class info."
6741 (when (featurep 'font-lock)
6743 (set-buffer "*Completions*")
6745 (goto-char (point-min))
6746 (let ((buffer-read-only nil))
6747 (while (re-search-forward "\\.*<[^>]+>" nil t)
6748 (put-text-property (match-beginning 0) (match-end 0)
6749 'face 'font-lock-string-face)))))))
6751 (defun idlwave-uniquify (list)
6753 (loop for x in list do
6754 (add-to-list 'nlist x))
6757 (defun idlwave-after-successful-completion (type slash &optional verify)
6758 "Add `=' or `(' after successful completion of keyword and function.
6759 Restore the pre-completion window configuration if possible."
6761 ((eq type 'procedure)
6763 ((eq type 'function)
6765 ((equal idlwave-function-completion-adds-paren nil) nil)
6766 ((or (equal idlwave-function-completion-adds-paren t)
6767 (equal idlwave-function-completion-adds-paren 1))
6769 ((equal idlwave-function-completion-adds-paren 2)
6774 (if (and idlwave-keyword-completion-adds-equal
6776 (progn (insert "=") t)
6779 ;; Restore the pre-completion window configuration if this is safe.
6781 (if (or (eq verify 'force) ; force
6783 (get-buffer-window "*Completions*") ; visible
6784 (idlwave-local-value 'idlwave-completion-p
6785 "*Completions*") ; cib-buffer
6786 (eq (marker-buffer idlwave-completion-mark)
6787 (current-buffer)) ; buffer OK
6788 (equal (marker-position idlwave-completion-mark)
6790 (idlwave-restore-wconf-after-completion))
6791 (move-marker idlwave-completion-mark nil)
6792 (setq idlwave-before-completion-wconf nil))
6794 (defun idlwave-mouse-context-help (ev &optional arg)
6795 "Call `idlwave-context-help' on the clicked location."
6797 (mouse-set-point ev)
6798 (idlwave-context-help arg))
6800 (defvar idlwave-last-context-help-pos nil)
6801 (defun idlwave-context-help (&optional arg)
6802 "Display IDL Online Help on context.
6803 If point is on a keyword, help for that keyword will be shown. If
6804 point is on a routine name or in the argument list of a routine, help
6805 for that routine will be displayed. Works for system routines and
6806 keywords, it pulls up text help. For other routies and keywords,
6807 visits the source file, finding help in the header (if
6808 `idlwave-help-source-try-header' is non-nil) or the routine definition
6811 (idlwave-require-online-help)
6812 (idlwave-do-context-help arg))
6814 (defun idlwave-mouse-completion-help (ev)
6815 "Display online help about the completion at point."
6817 (idlwave-require-online-help)
6818 ;; Restore last-command for next command, to make scrolling of completions
6820 (setq this-command last-command)
6821 (idlwave-do-mouse-completion-help ev))
6823 (defvar idlwave-help-is-loaded nil
6824 "Is online help avaiable?")
6825 ;; The following variables will be defined by `idlw-help.el'.
6826 (defvar idlwave-help-frame-width nil)
6827 (defvar idlwave-help-file nil)
6828 (defvar idlwave-help-topics nil)
6830 (defun idlwave-help-directory ()
6831 "Return the help directory, or nil if that is not known."
6832 (or (and (stringp idlwave-help-directory)
6833 (> (length idlwave-help-directory) 0)
6834 idlwave-help-directory)
6835 (getenv "IDLWAVE_HELP_DIRECTORY")))
6837 (defun idlwave-require-online-help ()
6838 (if idlwave-help-is-loaded
6839 t ;; everything is OK.
6840 (let* ((dir (or (idlwave-help-directory)
6841 (error "Online Help not installed (help directory unknown) - download at idlwave.org")))
6842 (lfile1 (expand-file-name "idlw-help.elc" dir))
6843 (lfile2 (expand-file-name "idlw-help.el" dir))
6844 (hfile (expand-file-name "idlw-help.txt" dir)))
6845 (if (or (and (file-regular-p lfile1) (load-file lfile1))
6846 (and (file-regular-p lfile2) (load-file lfile2)))
6848 (if (and idlwave-help-frame-parameters
6849 (not (assoc 'width idlwave-help-frame-parameters)))
6850 (push (cons 'width idlwave-help-frame-width)
6851 idlwave-help-frame-parameters))
6852 (or idlwave-help-topics
6853 (error "File `%s' in help dir `%s' does not define `idlwave-help-topics'"
6854 "idlw-help.el" dir)))
6855 (error "No such file `%s' in help dir `%s'" "idlw-help.el" dir))
6856 (if (file-regular-p hfile)
6857 (setq idlwave-help-is-loaded t
6858 idlwave-help-file hfile)
6859 (error "No such file `%s' in dir `%s'" "idlw-help.txt" dir)))))
6861 (defun idlwave-routine-info (&optional arg external)
6862 "Display a routines calling sequence and list of keywords.
6863 When point is on the name a function or procedure, or in the argument
6864 list of a function or procedure, this command displays a help buffer
6865 with the information. When called with prefix arg, enforce class
6868 When point is on an object operator `->', display the class stored in
6869 this arrow, if any (see `idlwave-store-inquired-class'). With a
6870 prefix arg, the class property is cleared out."
6874 (if (string-match "->" (buffer-substring
6875 (max (point-min) (1- (point)))
6876 (min (+ 2 (point)) (point-max))))
6877 ;; Cursor is on an arrow
6878 (if (get-text-property (point) 'idlwave-class)
6879 ;; arrow has class property
6884 (when (looking-at ".?\\(->\\)")
6885 (remove-text-properties (match-beginning 1) (match-end 1)
6886 '(idlwave-class nil face nil))
6887 (message "Class property removed from arrow")))
6888 ;; Echo class property
6889 (message "Arrow has text property identifying object to be class %s"
6890 (get-text-property (point) 'idlwave-class)))
6891 ;; No property found
6892 (message "Arrow has no class text property"))
6894 ;; Not on an arrow...
6895 (let* ((idlwave-query-class nil)
6896 (idlwave-force-class-query (equal arg '(4)))
6897 (module (idlwave-what-module)))
6899 (apply 'idlwave-display-calling-sequence
6900 (idlwave-fix-module-if-obj_new module))
6901 (error "Don't know which calling sequence to show")))))
6903 (defun idlwave-resolve (&optional arg)
6904 "Call RESOLVE on the module name at point.
6905 Like `idlwave-routine-info', this looks for a routine call at point.
6906 After confirmation in the minibuffer, it will use the shell to issue
6907 a RESOLVE call for this routine, to attempt to make it defined and its
6908 routine info available for IDLWAVE. If the routine is a method call,
6909 both `class__method' and `class__define' will be tried.
6910 With ARG, enforce query for the class of object methods."
6912 (let* ((idlwave-query-class nil)
6913 (idlwave-force-class-query (equal arg '(4)))
6914 (module (idlwave-what-module))
6915 (name (idlwave-make-full-name (nth 2 module) (car module)))
6916 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
6917 (resolve (read-string "Resolve: " (format "%s %s" type name)))
6920 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
6922 (setq type (match-string 1 resolve)
6923 class (if (match-beginning 2)
6924 (match-string 3 resolve)
6926 name (match-string 4 resolve)))
6927 (if (string= (downcase type) "function")
6928 (setq kwd ",/is_function"))
6932 (idlwave-shell-send-command
6933 (format "resolve_routine,'%s'%s" (downcase name) kwd)
6934 'idlwave-update-routine-info
6937 (idlwave-shell-send-command
6938 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
6939 (list 'idlwave-shell-send-command
6940 (format "resolve_routine,'%s__%s'%s"
6941 (downcase class) (downcase name) kwd)
6942 '(idlwave-update-routine-info)
6945 (defun idlwave-find-module (&optional arg)
6946 "Find the source code of an IDL module.
6947 Works for modules for which IDLWAVE has routine info available.
6948 The function offers as default the module name `idlwave-routine-info' would
6949 use. With ARG force class query for object methods."
6951 (let* ((idlwave-query-class nil)
6952 (idlwave-force-class-query (equal arg '(4)))
6953 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
6954 (default (concat (idlwave-make-full-name (nth 2 module) (car module))
6955 (if (eq (nth 1 module) 'pro) "<p>" "<f>")))
6959 (if (eq 'system (car-safe (nth 3 x)))
6960 ;; Take out system routines with no source.
6963 (concat (idlwave-make-full-name (nth 2 x) (car x))
6964 (if (eq (nth 1 x) 'pro) "<p>" "<f>"))
6966 (idlwave-routines))))
6967 (name (idlwave-completing-read
6968 (format "Module (Default %s): "
6969 (if default default "none"))
6972 (if (string-match "\\`\\s-*\\'" name)
6973 ;; Nothing, use the default.
6974 (setq name default))
6975 (if (string-match "<[fp]>" name)
6976 (setq type (substring name -2 -1)
6977 name (substring name 0 -3)))
6978 (if (string-match "\\(.*\\)::\\(.*\\)" name)
6979 (setq class (match-string 1 name)
6980 name (match-string 2 name)))
6981 (setq name (idlwave-sintern-routine-or-method name class)
6982 class (idlwave-sintern-class class)
6983 type (cond ((equal type "f") 'fun)
6984 ((equal type "p") 'pro)
6986 (idlwave-do-find-module name type class)))
6988 (defun idlwave-do-find-module (name type class &optional force-source)
6989 (let ((name1 (idlwave-make-full-name class name))
6991 (buf (current-buffer))
6994 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines))
6995 source (or force-source (nth 3 entry))
6996 name2 (if (nth 2 entry)
6997 (idlwave-make-full-name (nth 2 entry) name)
7000 ((or (null name) (equal name ""))
7003 (error "Nothing known about a module %s" name2))
7004 ((eq (car source) 'system)
7005 (error "Source code for system routine %s is not available"
7007 ((equal (cdr source) "")
7008 (error "Source code for routine %s is not available"
7010 ((memq (car source) '(buffer lib compiled))
7012 (if (eq (car source) 'lib)
7013 (idlwave-find-file-noselect
7014 (idlwave-expand-lib-file-name
7016 (format "%s.pro" (downcase name)))) 'find)
7017 (idlwave-find-file-noselect (cdr source) 'find)))
7018 (pop-to-buffer buf1 t)
7019 (goto-char (point-max))
7020 (let ((case-fold-search t))
7021 (if (re-search-backward
7022 (concat "^[ \t]*\\<"
7023 (cond ((equal type "f") "function")
7024 ((equal type "p") "pro")
7025 (t "\\(pro\\|function\\)"))
7027 (regexp-quote (downcase name2))
7030 (goto-char (match-beginning 0))
7033 (error "Could not find routine %s" name2)))))))
7035 (defun idlwave-what-module ()
7036 "Return a default module for stuff near point.
7037 Used by `idlwave-routine-info' and `idlwave-find-module'."
7039 (if (let ((case-fold-search t))
7041 (idlwave-beginning-of-statement)
7042 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7043 ;; This is a function or procedure definition statement
7044 ;; We return the defined routine as module.
7046 (idlwave-sintern-routine-or-method (match-string 4)
7048 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7049 (idlwave-sintern-class (match-string 3)))
7051 ;; Not a definition statement - analyze precise positon.
7052 (let* ((where (idlwave-where))
7054 (pro (car (nth 0 where)))
7055 (func (car (nth 1 where)))
7056 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7057 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7061 ((and (eq cw 'procedure)
7062 (not (equal this-word "")))
7063 (setq this-word (idlwave-sintern-routine-or-method
7064 this-word (nth 2 (nth 3 where))))
7065 (list this-word 'pro
7066 (idlwave-determine-class
7067 (cons this-word (cdr (nth 3 where)))
7069 ((and (eq cw 'function)
7070 (not (equal this-word ""))
7071 (or (eq next-char ?\() ; exclude arrays, vars.
7072 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7073 (setq this-word (idlwave-sintern-routine-or-method
7074 this-word (nth 2 (nth 3 where))))
7075 (list this-word 'fun
7076 (idlwave-determine-class
7077 (cons this-word (cdr (nth 3 where)))
7079 ((and (memq cw '(function-keyword procedure-keyword))
7080 (not (equal this-word ""))
7081 (eq next-char ?\()) ; A function!
7082 (setq this-word (idlwave-sintern-routine this-word))
7083 (list this-word 'fun nil))
7085 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7087 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7090 (defun idlwave-what-module-find-class ()
7091 "Call idlwave-what-module and find the inherited class if necessary."
7092 (let* ((module (idlwave-what-module))
7093 (class (nth 2 module))
7095 (if (and (= (length module) 3)
7099 (apply 'idlwave-find-inherited-class module))
7102 (defun idlwave-find-inherited-class (name type class)
7103 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7104 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7109 (defun idlwave-fix-module-if-obj_new (module)
7110 "Check if MODULE points to obj_new. If yes, and if the cursor is in the
7111 keyword region, change to the appropriate Init method."
7112 (let* ((name (car module))
7114 (case-fold-search t)
7116 (if (and (stringp name)
7117 (equal (downcase name) "obj_new")
7119 (idlwave-beginning-of-statement)
7120 (setq string (buffer-substring (point) pos))
7121 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7124 (class (match-string 1 string)))
7125 (setq module (list (idlwave-sintern-method "Init")
7127 (idlwave-sintern-class class)))))
7131 (defun idlwave-fix-keywords (name type class keywords)
7132 ;; This fixes the list of keywords.
7133 (let ((case-fold-search t))
7135 ;; If this is the OBJ_NEW function, try to figure out the class and use
7136 ;; the keywords from the corresponding INIT method.
7137 (if (and (equal (upcase name) "OBJ_NEW")
7138 (or (eq major-mode 'idlwave-mode)
7139 (eq major-mode 'idlwave-shell-mode)))
7140 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7141 (string (buffer-substring bos (point)))
7142 (case-fold-search t)
7144 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7146 (setq class (idlwave-sintern-class (match-string 1 string)))
7147 (setq idlwave-current-obj_new-class class)
7150 (nth 5 (idlwave-rinfo-assq
7151 (idlwave-sintern-method "INIT")
7154 (idlwave-routines))))))))
7156 ;; If the class is `t', combine all keywords of all methods NAME
7158 (loop for x in (idlwave-routines) do
7159 (and (nth 2 x) ; non-nil class
7160 (eq (nth 1 x) type) ; correct type
7161 (eq (car x) name) ; correct name
7162 (mapcar (lambda (k) (add-to-list 'keywords k))
7164 (setq keywords (idlwave-uniquify keywords)))
7166 ;; If we have inheritance, add all keywords from superclasses, if
7167 ;; the user indicated that method in
7168 ;; `idlwave-keyword-class-inheritance'
7170 idlwave-keyword-class-inheritance
7172 (or (assq (idlwave-sintern-keyword "_extra") keywords)
7173 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7174 (boundp 'super-classes)
7175 ;; Check if one of the keyword-class regexps matches the name
7176 (let ((regexps idlwave-keyword-class-inheritance) re)
7178 (while (setq re (pop regexps))
7179 (if (string-match re name) (throw 'exit t))))))
7180 (loop for x in (idlwave-routines) do
7181 (and (nth 2 x) ; non-nil class
7182 (or (eq (nth 2 x) class) ; the right class
7183 (memq (nth 2 x) super-classes)) ; an inherited class
7184 (eq (nth 1 x) type) ; correct type
7185 (eq (car x) name) ; correct name
7186 (mapcar (lambda (k) (add-to-list 'keywords k))
7188 (setq keywords (idlwave-uniquify keywords)))
7190 ;; Return the final list
7193 (defun idlwave-expand-keyword (keyword module)
7194 "Expand KEYWORD to one of the legal keyword parameters of MODULE.
7195 KEYWORD may be an exact match or an abbreviation of a keyword.
7196 If the match is exact, KEYWORD itself is returned, even if there may be other
7197 keywords of which KEYWORD is an abbreviation. This is necessary because some
7198 system routines have keywords which are prefixes of other keywords.
7199 If KEYWORD is an abbreviation of several keywords, a list of all possible
7200 completions is returned.
7201 If the abbreviation was unique, the correct keyword is returned.
7202 If it cannot be a keyword, the function return nil.
7203 If we do not know about MODULE, just return KEYWORD literally."
7204 (let* ((name (car module))
7205 (type (nth 1 module))
7206 (class (nth 2 module))
7207 (kwd (idlwave-sintern-keyword keyword))
7208 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7209 (kwd-alist (nth 5 entry))
7210 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7211 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7212 (completion-ignore-case t)
7214 (cond ((assq kwd kwd-alist)
7216 ((setq candidates (all-completions kwd kwd-alist))
7217 (if (= (length candidates) 1)
7221 ;; Inheritance may cause this keyword to be correct
7224 ;; We do know the function, which does not have the keyword.
7227 ;; We do not know the function, so this just might be a correct
7228 ;; keyword - return it as it is.
7231 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7232 (defvar idlwave-rinfo-map (make-sparse-keymap))
7233 (define-key idlwave-rinfo-mouse-map
7234 (if (featurep 'xemacs) [button2] [mouse-2])
7235 'idlwave-mouse-active-rinfo)
7236 (define-key idlwave-rinfo-mouse-map
7237 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7238 'idlwave-mouse-active-rinfo-shift)
7239 (define-key idlwave-rinfo-mouse-map
7240 (if (featurep 'xemacs) [button3] [mouse-3])
7241 'idlwave-mouse-active-rinfo-right)
7242 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7243 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7244 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7245 (defvar idlwave-popup-source nil)
7246 (defvar idlwave-rinfo-marker (make-marker))
7248 (defun idlwave-quit-help ()
7250 (let ((ri-window (get-buffer-window "*Help*"))
7251 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7252 (when (and olh-window
7253 (fboundp 'idlwave-help-quit))
7254 (select-window olh-window)
7255 (idlwave-help-quit))
7256 (when (window-live-p ri-window)
7257 (delete-window ri-window))))
7259 (defun idlwave-display-calling-sequence (name type class
7260 &optional initial-class)
7261 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7262 (let* ((initial-class (or initial-class class))
7263 (entry (or (idlwave-best-rinfo-assq name type class
7265 (idlwave-rinfo-assq name type class
7266 idlwave-unresolved-routines)))
7267 (name (or (car entry) name))
7268 (class (or (nth 2 entry) class))
7269 (superclasses (idlwave-all-class-inherits initial-class))
7270 (twins (idlwave-routine-twins entry))
7271 (dtwins (idlwave-study-twins twins))
7273 (system (idlwave-rinfo-assq
7274 name type class idlwave-system-routines))
7275 (have-sysdoc (and system (idlwave-help-directory)))
7276 ;; (source (nth 3 entry))
7277 (have-olh (and (or system idlwave-extra-help-function)
7278 (idlwave-help-directory)))
7279 (calling-seq (nth 4 entry))
7280 (keywords (nth 5 entry))
7284 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') Button3: Online Help "
7285 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD')."))
7288 "Button2/3: Online Help"
7291 (if (idlwave-help-directory)
7292 "Button2: Pop to source and back. Button3: Source in Help window."
7293 "Button2: Pop to source and back."))
7295 "Button2: Display info about same method in superclass")
7297 (data (list name type class (current-buffer) olh initial-class))
7298 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7299 (face 'idlwave-help-link-face)
7300 beg props win cnt total)
7301 (setq keywords (idlwave-fix-keywords name type class keywords))
7304 (error "No %s %s known %s" type name
7305 (if initial-class (concat "in class " initial-class) "")))
7306 ((or (null name) (equal name ""))
7307 (error "No function or procedure call at point"))
7309 (error "Calling sequence of %s %s is not available" type name))
7312 (move-marker idlwave-rinfo-marker (point))
7313 (set-buffer (get-buffer-create "*Help*"))
7314 (use-local-map idlwave-rinfo-map)
7315 (setq buffer-read-only nil)
7317 (set (make-local-variable 'idlwave-popup-source) nil)
7318 (set (make-local-variable 'idlwave-current-obj_new-class)
7319 idlwave-current-obj_new-class)
7321 (setq props (list 'mouse-face 'highlight
7322 km-prop idlwave-rinfo-mouse-map
7323 'help-echo help-echo-class
7324 'data (cons 'class data)))
7325 (let ((classes (cons initial-class superclasses)) c)
7326 (insert "Classes: ")
7327 (while (setq c (pop classes))
7331 (if (equal (downcase c) (downcase class))
7332 (add-text-properties beg (point) (list 'face 'bold))
7333 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7334 (add-text-properties beg (point) props))))
7336 (setq props (if have-olh
7337 (list 'mouse-face 'highlight
7338 km-prop idlwave-rinfo-mouse-map
7339 'help-echo help-echo-use
7340 'data (cons 'usage data))))
7341 (if have-sysdoc (setq props (append (list 'face face) props)))
7345 (format calling-seq class name)
7346 (format calling-seq name))
7348 (add-text-properties beg (point) props)
7350 (insert "Keywords:")
7352 (insert " No keywords accepted.")
7356 (if (>= (+ col 1 (length (car x)))
7363 props (list 'mouse-face 'highlight
7364 km-prop idlwave-rinfo-mouse-map
7365 'data (cons 'keyword data)
7366 'help-echo help-echo-kwd
7368 (if have-sysdoc (setq props (append (list 'face face) props)))
7370 (add-text-properties beg (point) props)
7371 (setq col (+ col 1 (length (car x)))))
7374 (setq cnt 1 total (length all))
7375 (while (setq entry (pop all))
7376 (setq props (list 'mouse-face 'highlight
7377 km-prop idlwave-rinfo-mouse-map
7378 'help-echo help-echo-src
7379 'source (cons (car (nth 2 entry)) (nth 1 entry))
7380 'data (cons 'source data)))
7381 (idlwave-insert-source-location
7384 (if (> total 1) "Sources:" "Source:")
7386 (if (> total 1) "- " ""))
7389 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7390 ;; No more source lines, please
7392 "\n Source information truncated to %d entries."
7393 idlwave-rinfo-max-source-lines))
7396 (setq buffer-read-only t))
7397 (display-buffer "*Help*")
7398 (if (and (setq win (get-buffer-window "*Help*"))
7399 idlwave-resize-routine-help-window)
7401 (let ((ww (selected-window)))
7405 (enlarge-window (- (/ (frame-height) 2)
7407 (shrink-window-if-larger-than-buffer))
7408 (select-window ww)))))))))
7410 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7411 "Insert a source location into the routine info buffer.
7412 Start line with PREFIX.
7413 If a file name is inserted, add FILE-PROPS to it."
7415 (let* ((key (car entry))
7416 (file (nth 1 entry))
7417 (types (nth 2 entry))
7418 (shell-flag (member 'compiled types))
7419 (buffer-flag (member 'buffer types))
7420 (lib-flag (member 'lib types))
7421 (ndupl (or (and buffer-flag (idlwave-count-eq 'buffer types))
7422 (and lib-flag (idlwave-count-eq 'lib types))
7435 (insert "Builtin "))
7436 ((and (not file) shell-flag)
7437 (insert "Unresolved"))
7438 ((null file) (insert "ERROR"))
7439 ((setq special (idlwave-special-lib-test file))
7440 (insert (format "%-10s" special)))
7441 ((idlwave-syslib-p file)
7442 (if (string-match "obsolete" (file-name-directory file))
7443 (insert "Obsolete ")
7444 (insert "SystemLib ")))
7445 ((idlwave-lib-p file) (insert "Library "))
7446 (t (insert "Other ")))
7451 (if lib-flag "C" "-")
7452 (if shell-flag "S" "-")
7453 (if buffer-flag "B" "-")
7457 (insert (format "(%dx) " ndupl))
7458 (add-text-properties beg (point) (list 'face 'bold)))
7459 (when (and file (not (equal file "")))
7461 (insert (apply 'abbreviate-file-name
7462 (if (featurep 'xemacs) (list file t) (list file))))
7464 (add-text-properties beg (point) file-props)))))
7466 (defun idlwave-special-lib-test (file)
7467 "Check the path of FILE against the regexps which define special libs.
7468 Return the name of the special lib if there is a match."
7469 (let ((alist idlwave-special-lib-alist)
7473 (while (setq entry (pop alist))
7474 (if (string-match (car entry) file)
7475 (setq rtn (cdr entry)
7480 (defun idlwave-mouse-active-rinfo-right (ev)
7482 (idlwave-mouse-active-rinfo ev 'right))
7484 (defun idlwave-mouse-active-rinfo-shift (ev)
7486 (idlwave-mouse-active-rinfo ev nil 'shift))
7488 (defun idlwave-active-rinfo-space ()
7490 (idlwave-mouse-active-rinfo nil 'right))
7492 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
7493 "Does the mouse actions in the routine info buffer.
7494 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
7497 (if ev (mouse-set-point ev))
7498 (let (data id name type class buf keyword bufwin source word initial-class)
7499 (setq data (get-text-property (point) 'data)
7500 source (get-text-property (point) 'source)
7501 keyword (get-text-property (point) 'keyword)
7503 name (nth 1 data) type (nth 2 data) class (nth 3 data)
7505 initial-class (nth 6 data)
7506 word (idlwave-this-word)
7507 bufwin (get-buffer-window buf t))
7508 (cond ((eq id 'class)
7509 (if (window-live-p bufwin) (select-window bufwin))
7510 (idlwave-display-calling-sequence
7511 (idlwave-sintern-method name)
7512 type (idlwave-sintern-class word)
7515 (idlwave-require-online-help)
7516 (idlwave-online-help nil name type class))
7518 (if (and right (idlwave-help-directory))
7519 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
7520 (idlwave-help-source-try-header nil)
7521 ;; Fake idlwave-routines, to make help find the right entry
7523 (list (list (nth 1 data) (nth 2 data) (nth 3 data) source ""))))
7524 (idlwave-require-online-help)
7525 (idlwave-help-get-special-help name type class nil))
7526 (setq idlwave-popup-source (not idlwave-popup-source))
7527 (if idlwave-popup-source
7529 (idlwave-do-find-module name type class source)
7531 (setq idlwave-popup-source nil)
7532 (if (window-live-p bufwin) (select-window bufwin))
7533 (error (nth 1 err))))
7535 (select-window bufwin)
7536 (pop-to-buffer buf))
7537 (goto-char (marker-position idlwave-rinfo-marker)))))
7541 (idlwave-require-online-help)
7542 (idlwave-online-help nil name type class keyword))
7543 (idlwave-rinfo-insert-keyword keyword buf shift))))))
7545 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
7546 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
7547 (let ((bwin (get-buffer-window buffer)))
7548 (if idlwave-complete-empty-string-as-lower-case
7549 (setq keyword (downcase keyword)))
7551 (select-window bwin)
7552 (pop-to-buffer buffer)
7553 (setq bwin (get-buffer-window buffer)))
7554 (if (eq (preceding-char) ?/)
7556 (unless (save-excursion
7558 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
7559 (min (- (point) 100) (point-min)) t))
7561 (if shift (insert "/"))
7563 (if (and (not shift)
7564 idlwave-keyword-completion-adds-equal)
7567 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
7568 "List the load path shadows of all routines defined in current buffer."
7571 (if (eq major-mode 'idlwave-mode)
7572 (idlwave-list-load-path-shadows
7573 nil (idlwave-update-current-buffer-info 'save-buffer)
7574 "in current buffer")
7575 (error "Current buffer is not in idlwave-mode")))
7577 (defun idlwave-list-shell-load-path-shadows (&optional arg)
7578 "List the load path shadows of all routines compiled under the shell.
7579 This is very useful for checking an IDL application. Just compile the
7580 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
7581 routines and update IDLWAVE internal info. Then check for shadowing
7585 ((or (not (fboundp 'idlwave-shell-is-running))
7586 (not (idlwave-shell-is-running)))
7587 (error "Shell is not running"))
7588 ((null idlwave-compiled-routines)
7589 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
7591 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
7594 (defun idlwave-list-all-load-path-shadows (&optional arg)
7595 "List the load path shadows of all routines known to IDLWAVE."
7597 (idlwave-list-load-path-shadows nil nil "globally"))
7599 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
7600 "List the routines which are defined multiple times.
7601 Search the information IDLWAVE has about IDL routines for multiple
7603 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
7605 When IDL hits a routine call which is not defined, it will search on
7606 the load path in order to find a definition. The output of this
7607 command can be used to detect possible name clashes during this process."
7608 (idlwave-routines) ; Make sure everything is loaded.
7609 (unless idlwave-library-routines
7611 "You don't have a library catalog. Continue anyway? ")
7613 (let* ((routines (append idlwave-system-routines
7614 idlwave-compiled-routines
7615 idlwave-library-routines
7616 idlwave-buffer-routines
7618 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7619 (keymap (make-sparse-keymap))
7620 (props (list 'mouse-face 'highlight
7622 'help-echo "Mouse2: Find source"))
7623 (nroutines (length (or special-routines routines)))
7624 (step (/ nroutines 99))
7628 (idlwave-sort-prefer-buffer-info nil)
7629 routine twins dtwins twin done props1 lroutines)
7631 (if special-routines
7632 ;; Just looking for shadows of a few special routines
7633 (setq lroutines routines
7634 routines special-routines))
7636 (message "Sorting routines...")
7637 (setq routines (sort routines
7639 (string< (downcase (idlwave-make-full-name
7641 (downcase (idlwave-make-full-name
7642 (nth 2 b) (car b)))))))
7643 (message "Sorting routines...done")
7645 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
7648 (mouse-set-point ev)
7649 (apply 'idlwave-do-find-module
7650 (get-text-property (point) 'find-args))))
7651 (define-key keymap [(return)]
7654 (apply 'idlwave-do-find-module
7655 (get-text-property (point) 'find-args))))
7656 (message "Compiling list...( 0%%)")
7658 (set-buffer (get-buffer-create "*Shadows*"))
7659 (setq buffer-read-only nil)
7661 (while (setq routine (pop routines))
7663 (if (= (* next-perc step) n)
7665 (message "Compiling list...(%2d%%)" next-perc)
7666 (setq next-perc (1+ next-perc))))
7667 ;; Get a list of all twins
7668 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
7669 (if (memq routine done)
7671 (setq dtwins (idlwave-study-twins twins)))
7672 ;; Mark all twins as dealt with
7673 (setq done (append twins done))
7674 (when (or (> (length dtwins) 1)
7675 (> (idlwave-count-eq 'lib (nth 2 (car dtwins))) 1)
7676 (> (idlwave-count-eq 'buffer (nth 2 (car dtwins))) 1))
7678 (insert (format "\n%s%s"
7679 (idlwave-make-full-name (nth 2 routine) (car routine))
7680 (if (eq (nth 1 routine) 'fun) "()" "")))
7681 (while (setq twin (pop dtwins))
7682 (setq props1 (append (list 'find-args
7683 (list (nth 0 routine)
7686 (cons 'lib (nth 1 twin))))
7688 (idlwave-insert-source-location "\n - " twin props1))))
7689 (goto-char (point-min))
7690 (setq buffer-read-only t))
7691 (setq loc (or loc ""))
7694 (display-buffer (get-buffer "*Shadows*"))
7695 (message "%d case%s of shadowing found %s"
7696 cnt (if (= cnt 1) "" "s") loc))
7697 (message "No shadowing conflicts found %s" loc))))
7699 (defun idlwave-print-source (routine)
7700 (let* ((source (nth 3 routine))
7701 (stype (car source))
7702 (sfile (cdr source)))
7703 (if (and (eq stype 'lib) sfile)
7705 (setq sfile (idlwave-expand-lib-file-name sfile))
7706 (if (idlwave-syslib-p sfile) (setq stype 'syslib))))
7707 (if (and (eq stype 'compiled)
7708 (or (not (stringp sfile))
7709 (not (string-match "\\S-" sfile))))
7710 (setq stype 'unresolved))
7711 (princ (format " %-10s %s\n"
7713 (if sfile sfile "No source code available")))))
7715 (defun idlwave-routine-twins (entry &optional list)
7716 "Return all twin entries of ENTRY in LIST.
7717 LIST defaults to `idlwave-routines'.
7718 Twin entries are those which have the same name, type, and class.
7719 ENTRY will also be returned, as the first item of this list."
7720 (let* ((name (car entry))
7721 (type (nth 1 entry))
7722 (class (nth 2 entry))
7723 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
7725 (while (setq candidate (pop candidates))
7726 (if (and (not (eq candidate entry))
7727 (eq type (nth 1 candidate))
7728 (eq class (nth 2 candidate)))
7729 (push candidate twins)))
7730 (if (setq candidate (idlwave-rinfo-assq name type class
7731 idlwave-unresolved-routines))
7732 (push candidate twins))
7733 (cons entry (nreverse twins))))
7735 (defun idlwave-study-twins (entries)
7736 "Return dangerous twins of first entry in TWINS.
7737 Dangerous twins are routines with same name, but in different files
7739 If a file is in the system library and has an entry in the
7740 `idlwave-system-routines' list, we omit the latter because many IDL
7741 routines are implemented as library routines."
7742 (let* ((entry (car entries))
7743 (name (car entry)) ;
7744 (type (nth 1 entry)) ; Must be bound for
7745 (class (nth 2 entry)) ; idlwave-routine-twin-compare
7747 source type file thefile alist syslibp key)
7748 (while (setq entry (pop entries))
7750 (setq source (nth 3 entry)
7754 (setq file (idlwave-expand-lib-file-name file)))
7755 ;; Make KEY to index entry properly
7756 (setq key (cond ((eq type 'system) type)
7757 (file (file-truename file))
7761 (idlwave-syslib-p file))
7762 ;; We do have an entry in the system library
7765 (setq thefile (or thefile file))
7766 (if (setq entry (assoc key alist))
7767 (push type (nth 2 entry))
7768 (push (list key file (list type)) alist)))
7770 (setq alist (nreverse alist))
7773 ;; File is system *library* - remove any system entry
7774 (setq alist (delq (assoc 'system alist) alist)))
7776 (when (and (idlwave-syslib-scanned-p)
7777 (setq entry (assoc 'system alist)))
7778 (setcar entry 'builtin))
7779 (sort alist 'idlwave-routine-twin-compare)))
7784 (defvar idlwave-sort-prefer-buffer-info t
7785 "Internal variable used to influence `idlwave-routine-twin-compare'.")
7787 (defmacro idlwave-xor (a b)
7791 (defun idlwave-routine-entry-compare (a b)
7792 "Compare two routine info entries for sortiung. This is the general case.
7793 It first compates class, names, and type. If it turns out that A and B
7794 are twins (same name, class, and type), calls another routine which
7795 compares twins on the basis of their file names and path locations."
7796 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
7798 ((not (equal (idlwave-downcase-safe class)
7799 (idlwave-downcase-safe (nth 2 b))))
7801 (cond ((null (nth 2 b)) nil)
7803 (t (string< (downcase class) (downcase (nth 2 b))))))
7804 ((not (equal (downcase name) (downcase (car b))))
7806 (string< (downcase name) (downcase (car b))))
7807 ((not (eq type (nth 1 b)))
7809 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
7811 ;; A and B are twins - so the decision is more complicated.
7812 ;; Call twin-compare with the proper arguments.
7813 (idlwave-routine-entry-compare-twins a b)))))
7815 (defun idlwave-routine-entry-compare-twins (a b)
7816 "Compare two routine entries, under the assumption that they are twins.
7817 This basically calles `idlwave-routine-twin-compare' with the correct args."
7818 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
7819 (atype (car (nth 3 a)))
7820 (btype (car (nth 3 b)))
7821 (afile (cdr (nth 3 a)))
7822 (bfile (cdr (nth 3 b))))
7824 (setq afile (idlwave-expand-lib-file-name afile)))
7826 (setq bfile (idlwave-expand-lib-file-name bfile)))
7827 (idlwave-routine-twin-compare
7829 (list (file-truename afile) afile (list atype))
7830 (list atype afile (list atype)))
7832 (list (file-truename bfile) bfile (list btype))
7833 (list btype bfile (list btype))))
7836 (defun idlwave-routine-twin-compare (a b)
7837 "Compare two routine twin entries for sorting.
7838 In here, A and B are not normal routine info entries, but special
7839 lists (KEY FILENAME (TYPES...)).
7840 This expects NAME TYPE CLASS to be bound to the right values."
7841 (let* (;; Dis-assemble entries
7842 (akey (car a)) (bkey (car b))
7843 (afile (nth 1 a)) (bfile (nth 1 b))
7844 (atypes (nth 2 a)) (btypes (nth 2 b))
7846 (asysp (memq akey '(builtin system)))
7847 (bsysp (memq bkey '(builtin system)))
7848 ;; Compiled routines?
7849 (acompp (memq 'compiled atypes))
7850 (bcompp (memq 'compiled btypes))
7852 (aunresp (or (eq akey 'unresolved)
7853 (and acompp (not afile))))
7854 (bunresp (or (eq bkey 'unresolved)
7855 (and bcompp (not bfile))))
7856 ;; Buffer info available?
7857 (abufp (memq 'buffer atypes))
7858 (bbufp (memq 'buffer btypes))
7860 (tpath-alist (idlwave-true-path-alist))
7861 (apathp (assoc akey tpath-alist))
7862 (bpathp (assoc bkey tpath-alist))
7863 ;; How early on search path? High number means early since we
7864 ;; measure the tail of the path list
7865 (anpath (length (memq apathp tpath-alist)))
7866 (bnpath (length (memq bpathp tpath-alist)))
7867 ;; Look at file names
7868 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
7869 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
7870 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
7871 (regexp-quote (downcase class))
7872 (regexp-quote (downcase name)))
7873 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
7874 ;; Is file name derived from the routine name?
7875 ;; Method file or class definition file?
7876 (anamep (string-match fname-re aname))
7877 (adefp (and class anamep (string= "define" (match-string 1 aname))))
7878 (bnamep (string-match fname-re bname))
7879 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
7881 ;; Now: follow JD's ideas about sorting. Looks really simple now,
7882 ;; doesn't it? The difficult stuff is hidden above...
7884 ((idlwave-xor asysp bsysp) asysp) ; System entries first
7885 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
7886 ((and idlwave-sort-prefer-buffer-info
7887 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
7888 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
7889 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
7890 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
7891 ((and class anamep bnamep ; both file names match ->
7892 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
7893 ((> anpath bnpath) t) ; Who is first on path?
7894 (t nil)))) ; Default
7896 (defun idlwave-downcase-safe (string)
7897 "Donwcase if string, else return unchanged."
7898 (if (stringp string)
7902 (defun idlwave-count-eq (elt list)
7903 "How often is ELT in LIST?"
7904 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
7906 (defun idlwave-syslib-p (file)
7907 "Non-nil of FILE is in the system library."
7908 (let* ((true-syslib (file-name-as-directory
7910 (expand-file-name "lib" (idlwave-sys-dir)))))
7911 (true-file (file-truename file)))
7912 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
7914 (defun idlwave-lib-p (file)
7915 "Non-nil if file is in the library"
7916 (let ((true-dir (file-name-directory (file-truename file))))
7917 (assoc true-dir (idlwave-true-path-alist))))
7919 (defun idlwave-true-path-alist ()
7920 "Return `idlwave-path-alist' alist with true-names.
7921 Info is cached, but relies on the functons setting `idlwave-path-alist'
7922 to reset the variable `idlwave-true-path-alist' to nil."
7923 (or idlwave-true-path-alist
7924 (setq idlwave-true-path-alist
7925 (mapcar (lambda(x) (cons
7926 (file-name-as-directory
7928 (directory-file-name
7931 idlwave-path-alist))))
7933 (defun idlwave-syslib-scanned-p ()
7934 "Non-nil if the system lib file !DIR/lib has been scanned."
7935 (let* ((true-syslib (file-name-as-directory
7937 (expand-file-name "lib" (idlwave-sys-dir))))))
7938 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
7940 ;; ----------------------------------------------------------------------------
7942 ;; Online Help display
7945 ;; ----------------------------------------------------------------------------
7947 ;; Additions for use with imenu.el and func-menu.el
7948 ;; (pop-up a list of IDL units in the current file).
7951 (defun idlwave-prev-index-position ()
7952 "Search for the previous procedure or function.
7953 Return nil if not found. For use with imenu.el."
7956 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
7957 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
7960 (defun idlwave-unit-name ()
7961 "Return the unit name.
7962 Assumes that point is at the beginning of the unit as found by
7963 `idlwave-prev-index-position'."
7966 (let ((begin (point)))
7967 (re-search-forward "[a-zA-Z][a-zA-Z0-9$_]+\\(::[a-zA-Z][a-zA-Z0-9$_]+\\)?")
7968 (if (fboundp 'buffer-substring-no-properties)
7969 (buffer-substring-no-properties begin (point))
7970 (buffer-substring begin (point)))))
7972 (defalias 'idlwave-function-menu
7975 (require 'func-menu)
7977 (error (condition-case nil
7983 ;; Here we kack func-menu.el in order to support this new mode.
7984 ;; The latest versions of func-menu.el already have this stuff in, so
7985 ;; we hack only if it is not already there.
7986 (when (fboundp 'eval-after-load)
7987 (eval-after-load "func-menu"
7989 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
7990 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
7991 (setq fume-function-name-regexp-alist
7992 (cons '(idlwave-mode . fume-function-name-regexp-idl)
7993 fume-function-name-regexp-alist)))
7994 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
7995 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
7996 (setq fume-find-function-name-method-alist
7997 (cons '(idlwave-mode . fume-find-next-idl-function-name)
7998 fume-find-function-name-method-alist))))))
8000 (defun idlwave-edit-in-idlde ()
8001 "Edit the current file in IDL Development environment."
8003 (start-process "idldeclient" nil
8004 idlwave-shell-explicit-file-name "-c" "-e"
8005 (buffer-file-name) "&"))
8007 (defun idlwave-launch-idlhelp ()
8008 "Start the IDLhelp application."
8010 (start-process "idlhelp" nil idlwave-help-application))
8012 ;; Menus - using easymenu.el
8013 (defvar idlwave-mode-menu-def
8015 ["PRO/FUNC menu" idlwave-function-menu t]
8017 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8018 ["Subprogram End" idlwave-end-of-subprogram t]
8019 ["Block Start" idlwave-beginning-of-block t]
8020 ["Block End" idlwave-end-of-block t]
8021 ["Up Block" idlwave-backward-up-block t]
8022 ["Down Block" idlwave-down-block t]
8023 ["Skip Block Backward" idlwave-backward-block t]
8024 ["Skip Block Forward" idlwave-forward-block t])
8026 ["Subprogram" idlwave-mark-subprogram t]
8027 ["Block" idlwave-mark-block t]
8028 ["Header" idlwave-mark-doclib t])
8030 ["Indent Subprogram" idlwave-indent-subprogram t]
8031 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8032 ["Continue/Split line" idlwave-split-line t]
8034 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8035 :selected (symbol-value idlwave-fill-function)])
8037 ["Procedure" idlwave-procedure t]
8038 ["Function" idlwave-function t]
8039 ["Doc Header" idlwave-doc-header t]
8040 ["Log" idlwave-doc-modification t]
8042 ["Case" idlwave-case t]
8043 ["For" idlwave-for t]
8044 ["Repeat" idlwave-repeat t]
8045 ["While" idlwave-while t]
8047 ["Close Block" idlwave-close-block t])
8049 ["Complete" idlwave-complete t]
8051 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8052 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8054 ["3 Function Name" (idlwave-complete 'function) t]
8055 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8057 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8058 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8060 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8061 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8063 ["9 Class Name" idlwave-complete-class t]))
8065 ["Show Routine Info" idlwave-routine-info t]
8066 ["Online Context Help" idlwave-context-help (idlwave-help-directory)]
8068 ["Find Routine Source" idlwave-find-module t]
8069 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8071 ["Update Routine Info" idlwave-update-routine-info t]
8073 "IDL Library Catalog"
8074 ["Select Catalog Directories" (idlwave-create-libinfo-file nil) t]
8075 ["Scan Directories" (idlwave-update-routine-info '(16))
8076 (and idlwave-path-alist (not idlwave-catalog-process))]
8077 ["Scan Directories &" (idlwave-update-routine-info '(64))
8078 (and idlwave-path-alist (not idlwave-catalog-process))]
8081 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8082 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8083 ["Check Everything" idlwave-list-all-load-path-shadows t])
8085 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8087 ["Insert TAB character" idlwave-hard-tab t])
8090 ["Generate IDL tags" idlwave-make-tags t]
8091 ["Start IDL shell" idlwave-shell t]
8092 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8093 ["Launch IDL Help" idlwave-launch-idlhelp t])
8096 ["Browse IDLWAVE Group" idlwave-customize t]
8098 ["Build Full Customize Menu" idlwave-create-customize-menu
8099 (fboundp 'customize-menu-create)])
8101 ["Describe Mode" describe-mode t]
8102 ["Abbreviation List" idlwave-list-abbrevs t]
8104 ["Commentary in idlwave.el" idlwave-show-commentary t]
8105 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8107 ["Info" idlwave-info t]
8109 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8111 (defvar idlwave-mode-debug-menu-def
8113 ["Start IDL shell" idlwave-shell t]
8114 ["Save and .RUN buffer" idlwave-shell-save-and-run
8115 (and (boundp 'idlwave-shell-automatic-start)
8116 idlwave-shell-automatic-start)]))
8118 (if (or (featurep 'easymenu) (load "easymenu" t))
8120 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8121 "IDL and WAVE CL editing menu"
8122 idlwave-mode-menu-def)
8123 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8124 "IDL and WAVE CL editing menu"
8125 idlwave-mode-debug-menu-def)))
8127 (defun idlwave-customize ()
8128 "Call the customize function with idlwave as argument."
8130 ;; Try to load the code for the shell, so that we can customize it
8132 (or (featurep 'idlw-shell)
8133 (load "idlw-shell" t))
8134 (customize-browse 'idlwave))
8136 (defun idlwave-create-customize-menu ()
8137 "Create a full customization menu for IDLWAVE, insert it into the menu."
8139 (if (fboundp 'customize-menu-create)
8141 ;; Try to load the code for the shell, so that we can customize it
8143 (or (featurep 'idlw-shell)
8144 (load "idlw-shell" t))
8146 '("IDLWAVE") "Customize"
8147 `(["Browse IDLWAVE group" idlwave-customize t]
8149 ,(customize-menu-create 'idlwave)
8150 ["Set" Custom-set t]
8151 ["Save" Custom-save t]
8152 ["Reset to Current" Custom-reset-current t]
8153 ["Reset to Saved" Custom-reset-saved t]
8154 ["Reset to Standard Settings" Custom-reset-standard t]))
8155 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8156 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8158 (defun idlwave-show-commentary ()
8159 "Use the finder to view the file documentation from `idlwave.el'."
8162 (finder-commentary "idlwave.el"))
8164 (defun idlwave-shell-show-commentary ()
8165 "Use the finder to view the file documentation from `idlw-shell.el'."
8168 (finder-commentary "idlw-shell.el"))
8170 (defun idlwave-info ()
8171 "Read documentation for IDLWAVE in the info system."
8174 (Info-goto-node "(idlwave)"))
8176 (defun idlwave-list-abbrevs (arg)
8177 "Show the code abbreviations define in IDLWAVE mode.
8178 This lists all abbrevs where the replacement text differs from the input text.
8179 These are the ones the users want to learn to speed up their writing.
8181 The function does *not* list abbrevs which replace a word with itself
8182 to call a hook. These hooks are used to change the case of words or
8183 to blink the matching `begin', and the user does not need to know them.
8185 With arg, list all abbrevs with the corresponding hook.
8187 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8190 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8192 str rpl func fmt (len-str 0) (len-rpl 0))
8195 (if (symbol-value sym)
8197 (setq str (symbol-name sym)
8198 rpl (symbol-value sym)
8199 func (symbol-function sym))
8201 (setq func (prin1-to-string func))
8202 (if (and (listp func) (stringp (nth 2 func)))
8203 (setq rpl (concat "EVAL: " (nth 2 func))
8206 (if (or arg (not (string= rpl str)))
8208 (setq len-str (max len-str (length str)))
8209 (setq len-rpl (max len-rpl (length rpl)))
8210 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8213 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8215 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8216 (with-output-to-temp-buffer "*Help*"
8219 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8220 (princ "=========================================\n\n")
8221 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8222 (princ (format fmt "---" "-------" "----")))
8223 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8224 (princ "================================================\n\n")
8225 (princ (format fmt "KEY" "ACTION" ""))
8226 (princ (format fmt "---" "------" "")))
8229 (setq str (car list)
8232 (princ (format fmt str rpl func)))
8234 ;; Make sure each abbreviation uses only one display line
8236 (set-buffer "*Help*")
8237 (setq truncate-lines t)))
8239 ;; Add .pro files to speedbar for support, if it's loaded
8240 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8242 ;; Try to load online help, but catch any errors.
8244 (idlwave-require-online-help)
8247 ;; Set an idle timer to load the routine info.
8248 ;; Will only work on systems which support this.
8249 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8252 (run-hooks 'idlwave-load-hook)
8256 ;;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
8257 ;;; idlwave.el ends here