1 ;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; Keywords: languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; IDLWAVE enables feature-rich development and interaction with IDL.
33 ;; In the remotely distant past, based on pascal.el, though bears
34 ;; little resemblance to it now.
36 ;; Incorporates many ideas, such as abbrevs, action routines, and
37 ;; continuation line indenting, from wave.el.
38 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
40 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
41 ;; for features, key bindings, and info.
42 ;; Also, Info format documentation is available with `M-x idlwave-info'
44 ;; New versions of IDLWAVE, documentation, and more information
51 ;; Follow the instructions in the INSTALL file of the distribution.
52 ;; In short, put this file on your load path and add the following
53 ;; lines to your .emacs file:
55 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
56 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
57 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
63 ;; The newest version of this file is available from the maintainer's
71 ;; IDLWAVE is documented online in info format. A printable version
72 ;; of the documentation is available from the maintainers webpage (see
79 ;; Thanks to the following people for their contributions and comments:
81 ;; Ulrik Dickow <dickow_at_nbi.dk>
82 ;; Eric E. Dors <edors_at_lanl.gov>
83 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
84 ;; David Huenemoerder <dph_at_space.mit.edu>
85 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
86 ;; Dick Jackson <dick_at_d-jackson.com>
87 ;; Xuyong Liu <liu_at_stsci.edu>
88 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
89 ;; Laurent Mugnier <mugnier_at_onera.fr>
90 ;; Lubos Pochman <lubos_at_rsinc.com>
91 ;; Bob Portmann <portmann_at_al.noaa.gov>
92 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
93 ;; Marty Ryba <ryba_at_ll.mit.edu>
94 ;; Paul Sorenson <aardvark62_at_msn.com>
95 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
96 ;; Phil Williams <williams_at_irc.chmcc.org>
101 ;; IDLWAVE has extensive customize support; to learn about the
102 ;; variables which control the mode's behavior, use `M-x
103 ;; idlwave-customize'.
105 ;; You can set your own preferred values with Customize, or with Lisp
106 ;; code in .emacs. For an example of what to put into .emacs, check
107 ;; the TexInfo documentation or see a complete .emacs available at the
113 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
114 ;; Numerics, Inc. is growing less and less complete as the two
115 ;; languages grow increasingly apart. The mode probably shouldn't
116 ;; even have "WAVE" in its title, but it's catchy, and was required
117 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
119 ;; Moving the point backwards in conjunction with abbrev expansion
120 ;; does not work as I would like it, but this is a problem with
121 ;; emacs abbrev expansion done by the self-insert-command. It ends
122 ;; up inserting the character that expanded the abbrev after moving
123 ;; point backward, e.g., "\cl" expanded with a space becomes
124 ;; "LONG( )" with point before the close paren. This is solved by
125 ;; using a temporary function in `post-command-hook' - not pretty,
128 ;; Tabs and spaces are treated equally as whitespace when filling a
129 ;; comment paragraph. To accomplish this, tabs are permanently
130 ;; replaced by spaces in the text surrounding the paragraph, which
131 ;; may be an undesirable side-effect. Replacing tabs with spaces is
132 ;; limited to comments only and occurs only when a comment
133 ;; paragraph is filled via `idlwave-fill-paragraph'.
135 ;; Muti-statement lines (using "&") on block begin and end lines can
136 ;; ruin the formatting. For example, multiple end statements on a
137 ;; line: endif & endif. Using "&" outside of block begin/end lines
140 ;; Determining the expression at point for printing and other
141 ;; examination commands is somewhat rough: currently only fairly
142 ;; simple entities are found. You can always drag-select or examine
143 ;; a pre-selected region.
145 ;; When forcing completion of method keywords, the initial
146 ;; query for a method has multiple entries for some methods. Would
147 ;; be too difficult to fix this hardly used case.
153 (eval-when-compile (require 'cl))
157 (unless (fboundp 'line-beginning-position)
158 (defalias 'line-beginning-position 'point-at-bol))
159 (unless (fboundp 'line-end-position)
160 (defalias 'line-end-position 'point-at-eol))
161 (unless (fboundp 'char-valid-p)
162 (defalias 'char-valid-p 'characterp))
164 (if (not (fboundp 'cancel-timer))
170 ;; Kludge to allow `defcustom' for Emacs 19.
171 (condition-case () (require 'custom) (error nil))
172 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
173 nil ;; We've got what we needed
174 ;; We have the old or no custom-library, hack around it!
175 (defmacro defgroup (&rest args) nil)
176 (defmacro defcustom (var value doc &rest args)
177 `(defvar ,var ,value ,doc))))
179 (defgroup idlwave nil
180 "Major mode for editing IDL .pro files."
182 :link '(url-link :tag "Home Page"
183 "http://idlwave.org")
184 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
186 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
187 :link '(custom-manual "(idlwave)Top")
192 ;;; Variables for indentation behavior ---------------------------------------
194 (defgroup idlwave-code-formatting nil
195 "Indentation and formatting options for IDLWAVE mode."
198 (defcustom idlwave-main-block-indent 0
199 "*Extra indentation for the main block of code.
200 That is the block between the FUNCTION/PRO statement and the END
201 statement for that program unit."
202 :group 'idlwave-code-formatting
205 (defcustom idlwave-block-indent 4
206 "*Extra indentation applied to block lines.
207 If you change this, you probably also want to change `idlwave-end-offset'."
208 :group 'idlwave-code-formatting
211 (defcustom idlwave-end-offset -4
212 "*Extra indentation applied to block END lines.
213 A value equal to negative `idlwave-block-indent' will make END lines
214 line up with the block BEGIN lines."
215 :group 'idlwave-code-formatting
218 (defcustom idlwave-continuation-indent 2
219 "*Extra indentation applied to continuation lines.
220 This extra offset applies to the first of a set of continuation lines.
221 The following lines receive the same indentation as the first."
222 :group 'idlwave-code-formatting
225 (defcustom idlwave-max-extra-continuation-indent 20
226 "*Maximum additional indentation for special continuation indent.
227 Several special indentations are tried to help line up continuation
228 lines in routine calls or definitions, other statements with
229 parentheses, or assignment statements. This variable specifies a
230 maximum amount by which this special indentation can exceed the
231 standard continuation indentation, otherwise defaulting to a fixed
232 offset. Set to 0 to effectively disable all special continuation
233 indentation, or to a large number (like 100) to enable it in all
234 cases. See also `idlwave-indent-to-open-paren', which can override
236 :group 'idlwave-code-formatting
239 (defcustom idlwave-indent-to-open-paren t
240 "*Non-nil means, indent continuation lines to innermost open
241 parenthesis. This indentation occurs even if otherwise disallowed by
242 `idlwave-max-extra-continuation-indent'. Matching parens and the
243 interleaving args are lined up. Example:
245 x = function_a(function_b(function_c( a, b, [1,2,3, $
251 When this variable is nil, paren alignment may still occur, based on
252 the value of `max-extra-continuation-indent', which, if zero, would
255 x = function_a(function_b(function_c( a, b, [1,2,3, $
260 :group 'idlwave-code-formatting
263 (defcustom idlwave-indent-parens-nested nil
264 "*Non-nil means, indent continuation lines with parens by nesting
265 lines at consecutively deeper levels."
266 :group 'idlwave-code-formatting
270 (defcustom idlwave-hanging-indent t
271 "*If set non-nil then comment paragraphs are indented under the
272 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
274 :group 'idlwave-code-formatting
277 (defcustom idlwave-hang-indent-regexp "- "
278 "*Regular expression matching the position of the hanging indent
279 in the first line of a comment paragraph. The size of the indent
280 extends to the end of the match for the regular expression."
281 :group 'idlwave-code-formatting
284 (defcustom idlwave-use-last-hang-indent nil
285 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
286 :group 'idlwave-code-formatting
289 (defcustom idlwave-fill-comment-line-only t
290 "*If non-nil then auto fill will only operate on comment lines."
291 :group 'idlwave-code-formatting
294 (defcustom idlwave-auto-fill-split-string t
295 "*If non-nil then auto fill will split strings with the IDL `+' operator.
296 When the line end falls within a string, string concatenation with the
297 '+' operator will be used to distribute a long string over lines.
298 If nil and a string is split then a terminal beep and warning are issued.
300 This variable is ignored when `idlwave-fill-comment-line-only' is
301 non-nil, since in this case code is not auto-filled."
302 :group 'idlwave-code-formatting
305 (defcustom idlwave-split-line-string t
306 "*If non-nil then `idlwave-split-line' will split strings with `+'.
307 When the splitting point of a line falls inside a string, split the string
308 using the `+' string concatenation operator. If nil and a string is
309 split then a terminal beep and warning are issued."
310 :group 'idlwave-code-formatting
313 (defcustom idlwave-no-change-comment ";;;"
314 "*The indentation of a comment that starts with this regular
315 expression will not be changed. Note that the indentation of a comment
316 at the beginning of a line is never changed."
317 :group 'idlwave-code-formatting
320 (defcustom idlwave-begin-line-comment nil
321 "*A comment anchored at the beginning of line.
322 A comment matching this regular expression will not have its
323 indentation changed. If nil the default is \"^;\", i.e., any line
324 beginning with a \";\". Expressions for comments at the beginning of
325 the line should begin with \"^\"."
326 :group 'idlwave-code-formatting
327 :type '(choice (const :tag "Any line beginning with `;'" nil)
330 (defcustom idlwave-code-comment ";;[^;]"
331 "*A comment that starts with this regular expression on a line by
332 itself is indented as if it is a part of IDL code. As a result if
333 the comment is not preceded by whitespace it is unchanged."
334 :group 'idlwave-code-formatting
337 ;; Comments not matching any of the above will be indented as a
338 ;; right-margin comment, i.e., to a minimum of `comment-column'.
340 ;;; Routine Info and Completion ---------------------------------------
342 (defgroup idlwave-routine-info nil
343 "Routine Info options for IDLWAVE mode."
346 (defcustom idlwave-use-library-catalogs t
347 "*Non-nil means search the IDL path for library catalog files.
349 These files, named .idlwave_catalog, document routine information for
350 individual directories and libraries of IDL .pro files. Many popular
351 libraries come with catalog files by default, so leaving this on is a
352 usually a good idea.."
353 :group 'idlwave-routine-info
356 (defcustom idlwave-init-rinfo-when-idle-after 10
357 "*Seconds of idle time before routine info is automatically initialized.
358 Initializing the routine info can take long, in particular if a large
359 library catalog is involved. When Emacs is idle for more than the number
360 of seconds specified by this variable, it starts the initialization.
361 The process is split into five steps, in order to keep possible work
362 interruption as short as possible. If one of the steps finishes, and no
363 user input has arrived in the mean time, initialization proceeds immediately
365 A good value for this variable is about 1/3 of the time initialization
366 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.
367 A Value of 0 means, don't initialize automatically."
368 :group 'idlwave-routine-info
371 (defcustom idlwave-scan-all-buffers-for-routine-info t
372 "*Non-nil means, scan buffers for IDL programs when updating info.
373 The scanning is done by the command `idlwave-update-routine-info'.
374 The following values are allowed:
376 nil Don't scan any buffers.
377 t Scan all idlwave-mode buffers in the current editing session.
378 current Scan only the current buffer, but no other buffers."
379 :group 'idlwave-routine-info
381 (const :tag "No buffer" nil)
382 (const :tag "All buffers" t)
383 (const :tag "Current buffer only" 'current)))
385 (defcustom idlwave-query-shell-for-routine-info t
386 "*Non-nil means query the shell for info about compiled routines.
387 Querying the shell is useful to get information about compiled modules,
388 and it is turned on by default. However, when you have a complete library
389 scan, this is not necessary."
390 :group 'idlwave-routine-info
393 (defcustom idlwave-auto-routine-info-updates
394 '(find-file save-buffer kill-buffer compile-buffer)
395 "*Controls under what circumstances routine info is updated automatically.
399 \(...) A list of circumstances. Allowed members are:
400 find-file Add info for new IDLWAVE buffers.
401 save-buffer Update buffer info when buffer is saved
402 kill-buffer Remove buffer info when buffer gets killed
403 compile-buffer Update shell info after `idlwave-shell-save-and...'"
404 :group 'idlwave-routine-info
406 (const :tag "Never" nil)
407 (const :tag "As often as possible" t)
408 (set :tag "Checklist" :greedy t
409 (const :tag "When visiting a file" find-file)
410 (const :tag "When saving a buffer" save-buffer)
411 (const :tag "After a buffer was killed" kill-buffer)
412 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
414 (defcustom idlwave-rinfo-max-source-lines 5
415 "*Maximum number of source files displayed in the Routine Info window.
416 When an integer, it is the maximum number of source files displayed.
417 t means to show all source files."
418 :group 'idlwave-routine-info
421 (defcustom idlwave-library-path nil
422 "Library path for Windows and MacOS. Not needed under Unix. When
423 selecting the directories to scan for IDL user catalog routine info,
424 IDLWAVE can, under UNIX, query the shell for the exact search path
425 \(the value of !PATH). However, under Windows and MacOS (pre-OSX),
426 the IDLWAVE shell does not work. In this case, this variable can be
427 set to specify the paths where IDLWAVE can find PRO files. The shell
428 will only be asked for a list of paths when this variable is nil. The
429 value is a list of directories. A directory preceeded by a `+' will
430 be searched recursively. If you set this variable on a UNIX system,
431 the shell will not be queried. See also `idlwave-system-directory'."
432 :group 'idlwave-routine-info
433 :type '(repeat (directory)))
435 (defcustom idlwave-system-directory ""
436 "The IDL system directory for Windows and MacOS. Not needed under
437 UNIX. Set this to the value of the `!DIR' system variable in IDL.
438 IDLWAVE uses this to find out which of the library routines belong to
439 the official system library. All files inside the `lib' subdirectory
440 are considered system library files - so don't install private stuff
441 in this directory. On UNIX systems, IDLWAVE queries the shell for the
442 value of `!DIR'. See also `idlwave-library-path'."
443 :group 'idlwave-routine-info
446 (defcustom idlwave-config-directory
447 (convert-standard-filename "~/.idlwave")
448 "*Directory for configuration files and user-library catalog."
449 :group 'idlwave-routine-info
452 (defvar idlwave-user-catalog-file "idlusercat.el")
453 (defvar idlwave-path-file "idlpath.el")
455 (defvar idlwave-libinfo-file nil
456 "*Obsolete variable, no longer used.")
458 (defcustom idlwave-special-lib-alist nil
459 "Alist of regular expressions matching special library directories.
460 When listing routine source locations, IDLWAVE gives a short hint where
461 the file defining the routine is located. By default it lists `SystemLib'
462 for routines in the system library `!DIR/lib' and `Library' for anything
463 else. This variable can define additional types. The car of each entry
464 is a regular expression matching the file name (they normally will match
465 on the path). The cdr is the string to be used as identifier. Max 10
467 :group 'idlwave-routine-info
469 (cons regexp string)))
471 (defcustom idlwave-auto-write-paths t
472 "Write out path (!PATH) and system directory (!DIR) info automatically.
473 Path info is needed to locate library catalog files. If non-nil,
474 whenever the path-list changes as a result of shell-query, etc., it is
475 written to file. Otherwise, the menu option \"Write Paths\" can be
476 used to force a write."
477 :group 'idlwave-routine-info
480 (defgroup idlwave-completion nil
481 "Completion options for IDLWAVE mode."
486 (defconst idlwave-tmp
487 '(choice :tag "by applying the function"
492 (symbol :tag "Other"))))
494 (defcustom idlwave-completion-case '((routine . upcase)
498 "Association list setting the case of completed words.
500 This variable determines the case (UPPER/lower/Capitalized...) of
501 words inserted into the buffer by completion. The preferred case can
502 be specified separately for routine names, keywords, classes and
504 This alist should therefore have entries for `routine' (normal
505 functions and procedures, i.e. non-methods), `keyword', `class', and
506 `method'. Plausible values are
508 upcase upcase whole word, like `BOX_CURSOR'
509 downcase downcase whole word, like `read_ppm'
510 capitalize capitalize each part, like `Widget_Control'
511 preserve preserve case as is, like `IDLgrView'
513 The value can also be any Emacs Lisp function which transforms the
514 case of characters in a string.
516 A value of `preserve' means that the case of the completed word is
517 identical to the way it was written in the definition statement of the
518 routine. This was implemented to allow for mixed-case completion, in
519 particular of object classes and methods.
520 If a completable word is defined in multiple locations, the meaning of
521 `preserve' is not unique since the different definitions might be
522 cased differently. Therefore IDLWAVE always takes the case of the
523 *first* definition it encounters during routine info collection and
524 uses the case derived from it consistently.
526 Note that a lowercase-only string in the buffer will always be completed in
527 lower case (but see the variable `idlwave-completion-force-default-case').
529 After changing this variable, you need to either restart Emacs or press
530 `C-u C-c C-i' to update the internal lists."
531 :group 'idlwave-completion
533 (cons (symbol :tag "Derive completion case for")
536 (defcustom idlwave-completion-force-default-case nil
537 "*Non-nil means, completion will always honor `idlwave-completion-case'.
538 When nil, only the completion of a mixed case or upper case string
539 will honor the default settings in `idlwave-completion-case', while
540 the completion of lower case strings will be completed entirely in
542 :group 'idlwave-completion
545 (defcustom idlwave-complete-empty-string-as-lower-case nil
546 "*Non-nil means, the empty string is considered downcase for completion.
547 The case of what is already in the buffer determines the case of completions.
548 When this variable is non-nil, the empty string is considered to be downcase.
549 Completing on the empty string then offers downcase versions of the possible
551 :group 'idlwave-completion
554 (defvar idlwave-default-completion-case-is-down nil
555 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
556 `idlwave-completion-case'.")
558 (defcustom idlwave-buffer-case-takes-precedence nil
559 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
560 To make this possible, we need to re-case everything each time we update
561 the routine info from the buffers. This is slow.
562 The default is to consider the case given in the system and library files
563 first which makes updating much faster."
564 :group 'idlwave-completion
567 (defcustom idlwave-highlight-help-links-in-completion t
568 "*Non-nil means, highlight completions for which system help is available.
569 Help can then be accessed with mouse-3.
570 This option is only effective when the online help system is installed."
571 :group 'idlwave-completion
574 (defcustom idlwave-support-inheritance t
575 "Non-nil means, treat inheritance with completion, online help etc.
576 When nil, IDLWAVE only knows about the native methods and tags of a class,
577 not about inherited ones."
578 :group 'idlwave-routine-info
581 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
582 "List of regular expressions for class-driven keyword inheritance.
583 Keyword inheritance is often tied to class inheritance by \"chaining\"
584 up the class tree. While it cannot be assumed that the presence of an
585 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
586 certain methods this assumption is almost always true. The methods
587 for which to assume this can be set here."
588 :group 'idlwave-routine-info
589 :type '(repeat (regexp :tag "Match method:")))
592 (defcustom idlwave-completion-show-classes 1
593 "*Number of classes to show when completing object methods and keywords.
594 When completing methods or keywords for an object with unknown class,
595 the *Completions* buffer will show the valid classes for each completion
598 MyMethod <Class1,Class2,Class3>
600 The value of this variable may be nil to inhibit display, or an integer to
601 indicate the maximum number of classes to display.
603 On XEmacs, a full list of classes will also be placed into a `help-echo'
604 property on the competion items, so that the list of classes for the current
605 item is displayed in the echo area. If the value of this variable is a
606 negative integer, the `help-echo' property will be suppressed."
607 :group 'idlwave-completion
608 :type '(choice (const :tag "Don't show" nil)
609 (integer :tag "Number of classes shown" 1)))
611 (defcustom idlwave-completion-fontify-classes t
612 "*Non-nil means, fontify the classes in completions buffer.
613 This makes it easier to distinguish the completion items from the extra
614 class info listed. See `idlwave-completion-show-classes'."
615 :group 'idlwave-completion
618 (defcustom idlwave-query-class '((method-default . nil)
619 (keyword-default . nil))
620 "Association list governing specification of object classes for completion.
622 When IDLWAVE tries to complete object-oriented methods, it usually
623 cannot determine the class of a given object from context. In order
624 to provide the user with a correct list of methods or keywords, it
625 needs to determine the appropriate class. IDLWAVE has two ways of
626 doing this (well, three ways if you count the shell... see
627 `idlwave-shell-query-for-class'):
629 1. Combine the items of all available classes which contain this
630 method for the purpose of completion. So when completing a method,
631 all methods of all known classes are available, and when completing
632 a keyword, all keywords allowed for this method in any class are
633 shown. This behavior is very much like normal completion and is
634 therefore the default. It works much better than one might think -
635 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
636 become uncomfortably long. See also
637 `idlwave-completion-show-classes'.
639 2. The second possibility is to ask the user on each occasion. To
640 make this less interruptive, IDLWAVE can store the class as a text
641 property on the object operator `->'. For a given object in the
642 source code, class selection will then be needed only once
643 - for example to complete the method. Keywords to the method can
644 then be completed directly, because the class is already known.
645 You will have to turn on the storage of the selected class
646 explicitly with the variable `idlwave-store-inquired-class'.
648 This variable allows you to configure IDLWAVE's method and
649 method-keyword completion behavior. Its value is an alist, which
650 should contain at least two elements: (method-default . VALUE) and
651 \(keyword-default . VALUE), where VALUE is either t or nil. These
652 specify if the class should be found during method and keyword
653 completion, respectively.
655 The alist may have additional entries specifying exceptions from the
656 keyword completion rule for specific methods, like INIT or
657 GETPROPERTY. In order to turn on class specification for the INIT
658 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
659 :group 'idlwave-completion
661 (cons (const method-default)
662 (boolean :tag "Determine class when completing METHODS "))
663 (cons (const keyword-default)
664 (boolean :tag "Determine class when completing KEYWORDS "))
666 :tag "Exceptions to defaults"
668 (cons (string :tag "MODULE" :value "")
669 (boolean :tag "Determine class for this method")))))
671 (defcustom idlwave-store-inquired-class nil
672 "*Non-nil means, store class of a method call as text property on `->'.
673 IDLWAVE sometimes has to ask the user for the class associated with a
674 particular object method call. This happens during the commands
675 `idlwave-routine-info' and `idlwave-complete', depending upon the
676 value of the variable `idlwave-query-class'.
678 When you specify a class, this information can be stored as a text
679 property on the `->' arrow in the source code, so that during the same
680 editing session, IDLWAVE will not have to ask again. When this
681 variable is non-nil, IDLWAVE will store and reuse the class information.
682 The class stored can be checked and removed with `\\[idlwave-routine-info]'
685 The default of this variable is nil, since the result of commands then
686 is more predictable. However, if you know what you are doing, it can
687 be nice to turn this on.
689 An arrow which knows the class will be highlighted with
690 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
691 displays (with prefix arg: deletes) the class stored on the arrow
693 :group 'idlwave-completion
696 (defcustom idlwave-class-arrow-face 'bold
697 "*Face to highlight object operator arrows `->' which carry a class property.
698 When IDLWAVE stores a class name as text property on an object arrow
699 \(see variable `idlwave-store-inquired-class', it highlights the arrow
700 with this font in order to remind the user that this arrow is special."
701 :group 'idlwave-completion
704 (defcustom idlwave-resize-routine-help-window t
705 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
706 :group 'idlwave-completion
709 (defcustom idlwave-keyword-completion-adds-equal t
710 "*Non-nil means, completion automatically adds `=' after completed keywords."
711 :group 'idlwave-completion
714 (defcustom idlwave-function-completion-adds-paren t
715 "*Non-nil means, completion automatically adds `(' after completed function.
716 nil means, don't add anything.
717 A value of `2' means, also add the closing parenthesis and position cursor
719 :group 'idlwave-completion
720 :type '(choice (const :tag "Nothing" nil)
722 (const :tag "()" 2)))
724 (defcustom idlwave-completion-restore-window-configuration t
725 "*Non-nil means, try to restore the window configuration after completion.
726 When completion is not unique, Emacs displays a list of completions.
727 This messes up your window configuration. With this variable set, IDLWAVE
728 restores the old configuration after successful completion."
729 :group 'idlwave-completion
732 ;;; Variables for abbrev and action behavior -----------------------------
734 (defgroup idlwave-abbrev-and-indent-action nil
735 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
736 The variables in this group govern this."
739 (defcustom idlwave-do-actions nil
740 "*Non-nil means performs actions when indenting.
741 The actions that can be performed are listed in `idlwave-indent-action-table'."
742 :group 'idlwave-abbrev-and-indent-action
745 (defcustom idlwave-abbrev-start-char "\\"
746 "*A single character string used to start abbreviations in abbrev mode.
747 Possible characters to chose from: ~`\%
748 or even '?'. '.' is not a good choice because it can make structure
749 field names act like abbrevs in certain circumstances.
751 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
752 must set it directly using `setq' in the .emacs file before idlwave.el
754 :group 'idlwave-abbrev-and-indent-action
757 (defcustom idlwave-surround-by-blank nil
758 "*Non-nil means, enable `idlwave-surround'.
759 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
761 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
763 Also see the default key bindings for keys using `idlwave-surround'.
764 Keys are bound and made into actions calling `idlwave-surround' with
765 `idlwave-action-and-binding'.
766 See help for `idlwave-action-and-binding' for examples.
768 Also see help for `idlwave-surround'."
769 :group 'idlwave-abbrev-and-indent-action
772 (defcustom idlwave-pad-keyword t
773 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
774 Whenever `idlwave-surround' is non-nil then this affects how '=' is
775 padded for keywords and for variables. If t, pad the same as for
776 assignments. If nil then spaces are removed. With any other value,
777 spaces are left unchanged."
778 :group 'idlwave-abbrev-and-indent-action
780 (const :tag "Pad like assignments" t)
781 (const :tag "Remove space near `='" nil)
782 (const :tag "Keep space near `='" 'keep)))
784 (defcustom idlwave-show-block t
785 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
786 :group 'idlwave-abbrev-and-indent-action
789 (defcustom idlwave-expand-generic-end nil
790 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
791 :group 'idlwave-abbrev-and-indent-action
794 (defcustom idlwave-reindent-end t
795 "*Non-nil means re-indent line after END was typed."
796 :group 'idlwave-abbrev-and-indent-action
799 (defcustom idlwave-abbrev-move t
800 "*Non-nil means the abbrev hook can move point.
801 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
802 definitions, use the command `list-abbrevs', for abbrevs that move
803 point. Moving point is useful, for example, to place point between
804 parentheses of expanded functions.
806 See `idlwave-check-abbrev'."
807 :group 'idlwave-abbrev-and-indent-action
810 (defcustom idlwave-abbrev-change-case nil
811 "*Non-nil means all abbrevs will be forced to either upper or lower case.
812 If the value t, all expanded abbrevs will be upper case.
813 If the value is 'down then abbrevs will be forced to lower case.
814 If nil, the case will not change.
815 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
816 upper case, regardless of this variable."
817 :group 'idlwave-abbrev-and-indent-action
820 (defcustom idlwave-reserved-word-upcase nil
821 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
822 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
823 Has effect only if in abbrev-mode."
824 :group 'idlwave-abbrev-and-indent-action
827 ;;; Action/Expand Tables.
829 ;; The average user may have difficulty modifying this directly. It
830 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
831 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
832 ;; examples of how to add an action.
834 ;; The action table is used by `idlwave-indent-line' whereas both the
835 ;; action and expand tables are used by `idlwave-indent-and-action'. In
836 ;; general, the expand table is only used when a line is explicitly
837 ;; indented. Whereas, in addition to being used when the expand table
838 ;; is used, the action table is used when a line is indirectly
839 ;; indented via line splitting, auto-filling or a new line creation.
843 ;; Capitalize system vars
844 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
846 ;; Capitalize procedure name
847 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
848 ;; '(capitalize-word 1) t)
850 ;; Capitalize common block name
851 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
852 ;; '(capitalize-word 1) t)
854 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
855 ;; '(capitalize-word -1) t)
857 (defvar idlwave-indent-action-table nil
858 "*Associated array containing action lists of search string (car),
859 and function as a cdr. This table is used by `idlwave-indent-line'.
860 See documentation for `idlwave-do-action' for a complete description of
863 Additions to the table are made with `idlwave-action-and-binding' when a
864 binding is not requested.
865 See help on `idlwave-action-and-binding' for examples.")
867 (defvar idlwave-indent-expand-table nil
868 "*Associated array containing action lists of search string (car),
869 and function as a cdr. The table is used by the
870 `idlwave-indent-and-action' function. See documentation for
871 `idlwave-do-action' for a complete description of the action lists.
873 Additions to the table are made with `idlwave-action-and-binding' when a
874 binding is requested.
875 See help on `idlwave-action-and-binding' for examples.")
877 ;;; Documentation header and history keyword ---------------------------------
879 (defgroup idlwave-documentation nil
880 "Options for documenting IDLWAVE files."
883 ;; FIXME: make defcustom?
884 (defvar idlwave-file-header
911 ; KEYWORD PARAMETERS:
943 ; MODIFICATION HISTORY:
947 "*A list (PATHNAME STRING) specifying the doc-header template to use for
948 summarizing a file. If PATHNAME is non-nil then this file will be included.
949 Otherwise STRING is used. If nil, the file summary will be omitted.
950 For example you might set PATHNAME to the path for the
951 lib_template.pro file included in the IDL distribution.")
953 (defcustom idlwave-header-to-beginning-of-file nil
954 "*Non-nil means, the documentation header will always be at start of file.
955 When nil, the header is positioned between the PRO/FUNCTION line of
956 the current routine and the code, allowing several routine headers in
958 :group 'idlwave-documentation
961 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
962 "*The hook function used to update the timestamp of a function."
963 :group 'idlwave-documentation
966 (defcustom idlwave-doc-modifications-keyword "HISTORY"
967 "*The modifications keyword to use with the log documentation commands.
968 A ':' is added to the keyword end.
969 Inserted by doc-header and used to position logs by doc-modification.
970 If nil it will not be inserted."
971 :group 'idlwave-documentation
974 (defcustom idlwave-doclib-start "^;+\\+"
975 "*Regexp matching the start of a document library header."
976 :group 'idlwave-documentation
979 (defcustom idlwave-doclib-end "^;+-"
980 "*Regexp matching the end of a document library header."
981 :group 'idlwave-documentation
984 ;;; External Programs -------------------------------------------------------
986 (defgroup idlwave-external-programs nil
987 "Path locations of external commands used by IDLWAVE."
990 ;; WARNING: The following variable has recently been moved from
991 ;; idlw-shell.el to this file. I hope this does not break
994 (defcustom idlwave-shell-explicit-file-name "idl"
995 "*If non-nil, this is the command to run IDL.
996 Should be an absolute file path or path relative to the current environment
997 execution search path. If you want to specify command line switches
998 for the idl program, use `idlwave-shell-command-line-options'.
1000 I know the name of this variable is badly chosen, but I cannot change
1001 it without compromizing backwards-compatibility."
1002 :group 'idlwave-external-programs
1005 (defcustom idlwave-shell-command-line-options nil
1006 "*A list of command line options for calling the IDL program.
1007 Since IDL is executed directly without going through a shell like /bin/sh,
1008 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1009 string for each argument. But you may also give a single string which
1010 contains the options whitespace-separated. Emacs will be kind enough to
1014 (repeat (string :value "")))
1015 :group 'idlwave-external-programs)
1017 (defcustom idlwave-help-application "idlhelp"
1018 "*The external application providing reference help for programming."
1019 :group 'idlwave-external-programs
1022 ;;; Some Shell variables which must be defined here.-----------------------
1024 (defcustom idlwave-shell-debug-modifiers '()
1025 "List of modifiers to be used for the debugging commands.
1026 Will be used to bind debugging commands in the shell buffer and in all
1027 source buffers. These are additional convenience bindings, the debugging
1028 commands are always available with the `C-c C-d' prefix.
1029 If you set this to '(control shift), this means setting a breakpoint will
1030 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1031 are `control', `meta', `super', `hyper', `alt', and `shift'."
1032 :group 'idlwave-shell-general-setup
1033 :type '(set :tag "Specify modifiers"
1041 (defcustom idlwave-shell-automatic-start nil
1042 "*If non-nil attempt invoke idlwave-shell if not already running.
1043 This is checked when an attempt to send a command to an
1044 IDL process is made."
1045 :group 'idlwave-shell-general-setup
1048 ;;; Miscellaneous variables -------------------------------------------------
1050 (defgroup idlwave-misc nil
1051 "Miscellaneous options for IDLWAVE mode."
1052 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
1055 (defcustom idlwave-startup-message t
1056 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1057 :group 'idlwave-misc
1060 (defcustom idlwave-default-font-lock-items
1061 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1062 common-blocks class-arrows)
1063 "Items which should be fontified on the default fontification level 2.
1064 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1065 is everything and level 2 is specified by this list.
1066 This variable must be set before IDLWAVE gets loaded. It is
1067 a list of symbols, the following symbols are allowed.
1069 pros-and-functions Procedure and Function definitions
1070 batch-files Batch Files
1071 idlwave-idl-keywords IDL Keywords
1072 label Statement Labels
1073 goto Goto Statements
1074 common-blocks Common Blocks
1075 keyword-parameters Keyword Parameters in routine definitions and calls
1076 system-variables System Variables
1077 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1078 class-arrows Object Arrows with class property"
1079 :group 'idlwave-misc
1082 (const :tag "Procedure and Function definitions" pros-and-functions)
1083 (const :tag "Batch Files" batch-files)
1084 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1085 (const :tag "Statement Labels" label)
1086 (const :tag "Goto Statements" goto)
1087 (const :tag "Tags in Structure Definition" structtag)
1088 (const :tag "Structure Name" structname)
1089 (const :tag "Common Blocks" common-blocks)
1090 (const :tag "Keyword Parameters" keyword-parameters)
1091 (const :tag "System Variables" system-variables)
1092 (const :tag "FIXME: Warning" fixme)
1093 (const :tag "Object Arrows with class property " class-arrows)))
1095 (defcustom idlwave-mode-hook nil
1096 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1097 :group 'idlwave-misc
1100 (defcustom idlwave-load-hook nil
1101 "Normal hook. Executed when idlwave.el is loaded."
1102 :group 'idlwave-misc
1105 (defvar idlwave-experimental nil
1106 "Non-nil means turn on a few experimental features.
1107 This variable is only for the maintainer, to test difficult stuff,
1108 while still distributing stable releases.
1109 As a user, you should not set this to t.")
1112 ;;; End customization variables section
1115 ;;; Non customization variables
1117 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1118 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1119 ;;; and Carsten Dominik...
1121 ;; The following are the reserved words in IDL. Maybe we should
1122 ;; highlight some more stuff as well?
1123 ;; Procedure declarations. Fontify keyword plus procedure name.
1124 (defvar idlwave-idl-keywords
1125 ;; To update this regexp, update the list of keywords and
1126 ;; evaluate the form.
1132 ;; '("||" "&&" "and" "or" "xor" "not"
1133 ;; "eq" "ge" "gt" "le" "lt" "ne"
1134 ;; "for" "do" "endfor"
1135 ;; "if" "then" "endif" "else" "endelse"
1136 ;; "case" "of" "endcase"
1137 ;; "switch" "break" "continue" "endswitch"
1139 ;; "repeat" "until" "endrep"
1140 ;; "while" "endwhile"
1143 ;; "compile_opt" "forward_function"
1144 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1146 "\\<\\(&&\\|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\\|||\\)\\>")
1149 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1150 ;; Function declarations. Fontify keyword plus function name.
1152 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1153 (1 font-lock-keyword-face)
1154 (2 font-lock-function-name-face nil t)))
1158 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1159 (1 font-lock-keyword-face) ; "common"
1160 (2 font-lock-reference-face nil t) ; block name
1161 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1162 ;; Start with point after block name and comma
1163 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1165 (1 font-lock-variable-name-face) ; variable names
1170 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1174 '("\\<FIXME:" (0 font-lock-warning-face t)))
1178 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1180 ;; The goto statement and its label
1182 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1183 (1 font-lock-keyword-face)
1184 (2 font-lock-reference-face)))
1186 ;; Tags in structure definitions. Note that this definition
1187 ;; actually collides with labels, so we have to use the same
1188 ;; face. It also matches named subscript ranges,
1189 ;; e.g. vec{bottom:top]. No good way around this.
1191 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1195 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1196 (2 font-lock-function-name-face)))
1198 ;; Keyword parameters, like /xlog or ,xrange=[]
1199 ;; This is anchored to the comma preceeding the keyword.
1200 ;; Treats continuation lines, works only during whole buffer
1201 ;; fontification. Slow, use it only in fancy fontification.
1203 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1204 (5 font-lock-reference-face)))
1206 ;; System variables start with a bang.
1208 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1209 (1 font-lock-variable-name-face)))
1211 ;; Special and unusual operators (not used because too noisy)
1213 '("[<>#]" (0 font-lock-keyword-face)))
1215 ;; All operators (not used because too noisy)
1217 '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1219 ;; Arrows with text property `idlwave-class'
1221 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1223 (defconst idlwave-font-lock-keywords-1
1224 (list pros-and-functions batch-files)
1225 "Subdued level highlighting for IDLWAVE mode.")
1227 (defconst idlwave-font-lock-keywords-2
1228 (mapcar 'symbol-value idlwave-default-font-lock-items)
1229 "Medium level highlighting for IDLWAVE mode.")
1231 (defconst idlwave-font-lock-keywords-3
1232 (list pros-and-functions
1234 idlwave-idl-keywords
1242 "Gaudy level highlighting for IDLWAVE mode."))
1244 (defun idlwave-match-class-arrows (limit)
1245 ;; Match an object arrow with class property
1246 (and idlwave-store-inquired-class
1247 (re-search-forward "->" limit 'limit)
1248 (get-text-property (match-beginning 0) 'idlwave-class)))
1250 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1251 "Default expressions to highlight in IDLWAVE mode.")
1253 (defvar idlwave-font-lock-defaults
1254 '((idlwave-font-lock-keywords
1255 idlwave-font-lock-keywords-1
1256 idlwave-font-lock-keywords-2
1257 idlwave-font-lock-keywords-3)
1259 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
1262 (put 'idlwave-mode 'font-lock-defaults
1263 idlwave-font-lock-defaults) ; XEmacs
1265 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1266 "Regexp to match the start of a full-line comment.
1267 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1268 only by whitespace.")
1270 (defconst idlwave-begin-block-reg
1271 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1272 "Regular expression to find the beginning of a block. The case does
1273 not matter. The search skips matches in comments.")
1275 (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1276 "Regular expression to find the beginning of a unit. The case does
1279 (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1280 "Regular expression to find the line that indicates the end of unit.
1281 This line is the end of buffer or the start of another unit. The case does
1282 not matter. The search skips matches in comments.")
1284 (defconst idlwave-continue-line-reg "\\<\\$"
1285 "Regular expression to match a continued line.")
1287 (defconst idlwave-end-block-reg
1288 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1289 "Regular expression to find the end of a block. The case does
1290 not matter. The search skips matches found in comments.")
1292 (defconst idlwave-block-matches
1294 ("function" . "end")
1295 ("case" . "endcase")
1296 ("else" . "endelse")
1299 ("repeat" . "endrep")
1300 ("switch" . "endswitch")
1301 ("while" . "endwhile"))
1302 "Matches between statements and the corresponding END variant.
1303 The cars are the reserved words starting a block. If the block really
1304 begins with BEGIN, the cars are the reserved words before the begin
1305 which can be used to identify the block type.
1306 This is used to check for the correct END type, to close blocks and
1307 to expand generic end statements to their detailed form.")
1309 (defconst idlwave-block-match-regexp
1310 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1311 "Regular expression matching reserved words which can stand before
1312 blocks starting with a BEGIN statement. The matches must have associations
1313 `idlwave-block-matches'")
1315 (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
1316 "Regular expression matching an IDL identifier.")
1318 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1319 "Regular expression matching IDL system variables.")
1321 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1322 "Regular expression matching IDL variable names.")
1324 (defconst idlwave-label (concat idlwave-identifier ":")
1325 "Regular expression matching IDL labels.")
1327 (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1328 "\\(\\s *" idlwave-identifier "::\\)?"
1331 (defconst idlwave-statement-match
1333 ;; "endif else" is the only possible "end" that can be
1334 ;; followed by a statement on the same line.
1335 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1336 ;; all other "end"s can not be followed by a statement.
1337 (cons 'end (list idlwave-end-block-reg nil))
1338 '(if . ("if\\>" "then"))
1339 '(for . ("for\\>" "do"))
1340 '(begin . ("begin\\>" nil))
1341 '(pdef . ("pro\\>\\|function\\>" nil))
1342 '(while . ("while\\>" "do"))
1343 '(repeat . ("repeat\\>" "repeat"))
1344 '(goto . ("goto\\>" nil))
1345 '(case . ("case\\>" nil))
1346 '(switch . ("switch\\>" nil))
1347 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
1348 "\\(" idlwave-method-call "\\s *\\)?"
1351 (cons 'call (list (concat
1352 "\\(" idlwave-method-call "\\s *\\)?"
1354 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
1355 (cons 'assign (list (concat
1356 "\\(" idlwave-variable "\\) *=") nil)))
1358 "Associated list of statement matching regular expressions.
1359 Each regular expression matches the start of an IDL statement. The
1360 first element of each association is a symbol giving the statement
1361 type. The associated value is a list. The first element of this list
1362 is a regular expression matching the start of an IDL statement for
1363 identifying the statement type. The second element of this list is a
1364 regular expression for finding a substatement for the type. The
1365 substatement starts after the end of the found match modulo
1366 whitespace. If it is nil then the statement has no substatement. The
1367 list order matters since matching an assignment statement exactly is
1368 not possible without parsing. Thus assignment statement become just
1369 the leftover unidentified statements containing an equal sign." )
1371 (defvar idlwave-fill-function 'auto-fill-function
1372 "IDL mode auto fill function.")
1374 (defvar idlwave-comment-indent-function 'comment-indent-function
1375 "IDL mode comment indent function.")
1377 ;; Note that this is documented in the v18 manuals as being a string
1378 ;; of length one rather than a single character.
1379 ;; The code in this file accepts either format for compatibility.
1380 (defvar idlwave-comment-indent-char ?\
1381 "Character to be inserted for IDL comment indentation.
1384 (defconst idlwave-continuation-char ?$
1385 "Character which is inserted as a last character on previous line by
1386 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1388 (defconst idlwave-mode-version "5.7_22")
1390 (defmacro idlwave-keyword-abbrev (&rest args)
1391 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1393 ,(append '(idlwave-check-abbrev) args))))
1395 ;; If I take the time I can replace idlwave-keyword-abbrev with
1396 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1397 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1398 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1399 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1401 (defmacro idlwave-code-abbrev (&rest args)
1402 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1403 Specifically, if the abbrev is in a comment or string it is unexpanded.
1404 Otherwise ARGS forms a list that is evaluated."
1406 ,(prin1-to-string args) ;; Puts the code in the doc string
1407 (if (idlwave-quoted)
1408 (progn (unexpand-abbrev) nil)
1411 (defvar idlwave-mode-map (make-sparse-keymap)
1412 "Keymap used in IDL mode.")
1414 (defvar idlwave-mode-syntax-table (make-syntax-table)
1415 "Syntax table in use in `idlwave-mode' buffers.")
1417 (modify-syntax-entry ?+ "." idlwave-mode-syntax-table)
1418 (modify-syntax-entry ?- "." idlwave-mode-syntax-table)
1419 (modify-syntax-entry ?* "." idlwave-mode-syntax-table)
1420 (modify-syntax-entry ?/ "." idlwave-mode-syntax-table)
1421 (modify-syntax-entry ?^ "." idlwave-mode-syntax-table)
1422 (modify-syntax-entry ?# "." idlwave-mode-syntax-table)
1423 (modify-syntax-entry ?= "." idlwave-mode-syntax-table)
1424 (modify-syntax-entry ?% "." idlwave-mode-syntax-table)
1425 (modify-syntax-entry ?< "." idlwave-mode-syntax-table)
1426 (modify-syntax-entry ?> "." idlwave-mode-syntax-table)
1427 (modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table)
1428 (modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table)
1429 (modify-syntax-entry ?\\ "." idlwave-mode-syntax-table)
1430 (modify-syntax-entry ?_ "_" idlwave-mode-syntax-table)
1431 (modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table)
1432 (modify-syntax-entry ?} "){" idlwave-mode-syntax-table)
1433 (modify-syntax-entry ?$ "_" idlwave-mode-syntax-table)
1434 (modify-syntax-entry ?. "." idlwave-mode-syntax-table)
1435 (modify-syntax-entry ?\; "<" idlwave-mode-syntax-table)
1436 (modify-syntax-entry ?\n ">" idlwave-mode-syntax-table)
1437 (modify-syntax-entry ?\f ">" idlwave-mode-syntax-table)
1439 (defvar idlwave-find-symbol-syntax-table
1440 (copy-syntax-table idlwave-mode-syntax-table)
1441 "Syntax table that treats symbol characters as word characters.")
1443 (modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1444 (modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1445 (modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table)
1446 (modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table)
1448 (defmacro idlwave-with-special-syntax (&rest body)
1449 "Execute BODY with a different syntax table."
1450 `(let ((saved-syntax (syntax-table)))
1453 (set-syntax-table idlwave-find-symbol-syntax-table)
1455 (set-syntax-table saved-syntax))))
1457 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1458 ; "Execute BODY with a different syntax table."
1459 ; `(let ((saved-syntax (syntax-table)))
1462 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1464 ; (set-syntax-table saved-syntax))))
1466 (defun idlwave-action-and-binding (key cmd &optional select)
1467 "KEY and CMD are made into a key binding and an indent action.
1468 KEY is a string - same as for the `define-key' function. CMD is a
1469 function of no arguments or a list to be evaluated. CMD is bound to
1470 KEY in `idlwave-mode-map' by defining an anonymous function calling
1471 `self-insert-command' followed by CMD. If KEY contains more than one
1472 character a binding will only be set if SELECT is 'both.
1474 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1475 replacing any previous value for KEY. If a binding is not set then it
1476 will instead be placed in `idlwave-indent-action-table'.
1478 If the optional argument SELECT is nil then an action and binding are
1479 created. If SELECT is 'noaction, then a binding is always set and no
1480 action is created. If SELECT is 'both then an action and binding
1481 will both be created even if KEY contains more than one character.
1482 Otherwise, if SELECT is non-nil then only an action is created.
1485 No spaces before and 1 after a comma
1486 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1487 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1488 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1489 Capitalize system variables - action only
1490 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1491 (if (not (equal select 'noaction))
1493 (let* ((table (if select 'idlwave-indent-action-table
1494 'idlwave-indent-expand-table))
1495 (table-key (regexp-quote key))
1496 (cell (assoc table-key (eval table))))
1498 ;; Replace action command
1501 (set table (append (eval table) (list (cons table-key cmd)))))))
1502 ;; Make key binding for action
1503 (if (or (and (null select) (= (length key) 1))
1504 (equal select 'noaction)
1505 (equal select 'both))
1506 (define-key idlwave-mode-map key
1509 (self-insert-command 1))
1510 (list (if (listp cmd)
1514 (fset 'idlwave-debug-map (make-sparse-keymap))
1516 (define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab)
1517 (define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab)
1518 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1519 (define-key idlwave-mode-map "'" 'idlwave-show-matching-quote)
1520 (define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote)
1521 (define-key idlwave-mode-map "\C-g" 'idlwave-keyboard-quit)
1522 (define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region)
1523 (define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1524 (define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram)
1525 (define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block)
1526 (define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block)
1527 (define-key idlwave-mode-map "\C-c]" 'idlwave-close-block)
1528 (define-key idlwave-mode-map [(meta control h)] 'idlwave-mark-subprogram)
1529 (define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block)
1530 (define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block)
1531 (define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block)
1532 (define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block)
1533 (define-key idlwave-mode-map "\M-\r" 'idlwave-split-line)
1534 (define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram)
1535 (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement)
1536 (define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
1537 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1538 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1539 (define-key idlwave-mode-map [(shift tab)] 'idlwave-indent-statement)
1540 (define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
1541 (define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph)
1542 (define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde)
1543 (define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header)
1544 (define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification)
1545 (define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case)
1546 (define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map)
1547 (when (and (boundp 'idlwave-shell-debug-modifiers)
1548 (listp idlwave-shell-debug-modifiers)
1549 (not (equal idlwave-shell-debug-modifiers '())))
1550 ;; Bind the debug commands also with the special modifiers.
1551 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1552 (mods-noshift (delq 'shift
1553 (copy-sequence idlwave-shell-debug-modifiers))))
1554 (define-key idlwave-mode-map
1555 (vector (append mods-noshift (list (if shift ?C ?c))))
1556 'idlwave-shell-save-and-run)
1557 (define-key idlwave-mode-map
1558 (vector (append mods-noshift (list (if shift ?B ?b))))
1559 'idlwave-shell-break-here)
1560 (define-key idlwave-mode-map
1561 (vector (append mods-noshift (list (if shift ?E ?e))))
1562 'idlwave-shell-run-region)))
1563 (define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1564 (define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1565 (define-key idlwave-mode-map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1566 (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for)
1567 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1568 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1569 (define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat)
1570 (define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while)
1571 (define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1572 (define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell)
1573 (define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1574 (define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1575 (autoload 'idlwave-shell "idlw-shell"
1576 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1577 (autoload 'idlwave-shell-send-command "idlw-shell")
1578 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1579 "Run `idlwave-shell' and switch back to current window" t)
1580 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1581 "Save and run buffer under the shell." t)
1582 (autoload 'idlwave-shell-break-here "idlw-shell"
1583 "Set breakpoint in current line." t)
1584 (autoload 'idlwave-shell-run-region "idlw-shell"
1585 "Compile and run the region." t)
1586 (define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module)
1587 (define-key idlwave-mode-map "\C-c\C-t" 'idlwave-find-module-this-file)
1588 (define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info)
1589 (define-key idlwave-mode-map "\M-?" 'idlwave-context-help)
1590 (define-key idlwave-mode-map [(control meta ?\?)] 'idlwave-online-help)
1591 ;; Pickup both forms of Esc/Meta binding
1592 (define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
1593 (define-key idlwave-mode-map [?\e?\t] 'idlwave-complete)
1594 (define-key idlwave-mode-map "\M-\C-i" 'idlwave-complete)
1595 (define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
1596 (define-key idlwave-mode-map "\C-c=" 'idlwave-resolve)
1597 (define-key idlwave-mode-map
1598 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1599 'idlwave-mouse-context-help)
1601 ;; Set action and key bindings.
1602 ;; See description of the function `idlwave-action-and-binding'.
1603 ;; Automatically add spaces for the following characters
1604 ;(idlwave-action-and-binding "&" '(idlwave-surround -1 -1 '(?&) 1
1605 ; (lambda (char) 0)))
1606 (idlwave-action-and-binding "<" '(idlwave-surround -1 -1))
1607 ;; Binding works for both > and ->, by changing the length of the token.
1608 (idlwave-action-and-binding ">" '(idlwave-surround -1 -1 '(?-) 1
1609 'idlwave-gtr-pad-hook))
1610 (idlwave-action-and-binding "->" '(idlwave-surround -1 -1 nil 2) t)
1611 (idlwave-action-and-binding "," '(idlwave-surround 0 -1))
1613 ;; Automatically add spaces to equal sign if not keyword
1614 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1619 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1620 ;;; space is inserted (this is the space typed by the user to expanded
1623 (defvar idlwave-mode-abbrev-table nil
1624 "Abbreviation table used for IDLWAVE mode")
1625 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1627 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1628 "Define-abbrev with backward compatibility.
1630 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1631 idlwave-mode-abbrev-table unless TABLE is non-nil."
1632 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1633 (args (list (or table idlwave-mode-abbrev-table)
1634 (if noprefix name (concat idlwave-abbrev-start-char name))
1638 (apply 'define-abbrev (append args '(0 t)))
1639 (error (apply 'define-abbrev args)))))
1642 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1643 "w" idlwave-mode-syntax-table)
1649 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1650 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1651 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1652 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1653 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1654 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1655 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1656 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1657 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1659 ;; Keywords, system functions, conversion routines
1661 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1662 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1663 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1664 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1665 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1666 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1667 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1668 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1669 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1672 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1673 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1674 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1675 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1676 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1677 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1678 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1679 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1680 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1681 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1682 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1683 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1684 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1685 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1686 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1687 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1688 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1689 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1690 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1693 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1697 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1698 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1699 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1700 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1701 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1702 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1704 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1705 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1706 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1707 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1708 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1709 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1710 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1711 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1712 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1714 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1715 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1716 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1718 ;; This section is reserved words only. (From IDL user manual)
1720 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1721 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1722 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1723 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1724 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1725 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1726 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1727 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1728 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1729 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1730 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1731 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1732 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1733 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1734 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1735 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1736 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1737 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1738 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1739 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1740 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1741 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1742 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1743 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1744 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1745 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1746 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1760 (defvar imenu-create-index-function)
1761 (defvar extract-index-name-function)
1762 (defvar prev-index-position-function)
1763 (defvar imenu-extract-index-name-function)
1764 (defvar imenu-prev-index-position-function)
1765 ;; defined later - so just make the compiler hush
1766 (defvar idlwave-mode-menu)
1767 (defvar idlwave-mode-debug-menu)
1770 (defun idlwave-mode ()
1771 "Major mode for editing IDL source files (version 5.7_22).
1773 The main features of this mode are
1775 1. Indentation and Formatting
1776 --------------------------
1777 Like other Emacs programming modes, C-j inserts a newline and indents.
1778 TAB is used for explicit indentation of the current line.
1780 To start a continuation line, use \\[idlwave-split-line]. This
1781 function can also be used in the middle of a line to split the line
1782 at that point. When used inside a long constant string, the string
1783 is split at that point with the `+' concatenation operator.
1785 Comments are indented as follows:
1787 `;;;' Indentation remains unchanged.
1788 `;;' Indent like the surrounding code
1789 `;' Indent to a minimum column.
1791 The indentation of comments starting in column 0 is never changed.
1793 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1794 comment. The indentation of the second line of the paragraph
1795 relative to the first will be retained. Use
1796 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1797 comments. When the variable `idlwave-fill-comment-line-only' is
1798 nil, code can also be auto-filled and auto-indented.
1800 To convert pre-existing IDL code to your formatting style, mark the
1801 entire buffer with \\[mark-whole-buffer] and execute
1802 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1803 again followed by \\[indent-region] (`indent-region').
1807 IDLWAVE displays information about the calling sequence and the
1808 accepted keyword parameters of a procedure or function with
1809 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1810 source file of a module. These commands know about system
1811 routines, all routines in idlwave-mode buffers and (when the
1812 idlwave-shell is active) about all modules currently compiled under
1813 this shell. It also makes use of pre-compiled or custom-scanned
1814 user and library catalogs many popular libraries ship with by
1815 default. Use \\[idlwave-update-routine-info] to update this
1816 information, which is also used for completion (see item 4).
1820 \\[idlwave-context-help] displays the IDL documentation relevant
1821 for the system variable, keyword, or routine at point. A single
1822 key stroke gets you directly to the right place in the docs. The
1823 HTML help files package must be installed for this to work -- check
1824 the IDLWAVE webpage for the correct package for your version. See
1825 the manual to configure where and how the HTML help is displayed.
1829 \\[idlwave-complete] completes the names of procedures, functions
1830 class names, keyword parameters, system variables and tags, class
1831 tags, structure tags, filenames and much more. It is context
1832 sensitive and figures out what is expected at point. Lower case
1833 strings are completed in lower case, other strings in mixed or
1836 5. Code Templates and Abbreviations
1837 --------------------------------
1838 Many Abbreviations are predefined to expand to code fragments and templates.
1839 The abbreviations start generally with a `\\`. Some examples
1841 \\pr PROCEDURE template
1842 \\fu FUNCTION template
1843 \\c CASE statement template
1844 \\sw SWITCH statement template
1845 \\f FOR loop template
1846 \\r REPEAT Loop template
1847 \\w WHILE loop template
1848 \\i IF statement template
1849 \\elif IF-ELSE statement template
1852 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1853 have direct keybindings - see the list of keybindings below.
1855 \\[idlwave-doc-header] inserts a documentation header at the
1856 beginning of the current program unit (pro, function or main).
1857 Change log entries can be added to the current program unit with
1858 \\[idlwave-doc-modification].
1860 6. Automatic Case Conversion
1861 -------------------------
1862 The case of reserved words and some abbrevs is controlled by
1863 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1865 7. Automatic END completion
1866 ------------------------
1867 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1868 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1872 Loading idlwave.el runs `idlwave-load-hook'.
1873 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1875 9. Documentation and Customization
1876 -------------------------------
1877 Info documentation for this package is available. Use
1878 \\[idlwave-info] to display (complain to your sysadmin if that does
1879 not work). For Postscript, PDF, and HTML versions of the
1880 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1881 IDLWAVE has customize support - see the group `idlwave'.
1885 Here is a list of all keybindings of this mode.
1886 If some of the key bindings below show with ??, use \\[describe-key]
1887 followed by the key sequence to see what the key sequence does.
1889 \\{idlwave-mode-map}"
1892 (kill-all-local-variables)
1894 (if idlwave-startup-message
1895 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1896 (setq idlwave-startup-message nil)
1898 (setq local-abbrev-table idlwave-mode-abbrev-table)
1899 (set-syntax-table idlwave-mode-syntax-table)
1901 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1903 (make-local-variable idlwave-comment-indent-function)
1904 (set idlwave-comment-indent-function 'idlwave-comment-hook)
1906 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1907 (set (make-local-variable 'comment-start) ";")
1908 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
1909 (set (make-local-variable 'abbrev-all-caps) t)
1910 (set (make-local-variable 'indent-tabs-mode) nil)
1911 (set (make-local-variable 'completion-ignore-case) t)
1913 (use-local-map idlwave-mode-map)
1915 (when (featurep 'easymenu)
1916 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1917 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1919 (setq mode-name "IDLWAVE")
1920 (setq major-mode 'idlwave-mode)
1921 (setq abbrev-mode t)
1923 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1924 (setq comment-end "")
1925 (set (make-local-variable 'comment-multi-line) nil)
1926 (set (make-local-variable 'paragraph-separate)
1927 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1928 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1929 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1930 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1932 ;; Set tag table list to use IDLTAGS as file name.
1933 (if (boundp 'tag-table-alist)
1934 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1936 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1937 ;; Following line is for Emacs - XEmacs uses the corresponding property
1938 ;; on the `idlwave-mode' symbol.
1939 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1942 (set (make-local-variable 'imenu-create-index-function)
1943 'imenu-default-create-index-function)
1944 (set (make-local-variable 'imenu-extract-index-name-function)
1946 (set (make-local-variable 'imenu-prev-index-position-function)
1947 'idlwave-prev-index-position)
1949 ;; Make a local post-command-hook and add our hook to it
1950 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1952 ;; Make local hooks for buffer updates
1953 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1954 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1955 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1957 ;; Setup directories and file, if necessary
1960 ;; Update the routine info with info about current buffer?
1961 (idlwave-new-buffer-update)
1963 ;; Run the mode hook
1964 (run-mode-hooks 'idlwave-mode-hook))
1966 (defvar idlwave-setup-done nil)
1967 (defun idlwave-setup ()
1968 (unless idlwave-setup-done
1969 (if (not (file-directory-p idlwave-config-directory))
1970 (make-directory idlwave-config-directory))
1971 (setq idlwave-user-catalog-file (expand-file-name
1972 idlwave-user-catalog-file
1973 idlwave-config-directory)
1974 idlwave-path-file (expand-file-name
1976 idlwave-config-directory))
1977 (idlwave-read-paths) ; we may need these early
1978 (setq idlwave-setup-done t)))
1981 ;; Code Formatting ----------------------------------------------------
1984 (defun idlwave-push-mark (&rest rest)
1985 "Push mark for compatibility with Emacs 18/19."
1986 (if (fboundp 'iconify-frame)
1987 (apply 'push-mark rest)
1990 (defun idlwave-hard-tab ()
1991 "Inserts TAB in buffer in current position."
1995 ;;; This stuff is experimental
1997 (defvar idlwave-command-hook nil
1998 "If non-nil, a list that can be evaluated using `eval'.
1999 It is evaluated in the lisp function `idlwave-command-hook' which is
2000 placed in `post-command-hook'.")
2002 (defun idlwave-command-hook ()
2003 "Command run after every command.
2004 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2005 sets the variable to zero afterwards."
2006 (and idlwave-command-hook
2007 (listp idlwave-command-hook)
2009 (eval idlwave-command-hook)
2011 (setq idlwave-command-hook nil))
2015 ;; It would be better to use expand.el for better abbrev handling and
2018 (defun idlwave-check-abbrev (arg &optional reserved)
2019 "Reverses abbrev expansion if in comment or string.
2020 Argument ARG is the number of characters to move point
2021 backward if `idlwave-abbrev-move' is non-nil.
2022 If optional argument RESERVED is non-nil then the expansion
2023 consists of reserved words, which will be capitalized if
2024 `idlwave-reserved-word-upcase' is non-nil.
2025 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2026 is non-nil, unless its value is \`down in which case the abbrev will be
2027 made into all lowercase.
2028 Returns non-nil if abbrev is left expanded."
2029 (if (idlwave-quoted)
2030 (progn (unexpand-abbrev)
2032 (if (and reserved idlwave-reserved-word-upcase)
2033 (upcase-region last-abbrev-location (point))
2035 ((equal idlwave-abbrev-change-case 'down)
2036 (downcase-region last-abbrev-location (point)))
2037 (idlwave-abbrev-change-case
2038 (upcase-region last-abbrev-location (point)))))
2039 (if (and idlwave-abbrev-move (> arg 0))
2040 (if (boundp 'post-command-hook)
2041 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2042 (backward-char arg)))
2045 (defun idlwave-in-comment ()
2046 "Returns t if point is inside a comment, nil otherwise."
2048 (let ((here (point)))
2049 (and (idlwave-goto-comment) (> here (point))))))
2051 (defun idlwave-goto-comment ()
2052 "Move to start of comment delimiter on current line.
2053 Moves to end of line if there is no comment delimiter.
2054 Ignores comment delimiters in strings.
2055 Returns point if comment found and nil otherwise."
2056 (let ((eos (progn (end-of-line) (point)))
2059 ;; Look for first comment delimiter not in a string
2061 (setq found (search-forward comment-start eos 'lim))
2062 (while (and found (idlwave-in-quote))
2063 (setq found (search-forward comment-start eos 'lim)))
2064 (store-match-data data)
2065 (and found (not (idlwave-in-quote))
2070 (defvar transient-mark-mode)
2071 (defvar zmacs-regions)
2072 (defvar mark-active)
2073 (defun idlwave-region-active-p ()
2074 "Is transient-mark-mode on and the region active?
2075 Works on both Emacs and XEmacs."
2076 (if (featurep 'xemacs)
2077 (and zmacs-regions (region-active-p))
2078 (and transient-mark-mode mark-active)))
2080 (defun idlwave-show-matching-quote ()
2081 "Insert quote and show matching quote if this is end of a string."
2083 (let ((bq (idlwave-in-quote))
2084 (inq last-command-char))
2085 (if (and bq (not (idlwave-in-comment)))
2086 (let ((delim (char-after bq)))
2092 ;; Not the end of a string
2095 (defun idlwave-show-begin-check ()
2096 "Ensure that the previous word was a token before `idlwave-show-begin'.
2097 An END token must be preceded by whitespace."
2098 (if (not (idlwave-quoted))
2103 (looking-at "[ \t\n\f]"))
2104 (idlwave-show-begin))))
2106 (defun idlwave-show-begin ()
2107 "Finds the start of current block and blinks to it for a second.
2108 Also checks if the correct end statement has been used."
2109 ;; All end statements are reserved words
2110 ;; Re-indent end line
2111 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2113 (let* ((pos (point-marker))
2114 (last-abbrev-marker (copy-marker last-abbrev-location))
2115 (eol-pos (save-excursion (end-of-line) (point)))
2116 begin-pos end-pos end end1 )
2117 (if idlwave-reindent-end (idlwave-indent-line))
2118 (setq last-abbrev-location (marker-position last-abbrev-marker))
2119 (when (and (idlwave-check-abbrev 0 t)
2122 ;; Move inside current block
2123 (goto-char last-abbrev-marker)
2124 (idlwave-block-jump-out -1 'nomark)
2125 (setq begin-pos (point))
2126 (idlwave-block-jump-out 1 'nomark)
2127 (setq end-pos (point))
2128 (if (> end-pos eol-pos)
2131 (setq end (buffer-substring
2133 (skip-chars-backward "a-zA-Z")
2136 (goto-char begin-pos)
2137 (when (setq end1 (cdr (idlwave-block-master)))
2139 ((null end1)) ; no-operation
2140 ((string= (downcase end) (downcase end1))
2142 ((string= (downcase end) "end")
2144 (if idlwave-expand-generic-end
2148 (insert (if (string= end "END") (upcase end1) end1))
2153 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2158 (defun idlwave-block-master ()
2159 (let ((case-fold-search t))
2162 ((looking-at "pro\\|case\\|switch\\|function\\>")
2163 (assoc (downcase (match-string 0)) idlwave-block-matches))
2164 ((looking-at "begin\\>")
2165 (let ((limit (save-excursion
2166 (idlwave-beginning-of-statement)
2169 ((re-search-backward ":[ \t]*\\=" limit t)
2170 ;; seems to be a case thing
2172 ((re-search-backward idlwave-block-match-regexp limit t)
2173 (assoc (downcase (match-string 1))
2174 idlwave-block-matches))
2176 ;; Just a normal block
2177 '("begin" . "end")))))
2180 (defun idlwave-close-block ()
2181 "Terminate the current block with the correct END statement."
2184 ;; Start new line if we are not in a new line
2185 (unless (save-excursion
2186 (skip-chars-backward " \t")
2188 (let ((idlwave-show-block nil))
2189 (newline-and-indent)))
2190 (let ((last-abbrev-location (point))) ; for upcasing
2192 (idlwave-show-begin)))
2194 (defun idlwave-gtr-pad-hook (char)
2195 "Let the > symbol expand around -> if present. The new token length
2199 (defun idlwave-surround (&optional before after escape-chars length ec-hook)
2200 "Surround the LENGTH characters before point with blanks.
2201 LENGTH defaults to 1.
2202 Optional arguments BEFORE and AFTER affect the behavior before and
2203 after the characters (see also description of `idlwave-make-space'):
2207 integer > 0 force exactly n spaces
2208 integer < 0 at least |n| spaces
2210 The function does nothing if any of the following conditions is true:
2211 - `idlwave-surround-by-blank' is nil
2212 - the character before point is inside a string or comment
2213 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2214 This hack is used to avoid padding of `>' when it is part of
2215 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2217 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2218 the named function will be called with a single argument of the
2219 preceeding character. Then idlwave-surround will run as usual if
2220 EC-HOOK returns non-nil, and a new length will be taken from the
2222 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2223 (let* ((length (or length 1)) ; establish a default for LENGTH
2224 (prev-char (char-after (- (point) (1+ length)))))
2225 (when (or (not (memq prev-char escape-chars))
2226 (and (fboundp ec-hook)
2228 (save-excursion (funcall ec-hook prev-char)))))
2229 (backward-char length)
2231 (let ((here (point)))
2232 (skip-chars-backward " \t")
2234 ;; avoid clobbering indent
2236 (move-to-column (idlwave-calculate-indent))
2237 (if (<= (point) here)
2238 (narrow-to-region (point) here))
2240 (idlwave-make-space before))
2241 (skip-chars-forward " \t"))
2242 (forward-char length)
2243 (idlwave-make-space after)
2244 ;; Check to see if the line should auto wrap
2245 (if (and (equal (char-after (1- (point))) ?\ )
2246 (> (current-column) fill-column))
2247 (funcall auto-fill-function))))))
2249 (defun idlwave-make-space (n)
2250 "Make space at point.
2251 The space affected is all the spaces and tabs around point.
2252 If n is non-nil then point is left abs(n) spaces from the beginning of
2253 the contiguous space.
2254 The amount of space at point is determined by N.
2255 If the value of N is:
2257 > 0 - exactly N spaces.
2258 < 0 - a minimum of -N spaces, i.e., do not change if there are
2260 0 - no spaces (i.e. remove any existing space)."
2263 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2265 (end-col (progn (skip-chars-forward " \t") (current-column))))
2266 (delete-horizontal-space)
2269 (idlwave-indent-to (+ start-col n))
2270 (goto-char (+ left n)))
2272 (idlwave-indent-to end-col (- n))
2273 (goto-char (- left n)))
2277 (defun idlwave-newline ()
2278 "Inserts a newline and indents the current and previous line."
2281 ;; Handle unterminated single and double quotes
2282 ;; If not in a comment and in a string then insertion of a newline
2283 ;; will mean unbalanced quotes.
2285 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2287 (message "Warning: unbalanced quotes?")))
2290 ;; The current line is being split, the cursor should be at the
2291 ;; beginning of the new line skipping the leading indentation.
2293 ;; The reason we insert the new line before indenting is that the
2294 ;; indenting could be confused by keywords (e.g. END) on the line
2295 ;; after the split point. This prevents us from just using
2296 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2298 (beginning-of-line 0)
2299 (idlwave-indent-line)
2301 (idlwave-indent-line))
2304 ;; Use global variable 'comment-column' to set parallel comment
2306 ;; Modeled on lisp.el
2307 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2308 (defun idlwave-comment-hook ()
2309 "Compute indent for the beginning of the IDL comment delimiter."
2310 (if (or (looking-at idlwave-no-change-comment)
2311 (if idlwave-begin-line-comment
2312 (looking-at idlwave-begin-line-comment)
2315 (if (looking-at idlwave-code-comment)
2316 (if (save-excursion (skip-chars-backward " \t") (bolp))
2317 ;; On line by itself, indent as code
2318 (let ((tem (idlwave-calculate-indent)))
2319 (if (listp tem) (car tem) tem))
2320 ;; after code - do not change
2322 (skip-chars-backward " \t")
2323 (max (if (bolp) 0 (1+ (current-column)))
2326 (defun idlwave-split-line ()
2327 "Continue line by breaking line at point and indent the lines.
2328 For a code line insert continuation marker. If the line is a line comment
2329 then the new line will contain a comment with the same indentation.
2330 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2333 ;; Expand abbreviation, just like normal RET would.
2334 (and abbrev-mode (expand-abbrev))
2336 (if (not (idlwave-in-comment))
2337 ;; For code line add continuation.
2338 ;; Check if splitting a string.
2340 (if (setq beg (idlwave-in-quote))
2341 (if idlwave-split-line-string
2342 ;; Split the string.
2343 (progn (insert (setq beg (char-after beg)) " + "
2344 idlwave-continuation-char beg)
2346 (newline-and-indent)
2348 ;; Do not split the string.
2350 (message "Warning: continuation inside string!!")
2351 (insert " " idlwave-continuation-char))
2352 ;; Not splitting a string.
2353 (if (not (member (char-before) '(?\ ?\t)))
2355 (insert idlwave-continuation-char)
2356 (newline-and-indent)))
2357 (indent-new-comment-line))
2358 ;; Indent previous line
2359 (setq beg (- (point-max) (point)))
2361 (idlwave-indent-line)
2362 (goto-char (- (point-max) beg))
2363 ;; Reindent new line
2364 (idlwave-indent-line)))
2366 (defun idlwave-beginning-of-subprogram ()
2367 "Moves point to the beginning of the current program unit."
2369 (idlwave-find-key idlwave-begin-unit-reg -1))
2371 (defun idlwave-end-of-subprogram ()
2372 "Moves point to the start of the next program unit."
2374 (idlwave-end-of-statement)
2375 (idlwave-find-key idlwave-end-unit-reg 1))
2377 (defun idlwave-mark-statement ()
2378 "Mark current IDL statement."
2380 (idlwave-end-of-statement)
2381 (let ((end (point)))
2382 (idlwave-beginning-of-statement)
2383 (idlwave-push-mark end nil t)))
2385 (defun idlwave-mark-block ()
2386 "Mark containing block."
2388 (idlwave-end-of-statement)
2389 (idlwave-backward-up-block -1)
2390 (idlwave-end-of-statement)
2391 (let ((end (point)))
2392 (idlwave-backward-block)
2393 (idlwave-beginning-of-statement)
2394 (idlwave-push-mark end nil t)))
2397 (defun idlwave-mark-subprogram ()
2398 "Put mark at beginning of program, point at end.
2399 The marks are pushed."
2401 (idlwave-end-of-statement)
2402 (idlwave-beginning-of-subprogram)
2403 (let ((beg (point)))
2404 (idlwave-forward-block)
2405 (idlwave-push-mark beg nil t))
2406 (exchange-point-and-mark))
2408 (defun idlwave-backward-up-block (&optional arg)
2409 "Move to beginning of enclosing block if prefix ARG >= 0.
2410 If prefix ARG < 0 then move forward to enclosing block end."
2412 (idlwave-block-jump-out (- arg) 'nomark))
2414 (defun idlwave-beginning-of-block ()
2415 "Go to the beginning of the current block."
2417 (idlwave-block-jump-out -1 'nomark)
2420 (defun idlwave-end-of-block ()
2421 "Go to the beginning of the current block."
2423 (idlwave-block-jump-out 1 'nomark)
2426 (defun idlwave-forward-block ()
2427 "Move across next nested block."
2429 (if (idlwave-down-block 1)
2430 (idlwave-block-jump-out 1 'nomark)))
2432 (defun idlwave-backward-block ()
2433 "Move backward across previous nested block."
2435 (if (idlwave-down-block -1)
2436 (idlwave-block-jump-out -1 'nomark)))
2438 (defun idlwave-down-block (&optional arg)
2440 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2441 Returns non-nil if successfull."
2446 (let ((eos (save-excursion
2447 (idlwave-block-jump-out -1 'nomark)
2449 (if (setq status (idlwave-find-key
2450 idlwave-end-block-reg -1 'nomark eos))
2451 (idlwave-beginning-of-statement)
2452 (message "No nested block before beginning of containing block.")))
2454 (let ((eos (save-excursion
2455 (idlwave-block-jump-out 1 'nomark)
2457 (if (setq status (idlwave-find-key
2458 idlwave-begin-block-reg 1 'nomark eos))
2459 (idlwave-end-of-statement)
2460 (message "No nested block before end of containing block."))))
2463 (defun idlwave-mark-doclib ()
2464 "Put point at beginning of doc library header, mark at end.
2465 The marks are pushed."
2469 (goto-char (point-max))
2470 (if (re-search-backward idlwave-doclib-start nil t)
2472 (setq beg (progn (beginning-of-line) (point)))
2473 (if (re-search-forward idlwave-doclib-end nil t)
2476 (idlwave-push-mark beg nil t)
2477 (message "Could not find end of doc library header.")))
2478 (message "Could not find doc library header start.")
2479 (goto-char here)))))
2482 (defun idlwave-current-routine ()
2483 "Return (NAME TYPE CLASS) of current routine."
2486 (idlwave-beginning-of-subprogram)
2487 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2488 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2490 (class (idlwave-sintern-class (match-string 3)))
2491 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2492 (list name type class)))))
2494 (defvar idlwave-shell-prompt-pattern)
2495 (defun idlwave-beginning-of-statement ()
2496 "Move to beginning of the current statement.
2497 Skips back past statement continuations.
2498 Point is placed at the beginning of the line whether or not this is an
2502 ((eq major-mode 'idlwave-shell-mode)
2503 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2504 (goto-char (match-end 0))))
2506 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2507 (idlwave-previous-statement)
2508 (beginning-of-line)))))
2510 (defun idlwave-previous-statement ()
2511 "Moves point to beginning of the previous statement.
2512 Returns t if the current line before moving is the beginning of
2513 the first non-comment statement in the file, and nil otherwise."
2515 (let (first-statement)
2516 (if (not (= (forward-line -1) 0))
2517 ;; first line in file
2519 ;; skip blank lines, label lines, include lines and line comments
2521 ;; The current statement is the first statement until we
2522 ;; reach another statement.
2523 (setq first-statement
2525 (looking-at idlwave-comment-line-start-skip)
2526 (looking-at "[ \t]*$")
2527 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2529 (= (forward-line -1) 0)))
2530 ;; skip continuation lines
2534 (idlwave-is-continuation-line))
2535 (= (forward-line -1) 0)))
2538 (defun idlwave-end-of-statement ()
2539 "Moves point to the end of the current IDL statement.
2540 If not in a statement just moves to end of line. Returns position."
2542 (while (and (idlwave-is-continuation-line)
2543 (= (forward-line 1) 0))
2544 (while (and (idlwave-is-comment-or-empty-line)
2545 (= (forward-line 1) 0))))
2549 (defun idlwave-end-of-statement0 ()
2550 "Moves point to the end of the current IDL statement.
2551 If not in a statement just moves to end of line. Returns position."
2553 (while (and (idlwave-is-continuation-line)
2554 (= (forward-line 1) 0)))
2558 (defun idlwave-next-statement ()
2559 "Moves point to beginning of the next IDL statement.
2560 Returns t if that statement is the last
2561 non-comment IDL statement in the file, and nil otherwise."
2563 (let (last-statement)
2564 (idlwave-end-of-statement)
2565 ;; skip blank lines, label lines, include lines and line comments
2566 (while (and (= (forward-line 1) 0)
2567 ;; The current statement is the last statement until
2568 ;; we reach a new statement.
2569 (setq last-statement
2571 (looking-at idlwave-comment-line-start-skip)
2572 (looking-at "[ \t]*$")
2573 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2574 (looking-at "^@")))))
2577 (defun idlwave-skip-multi-commands (&optional lim)
2578 "Skip past multiple commands on a line (with `&')."
2579 (let ((save-point (point)))
2580 (when (re-search-forward ".*&" lim t)
2581 (goto-char (match-end 0))
2582 (if (idlwave-quoted)
2583 (goto-char save-point)
2584 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2587 (defun idlwave-skip-label-or-case ()
2588 "Skip label or case statement element.
2589 Returns position after label.
2590 If there is no label point is not moved and nil is returned."
2591 ;; Case expressions and labels are terminated by a colon.
2592 ;; So we find the first colon in the line and make sure
2593 ;; - no `?' is before it (might be a ? b : c)
2594 ;; - it is not in a comment
2595 ;; - not in a string constant
2596 ;; - not in parenthesis (like a[0:3])
2597 ;; - not followed by another ":" in explicit class, ala a->b::c
2598 ;; As many in this mode, this function is heuristic and not an exact
2600 (let* ((start (point))
2601 (eos (save-excursion (idlwave-end-of-statement) (point)))
2602 (end (idlwave-find-key ":" 1 'nomark eos)))
2604 (= (nth 0 (parse-partial-sexp start end)) 0)
2605 (not (string-match "\\?" (buffer-substring start end)))
2606 (not (string-match "^::" (buffer-substring end eos))))
2613 (defun idlwave-start-of-substatement (&optional pre)
2614 "Move to start of next IDL substatement after point.
2615 Uses the type of the current IDL statement to determine if the next
2616 statement is on a new line or is a subpart of the current statement.
2617 Returns point at start of substatement modulo whitespace.
2618 If optional argument is non-nil move to beginning of current
2620 (let ((orig (point))
2621 (eos (idlwave-end-of-statement))
2624 (idlwave-beginning-of-statement)
2625 (idlwave-skip-label-or-case)
2626 (if (< (point) orig)
2627 (idlwave-skip-multi-commands orig))
2629 ;; Continue looking for substatements until we are past orig
2630 (while (and (<= (point) orig) (not (eobp)))
2632 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2633 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2635 (idlwave-find-key nst 1 'nomark eos))
2636 (goto-char (match-end 0)))
2637 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2638 (setq ifnest (1- ifnest))
2639 (goto-char (match-end 0)))
2641 (idlwave-next-statement))))
2642 (if pre (goto-char last))
2643 ;; If a continuation line starts here, move to next line
2644 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2645 (beginning-of-line 2))
2648 (defun idlwave-statement-type ()
2649 "Return the type of the current IDL statement.
2650 Uses `idlwave-statement-match' to return a cons of (type . point) with
2651 point the ending position where the type was determined. Type is the
2652 association from `idlwave-statement-match', i.e. the cons cell from the
2653 list not just the type symbol. Returns nil if not an identifiable
2656 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2657 ;; and possibly comments
2658 (while (looking-at "[ \t]*\\$")
2660 (skip-chars-forward " \t")
2661 (let ((st idlwave-statement-match)
2662 (case-fold-search t))
2663 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2664 (setq st (cdr st))))
2666 (append st (match-end 0))))))
2668 (defun idlwave-expand-equal (&optional before after)
2669 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2670 assignment. Which case is determined using
2671 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2672 equal sign will be surrounded by BEFORE and AFTER blanks. If
2673 `idlwave-pad-keyword' is t then keyword assignment is treated just
2674 like assignment statements. When nil, spaces are removed for keyword
2675 assignment. Any other value keeps the current space around the `='.
2676 Limits in for loops are treated as keyword assignment.
2678 Starting with IDL 6.0, a number of op= assignments are available.
2679 Since ambiguities of the form:
2684 can occur, alphanumeric operator assignment will never be pre-padded,
2685 only post-padded. You must use a space before these to disambiguate
2686 \(not just for padding, but for proper parsing by IDL too!). Other
2687 operators, such as ##=, ^=, etc., will be pre-padded.
2689 See `idlwave-surround'."
2690 (if idlwave-surround-by-blank
2692 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2694 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2698 (let ((case-fold-search t))
2701 (re-search-backward non-an-ops nil t)
2702 ;; Why doesn't ##? work for both?
2703 (re-search-backward "\\(#\\)\\=" nil t))
2704 (setq len (1+ (length (match-string 1))))
2705 (when (re-search-backward an-ops nil t)
2706 ;(setq begin nil) ; won't modify begin
2707 (setq len (1+ (length (match-string 1))))))))
2709 (if (eq t idlwave-pad-keyword)
2710 ;; Everything gets padded equally
2711 (idlwave-surround before after nil len)
2712 ;; Treating keywords/for variables specially...
2713 (let ((st (save-excursion ; To catch "for" variables
2714 (idlwave-start-of-substatement t)
2715 (idlwave-statement-type)))
2716 (what (save-excursion ; To catch keywords
2717 (skip-chars-backward "= \t")
2718 (nth 2 (idlwave-where)))))
2719 (cond ((or (memq what '(function-keyword procedure-keyword))
2720 (memq (caar st) '(for pdef)))
2722 ((null idlwave-pad-keyword)
2723 (idlwave-surround 0 0)
2725 (t))) ; leave any spaces alone
2726 (t (idlwave-surround before after nil len))))))))
2729 (defun idlwave-indent-and-action (&optional arg)
2730 "Call `idlwave-indent-line' and do expand actions.
2731 With prefix ARG non-nil, indent the entire sub-statement."
2734 (if (and idlwave-expand-generic-end
2735 (re-search-backward "\\<\\(end\\)\\s-*\\="
2736 (max 0 (- (point) 10)) t)
2737 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2738 (progn (goto-char (match-end 1))
2739 ;;Expand the END abbreviation, just as RET or Space would have.
2740 (if abbrev-mode (expand-abbrev)
2741 (idlwave-show-begin)))))
2742 (when (and (not arg) current-prefix-arg)
2743 (setq arg current-prefix-arg)
2744 (setq current-prefix-arg nil))
2746 (idlwave-indent-statement)
2747 (idlwave-indent-line t)))
2749 (defun idlwave-indent-line (&optional expand)
2750 "Indents current IDL line as code or as a comment.
2751 The actions in `idlwave-indent-action-table' are performed.
2752 If the optional argument EXPAND is non-nil then the actions in
2753 `idlwave-indent-expand-table' are performed."
2755 ;; Move point out of left margin.
2757 (skip-chars-backward " \t")
2759 (skip-chars-forward " \t"))
2760 (let ((mloc (point-marker)))
2763 (if (looking-at idlwave-comment-line-start-skip)
2764 ;; Indentation for a line comment
2766 (skip-chars-forward " \t")
2767 (idlwave-indent-left-margin (idlwave-comment-hook)))
2771 ;; Before indenting, run action routines.
2773 (if (and expand idlwave-do-actions)
2774 (mapcar 'idlwave-do-action idlwave-indent-expand-table))
2776 (if idlwave-do-actions
2777 (mapcar 'idlwave-do-action idlwave-indent-action-table))
2779 ;; No longer expand abbrevs on the line. The user can do this
2780 ;; manually using expand-region-abbrevs.
2782 ;; Indent for code line
2787 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2789 (looking-at "^[ \t]*@"))
2793 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2794 ;; Adjust parallel comment
2796 (if (idlwave-in-comment)
2797 ;; Emacs 21 is too smart with fill-column on comment indent
2798 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2801 (indent-for-comment)))))
2803 ;; Get rid of marker
2804 (set-marker mloc nil)))
2806 (defun idlwave-do-action (action)
2807 "Perform an action repeatedly on a line.
2808 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2809 either a function name to be called with `funcall' or a list to be
2810 evaluated with `eval'. The action performed by FUNC should leave point
2811 after the match for REG - otherwise an infinite loop may be entered."
2812 (let ((action-key (car action))
2813 (action-routine (cdr action)))
2815 (while (idlwave-look-at action-key)
2816 (if (listp action-routine)
2817 (eval action-routine)
2818 (funcall action-routine)))))
2820 (defun idlwave-indent-to (col &optional min)
2821 "Indent from point with spaces until column COL.
2822 Inserts space before markers at point."
2823 (if (not min) (setq min 0))
2824 (insert-before-markers
2825 (make-string (max min (- col (current-column))) ?\ )))
2827 (defun idlwave-indent-left-margin (col)
2828 "Indent the current line to column COL.
2829 Indents such that first non-whitespace character is at column COL
2830 Inserts spaces before markers at point."
2833 (delete-horizontal-space)
2834 (idlwave-indent-to col)))
2836 (defun idlwave-indent-subprogram ()
2837 "Indents program unit which contains point."
2840 (idlwave-end-of-statement)
2841 (idlwave-beginning-of-subprogram)
2842 (let ((beg (point)))
2843 (idlwave-forward-block)
2844 (message "Indenting subprogram...")
2845 (indent-region beg (point) nil))
2846 (message "Indenting subprogram...done.")))
2848 (defun idlwave-indent-statement ()
2849 "Indent current statement, including all continuation lines."
2852 (idlwave-beginning-of-statement)
2853 (let ((beg (point)))
2854 (idlwave-end-of-statement)
2855 (indent-region beg (point) nil))))
2857 (defun idlwave-calculate-indent ()
2858 "Return appropriate indentation for current line as IDL code."
2862 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2864 ((idlwave-look-at idlwave-begin-unit-reg)
2866 ;; Check for continuation line
2868 (and (= (forward-line -1) 0)
2869 (idlwave-is-continuation-line)))
2870 (idlwave-calculate-cont-indent))
2871 ;; calculate indent based on previous and current statements
2872 (t (let* (beg-prev-pos
2874 ;; calculate indent based on previous statement
2877 ;; Beginning of file
2879 (idlwave-previous-statement)
2880 (setq beg-prev-pos (point)))
2883 ((idlwave-look-at idlwave-begin-unit-reg t)
2884 (+ (idlwave-current-statement-indent)
2885 idlwave-main-block-indent))
2887 ((idlwave-look-at idlwave-begin-block-reg t)
2888 (+ (idlwave-min-current-statement-indent)
2889 idlwave-block-indent))
2891 ((idlwave-look-at idlwave-end-block-reg t)
2893 ;; Match to the *beginning* of the block opener
2894 (goto-char beg-prev-pos)
2895 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2896 (idlwave-min-current-statement-indent)))
2897 ;; idlwave-end-offset
2898 ;; idlwave-block-indent))
2900 ;; Default to current indent
2901 ((idlwave-current-statement-indent))))))
2902 ;; adjust the indentation based on the current statement
2905 ((idlwave-look-at idlwave-end-block-reg)
2906 (+ the-indent idlwave-end-offset))
2910 ;; Parentheses indent
2913 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2914 "Calculate the continuation indent inside a paren group.
2915 Returns a cons-cell with (open . indent), where open is the
2916 location of the open paren"
2917 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2918 ;; Found an innermost open paren.
2921 ;; Line up with next word unless this is a closing paren.
2924 ;; Plain Kernighan-style nested indent
2925 (idlwave-indent-parens-nested
2926 (+ idlwave-continuation-indent (idlwave-current-indent)))
2928 ;; This is a closed paren - line up under open paren.
2932 ;; Empty (or just comment) follows -- revert to basic indent
2936 (looking-at "[ \t$]*\\(;.*\\)?$"))
2939 ;; Line up with first word after any blank space
2941 (skip-chars-forward " \t")
2942 (current-column))))))))
2944 (defun idlwave-calculate-cont-indent ()
2945 "Calculates the IDL continuation indent column from the previous
2946 statement. Note that here previous statement usually means the
2947 beginning of the current statement if this statement is a continuation
2948 of the previous line. Various special types of continuations,
2949 including assignments, routine definitions, and parenthetical
2950 groupings, are treated separately."
2952 (let* ((case-fold-search t)
2953 (end-reg (progn (beginning-of-line) (point)))
2954 (beg-last-statement (save-excursion (idlwave-previous-statement)
2956 (beg-reg (progn (idlwave-start-of-substatement 'pre)
2957 (if (eq (line-beginning-position) end-reg)
2958 (goto-char beg-last-statement)
2960 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
2961 idlwave-continuation-indent))
2962 fancy-nonparen-indent fancy-paren-indent)
2964 ;; Align then with its matching if, etc.
2965 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
2966 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
2967 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
2968 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2970 ("\\<case\\>" . "[ \t]*of")))
2976 (while (setq match (car matchers))
2977 (if (looking-at (cdr match))
2978 (throw 'exit (car match)))
2979 (setq matchers (cdr matchers)))))
2980 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
2981 (if (looking-at "end") ;; that one's special
2982 (- (idlwave-current-indent)
2983 (+ idlwave-block-indent idlwave-end-offset))
2984 (idlwave-current-indent)))
2986 ;; Indent in from the previous line for continuing statements
2987 ((let ((matchers '("\\<then\\>"
2994 (if (/= (forward-line -1) 0)
2996 (while (setq match (car matchers))
2997 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3000 (setq matchers (cdr matchers)))))
3001 (+ idlwave-continuation-indent (idlwave-current-indent)))
3003 ;; Parenthetical indent, either traditional or Kernighan style
3004 ((setq fancy-paren-indent
3005 (let* ((end-reg end-reg)
3008 (skip-chars-forward " \t")
3009 (looking-at "\\s)")))
3012 (while (setq indent-cons (idlwave-calculate-paren-indent
3013 beg-reg end-reg close-exp))
3014 ;; First permitted containing paren
3016 idlwave-indent-to-open-paren
3017 idlwave-indent-parens-nested
3018 (null (cdr indent-cons))
3019 (< (- (cdr indent-cons) basic-indent)
3020 idlwave-max-extra-continuation-indent))
3021 (throw 'loop (cdr indent-cons)))
3022 (setq end-reg (car indent-cons))))))
3025 ;; A continued assignment, or procedure call/definition
3027 (> idlwave-max-extra-continuation-indent 0)
3028 (setq fancy-nonparen-indent
3031 (while (idlwave-look-at "&")) ; skip continued statements
3033 ;; A continued Procedure call or definition
3035 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3036 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3037 (goto-char (match-end 0))
3038 ;; Comment only, or blank line with "$"? Basic indent.
3039 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3043 ;; Continued assignment (with =):
3045 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3046 (goto-char (match-end 0))
3047 (if (null (idlwave-what-function beg-reg))
3048 (throw 'assign t))))
3051 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3053 (goto-char beg-last-statement)
3054 (eq (caar (idlwave-statement-type)) 'for)))
3055 (current-column))))))
3056 (< (- fancy-nonparen-indent basic-indent)
3057 idlwave-max-extra-continuation-indent))
3058 (if fancy-paren-indent ;calculated but disallowed paren indent
3059 (+ fancy-nonparen-indent idlwave-continuation-indent)
3060 fancy-nonparen-indent))
3062 ;; Basic indent, by default
3063 (t basic-indent)))))
3067 (defun idlwave-find-key (key-re &optional dir nomark limit)
3068 "Move to next match of the regular expression KEY-RE.
3069 Matches inside comments or string constants will be ignored.
3070 If DIR is negative, the search will be backwards.
3071 At a successful match, the mark is pushed unless NOMARK is non-nil.
3072 Searches are limited to LIMIT.
3073 Searches are case-insensitive and use a special syntax table which
3074 treats `$' and `_' as word characters.
3075 Return value is the beginning of the match or (in case of failure) nil."
3076 (setq dir (or dir 0))
3077 (let ((case-fold-search t)
3078 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3080 (idlwave-with-special-syntax
3083 (while (funcall search-func key-re limit t)
3084 (if (not (idlwave-quoted))
3085 (throw 'exit (setq found (match-beginning 0)))
3086 (if (or (and (> dir 0) (eobp))
3087 (and (< dir 0) (bobp)))
3088 (throw 'exit nil)))))))
3091 (if (not nomark) (push-mark))
3096 (defun idlwave-block-jump-out (&optional dir nomark)
3097 "When optional argument DIR is non-negative, move forward to end of
3098 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3099 regular expressions. When DIR is negative, move backwards to block beginning.
3100 Recursively calls itself to skip over nested blocks. DIR defaults to
3101 forward. Calls `push-mark' unless the optional argument NOMARK is
3102 non-nil. Movement is limited by the start of program units because of
3103 possibility of unbalanced blocks."
3105 (or dir (setq dir 0))
3106 (let* ((here (point))
3107 (case-fold-search t)
3108 (limit (if (>= dir 0) (point-max) (point-min)))
3109 (block-limit (if (>= dir 0)
3110 idlwave-begin-block-reg
3111 idlwave-end-block-reg))
3113 (block-reg (concat idlwave-begin-block-reg "\\|"
3114 idlwave-end-block-reg))
3115 (unit-limit (or (save-excursion
3118 idlwave-begin-unit-reg dir t limit)
3121 idlwave-end-unit-reg dir t limit)))
3123 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3124 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3125 (while (and found (looking-at block-limit))
3126 (if (>= dir 0) (forward-word 1))
3127 (idlwave-block-jump-out dir t)
3128 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3129 (if (not nomark) (push-mark here))
3130 (if (not found) (goto-char unit-limit)
3131 (if (>= dir 0) (forward-word 1)))))
3133 (defun idlwave-min-current-statement-indent (&optional end-reg)
3134 "The minimum indent in the current statement."
3135 (idlwave-beginning-of-statement)
3136 (if (not (idlwave-is-continuation-line))
3137 (idlwave-current-indent)
3138 (let ((min (idlwave-current-indent)) comm-or-empty)
3139 (while (and (= (forward-line 1) 0)
3140 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3141 (idlwave-is-continuation-line))
3142 (or (null end-reg) (< (point) end-reg)))
3143 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3144 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3146 (min min (idlwave-current-indent))))))
3148 (defun idlwave-current-statement-indent (&optional last-line)
3149 "Return indentation of the current statement.
3150 If in a statement, moves to beginning of statement before finding indent."
3152 (idlwave-end-of-statement)
3153 (idlwave-beginning-of-statement))
3154 (idlwave-current-indent))
3156 (defun idlwave-current-indent ()
3157 "Return the column of the indentation of the current line.
3158 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3161 (skip-chars-forward " \t")
3162 ;; if we are at the end of blank line return 0
3164 ((current-column)))))
3166 (defun idlwave-is-continuation-line ()
3167 "Tests if current line is continuation line.
3168 Blank or comment-only lines following regular continuation lines (with
3169 `$') count as continuations too."
3172 (idlwave-look-at "\\<\\$")
3174 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3175 (eq (forward-line -1) 0))
3176 (if (idlwave-look-at "\\<\\$") (throw 'loop t)))))))
3178 (defun idlwave-is-comment-line ()
3179 "Tests if the current line is a comment line."
3181 (beginning-of-line 1)
3182 (looking-at "[ \t]*;")))
3184 (defun idlwave-is-comment-or-empty-line ()
3185 "Tests if the current line is a comment line."
3187 (beginning-of-line 1)
3188 (looking-at "[ \t]*[;\n]")))
3190 (defun idlwave-look-at (regexp &optional cont beg)
3191 "Searches current line from current point for REGEXP.
3192 If optional argument CONT is non-nil, searches to the end of
3193 the current statement.
3194 If optional arg BEG is non-nil, search starts from the beginning of the
3196 Ignores matches that end in a comment or inside a string expression.
3197 Returns point if successful, nil otherwise.
3198 This function produces unexpected results if REGEXP contains quotes or
3199 a comment delimiter. The search is case insensitive.
3200 If successful leaves point after the match, otherwise, does not move point."
3201 (let ((here (point))
3202 (case-fold-search t)
3203 (eos (save-excursion
3204 (if cont (idlwave-end-of-statement) (end-of-line))
3207 (idlwave-with-special-syntax
3208 (if beg (idlwave-beginning-of-statement))
3209 (while (and (setq found (re-search-forward regexp eos t))
3211 (if (not found) (goto-char here))
3214 (defun idlwave-fill-paragraph (&optional nohang)
3215 "Fills paragraphs in comments.
3216 A paragraph is made up of all contiguous lines having the same comment
3217 leader (the leading whitespace before the comment delimiter and the
3218 comment delimiter). In addition, paragraphs are separated by blank
3219 line comments. The indentation is given by the hanging indent of the
3220 first line, otherwise by the minimum indentation of the lines after
3221 the first line. The indentation of the first line does not change.
3222 Does not effect code lines. Does not fill comments on the same line
3223 with code. The hanging indent is given by the end of the first match
3224 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3225 optional argument NOHANG is non-nil then the hanging indent is
3228 ;; check if this is a line comment
3231 (skip-chars-forward " \t")
3232 (looking-at comment-start))
3235 pre here diff fill-prefix-reg bcl first-indent
3237 ;; Change tabs to spaces in the surrounding paragraph.
3238 ;; The surrounding paragraph will be the largest containing block of
3239 ;; contiguous line comments. Thus, we may be changing tabs in
3240 ;; a much larger area than is needed, but this is the easiest
3241 ;; brute force way to do it.
3243 ;; This has the undesirable side effect of replacing the tabs
3244 ;; permanently without the user's request or knowledge.
3246 (backward-paragraph)
3247 (setq start (point)))
3251 (untabify start end)
3257 (concat "^[ \t]*" comment-start "+")
3258 (save-excursion (end-of-line) (point))
3260 ;; Get the comment leader on the line and its length
3261 (setq pre (current-column))
3262 ;; the comment leader is the indentation plus exactly the
3263 ;; number of consecutive ";".
3264 (setq fill-prefix-reg
3268 (buffer-substring (save-excursion
3269 (beginning-of-line) (point))
3273 ;; Mark the beginning and end of the paragraph
3275 (while (and (looking-at fill-prefix-reg)
3276 (not (looking-at paragraph-separate))
3279 ;; Move to first line of paragraph
3280 (if (/= (point) bcl)
3282 (setq start (point))
3284 (while (and (looking-at fill-prefix-reg)
3285 (not (looking-at paragraph-separate))
3289 (if (or (not (looking-at fill-prefix-reg))
3290 (looking-at paragraph-separate))
3293 ;; if at end of buffer add a newline (need this because
3294 ;; fill-region needs END to be at the beginning of line after
3295 ;; the paragraph or it will add a line).
3297 (progn (insert ?\n) (backward-char 1)))
3298 ;; Set END to the beginning of line after the paragraph
3299 ;; END is calculated as distance from end of buffer
3300 (setq end (- (point-max) (point) 1))
3302 ;; Calculate the indentation for the paragraph.
3304 ;; In the following while statements, after one iteration
3305 ;; point will be at the beginning of a line in which case
3306 ;; the while will not be executed for the
3307 ;; the first paragraph line and thus will not affect the
3310 ;; First check to see if indentation is based on hanging indent.
3311 (if (and (not nohang) idlwave-hanging-indent
3315 (idlwave-calc-hanging-indent))))
3316 ;; Adjust lines of paragraph by inserting spaces so that
3317 ;; each line's indent is at least as great as the hanging
3318 ;; indent. This is needed for fill-paragraph to work with
3323 (while (> (point) start)
3324 (re-search-forward comment-start-skip
3325 (save-excursion (end-of-line) (point))
3327 (if (> (setq diff (- indent (current-column))) 0)
3329 (if (>= here (point))
3330 ;; adjust the original location for the
3332 (setq here (+ here diff)))
3333 (insert (make-string diff ?\ ))))
3337 ;; No hang. Instead find minimum indentation of paragraph
3338 ;; after first line.
3339 ;; For the following while statement, since START is at the
3340 ;; beginning of line and END is at the end of line
3341 ;; point is greater than START at least once (which would
3342 ;; be the case for a single line paragraph).
3343 (while (> (point) start)
3350 (save-excursion (end-of-line) (point))
3355 (setq fill-prefix (concat fill-prefix
3356 (make-string (- indent pre)
3358 ;; first-line indent
3364 (save-excursion (end-of-line) (point))
3369 ;; try to keep point at its original place
3372 ;; In place of the more modern fill-region-as-paragraph, a hack
3373 ;; to keep whitespace untouched on the first line within the
3374 ;; indent length and to preserve any indent on the first line
3378 (buffer-substring start (+ start first-indent -1)))
3379 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3380 (fill-region-as-paragraph
3383 (current-justification)
3385 (delete-region start (+ start first-indent -1))
3388 ;; When we want the point at the beginning of the comment
3389 ;; body fill-region will put it at the beginning of the line.
3390 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3391 (setq fill-prefix nil))))
3393 (defun idlwave-calc-hanging-indent ()
3394 "Calculate the position of the hanging indent for the comment
3395 paragraph. The hanging indent position is given by the first match
3396 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3397 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3399 If not found returns nil."
3400 (if idlwave-use-last-hang-indent
3403 (if (re-search-backward
3404 idlwave-hang-indent-regexp
3405 (save-excursion (beginning-of-line) (point))
3407 (+ (current-column) (length idlwave-hang-indent-regexp))))
3410 (if (re-search-forward
3411 idlwave-hang-indent-regexp
3412 (save-excursion (end-of-line) (point))
3414 (current-column)))))
3416 (defun idlwave-auto-fill ()
3417 "Called to break lines in auto fill mode.
3418 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3419 non-nil. Places a continuation character at the end of the line if
3420 not in a comment. Splits strings with IDL concatenation operator `+'
3421 if `idlwave-auto-fill-split-string' is non-nil."
3422 (if (<= (current-column) fill-column)
3423 nil ; do not to fill
3424 (if (or (not idlwave-fill-comment-line-only)
3426 ;; Check for comment line
3428 (looking-at idlwave-comment-line-start-skip)))
3430 (idlwave-indent-line)
3431 ;; Prevent actions do-auto-fill which calls indent-line-function.
3432 (let (idlwave-do-actions
3433 (paragraph-start ".")
3434 (paragraph-separate ".")
3435 (fill-nobreak-predicate
3436 (if (and (idlwave-in-quote)
3437 idlwave-auto-fill-split-string)
3438 (lambda () ;; We'll need 5 spaces for " ' + $"
3439 (<= (- fill-column (current-column)) 5)
3444 ;; Indent the split line
3445 (idlwave-indent-line)
3449 (looking-at idlwave-comment-line-start-skip))
3450 ;; A continued line comment
3451 ;; We treat continued line comments as part of a comment
3452 ;; paragraph. So we check for a hanging indent.
3453 (if idlwave-hanging-indent
3454 (let ((here (- (point-max) (point)))
3458 (idlwave-calc-hanging-indent))))
3461 ;; Remove whitespace between comment delimiter and
3462 ;; text, insert spaces for appropriate indentation.
3466 (save-excursion (end-of-line) (point)) t)
3467 (delete-horizontal-space)
3468 (idlwave-indent-to indent)
3469 (goto-char (- (point-max) here)))
3471 ;; Split code or comment?
3474 (idlwave-in-comment))
3475 ;; Splitting a non-full-line comment.
3476 ;; Insert the comment delimiter from split line
3480 (skip-chars-forward " \t")
3481 ;; Insert blank to keep off beginning of line
3485 (buffer-substring (idlwave-goto-comment)
3487 (skip-chars-forward "; ")
3489 (idlwave-indent-line))
3490 ;; Split code line - add continuation character
3493 ;; Check to see if we split a string
3494 (if (and (setq beg (idlwave-in-quote))
3495 idlwave-auto-fill-split-string)
3496 ;; Split the string and concatenate.
3497 ;; The first extra space is for the space
3498 ;; the line was split. That space was removed.
3499 (insert " " (char-after beg) " +"))
3502 (if idlwave-auto-fill-split-string
3503 ;; Make the second part of continued string
3506 (skip-chars-forward " \t")
3507 (insert (char-after beg)))
3510 (message "Warning: continuation inside a string.")))
3511 ;; Although do-auto-fill (via indent-new-comment-line) calls
3512 ;; idlwave-indent-line for the new line, re-indent again
3513 ;; because of the addition of the continuation character.
3514 (idlwave-indent-line))
3517 (defun idlwave-auto-fill-mode (arg)
3518 "Toggle auto-fill mode for IDL mode.
3519 With arg, turn auto-fill mode on if arg is positive.
3520 In auto-fill mode, inserting a space at a column beyond `fill-column'
3521 automatically breaks the line at a previous space."
3523 (prog1 (set idlwave-fill-function
3525 (not (symbol-value idlwave-fill-function))
3526 (> (prefix-numeric-value arg) 0))
3530 (set-buffer-modified-p (buffer-modified-p))))
3532 ;(defun idlwave-fill-routine-call ()
3533 ; "Fill a routine definition or statement, indenting appropriately."
3534 ; (let ((where (idlwave-where)))))
3537 (defun idlwave-doc-header (&optional nomark )
3538 "Insert a documentation header at the beginning of the unit.
3539 Inserts the value of the variable idlwave-file-header. Sets mark before
3540 moving to do insertion unless the optional prefix argument NOMARK
3543 (or nomark (push-mark))
3544 ;; make sure we catch the current line if it begins the unit
3545 (if idlwave-header-to-beginning-of-file
3546 (goto-char (point-min))
3548 (idlwave-beginning-of-subprogram)
3550 ;; skip function or procedure line
3551 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3553 (idlwave-end-of-statement)
3554 (if (> (forward-line 1) 0) (insert "\n")))))
3555 (let ((pos (point)))
3556 (if idlwave-file-header
3557 (cond ((car idlwave-file-header)
3558 (insert-file-contents (car idlwave-file-header)))
3559 ((stringp (car (cdr idlwave-file-header)))
3560 (insert (car (cdr idlwave-file-header))))))
3563 (defun idlwave-default-insert-timestamp ()
3564 "Default timestamp insertion function"
3565 (insert (current-time-string))
3566 (insert ", " (user-full-name))
3567 (if (boundp 'user-mail-address)
3568 (insert " <" user-mail-address ">")
3569 (insert " <" (user-login-name) "@" (system-name) ">"))
3570 ;; Remove extra spaces from line
3571 (idlwave-fill-paragraph)
3572 ;; Insert a blank line comment to separate from the date entry -
3573 ;; will keep the entry from flowing onto date line if re-filled.
3574 (insert "\n;\n;\t\t"))
3576 (defun idlwave-doc-modification ()
3577 "Insert a brief modification log at the beginning of the current program.
3578 Looks for an occurrence of the value of user variable
3579 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3580 and places the point for the user to add a log. Before moving, saves
3581 location on mark ring so that the user can return to previous point."
3585 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3587 (goto-char (point-min))
3588 (re-search-forward idlwave-doclib-start nil t)))
3589 (setq beg (match-beginning 0))
3590 (re-search-forward idlwave-doclib-end nil t)
3591 (setq end (match-end 0)))
3594 (if (re-search-forward
3595 (concat idlwave-doc-modifications-keyword ":")
3600 (insert "\n" comment-start "\n")
3601 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3603 (run-hooks 'idlwave-timestamp-hook))
3604 (error "No valid DOCLIB header"))))
3607 ;;; Interface to expand-region-abbrevs which did not work when the
3608 ;;; abbrev hook associated with an abbrev moves point backwards
3609 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3610 ;;; The original would enter an infinite loop in attempting to expand
3611 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3612 ;;; because the point would keep going back to the beginning of the
3613 ;;; abbrev instead of to the end of the abbrev). We now keep the
3614 ;;; abbrev hook from moving backwards.
3616 (defun idlwave-expand-region-abbrevs (start end)
3617 "Expand each abbrev occurrence in the region.
3618 Calling from a program, arguments are START END."
3621 (goto-char (min start end))
3622 (let ((idlwave-show-block nil) ;Do not blink
3623 (idlwave-abbrev-move nil)) ;Do not move
3624 (expand-region-abbrevs start end 'noquery))))
3626 (defun idlwave-quoted ()
3627 "Returns t if point is in a comment or quoted string.
3629 (or (idlwave-in-comment) (idlwave-in-quote)))
3631 (defun idlwave-in-quote ()
3632 "Returns location of the opening quote
3633 if point is in a IDL string constant, nil otherwise.
3634 Ignores comment delimiters on the current line.
3635 Properly handles nested quotation marks and octal
3636 constants - a double quote followed by an octal digit."
3637 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3638 ;;; double quote followed by an octal digit to be an octal constant
3639 ;;; rather than a string. Therefore, there is no terminating double
3642 ;; Because single and double quotes can quote each other we must
3643 ;; search for the string start from the beginning of line.
3644 (let* ((start (point))
3645 (eol (progn (end-of-line) (point)))
3646 (bq (progn (beginning-of-line) (point)))
3651 (while (< endq start)
3652 ;; Find string start
3653 ;; Don't find an octal constant beginning with a double quote
3654 (if (re-search-forward "[\"']" eol 'lim)
3655 ;; Find the string end.
3656 ;; In IDL, two consecutive delimiters after the start of a
3658 ;; escape for the delimiter in the string.
3659 ;; Two consecutive delimiters alone (i.e., not after the
3660 ;; start of a string) is the null string.
3662 ;; Move to position after quote
3663 (goto-char (1+ (match-beginning 0)))
3664 (setq bq (1- (point)))
3665 ;; Get the string delimiter
3666 (setq delim (char-to-string (preceding-char)))
3667 ;; Check for null string
3668 (if (looking-at delim)
3669 (progn (setq endq (point)) (forward-char 1))
3670 ;; Look for next unpaired delimiter
3671 (setq found (search-forward delim eol 'lim))
3672 (while (looking-at delim)
3674 (setq found (search-forward delim eol 'lim)))
3676 (setq endq (- (point) 1))
3677 (setq endq (point)))
3679 (progn (setq bq (point)) (setq endq (point)))))
3680 (store-match-data data)
3681 ;; return string beginning position or nil
3682 (if (> start bq) bq))))
3684 (defun idlwave-is-pointer-dereference (&optional limit)
3685 "Determines if the character after point is a pointer dereference *."
3686 (let ((pos (point)))
3688 (eq (char-after) ?\*)
3689 (not (idlwave-in-quote))
3692 (re-search-backward (concat "\\(" idlwave-idl-keywords
3693 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t)))))
3696 ;; Statement templates
3698 ;; Replace these with a general template function, something like
3699 ;; expand.el (I think there was also something with a name similar to
3702 (defun idlwave-template (s1 s2 &optional prompt noindent)
3703 "Build a template with optional prompt expression.
3705 Opens a line if point is not followed by a newline modulo intervening
3706 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3707 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3708 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3709 PROMPT is a string then it is displayed as a message in the
3710 minibuffer. The PROMPT serves as a reminder to the user of an
3711 expression to enter.
3713 The lines containing S1 and S2 are reindented using `indent-region'
3714 unless the optional second argument NOINDENT is non-nil."
3715 (if (eq major-mode 'idlwave-shell-mode)
3716 ;; This is a gross hack to avoit template abbrev expansion
3717 ;; in the shell. FIXME: This is a dirty hack.
3718 (if (and (eq this-command 'self-insert-command)
3719 (equal last-abbrev-location (point)))
3720 (insert last-abbrev-text)
3721 (error "No templates in idlwave-shell"))
3722 (cond ((eq idlwave-abbrev-change-case 'down)
3723 (setq s1 (downcase s1) s2 (downcase s2)))
3724 (idlwave-abbrev-change-case
3725 (setq s1 (upcase s1) s2 (upcase s2))))
3726 (let ((beg (save-excursion (beginning-of-line) (point)))
3728 (if (not (looking-at "\\s-*\n"))
3735 (indent-region beg end nil))
3736 (if (stringp prompt)
3737 (message prompt)))))
3739 (defun idlwave-rw-case (string)
3740 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3741 (if idlwave-reserved-word-upcase
3745 (defun idlwave-elif ()
3746 "Build skeleton IDL if-else block."
3749 (idlwave-rw-case "if")
3750 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3751 "Condition expression"))
3753 (defun idlwave-case ()
3754 "Build skeleton IDL case statement."
3757 (idlwave-rw-case "case")
3758 (idlwave-rw-case " of\n\nendcase")
3759 "Selector expression"))
3761 (defun idlwave-switch ()
3762 "Build skeleton IDL switch statement."
3765 (idlwave-rw-case "switch")
3766 (idlwave-rw-case " of\n\nendswitch")
3767 "Selector expression"))
3769 (defun idlwave-for ()
3770 "Build skeleton for loop statment."
3773 (idlwave-rw-case "for")
3774 (idlwave-rw-case " do begin\n\nendfor")
3777 (defun idlwave-if ()
3778 "Build skeleton for loop statment."
3781 (idlwave-rw-case "if")
3782 (idlwave-rw-case " then begin\n\nendif")
3783 "Scalar logical expression"))
3785 (defun idlwave-procedure ()
3788 (idlwave-rw-case "pro")
3789 (idlwave-rw-case "\n\nreturn\nend")
3792 (defun idlwave-function ()
3795 (idlwave-rw-case "function")
3796 (idlwave-rw-case "\n\nreturn\nend")
3799 (defun idlwave-repeat ()
3802 (idlwave-rw-case "repeat begin\n\nendrep until")
3803 (idlwave-rw-case "")
3806 (defun idlwave-while ()
3809 (idlwave-rw-case "while")
3810 (idlwave-rw-case " do begin\n\nendwhile")
3813 (defun idlwave-split-string (string &optional pattern)
3814 "Return a list of substrings of STRING which are separated by PATTERN.
3815 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3817 (setq pattern "[ \f\t\n\r\v]+"))
3818 (let (parts (start 0))
3819 (while (string-match pattern string start)
3820 (setq parts (cons (substring string start (match-beginning 0)) parts)
3821 start (match-end 0)))
3822 (nreverse (cons (substring string start) parts))))
3824 (defun idlwave-replace-string (string replace_string replace_with)
3826 (last (length string))
3829 (while (setq end (string-match replace_string string start))
3831 (concat ret_string (substring string start end) replace_with))
3832 (setq start (match-end 0)))
3833 (setq ret_string (concat ret_string (substring string start last)))))
3835 (defun idlwave-get-buffer-visiting (file)
3836 ;; Return the buffer currently visiting FILE
3838 ((boundp 'find-file-compare-truenames) ; XEmacs
3839 (let ((find-file-compare-truenames t))
3840 (get-file-buffer file)))
3841 ((fboundp 'find-buffer-visiting) ; Emacs
3842 (find-buffer-visiting file))
3843 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3845 (defvar idlwave-outlawed-buffers nil
3846 "List of buffer pulled up by idlwave for special reasons.
3847 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3849 (defun idlwave-find-file-noselect (file &optional why)
3850 ;; Return a buffer visiting file.
3851 (or (idlwave-get-buffer-visiting file)
3852 (let ((buf (find-file-noselect file)))
3853 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3856 (defun idlwave-kill-autoloaded-buffers ()
3857 "Kill buffers created automatically by IDLWAVE.
3858 Function prompts for a letter to identify the buffers to kill.
3859 Possible letters are:
3861 f Buffers created by the command \\[idlwave-find-module] or mouse
3862 clicks in the routine info window.
3863 s Buffers created by the IDLWAVE Shell to display where execution
3864 stopped or an error was found.
3865 a Both of the above.
3867 Buffer containing unsaved changes require confirmation before they are killed."
3869 (if (null idlwave-outlawed-buffers)
3870 (error "No IDLWAVE-created buffers available")
3871 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3872 (idlwave-count-outlawed-buffers 'find)
3873 (idlwave-count-outlawed-buffers 'shell)))
3874 (let ((c (read-char)))
3876 ((member c '(?f ?\C-f))
3877 (idlwave-do-kill-autoloaded-buffers 'find))
3878 ((member c '(?s ?\C-s))
3879 (idlwave-do-kill-autoloaded-buffers 'shell))
3880 ((member c '(?a ?\C-a))
3881 (idlwave-do-kill-autoloaded-buffers t))
3882 (t (error "Abort"))))))
3884 (defun idlwave-count-outlawed-buffers (tag)
3885 "How many outlawed buffers have tag TAG?"
3888 (lambda (x) (eq (cdr x) tag))
3889 idlwave-outlawed-buffers))))
3891 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3892 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3893 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3896 (while (setq entry (pop list))
3897 (if (buffer-live-p (car entry))
3898 (and (or (memq t reasons)
3899 (memq (cdr entry) reasons))
3900 (kill-buffer (car entry))
3902 (setq idlwave-outlawed-buffers
3903 (delq entry idlwave-outlawed-buffers)))
3904 (setq idlwave-outlawed-buffers
3905 (delq entry idlwave-outlawed-buffers))))
3906 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3908 (defun idlwave-revoke-license-to-kill ()
3909 "Remove BUFFER from the buffers which may be killed.
3910 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3911 Intended for `after-save-hook'."
3912 (let* ((buf (current-buffer))
3913 (entry (assq buf idlwave-outlawed-buffers)))
3916 (setq idlwave-outlawed-buffers
3917 (delq entry idlwave-outlawed-buffers)))
3918 ;; Remove this function from the hook.
3919 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3921 (defvar idlwave-path-alist)
3922 (defun idlwave-locate-lib-file (file)
3923 ;; Find FILE on the scanned lib path and return a buffer visiting it
3924 (let* ((dirs idlwave-path-alist)
3927 (while (setq dir (car (pop dirs)))
3929 (setq efile (expand-file-name file dir)))
3930 (throw 'exit efile))))))
3932 (defun idlwave-expand-lib-file-name (file)
3933 ;; Find FILE on the scanned lib path and return a buffer visiting it
3934 ;; This is for, e.g., finding source with no user catalog
3937 ((file-name-absolute-p file) file)
3938 (t (idlwave-locate-lib-file file))))
3940 (defun idlwave-make-tags ()
3941 "Creates the IDL tags file IDLTAGS in the current directory from
3942 the list of directories specified in the minibuffer. Directories may be
3943 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3944 specified top directories are searched if the directory name is prefixed
3945 by @. Specify @ directories with care, it may take a long, long time if
3948 (let (directory directories cmd append status numdirs dir getsubdirs
3949 buffer save_buffer files numfiles item errbuf)
3952 ;; Read list of directories
3953 (setq directory (read-string "Tag Directories: " "."))
3954 (setq directories (idlwave-split-string directory "[ \t]+"))
3956 ;; Set etags command, vars
3957 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3958 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3959 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3963 ;; For each directory
3965 (setq dir (nth numdirs directories))
3968 ;; Find the subdirectories
3969 (if (string-match "^[@]\\(.+\\)$" dir)
3970 (setq getsubdirs t) (setq getsubdirs nil))
3971 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3972 (setq dir (expand-file-name dir))
3973 (if (file-directory-p dir)
3975 (if (and getsubdirs)
3977 (setq buffer (get-buffer-create "*idltags*"))
3978 (call-process "sh" nil buffer nil "-c"
3979 (concat "find " dir " -type d -print"))
3980 (setq save_buffer (current-buffer))
3982 (setq files (idlwave-split-string
3983 (idlwave-replace-string
3984 (buffer-substring 1 (point-max))
3987 (set-buffer save_buffer)
3988 (kill-buffer buffer))
3989 (setq files (list (concat dir "/*.pro"))))
3991 ;; For each subdirectory
3993 (setq item (nth numfiles files))
3997 (if (not (string-match "^[ \\t]*$" item))
3999 (message "%s" (concat "Tagging " item "..."))
4000 (setq errbuf (get-buffer-create "*idltags-error*"))
4001 (setq status (+ status
4002 (if (eq 0 (call-process
4003 "sh" nil errbuf nil "-c"
4004 (concat cmd append item)))
4008 ;; Append additional tags
4009 (setq append " --append ")
4010 (setq numfiles (1+ numfiles))
4011 (setq item (nth numfiles files)))
4013 (setq numfiles (1+ numfiles))
4014 (setq item (nth numfiles files))
4017 (setq numdirs (1+ numdirs))
4018 (setq dir (nth numdirs directories)))
4020 (setq numdirs (1+ numdirs))
4021 (setq dir (nth numdirs directories)))))
4023 (setq errbuf (get-buffer-create "*idltags-error*"))
4025 (kill-buffer errbuf))
4029 (defun idlwave-toggle-comment-region (beg end &optional n)
4030 "Comment the lines in the region if the first non-blank line is
4031 commented, and conversely, uncomment region. If optional prefix arg
4032 N is non-nil, then for N positive, add N comment delimiters or for N
4033 negative, remove N comment delimiters.
4034 Uses `comment-region' which does not place comment delimiters on
4036 (interactive "r\nP")
4038 (comment-region beg end (prefix-numeric-value n))
4043 (skip-chars-forward " \t\n")
4044 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4045 (if (fboundp 'uncomment-region)
4046 (uncomment-region beg end)
4047 (comment-region beg end
4048 (- (length (buffer-substring
4051 (comment-region beg end)))))
4054 ;; ----------------------------------------------------------------------------
4055 ;; ----------------------------------------------------------------------------
4056 ;; ----------------------------------------------------------------------------
4057 ;; ----------------------------------------------------------------------------
4059 ;; Completion and Routine Info
4062 ;; String "intern" functions
4064 ;; For the completion and routine info function, we want to normalize
4065 ;; the case of procedure names etc. We do this by "interning" these
4066 ;; string is a hand-crafted way. Hashes are used to map the downcase
4067 ;; version of the strings to the cased versions. Most *-sint-*
4068 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4069 ;; system hash. The former is re-scanned, and the latter takes case
4072 ;; Since these cased versions are really lisp objects, we can use `eq'
4073 ;; to search, which is a large performance boost. All new strings
4074 ;; need to be "sinterned". We do this as early as possible after
4075 ;; getting these strings from completion or buffer substrings. So
4076 ;; most of the code can simply assume to deal with "sinterned"
4077 ;; strings. The only exception is that the functions which scan whole
4078 ;; buffers for routine information do not intern the grabbed strings.
4079 ;; This is only done afterwards. Therefore in these functions it is
4080 ;; *not* safe to assume the strings can be compared with `eq' and be
4081 ;; fed into the routine assq functions.
4083 ;; Here we define the hashing functions.
4085 ;; The variables which hold the hashes.
4086 (defvar idlwave-sint-routines '(nil))
4087 (defvar idlwave-sint-keywords '(nil))
4088 (defvar idlwave-sint-methods '(nil))
4089 (defvar idlwave-sint-classes '(nil))
4090 (defvar idlwave-sint-dirs '(nil))
4091 (defvar idlwave-sint-libnames '(nil))
4093 (defun idlwave-reset-sintern (&optional what)
4094 "Reset all sintern hashes."
4095 ;; Make sure the hash functions are accessible.
4096 (if (or (not (fboundp 'gethash))
4097 (not (fboundp 'puthash)))
4100 (or (fboundp 'puthash)
4101 (defalias 'puthash 'cl-puthash))))
4102 (let ((entries '((idlwave-sint-routines 1000 10)
4103 (idlwave-sint-keywords 1000 10)
4104 (idlwave-sint-methods 100 10)
4105 (idlwave-sint-classes 10 10))))
4107 ;; Make sure these are lists
4108 (loop for entry in entries
4109 for var = (car entry)
4110 do (if (not (consp (symbol-value var))) (set var (list nil))))
4112 (when (or (eq what t) (eq what 'syslib)
4113 (null (cdr idlwave-sint-routines)))
4114 ;; Reset the system & library hash
4115 (loop for entry in entries
4116 for var = (car entry) for size = (nth 1 entry)
4117 do (setcdr (symbol-value var)
4118 (make-hash-table ':size size ':test 'equal)))
4119 (setq idlwave-sint-dirs nil
4120 idlwave-sint-libnames nil))
4122 (when (or (eq what t) (eq what 'bufsh)
4123 (null (car idlwave-sint-routines)))
4124 ;; Reset the buffer & shell hash
4125 (loop for entry in entries
4126 for var = (car entry) for size = (nth 1 entry)
4127 do (setcar (symbol-value var)
4128 (make-hash-table ':size size ':test 'equal))))))
4130 (defun idlwave-sintern-routine-or-method (name &optional class set)
4132 (idlwave-sintern-method name set)
4133 (idlwave-sintern-routine name set)))
4135 (defun idlwave-sintern (stype &rest args)
4136 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4138 ;;(defmacro idlwave-sintern (type var)
4139 ;; `(cond ((not (stringp name)) name)
4140 ;; ((gethash (downcase name) (cdr ,var)))
4141 ;; ((gethash (downcase name) (car ,var)))
4142 ;; (set (idlwave-sintern-set name ,type ,var set))
4145 (defun idlwave-sintern-routine (name &optional set)
4146 (cond ((not (stringp name)) name)
4147 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4148 ((gethash (downcase name) (car idlwave-sint-routines)))
4149 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4151 (defun idlwave-sintern-keyword (name &optional set)
4152 (cond ((not (stringp name)) name)
4153 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4154 ((gethash (downcase name) (car idlwave-sint-keywords)))
4155 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4157 (defun idlwave-sintern-method (name &optional set)
4158 (cond ((not (stringp name)) name)
4159 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4160 ((gethash (downcase name) (car idlwave-sint-methods)))
4161 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4163 (defun idlwave-sintern-class (name &optional set)
4164 (cond ((not (stringp name)) name)
4165 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4166 ((gethash (downcase name) (car idlwave-sint-classes)))
4167 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4170 (defun idlwave-sintern-dir (dir &optional set)
4171 (car (or (member dir idlwave-sint-dirs)
4172 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4173 (defun idlwave-sintern-libname (name &optional set)
4174 (car (or (member name idlwave-sint-libnames)
4175 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4177 (defun idlwave-sintern-set (name type tables set)
4178 (let* ((func (or (cdr (assq type idlwave-completion-case))
4180 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4181 (table (if (eq set 'sys) (cdr tables) (car tables))))
4182 (puthash (downcase name) iname table)
4185 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4186 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4188 (setcar x (idlwave-sintern-keyword (car x) set)))
4192 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4193 "Sintern all strings in the rinfo LIST. With optional parameter
4194 SET: also set new patterns. Probably this will always have to be t.
4195 If DEFAULT-DIR is passed, it is used as the base of the directory"
4196 (let (entry name type class kwds res source call new)
4198 (setq entry (car list)
4203 source (nth 3 entry)
4205 kwds (nthcdr 5 entry))
4207 ;; The class and name
4210 (if (symbolp class) (setq class (symbol-name class)))
4211 (setq class (idlwave-sintern-class class set))
4212 (setq name (idlwave-sintern-method name set)))
4213 (setq name (idlwave-sintern-routine name set)))
4216 (let ((source-type (car source))
4217 (source-file (nth 1 source))
4218 (source-dir (if default-dir
4219 (file-name-as-directory default-dir)
4221 (source-lib (nth 3 source)))
4222 (if (stringp source-dir)
4223 (setq source-dir (idlwave-sintern-dir source-dir set)))
4224 (if (stringp source-lib)
4225 (setq source-lib (idlwave-sintern-libname source-lib set)))
4226 (setq source (list source-type source-file source-dir source-lib)))
4229 (setq kwds (mapcar (lambda (x)
4230 (idlwave-sintern-keyword-list x set))
4233 ;; Build a canonicalized list
4234 (setq new (nconc (list name type class source call) kwds)
4235 res (cons new res)))
4238 ;; Creating new sintern tables
4240 (defun idlwave-new-sintern-type (tag)
4241 "Define a variable and a function to sintern the new type TAG.
4242 This defines the function `idlwave-sintern-TAG' and the variable
4243 `idlwave-sint-TAGs'."
4244 (let* ((name (symbol-name tag))
4245 (names (concat name "s"))
4246 (var (intern (concat "idlwave-sint-" names)))
4247 (func (intern (concat "idlwave-sintern-" name))))
4248 (set var nil) ; initial value of the association list
4249 (fset func ; set the function
4250 `(lambda (name &optional set)
4251 (cond ((not (stringp name)) name)
4252 ((cdr (assoc (downcase name) ,var)))
4254 (setq ,var (cons (cons (downcase name) name) ,var))
4258 (defun idlwave-reset-sintern-type (tag)
4259 "Reset the sintern variable associated with TAG."
4260 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4262 ;;---------------------------------------------------------------------------
4265 ;; The variables which hold the information
4266 (defvar idlwave-system-routines nil
4267 "Holds the routine-info obtained by scanning buffers.")
4268 (defvar idlwave-buffer-routines nil
4269 "Holds the routine-info obtained by scanning buffers.")
4270 (defvar idlwave-compiled-routines nil
4271 "Holds the routine-info obtained by asking the shell.")
4272 (defvar idlwave-unresolved-routines nil
4273 "Holds the unresolved routine-info obtained by asking the shell.")
4274 (defvar idlwave-user-catalog-routines nil
4275 "Holds the procedure routine-info from the user scan.")
4276 (defvar idlwave-library-catalog-routines nil
4277 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4278 (defvar idlwave-library-catalog-libname nil
4279 "Name of library catalog loaded from .idlwave_catalog files.")
4280 (defvar idlwave-path-alist nil
4281 "Alist with !PATH directories and zero or more flags if the dir has
4282 been scanned in a user catalog ('user) or discovered in a library
4284 (defvar idlwave-true-path-alist nil
4285 "Like `idlwave-path-alist', but with true filenames.")
4286 (defvar idlwave-routines nil
4287 "Holds the combinded procedure/function/method routine-info.")
4288 (defvar idlwave-class-alist nil
4289 "Holds the class names known to IDLWAVE.")
4290 (defvar idlwave-class-history nil
4291 "The history of classes selected with the minibuffer.")
4292 (defvar idlwave-force-class-query nil)
4293 (defvar idlwave-before-completion-wconf nil
4294 "The window configuration just before the completion buffer was displayed.")
4295 (defvar idlwave-last-system-routine-info-cons-cell nil
4296 "The last cons cell in the system routine info.")
4299 ;; The code to get routine info from different sources.
4301 (defvar idlwave-system-routines)
4302 (defvar idlwave-catalog-process nil
4303 "The background process currently updating the catalog.")
4305 (defun idlwave-routines ()
4306 "Provide a list of IDL routines.
4307 This routine loads the builtin routines on the first call. Later it
4308 only returns the value of the variable."
4309 (if (and idlwave-catalog-process
4310 (processp idlwave-catalog-process))
4313 ((equal (process-status idlwave-catalog-process) 'exit)
4314 (message "updating........")
4315 (setq idlwave-catalog-process nil)
4316 (idlwave-update-routine-info '(4)))
4317 ((equal (process-status idlwave-catalog-process) 'run)
4318 ;; Keep it running...
4321 ;; Something is wrong, get rid of the process
4322 (message "Problem with catalog process") (beep)
4324 (kill-process idlwave-catalog-process)
4326 (setq idlwave-catalog-process nil)))))
4327 (or idlwave-routines
4329 (idlwave-update-routine-info)
4330 ;; return the current value
4333 (defvar idlwave-update-rinfo-hook nil
4334 "List of functions which should run after a global rinfo update.
4335 Does not run after automatic updates of buffer or the shell.")
4337 (defun idlwave-rescan-catalog-directories ()
4338 "Rescan the previously selected directories. For batch processing."
4339 (idlwave-update-routine-info '(16)))
4341 (defun idlwave-rescan-asynchronously ()
4342 "Dispatch another emacs instance to update the idlwave catalog.
4343 After the process finishes normally, the first access to routine info
4344 will re-read the catalog."
4346 (if (processp idlwave-catalog-process)
4347 (if (eq (process-status idlwave-catalog-process) 'run)
4348 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4351 (kill-process idlwave-catalog-process)
4353 (error "Process killed, no new process started"))
4356 (kill-process idlwave-catalog-process)
4358 (if (or (not idlwave-user-catalog-file)
4359 (not (stringp idlwave-user-catalog-file))
4360 (not (file-regular-p idlwave-user-catalog-file)))
4361 (error "No catalog has been produced yet"))
4362 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4363 (args (list "-batch"
4364 "-l" (expand-file-name "~/.emacs")
4366 "-f" "idlwave-rescan-catalog-directories"))
4367 (process (apply 'start-process "idlcat"
4369 (setq idlwave-catalog-process process)
4370 (set-process-sentinel
4373 (when (string-match "finished" why)
4374 (setq idlwave-routines nil
4375 idlwave-system-routines nil
4376 idlwave-catalog-process nil)
4377 (or (idlwave-start-load-rinfo-timer)
4378 (idlwave-update-routine-info '(4))))))
4379 (message "Background job started to update catalog file")))
4382 ;; Format for all routine info user catalog, library catalogs, etc.:
4384 ;; ("ROUTINE" type class
4385 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4386 ;; (buffer pro_file dir) | (compiled pro_file dir)
4387 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
4389 ;; DIR will be supplied dynamically while loading library catalogs,
4390 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4391 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4392 ;; be nil, as can LINK1, etc., if no HTML help is available.
4395 (defvar idlwave-load-rinfo-idle-timer)
4396 (defvar idlwave-shell-path-query)
4398 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4399 "Update the internal routine-info lists.
4400 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4401 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4402 about individual routines.
4404 The information can come from 4 sources:
4405 1. IDL programs in the current editing session
4406 2. Compiled modules in an IDL shell running as Emacs subprocess
4407 3. A list which covers the IDL system routines.
4408 4. A list which covers the prescanned library files.
4410 Scans all IDLWAVE-mode buffers of the current editing session (see
4411 `idlwave-scan-all-buffers-for-routine-info').
4412 When an IDL shell is running, this command also queries the IDL program
4413 for currently compiled routines.
4415 With prefix ARG, also reload the system and library lists.
4416 With two prefix ARG's, also rescans the chosen user catalog tree.
4417 With three prefix args, dispatch asynchronous process to do the update.
4419 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4420 lists, but instead wait for the shell query to complete and
4421 asynchronously finish updating routine info. This is set
4422 automatically when called interactively. When you need routine
4423 information updated immediately, leave NO-CONCATENATE nil."
4424 (interactive "P\np")
4425 ;; Stop any idle processing
4426 (if (or (and (fboundp 'itimerp)
4427 (itimerp idlwave-load-rinfo-idle-timer))
4428 (and (fboundp 'timerp)
4429 (timerp idlwave-load-rinfo-idle-timer)))
4430 (cancel-timer idlwave-load-rinfo-idle-timer))
4433 ;; Start a background process which updates the catalog.
4434 (idlwave-rescan-asynchronously))
4436 ;; Update the user catalog now, and wait for them.
4437 (idlwave-create-user-catalog-file t))
4439 (let* ((load (or arg
4440 idlwave-buffer-case-takes-precedence
4441 (null idlwave-routines)))
4442 ;; The override-idle means, even if the idle timer has done some
4443 ;; preparing work, load and renormalize everything anyway.
4444 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4446 (setq idlwave-buffer-routines nil
4447 idlwave-compiled-routines nil
4448 idlwave-unresolved-routines nil)
4449 ;; Reset the appropriate hashes
4450 (if (get 'idlwave-reset-sintern 'done-by-idle)
4451 ;; reset was already done in idle time, so skip this step now once
4452 (put 'idlwave-reset-sintern 'done-by-idle nil)
4453 (idlwave-reset-sintern (cond (load t)
4454 ((null idlwave-system-routines) t)
4457 (if idlwave-buffer-case-takes-precedence
4458 ;; We can safely scan the buffer stuff first
4460 (idlwave-update-buffer-routine-info)
4461 (and load (idlwave-load-system-rinfo override-idle)))
4462 ;; We first do the system info, and then the buffers
4463 (and load (idlwave-load-system-rinfo override-idle))
4464 (idlwave-update-buffer-routine-info))
4466 ;; Let's see if there is a shell
4467 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4468 (idlwave-shell-is-running)))
4469 (ask-shell (and shell-is-running
4470 idlwave-query-shell-for-routine-info)))
4472 ;; Load the library catalogs again, first re-scanning the path
4474 (if shell-is-running
4475 (idlwave-shell-send-command idlwave-shell-path-query
4477 (idlwave-shell-get-path-info)
4478 (idlwave-scan-library-catalogs))
4480 (idlwave-scan-library-catalogs)))
4482 (if (or (not ask-shell)
4483 (not no-concatenate))
4484 ;; 1. If we are not going to ask the shell, we need to do the
4485 ;; concatenation now.
4486 ;; 2. When this function is called non-interactively, it
4487 ;; means that someone needs routine info *now*. The
4488 ;; shell update causes the concatenation to be
4489 ;; *delayed*, so not in time for the current command.
4490 ;; Therefore, we do a concatenation now, even though
4491 ;; the shell might do it again.
4492 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4495 ;; Ask the shell about the routines it knows of.
4496 (message "Querying the shell")
4497 (idlwave-shell-update-routine-info nil t)))))))
4500 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4501 (defvar idlwave-load-rinfo-idle-timer nil)
4502 (defun idlwave-start-load-rinfo-timer ()
4503 (if (or (and (fboundp 'itimerp)
4504 (itimerp idlwave-load-rinfo-idle-timer))
4505 (and (fboundp 'timerp)
4506 (timerp idlwave-load-rinfo-idle-timer)))
4507 (cancel-timer idlwave-load-rinfo-idle-timer))
4508 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4509 (setq idlwave-load-rinfo-idle-timer nil)
4510 (if (and idlwave-init-rinfo-when-idle-after
4511 (numberp idlwave-init-rinfo-when-idle-after)
4512 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4513 (not idlwave-routines))
4516 (setq idlwave-load-rinfo-idle-timer
4517 (run-with-idle-timer
4518 idlwave-init-rinfo-when-idle-after
4519 nil 'idlwave-load-rinfo-next-step)))
4522 (defvar idlwave-library-routines nil "Obsolete variable.")
4524 (defun idlwave-load-rinfo-next-step ()
4525 (let ((inhibit-quit t)
4526 (arr idlwave-load-rinfo-steps-done))
4528 (when (not (aref arr 0))
4529 (message "Loading idlw-rinfo.el in idle time...")
4530 (load "idlw-rinfo" 'noerror 'nomessage)
4531 (message "Loading idlw-rinfo.el in idle time...done")
4534 (when (not (aref arr 1))
4535 (message "Normalizing idlwave-system-routines in idle time...")
4536 (idlwave-reset-sintern t)
4537 (put 'idlwave-reset-sintern 'done-by-idle t)
4538 (setq idlwave-system-routines
4539 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4540 (message "Normalizing idlwave-system-routines in idle time...done")
4543 (when (not (aref arr 2))
4544 (when (and (stringp idlwave-user-catalog-file)
4545 (file-regular-p idlwave-user-catalog-file))
4546 (message "Loading user catalog in idle time...")
4548 (load-file idlwave-user-catalog-file)
4549 (error (throw 'exit nil)))
4550 ;; Check for the old style catalog and warn
4552 (boundp 'idlwave-library-routines)
4553 idlwave-library-routines)
4555 (setq idlwave-library-routines nil)
4557 (message "Outdated user catalog: %s... recreate"
4558 idlwave-user-catalog-file))
4559 (message "Loading user catalog in idle time...done"))
4562 (when (not (aref arr 3))
4563 (when idlwave-user-catalog-routines
4564 (message "Normalizing user catalog routines in idle time...")
4565 (setq idlwave-user-catalog-routines
4566 (idlwave-sintern-rinfo-list
4567 idlwave-user-catalog-routines 'sys))
4569 "Normalizing user catalog routines in idle time...done"))
4572 (when (not (aref arr 4))
4573 (idlwave-scan-library-catalogs
4574 "Loading and normalizing library catalogs in idle time...")
4577 (when (not (aref arr 5))
4578 (message "Finishing initialization in idle time...")
4580 (message "Finishing initialization in idle time...done")
4582 ;; restart the timer
4584 (idlwave-load-rinfo-next-step)
4585 (setq idlwave-load-rinfo-idle-timer
4586 (run-with-idle-timer
4587 idlwave-init-rinfo-when-idle-after
4588 nil 'idlwave-load-rinfo-next-step))))))
4590 (defun idlwave-load-system-rinfo (&optional force)
4591 ;; Load and case-treat the system and catalog files.
4592 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
4593 (load "idlw-rinfo" 'noerror 'nomessage))
4594 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
4595 (message "Normalizing idlwave-system-routines...")
4596 (setq idlwave-system-routines
4597 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4598 (message "Normalizing idlwave-system-routines...done"))
4599 (setq idlwave-routines (copy-sequence idlwave-system-routines))
4600 (setq idlwave-last-system-routine-info-cons-cell
4601 (nthcdr (1- (length idlwave-routines)) idlwave-routines))
4602 (when (and (stringp idlwave-user-catalog-file)
4603 (file-regular-p idlwave-user-catalog-file))
4605 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
4606 (load-file idlwave-user-catalog-file))
4608 (when (boundp 'idlwave-library-routines)
4609 (setq idlwave-library-routines nil)
4610 (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file))
4611 (setq idlwave-true-path-alist nil)
4612 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
4613 (message "Normalizing user catalog routines...")
4614 (setq idlwave-user-catalog-routines
4615 (idlwave-sintern-rinfo-list
4616 idlwave-user-catalog-routines 'sys))
4617 (message "Normalizing user catalog routines...done")))
4618 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
4619 (idlwave-scan-library-catalogs
4620 "Loading and normalizing library catalogs..."))
4621 (run-hooks 'idlwave-after-load-rinfo-hook))
4624 (defun idlwave-update-buffer-routine-info ()
4627 ((eq idlwave-scan-all-buffers-for-routine-info t)
4628 ;; Scan all buffers, current buffer last
4629 (message "Scanning all buffers...")
4630 (setq res (idlwave-get-routine-info-from-buffers
4631 (reverse (buffer-list)))))
4632 ((null idlwave-scan-all-buffers-for-routine-info)
4633 ;; Don't scan any buffers
4636 ;; Just scan this buffer
4637 (if (eq major-mode 'idlwave-mode)
4639 (message "Scanning current buffer...")
4640 (setq res (idlwave-get-routine-info-from-buffers
4641 (list (current-buffer))))))))
4642 ;; Put the result into the correct variable
4643 (setq idlwave-buffer-routines
4644 (idlwave-sintern-rinfo-list res 'set))))
4646 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
4647 "Put the different sources for routine information together."
4648 ;; The sequence here is important because earlier definitions shadow
4649 ;; later ones. We assume that if things in the buffers are newer
4650 ;; then in the shell of the system, they are meant to be different.
4651 (setcdr idlwave-last-system-routine-info-cons-cell
4652 (append idlwave-buffer-routines
4653 idlwave-compiled-routines
4654 idlwave-library-catalog-routines
4655 idlwave-user-catalog-routines))
4656 (setq idlwave-class-alist nil)
4658 ;; Give a message with information about the number of routines we have.
4661 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
4662 (length idlwave-buffer-routines)
4663 (length idlwave-compiled-routines)
4664 (length idlwave-library-catalog-routines)
4665 (length idlwave-user-catalog-routines)
4666 (length idlwave-system-routines)))
4668 (run-hooks 'idlwave-update-rinfo-hook)))
4670 (defun idlwave-class-alist ()
4671 "Return the class alist - make it if necessary."
4672 (or idlwave-class-alist
4674 (loop for x in idlwave-routines do
4675 (when (and (setq class (nth 2 x))
4676 (not (assq class idlwave-class-alist)))
4677 (push (list class) idlwave-class-alist)))
4678 idlwave-class-alist)))
4680 ;; Three functions for the hooks
4681 (defun idlwave-save-buffer-update ()
4682 (idlwave-update-current-buffer-info 'save-buffer))
4683 (defun idlwave-kill-buffer-update ()
4684 (idlwave-update-current-buffer-info 'kill-buffer))
4685 (defun idlwave-new-buffer-update ()
4686 (idlwave-update-current-buffer-info 'find-file))
4688 (defun idlwave-update-current-buffer-info (why)
4689 "Update idlwave-routines for current buffer. Can run from after-save-hook."
4690 (when (and (eq major-mode 'idlwave-mode)
4691 (or (eq t idlwave-auto-routine-info-updates)
4692 (memq why idlwave-auto-routine-info-updates))
4693 idlwave-scan-all-buffers-for-routine-info
4697 (idlwave-replace-buffer-routine-info
4699 (if (eq why 'kill-buffer)
4702 (idlwave-sintern-rinfo-list
4703 (idlwave-get-routine-info-from-buffers
4704 (list (current-buffer))) 'set))))
4705 (idlwave-concatenate-rinfo-lists 'quiet)
4709 (defun idlwave-replace-buffer-routine-info (file new)
4710 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4711 (let ((list idlwave-buffer-routines)
4714 ;; The following test uses eq to make sure it works correctly
4715 ;; when two buffers visit the same file. Then the file names
4716 ;; will be equal, but not eq.
4717 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
4722 ;; End of that section reached. Jump.
4724 (setq list (cdr list)))
4725 (setq idlwave-buffer-routines
4726 (append new (delq nil idlwave-buffer-routines)))))
4728 ;;----- Scanning buffers -------------------
4730 (defun idlwave-get-routine-info-from-buffers (buffers)
4731 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4732 (let (buf routine-lists res)
4734 (while (setq buf (pop buffers))
4736 (if (and (eq major-mode 'idlwave-mode)
4738 ;; yes, this buffer has the right mode.
4739 (progn (setq res (condition-case nil
4740 (idlwave-get-buffer-routine-info)
4742 (push res routine-lists)))))
4743 ;; Concatenate the individual lists and return the result
4744 (apply 'nconc routine-lists)))
4746 (defun idlwave-get-buffer-routine-info ()
4747 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4748 (let* ((case-fold-search t)
4749 routine-list string entry)
4753 (goto-char (point-min))
4754 (while (re-search-forward
4755 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
4756 (setq string (buffer-substring-no-properties
4759 (idlwave-end-of-statement)
4761 (setq entry (idlwave-parse-definition string))
4762 (push entry routine-list))))
4765 (defvar idlwave-scanning-lib-dir)
4766 (defun idlwave-parse-definition (string)
4767 "Parse a module definition."
4768 (let ((case-fold-search t)
4769 start name args type keywords class)
4771 (while (string-match ";.*" string)
4772 (setq string (replace-match "" t t string)))
4773 ;; Remove the continuation line stuff
4774 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
4775 (setq string (replace-match "\\1 " t nil string)))
4776 (while (string-match "\n" string)
4777 (setq string (replace-match " " t nil string)))
4778 ;; Match the name and type.
4780 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
4781 (setq start (match-end 0))
4782 (setq type (downcase (match-string 1 string)))
4783 (if (match-beginning 3)
4784 (setq class (match-string 3 string)))
4785 (setq name (match-string 4 string)))
4786 ;; Match normal args and keyword args
4787 (while (string-match
4788 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4790 (setq start (match-end 0))
4791 (if (match-beginning 3)
4792 (push (match-string 1 string) keywords)
4793 (push (match-string 1 string) args)))
4794 ;; Normalize and sort.
4795 (setq args (nreverse args))
4796 (setq keywords (sort keywords (lambda (a b)
4797 (string< (downcase a) (downcase b)))))
4798 ;; Make and return the entry
4799 ;; We don't know which argument are optional, so this information
4800 ;; will not be contained in the calling sequence.
4802 (if (equal type "pro") 'pro 'fun)
4804 (cond ((not (boundp 'idlwave-scanning-lib))
4805 (list 'buffer (buffer-file-name)))
4806 ; ((string= (downcase
4807 ; (file-name-sans-extension
4808 ; (file-name-nondirectory (buffer-file-name))))
4811 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4812 (t (list 'user (file-name-nondirectory (buffer-file-name))
4813 idlwave-scanning-lib-dir "UserLib")))
4815 (if (string= type "function") "Result = " "")
4816 (if class "Obj ->[%s::]" "")
4820 (if (string= type "function") "(" ", ")
4821 (mapconcat 'identity args ", ")
4822 (if (string= type "function") ")" ""))))
4824 (cons nil (mapcar 'list keywords)) ;No help file
4828 ;;----- Scanning the user catalog -------------------
4830 (defun idlwave-sys-dir ()
4831 "Return the syslib directory, or a dummy that never matches."
4833 ((and idlwave-system-directory
4834 (not (string= idlwave-system-directory "")))
4835 idlwave-system-directory)
4836 ((getenv "IDL_DIR"))
4841 (defun idlwave-create-user-catalog-file (&optional arg)
4842 "Scan all files on selected dirs of IDL search path for routine information.
4844 A widget checklist will allow you to choose the directories. Write
4845 the result as a file `idlwave-user-catalog-file'. When this file
4846 exists, will be automatically loaded to give routine information about
4847 library routines. With ARG, just rescan the same directories as last
4848 time - so no widget will pop up."
4850 ;; Make sure the file is loaded if it exists.
4851 (if (and (stringp idlwave-user-catalog-file)
4852 (file-regular-p idlwave-user-catalog-file))
4854 (load-file idlwave-user-catalog-file)
4856 ;; Make sure the file name makes sense
4857 (unless (and (stringp idlwave-user-catalog-file)
4858 (> (length idlwave-user-catalog-file) 0)
4859 (file-accessible-directory-p
4860 (file-name-directory idlwave-user-catalog-file))
4861 (not (string= "" (file-name-nondirectory
4862 idlwave-user-catalog-file))))
4863 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
4866 ;; Rescan the known directories
4867 ((and arg idlwave-path-alist
4868 (consp (car idlwave-path-alist)))
4869 (idlwave-scan-user-lib-files idlwave-path-alist))
4871 ;; Expand the directories from library-path and run the widget
4872 (idlwave-library-path
4873 (idlwave-display-user-catalog-widget
4874 (if idlwave-true-path-alist
4875 ;; Propagate any flags on the existing path-alist
4877 (let ((path-entry (assoc (file-truename x)
4878 idlwave-true-path-alist)))
4880 (cons x (cdr path-entry))
4882 (idlwave-expand-path idlwave-library-path))
4883 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
4885 ;; Ask the shell for the path and then run the widget
4887 (message "Asking the shell for IDL path...")
4888 (require 'idlw-shell)
4889 (idlwave-shell-send-command idlwave-shell-path-query
4890 '(idlwave-user-catalog-command-hook nil)
4894 ;; Parse shell path information and select among it.
4895 (defun idlwave-user-catalog-command-hook (&optional arg)
4896 ;; Command hook used by `idlwave-create-user-catalog-file'.
4899 (idlwave-scan-user-lib-files idlwave-path-alist)
4900 ;; Set the path and display the widget
4901 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
4902 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
4903 (idlwave-display-user-catalog-widget idlwave-path-alist)))
4905 (defconst idlwave-user-catalog-widget-help-string
4906 "This is the front-end to the creation of the IDLWAVE user catalog.
4907 Please select the directories on IDL's search path from which you
4908 would like to extract routine information, to be stored in the file:
4912 If this is not the correct file, first set variable
4913 `idlwave-user-catalog-file', and call this command again.
4915 N.B. Many libraries include pre-scanned catalog files
4916 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
4917 not be scanned. You can scan your own libraries off-line using the
4918 perl script `idlwave_catalog'.
4920 After selecting the directories, choose [Scan & Save] to scan the library
4921 directories and save the routine info.
4924 (defvar idlwave-widget)
4925 (defvar widget-keymap)
4926 (defun idlwave-display-user-catalog-widget (dirs-list)
4927 "Create the widget to select IDL search path directories for scanning."
4932 (error "Don't know IDL's search path"))
4934 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4935 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4936 (kill-all-local-variables)
4937 (make-local-variable 'idlwave-widget)
4938 (widget-insert (format idlwave-user-catalog-widget-help-string
4939 idlwave-user-catalog-file))
4941 (widget-create 'push-button
4942 :notify 'idlwave-widget-scan-user-lib-files
4945 (widget-create 'push-button
4946 :notify 'idlwave-delete-user-catalog-file
4949 (widget-create 'push-button
4951 '(lambda (&rest ignore)
4952 (let ((path-list (widget-get idlwave-widget :path-dirs)))
4954 (unless (memq 'lib (cdr x))
4955 (idlwave-path-alist-add-flag x 'user)))
4957 (idlwave-display-user-catalog-widget path-list)))
4958 "Select All Non-Lib")
4960 (widget-create 'push-button
4962 '(lambda (&rest ignore)
4963 (let ((path-list (widget-get idlwave-widget :path-dirs)))
4965 (idlwave-path-alist-remove-flag x 'user))
4967 (idlwave-display-user-catalog-widget path-list)))
4970 (widget-create 'push-button
4971 :notify (lambda (&rest ignore)
4972 (kill-buffer (current-buffer)))
4974 (widget-insert "\n\n")
4976 (widget-insert "Select Directories: \n")
4978 (setq idlwave-widget
4979 (apply 'widget-create
4981 :value (delq nil (mapcar (lambda (x)
4982 (if (memq 'user (cdr x))
4986 :tag "List of directories"
4989 (if (memq 'lib (cdr x))
4990 (concat "[LIB] " (car x) )
4991 (car x)))) dirs-list)))
4992 (widget-put idlwave-widget :path-dirs dirs-list)
4993 (widget-insert "\n")
4994 (use-local-map widget-keymap)
4996 (goto-char (point-min))
4997 (delete-other-windows))
4999 (defun idlwave-delete-user-catalog-file (&rest ignore)
5001 (format "Delete file %s " idlwave-user-catalog-file))
5003 (delete-file idlwave-user-catalog-file)
5004 (message "%s has been deleted" idlwave-user-catalog-file))))
5006 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5007 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5008 (let* ((widget idlwave-widget)
5009 (selected-dirs (widget-value widget))
5010 (path-alist (widget-get widget :path-dirs))
5011 (this-path-alist path-alist)
5013 (while (setq dir-entry (pop this-path-alist))
5015 (if (memq 'lib (cdr dir-entry))
5016 (concat "[LIB] " (car dir-entry))
5019 (idlwave-path-alist-add-flag dir-entry 'user)
5020 (idlwave-path-alist-remove-flag dir-entry 'user)))
5021 (idlwave-scan-user-lib-files path-alist)))
5023 (defvar font-lock-mode)
5024 (defun idlwave-scan-user-lib-files (path-alist)
5025 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5026 (let* ((idlwave-scanning-lib t)
5027 (idlwave-scanning-lib-dir "")
5028 (idlwave-completion-case nil)
5029 dirs-alist dir files file)
5030 (setq idlwave-user-catalog-routines nil
5031 idlwave-path-alist path-alist ; for library-path instead
5032 idlwave-true-path-alist nil)
5033 (if idlwave-auto-write-paths (idlwave-write-paths))
5035 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5037 (setq dirs-alist (reverse path-alist))
5038 (while (setq dir (pop dirs-alist))
5039 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5040 (setq dir (car dir))
5041 (setq idlwave-scanning-lib-dir dir)
5042 (when (file-directory-p dir)
5043 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5044 (while (setq file (pop files))
5045 (when (file-regular-p file)
5046 (if (not (file-readable-p file))
5047 (message "Skipping %s (no read permission)" file)
5048 (message "Scanning %s..." file)
5050 (insert-file-contents file 'visit)
5051 (setq idlwave-user-catalog-routines
5052 (append (idlwave-get-routine-info-from-buffers
5053 (list (current-buffer)))
5054 idlwave-user-catalog-routines)))))))))
5055 (message "Creating user catalog file...")
5056 (kill-buffer "*idlwave-scan.pro*")
5057 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5058 (let ((font-lock-maximum-size 0)
5059 (auto-mode-alist nil))
5060 (find-file idlwave-user-catalog-file))
5061 (if (and (boundp 'font-lock-mode)
5065 (insert ";; IDLWAVE user catalog file\n")
5066 (insert (format ";; Created %s\n\n" (current-time-string)))
5068 ;; Define the routine info list
5069 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5070 (let ((standard-output (current-buffer)))
5074 (goto-char (point-max)))
5075 idlwave-user-catalog-routines))
5076 (insert (format "))\n\n;;; %s ends here\n"
5077 (file-name-nondirectory idlwave-user-catalog-file)))
5078 (goto-char (point-min))
5081 (kill-buffer (current-buffer)))
5082 (message "Creating user catalog file...done")
5083 (message "Info for %d routines saved in %s"
5084 (length idlwave-user-catalog-routines)
5085 idlwave-user-catalog-file)
5087 (idlwave-update-routine-info t))
5089 (defun idlwave-read-paths ()
5090 (if (and (stringp idlwave-path-file)
5091 (file-regular-p idlwave-path-file))
5093 (load idlwave-path-file t t t)
5096 (defun idlwave-write-paths ()
5098 (when (and idlwave-path-alist idlwave-system-directory)
5099 (let ((font-lock-maximum-size 0)
5100 (auto-mode-alist nil))
5101 (find-file idlwave-path-file))
5102 (if (and (boundp 'font-lock-mode)
5106 (insert ";; IDLWAVE paths\n")
5107 (insert (format ";; Created %s\n\n" (current-time-string)))
5108 ;; Define the variable which knows the value of "!DIR"
5109 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5110 idlwave-system-directory))
5112 ;; Define the variable which contains a list of all scanned directories
5113 (insert "\n(setq idlwave-path-alist\n '(")
5114 (let ((standard-output (current-buffer)))
5118 (goto-char (point-max)))
5119 idlwave-path-alist))
5122 (kill-buffer (current-buffer))))
5125 (defun idlwave-expand-path (path &optional default-dir)
5126 ;; Expand parts of path starting with '+' recursively into directory list.
5127 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5128 (message "Expanding path...")
5129 (let (path1 dir recursive)
5130 (while (setq dir (pop path))
5131 (if (setq recursive (string= (substring dir 0 1) "+"))
5132 (setq dir (substring dir 1)))
5134 (not (file-name-absolute-p dir)))
5135 (setq dir (expand-file-name dir default-dir)))
5137 ;; Expand recursively
5138 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5141 (message "Expanding path...done")
5144 (defun idlwave-recursive-directory-list (dir)
5145 ;; Return a list of all directories below DIR, including DIR itself
5146 (let ((path (list dir)) path1 file files)
5147 (while (setq dir (pop path))
5148 (when (file-directory-p dir)
5149 (setq files (nreverse (directory-files dir t "[^.]")))
5150 (while (setq file (pop files))
5151 (if (file-directory-p file)
5152 (push (file-name-as-directory file) path)))
5157 ;;----- Scanning the library catalogs ------------------
5162 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5163 "Scan for library catalog files (.idlwave_catalog) and ingest.
5165 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5166 instead, if present) are searched. Print MESSAGE-BASE along with the
5167 libraries being loaded, if passed, and skip loading/normalizing if
5168 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5169 be set to nil to disable library catalog scanning."
5170 (when idlwave-use-library-catalogs
5172 (if idlwave-library-path
5173 (idlwave-expand-path idlwave-library-path)
5174 (mapcar 'car idlwave-path-alist)))
5176 dir-entry dir flags catalog all-routines)
5177 (if message-base (message message-base))
5178 (while (setq dir (pop dirs))
5180 (when (file-readable-p
5181 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5183 (setq idlwave-library-catalog-routines nil)
5184 ;; Load the catalog file
5186 (load catalog t t t)
5187 (error (throw 'continue t)))
5190 (not (string= idlwave-library-catalog-libname
5192 (message "%s" (concat message-base
5193 idlwave-library-catalog-libname))
5194 (setq old-libname idlwave-library-catalog-libname))
5195 (when idlwave-library-catalog-routines
5198 (idlwave-sintern-rinfo-list
5199 idlwave-library-catalog-routines 'sys dir)
5202 ;; Add a 'lib flag if on path-alist
5203 (when (and idlwave-path-alist
5204 (setq dir-entry (assoc dir idlwave-path-alist)))
5205 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5206 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5207 (if message-base (message (concat message-base "done"))))))
5209 ;;----- Communicating with the Shell -------------------
5211 ;; First, here is the idl program which can be used to query IDL for
5212 ;; defined routines.
5213 (defconst idlwave-routine-info.pro
5215 ;; START OF IDLWAVE SUPPORT ROUTINES
5216 pro idlwave_print_info_entry,name,func=func,separator=sep
5217 ;; See if it's an object method
5218 if name eq '' then return
5219 func = keyword_set(func)
5220 methsep = strpos(name,'::')
5221 meth = methsep ne -1
5224 pars = routine_info(name,/parameters,functions=func)
5225 source = routine_info(name,/source,functions=func)
5226 nargs = pars.num_args
5227 nkw = pars.num_kw_args
5228 if nargs gt 0 then args = pars.args
5229 if nkw gt 0 then kwargs = pars.kw_args
5231 ;; Trim the class, and make the name
5233 class = strmid(name,0,methsep)
5234 name = strmid(name,methsep+2,strlen(name)-1)
5235 if nargs gt 0 then begin
5236 ;; remove the self argument
5237 wh = where(args ne 'SELF',nargs)
5238 if nargs gt 0 then args = args[wh]
5241 ;; No class, just a normal routine.
5247 if func then cs = 'Result = '
5248 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5250 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5251 if nargs gt 0 then begin
5252 for j=0,nargs-1 do begin
5254 if j lt nargs-1 then cs = cs + ', '
5257 if func then cs = cs + ')'
5258 ;; Keyword arguments
5260 if nkw gt 0 then begin
5261 for j=0,nkw-1 do begin
5262 kwstring = kwstring + ' ' + kwargs[j]
5266 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5268 print,ret + ': ' + name + sep + class + sep + source[0].path $
5269 + sep + cs + sep + kwstring
5272 pro idlwave_routine_info
5275 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5276 all = routine_info()
5277 for i=0,n_elements(all)-1 do $
5278 idlwave_print_info_entry,all[i],separator=sep
5279 all = routine_info(/functions)
5280 for i=0,n_elements(all)-1 do $
5281 idlwave_print_info_entry,all[i],/func,separator=sep
5282 print,'>>>END OF IDLWAVE ROUTINE INFO'
5285 pro idlwave_get_sysvars
5288 if error_status ne 0 then begin
5289 print, 'Cannot get info about system variables'
5291 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5292 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5293 v = strsplit(s,' +',/regex,/extract) ; get variables
5294 for i=0,n_elements(v)-1 do begin
5295 t = [''] ; get tag list
5296 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5297 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5302 pro idlwave_get_class_tags, class
5303 res = execute('tags=tag_names({'+class+'})')
5304 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5306 ;; END OF IDLWAVE SUPPORT ROUTINES
5308 "The idl programs to get info from the shell.")
5310 (defvar idlwave-idlwave_routine_info-compiled nil
5311 "Remembers if the routine info procedure is already compiled.")
5313 (defvar idlwave-shell-temp-pro-file)
5314 (defvar idlwave-shell-temp-rinfo-save-file)
5315 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait)
5316 "Query the shell for routine_info of compiled modules and update the lists."
5317 ;; Save and compile the procedure. The compiled procedure is then
5318 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5319 ;; We need to RESTORE the procedure each time we use it, since
5320 ;; the user may have killed or redefined it. In particular,
5321 ;; .RESET_SESSION will kill all user procedures.
5322 (unless (and idlwave-idlwave_routine_info-compiled
5323 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5325 (set-buffer (idlwave-find-file-noselect
5326 (idlwave-shell-temp-file 'pro)))
5328 (insert idlwave-routine-info.pro)
5330 (idlwave-shell-send-command
5331 (concat ".run " idlwave-shell-temp-pro-file)
5333 ; (message "SENDING SAVE") ; ????????????????????????
5334 (idlwave-shell-send-command
5335 (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5336 (idlwave-shell-temp-file 'rinfo))
5339 ;; Restore and execute the procedure, analyze the output
5340 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5341 (idlwave-shell-send-command
5342 (format "RESTORE, '%s' & idlwave_routine_info"
5343 idlwave-shell-temp-rinfo-save-file)
5345 (idlwave-shell-routine-info-filter)
5346 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5349 ;; ---------------------------------------------------------------------------
5351 ;; Completion and displaying routine calling sequences
5353 (defvar idlwave-completion-help-info nil)
5354 (defvar idlwave-completion-help-links nil)
5355 (defvar idlwave-current-obj_new-class nil)
5356 (defvar idlwave-complete-special nil)
5358 (defun idlwave-complete (&optional arg module class)
5359 "Complete a function, procedure or keyword name at point.
5360 This function is smart and figures out what can be completed
5362 - At the beginning of a statement it completes procedure names.
5363 - In the middle of a statement it completes function names.
5364 - after a `(' or `,' in the argument list of a function or procedure,
5365 it completes a keyword of the relevant function or procedure.
5366 - In the first arg of `OBJ_NEW', it completes a class name.
5368 When several completions are possible, a list will be displayed in the
5369 *Completions* buffer. If this list is too long to fit into the
5370 window, scrolling can be achieved by repeatedly pressing
5371 \\[idlwave-complete].
5373 The function also knows about object methods. When it needs a class
5374 name, the action depends upon `idlwave-query-class', which see. You
5375 can force IDLWAVE to ask you for a class name with a
5376 \\[universal-argument] prefix argument to this command.
5378 See also the variables `idlwave-keyword-completion-adds-equal' and
5379 `idlwave-function-completion-adds-paren'.
5381 The optional ARG can be used to specify the completion type in order
5382 to override IDLWAVE's idea of what should be completed at point.
5383 Possible values are:
5385 0 <=> query for the completion type
5387 2 <=> 'procedure-keyword
5389 4 <=> 'function-keyword
5390 5 <=> 'procedure-method
5391 6 <=> 'procedure-method-keyword
5392 7 <=> 'function-method
5393 8 <=> 'function-method-keyword
5396 As a special case, the universal argument C-u forces completion of
5397 function names in places where the default would be a keyword.
5399 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5402 For Lisp programmers only:
5403 When we force a keyword, optional argument MODULE can contain the module name.
5404 When we force a method or a method keyword, CLASS can specify the class."
5409 (or (and (integerp arg) (not (equal arg '(16))))
5411 (idlwave-make-force-complete-where-list arg module class)
5413 (what (nth 2 where-list))
5414 (idlwave-force-class-query (equal arg '(4)))
5415 (completion-regexp-list
5416 (if (equal arg '(16))
5417 (list (read-string (concat "Completion Regexp: "))))))
5419 (if (and module (string-match "::" module))
5420 (setq class (substring module 0 (match-beginning 0))
5421 module (substring module (match-end 0))))
5426 (eq (car-safe last-command) 'idlwave-display-completion-list)
5427 (get-buffer-window "*Completions*"))
5428 (setq this-command last-command)
5429 (idlwave-scroll-completions))
5431 ;; Complete a filename in quotes
5432 ((and (idlwave-in-quote)
5433 (not (eq what 'class)))
5434 (idlwave-complete-filename))
5436 ;; Check for any special completion functions
5437 ((and idlwave-complete-special
5438 (idlwave-call-special idlwave-complete-special)))
5441 (error "Nothing to complete here"))
5445 (setq idlwave-completion-help-info '(class))
5446 (idlwave-complete-class))
5448 ((eq what 'procedure)
5449 ;; Complete a procedure name
5450 (let* ((cw-list (nth 3 where-list))
5451 (class-selector (idlwave-determine-class cw-list 'pro))
5452 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5453 (idlwave-all-class-inherits class-selector)))
5454 (isa (concat "procedure" (if class-selector "-method" "")))
5455 (type-selector 'pro))
5456 (setq idlwave-completion-help-info
5457 (list 'routine nil type-selector class-selector nil super-classes))
5458 (idlwave-complete-in-buffer
5459 'procedure (if class-selector 'method 'routine)
5460 (idlwave-routines) 'idlwave-selector
5461 (format "Select a %s name%s"
5464 (format " (class is %s)"
5465 (if (eq class-selector t)
5466 "unknown" class-selector))
5469 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5471 ((eq what 'function)
5472 ;; Complete a function name
5473 (let* ((cw-list (nth 3 where-list))
5474 (class-selector (idlwave-determine-class cw-list 'fun))
5475 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5476 (idlwave-all-class-inherits class-selector)))
5477 (isa (concat "function" (if class-selector "-method" "")))
5478 (type-selector 'fun))
5479 (setq idlwave-completion-help-info
5480 (list 'routine nil type-selector class-selector nil super-classes))
5481 (idlwave-complete-in-buffer
5482 'function (if class-selector 'method 'routine)
5483 (idlwave-routines) 'idlwave-selector
5484 (format "Select a %s name%s"
5487 (format " (class is %s)"
5488 (if (eq class-selector t)
5489 "unknown" class-selector))
5492 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5494 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5496 (idlwave-complete 3))
5498 ((eq what 'procedure-keyword)
5499 ;; Complete a procedure keyword
5500 (let* ((where (nth 3 where-list))
5502 (method-selector name)
5503 (type-selector 'pro)
5504 (class (idlwave-determine-class where 'pro))
5505 (class-selector class)
5506 (super-classes (idlwave-all-class-inherits class-selector))
5507 (isa (format "procedure%s-keyword" (if class "-method" "")))
5508 (entry (idlwave-best-rinfo-assq
5509 name 'pro class (idlwave-routines)))
5510 (system (if entry (eq (car (nth 3 entry)) 'system)))
5511 (list (idlwave-entry-keywords entry 'do-link)))
5512 (unless (or entry (eq class t))
5513 (error "Nothing known about procedure %s"
5514 (idlwave-make-full-name class name)))
5515 (setq list (idlwave-fix-keywords name 'pro class list
5516 super-classes system))
5517 (unless list (error "No keywords available for procedure %s"
5518 (idlwave-make-full-name class name)))
5519 (setq idlwave-completion-help-info
5520 (list 'keyword name type-selector class-selector entry super-classes))
5521 (idlwave-complete-in-buffer
5522 'keyword 'keyword list nil
5523 (format "Select keyword for procedure %s%s"
5524 (idlwave-make-full-name class name)
5525 (if (or (member '("_EXTRA") list)
5526 (member '("_REF_EXTRA") list))
5527 " (note _EXTRA)" ""))
5529 'idlwave-attach-keyword-classes)))
5531 ((eq what 'function-keyword)
5532 ;; Complete a function keyword
5533 (let* ((where (nth 3 where-list))
5535 (method-selector name)
5536 (type-selector 'fun)
5537 (class (idlwave-determine-class where 'fun))
5538 (class-selector class)
5539 (super-classes (idlwave-all-class-inherits class-selector))
5540 (isa (format "function%s-keyword" (if class "-method" "")))
5541 (entry (idlwave-best-rinfo-assq
5542 name 'fun class (idlwave-routines)))
5543 (system (if entry (eq (car (nth 3 entry)) 'system)))
5544 (list (idlwave-entry-keywords entry 'do-link))
5546 (unless (or entry (eq class t))
5547 (error "Nothing known about function %s"
5548 (idlwave-make-full-name class name)))
5549 (setq list (idlwave-fix-keywords name 'fun class list
5550 super-classes system))
5551 ;; OBJ_NEW: Messages mention the proper Init method
5552 (setq msg-name (if (and (null class)
5553 (string= (upcase name) "OBJ_NEW"))
5554 (concat idlwave-current-obj_new-class
5555 "::Init (via OBJ_NEW)")
5556 (idlwave-make-full-name class name)))
5557 (unless list (error "No keywords available for function %s"
5559 (setq idlwave-completion-help-info
5560 (list 'keyword name type-selector class-selector nil super-classes))
5561 (idlwave-complete-in-buffer
5562 'keyword 'keyword list nil
5563 (format "Select keyword for function %s%s" msg-name
5564 (if (or (member '("_EXTRA") list)
5565 (member '("_REF_EXTRA") list))
5566 " (note _EXTRA)" ""))
5568 'idlwave-attach-keyword-classes)))
5570 (t (error "This should not happen (idlwave-complete)")))))
5572 (defvar idlwave-complete-special nil
5573 "List of special completion functions.
5574 These functions are called for each completion. Each function must
5575 check if its own special completion context is present. If yes, it
5576 should use `idlwave-complete-in-buffer' to do some completion and
5577 return t. If such a function returns t, *no further* attempts to
5578 complete other contexts will be done. If the function returns nil,
5579 other completions will be tried.")
5581 (defun idlwave-call-special (functions &rest args)
5582 (let ((funcs functions)
5585 (while (setq fun (pop funcs))
5586 (if (setq ret (apply fun args))
5590 (defun idlwave-make-force-complete-where-list (what &optional module class)
5591 ;; Return an artificial WHERE specification to force the completion
5592 ;; routine to complete a specific item independent of context.
5593 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5594 ;; MODULE and CLASS can be used to specify the routine name and class.
5595 ;; The class name will also be found in MODULE if that is like "class::mod".
5596 (let* ((what-list '(("procedure") ("procedure-keyword")
5597 ("function") ("function-keyword")
5598 ("procedure-method") ("procedure-method-keyword")
5599 ("function-method") ("function-method-keyword")
5601 (module (idlwave-sintern-routine-or-method module class))
5602 (class (idlwave-sintern-class class))
5606 (intern (completing-read
5607 "Complete what? " what-list nil t))))
5609 (setq what (intern (car (nth (1- what) what-list)))))
5612 (assoc (symbol-name what) what-list))
5614 (t (error "Invalid WHAT"))))
5615 (nil-list '(nil nil nil nil))
5616 (class-list (list nil nil (or class t) nil)))
5620 ((eq what 'procedure)
5621 (list nil-list nil-list 'procedure nil-list nil))
5623 ((eq what 'procedure-keyword)
5624 (let* ((class-selector nil)
5626 (type-selector 'pro)
5628 (idlwave-completing-read
5629 "Procedure: " (idlwave-routines) 'idlwave-selector))))
5630 (setq pro (idlwave-sintern-routine pro))
5631 (list nil-list nil-list 'procedure-keyword
5632 (list pro nil nil nil) nil)))
5634 ((eq what 'function)
5635 (list nil-list nil-list 'function nil-list nil))
5637 ((eq what 'function-keyword)
5638 (let* ((class-selector nil)
5640 (type-selector 'fun)
5642 (idlwave-completing-read
5643 "Function: " (idlwave-routines) 'idlwave-selector))))
5644 (setq func (idlwave-sintern-routine func))
5645 (list nil-list nil-list 'function-keyword
5646 (list func nil nil nil) nil)))
5648 ((eq what 'procedure-method)
5649 (list nil-list nil-list 'procedure class-list nil))
5651 ((eq what 'procedure-method-keyword)
5652 (let* ((class (idlwave-determine-class class-list 'pro))
5653 (class-selector class)
5654 (super-classes (idlwave-all-class-inherits class-selector))
5655 (type-selector 'pro)
5657 (idlwave-completing-read
5658 (format "Procedure in %s class: " class-selector)
5659 (idlwave-routines) 'idlwave-selector))))
5660 (setq pro (idlwave-sintern-method pro))
5661 (list nil-list nil-list 'procedure-keyword
5662 (list pro nil class nil) nil)))
5664 ((eq what 'function-method)
5665 (list nil-list nil-list 'function class-list nil))
5667 ((eq what 'function-method-keyword)
5668 (let* ((class (idlwave-determine-class class-list 'fun))
5669 (class-selector class)
5670 (super-classes (idlwave-all-class-inherits class-selector))
5671 (type-selector 'fun)
5673 (idlwave-completing-read
5674 (format "Function in %s class: " class-selector)
5675 (idlwave-routines) 'idlwave-selector))))
5676 (setq func (idlwave-sintern-method func))
5677 (list nil-list nil-list 'function-keyword
5678 (list func nil class nil) nil)))
5681 (list nil-list nil-list 'class nil-list nil))
5683 (t (error "Invalid value for WHAT")))))
5685 (defun idlwave-completing-read (&rest args)
5686 ;; Completing read, case insensitive
5687 (let ((old-value (default-value 'completion-ignore-case)))
5690 (setq-default completion-ignore-case t)
5691 (apply 'completing-read args))
5692 (setq-default completion-ignore-case old-value))))
5694 (defvar idlwave-shell-default-directory)
5695 (defun idlwave-complete-filename ()
5696 "Use the comint stuff to complete a file name."
5698 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5699 (comint-completion-addsuffix nil)
5701 (if (and (boundp 'idlwave-shell-default-directory)
5702 (stringp idlwave-shell-default-directory)
5703 (file-directory-p idlwave-shell-default-directory))
5704 idlwave-shell-default-directory
5705 default-directory)))
5706 (comint-dynamic-complete-filename)))
5708 (defun idlwave-make-full-name (class name)
5709 ;; Make a fully qualified module name including the class name
5710 (concat (if class (format "%s::" class) "") name))
5712 (defun idlwave-rinfo-assoc (name type class list)
5713 "Like `idlwave-rinfo-assq', but sintern strings first."
5715 (idlwave-sintern-routine-or-method name class)
5716 type (idlwave-sintern-class class) list))
5718 (defun idlwave-rinfo-assq (name type class list)
5719 ;; Works like assq, but also checks type and class
5722 (while (setq match (assq name list))
5723 (and (or (eq type t)
5724 (eq (nth 1 match) type))
5725 (eq (nth 2 match) class)
5726 (throw 'exit match))
5727 (setq list (cdr (memq match list)))))))
5729 (defun idlwave-rinfo-assq-any-class (name type class list)
5730 ;; Return the first matching method on the inheritance list
5731 (let* ((classes (cons class (idlwave-all-class-inherits class)))
5734 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
5735 (setq classes nil)))
5738 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
5740 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
5741 If WITH-FILE is passed, find the best rinfo entry with a file
5742 included. If KEEP-SYSTEM is set, don't prune system for compiled
5744 (let ((twins (idlwave-routine-twins
5745 (idlwave-rinfo-assq-any-class name type class list)
5748 (when (> (length twins) 1)
5749 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
5750 (if (and (null keep-system)
5751 (eq 'system (car (nth 3 (car twins))))
5752 (setq syslibp (idlwave-any-syslib (cdr twins)))
5753 (not (equal 1 syslibp)))
5754 ;; Its a compiled syslib, so we need to remove the system entry
5755 (setq twins (cdr twins)))
5757 (setq twins (delq nil
5759 (if (nth 1 (nth 3 x)) x))
5763 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
5765 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5766 (idlwave-best-rinfo-assq
5767 (idlwave-sintern-routine-or-method name class)
5768 type (idlwave-sintern-class class) list with-file keep-system))
5770 (defun idlwave-any-syslib (entries)
5771 "Does the entry list ENTRIES contain a syslib entry?
5772 If yes, return the index (>=1)."
5777 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
5778 (if (and file (idlwave-syslib-p file))
5780 (setq entries (cdr entries))))
5783 (defun idlwave-all-assq (key list)
5784 "Return a list of all associations of Key in LIST."
5786 (while (setq elt (assq key list))
5788 (setq list (cdr (memq elt list))))
5791 (defun idlwave-all-method-classes (method &optional type)
5792 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5793 When TYPE is not specified, both procedures and functions will be considered."
5795 (mapcar 'car (idlwave-class-alist))
5800 (eq type (nth 1 x)))
5801 (push (nth 2 x) rtn)))
5802 (idlwave-all-assq method (idlwave-routines)))
5803 (idlwave-uniquify rtn))))
5805 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
5806 "Return all classes which have a method METHOD with keyword KEYWORD.
5807 TYPE is 'fun or 'pro.
5808 When TYPE is not specified, both procedures and functions will be considered."
5809 (if (or (null method)
5814 (and (nth 2 x) ; non-nil class
5815 (or (not type) ; correct or unspecified type
5816 (eq type (nth 1 x)))
5817 (assoc keyword (idlwave-entry-keywords x))
5818 (push (nth 2 x) rtn)))
5819 (idlwave-all-assq method (idlwave-routines)))
5820 (idlwave-uniquify rtn))))
5822 (defun idlwave-members-only (list club)
5823 "Return list of all elements in LIST which are also in CLUB."
5826 (if (member (car list) club)
5827 (setq rtn (cons (car list) rtn)))
5828 (setq list (cdr list)))
5831 (defun idlwave-nonmembers-only (list club)
5832 "Return list of all elements in LIST which are not in CLUB."
5835 (if (member (car list) club)
5837 (setq rtn (cons (car list) rtn)))
5838 (setq list (cdr list)))
5841 (defun idlwave-explicit-class-listed (info)
5842 "Return whether or not the class is listed explicitly, ala a->b::c.
5843 INFO is as returned by idlwave-what-function or -procedure."
5844 (let ((apos (nth 3 info)))
5846 (save-excursion (goto-char apos)
5847 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5849 (defvar idlwave-determine-class-special nil
5850 "List of special functions for determining class.
5851 Must accept two arguments: `apos' and `info'")
5853 (defun idlwave-determine-class (info type)
5854 ;; Determine the class of a routine call.
5855 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5856 ;; The second element in this structure is the class. When nil, we
5857 ;; return nil. When t, try to get the class from text properties at
5858 ;; the arrow. When the object is "self", we use the class of the
5859 ;; current routine. otherwise prompt the user for a class name.
5860 ;; Also stores the selected class as a text property at the arrow.
5861 ;; TYPE is 'fun or 'pro.
5862 (let* ((class (nth 2 info))
5864 (nassoc (assoc (if (stringp (car info))
5867 idlwave-query-class))
5868 (dassoc (assq (if (car info) 'keyword-default 'method-default)
5869 idlwave-query-class))
5870 (query (cond (nassoc (cdr nassoc))
5871 (dassoc (cdr dassoc))
5873 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
5876 (save-excursion (goto-char apos)
5878 (let ((case-fold-search t))
5879 (looking-at "self\\>")))))
5880 (force-query idlwave-force-class-query)
5881 store special-class class-alist)
5885 ;; There is an object which would like to know its class
5886 (if (and arrow (get-text-property apos 'idlwave-class)
5887 idlwave-store-inquired-class
5889 (setq class (get-text-property apos 'idlwave-class)
5890 class (idlwave-sintern-class class)))
5891 (if (and (eq t class) is-self)
5892 (setq class (or (nth 2 (idlwave-current-routine)) class)))
5894 ;; Before prompting, try any special class determination routines
5895 (when (and (eq t class)
5896 idlwave-determine-class-special
5899 (idlwave-call-special idlwave-determine-class-special apos))
5901 (setq class (idlwave-sintern-class special-class)
5902 store idlwave-store-inquired-class)))
5904 ;; Prompt for a class, if we need to
5905 (when (and (eq class t)
5906 (or force-query query))
5908 (mapcar 'list (idlwave-all-method-classes (car info) type)))
5910 (idlwave-sintern-class
5912 ((and (= (length class-alist) 0) (not force-query))
5913 (error "No classes available with method %s" (car info)))
5914 ((and (= (length class-alist) 1) (not force-query))
5915 (car (car class-alist)))
5917 (setq store idlwave-store-inquired-class)
5918 (idlwave-completing-read
5919 (format "Class%s: " (if (stringp (car info))
5920 (format " for %s method %s"
5923 class-alist nil nil nil 'idlwave-class-history))))))
5925 ;; Store it, if requested
5926 (when (and class (not (eq t class)))
5927 ;; We have a real class here
5928 (when (and store arrow)
5930 (add-text-properties
5932 `(idlwave-class ,class face ,idlwave-class-arrow-face
5935 (setf (nth 2 info) class))
5938 ;; Default as fallback
5941 (defvar type-selector)
5942 (defvar class-selector)
5943 (defvar method-selector)
5944 (defvar super-classes)
5945 (defun idlwave-selector (a)
5946 (and (eq (nth 1 a) type-selector)
5947 (or (and (nth 2 a) (eq class-selector t))
5948 (eq (nth 2 a) class-selector)
5949 (memq (nth 2 a) super-classes))))
5951 (defun idlwave-add-file-link-selector (a)
5952 ;; Record a file link, if any, for the tested names during selection.
5953 (let ((sel (idlwave-selector a)) file)
5954 (if (and sel (setq file (idlwave-entry-has-help a)))
5955 (push (cons (car a) file) idlwave-completion-help-links))
5959 (defun idlwave-where ()
5960 "Find out where we are.
5961 The return value is a list with the following stuff:
5962 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5964 PRO-LIST (PRO POINT CLASS ARROW)
5965 FUNC-LIST (FUNC POINT CLASS ARROW)
5966 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5967 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5969 LAST-CHAR last relevant character before point (non-white non-comment,
5970 not part of current identifier or leading slash).
5972 In the lists, we have these meanings:
5975 POINT: Where is this
5976 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5977 ARROW: Location of the arrow"
5979 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5980 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
5981 (func-entry (idlwave-what-function bos))
5982 (func (car func-entry))
5983 (func-class (nth 1 func-entry))
5984 (func-arrow (nth 2 func-entry))
5985 (func-point (or (nth 3 func-entry) 0))
5986 (func-level (or (nth 4 func-entry) 0))
5987 (pro-entry (idlwave-what-procedure bos))
5988 (pro (car pro-entry))
5989 (pro-class (nth 1 pro-entry))
5990 (pro-arrow (nth 2 pro-entry))
5991 (pro-point (or (nth 3 pro-entry) 0))
5992 (last-char (idlwave-last-valid-char))
5993 (case-fold-search t)
5994 (match-string (buffer-substring bos (point)))
5995 cw cw-mod cw-arrow cw-class cw-point)
5996 (if (< func-point pro-point) (setq func nil))
5998 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6002 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6004 (buffer-substring pro-point (point))
6006 (setq cw 'procedure cw-class pro-class cw-point pro-point
6007 cw-arrow pro-arrow))
6008 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6011 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6014 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6018 (> func-point pro-point)
6020 (memq last-char '(?\( ?,)))
6021 (setq cw 'function-keyword cw-mod func cw-point func-point
6022 cw-class func-class cw-arrow func-arrow))
6023 ((and pro (eq last-char ?,))
6024 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6025 cw-class pro-class cw-arrow pro-arrow))
6026 ; ((member last-char '(?\' ?\) ?\] ?!))
6027 ; ;; after these chars, a function makes no sense
6028 ; ;; FIXME: I am sure there can be more in this list
6029 ; ;; FIXME: Do we want to do this at all?
6031 ;; Everywhere else we try a function.
6035 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6036 (setq cw-arrow (copy-marker (match-beginning 0))
6037 cw-class (if (match-end 4)
6038 (idlwave-sintern-class (match-string 4))
6040 (list (list pro pro-point pro-class pro-arrow)
6041 (list func func-point func-class func-arrow)
6043 (list cw-mod cw-point cw-class cw-arrow)
6046 (defun idlwave-this-word (&optional class)
6047 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6048 (setq class (or class "a-zA-Z0-9$_."))
6051 (progn (skip-chars-backward class) (point))
6052 (progn (skip-chars-forward class) (point)))))
6054 (defun idlwave-what-function (&optional bound)
6055 ;; Find out if point is within the argument list of a function.
6056 ;; The return value is ("function-name" class arrow-start (point) level).
6057 ;; Level is 1 on the top level parentheses, higher further down.
6059 ;; If the optional BOUND is an integer, bound backwards directed
6060 ;; searches to this point.
6066 func arrow-start class)
6067 (idlwave-with-special-syntax
6070 (narrow-to-region (max 1 (or bound 0)) (point-max))
6071 ;; move back out of the current parenthesis
6072 (while (condition-case nil
6073 (progn (up-list -1) t)
6077 (when (and (= (following-char) ?\()
6079 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6081 (setq func (match-string 2)
6082 func-point (goto-char (match-beginning 2))
6084 (if (re-search-backward
6085 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6086 (setq arrow-start (copy-marker (match-beginning 0))
6087 class (or (match-string 2) t)))
6091 (idlwave-sintern-routine-or-method func class)
6092 (idlwave-sintern-class class)
6093 arrow-start func-point cnt)))
6095 (throw 'exit nil)))))))
6097 (defun idlwave-what-procedure (&optional bound)
6098 ;; Find out if point is within the argument list of a procedure.
6099 ;; The return value is ("procedure-name" class arrow-pos (point)).
6101 ;; If the optional BOUND is an integer, bound backwards directed
6102 ;; searches to this point.
6103 (let ((pos (point)) pro-point
6104 pro class arrow-start string)
6106 ;;(idlwave-beginning-of-statement)
6107 (idlwave-start-of-substatement 'pre)
6108 (setq string (buffer-substring (point) pos))
6110 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6111 (setq pro (match-string 1 string)
6112 pro-point (+ (point) (match-beginning 1)))
6113 (if (and (idlwave-skip-object)
6114 (setq string (buffer-substring (point) pos))
6116 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6118 (setq pro (if (match-beginning 4)
6119 (match-string 4 string))
6120 pro-point (if (match-beginning 4)
6121 (+ (point) (match-beginning 4))
6123 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6124 class (or (match-string 3 string) t)))))
6125 (list (idlwave-sintern-routine-or-method pro class)
6126 (idlwave-sintern-class class)
6130 (defun idlwave-skip-object ()
6131 ;; If there is an object at point, move over it and return t.
6132 (let ((pos (point)))
6135 (skip-chars-forward " ") ; white space
6136 (skip-chars-forward "*") ; de-reference
6138 ((looking-at idlwave-identifier)
6139 (goto-char (match-end 0)))
6140 ((eq (following-char) ?\()
6142 (t (throw 'exit nil)))
6145 (cond ((eq (following-char) ?.)
6147 (if (not (looking-at idlwave-identifier))
6149 (goto-char (match-end 0)))
6150 ((memq (following-char) '(?\( ?\[))
6153 (error (throw 'exit nil))))
6154 (t (throw 'endwhile t)))))
6155 (if (looking-at "[ \t]*->")
6156 (throw 'exit (setq pos (match-beginning 0)))
6157 (throw 'exit nil))))
6161 (defun idlwave-last-valid-char ()
6162 "Return the last character before point which is not white or a comment
6163 and also not part of the current identifier. Since we do this in
6164 order to identify places where keywords are, we consider the initial
6165 `/' of a keyword as part of the identifier.
6166 This function is not general, can only be used for completion stuff."
6169 ;; skip the current identifier
6170 (skip-chars-backward "a-zA-Z0-9_$")
6171 ;; also skip a leading slash which might be belong to the keyword
6172 (if (eq (preceding-char) ?/)
6174 ;; FIXME: does not check if this is a valid identifier
6176 (skip-chars-backward " \t")
6178 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6179 ((eq (preceding-char) ?\n)
6180 (beginning-of-line 0)
6181 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6182 ;; continuation line
6183 (goto-char (match-end 1))
6185 (t (throw 'exit (preceding-char))))))))
6187 (defvar idlwave-complete-after-success-form nil
6188 "A form to evaluate after successful completion.")
6189 (defvar idlwave-complete-after-success-form-force nil
6190 "A form to evaluate after completion selection in *Completions* buffer.")
6191 (defconst idlwave-completion-mark (make-marker)
6192 "A mark pointing to the beginning of the completion string.")
6194 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6195 &optional prepare-display-function
6197 "Perform TYPE completion of word before point against LIST.
6198 SELECTOR is the PREDICATE argument for the completion function. Show
6199 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6200 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6201 used only once, for `all-completions', and can be used to, e.g.,
6202 accumulate information on matching completions."
6203 (let* ((completion-ignore-case t)
6204 beg (end (point)) slash part spart completion all-completions
6208 (error (concat prompt ": No completions available")))
6210 ;; What is already in the buffer?
6212 (skip-chars-backward "a-zA-Z0-9_$")
6213 (setq slash (eq (preceding-char) ?/)
6215 idlwave-complete-after-success-form
6216 (list 'idlwave-after-successful-completion
6217 (list 'quote type) slash beg)
6218 idlwave-complete-after-success-form-force
6219 (list 'idlwave-after-successful-completion
6220 (list 'quote type) slash (list 'quote 'force))))
6223 (setq part (buffer-substring beg end)
6224 dpart (downcase part)
6225 spart (idlwave-sintern stype part)
6226 completion (try-completion part list selector)
6227 dcompletion (if (stringp completion) (downcase completion))
6228 idlwave-completion-help-links nil)
6231 ;; nothing available.
6232 (error (concat prompt ": no completion for \"%s\"") part))
6233 ((and (not (equal dpart dcompletion))
6234 (not (eq t completion)))
6235 ;; We can add something
6236 (delete-region beg end)
6237 (if (and (string= part dpart)
6238 (or (not (string= part ""))
6239 idlwave-complete-empty-string-as-lower-case)
6240 (not idlwave-completion-force-default-case))
6241 (insert dcompletion)
6242 (insert completion))
6243 (if (eq t (try-completion completion list selector))
6244 ;; Now this is a unique match
6245 (idlwave-after-successful-completion type slash beg))
6247 ((or (eq completion t)
6248 (and (= 1 (length (setq all-completions
6250 (all-completions part list
6251 (or special-selector
6253 (equal dpart dcompletion)))
6254 ;; This is already complete
6255 (idlwave-after-successful-completion type slash beg)
6256 (message "%s is already the complete %s" part isa)
6259 ;; We cannot add something - offer a list.
6260 (message "Making completion list...")
6262 (unless idlwave-completion-help-links ; already set somewhere?
6263 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6264 (let ((link (get-text-property 0 'link (car x))))
6266 (push (cons (car x) link)
6267 idlwave-completion-help-links))))
6269 (let* ((list all-completions)
6270 ;; "complete" means, this is already a valid completion
6271 (complete (memq spart all-completions))
6272 (completion-highlight-first-word-only t)) ; XEmacs
6273 ; (completion-fixup-function ; Emacs
6274 ; (lambda () (and (eq (preceding-char) ?>)
6275 ; (re-search-backward " <" beg t)))))
6277 (setq list (sort list (lambda (a b)
6278 (string< (downcase a) (downcase b)))))
6279 (if prepare-display-function
6280 (setq list (funcall prepare-display-function list)))
6281 (if (and (string= part dpart)
6282 (or (not (string= part ""))
6283 idlwave-complete-empty-string-as-lower-case)
6284 (not idlwave-completion-force-default-case))
6285 (setq list (mapcar (lambda (x)
6287 (setcar x (downcase (car x)))
6288 (setq x (downcase x)))
6291 (idlwave-display-completion-list list prompt beg complete))
6294 (defun idlwave-complete-class ()
6295 "Complete a class at point."
6297 ;; Call `idlwave-routines' to make sure the class list will be available
6299 ;; Check for the special case of completing empty string after pro/function
6300 (if (let ((case-fold-search t))
6303 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6305 (goto-char (point-min))
6307 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6308 ;; Yank the full class specification
6309 (insert (match-string 2))
6310 ;; Do the completion, using list gathered from `idlwave-routines'
6311 (idlwave-complete-in-buffer
6312 'class 'class (idlwave-class-alist) nil
6313 "Select a class" "class"
6314 '(lambda (list) ;; Push it to help-links if system help available
6316 (let* ((entry (idlwave-class-info x))
6317 (link (nth 1 (assq 'link entry))))
6318 (if link (push (cons x link)
6319 idlwave-completion-help-links))
6323 (defun idlwave-attach-classes (list type show-classes)
6324 ;; Attach the proper class list to a LIST of completion items.
6325 ;; TYPE, when 'kwd, shows classes for method keywords, when
6326 ;; 'class-tag, for class tags, and otherwise for methods.
6327 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6328 (if (or (null show-classes) ; don't want to see classes
6329 (null class-selector) ; not a method call
6331 (stringp class-selector) ; the class is already known
6332 (not super-classes))) ; no possibilities for inheritance
6333 ;; In these cases, we do not have to do anything
6335 (let* ((do-prop (and (>= show-classes 0)
6336 (>= emacs-major-version 21)))
6337 (do-buf (not (= show-classes 0)))
6338 ;; (do-dots (featurep 'xemacs))
6340 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6341 (cons class-selector super-classes)))
6342 (max (abs show-classes))
6343 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6344 classes nclasses class-info space)
6348 (if (eq type 'class-tag)
6349 ;; Just one class for tags
6352 (idlwave-class-or-superclass-with-tag class-selector x)))
6353 ;; Multiple classes for method or method-keyword
6356 (idlwave-all-method-keyword-classes
6357 method-selector x type-selector)
6358 (idlwave-all-method-classes x type-selector)))
6362 (mapcar (lambda (x) (if (memq x inherit) x nil))
6364 (setq nclasses (length classes))
6365 ;; Make the separator between item and class-info
6367 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6370 ;; We do want info in the buffer
6371 (if (<= nclasses max)
6372 (setq class-info (concat
6374 "<" (mapconcat 'identity classes ",") ">"))
6375 (setq class-info (format "%s<%d classes>" space nclasses)))
6376 (setq class-info nil))
6378 ;; We do want properties
6379 (setq x (copy-sequence x))
6380 (put-text-property 0 (length x)
6381 'help-echo (mapconcat 'identity classes " ")
6388 (defun idlwave-attach-method-classes (list)
6389 ;; Call idlwave-attach-classes with method parameters
6390 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6391 (defun idlwave-attach-keyword-classes (list)
6392 ;; Call idlwave-attach-classes with keyword parameters
6393 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6394 (defun idlwave-attach-class-tag-classes (list)
6395 ;; Call idlwave-attach-classes with class structure tags
6396 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6399 ;;----------------------------------------------------------------------
6400 ;;----------------------------------------------------------------------
6401 ;;----------------------------------------------------------------------
6402 ;;----------------------------------------------------------------------
6403 ;;----------------------------------------------------------------------
6405 (defun idlwave-pset (item)
6408 (defun idlwave-popup-select (ev list title &optional sort)
6409 "Select an item in LIST with a popup menu.
6410 TITLE is the title to put atop the popup. If SORT is non-nil,
6411 sort the list before displaying"
6412 (let ((maxpopup idlwave-max-popup-menu-items)
6415 ((= 1 (length list))
6416 (setq rtn (car list)))
6418 (if sort (setq list (sort list (lambda (a b)
6419 (string< (upcase a) (upcase b))))))
6421 (append (list title)
6422 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6425 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6426 (setq resp (get-popup-menu-response menu))
6427 (funcall (event-function resp) (event-object resp)))
6429 (if sort (setq list (sort list (lambda (a b)
6430 (string< (upcase a) (upcase b))))))
6431 (setq menu (cons title
6434 (mapcar (lambda(x) (cons x x)) list)))))
6435 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6436 (setq rtn (x-popup-menu ev menu))))
6439 (defun idlwave-split-menu-xemacs (menu N)
6440 "Split the MENU into submenus of maximum length N."
6441 (if (<= (length menu) (1+ N))
6442 ;; No splitting needed
6444 (let* ((title (car menu))
6445 (entries (cdr menu))
6450 (while (and entries (< cnt N))
6452 nextmenu (cons (car entries) nextmenu)
6453 entries (cdr entries)))
6454 (setq nextmenu (nreverse nextmenu))
6455 (setq nextmenu (cons (format "%s...%s"
6456 (aref (car nextmenu) 0)
6457 (aref (nth (1- cnt) nextmenu) 0))
6459 (setq menu (cons nextmenu menu)
6464 (defun idlwave-split-menu-emacs (menu N)
6465 "Split the MENU into submenus of maximum length N."
6466 (if (<= (length (nth 1 menu)) (1+ N))
6467 ;; No splitting needed
6469 (let* ((title (car menu))
6470 (entries (cdr (nth 1 menu)))
6475 (while (and entries (< cnt N))
6477 nextmenu (cons (car entries) nextmenu)
6478 entries (cdr entries)))
6479 (setq nextmenu (nreverse nextmenu))
6481 (setq nextmenu (cons (format "%s...%s"
6482 (car (car nextmenu))
6483 (car (nth (1- cnt) nextmenu)))
6485 (setq menu (cons nextmenu menu)
6488 (setq menu (nreverse menu))
6489 (setq menu (cons title menu))
6492 (defvar idlwave-completion-setup-hook nil)
6494 (defun idlwave-scroll-completions (&optional message)
6495 "Scroll the completion window on this frame."
6496 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6497 (win (selected-window)))
6500 (select-window cwin)
6503 (error (if (and (listp last-command)
6504 (nth 2 last-command))
6507 (eval idlwave-complete-after-success-form))
6508 (set-window-start cwin (point-min)))))
6509 (and message (message message)))
6510 (select-window win))))
6512 (defun idlwave-display-completion-list (list &optional message beg complete)
6513 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6514 (unless (and (get-buffer-window "*Completions*")
6515 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6516 (move-marker idlwave-completion-mark beg)
6517 (setq idlwave-before-completion-wconf (current-window-configuration)))
6519 (if (featurep 'xemacs)
6520 (idlwave-display-completion-list-xemacs
6522 (idlwave-display-completion-list-emacs list))
6524 ;; Store a special value in `this-command'. When `idlwave-complete'
6525 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6526 (setq this-command (list 'idlwave-display-completion-list message complete))
6528 ;; Mark the completions buffer as created by cib
6529 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6531 ;; Fontify the classes
6532 (if (and idlwave-completion-fontify-classes
6534 (idlwave-completion-fontify-classes))
6537 (run-hooks 'idlwave-completion-setup-hook)
6539 ;; Display the message
6540 (message (or message "Making completion list...done")))
6542 (defun idlwave-choose (function &rest args)
6543 "Call FUNCTION as a completion chooser and pass ARGS to it."
6544 (let ((completion-ignore-case t)) ; install correct value
6545 (apply function args))
6546 (if (and (eq major-mode 'idlwave-shell-mode)
6547 (boundp 'font-lock-mode)
6548 (not font-lock-mode))
6549 ;; For the shell, remove the fontification of the word before point
6550 (let ((beg (save-excursion
6551 (skip-chars-backward "a-zA-Z0-9_")
6553 (remove-text-properties beg (point) '(face nil))))
6554 (eval idlwave-complete-after-success-form-force))
6556 (defun idlwave-keyboard-quit ()
6559 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
6560 (idlwave-restore-wconf-after-completion))
6563 (defun idlwave-restore-wconf-after-completion ()
6564 "Restore the old (before completion) window configuration."
6565 (and idlwave-completion-restore-window-configuration
6566 idlwave-before-completion-wconf
6567 (set-window-configuration idlwave-before-completion-wconf)))
6569 (defun idlwave-one-key-select (sym prompt delay)
6570 "Make the user select an element from the alist in the variable SYM.
6571 The keys of the alist are expected to be strings. The function returns the
6572 car of the selected association.
6573 To do this, PROMPT is displayed and and the user must hit a letter key to
6574 select an entry. If the user does not reply within DELAY seconds, a help
6575 window with the options is displayed automatically.
6576 The key which is associated with each option is generated automatically.
6577 First, the strings are checked for preselected keys, like in \"[P]rint\".
6578 If these don't exist, a letter in the string is automatically selected."
6579 (let* ((alist (symbol-value sym))
6580 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
6581 '(fit-window-to-buffer)))
6583 ;; First check the cache
6584 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
6585 (setq keys-alist (get sym :one-key-alist-cache))
6586 ;; Need to make new list
6587 (setq keys-alist (idlwave-make-one-key-alist alist))
6588 (put sym :one-key-alist-cache keys-alist)
6589 (put sym :one-key-alist-last alist))
6590 ;; Display prompt and wait for quick reply
6591 (message "%s[%s]" prompt
6592 (mapconcat (lambda(x) (char-to-string (car x)))
6595 ;; No quick reply: Show help
6596 (save-window-excursion
6597 (with-output-to-temp-buffer "*Completions*"
6602 (setq char (read-char)))
6603 (setq char (read-char)))
6605 ;; Return the selected result
6606 (nth 2 (assoc char keys-alist))))
6608 ;; Used for, e.g., electric debug super-examine.
6609 (defun idlwave-make-one-key-alist (alist)
6610 "Make an alist for single key selection."
6611 (let ((l alist) keys-alist name start char help
6613 (case-fold-search nil))
6615 (setq name (car (car l))
6618 ;; First check if the configuration predetermined a key
6619 (if (string-match "\\[\\(.\\)\\]" name)
6621 (setq char (string-to-char (downcase (match-string 1 name)))
6622 help (format "%c: %s" char name)
6623 keys-alist (cons (list char help name) keys-alist))
6625 ;; Then check for capital letters
6627 (while (string-match "[A-Z]" name start)
6628 (setq start (match-end 0)
6629 char (string-to-char (downcase (match-string 0 name))))
6630 (if (not (assoc char keys-alist))
6632 (setq help (format "%c: %s" char
6634 (concat "[" (match-string 0 name) "]")
6636 keys-alist (cons (list char help name) keys-alist))
6638 ;; Now check for lowercase letters
6640 (while (string-match "[a-z]" name start)
6641 (setq start (match-end 0)
6642 char (string-to-char (match-string 0 name)))
6643 (if (not (assoc char keys-alist))
6645 (setq help (format "%c: %s" char
6647 (concat "[" (match-string 0 name) "]")
6649 keys-alist (cons (list char help name) keys-alist))
6651 ;; Bummer, nothing found! Use a stupid number
6652 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
6653 help (format "%c: %s" char name)
6654 keys-alist (cons (list char help name) keys-alist))))
6655 (nreverse keys-alist)))
6657 (defun idlwave-set-local (var value &optional buffer)
6658 "Set the buffer-local value of VAR in BUFFER to VALUE."
6660 (set-buffer (or buffer (current-buffer)))
6661 (set (make-local-variable var) value)))
6663 (defun idlwave-local-value (var &optional buffer)
6664 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6666 (set-buffer (or buffer (current-buffer)))
6667 (and (local-variable-p var (current-buffer))
6668 (symbol-value var))))
6670 ;; In XEmacs, we can use :activate-callback directly to advice the
6671 ;; choose functions. We use the private keymap only for the online
6674 (defvar idlwave-completion-map nil
6675 "Keymap for completion-list-mode with idlwave-complete.")
6677 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
6678 (with-output-to-temp-buffer "*Completions*"
6679 (apply 'display-completion-list list
6680 ':activate-callback 'idlwave-default-choose-completion
6683 (set-buffer "*Completions*")
6685 (or idlwave-completion-map
6686 (setq idlwave-completion-map
6687 (idlwave-make-modified-completion-map-xemacs
6688 (current-local-map)))))))
6690 (defun idlwave-default-choose-completion (&rest args)
6691 "Execute `default-choose-completion' and then restore the win-conf."
6692 (apply 'idlwave-choose 'default-choose-completion args))
6694 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6695 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6696 (let ((new-map (copy-keymap old-map)))
6697 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
6698 (define-key new-map [button3] (lambda ()
6700 (setq this-command last-command)))
6703 ;; In Emacs we also replace keybindings in the completion
6704 ;; map in order to install our wrappers.
6706 (defun idlwave-display-completion-list-emacs (list)
6707 "Display completion list and install the choose wrappers."
6708 (with-output-to-temp-buffer "*Completions*"
6709 (display-completion-list list))
6711 (set-buffer "*Completions*")
6713 (or idlwave-completion-map
6714 (setq idlwave-completion-map
6715 (idlwave-make-modified-completion-map-emacs
6716 (current-local-map)))))))
6718 (defun idlwave-make-modified-completion-map-emacs (old-map)
6719 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6720 (let ((new-map (copy-keymap old-map)))
6721 (substitute-key-definition
6722 'choose-completion 'idlwave-choose-completion new-map)
6723 (substitute-key-definition
6724 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6725 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6728 (defun idlwave-choose-completion (&rest args)
6729 "Choose the completion that point is in or next to."
6731 (apply 'idlwave-choose 'choose-completion args))
6733 (defun idlwave-mouse-choose-completion (&rest args)
6734 "Click on an alternative in the `*Completions*' buffer to choose it."
6736 (apply 'idlwave-choose 'mouse-choose-completion args))
6738 ;;----------------------------------------------------------------------
6739 ;;----------------------------------------------------------------------
6741 ;;; ------------------------------------------------------------------------
6742 ;;; Stucture parsing code, and code to manage class info
6745 ;; - Go again over the documentation how to write a completion
6746 ;; plugin. It is in self.el, but currently still very bad.
6747 ;; This could be in a separate file in the distribution, or
6748 ;; in an appendix for the manual.
6750 (defvar idlwave-struct-skip
6751 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
6752 "Regexp for skipping continued blank or comment-only lines in
6755 (defvar idlwave-struct-tag-regexp
6756 (concat "[{,]" ;leading comma/brace
6757 idlwave-struct-skip ; 4 groups
6758 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
6759 "[ \t]*:") ; the final colon
6760 "Regexp for structure tags.")
6762 (defun idlwave-struct-tags ()
6763 "Return a list of all tags in the structure defined at point.
6764 Point is expected just before the opening `{' of the struct definition."
6766 (let* ((borders (idlwave-struct-borders))
6772 (narrow-to-region beg end)
6773 (while (re-search-forward idlwave-struct-tag-regexp end t)
6774 ;; Check if we are still on the top level of the structure.
6775 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6777 (push (match-string-no-properties 5) tags))
6778 (goto-char (match-end 0))))
6781 (defun idlwave-find-struct-tag (tag)
6782 "Find a given TAG in the structure defined at point."
6783 (let* ((borders (idlwave-struct-borders))
6786 (case-fold-search t))
6787 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6790 (defun idlwave-struct-inherits ()
6791 "Return a list of all `inherits' names in the struct at point.
6792 Point is expected just before the opening `{' of the struct definition."
6794 (let* ((borders (idlwave-struct-borders))
6797 (case-fold-search t)
6801 (narrow-to-region beg end)
6802 (while (re-search-forward
6803 (concat "[{,]" ;leading comma/brace
6804 idlwave-struct-skip ; 4 groups
6805 "inherits" ; The INHERITS tag
6806 idlwave-struct-skip ; 4 more
6807 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
6809 ;; Check if we are still on the top level of the structure.
6810 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6812 (push (match-string-no-properties 9) names))
6813 (goto-char (match-end 0))))
6816 (defun idlwave-in-structure ()
6817 "Return t if point is inside an IDL structure definition."
6818 (let ((beg (point)))
6820 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6821 (if (idlwave-find-structure-definition nil nil 'back)
6822 (let ((borders (idlwave-struct-borders)))
6823 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6824 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6826 (defun idlwave-struct-borders ()
6827 "Return the borders of the {...} after point as a cons cell."
6830 (skip-chars-forward "^{")
6832 (condition-case nil (forward-list 1)
6833 (error (goto-char beg)))
6834 (cons beg (point)))))
6836 (defun idlwave-find-structure-definition (&optional var name bound)
6837 "Search forward for a structure definition. If VAR is non-nil,
6838 search for a structure assigned to variable VAR. If NAME is non-nil,
6839 search for a named structure NAME, if a string, or a generic named
6840 structure otherwise. If BOUND is an integer, limit the search. If
6841 BOUND is the symbol `all', we search first back and then forward
6842 through the entire file. If BOUND is the symbol `back' we search only
6844 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6845 (case-fold-search t)
6846 (lim (if (integerp bound) bound nil))
6849 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6854 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
6855 ;; Just a generic name
6856 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
6858 (if (or (and (or (eq bound 'all) (eq bound 'back))
6859 (re-search-backward re nil t))
6860 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6862 (goto-char (match-beginning 3))
6863 (match-string-no-properties 5)))))
6865 (defvar idlwave-class-info nil)
6866 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
6867 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
6869 (add-hook 'idlwave-update-rinfo-hook
6870 (lambda () (setq idlwave-class-reset t)))
6871 (add-hook 'idlwave-after-load-rinfo-hook
6872 (lambda () (setq idlwave-class-info nil)))
6874 (defun idlwave-class-info (class)
6876 (if idlwave-class-info
6877 (if idlwave-class-reset
6879 idlwave-class-reset nil
6880 idlwave-class-info ; Remove any visited in a buffer
6884 (idlwave-class-file-or-buffer
6885 (or (cdr (assq 'found-in x)) (car x)))))
6889 idlwave-class-info))))
6890 ;; Info is nil, put in the system stuff to start.
6891 (setq idlwave-class-info idlwave-system-class-info)
6892 (setq list idlwave-class-info)
6893 (while (setq entry (pop list))
6894 (idlwave-sintern-class-info entry)))
6895 (setq class (idlwave-sintern-class class))
6896 (or (assq class idlwave-class-info)
6897 (progn (idlwave-scan-class-info class)
6898 (assq class idlwave-class-info)))))
6900 (defun idlwave-sintern-class-info (entry)
6901 "Sintern the class names in a class-info entry."
6902 (let ((taglist (assq 'tags entry))
6903 (inherits (assq 'inherits entry)))
6904 (setcar entry (idlwave-sintern-class (car entry) 'set))
6906 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6909 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
6910 "Find class structure definition(s)
6911 If ALL-HOOK is set, find all named structure definitions in a given
6912 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
6913 set, look for the name__define pro, and inside of it, for the ALT-CLASS
6914 class/struct definition"
6915 (let ((case-fold-search t) end-lim list name)
6916 (when (re-search-forward
6917 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6920 ;; For everything there
6921 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
6923 (idlwave-find-structure-definition nil t end-lim))
6924 (funcall all-hook name)))
6925 (idlwave-find-structure-definition nil (or alt-class class))))))
6928 (defun idlwave-class-file-or-buffer (class)
6929 "Find buffer visiting CLASS definition"
6930 (let* ((pro (concat (downcase class) "__define"))
6931 (file (idlwave-routine-source-file
6932 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6933 (idlwave-routines))))))
6934 (cons file (if file (idlwave-get-buffer-visiting file)))))
6937 (defun idlwave-scan-class-info (class)
6938 "Scan all class and named structure info in the class__define pro"
6939 (let* ((idlwave-auto-routine-info-updates nil)
6940 (filebuf (idlwave-class-file-or-buffer class))
6941 (file (car filebuf))
6943 (class (idlwave-sintern-class class)))
6946 (and ;; neither a regular file nor a visited buffer
6948 (not (file-regular-p file))))
6949 nil ; Cannot find the file/buffer to get any info
6951 (if buf (set-buffer buf)
6952 ;; Read the file in temporarily
6953 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6955 (unless (eq major-mode 'idlwave-mode)
6957 (insert-file-contents file))
6960 (idlwave-find-class-definition class
6961 ;; Scan all of the structures found there
6963 (let* ((this-class (idlwave-sintern-class name))
6966 (cons 'tags (idlwave-struct-tags))
6967 (cons 'inherits (idlwave-struct-inherits)))))
6968 (if (not (eq this-class class))
6969 (setq entry (nconc entry (list (cons 'found-in class)))))
6970 (idlwave-sintern-class-info entry)
6971 (push entry idlwave-class-info)))))))))
6973 (defun idlwave-class-found-in (class)
6974 "Return the FOUND-IN property of the class."
6975 (cdr (assq 'found-in (idlwave-class-info class))))
6976 (defun idlwave-class-tags (class)
6977 "Return the native tags in CLASS."
6978 (cdr (assq 'tags (idlwave-class-info class))))
6979 (defun idlwave-class-inherits (class)
6980 "Return the direct superclasses of CLASS."
6981 (cdr (assq 'inherits (idlwave-class-info class))))
6984 (defun idlwave-all-class-tags (class)
6985 "Return a list of native and inherited tags in CLASS."
6987 (apply 'append (mapcar 'idlwave-class-tags
6988 (cons class (idlwave-all-class-inherits class))))
6990 (idlwave-class-tag-reset)
6991 (error "%s" (error-message-string err)))))
6994 (defun idlwave-all-class-inherits (class)
6995 "Return a list of all superclasses of CLASS (recursively expanded).
6996 The list is cached in `idlwave-class-info' for faster access."
6998 ((not idlwave-support-inheritance) nil)
6999 ((eq class nil) nil)
7002 (let ((info (idlwave-class-info class))
7004 (if (setq entry (assq 'all-inherits info))
7006 ;; Save the depth of inheritance scan to check for circular references
7007 (let ((inherits (mapcar (lambda (x) (cons x 0))
7008 (idlwave-class-inherits class)))
7009 rtn all-inherits cl)
7011 (setq cl (pop inherits)
7012 rtn (cons (car cl) rtn)
7013 inherits (append (mapcar (lambda (x)
7014 (cons x (1+ (cdr cl))))
7015 (idlwave-class-inherits (car cl)))
7017 (if (> (cdr cl) 999)
7019 "Class scan: inheritance depth exceeded. Circular inheritance?")
7021 (setq all-inherits (nreverse rtn))
7022 (nconc info (list (cons 'all-inherits all-inherits)))
7025 (defun idlwave-entry-keywords (entry &optional record-link)
7026 "Return the flat entry keywords alist from routine-info entry.
7027 If RECORD-LINK is non-nil, the keyword text is copied and a text
7028 property indicating the link is added."
7032 (let ((file (car key-list)))
7033 (mapcar (lambda (key-cons)
7034 (let ((key (car key-cons))
7035 (link (cdr key-cons)))
7036 (when (and record-link file)
7037 (setq key (copy-sequence key))
7044 (concat idlwave-html-link-sep
7045 (number-to-string link))))
7047 (push (list key) kwds)))
7052 (defun idlwave-entry-find-keyword (entry keyword)
7053 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7057 (let ((file (car key-list))
7058 (kwd (assoc keyword (cdr key-list))))
7060 (setq kwd (cons (car kwd)
7061 (if (and file (cdr kwd))
7063 idlwave-html-link-sep
7064 (number-to-string (cdr kwd)))
7066 (throw 'exit kwd))))
7069 ;;==========================================================================
7071 ;; Completing class structure tags. This is a completion plugin.
7072 ;; The necessary taglist is constructed dynamically
7074 (defvar idlwave-current-tags-class nil)
7075 (defvar idlwave-current-class-tags nil)
7076 (defvar idlwave-current-native-class-tags nil)
7077 (defvar idlwave-sint-class-tags nil)
7078 (idlwave-new-sintern-type 'class-tag)
7079 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7080 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7082 (defun idlwave-complete-class-structure-tag ()
7083 "Complete a structure tag on a `self' argument in an object method."
7086 (case-fold-search t))
7088 ;; Check if the context is right
7089 (skip-chars-backward "a-zA-Z0-9._$")
7090 (and (< (point) (- pos 4))
7091 (looking-at "self\\.")))
7092 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7093 (super-classes (idlwave-all-class-inherits class-selector)))
7094 ;; Check if we are in a class routine
7095 (unless class-selector
7096 (error "Not in a method procedure or function"))
7097 ;; Check if we need to update the "current" class
7098 (if (not (equal class-selector idlwave-current-tags-class))
7099 (idlwave-prepare-class-tag-completion class-selector))
7100 (setq idlwave-completion-help-info
7101 (list 'idlwave-complete-class-structure-tag-help
7102 (idlwave-sintern-routine
7103 (concat class-selector "__define"))
7105 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7106 (idlwave-complete-in-buffer
7107 'class-tag 'class-tag
7108 idlwave-current-class-tags nil
7109 (format "Select a tag of class %s" class-selector)
7111 'idlwave-attach-class-tag-classes))
7112 t) ; return t to skip other completions
7115 (defun idlwave-class-tag-reset ()
7116 (setq idlwave-current-tags-class nil))
7118 (defun idlwave-prepare-class-tag-completion (class)
7119 "Find and parse the necessary class definitions for class structure tags."
7120 (setq idlwave-sint-class-tags nil)
7121 (setq idlwave-current-tags-class class)
7122 (setq idlwave-current-class-tags
7124 (list (idlwave-sintern-class-tag x 'set)))
7125 (idlwave-all-class-tags class)))
7126 (setq idlwave-current-native-class-tags
7127 (mapcar 'downcase (idlwave-class-tags class))))
7129 ;===========================================================================
7131 ;; Completing system variables and their structure fields
7132 ;; This is also a plugin.
7134 (defvar idlwave-sint-sysvars nil)
7135 (defvar idlwave-sint-sysvartags nil)
7136 (idlwave-new-sintern-type 'sysvar)
7137 (idlwave-new-sintern-type 'sysvartag)
7138 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7139 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7140 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7142 (defvar idlwave-executive-commands-alist nil
7143 "Alist of system variables and their help files.")
7145 (defvar idlwave-system-variables-alist nil
7146 "Alist of system variables and the associated structure tags.
7147 Gets set in `idlw-rinfo.el'.")
7149 (defun idlwave-complete-sysvar-or-tag ()
7150 "Complete a system variable."
7153 (case-fold-search t))
7154 (cond ((save-excursion
7155 ;; Check if the context is right for system variable
7156 (skip-chars-backward "[a-zA-Z0-9_$]")
7157 (equal (char-before) ?!))
7158 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7159 (idlwave-complete-in-buffer 'sysvar 'sysvar
7160 idlwave-system-variables-alist nil
7161 "Select a system variable"
7163 t) ; return t to skip other completions
7165 ;; Check if the context is right for sysvar tag
7166 (skip-chars-backward "a-zA-Z0-9_$.")
7167 (and (equal (char-before) ?!)
7168 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7169 (<= (match-end 0) pos)))
7170 ;; Complete a system variable tag
7171 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7172 (entry (assq var idlwave-system-variables-alist))
7173 (tags (cdr (assq 'tags entry))))
7174 (or entry (error "!%s is not a known system variable" var))
7175 (or tags (error "System variable !%s is not a structure" var))
7176 (setq idlwave-completion-help-info
7177 (list 'idlwave-complete-sysvar-tag-help var))
7178 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7180 "Select a system variable tag"
7181 "system variable tag")
7182 t)) ; return t to skip other completions
7185 (defvar link) ;dynamic
7186 (defun idlwave-complete-sysvar-help (mode word)
7187 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7188 (entry (assoc word idlwave-system-variables-alist)))
7191 (and (stringp word) entry (nth 1 (assq 'link entry))))
7193 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7194 (t (error "This should not happen")))))
7196 (defun idlwave-complete-sysvar-tag-help (mode word)
7197 (let* ((var (nth 1 idlwave-completion-help-info))
7198 (entry (assoc var idlwave-system-variables-alist))
7199 (tags (cdr (assq 'tags entry)))
7200 (main (nth 1 (assq 'link entry)))
7203 ((eq mode 'test) ; we can at least link the main
7204 (and (stringp word) entry main))
7208 (if (setq target (cdr (assoc word tags)))
7209 (idlwave-substitute-link-target main target)
7210 main)))) ;; setting dynamic!!!
7211 (t (error "This should not happen")))))
7213 (defun idlwave-substitute-link-target (link target)
7214 "Substitute the target anchor for the given link."
7216 (setq main-base (if (string-match "#" link)
7217 (substring link 0 (match-beginning 0))
7220 (concat main-base idlwave-html-link-sep (number-to-string target))
7223 ;; Fake help in the source buffer for class structure tags.
7224 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7227 (defvar idlwave-help-do-class-struct-tag nil)
7228 (defun idlwave-complete-class-structure-tag-help (mode word)
7230 ((eq mode 'test) ; nothing gets fontified for class tags
7233 (let (class-with found-in)
7234 (when (setq class-with
7235 (idlwave-class-or-superclass-with-tag
7236 idlwave-current-tags-class
7238 (if (assq (idlwave-sintern-class class-with)
7239 idlwave-system-class-info)
7240 (error "No help available for system class tags"))
7241 (if (setq found-in (idlwave-class-found-in class-with))
7242 (setq name (cons (concat found-in "__define") class-with))
7243 (setq name (concat class-with "__define")))))
7245 idlwave-help-do-class-struct-tag t))
7246 (t (error "This should not happen"))))
7248 (defun idlwave-class-or-superclass-with-tag (class tag)
7249 "Find and return the CLASS or one of its superclass with the
7250 associated TAG, if any."
7251 (let ((sclasses (cons class (cdr (assq 'all-inherits
7252 (idlwave-class-info class)))))
7256 (setq cl (pop sclasses))
7257 (let ((tags (idlwave-class-tags cl)))
7259 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7261 (setq tags (cdr tags))))))))
7264 (defun idlwave-sysvars-reset ()
7265 (if (and (fboundp 'idlwave-shell-is-running)
7266 (idlwave-shell-is-running)
7267 idlwave-idlwave_routine_info-compiled)
7268 (idlwave-shell-send-command "idlwave_get_sysvars"
7269 'idlwave-process-sysvars 'hide)))
7271 (defun idlwave-process-sysvars ()
7272 (idlwave-shell-filter-sysvars)
7273 (setq idlwave-sint-sysvars nil
7274 idlwave-sint-sysvartags nil)
7275 (idlwave-sintern-sysvar-alist))
7277 (defun idlwave-sintern-sysvar-alist ()
7278 (let ((list idlwave-system-variables-alist) entry tags)
7279 (while (setq entry (pop list))
7280 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7281 (setq tags (assq 'tags entry))
7285 (cons (idlwave-sintern-sysvartag (car x) 'set)
7289 (defvar idlwave-shell-command-output)
7290 (defun idlwave-shell-filter-sysvars ()
7291 "Get any new system variables and tags."
7292 (let ((text idlwave-shell-command-output)
7294 (old idlwave-system-variables-alist)
7295 var tags type name class link old-entry)
7296 (setq idlwave-system-variables-alist nil)
7297 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7299 (setq start (match-end 0)
7300 var (match-string 1 text)
7301 tags (if (match-end 3)
7302 (idlwave-split-string (match-string 3 text))))
7303 ;; Maintain old links, if present
7304 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7305 (setq link (assq 'link old-entry))
7306 (setq idlwave-system-variables-alist
7313 (idlwave-sintern-sysvartag x)
7314 (cdr (assq 'tags old-entry))))))
7316 idlwave-system-variables-alist)))
7317 ;; Keep the old value if query was not successful
7318 (setq idlwave-system-variables-alist
7319 (or idlwave-system-variables-alist old))))
7321 (defun idlwave-completion-fontify-classes ()
7322 "Goto the *Completions* buffer and fontify the class info."
7323 (when (featurep 'font-lock)
7325 (set-buffer "*Completions*")
7327 (goto-char (point-min))
7328 (let ((buffer-read-only nil))
7329 (while (re-search-forward "\\.*<[^>]+>" nil t)
7330 (put-text-property (match-beginning 0) (match-end 0)
7331 'face 'font-lock-string-face)))))))
7333 (defun idlwave-uniquify (list)
7334 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7337 (unless (gethash x ht)
7342 (defun idlwave-after-successful-completion (type slash &optional verify)
7343 "Add `=' or `(' after successful completion of keyword and function.
7344 Restore the pre-completion window configuration if possible."
7346 ((eq type 'procedure)
7348 ((eq type 'function)
7350 ((equal idlwave-function-completion-adds-paren nil) nil)
7351 ((or (equal idlwave-function-completion-adds-paren t)
7352 (equal idlwave-function-completion-adds-paren 1))
7354 ((equal idlwave-function-completion-adds-paren 2)
7359 (if (and idlwave-keyword-completion-adds-equal
7361 (progn (insert "=") t)
7364 ;; Restore the pre-completion window configuration if this is safe.
7366 (if (or (eq verify 'force) ; force
7368 (get-buffer-window "*Completions*") ; visible
7369 (idlwave-local-value 'idlwave-completion-p
7370 "*Completions*") ; cib-buffer
7371 (eq (marker-buffer idlwave-completion-mark)
7372 (current-buffer)) ; buffer OK
7373 (equal (marker-position idlwave-completion-mark)
7375 (idlwave-restore-wconf-after-completion))
7376 (move-marker idlwave-completion-mark nil)
7377 (setq idlwave-before-completion-wconf nil))
7379 (defun idlwave-mouse-context-help (ev &optional arg)
7380 "Call `idlwave-context-help' on the clicked location."
7382 (mouse-set-point ev)
7383 (idlwave-context-help arg))
7385 (defvar idlwave-last-context-help-pos nil)
7386 (defun idlwave-context-help (&optional arg)
7387 "Display IDL Online Help on context.
7388 If point is on a keyword, help for that keyword will be shown. If
7389 point is on a routine name or in the argument list of a routine, help
7390 for that routine will be displayed. Works for system routines and
7391 keywords, it pulls up text help. For other routies and keywords,
7392 visits the source file, finding help in the header (if
7393 `idlwave-help-source-try-header' is non-nil) or the routine definition
7396 (idlwave-do-context-help arg))
7398 (defun idlwave-mouse-completion-help (ev)
7399 "Display online help about the completion at point."
7401 ;; Restore last-command for next command, to make
7402 ;; scrolling/cancelling of completions work.
7403 (setq this-command last-command)
7404 (idlwave-do-mouse-completion-help ev))
7406 (defun idlwave-routine-info (&optional arg external)
7407 "Display a routines calling sequence and list of keywords. When
7408 point is on the name a function or procedure, or in the argument list
7409 of a function or procedure, this command displays a help buffer with
7410 the information. When called with prefix arg, enforce class query.
7412 When point is on an object operator `->', display the class stored in
7413 this arrow, if any (see `idlwave-store-inquired-class'). With a
7414 prefix arg, the class property is cleared out."
7418 (if (string-match "->" (buffer-substring
7419 (max (point-min) (1- (point)))
7420 (min (+ 2 (point)) (point-max))))
7421 ;; Cursor is on an arrow
7422 (if (get-text-property (point) 'idlwave-class)
7423 ;; arrow has class property
7428 (when (looking-at ".?\\(->\\)")
7429 (remove-text-properties (match-beginning 1) (match-end 1)
7430 '(idlwave-class nil face nil))
7431 (message "Class property removed from arrow")))
7432 ;; Echo class property
7433 (message "Arrow has text property identifying object to be class %s"
7434 (get-text-property (point) 'idlwave-class)))
7435 ;; No property found
7436 (message "Arrow has no class text property"))
7438 ;; Not on an arrow...
7439 (let* ((idlwave-query-class nil)
7440 (idlwave-force-class-query (equal arg '(4)))
7441 (module (idlwave-what-module)))
7443 (apply 'idlwave-display-calling-sequence
7444 (idlwave-fix-module-if-obj_new module))
7445 (error "Don't know which calling sequence to show")))))
7447 (defun idlwave-resolve (&optional arg)
7448 "Call RESOLVE_ROUTINE on the module name at point.
7449 Like `idlwave-routine-info', this looks for a routine call at point.
7450 After confirmation in the minibuffer, it will use the shell to issue
7451 a RESOLVE call for this routine, to attempt to make it defined and its
7452 routine info available for IDLWAVE. If the routine is a method call,
7453 both `class__method' and `class__define' will be tried.
7454 With ARG, enforce query for the class of object methods."
7456 (let* ((idlwave-query-class nil)
7457 (idlwave-force-class-query (equal arg '(4)))
7458 (module (idlwave-what-module))
7459 (name (idlwave-make-full-name (nth 2 module) (car module)))
7460 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7461 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7464 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7466 (setq type (match-string 1 resolve)
7467 class (if (match-beginning 2)
7468 (match-string 3 resolve)
7470 name (match-string 4 resolve)))
7471 (if (string= (downcase type) "function")
7472 (setq kwd ",/is_function"))
7476 (idlwave-shell-send-command
7477 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7478 'idlwave-update-routine-info
7481 (idlwave-shell-send-command
7482 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7483 (list 'idlwave-shell-send-command
7484 (format "resolve_routine,'%s__%s'%s"
7485 (downcase class) (downcase name) kwd)
7486 '(idlwave-update-routine-info)
7489 (defun idlwave-find-module-this-file ()
7491 (idlwave-find-module '(4)))
7493 (defun idlwave-find-module (&optional arg)
7494 "Find the source code of an IDL module.
7495 Works for modules for which IDLWAVE has routine info available. The
7496 function offers as default the module name `idlwave-routine-info'
7497 would use. With ARG limit to this buffer. With two prefix ARG's
7498 force class query for object methods."
7500 (let* ((idlwave-query-class nil)
7501 (idlwave-force-class-query (equal arg '(16)))
7502 (this-buffer (equal arg '(4)))
7503 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7505 (concat (idlwave-make-full-name
7506 (nth 2 module) (car module))
7507 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7513 (if (eq 'system (car-safe (nth 3 x)))
7514 ;; Take out system routines with no source.
7517 (concat (idlwave-make-full-name
7519 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7521 (idlwave-save-buffer-update)
7522 (idlwave-routines))))))
7523 (name (idlwave-completing-read
7524 (if (or (not this-buffer)
7525 (assoc default list))
7526 (format "Module (Default %s): " default)
7527 (format "Module in this file: "))
7530 (if (string-match "\\`\\s-*\\'" name)
7531 ;; Nothing, use the default.
7532 (setq name default))
7533 (if (string-match "<[fp]>" name)
7534 (setq type (substring name -2 -1)
7535 name (substring name 0 -3)))
7536 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7537 (setq class (match-string 1 name)
7538 name (match-string 2 name)))
7539 (setq name (idlwave-sintern-routine-or-method name class)
7540 class (idlwave-sintern-class class)
7541 type (cond ((equal type "f") 'fun)
7542 ((equal type "p") 'pro)
7544 (idlwave-do-find-module name type class nil this-buffer)))
7546 (defun idlwave-do-find-module (name type class
7547 &optional force-source this-buffer)
7548 (let ((name1 (idlwave-make-full-name class name))
7550 (buf (current-buffer))
7553 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7555 source (or force-source (nth 3 entry))
7556 name2 (if (nth 2 entry)
7557 (idlwave-make-full-name (nth 2 entry) name)
7560 (setq file (idlwave-routine-source-file source)))
7561 (unless file ; Try to find it on the path.
7563 (idlwave-expand-lib-file-name
7565 (format "%s__define.pro" (downcase class))
7566 (format "%s.pro" (downcase name))))))
7568 ((or (null name) (equal name ""))
7570 ((eq (car source) 'system)
7571 (error "Source code for system routine %s is not available"
7573 ((or (not file) (not (file-regular-p file)))
7574 (error "Source code for routine %s is not available"
7577 (when (not this-buffer)
7579 (idlwave-find-file-noselect file 'find))
7580 (pop-to-buffer buf1 t))
7581 (goto-char (point-max))
7582 (let ((case-fold-search t))
7583 (if (re-search-backward
7584 (concat "^[ \t]*\\<"
7585 (cond ((eq type 'fun) "function")
7586 ((eq type 'pro) "pro")
7587 (t "\\(pro\\|function\\)"))
7589 (regexp-quote (downcase name2))
7592 (goto-char (match-beginning 0))
7595 (error "Could not find routine %s" name2)))))))
7597 (defun idlwave-what-module ()
7598 "Return a default module for stuff near point.
7599 Used by `idlwave-routine-info' and `idlwave-find-module'."
7601 (if (let ((case-fold-search t))
7603 (idlwave-beginning-of-statement)
7604 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7605 ;; This is a function or procedure definition statement
7606 ;; We return the defined routine as module.
7608 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
7609 (match-string-no-properties 2))
7610 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7611 (idlwave-sintern-class (match-string 3)))
7613 ;; Not a definition statement - analyze precise position.
7614 (let* ((where (idlwave-where))
7616 (pro (car (nth 0 where)))
7617 (func (car (nth 1 where)))
7618 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7619 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7623 ((and (eq cw 'procedure)
7624 (not (equal this-word "")))
7625 (setq this-word (idlwave-sintern-routine-or-method
7626 this-word (nth 2 (nth 3 where))))
7627 (list this-word 'pro
7628 (idlwave-determine-class
7629 (cons this-word (cdr (nth 3 where)))
7631 ((and (eq cw 'function)
7632 (not (equal this-word ""))
7633 (or (eq next-char ?\() ; exclude arrays, vars.
7634 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7635 (setq this-word (idlwave-sintern-routine-or-method
7636 this-word (nth 2 (nth 3 where))))
7637 (list this-word 'fun
7638 (idlwave-determine-class
7639 (cons this-word (cdr (nth 3 where)))
7641 ((and (memq cw '(function-keyword procedure-keyword))
7642 (not (equal this-word ""))
7643 (eq next-char ?\()) ; A function!
7644 (setq this-word (idlwave-sintern-routine this-word))
7645 (list this-word 'fun nil))
7647 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7649 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7652 (defun idlwave-what-module-find-class ()
7653 "Call idlwave-what-module and find the inherited class if necessary."
7654 (let* ((module (idlwave-what-module))
7655 (class (nth 2 module))
7657 (if (and (= (length module) 3)
7661 (apply 'idlwave-find-inherited-class module))
7664 (defun idlwave-find-inherited-class (name type class)
7665 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7666 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7671 (defun idlwave-fix-module-if-obj_new (module)
7672 "Check if MODULE points to obj_new.
7673 If yes, and if the cursor is in the keyword region, change to the
7674 appropriate Init method."
7675 (let* ((name (car module))
7677 (case-fold-search t)
7679 (if (and (stringp name)
7680 (equal (downcase name) "obj_new")
7682 (idlwave-beginning-of-statement)
7683 (setq string (buffer-substring (point) pos))
7684 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7687 (class (match-string 1 string)))
7688 (setq module (list (idlwave-sintern-method "Init")
7690 (idlwave-sintern-class class)))))
7693 (defun idlwave-fix-keywords (name type class keywords
7694 &optional super-classes system)
7695 "Update a list of keywords.
7696 Translate OBJ_NEW, adding all super-class keywords, or all keywords
7697 from all classes if class equals t. If SYSTEM is non-nil, don't
7698 demand _EXTRA in the keyword list."
7699 (let ((case-fold-search t))
7701 ;; If this is the OBJ_NEW function, try to figure out the class and use
7702 ;; the keywords from the corresponding INIT method.
7703 (if (and (equal (upcase name) "OBJ_NEW")
7704 (or (eq major-mode 'idlwave-mode)
7705 (eq major-mode 'idlwave-shell-mode)))
7706 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7707 (string (buffer-substring bos (point)))
7708 (case-fold-search t)
7710 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7712 (setq class (idlwave-sintern-class (match-string 1 string)))
7713 (setq idlwave-current-obj_new-class class)
7716 (idlwave-entry-keywords
7718 (idlwave-sintern-method "INIT")
7721 (idlwave-routines)) 'do-link))))))
7723 ;; If the class is `t', combine all keywords of all methods NAME
7725 (mapc (lambda (entry)
7727 (nth 2 entry) ; non-nil class
7728 (eq (nth 1 entry) type) ; correct type
7731 (idlwave-entry-keywords entry 'do-link)))))
7732 (idlwave-all-assq name (idlwave-routines)))
7733 (setq keywords (idlwave-uniquify keywords)))
7735 ;; If we have inheritance, add all keywords from superclasses, if
7736 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
7739 idlwave-keyword-class-inheritance
7743 (assq (idlwave-sintern-keyword "_extra") keywords)
7744 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7745 ;; Check if one of the keyword-class regexps matches the name
7746 (let ((regexps idlwave-keyword-class-inheritance) re)
7748 (while (setq re (pop regexps))
7749 (if (string-match re name) (throw 'exit t))))))
7751 (loop for entry in (idlwave-routines) do
7752 (and (nth 2 entry) ; non-nil class
7753 (memq (nth 2 entry) super-classes) ; an inherited class
7754 (eq (nth 1 entry) type) ; correct type
7755 (eq (car entry) name) ; correct name
7756 (mapcar (lambda (k) (add-to-list 'keywords k))
7757 (idlwave-entry-keywords entry 'do-link))))
7758 (setq keywords (idlwave-uniquify keywords)))
7760 ;; Return the final list
7763 (defun idlwave-expand-keyword (keyword module)
7764 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
7765 KEYWORD may be an exact match or an abbreviation of a keyword.
7766 If the match is exact, KEYWORD itself is returned, even if there may be other
7767 keywords of which KEYWORD is an abbreviation. This is necessary because some
7768 system routines have keywords which are prefixes of other keywords.
7769 If KEYWORD is an abbreviation of several keywords, a list of all possible
7770 completions is returned.
7771 If the abbreviation was unique, the correct keyword is returned.
7772 If it cannot be a keyword, the function return nil.
7773 If we do not know about MODULE, just return KEYWORD literally."
7774 (let* ((name (car module))
7775 (type (nth 1 module))
7776 (class (nth 2 module))
7777 (kwd (idlwave-sintern-keyword keyword))
7778 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7779 (kwd-alist (idlwave-entry-keywords entry))
7780 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7781 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7782 (completion-ignore-case t)
7784 (cond ((assq kwd kwd-alist)
7786 ((setq candidates (all-completions kwd kwd-alist))
7787 (if (= (length candidates) 1)
7791 ;; Inheritance may cause this keyword to be correct
7794 ;; We do know the function, which does not have the keyword.
7797 ;; We do not know the function, so this just might be a correct
7798 ;; keyword - return it as it is.
7801 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7802 (defvar idlwave-rinfo-map (make-sparse-keymap))
7803 (define-key idlwave-rinfo-mouse-map
7804 (if (featurep 'xemacs) [button2] [mouse-2])
7805 'idlwave-mouse-active-rinfo)
7806 (define-key idlwave-rinfo-mouse-map
7807 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7808 'idlwave-mouse-active-rinfo-shift)
7809 (define-key idlwave-rinfo-mouse-map
7810 (if (featurep 'xemacs) [button3] [mouse-3])
7811 'idlwave-mouse-active-rinfo-right)
7812 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7813 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7814 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7815 (defvar idlwave-popup-source nil)
7816 (defvar idlwave-rinfo-marker (make-marker))
7818 (defun idlwave-quit-help ()
7820 (let ((ri-window (get-buffer-window "*Help*"))
7821 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7822 (when (and olh-window
7823 (fboundp 'idlwave-help-quit))
7824 (select-window olh-window)
7825 (idlwave-help-quit))
7826 (when (window-live-p ri-window)
7827 (delete-window ri-window))))
7829 (defun idlwave-display-calling-sequence (name type class
7830 &optional initial-class)
7831 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7832 (let* ((initial-class (or initial-class class))
7833 (entry (or (idlwave-best-rinfo-assq name type class
7835 (idlwave-rinfo-assq name type class
7836 idlwave-unresolved-routines)))
7837 (name (or (car entry) name))
7838 (class (or (nth 2 entry) class))
7839 (superclasses (idlwave-all-class-inherits initial-class))
7840 (twins (idlwave-routine-twins entry))
7841 (dtwins (idlwave-study-twins twins))
7843 (system (eq (car (nth 3 entry)) 'system))
7844 (calling-seq (nth 4 entry))
7845 (keywords (idlwave-entry-keywords entry 'do-link))
7846 (html-file (car (nth 5 entry)))
7848 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
7850 "Button2/3: Online Help")
7852 "Button2: Jump to source and back | Button3: Source in Help window.")
7854 "Button2: Display info about same method in superclass")
7856 (data (list name type class (current-buffer) nil initial-class))
7857 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7858 (face 'idlwave-help-link-face)
7859 beg props win cnt total)
7860 ;; Fix keywords, but don't add chained super-classes, since these
7861 ;; are shown separately for that super-class
7862 (setq keywords (idlwave-fix-keywords name type class keywords))
7865 (error "No %s %s known %s" type name
7866 (if initial-class (concat "in class " initial-class) "")))
7867 ((or (null name) (equal name ""))
7868 (error "No function or procedure call at point"))
7870 (error "Calling sequence of %s %s not available" type name))
7873 (move-marker idlwave-rinfo-marker (point))
7874 (set-buffer (get-buffer-create "*Help*"))
7875 (use-local-map idlwave-rinfo-map)
7876 (setq buffer-read-only nil)
7878 (set (make-local-variable 'idlwave-popup-source) nil)
7879 (set (make-local-variable 'idlwave-current-obj_new-class)
7880 idlwave-current-obj_new-class)
7882 (setq props (list 'mouse-face 'highlight
7883 km-prop idlwave-rinfo-mouse-map
7884 'help-echo help-echo-class
7885 'data (cons 'class data)))
7886 (let ((classes (cons initial-class superclasses)) c)
7887 (insert "Classes: ")
7888 (while (setq c (pop classes))
7892 (if (equal (downcase c) (downcase class))
7893 (add-text-properties beg (point) (list 'face 'bold))
7894 ;; If Method exists in a different class link it
7895 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7896 (add-text-properties beg (point) props))))
7898 (setq props (list 'mouse-face 'highlight
7899 km-prop idlwave-rinfo-mouse-map
7900 'help-echo help-echo-use
7901 'data (cons 'usage data)))
7902 (if html-file (setq props (append (list 'face face 'link html-file)
7907 (format calling-seq class name class name class name)
7908 (format calling-seq name name name name))
7910 (add-text-properties beg (point) props)
7912 (insert "Keywords:")
7914 (insert " No keywords accepted.")
7918 (if (>= (+ col 1 (length (car x)))
7925 ;; Relevant keywords already have link property attached
7926 props (list 'mouse-face 'highlight
7927 km-prop idlwave-rinfo-mouse-map
7928 'data (cons 'keyword data)
7929 'help-echo help-echo-kwd
7931 (if system (setq props (append (list 'face face) props)))
7933 (add-text-properties beg (point) props)
7934 (setq col (+ col 1 (length (car x)))))
7937 (setq cnt 1 total (length all))
7938 ;; Here entry is (key file (list of type-conses))
7939 (while (setq entry (pop all))
7940 (setq props (list 'mouse-face 'highlight
7941 km-prop idlwave-rinfo-mouse-map
7942 'help-echo help-echo-src
7943 'source (list (car (car (nth 2 entry))) ;type
7946 (cdr (car (nth 2 entry))))
7947 'data (cons 'source data)))
7948 (idlwave-insert-source-location
7951 (if (> total 1) "Sources:" "Source:")
7953 (if (> total 1) "- " ""))
7956 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7957 ;; No more source lines, please
7959 "\n Source information truncated to %d entries."
7960 idlwave-rinfo-max-source-lines))
7962 (goto-char (point-min))
7963 (setq buffer-read-only t))
7964 (display-buffer "*Help*")
7965 (if (and (setq win (get-buffer-window "*Help*"))
7966 idlwave-resize-routine-help-window)
7968 (let ((ww (selected-window)))
7972 (enlarge-window (- (/ (frame-height) 2)
7974 (shrink-window-if-larger-than-buffer))
7975 (select-window ww)))))))))
7977 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7978 "Insert a source location into the routine info buffer.
7979 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
7981 (let* ((key (car entry))
7982 (file (nth 1 entry))
7983 (types (nth 2 entry))
7984 (shell-flag (assq 'compiled types))
7985 (buffer-flag (assq 'buffer types))
7986 (user-flag (assq 'user types))
7987 (lib-flag (assq 'lib types))
7988 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
7989 (and user-flag (idlwave-count-memq 'user types))
7990 (and lib-flag (idlwave-count-memq 'lib types))
8004 (insert "Builtin "))
8006 ((and (not file) shell-flag)
8007 (insert "Unresolved"))
8012 ((idlwave-syslib-p file)
8013 (if (string-match "obsolete" (file-name-directory file))
8014 (insert "Obsolete ")
8015 (insert "SystemLib ")))
8017 ;; New special syntax: taken directly from routine-info for
8018 ;; library catalog routines
8019 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8020 (insert (format "%-10s" special)))
8022 ;; Old special syntax: a matching regexp
8023 ((setq special (idlwave-special-lib-test file))
8024 (insert (format "%-10s" special)))
8026 ;; Catch-all with file
8027 ((idlwave-lib-p file) (insert "Library "))
8030 (t (insert "Other ")))
8035 (if lib-flag "L" "-")
8036 (if user-flag "C" "-")
8037 (if shell-flag "S" "-")
8038 (if buffer-flag "B" "-")
8042 (insert (format "(%dx) " ndupl))
8043 (add-text-properties beg (point) (list 'face 'bold)))
8044 (when (and file (not (equal file "")))
8046 (insert (apply 'abbreviate-file-name
8047 (if (featurep 'xemacs) (list file t) (list file))))
8049 (add-text-properties beg (point) file-props)))))
8051 (defun idlwave-special-lib-test (file)
8052 "Check the path of FILE against the regexps which define special libs.
8053 Return the name of the special lib if there is a match."
8054 (let ((alist idlwave-special-lib-alist)
8058 (while (setq entry (pop alist))
8059 (if (string-match (car entry) file)
8060 (setq rtn (cdr entry)
8065 (defun idlwave-mouse-active-rinfo-right (ev)
8067 (idlwave-mouse-active-rinfo ev 'right))
8069 (defun idlwave-mouse-active-rinfo-shift (ev)
8071 (idlwave-mouse-active-rinfo ev nil 'shift))
8073 (defun idlwave-active-rinfo-space ()
8075 (idlwave-mouse-active-rinfo nil 'right))
8077 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8078 "Does the mouse actions in the routine info buffer.
8079 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8082 (if ev (mouse-set-point ev))
8083 (let (data id name type class buf bufwin source link keyword
8085 (setq data (get-text-property (point) 'data)
8086 source (get-text-property (point) 'source)
8087 keyword (get-text-property (point) 'keyword)
8088 link (get-text-property (point) 'link)
8090 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8092 initial-class (nth 6 data)
8093 word (idlwave-this-word)
8094 bufwin (get-buffer-window buf t))
8096 (cond ((eq id 'class) ; Switch class being displayed
8097 (if (window-live-p bufwin) (select-window bufwin))
8098 (idlwave-display-calling-sequence
8099 (idlwave-sintern-method name)
8100 type (idlwave-sintern-class word)
8102 ((eq id 'usage) ; Online help on this routine
8103 (idlwave-online-help link name type class))
8104 ((eq id 'source) ; Source in help or buffer
8106 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8107 (idlwave-help-source-try-header nil)
8108 ;; Fake idlwave-routines so help will find the right entry
8110 (list (list name type class source ""))))
8111 (idlwave-help-get-special-help name type class nil))
8112 ;; Otherwise just pop to the source
8113 (setq idlwave-popup-source (not idlwave-popup-source))
8114 (if idlwave-popup-source
8116 (idlwave-do-find-module name type class source)
8118 (setq idlwave-popup-source nil)
8119 (if (window-live-p bufwin) (select-window bufwin))
8120 (error (nth 1 err))))
8122 (select-window bufwin)
8123 (pop-to-buffer buf))
8124 (goto-char (marker-position idlwave-rinfo-marker)))))
8127 (idlwave-online-help link name type class keyword)
8128 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8130 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8131 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8132 (let ((bwin (get-buffer-window buffer)))
8133 (if idlwave-complete-empty-string-as-lower-case
8134 (setq keyword (downcase keyword)))
8136 (select-window bwin)
8137 (pop-to-buffer buffer)
8138 (setq bwin (get-buffer-window buffer)))
8139 (if (eq (preceding-char) ?/)
8141 (unless (save-excursion
8143 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8144 (min (- (point) 100) (point-min)) t))
8146 (if shift (insert "/"))
8148 (if (and (not shift)
8149 idlwave-keyword-completion-adds-equal)
8152 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8153 "List the load path shadows of all routines defined in current buffer."
8156 (if (eq major-mode 'idlwave-mode)
8157 (idlwave-list-load-path-shadows
8158 nil (idlwave-update-current-buffer-info 'save-buffer)
8159 "in current buffer")
8160 (error "Current buffer is not in idlwave-mode")))
8162 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8163 "List the load path shadows of all routines compiled under the shell.
8164 This is very useful for checking an IDL application. Just compile the
8165 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8166 routines and update IDLWAVE internal info. Then check for shadowing
8170 ((or (not (fboundp 'idlwave-shell-is-running))
8171 (not (idlwave-shell-is-running)))
8172 (error "Shell is not running"))
8173 ((null idlwave-compiled-routines)
8174 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8176 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8179 (defun idlwave-list-all-load-path-shadows (&optional arg)
8180 "List the load path shadows of all routines known to IDLWAVE."
8182 (idlwave-list-load-path-shadows nil nil "globally"))
8184 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8185 "List the routines which are defined multiple times.
8186 Search the information IDLWAVE has about IDL routines for multiple
8188 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8190 When IDL hits a routine call which is not defined, it will search on
8191 the load path in order to find a definition. The output of this
8192 command can be used to detect possible name clashes during this process."
8193 (idlwave-routines) ; Make sure everything is loaded.
8194 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8196 "You don't have any user or library catalogs. Continue anyway? ")
8198 (let* ((routines (append idlwave-system-routines
8199 idlwave-compiled-routines
8200 idlwave-library-catalog-routines
8201 idlwave-user-catalog-routines
8202 idlwave-buffer-routines
8204 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8205 (keymap (make-sparse-keymap))
8206 (props (list 'mouse-face 'highlight
8208 'help-echo "Mouse2: Find source"))
8209 (nroutines (length (or special-routines routines)))
8210 (step (/ nroutines 99))
8214 (idlwave-sort-prefer-buffer-info nil)
8215 routine twins dtwins twin done props1 lroutines)
8217 (if special-routines
8218 ;; Just looking for shadows of a few special routines
8219 (setq lroutines routines
8220 routines special-routines))
8222 (message "Sorting routines...")
8223 (setq routines (sort routines
8225 (string< (downcase (idlwave-make-full-name
8227 (downcase (idlwave-make-full-name
8228 (nth 2 b) (car b)))))))
8229 (message "Sorting routines...done")
8231 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8234 (mouse-set-point ev)
8235 (apply 'idlwave-do-find-module
8236 (get-text-property (point) 'find-args))))
8237 (define-key keymap [(return)]
8240 (apply 'idlwave-do-find-module
8241 (get-text-property (point) 'find-args))))
8242 (message "Compiling list...( 0%%)")
8244 (set-buffer (get-buffer-create "*Shadows*"))
8245 (setq buffer-read-only nil)
8247 (while (setq routine (pop routines))
8249 (if (= (* next-perc step) n)
8251 (message "Compiling list...(%2d%%)" next-perc)
8252 (setq next-perc (1+ next-perc))))
8253 ;; Get a list of all twins
8254 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8255 (if (memq routine done)
8257 (setq dtwins (idlwave-study-twins twins)))
8258 ;; Mark all twins as dealt with
8259 (setq done (append twins done))
8260 (when (or (> (length dtwins) 1)
8261 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8262 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8263 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8265 (insert (format "\n%s%s"
8266 (idlwave-make-full-name (nth 2 routine)
8268 (if (eq (nth 1 routine) 'fun) "()" "")))
8269 (while (setq twin (pop dtwins))
8270 (setq props1 (append (list 'find-args
8271 (list (nth 0 routine)
8275 (idlwave-insert-source-location "\n - " twin props1))))
8276 (goto-char (point-min))
8277 (setq buffer-read-only t))
8278 (setq loc (or loc ""))
8281 (display-buffer (get-buffer "*Shadows*"))
8282 (message "%d case%s of shadowing found %s"
8283 cnt (if (= cnt 1) "" "s") loc))
8284 (message "No shadowing conflicts found %s" loc))))
8286 (defun idlwave-print-source (routine)
8287 (let* ((source (nth 3 routine))
8288 (stype (car source))
8289 (sfile (idlwave-routine-source-file source)))
8290 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8291 (if (and (eq stype 'compiled)
8292 (or (not (stringp sfile))
8293 (not (string-match "\\S-" sfile))))
8294 (setq stype 'unresolved))
8295 (princ (format " %-10s %s\n"
8297 (if sfile sfile "No source code available")))))
8299 (defun idlwave-routine-twins (entry &optional list)
8300 "Return all twin entries of ENTRY in LIST.
8301 LIST defaults to `idlwave-routines'.
8302 Twin entries are those which have the same name, type, and class.
8303 ENTRY will also be returned, as the first item of this list."
8304 (let* ((name (car entry))
8305 (type (nth 1 entry))
8306 (class (nth 2 entry))
8307 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8309 (while (setq candidate (pop candidates))
8310 (if (and (not (eq candidate entry))
8311 (eq type (nth 1 candidate))
8312 (eq class (nth 2 candidate)))
8313 (push candidate twins)))
8314 (if (setq candidate (idlwave-rinfo-assq name type class
8315 idlwave-unresolved-routines))
8316 (push candidate twins))
8317 (cons entry (nreverse twins))))
8319 (defun idlwave-study-twins (entries)
8320 "Return dangerous twins of first entry in ENTRIES.
8321 Dangerous twins are routines with same name, but in different files on
8322 the load path. If a file is in the system library and has an entry in
8323 the `idlwave-system-routines' list, we omit the latter as
8324 non-dangerous because many IDL routines are implemented as library
8325 routines, and may have been scanned."
8326 (let* ((entry (car entries))
8327 (name (car entry)) ;
8328 (type (nth 1 entry)) ; Must be bound for
8329 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8331 source type type-cons file alist syslibp key)
8332 (while (setq entry (pop entries))
8334 (setq source (nth 3 entry)
8336 type-cons (cons type (nth 3 source))
8337 file (idlwave-routine-source-file source))
8339 ;; Make KEY to index entry properly
8340 (setq key (cond ((eq type 'system) type)
8341 (file (file-truename file))
8344 ;; Check for an entry in the system library
8347 (idlwave-syslib-p file))
8350 ;; If there's more than one matching entry for the same file, just
8351 ;; append the type-cons to the type list.
8352 (if (setq entry (assoc key alist))
8353 (push type-cons (nth 2 entry))
8354 (push (list key file (list type-cons)) alist)))
8356 (setq alist (nreverse alist))
8359 ;; File is in system *library* - remove any 'system entry
8360 (setq alist (delq (assq 'system alist) alist)))
8362 ;; If 'system remains and we've scanned the syslib, it's a builtin
8363 ;; (rather than a !DIR/lib/.pro file bundled as source).
8364 (when (and (idlwave-syslib-scanned-p)
8365 (setq entry (assoc 'system alist)))
8366 (setcar entry 'builtin))
8367 (sort alist 'idlwave-routine-twin-compare)))
8371 (defvar idlwave-sort-prefer-buffer-info t
8372 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8374 (defmacro idlwave-xor (a b)
8378 (defun idlwave-routine-entry-compare (a b)
8379 "Compare two routine info entries for sortiung. This is the general case.
8380 It first compates class, names, and type. If it turns out that A and B
8381 are twins (same name, class, and type), calls another routine which
8382 compares twins on the basis of their file names and path locations."
8383 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8385 ((not (equal (idlwave-downcase-safe class)
8386 (idlwave-downcase-safe (nth 2 b))))
8388 (cond ((null (nth 2 b)) nil)
8390 (t (string< (downcase class) (downcase (nth 2 b))))))
8391 ((not (equal (downcase name) (downcase (car b))))
8393 (string< (downcase name) (downcase (car b))))
8394 ((not (eq type (nth 1 b)))
8396 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8398 ;; A and B are twins - so the decision is more complicated.
8399 ;; Call twin-compare with the proper arguments.
8400 (idlwave-routine-entry-compare-twins a b)))))
8402 (defun idlwave-routine-entry-compare-twins (a b)
8403 "Compare two routine entries, under the assumption that they are
8404 twins. This basically calls `idlwave-routine-twin-compare' with the
8406 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8411 (afile (idlwave-routine-source-file asrc))
8412 (bfile (idlwave-routine-source-file bsrc)))
8413 (idlwave-routine-twin-compare
8415 (list (file-truename afile) afile (list atype))
8416 (list atype afile (list atype)))
8418 (list (file-truename bfile) bfile (list btype))
8419 (list btype bfile (list btype))))
8422 (defun idlwave-routine-twin-compare (a b)
8423 "Compare two routine twin entries for sorting.
8424 In here, A and B are not normal routine info entries, but special
8425 lists (KEY FILENAME (TYPES...)).
8426 This expects NAME TYPE CLASS to be bound to the right values."
8427 (let* (;; Dis-assemble entries
8428 (akey (car a)) (bkey (car b))
8429 (afile (nth 1 a)) (bfile (nth 1 b))
8430 (atypes (nth 2 a)) (btypes (nth 2 b))
8432 (asysp (memq akey '(builtin system)))
8433 (bsysp (memq bkey '(builtin system)))
8434 ;; Compiled routines?
8435 (acompp (memq 'compiled atypes))
8436 (bcompp (memq 'compiled btypes))
8438 (aunresp (or (eq akey 'unresolved)
8439 (and acompp (not afile))))
8440 (bunresp (or (eq bkey 'unresolved)
8441 (and bcompp (not bfile))))
8442 ;; Buffer info available?
8443 (abufp (memq 'buffer atypes))
8444 (bbufp (memq 'buffer btypes))
8446 (tpath-alist (idlwave-true-path-alist))
8447 (apathp (and (stringp akey)
8448 (assoc (file-name-directory akey) tpath-alist)))
8449 (bpathp (and (stringp bkey)
8450 (assoc (file-name-directory bkey) tpath-alist)))
8451 ;; How early on search path? High number means early since we
8452 ;; measure the tail of the path list
8453 (anpath (length (memq apathp tpath-alist)))
8454 (bnpath (length (memq bpathp tpath-alist)))
8455 ;; Look at file names
8456 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8457 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8458 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8459 (regexp-quote (downcase class))
8460 (regexp-quote (downcase name)))
8461 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8462 ;; Is file name derived from the routine name?
8463 ;; Method file or class definition file?
8464 (anamep (string-match fname-re aname))
8465 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8466 (bnamep (string-match fname-re bname))
8467 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8469 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8470 ;; doesn't it? The difficult stuff is hidden above...
8472 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8473 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8474 ((and idlwave-sort-prefer-buffer-info
8475 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8476 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8477 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8478 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8479 ((and class anamep bnamep ; both file names match ->
8480 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8481 ((> anpath bnpath) t) ; Who is first on path?
8482 (t nil)))) ; Default
8484 (defun idlwave-routine-source-file (source)
8486 (expand-file-name (nth 1 source) (nth 2 source))
8489 (defun idlwave-downcase-safe (string)
8490 "Donwcase if string, else return unchanged."
8491 (if (stringp string)
8495 (defun idlwave-count-eq (elt list)
8496 "How often is ELT in LIST?"
8497 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8499 (defun idlwave-count-memq (elt alist)
8500 "How often is ELT a key in ALIST?"
8501 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8503 (defun idlwave-syslib-p (file)
8504 "Non-nil if FILE is in the system library."
8505 (let* ((true-syslib (file-name-as-directory
8507 (expand-file-name "lib" (idlwave-sys-dir)))))
8508 (true-file (file-truename file)))
8509 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8511 (defun idlwave-lib-p (file)
8512 "Non-nil if file is in the library"
8513 (let ((true-dir (file-name-directory (file-truename file))))
8514 (assoc true-dir (idlwave-true-path-alist))))
8516 (defun idlwave-path-alist-add-flag (list-entry flag)
8517 "Add a flag to the path list entry, if not set."
8518 (let ((flags (cdr list-entry)))
8519 (add-to-list 'flags flag)
8520 (setcdr list-entry flags)))
8522 (defun idlwave-path-alist-remove-flag (list-entry flag)
8523 "Remove a flag to the path list entry, if set."
8524 (let ((flags (delq flag (cdr list-entry))))
8525 (setcdr list-entry flags)))
8527 (defun idlwave-true-path-alist ()
8528 "Return `idlwave-path-alist' alist with true-names.
8529 Info is cached, but relies on the functions setting `idlwave-path-alist'
8530 to reset the variable `idlwave-true-path-alist' to nil."
8531 (or idlwave-true-path-alist
8532 (setq idlwave-true-path-alist
8533 (mapcar (lambda(x) (cons
8534 (file-name-as-directory
8536 (directory-file-name
8539 idlwave-path-alist))))
8541 (defun idlwave-syslib-scanned-p ()
8542 "Non-nil if the system lib file !DIR/lib has been scanned."
8543 (let* ((true-syslib (file-name-as-directory
8545 (expand-file-name "lib" (idlwave-sys-dir))))))
8546 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8548 ;; ----------------------------------------------------------------------------
8550 ;; Online Help display
8553 ;; ----------------------------------------------------------------------------
8555 ;; Additions for use with imenu.el and func-menu.el
8556 ;; (pop-up a list of IDL units in the current file).
8559 (defun idlwave-prev-index-position ()
8560 "Search for the previous procedure or function.
8561 Return nil if not found. For use with imenu.el."
8564 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
8565 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
8568 (defun idlwave-unit-name ()
8569 "Return the unit name.
8570 Assumes that point is at the beginning of the unit as found by
8571 `idlwave-prev-index-position'."
8574 (let ((begin (point)))
8576 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
8577 (if (fboundp 'buffer-substring-no-properties)
8578 (buffer-substring-no-properties begin (point))
8579 (buffer-substring begin (point)))))
8581 (defalias 'idlwave-function-menu
8584 (require 'func-menu)
8586 (error (condition-case nil
8592 ;; Here we hack func-menu.el in order to support this new mode.
8593 ;; The latest versions of func-menu.el already have this stuff in, so
8594 ;; we hack only if it is not already there.
8595 (when (fboundp 'eval-after-load)
8596 (eval-after-load "func-menu"
8598 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
8599 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
8600 (setq fume-function-name-regexp-alist
8601 (cons '(idlwave-mode . fume-function-name-regexp-idl)
8602 fume-function-name-regexp-alist)))
8603 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
8604 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
8605 (setq fume-find-function-name-method-alist
8606 (cons '(idlwave-mode . fume-find-next-idl-function-name)
8607 fume-find-function-name-method-alist))))))
8609 (defun idlwave-edit-in-idlde ()
8610 "Edit the current file in IDL Development environment."
8612 (start-process "idldeclient" nil
8613 idlwave-shell-explicit-file-name "-c" "-e"
8614 (buffer-file-name) "&"))
8616 (defun idlwave-launch-idlhelp ()
8617 "Start the IDLhelp application."
8619 (start-process "idlhelp" nil idlwave-help-application))
8621 ;; Menus - using easymenu.el
8622 (defvar idlwave-mode-menu-def
8624 ["PRO/FUNC menu" idlwave-function-menu t]
8626 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8627 ["Subprogram End" idlwave-end-of-subprogram t]
8628 ["Block Start" idlwave-beginning-of-block t]
8629 ["Block End" idlwave-end-of-block t]
8630 ["Up Block" idlwave-backward-up-block t]
8631 ["Down Block" idlwave-down-block t]
8632 ["Skip Block Backward" idlwave-backward-block t]
8633 ["Skip Block Forward" idlwave-forward-block t])
8635 ["Subprogram" idlwave-mark-subprogram t]
8636 ["Block" idlwave-mark-block t]
8637 ["Header" idlwave-mark-doclib t])
8639 ["Indent Subprogram" idlwave-indent-subprogram t]
8640 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8641 ["Continue/Split line" idlwave-split-line t]
8643 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8644 :selected (symbol-value idlwave-fill-function)])
8646 ["Procedure" idlwave-procedure t]
8647 ["Function" idlwave-function t]
8648 ["Doc Header" idlwave-doc-header t]
8649 ["Log" idlwave-doc-modification t]
8651 ["Case" idlwave-case t]
8652 ["For" idlwave-for t]
8653 ["Repeat" idlwave-repeat t]
8654 ["While" idlwave-while t]
8656 ["Close Block" idlwave-close-block t])
8658 ["Complete" idlwave-complete t]
8660 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8661 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8663 ["3 Function Name" (idlwave-complete 'function) t]
8664 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8666 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8667 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8669 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8670 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8672 ["9 Class Name" idlwave-complete-class t]))
8674 ["Show Routine Info" idlwave-routine-info t]
8675 ["Online Context Help" idlwave-context-help t]
8677 ["Find Routine Source" idlwave-find-module t]
8678 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8680 ["Update Routine Info" idlwave-update-routine-info t]
8683 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
8684 ["Scan Directories" (idlwave-update-routine-info '(16))
8685 (and idlwave-path-alist (not idlwave-catalog-process))]
8686 ["Scan Directories &" (idlwave-update-routine-info '(64))
8687 (and idlwave-path-alist (not idlwave-catalog-process))]
8690 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8691 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8692 ["Check Everything" idlwave-list-all-load-path-shadows t])
8694 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8696 ["Insert TAB character" idlwave-hard-tab t])
8699 ["Generate IDL tags" idlwave-make-tags t]
8700 ["Start IDL shell" idlwave-shell t]
8701 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8702 ["Launch IDL Help" idlwave-launch-idlhelp t])
8705 ["Browse IDLWAVE Group" idlwave-customize t]
8707 ["Build Full Customize Menu" idlwave-create-customize-menu
8708 (fboundp 'customize-menu-create)])
8710 ["Describe Mode" describe-mode t]
8711 ["Abbreviation List" idlwave-list-abbrevs t]
8713 ["Commentary in idlwave.el" idlwave-show-commentary t]
8714 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8716 ["Info" idlwave-info t]
8718 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8720 (defvar idlwave-mode-debug-menu-def
8722 ["Start IDL shell" idlwave-shell t]
8723 ["Save and .RUN buffer" idlwave-shell-save-and-run
8724 (and (boundp 'idlwave-shell-automatic-start)
8725 idlwave-shell-automatic-start)]))
8727 (if (or (featurep 'easymenu) (load "easymenu" t))
8729 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8730 "IDL and WAVE CL editing menu"
8731 idlwave-mode-menu-def)
8732 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8733 "IDL and WAVE CL editing menu"
8734 idlwave-mode-debug-menu-def)))
8736 (defun idlwave-customize ()
8737 "Call the customize function with idlwave as argument."
8739 ;; Try to load the code for the shell, so that we can customize it
8741 (or (featurep 'idlw-shell)
8742 (load "idlw-shell" t))
8743 (customize-browse 'idlwave))
8745 (defun idlwave-create-customize-menu ()
8746 "Create a full customization menu for IDLWAVE, insert it into the menu."
8748 (if (fboundp 'customize-menu-create)
8750 ;; Try to load the code for the shell, so that we can customize it
8752 (or (featurep 'idlw-shell)
8753 (load "idlw-shell" t))
8755 '("IDLWAVE") "Customize"
8756 `(["Browse IDLWAVE group" idlwave-customize t]
8758 ,(customize-menu-create 'idlwave)
8759 ["Set" Custom-set t]
8760 ["Save" Custom-save t]
8761 ["Reset to Current" Custom-reset-current t]
8762 ["Reset to Saved" Custom-reset-saved t]
8763 ["Reset to Standard Settings" Custom-reset-standard t]))
8764 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8765 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8767 (defun idlwave-show-commentary ()
8768 "Use the finder to view the file documentation from `idlwave.el'."
8771 (finder-commentary "idlwave.el"))
8773 (defun idlwave-shell-show-commentary ()
8774 "Use the finder to view the file documentation from `idlw-shell.el'."
8777 (finder-commentary "idlw-shell.el"))
8779 (defun idlwave-info ()
8780 "Read documentation for IDLWAVE in the info system."
8783 (Info-goto-node "(idlwave)"))
8785 (defun idlwave-list-abbrevs (arg)
8786 "Show the code abbreviations define in IDLWAVE mode.
8787 This lists all abbrevs where the replacement text differs from the input text.
8788 These are the ones the users want to learn to speed up their writing.
8790 The function does *not* list abbrevs which replace a word with itself
8791 to call a hook. These hooks are used to change the case of words or
8792 to blink the matching `begin', and the user does not need to know them.
8794 With arg, list all abbrevs with the corresponding hook.
8796 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8799 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8801 str rpl func fmt (len-str 0) (len-rpl 0))
8804 (if (symbol-value sym)
8806 (setq str (symbol-name sym)
8807 rpl (symbol-value sym)
8808 func (symbol-function sym))
8810 (setq func (prin1-to-string func))
8811 (if (and (listp func) (stringp (nth 2 func)))
8812 (setq rpl (concat "EVAL: " (nth 2 func))
8815 (if (or arg (not (string= rpl str)))
8817 (setq len-str (max len-str (length str)))
8818 (setq len-rpl (max len-rpl (length rpl)))
8819 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8822 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8824 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8825 (with-output-to-temp-buffer "*Help*"
8828 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8829 (princ "=========================================\n\n")
8830 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8831 (princ (format fmt "---" "-------" "----")))
8832 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8833 (princ "================================================\n\n")
8834 (princ (format fmt "KEY" "ACTION" ""))
8835 (princ (format fmt "---" "------" "")))
8838 (setq str (car list)
8841 (princ (format fmt str rpl func)))
8843 ;; Make sure each abbreviation uses only one display line
8845 (set-buffer "*Help*")
8846 (setq truncate-lines t)))
8848 ;; Add .pro files to speedbar for support, if it's loaded
8849 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8851 ;; Set an idle timer to load the routine info.
8852 ;; Will only work on systems which support this.
8853 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8855 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
8858 (run-hooks 'idlwave-load-hook)
8862 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
8863 ;;; idlwave.el ends here