1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Carsten Dominik <dominik@science.uva.nl>
8 ;; Chris Chase <chase@att.com>
9 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
11 ;; Keywords: languages
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 3, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; IDLWAVE enables feature-rich development and interaction with IDL,
33 ;; the Interactive Data Language. It provides a compelling,
34 ;; full-featured alternative to the IDLDE development environment
37 ;; In the remotely distant past, based on pascal.el, though bears
38 ;; little resemblance to it now.
40 ;; Incorporates many ideas, such as abbrevs, action routines, and
41 ;; continuation line indenting, from wave.el.
42 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
44 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
45 ;; for features, key bindings, and info.
46 ;; Also, Info format documentation is available with `M-x idlwave-info'
48 ;; New versions of IDLWAVE, documentation, and more information
55 ;; Follow the instructions in the INSTALL file of the distribution.
56 ;; In short, put this file on your load path and add the following
57 ;; lines to your .emacs file:
59 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
60 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
61 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
67 ;; The newest version of this file is available from the maintainer's
75 ;; IDLWAVE is documented online in info format. A printable version
76 ;; of the documentation is available from the maintainers webpage (see
83 ;; Thanks to the following people for their contributions and comments:
85 ;; Ulrik Dickow <dickow_at_nbi.dk>
86 ;; Eric E. Dors <edors_at_lanl.gov>
87 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
88 ;; David Huenemoerder <dph_at_space.mit.edu>
89 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
90 ;; Dick Jackson <dick_at_d-jackson.com>
91 ;; Xuyong Liu <liu_at_stsci.edu>
92 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
93 ;; Laurent Mugnier <mugnier_at_onera.fr>
94 ;; Lubos Pochman <lubos_at_rsinc.com>
95 ;; Bob Portmann <portmann_at_al.noaa.gov>
96 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
97 ;; Marty Ryba <ryba_at_ll.mit.edu>
98 ;; Paul Sorenson <aardvark62_at_msn.com>
99 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
100 ;; Phil Williams <williams_at_irc.chmcc.org>
105 ;; IDLWAVE has extensive customize support; to learn about the
106 ;; variables which control the mode's behavior, use `M-x
107 ;; idlwave-customize'.
109 ;; You can set your own preferred values with Customize, or with Lisp
110 ;; code in .emacs. For an example of what to put into .emacs, check
111 ;; the TexInfo documentation or see a complete .emacs available at the
117 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
118 ;; Numerics, Inc. is growing less and less complete as the two
119 ;; languages grow increasingly apart. The mode probably shouldn't
120 ;; even have "WAVE" in its title, but it's catchy, and was required
121 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
123 ;; Moving the point backwards in conjunction with abbrev expansion
124 ;; does not work as I would like it, but this is a problem with
125 ;; emacs abbrev expansion done by the self-insert-command. It ends
126 ;; up inserting the character that expanded the abbrev after moving
127 ;; point backward, e.g., "\cl" expanded with a space becomes
128 ;; "LONG( )" with point before the close paren. This is solved by
129 ;; using a temporary function in `post-command-hook' - not pretty,
132 ;; Tabs and spaces are treated equally as whitespace when filling a
133 ;; comment paragraph. To accomplish this, tabs are permanently
134 ;; replaced by spaces in the text surrounding the paragraph, which
135 ;; may be an undesirable side-effect. Replacing tabs with spaces is
136 ;; limited to comments only and occurs only when a comment
137 ;; paragraph is filled via `idlwave-fill-paragraph'.
139 ;; Muti-statement lines (using "&") on block begin and end lines can
140 ;; ruin the formatting. For example, multiple end statements on a
141 ;; line: endif & endif. Using "&" outside of block begin/end lines
144 ;; Determining the expression at point for printing and other
145 ;; examination commands is somewhat rough: currently only fairly
146 ;; simple entities are found. You can always drag-select or examine
147 ;; a pre-selected region.
149 ;; When forcing completion of method keywords, the initial
150 ;; query for a method has multiple entries for some methods. Would
151 ;; be too difficult to fix this hardly used case.
157 (eval-when-compile (require 'cl
))
161 (unless (fboundp 'line-beginning-position
)
162 (defalias 'line-beginning-position
'point-at-bol
))
163 (unless (fboundp 'line-end-position
)
164 (defalias 'line-end-position
'point-at-eol
))
165 (unless (fboundp 'char-valid-p
)
166 (defalias 'char-valid-p
'characterp
))
167 (unless (fboundp 'match-string-no-properties
)
168 (defalias 'match-string-no-properties
'match-string
))
170 (if (not (fboundp 'cancel-timer
))
175 (declare-function idlwave-shell-get-path-info
"idlw-shell")
176 (declare-function idlwave-shell-temp-file
"idlw-shell")
177 (declare-function idlwave-shell-is-running
"idlw-shell")
178 (declare-function widget-value
"wid-edit" (widget))
179 (declare-function comint-dynamic-complete-filename
"comint" ())
181 (defgroup idlwave nil
182 "Major mode for editing IDL .pro files."
184 :link
'(url-link :tag
"Home Page"
185 "http://idlwave.org")
186 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
188 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
189 :link
'(custom-manual "(idlwave)Top")
194 ;;; Variables for indentation behavior ---------------------------------------
196 (defgroup idlwave-code-formatting nil
197 "Indentation and formatting options for IDLWAVE mode."
200 (defcustom idlwave-main-block-indent
2
201 "*Extra indentation for the main block of code.
202 That is the block between the FUNCTION/PRO statement and the END
203 statement for that program unit."
204 :group
'idlwave-code-formatting
207 (defcustom idlwave-block-indent
3
208 "*Extra indentation applied to block lines.
209 If you change this, you probably also want to change `idlwave-end-offset'."
210 :group
'idlwave-code-formatting
213 (defcustom idlwave-end-offset -
3
214 "*Extra indentation applied to block END lines.
215 A value equal to negative `idlwave-block-indent' will make END lines
216 line up with the block BEGIN lines."
217 :group
'idlwave-code-formatting
220 (defcustom idlwave-continuation-indent
3
221 "*Extra indentation applied to continuation lines.
222 This extra offset applies to the first of a set of continuation lines.
223 The following lines receive the same indentation as the first."
224 :group
'idlwave-code-formatting
227 (defcustom idlwave-max-extra-continuation-indent
40
228 "*Maximum additional indentation for special continuation indent.
229 Several special indentations are tried to help line up continuation
230 lines in routine calls or definitions, other statements with
231 parentheses, or assignment statements. This variable specifies a
232 maximum amount by which this special indentation can exceed the
233 standard continuation indentation, otherwise defaulting to a fixed
234 offset. Set to 0 to effectively disable all special continuation
235 indentation, or to a large number (like 100) to enable it in all
236 cases. See also `idlwave-indent-to-open-paren', which can override
238 :group
'idlwave-code-formatting
241 (defcustom idlwave-indent-to-open-paren t
242 "*Non-nil means, indent continuation lines to innermost open
243 parenthesis. This indentation occurs even if otherwise disallowed by
244 `idlwave-max-extra-continuation-indent'. Matching parens and the
245 interleaving args are lined up. Example:
247 x = function_a(function_b(function_c( a, b, [1,2,3, $
253 When this variable is nil, paren alignment may still occur, based on
254 the value of `max-extra-continuation-indent', which, if zero, would
257 x = function_a(function_b(function_c( a, b, [1,2,3, $
262 :group
'idlwave-code-formatting
265 (defcustom idlwave-indent-parens-nested nil
266 "*Non-nil means, indent continuation lines with parens by nesting
267 lines at consecutively deeper levels."
268 :group
'idlwave-code-formatting
272 (defcustom idlwave-hanging-indent t
273 "*If set non-nil then comment paragraphs are indented under the
274 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
276 :group
'idlwave-code-formatting
279 (defcustom idlwave-hang-indent-regexp
"- "
280 "*Regular expression matching the position of the hanging indent
281 in the first line of a comment paragraph. The size of the indent
282 extends to the end of the match for the regular expression."
283 :group
'idlwave-code-formatting
286 (defcustom idlwave-use-last-hang-indent nil
287 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
288 :group
'idlwave-code-formatting
291 (defcustom idlwave-fill-comment-line-only t
292 "*If non-nil then auto fill will only operate on comment lines."
293 :group
'idlwave-code-formatting
296 (defcustom idlwave-auto-fill-split-string t
297 "*If non-nil then auto fill will split strings with the IDL `+' operator.
298 When the line end falls within a string, string concatenation with the
299 '+' operator will be used to distribute a long string over lines.
300 If nil and a string is split then a terminal beep and warning are issued.
302 This variable is ignored when `idlwave-fill-comment-line-only' is
303 non-nil, since in this case code is not auto-filled."
304 :group
'idlwave-code-formatting
307 (defcustom idlwave-split-line-string t
308 "*If non-nil then `idlwave-split-line' will split strings with `+'.
309 When the splitting point of a line falls inside a string, split the string
310 using the `+' string concatenation operator. If nil and a string is
311 split then a terminal beep and warning are issued."
312 :group
'idlwave-code-formatting
315 (defcustom idlwave-no-change-comment
";;;"
316 "*The indentation of a comment that starts with this regular
317 expression will not be changed. Note that the indentation of a comment
318 at the beginning of a line is never changed."
319 :group
'idlwave-code-formatting
322 (defcustom idlwave-begin-line-comment nil
323 "*A comment anchored at the beginning of line.
324 A comment matching this regular expression will not have its
325 indentation changed. If nil the default is \"^;\", i.e., any line
326 beginning with a \";\". Expressions for comments at the beginning of
327 the line should begin with \"^\"."
328 :group
'idlwave-code-formatting
329 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
332 (defcustom idlwave-code-comment
";;[^;]"
333 "*A comment that starts with this regular expression on a line by
334 itself is indented as if it is a part of IDL code. As a result if
335 the comment is not preceded by whitespace it is unchanged."
336 :group
'idlwave-code-formatting
339 ;; Comments not matching any of the above will be indented as a
340 ;; right-margin comment, i.e., to a minimum of `comment-column'.
342 ;;; Routine Info and Completion ---------------------------------------
344 (defgroup idlwave-routine-info nil
345 "Routine Info options for IDLWAVE mode."
348 (defcustom idlwave-use-library-catalogs t
349 "*Non-nil means search the IDL path for library catalog files.
351 These files, named .idlwave_catalog, document routine information for
352 individual directories and libraries of IDL .pro files. Many popular
353 libraries come with catalog files by default, so leaving this on is a
354 usually a good idea.."
355 :group
'idlwave-routine-info
358 (defcustom idlwave-init-rinfo-when-idle-after
10
359 "*Seconds of idle time before routine info is automatically
360 initialized. Initializing the routine info can take a long time, in
361 particular if a large number of library catalogs are involved. When
362 Emacs is idle for more than the number of seconds specified by this
363 variable, it starts the initialization. The process is split into
364 five steps, in order to keep work interruption as short as possible.
365 If one of the steps finishes, and no user input has arrived in the
366 mean time, initialization proceeds immediately to the next step. A
367 good value for this variable is about 1/3 of the time initialization
368 take in your setup. So if you have a fast machine and no problems
369 with a slow network connection, don't hesitate to set this to 2
370 seconds. A Value of 0 means, don't initialize automatically, but
371 instead wait until routine information is needed, and initialize
373 :group
'idlwave-routine-info
376 (defcustom idlwave-scan-all-buffers-for-routine-info t
377 "*Non-nil means, scan buffers for IDL programs when updating info.
378 The scanning is done by the command `idlwave-update-routine-info'.
379 The following values are allowed:
381 nil Don't scan any buffers.
382 t Scan all idlwave-mode buffers in the current editing session.
383 current Scan only the current buffer, but no other buffers."
384 :group
'idlwave-routine-info
386 (const :tag
"No buffer" nil
)
387 (const :tag
"All buffers" t
)
388 (const :tag
"Current buffer only" 'current
)))
390 (defcustom idlwave-query-shell-for-routine-info t
391 "*Non-nil means query the shell for info about compiled routines.
392 Querying the shell is useful to get information about compiled modules,
393 and it is turned on by default. However, when you have a complete library
394 scan, this is not necessary."
395 :group
'idlwave-routine-info
398 (defcustom idlwave-auto-routine-info-updates
399 '(find-file save-buffer kill-buffer compile-buffer
)
400 "*Controls under what circumstances routine info is updated automatically.
404 \(...) A list of circumstances. Allowed members are:
405 find-file Add info for new IDLWAVE buffers.
406 save-buffer Update buffer info when buffer is saved
407 kill-buffer Remove buffer info when buffer gets killed
408 compile-buffer Update shell info after `idlwave-shell-save-and...'"
409 :group
'idlwave-routine-info
411 (const :tag
"Never" nil
)
412 (const :tag
"As often as possible" t
)
413 (set :tag
"Checklist" :greedy t
414 (const :tag
"When visiting a file" find-file
)
415 (const :tag
"When saving a buffer" save-buffer
)
416 (const :tag
"After a buffer was killed" kill-buffer
)
417 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
419 (defcustom idlwave-rinfo-max-source-lines
5
420 "*Maximum number of source files displayed in the Routine Info window.
421 When an integer, it is the maximum number of source files displayed.
422 t means to show all source files."
423 :group
'idlwave-routine-info
426 (defcustom idlwave-library-path nil
427 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
428 When selecting the directories to scan for IDL user catalog routine
429 info, IDLWAVE can, under UNIX, query the shell for the exact search
430 path \(the value of !PATH). However, under Windows and MacOS
431 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
432 variable can be set to specify the paths where IDLWAVE can find PRO
433 files. The shell will only be asked for a list of paths when this
434 variable is nil. The value is a list of directories. A directory
435 preceeded by a `+' will be searched recursively. If you set this
436 variable on a UNIX system, the shell will not be queried. See also
437 `idlwave-system-directory'."
438 :group
'idlwave-routine-info
439 :type
'(repeat (directory)))
441 (defcustom idlwave-system-directory
""
442 "The IDL system directory for Windows and MacOS. Not needed under
443 UNIX. Set this to the value of the `!DIR' system variable in IDL.
444 IDLWAVE uses this to find out which of the library routines belong to
445 the official system library. All files inside the `lib' subdirectory
446 are considered system library files - so don't install private stuff
447 in this directory. On UNIX systems, IDLWAVE queries the shell for the
448 value of `!DIR'. See also `idlwave-library-path'."
449 :group
'idlwave-routine-info
452 ;; Configuration files
453 (defcustom idlwave-config-directory
454 (convert-standard-filename "~/.idlwave")
455 "*Directory for configuration files and user-library catalog."
456 :group
'idlwave-routine-info
459 (defvar idlwave-user-catalog-file
"idlusercat.el")
460 (defvar idlwave-xml-system-rinfo-converted-file
"idl_xml_rinfo.el")
461 (defvar idlwave-path-file
"idlpath.el")
463 (defvar idlwave-libinfo-file nil
464 "*Obsolete variable, no longer used.")
466 (defcustom idlwave-special-lib-alist nil
467 "Alist of regular expressions matching special library directories.
468 When listing routine source locations, IDLWAVE gives a short hint where
469 the file defining the routine is located. By default it lists `SystemLib'
470 for routines in the system library `!DIR/lib' and `Library' for anything
471 else. This variable can define additional types. The car of each entry
472 is a regular expression matching the file name (they normally will match
473 on the path). The cdr is the string to be used as identifier. Max 10
475 :group
'idlwave-routine-info
477 (cons regexp string
)))
479 (defcustom idlwave-auto-write-paths t
480 "Write out path (!PATH) and system directory (!DIR) info automatically.
481 Path info is needed to locate library catalog files. If non-nil,
482 whenever the path-list changes as a result of shell-query, etc., it is
483 written to file. Otherwise, the menu option \"Write Paths\" can be
484 used to force a write."
485 :group
'idlwave-routine-info
488 (defgroup idlwave-completion nil
489 "Completion options for IDLWAVE mode."
494 (defconst idlwave-tmp
495 '(choice :tag
"by applying the function"
500 (symbol :tag
"Other"))))
502 (defcustom idlwave-completion-case
'((routine . upcase
)
506 "Association list setting the case of completed words.
508 This variable determines the case (UPPER/lower/Capitalized...) of
509 words inserted into the buffer by completion. The preferred case can
510 be specified separately for routine names, keywords, classes and
512 This alist should therefore have entries for `routine' (normal
513 functions and procedures, i.e. non-methods), `keyword', `class', and
514 `method'. Plausible values are
516 upcase upcase whole word, like `BOX_CURSOR'
517 downcase downcase whole word, like `read_ppm'
518 capitalize capitalize each part, like `Widget_Control'
519 preserve preserve case as is, like `IDLgrView'
521 The value can also be any Emacs Lisp function which transforms the
522 case of characters in a string.
524 A value of `preserve' means that the case of the completed word is
525 identical to the way it was written in the definition statement of the
526 routine. This was implemented to allow for mixed-case completion, in
527 particular of object classes and methods.
528 If a completable word is defined in multiple locations, the meaning of
529 `preserve' is not unique since the different definitions might be
530 cased differently. Therefore IDLWAVE always takes the case of the
531 *first* definition it encounters during routine info collection and
532 uses the case derived from it consistently.
534 Note that a lowercase-only string in the buffer will always be completed in
535 lower case (but see the variable `idlwave-completion-force-default-case').
537 After changing this variable, you need to either restart Emacs or press
538 `C-u C-c C-i' to update the internal lists."
539 :group
'idlwave-completion
541 (cons (symbol :tag
"Derive completion case for")
544 (defcustom idlwave-completion-force-default-case nil
545 "*Non-nil means, completion will always honor `idlwave-completion-case'.
546 When nil, only the completion of a mixed case or upper case string
547 will honor the default settings in `idlwave-completion-case', while
548 the completion of lower case strings will be completed entirely in
550 :group
'idlwave-completion
553 (defcustom idlwave-complete-empty-string-as-lower-case nil
554 "*Non-nil means, the empty string is considered downcase for completion.
555 The case of what is already in the buffer determines the case of completions.
556 When this variable is non-nil, the empty string is considered to be downcase.
557 Completing on the empty string then offers downcase versions of the possible
559 :group
'idlwave-completion
562 (defvar idlwave-default-completion-case-is-down nil
563 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
564 `idlwave-completion-case'.")
566 (defcustom idlwave-buffer-case-takes-precedence nil
567 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
568 To make this possible, we need to re-case everything each time we update
569 the routine info from the buffers. This is slow.
570 The default is to consider the case given in the system and library files
571 first which makes updating much faster."
572 :group
'idlwave-completion
575 (defcustom idlwave-highlight-help-links-in-completion t
576 "*Non-nil means, highlight completions for which system help is available.
577 Help can then be accessed with mouse-3.
578 This option is only effective when the online help system is installed."
579 :group
'idlwave-completion
582 (defcustom idlwave-support-inheritance t
583 "Non-nil means, treat inheritance with completion, online help etc.
584 When nil, IDLWAVE only knows about the native methods and tags of a class,
585 not about inherited ones."
586 :group
'idlwave-routine-info
589 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
590 "List of regular expressions for class-driven keyword inheritance.
591 Keyword inheritance is often tied to class inheritance by \"chaining\"
592 up the class tree. While it cannot be assumed that the presence of an
593 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
594 certain methods this assumption is almost always true. The methods
595 for which to assume this can be set here."
596 :group
'idlwave-routine-info
597 :type
'(repeat (regexp :tag
"Match method:")))
600 (defcustom idlwave-completion-show-classes
1
601 "*Number of classes to show when completing object methods and keywords.
602 When completing methods or keywords for an object with unknown class,
603 the *Completions* buffer will show the valid classes for each completion
606 MyMethod <Class1,Class2,Class3>
608 The value of this variable may be nil to inhibit display, or an integer to
609 indicate the maximum number of classes to display.
611 On XEmacs, a full list of classes will also be placed into a `help-echo'
612 property on the competion items, so that the list of classes for the current
613 item is displayed in the echo area. If the value of this variable is a
614 negative integer, the `help-echo' property will be suppressed."
615 :group
'idlwave-completion
616 :type
'(choice (const :tag
"Don't show" nil
)
617 (integer :tag
"Number of classes shown" 1)))
619 (defcustom idlwave-completion-fontify-classes t
620 "*Non-nil means, fontify the classes in completions buffer.
621 This makes it easier to distinguish the completion items from the extra
622 class info listed. See `idlwave-completion-show-classes'."
623 :group
'idlwave-completion
626 (defcustom idlwave-query-class
'((method-default . nil
)
627 (keyword-default . nil
))
628 "Association list governing specification of object classes for completion.
630 When IDLWAVE tries to complete object-oriented methods, it usually
631 cannot determine the class of a given object from context. In order
632 to provide the user with a correct list of methods or keywords, it
633 needs to determine the appropriate class. IDLWAVE has two ways of
634 doing this (well, three ways if you count the shell... see
635 `idlwave-shell-query-for-class'):
637 1. Combine the items of all available classes which contain this
638 method for the purpose of completion. So when completing a method,
639 all methods of all known classes are available, and when completing
640 a keyword, all keywords allowed for this method in any class are
641 shown. This behavior is very much like normal completion and is
642 therefore the default. It works much better than one might think -
643 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
644 become uncomfortably long. See also
645 `idlwave-completion-show-classes'.
647 2. The second possibility is to ask the user on each occasion. To
648 make this less interruptive, IDLWAVE can store the class as a text
649 property on the object operator `->'. For a given object in the
650 source code, class selection will then be needed only once
651 - for example to complete the method. Keywords to the method can
652 then be completed directly, because the class is already known.
653 You will have to turn on the storage of the selected class
654 explicitly with the variable `idlwave-store-inquired-class'.
656 This variable allows you to configure IDLWAVE's method and
657 method-keyword completion behavior. Its value is an alist, which
658 should contain at least two elements: (method-default . VALUE) and
659 \(keyword-default . VALUE), where VALUE is either t or nil. These
660 specify if the class should be found during method and keyword
661 completion, respectively.
663 The alist may have additional entries specifying exceptions from the
664 keyword completion rule for specific methods, like INIT or
665 GETPROPERTY. In order to turn on class specification for the INIT
666 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
667 :group
'idlwave-completion
669 (cons (const method-default
)
670 (boolean :tag
"Determine class when completing METHODS "))
671 (cons (const keyword-default
)
672 (boolean :tag
"Determine class when completing KEYWORDS "))
674 :tag
"Exceptions to defaults"
676 (cons (string :tag
"MODULE" :value
"")
677 (boolean :tag
"Determine class for this method")))))
679 (defcustom idlwave-store-inquired-class t
680 "*Non-nil means, store class of a method call as text property on `->'.
681 IDLWAVE sometimes has to ask the user for the class associated with a
682 particular object method call. This happens during the commands
683 `idlwave-routine-info' and `idlwave-complete', depending upon the
684 value of the variable `idlwave-query-class'.
686 When you specify a class, this information can be stored as a text
687 property on the `->' arrow in the source code, so that during the same
688 editing session, IDLWAVE will not have to ask again. When this
689 variable is non-nil, IDLWAVE will store and reuse the class information.
690 The class stored can be checked and removed with `\\[idlwave-routine-info]'
693 The default of this variable is nil, since the result of commands then
694 is more predictable. However, if you know what you are doing, it can
695 be nice to turn this on.
697 An arrow which knows the class will be highlighted with
698 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
699 displays (with prefix arg: deletes) the class stored on the arrow
701 :group
'idlwave-completion
704 (defcustom idlwave-class-arrow-face
'bold
705 "*Face to highlight object operator arrows `->' which carry a class property.
706 When IDLWAVE stores a class name as text property on an object arrow
707 \(see variable `idlwave-store-inquired-class', it highlights the arrow
708 with this font in order to remind the user that this arrow is special."
709 :group
'idlwave-completion
712 (defcustom idlwave-resize-routine-help-window t
713 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
714 :group
'idlwave-completion
717 (defcustom idlwave-keyword-completion-adds-equal t
718 "*Non-nil means, completion automatically adds `=' after completed keywords."
719 :group
'idlwave-completion
722 (defcustom idlwave-function-completion-adds-paren t
723 "*Non-nil means, completion automatically adds `(' after completed function.
724 nil means, don't add anything.
725 A value of `2' means, also add the closing parenthesis and position cursor
727 :group
'idlwave-completion
728 :type
'(choice (const :tag
"Nothing" nil
)
730 (const :tag
"()" 2)))
732 (defcustom idlwave-completion-restore-window-configuration t
733 "*Non-nil means, try to restore the window configuration after completion.
734 When completion is not unique, Emacs displays a list of completions.
735 This messes up your window configuration. With this variable set, IDLWAVE
736 restores the old configuration after successful completion."
737 :group
'idlwave-completion
740 ;;; Variables for abbrev and action behavior -----------------------------
742 (defgroup idlwave-abbrev-and-indent-action nil
743 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
744 The variables in this group govern this."
747 (defcustom idlwave-do-actions nil
748 "*Non-nil means performs actions when indenting.
749 The actions that can be performed are listed in `idlwave-indent-action-table'."
750 :group
'idlwave-abbrev-and-indent-action
753 (defcustom idlwave-abbrev-start-char
"\\"
754 "*A single character string used to start abbreviations in abbrev mode.
755 Possible characters to chose from: ~`\%
756 or even '?'. '.' is not a good choice because it can make structure
757 field names act like abbrevs in certain circumstances.
759 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
760 must set it directly using `setq' in the .emacs file before idlwave.el
762 :group
'idlwave-abbrev-and-indent-action
765 (defcustom idlwave-surround-by-blank nil
766 "*Non-nil means, enable `idlwave-surround'.
767 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
769 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
771 Also see the default key bindings for keys using `idlwave-surround'.
772 Keys are bound and made into actions calling `idlwave-surround' with
773 `idlwave-action-and-binding'.
774 See help for `idlwave-action-and-binding' for examples.
776 Also see help for `idlwave-surround'."
777 :group
'idlwave-abbrev-and-indent-action
780 (defcustom idlwave-pad-keyword t
781 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
782 Whenever `idlwave-surround' is non-nil then this affects how '=' is
783 padded for keywords and for variables. If t, pad the same as for
784 assignments. If nil then spaces are removed. With any other value,
785 spaces are left unchanged."
786 :group
'idlwave-abbrev-and-indent-action
788 (const :tag
"Pad like assignments" t
)
789 (const :tag
"Remove space near `='" nil
)
790 (const :tag
"Keep space near `='" 'keep
)))
792 (defcustom idlwave-show-block t
793 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
794 :group
'idlwave-abbrev-and-indent-action
797 (defcustom idlwave-expand-generic-end nil
798 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
799 :group
'idlwave-abbrev-and-indent-action
802 (defcustom idlwave-reindent-end t
803 "*Non-nil means re-indent line after END was typed."
804 :group
'idlwave-abbrev-and-indent-action
807 (defcustom idlwave-abbrev-move t
808 "*Non-nil means the abbrev hook can move point.
809 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
810 definitions, use the command `list-abbrevs', for abbrevs that move
811 point. Moving point is useful, for example, to place point between
812 parentheses of expanded functions.
814 See `idlwave-check-abbrev'."
815 :group
'idlwave-abbrev-and-indent-action
818 (defcustom idlwave-abbrev-change-case nil
819 "*Non-nil means all abbrevs will be forced to either upper or lower case.
820 If the value t, all expanded abbrevs will be upper case.
821 If the value is 'down then abbrevs will be forced to lower case.
822 If nil, the case will not change.
823 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
824 upper case, regardless of this variable."
825 :group
'idlwave-abbrev-and-indent-action
828 (defcustom idlwave-reserved-word-upcase nil
829 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
830 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
831 Has effect only if in abbrev-mode."
832 :group
'idlwave-abbrev-and-indent-action
835 ;;; Action/Expand Tables.
837 ;; The average user may have difficulty modifying this directly. It
838 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
839 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
840 ;; examples of how to add an action.
842 ;; The action table is used by `idlwave-indent-line' whereas both the
843 ;; action and expand tables are used by `idlwave-indent-and-action'. In
844 ;; general, the expand table is only used when a line is explicitly
845 ;; indented. Whereas, in addition to being used when the expand table
846 ;; is used, the action table is used when a line is indirectly
847 ;; indented via line splitting, auto-filling or a new line creation.
851 ;; Capitalize system vars
852 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
854 ;; Capitalize procedure name
855 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
856 ;; '(capitalize-word 1) t)
858 ;; Capitalize common block name
859 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
860 ;; '(capitalize-word 1) t)
862 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
863 ;; '(capitalize-word -1) t)
865 (defvar idlwave-indent-action-table nil
866 "*Associated array containing action lists of search string (car),
867 and function as a cdr. This table is used by `idlwave-indent-line'.
868 See documentation for `idlwave-do-action' for a complete description of
871 Additions to the table are made with `idlwave-action-and-binding' when a
872 binding is not requested.
873 See help on `idlwave-action-and-binding' for examples.")
875 (defvar idlwave-indent-expand-table nil
876 "*Associated array containing action lists of search string (car),
877 and function as a cdr. The table is used by the
878 `idlwave-indent-and-action' function. See documentation for
879 `idlwave-do-action' for a complete description of the action lists.
881 Additions to the table are made with `idlwave-action-and-binding' when a
882 binding is requested.
883 See help on `idlwave-action-and-binding' for examples.")
885 ;;; Documentation header and history keyword ---------------------------------
887 (defgroup idlwave-documentation nil
888 "Options for documenting IDLWAVE files."
891 ;; FIXME: make defcustom?
892 (defvar idlwave-file-header
919 ; KEYWORD PARAMETERS:
951 ; MODIFICATION HISTORY:
955 "*A list (PATHNAME STRING) specifying the doc-header template to use for
956 summarizing a file. If PATHNAME is non-nil then this file will be included.
957 Otherwise STRING is used. If nil, the file summary will be omitted.
958 For example you might set PATHNAME to the path for the
959 lib_template.pro file included in the IDL distribution.")
961 (defcustom idlwave-header-to-beginning-of-file t
962 "*Non-nil means, the documentation header will always be at start of file.
963 When nil, the header is positioned between the PRO/FUNCTION line of
964 the current routine and the code, allowing several routine headers in
966 :group
'idlwave-documentation
969 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
970 "*The hook function used to update the timestamp of a function."
971 :group
'idlwave-documentation
974 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
975 "*The modifications keyword to use with the log documentation commands.
976 A ':' is added to the keyword end.
977 Inserted by doc-header and used to position logs by doc-modification.
978 If nil it will not be inserted."
979 :group
'idlwave-documentation
982 (defcustom idlwave-doclib-start
"^;+\\+"
983 "*Regexp matching the start of a document library header."
984 :group
'idlwave-documentation
987 (defcustom idlwave-doclib-end
"^;+-"
988 "*Regexp matching the end of a document library header."
989 :group
'idlwave-documentation
992 ;;; External Programs -------------------------------------------------------
994 (defgroup idlwave-external-programs nil
995 "Path locations of external commands used by IDLWAVE."
998 (defcustom idlwave-shell-explicit-file-name
"idl"
999 "*If non-nil, this is the command to run IDL.
1000 Should be an absolute file path or path relative to the current environment
1001 execution search path. If you want to specify command line switches
1002 for the idl program, use `idlwave-shell-command-line-options'.
1004 I know the name of this variable is badly chosen, but I cannot change
1005 it without compromizing backwards-compatibility."
1006 :group
'idlwave-external-programs
1009 (defcustom idlwave-shell-command-line-options nil
1010 "*A list of command line options for calling the IDL program.
1011 Since IDL is executed directly without going through a shell like /bin/sh,
1012 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1013 string for each argument. But you may also give a single string which
1014 contains the options whitespace-separated. Emacs will be kind enough to
1018 (repeat (string :value
"")))
1019 :group
'idlwave-external-programs
)
1021 (defcustom idlwave-help-application
"idlhelp"
1022 "*The external application providing reference help for programming.
1023 Obsolete, if the IDL Assistant is being used for help."
1024 :group
'idlwave-external-programs
1027 ;;; Some Shell variables which must be defined here.-----------------------
1029 (defcustom idlwave-shell-debug-modifiers
'()
1030 "List of modifiers to be used for the debugging commands.
1031 Will be used to bind debugging commands in the shell buffer and in all
1032 source buffers. These are additional convenience bindings, the debugging
1033 commands are always available with the `C-c C-d' prefix.
1034 If you set this to '(control shift), this means setting a breakpoint will
1035 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1036 are `control', `meta', `super', `hyper', `alt', and `shift'."
1037 :group
'idlwave-shell-general-setup
1038 :type
'(set :tag
"Specify modifiers"
1046 (defcustom idlwave-shell-automatic-start nil
1047 "*If non-nil attempt invoke idlwave-shell if not already running.
1048 This is checked when an attempt to send a command to an
1049 IDL process is made."
1050 :group
'idlwave-shell-general-setup
1053 ;;; Miscellaneous variables -------------------------------------------------
1055 (defgroup idlwave-misc nil
1056 "Miscellaneous options for IDLWAVE mode."
1057 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
1060 (defcustom idlwave-startup-message t
1061 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1062 :group
'idlwave-misc
1065 (defcustom idlwave-default-font-lock-items
1066 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1067 common-blocks class-arrows
)
1068 "Items which should be fontified on the default fontification level 2.
1069 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1070 is everything and level 2 is specified by this list.
1071 This variable must be set before IDLWAVE gets loaded. It is
1072 a list of symbols, the following symbols are allowed.
1074 pros-and-functions Procedure and Function definitions
1075 batch-files Batch Files
1076 idlwave-idl-keywords IDL Keywords
1077 label Statement Labels
1078 goto Goto Statements
1079 common-blocks Common Blocks
1080 keyword-parameters Keyword Parameters in routine definitions and calls
1081 system-variables System Variables
1082 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1083 class-arrows Object Arrows with class property"
1084 :group
'idlwave-misc
1087 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1088 (const :tag
"Batch Files" batch-files
)
1089 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1090 (const :tag
"Statement Labels" label
)
1091 (const :tag
"Goto Statements" goto
)
1092 (const :tag
"Tags in Structure Definition" structtag
)
1093 (const :tag
"Structure Name" structname
)
1094 (const :tag
"Common Blocks" common-blocks
)
1095 (const :tag
"Keyword Parameters" keyword-parameters
)
1096 (const :tag
"System Variables" system-variables
)
1097 (const :tag
"FIXME: Warning" fixme
)
1098 (const :tag
"Object Arrows with class property " class-arrows
)))
1100 (defcustom idlwave-mode-hook nil
1101 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1102 :group
'idlwave-misc
1105 (defcustom idlwave-load-hook nil
1106 "Normal hook. Executed when idlwave.el is loaded."
1107 :group
'idlwave-misc
1110 (defvar idlwave-experimental nil
1111 "Non-nil means turn on a few experimental features.
1112 This variable is only for the maintainer, to test difficult stuff,
1113 while still distributing stable releases.
1114 As a user, you should not set this to t.")
1117 ;;; End customization variables section
1120 ;;; Non customization variables
1122 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1123 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1124 ;;; and Carsten Dominik...
1126 ;; The following are the reserved words in IDL. Maybe we should
1127 ;; highlight some more stuff as well?
1128 ;; Procedure declarations. Fontify keyword plus procedure name.
1129 (defvar idlwave-idl-keywords
1130 ;; To update this regexp, update the list of keywords and
1131 ;; evaluate the form.
1137 ;; '("||" "&&" "and" "or" "xor" "not"
1138 ;; "eq" "ge" "gt" "le" "lt" "ne"
1139 ;; "for" "do" "endfor"
1140 ;; "if" "then" "endif" "else" "endelse"
1141 ;; "case" "of" "endcase"
1142 ;; "switch" "break" "continue" "endswitch"
1144 ;; "repeat" "until" "endrep"
1145 ;; "while" "endwhile"
1148 ;; "compile_opt" "forward_function"
1149 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1151 "\\<\\(&&\\|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\\|||\\)\\>")
1154 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1155 ;; Function declarations. Fontify keyword plus function name.
1157 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1158 (1 font-lock-keyword-face
)
1159 (2 font-lock-function-name-face nil t
)))
1163 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1164 (1 font-lock-keyword-face
) ; "common"
1165 (2 font-lock-reference-face nil t
) ; block name
1166 ("[ \t]*\\(\\sw+\\)[ ,]*"
1167 ;; Start with point after block name and comma
1168 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1170 (1 font-lock-variable-name-face
) ; variable names
1175 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1179 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1183 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1185 ;; The goto statement and its label
1187 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1188 (1 font-lock-keyword-face
)
1189 (2 font-lock-reference-face
)))
1191 ;; Tags in structure definitions. Note that this definition
1192 ;; actually collides with labels, so we have to use the same
1193 ;; face. It also matches named subscript ranges,
1194 ;; e.g. vec{bottom:top]. No good way around this.
1196 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1200 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1201 (2 font-lock-function-name-face
)))
1203 ;; Keyword parameters, like /xlog or ,xrange=[]
1204 ;; This is anchored to the comma preceeding the keyword.
1205 ;; Treats continuation lines, works only during whole buffer
1206 ;; fontification. Slow, use it only in fancy fontification.
1208 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1209 (6 font-lock-reference-face
)))
1211 ;; System variables start with a bang.
1213 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1214 (1 font-lock-variable-name-face
)))
1216 ;; Special and unusual operators (not used because too noisy)
1218 '("[<>#]" (0 font-lock-keyword-face
)))
1220 ;; All operators (not used because too noisy)
1222 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1224 ;; Arrows with text property `idlwave-class'
1226 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1228 (defconst idlwave-font-lock-keywords-1
1229 (list pros-and-functions batch-files
)
1230 "Subdued level highlighting for IDLWAVE mode.")
1232 (defconst idlwave-font-lock-keywords-2
1233 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1234 "Medium level highlighting for IDLWAVE mode.")
1236 (defconst idlwave-font-lock-keywords-3
1237 (list pros-and-functions
1239 idlwave-idl-keywords
1247 "Gaudy level highlighting for IDLWAVE mode."))
1249 (defun idlwave-match-class-arrows (limit)
1250 ;; Match an object arrow with class property
1251 (and idlwave-store-inquired-class
1252 (re-search-forward "->" limit
'limit
)
1253 (get-text-property (match-beginning 0) 'idlwave-class
)))
1255 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1256 "Default expressions to highlight in IDLWAVE mode.")
1258 (defvar idlwave-font-lock-defaults
1259 '((idlwave-font-lock-keywords
1260 idlwave-font-lock-keywords-1
1261 idlwave-font-lock-keywords-2
1262 idlwave-font-lock-keywords-3
)
1264 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1267 (put 'idlwave-mode
'font-lock-defaults
1268 idlwave-font-lock-defaults
) ; XEmacs
1270 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1271 "Regexp to match the start of a full-line comment.
1272 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1273 only by whitespace.")
1275 (defconst idlwave-begin-block-reg
1276 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1277 "Regular expression to find the beginning of a block. The case does
1278 not matter. The search skips matches in comments.")
1280 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1281 "Regular expression to find the beginning of a unit. The case does
1284 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1285 "Regular expression to find the line that indicates the end of unit.
1286 This line is the end of buffer or the start of another unit. The case does
1287 not matter. The search skips matches in comments.")
1289 (defconst idlwave-continue-line-reg
"\\<\\$"
1290 "Regular expression to match a continued line.")
1292 (defconst idlwave-end-block-reg
1293 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1294 "Regular expression to find the end of a block. The case does
1295 not matter. The search skips matches found in comments.")
1297 (defconst idlwave-block-matches
1299 ("function" .
"end")
1300 ("case" .
"endcase")
1301 ("else" .
"endelse")
1304 ("repeat" .
"endrep")
1305 ("switch" .
"endswitch")
1306 ("while" .
"endwhile"))
1307 "Matches between statements and the corresponding END variant.
1308 The cars are the reserved words starting a block. If the block really
1309 begins with BEGIN, the cars are the reserved words before the begin
1310 which can be used to identify the block type.
1311 This is used to check for the correct END type, to close blocks and
1312 to expand generic end statements to their detailed form.")
1314 (defconst idlwave-block-match-regexp
1315 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1316 "Regular expression matching reserved words which can stand before
1317 blocks starting with a BEGIN statement. The matches must have associations
1318 `idlwave-block-matches'")
1320 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1321 "Regular expression matching an IDL identifier.")
1323 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1324 "Regular expression matching IDL system variables.")
1326 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1327 "Regular expression matching IDL variable names.")
1329 (defconst idlwave-label
(concat idlwave-identifier
":")
1330 "Regular expression matching IDL labels.")
1332 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1333 "\\(\\s *" idlwave-identifier
"::\\)?"
1336 (defconst idlwave-statement-match
1338 ;; "endif else" is the only possible "end" that can be
1339 ;; followed by a statement on the same line.
1340 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1341 ;; all other "end"s can not be followed by a statement.
1342 (cons 'end
(list idlwave-end-block-reg nil
))
1343 '(if .
("if\\>" "then"))
1344 '(for .
("for\\>" "do"))
1345 '(begin .
("begin\\>" nil
))
1346 '(pdef .
("pro\\>\\|function\\>" nil
))
1347 '(while .
("while\\>" "do"))
1348 '(repeat .
("repeat\\>" "repeat"))
1349 '(goto .
("goto\\>" nil
))
1350 '(case .
("case\\>" nil
))
1351 '(switch .
("switch\\>" nil
))
1352 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1353 "\\(" idlwave-method-call
"\\s *\\)?"
1356 (cons 'call
(list (concat
1357 "\\(" idlwave-method-call
"\\s *\\)?"
1359 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1360 (cons 'assign
(list (concat
1361 "\\(" idlwave-variable
"\\) *=") nil
)))
1363 "Associated list of statement matching regular expressions.
1364 Each regular expression matches the start of an IDL statement. The
1365 first element of each association is a symbol giving the statement
1366 type. The associated value is a list. The first element of this list
1367 is a regular expression matching the start of an IDL statement for
1368 identifying the statement type. The second element of this list is a
1369 regular expression for finding a substatement for the type. The
1370 substatement starts after the end of the found match modulo
1371 whitespace. If it is nil then the statement has no substatement. The
1372 list order matters since matching an assignment statement exactly is
1373 not possible without parsing. Thus assignment statement become just
1374 the leftover unidentified statements containing an equal sign." )
1376 (defvar idlwave-fill-function
'auto-fill-function
1377 "IDL mode auto fill function.")
1379 (defvar idlwave-comment-indent-function
'comment-indent-function
1380 "IDL mode comment indent function.")
1382 ;; Note that this is documented in the v18 manuals as being a string
1383 ;; of length one rather than a single character.
1384 ;; The code in this file accepts either format for compatibility.
1385 (defvar idlwave-comment-indent-char ?\
1386 "Character to be inserted for IDL comment indentation.
1389 (defconst idlwave-continuation-char ?$
1390 "Character which is inserted as a last character on previous line by
1391 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1393 (defconst idlwave-mode-version
"6.1_em22")
1395 (defmacro idlwave-keyword-abbrev
(&rest args
)
1396 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1398 ,(append '(idlwave-check-abbrev) args
))))
1400 ;; If I take the time I can replace idlwave-keyword-abbrev with
1401 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1402 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1403 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1404 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1406 (defmacro idlwave-code-abbrev
(&rest args
)
1407 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1408 Specifically, if the abbrev is in a comment or string it is unexpanded.
1409 Otherwise ARGS forms a list that is evaluated."
1411 ,(prin1-to-string args
) ;; Puts the code in the doc string
1412 (if (idlwave-quoted)
1413 (progn (unexpand-abbrev) nil
)
1416 (defvar idlwave-mode-map
(make-sparse-keymap)
1417 "Keymap used in IDL mode.")
1419 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1420 "Syntax table in use in `idlwave-mode' buffers.")
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 ?
{ "(}" idlwave-mode-syntax-table
)
1437 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1438 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1439 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1440 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1441 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1442 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1444 (defvar idlwave-find-symbol-syntax-table
1445 (copy-syntax-table idlwave-mode-syntax-table
)
1446 "Syntax table that treats symbol characters as word characters.")
1448 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1449 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1450 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1451 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1453 (defmacro idlwave-with-special-syntax
(&rest body
)
1454 "Execute BODY with a different syntax table."
1455 `(let ((saved-syntax (syntax-table)))
1458 (set-syntax-table idlwave-find-symbol-syntax-table
)
1460 (set-syntax-table saved-syntax
))))
1462 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1463 ; "Execute BODY with a different syntax table."
1464 ; `(let ((saved-syntax (syntax-table)))
1467 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1469 ; (set-syntax-table saved-syntax))))
1471 (defun idlwave-action-and-binding (key cmd
&optional select
)
1472 "KEY and CMD are made into a key binding and an indent action.
1473 KEY is a string - same as for the `define-key' function. CMD is a
1474 function of no arguments or a list to be evaluated. CMD is bound to
1475 KEY in `idlwave-mode-map' by defining an anonymous function calling
1476 `self-insert-command' followed by CMD. If KEY contains more than one
1477 character a binding will only be set if SELECT is 'both.
1479 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1480 replacing any previous value for KEY. If a binding is not set then it
1481 will instead be placed in `idlwave-indent-action-table'.
1483 If the optional argument SELECT is nil then an action and binding are
1484 created. If SELECT is 'noaction, then a binding is always set and no
1485 action is created. If SELECT is 'both then an action and binding
1486 will both be created even if KEY contains more than one character.
1487 Otherwise, if SELECT is non-nil then only an action is created.
1490 No spaces before and 1 after a comma
1491 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1492 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1493 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1494 Capitalize system variables - action only
1495 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1496 (if (not (equal select
'noaction
))
1498 (let* ((table (if select
'idlwave-indent-action-table
1499 'idlwave-indent-expand-table
))
1500 (table-key (regexp-quote key
))
1501 (cell (assoc table-key
(eval table
))))
1503 ;; Replace action command
1506 (set table
(append (eval table
) (list (cons table-key cmd
)))))))
1507 ;; Make key binding for action
1508 (if (or (and (null select
) (= (length key
) 1))
1509 (equal select
'noaction
)
1510 (equal select
'both
))
1511 (define-key idlwave-mode-map key
1514 (self-insert-command 1))
1515 (list (if (listp cmd
)
1519 (fset 'idlwave-debug-map
(make-sparse-keymap))
1521 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1522 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1523 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1524 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1525 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1526 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1527 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1528 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1529 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1530 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1531 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1532 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1533 (define-key idlwave-mode-map
[(meta control h
)] 'idlwave-mark-subprogram
)
1534 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1535 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1536 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1537 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1538 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1539 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1540 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1541 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1542 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1543 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1544 (define-key idlwave-mode-map
[(shift iso-lefttab
)] 'idlwave-indent-statement
)
1545 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1546 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1547 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1548 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1549 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1550 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1551 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1552 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1553 (listp idlwave-shell-debug-modifiers
)
1554 (not (equal idlwave-shell-debug-modifiers
'())))
1555 ;; Bind the debug commands also with the special modifiers.
1556 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1557 (mods-noshift (delq 'shift
1558 (copy-sequence idlwave-shell-debug-modifiers
))))
1559 (define-key idlwave-mode-map
1560 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1561 'idlwave-shell-save-and-run
)
1562 (define-key idlwave-mode-map
1563 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1564 'idlwave-shell-break-here
)
1565 (define-key idlwave-mode-map
1566 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1567 'idlwave-shell-run-region
)))
1568 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1569 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1570 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1571 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1572 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1573 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1574 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1575 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1576 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1577 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1578 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1579 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1580 (autoload 'idlwave-shell
"idlw-shell"
1581 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1582 (autoload 'idlwave-shell-send-command
"idlw-shell")
1583 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1584 "Run `idlwave-shell' and switch back to current window" t
)
1585 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1586 "Save and run buffer under the shell." t
)
1587 (autoload 'idlwave-shell-break-here
"idlw-shell"
1588 "Set breakpoint in current line." t
)
1589 (autoload 'idlwave-shell-run-region
"idlw-shell"
1590 "Compile and run the region." t
)
1591 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1592 (define-key idlwave-mode-map
"\C-c\C-t" 'idlwave-find-module-this-file
)
1593 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1594 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1595 (define-key idlwave-mode-map
[(control meta ?
\?)]
1596 'idlwave-help-assistant-help-with-topic
)
1597 ;; Pickup both forms of Esc/Meta binding
1598 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1599 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1600 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1601 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1602 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1603 (define-key idlwave-mode-map
1604 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1605 'idlwave-mouse-context-help
)
1607 ;; Set action and key bindings.
1608 ;; See description of the function `idlwave-action-and-binding'.
1609 ;; Automatically add spaces for the following characters
1611 ;; Actions for & are complicated by &&
1612 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround
)
1614 ;; Automatically add spaces to equal sign if not keyword. This needs
1615 ;; to go ahead of > and <, so >= and <= will be treated correctly
1616 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1618 ;; Actions for > and < are complicated by >=, <=, and ->...
1619 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil
))
1620 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr
))
1622 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1 1))
1628 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1629 ;;; space is inserted (this is the space typed by the user to expanded
1632 (defvar idlwave-mode-abbrev-table nil
1633 "Abbreviation table used for IDLWAVE mode")
1634 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1636 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1637 "Define-abbrev with backward compatibility.
1639 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1640 idlwave-mode-abbrev-table unless TABLE is non-nil."
1641 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1642 (args (list (or table idlwave-mode-abbrev-table
)
1643 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1647 (apply 'define-abbrev
(append args
'(0 t
)))
1648 (error (apply 'define-abbrev args
)))))
1651 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1652 "w" idlwave-mode-syntax-table
)
1658 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1659 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1660 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1661 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1662 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1663 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1664 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1665 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1666 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1668 ;; Keywords, system functions, conversion routines
1670 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1672 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1673 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1680 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1681 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1682 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1683 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1684 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1685 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1686 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1687 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1688 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1689 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1690 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1691 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1696 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1705 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1714 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1715 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1716 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1718 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1720 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1721 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1723 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1724 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1725 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1727 ;; This section is reserved words only. (From IDL user manual)
1729 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1730 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1735 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1736 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1737 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1738 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1739 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1740 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1741 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1742 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1743 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1744 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1745 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1746 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1747 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1748 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1749 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1750 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1751 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1752 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1753 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1754 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1755 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1756 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1757 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1758 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1759 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1760 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1761 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1762 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1763 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1764 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1765 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1766 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1767 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1769 (defvar imenu-create-index-function
)
1770 (defvar extract-index-name-function
)
1771 (defvar prev-index-position-function
)
1772 (defvar imenu-extract-index-name-function
)
1773 (defvar imenu-prev-index-position-function
)
1774 ;; defined later - so just make the compiler hush
1775 (defvar idlwave-mode-menu
)
1776 (defvar idlwave-mode-debug-menu
)
1779 (defun idlwave-mode ()
1780 "Major mode for editing IDL source files (version 6.1_em22).
1782 The main features of this mode are
1784 1. Indentation and Formatting
1785 --------------------------
1786 Like other Emacs programming modes, C-j inserts a newline and indents.
1787 TAB is used for explicit indentation of the current line.
1789 To start a continuation line, use \\[idlwave-split-line]. This
1790 function can also be used in the middle of a line to split the line
1791 at that point. When used inside a long constant string, the string
1792 is split at that point with the `+' concatenation operator.
1794 Comments are indented as follows:
1796 `;;;' Indentation remains unchanged.
1797 `;;' Indent like the surrounding code
1798 `;' Indent to a minimum column.
1800 The indentation of comments starting in column 0 is never changed.
1802 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1803 comment. The indentation of the second line of the paragraph
1804 relative to the first will be retained. Use
1805 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1806 comments. When the variable `idlwave-fill-comment-line-only' is
1807 nil, code can also be auto-filled and auto-indented.
1809 To convert pre-existing IDL code to your formatting style, mark the
1810 entire buffer with \\[mark-whole-buffer] and execute
1811 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1812 again followed by \\[indent-region] (`indent-region').
1816 IDLWAVE displays information about the calling sequence and the
1817 accepted keyword parameters of a procedure or function with
1818 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1819 source file of a module. These commands know about system
1820 routines, all routines in idlwave-mode buffers and (when the
1821 idlwave-shell is active) about all modules currently compiled under
1822 this shell. It also makes use of pre-compiled or custom-scanned
1823 user and library catalogs many popular libraries ship with by
1824 default. Use \\[idlwave-update-routine-info] to update this
1825 information, which is also used for completion (see item 4).
1830 \\[idlwave-context-help] displays the IDL documentation relevant
1831 for the system variable, keyword, or routines at point. A single
1832 key stroke gets you directly to the right place in the docs. See
1833 the manual to configure where and how the HTML help is displayed.
1837 \\[idlwave-complete] completes the names of procedures, functions
1838 class names, keyword parameters, system variables and tags, class
1839 tags, structure tags, filenames and much more. It is context
1840 sensitive and figures out what is expected at point. Lower case
1841 strings are completed in lower case, other strings in mixed or
1844 5. Code Templates and Abbreviations
1845 --------------------------------
1846 Many Abbreviations are predefined to expand to code fragments and templates.
1847 The abbreviations start generally with a `\\`. Some examples
1849 \\pr PROCEDURE template
1850 \\fu FUNCTION template
1851 \\c CASE statement template
1852 \\sw SWITCH statement template
1853 \\f FOR loop template
1854 \\r REPEAT Loop template
1855 \\w WHILE loop template
1856 \\i IF statement template
1857 \\elif IF-ELSE statement template
1860 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1861 have direct keybindings - see the list of keybindings below.
1863 \\[idlwave-doc-header] inserts a documentation header at the
1864 beginning of the current program unit (pro, function or main).
1865 Change log entries can be added to the current program unit with
1866 \\[idlwave-doc-modification].
1868 6. Automatic Case Conversion
1869 -------------------------
1870 The case of reserved words and some abbrevs is controlled by
1871 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1873 7. Automatic END completion
1874 ------------------------
1875 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1876 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1880 Loading idlwave.el runs `idlwave-load-hook'.
1881 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1883 9. Documentation and Customization
1884 -------------------------------
1885 Info documentation for this package is available. Use
1886 \\[idlwave-info] to display (complain to your sysadmin if that does
1887 not work). For Postscript, PDF, and HTML versions of the
1888 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1889 IDLWAVE has customize support - see the group `idlwave'.
1893 Here is a list of all keybindings of this mode.
1894 If some of the key bindings below show with ??, use \\[describe-key]
1895 followed by the key sequence to see what the key sequence does.
1897 \\{idlwave-mode-map}"
1900 (kill-all-local-variables)
1902 (if idlwave-startup-message
1903 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1904 (setq idlwave-startup-message nil
)
1906 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1907 (set-syntax-table idlwave-mode-syntax-table
)
1909 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1911 (make-local-variable idlwave-comment-indent-function
)
1912 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1914 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1915 (set (make-local-variable 'comment-start
) ";")
1916 (set (make-local-variable 'comment-add
) 1) ; ";;" for new and regions
1917 (set (make-local-variable 'require-final-newline
) t
)
1918 (set (make-local-variable 'abbrev-all-caps
) t
)
1919 (set (make-local-variable 'indent-tabs-mode
) nil
)
1920 (set (make-local-variable 'completion-ignore-case
) t
)
1922 (use-local-map idlwave-mode-map
)
1924 (when (featurep 'easymenu
)
1925 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1926 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1928 (setq mode-name
"IDLWAVE")
1929 (setq major-mode
'idlwave-mode
)
1930 (setq abbrev-mode t
)
1932 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1933 (setq comment-end
"")
1934 (set (make-local-variable 'comment-multi-line
) nil
)
1935 (set (make-local-variable 'paragraph-separate
)
1936 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1937 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1938 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1939 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1942 (set (make-local-variable 'add-log-current-defun-function
)
1943 'idlwave-current-routine-fullname
)
1945 ;; Set tag table list to use IDLTAGS as file name.
1946 (if (boundp 'tag-table-alist
)
1947 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1949 ;; Font-lock additions
1950 ;; Following line is for Emacs - XEmacs uses the corresponding property
1951 ;; on the `idlwave-mode' symbol.
1952 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1953 (set (make-local-variable 'font-lock-mark-block-function
)
1954 'idlwave-mark-subprogram
)
1955 (set (make-local-variable 'font-lock-fontify-region-function
)
1956 'idlwave-font-lock-fontify-region
)
1959 (set (make-local-variable 'imenu-create-index-function
)
1960 'imenu-default-create-index-function
)
1961 (set (make-local-variable 'imenu-extract-index-name-function
)
1963 (set (make-local-variable 'imenu-prev-index-position-function
)
1964 'idlwave-prev-index-position
)
1967 (add-to-list 'hs-special-modes-alist
1969 idlwave-begin-block-reg
1970 idlwave-end-block-reg
1972 'idlwave-forward-block nil
))
1974 ;; Make a local post-command-hook and add our hook to it
1975 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1976 ;; (make-local-hook 'post-command-hook)
1977 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1979 ;; Make local hooks for buffer updates
1980 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1981 ;; (make-local-hook 'kill-buffer-hook)
1982 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1983 ;; (make-local-hook 'after-save-hook)
1984 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1985 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1987 ;; Setup directories and file, if necessary
1990 ;; Update the routine info with info about current buffer?
1991 (idlwave-new-buffer-update)
1993 ;; Check help location
1994 (idlwave-help-check-locations)
1996 ;; Run the mode hook
1997 (run-mode-hooks 'idlwave-mode-hook
))
1999 (defvar idlwave-setup-done nil
)
2000 (defun idlwave-setup ()
2001 (unless idlwave-setup-done
2002 (if (not (file-directory-p idlwave-config-directory
))
2003 (make-directory idlwave-config-directory
))
2005 idlwave-user-catalog-file
(expand-file-name
2006 idlwave-user-catalog-file
2007 idlwave-config-directory
)
2008 idlwave-xml-system-rinfo-converted-file
2010 idlwave-xml-system-rinfo-converted-file
2011 idlwave-config-directory
)
2012 idlwave-path-file
(expand-file-name
2014 idlwave-config-directory
))
2015 (idlwave-read-paths) ; we may need these early
2016 (setq idlwave-setup-done t
)))
2018 (defun idlwave-font-lock-fontify-region (beg end
&optional verbose
)
2019 "Fontify continuation lines correctly."
2024 (when (setq pos
(idlwave-is-continuation-line))
2026 (idlwave-beginning-of-statement)
2027 (setq beg
(point)))))
2028 (font-lock-default-fontify-region beg end verbose
))
2031 ;; Code Formatting ----------------------------------------------------
2034 (defun idlwave-hard-tab ()
2035 "Inserts TAB in buffer in current position."
2039 ;;; This stuff is experimental
2041 (defvar idlwave-command-hook nil
2042 "If non-nil, a list that can be evaluated using `eval'.
2043 It is evaluated in the lisp function `idlwave-command-hook' which is
2044 placed in `post-command-hook'.")
2046 (defun idlwave-command-hook ()
2047 "Command run after every command.
2048 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2049 sets the variable to zero afterwards."
2050 (and idlwave-command-hook
2051 (listp idlwave-command-hook
)
2053 (eval idlwave-command-hook
)
2055 (setq idlwave-command-hook nil
))
2059 ;; It would be better to use expand.el for better abbrev handling and
2062 (defun idlwave-check-abbrev (arg &optional reserved
)
2063 "Reverses abbrev expansion if in comment or string.
2064 Argument ARG is the number of characters to move point
2065 backward if `idlwave-abbrev-move' is non-nil.
2066 If optional argument RESERVED is non-nil then the expansion
2067 consists of reserved words, which will be capitalized if
2068 `idlwave-reserved-word-upcase' is non-nil.
2069 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2070 is non-nil, unless its value is \`down in which case the abbrev will be
2071 made into all lowercase.
2072 Returns non-nil if abbrev is left expanded."
2073 (if (idlwave-quoted)
2074 (progn (unexpand-abbrev)
2076 (if (and reserved idlwave-reserved-word-upcase
)
2077 (upcase-region last-abbrev-location
(point))
2079 ((equal idlwave-abbrev-change-case
'down
)
2080 (downcase-region last-abbrev-location
(point)))
2081 (idlwave-abbrev-change-case
2082 (upcase-region last-abbrev-location
(point)))))
2083 (if (and idlwave-abbrev-move
(> arg
0))
2084 (if (boundp 'post-command-hook
)
2085 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2086 (backward-char arg
)))
2089 (defun idlwave-in-comment ()
2090 "Returns t if point is inside a comment, nil otherwise."
2092 (let ((here (point)))
2093 (and (idlwave-goto-comment) (> here
(point))))))
2095 (defun idlwave-goto-comment ()
2096 "Move to start of comment delimiter on current line.
2097 Moves to end of line if there is no comment delimiter.
2098 Ignores comment delimiters in strings.
2099 Returns point if comment found and nil otherwise."
2100 (let ((eos (progn (end-of-line) (point)))
2103 ;; Look for first comment delimiter not in a string
2105 (setq found
(search-forward comment-start eos
'lim
))
2106 (while (and found
(idlwave-in-quote))
2107 (setq found
(search-forward comment-start eos
'lim
)))
2108 (store-match-data data
)
2109 (and found
(not (idlwave-in-quote))
2114 (defun idlwave-region-active-p ()
2115 "Should we operate on an active region?"
2116 (if (fboundp 'use-region-p
)
2120 (defun idlwave-show-matching-quote ()
2121 "Insert quote and show matching quote if this is end of a string."
2123 (let ((bq (idlwave-in-quote))
2124 (inq last-command-char
))
2125 (if (and bq
(not (idlwave-in-comment)))
2126 (let ((delim (char-after bq
)))
2132 ;; Not the end of a string
2135 (defun idlwave-show-begin-check ()
2136 "Ensure that the previous word was a token before `idlwave-show-begin'.
2137 An END token must be preceded by whitespace."
2138 (if (not (idlwave-quoted))
2143 (looking-at "[ \t\n\f]"))
2144 (idlwave-show-begin))))
2146 (defun idlwave-show-begin ()
2147 "Finds the start of current block and blinks to it for a second.
2148 Also checks if the correct end statement has been used."
2149 ;; All end statements are reserved words
2150 ;; Re-indent end line
2151 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2153 (let* ((pos (point-marker))
2154 (last-abbrev-marker (copy-marker last-abbrev-location
))
2155 (eol-pos (save-excursion (end-of-line) (point)))
2156 begin-pos end-pos end end1
)
2157 (if idlwave-reindent-end
(idlwave-indent-line))
2158 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2159 (when (and (idlwave-check-abbrev 0 t
)
2162 ;; Move inside current block
2163 (goto-char last-abbrev-marker
)
2164 (idlwave-block-jump-out -
1 'nomark
)
2165 (setq begin-pos
(point))
2166 (idlwave-block-jump-out 1 'nomark
)
2167 (setq end-pos
(point))
2168 (if (> end-pos eol-pos
)
2171 (setq end
(buffer-substring
2173 (skip-chars-backward "a-zA-Z")
2176 (goto-char begin-pos
)
2177 (when (setq end1
(cdr (idlwave-block-master)))
2179 ((null end1
)) ; no-operation
2180 ((string= (downcase end
) (downcase end1
))
2182 ((string= (downcase end
) "end")
2184 (if idlwave-expand-generic-end
2188 (insert (if (string= end
"END") (upcase end1
) end1
))
2193 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2198 (defun idlwave-block-master ()
2199 (let ((case-fold-search t
))
2202 ((looking-at "pro\\|case\\|switch\\|function\\>")
2203 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2204 ((looking-at "begin\\>")
2205 (let ((limit (save-excursion
2206 (idlwave-beginning-of-statement)
2209 ((re-search-backward ":[ \t]*\\=" limit t
)
2210 ;; seems to be a case thing
2212 ((re-search-backward idlwave-block-match-regexp limit t
)
2213 (assoc (downcase (match-string 1))
2214 idlwave-block-matches
))
2216 ;; Just a normal block
2217 '("begin" .
"end")))))
2220 (defun idlwave-close-block ()
2221 "Terminate the current block with the correct END statement."
2223 ;; Start new line if we are not in a new line
2224 (unless (save-excursion
2225 (skip-chars-backward " \t")
2227 (let ((idlwave-show-block nil
))
2228 (newline-and-indent)))
2229 (let ((last-abbrev-location (point))) ; for upcasing
2231 (idlwave-show-begin)))
2233 (defun idlwave-custom-ampersand-surround (&optional is-action
)
2234 "Surround &, leaving room for && (which surrround as well)."
2235 (let* ((prev-char (char-after (- (point) 2)))
2236 (next-char (char-after (point)))
2237 (amp-left (eq prev-char ?
&))
2238 (amp-right (eq next-char ?
&))
2239 (len (if amp-left
2 1)))
2240 (unless amp-right
;no need to do it twice, amp-left will catch it.
2241 (idlwave-surround -
1 (if (or is-action amp-left
) -
1) len
))))
2243 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action
)
2244 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2245 (let* ((prev-char (char-after (- (point) 2)))
2246 (next-char (char-after (point)))
2247 (method-invoke (and gtr
(eq prev-char ?-
)))
2248 (len (if method-invoke
2 1)))
2249 (unless (eq next-char ?
=)
2250 ;; Key binding: pad only on left, to save for possible >=/<=
2251 (idlwave-surround -
1 (if (or is-action method-invoke
) -
1) len
))))
2253 (defun idlwave-surround (&optional before after length is-action
)
2254 "Surround the LENGTH characters before point with blanks.
2255 LENGTH defaults to 1.
2256 Optional arguments BEFORE and AFTER affect the behavior before and
2257 after the characters (see also description of `idlwave-make-space'):
2261 integer > 0 force exactly n spaces
2262 integer < 0 at least |n| spaces
2264 The function does nothing if any of the following conditions is true:
2265 - `idlwave-surround-by-blank' is nil
2266 - the character before point is inside a string or comment"
2267 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2268 (let ((length (or length
1))) ; establish a default for LENGTH
2269 (backward-char length
)
2271 (let ((here (point)))
2272 (skip-chars-backward " \t")
2274 ;; avoid clobbering indent
2276 (move-to-column (idlwave-calculate-indent))
2277 (if (<= (point) here
)
2278 (narrow-to-region (point) here
))
2280 (idlwave-make-space before
))
2281 (skip-chars-forward " \t"))
2282 (forward-char length
)
2283 (idlwave-make-space after
)
2284 ;; Check to see if the line should auto wrap
2285 (if (and (equal (char-after (1- (point))) ?\
)
2286 (> (current-column) fill-column
))
2287 (funcall auto-fill-function
)))))
2289 (defun idlwave-make-space (n)
2290 "Make space at point.
2291 The space affected is all the spaces and tabs around point.
2292 If n is non-nil then point is left abs(n) spaces from the beginning of
2293 the contiguous space.
2294 The amount of space at point is determined by N.
2295 If the value of N is:
2297 > 0 - exactly N spaces.
2298 < 0 - a minimum of -N spaces, i.e., do not change if there are
2300 0 - no spaces (i.e. remove any existing space)."
2303 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2305 (end-col (progn (skip-chars-forward " \t") (current-column))))
2306 (delete-horizontal-space)
2309 (idlwave-indent-to (+ start-col n
))
2310 (goto-char (+ left n
)))
2312 (idlwave-indent-to end-col
(- n
))
2313 (goto-char (- left n
)))
2317 (defun idlwave-newline ()
2318 "Inserts a newline and indents the current and previous line."
2321 ;; Handle unterminated single and double quotes
2322 ;; If not in a comment and in a string then insertion of a newline
2323 ;; will mean unbalanced quotes.
2325 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2327 (message "Warning: unbalanced quotes?")))
2330 ;; The current line is being split, the cursor should be at the
2331 ;; beginning of the new line skipping the leading indentation.
2333 ;; The reason we insert the new line before indenting is that the
2334 ;; indenting could be confused by keywords (e.g. END) on the line
2335 ;; after the split point. This prevents us from just using
2336 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2338 (beginning-of-line 0)
2339 (idlwave-indent-line)
2341 (idlwave-indent-line))
2344 ;; Use global variable 'comment-column' to set parallel comment
2346 ;; Modeled on lisp.el
2347 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2348 (defun idlwave-comment-hook ()
2349 "Compute indent for the beginning of the IDL comment delimiter."
2350 (if (or (looking-at idlwave-no-change-comment
)
2351 (if idlwave-begin-line-comment
2352 (looking-at idlwave-begin-line-comment
)
2355 (if (looking-at idlwave-code-comment
)
2356 (if (save-excursion (skip-chars-backward " \t") (bolp))
2357 ;; On line by itself, indent as code
2358 (let ((tem (idlwave-calculate-indent)))
2359 (if (listp tem
) (car tem
) tem
))
2360 ;; after code - do not change
2362 (skip-chars-backward " \t")
2363 (max (if (bolp) 0 (1+ (current-column)))
2366 (defun idlwave-split-line ()
2367 "Continue line by breaking line at point and indent the lines.
2368 For a code line insert continuation marker. If the line is a line comment
2369 then the new line will contain a comment with the same indentation.
2370 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2373 ;; Expand abbreviation, just like normal RET would.
2374 (and abbrev-mode
(expand-abbrev))
2376 (if (not (idlwave-in-comment))
2377 ;; For code line add continuation.
2378 ;; Check if splitting a string.
2380 (if (setq beg
(idlwave-in-quote))
2381 (if idlwave-split-line-string
2382 ;; Split the string.
2383 (progn (insert (setq beg
(char-after beg
)) " + "
2384 idlwave-continuation-char beg
)
2386 (newline-and-indent)
2388 ;; Do not split the string.
2390 (message "Warning: continuation inside string!!")
2391 (insert " " idlwave-continuation-char
))
2392 ;; Not splitting a string.
2393 (if (not (member (char-before) '(?\ ?
\t)))
2395 (insert idlwave-continuation-char
)
2396 (newline-and-indent)))
2397 (indent-new-comment-line))
2398 ;; Indent previous line
2399 (setq beg
(- (point-max) (point)))
2401 (idlwave-indent-line)
2402 (goto-char (- (point-max) beg
))
2403 ;; Reindent new line
2404 (idlwave-indent-line)))
2406 (defun idlwave-beginning-of-subprogram (&optional nomark
)
2407 "Moves point to the beginning of the current program unit.
2408 If NOMARK is non-nil, do not push mark."
2410 (idlwave-find-key idlwave-begin-unit-reg -
1 nomark
))
2412 (defun idlwave-end-of-subprogram (&optional nomark
)
2413 "Moves point to the start of the next program unit.
2414 If NOMARK is non-nil, do not push mark."
2416 (idlwave-end-of-statement)
2417 (idlwave-find-key idlwave-end-unit-reg
1 nomark
))
2419 (defun idlwave-mark-statement ()
2420 "Mark current IDL statement."
2422 (idlwave-end-of-statement)
2423 (let ((end (point)))
2424 (idlwave-beginning-of-statement)
2425 (push-mark end nil t
)))
2427 (defun idlwave-mark-block ()
2428 "Mark containing block."
2430 (idlwave-end-of-statement)
2431 (idlwave-backward-up-block -
1)
2432 (idlwave-end-of-statement)
2433 (let ((end (point)))
2434 (idlwave-backward-block)
2435 (idlwave-beginning-of-statement)
2436 (push-mark end nil t
)))
2439 (defun idlwave-mark-subprogram ()
2440 "Put mark at beginning of program, point at end.
2441 The marks are pushed."
2443 (idlwave-end-of-statement)
2444 (idlwave-beginning-of-subprogram)
2445 (let ((beg (point)))
2446 (idlwave-forward-block)
2447 (push-mark beg nil t
))
2448 (exchange-point-and-mark))
2450 (defun idlwave-backward-up-block (&optional arg
)
2451 "Move to beginning of enclosing block if prefix ARG >= 0.
2452 If prefix ARG < 0 then move forward to enclosing block end."
2454 (idlwave-block-jump-out (- arg
) 'nomark
))
2456 (defun idlwave-beginning-of-block ()
2457 "Go to the beginning of the current block."
2459 (idlwave-block-jump-out -
1 'nomark
)
2462 (defun idlwave-end-of-block ()
2463 "Go to the beginning of the current block."
2465 (idlwave-block-jump-out 1 'nomark
)
2468 (defun idlwave-forward-block (&optional arg
)
2469 "Move across next nested block."
2471 (let ((arg (or arg
1)))
2472 (if (idlwave-down-block arg
)
2473 (idlwave-block-jump-out arg
'nomark
))))
2475 (defun idlwave-backward-block ()
2476 "Move backward across previous nested block."
2478 (if (idlwave-down-block -
1)
2479 (idlwave-block-jump-out -
1 'nomark
)))
2481 (defun idlwave-down-block (&optional arg
)
2483 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2484 Returns non-nil if successfull."
2489 (let ((eos (save-excursion
2490 (idlwave-block-jump-out -
1 'nomark
)
2492 (if (setq status
(idlwave-find-key
2493 idlwave-end-block-reg -
1 'nomark eos
))
2494 (idlwave-beginning-of-statement)
2495 (message "No nested block before beginning of containing block.")))
2497 (let ((eos (save-excursion
2498 (idlwave-block-jump-out 1 'nomark
)
2500 (if (setq status
(idlwave-find-key
2501 idlwave-begin-block-reg
1 'nomark eos
))
2502 (idlwave-end-of-statement)
2503 (message "No nested block before end of containing block."))))
2506 (defun idlwave-mark-doclib ()
2507 "Put point at beginning of doc library header, mark at end.
2508 The marks are pushed."
2512 (goto-char (point-max))
2513 (if (re-search-backward idlwave-doclib-start nil t
)
2515 (setq beg
(progn (beginning-of-line) (point)))
2516 (if (re-search-forward idlwave-doclib-end nil t
)
2519 (push-mark beg nil t
)
2520 (message "Could not find end of doc library header.")))
2521 (message "Could not find doc library header start.")
2522 (goto-char here
)))))
2524 (defun idlwave-current-routine-fullname ()
2525 (let ((name (idlwave-current-routine)))
2526 (idlwave-make-full-name (nth 2 name
) (car name
))))
2528 (defun idlwave-current-routine ()
2529 "Return (NAME TYPE CLASS) of current routine."
2532 (idlwave-beginning-of-subprogram 'nomark
)
2533 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2534 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2536 (class (idlwave-sintern-class (match-string 3)))
2537 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2538 (list name type class
)))))
2540 (defvar idlwave-shell-prompt-pattern
)
2541 (defun idlwave-beginning-of-statement ()
2542 "Move to beginning of the current statement.
2543 Skips back past statement continuations.
2544 Point is placed at the beginning of the line whether or not this is an
2548 ((eq major-mode
'idlwave-shell-mode
)
2549 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2550 (goto-char (match-end 0))))
2552 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2553 (idlwave-previous-statement)
2554 (beginning-of-line)))))
2556 (defun idlwave-previous-statement ()
2557 "Moves point to beginning of the previous statement.
2558 Returns t if the current line before moving is the beginning of
2559 the first non-comment statement in the file, and nil otherwise."
2561 (let (first-statement)
2562 (if (not (= (forward-line -
1) 0))
2563 ;; first line in file
2565 ;; skip blank lines, label lines, include lines and line comments
2567 ;; The current statement is the first statement until we
2568 ;; reach another statement.
2569 (setq first-statement
2571 (looking-at idlwave-comment-line-start-skip
)
2572 (looking-at "[ \t]*$")
2573 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2575 (= (forward-line -
1) 0)))
2576 ;; skip continuation lines
2580 (idlwave-is-continuation-line))
2581 (= (forward-line -
1) 0)))
2584 (defun idlwave-end-of-statement ()
2585 "Moves point to the end of the current IDL statement.
2586 If not in a statement just moves to end of line. Returns position."
2588 (while (and (idlwave-is-continuation-line)
2589 (= (forward-line 1) 0))
2590 (while (and (idlwave-is-comment-or-empty-line)
2591 (= (forward-line 1) 0))))
2595 (defun idlwave-end-of-statement0 ()
2596 "Moves point to the end of the current IDL statement.
2597 If not in a statement just moves to end of line. Returns position."
2599 (while (and (idlwave-is-continuation-line)
2600 (= (forward-line 1) 0)))
2604 (defun idlwave-next-statement ()
2605 "Moves point to beginning of the next IDL statement.
2606 Returns t if that statement is the last
2607 non-comment IDL statement in the file, and nil otherwise."
2609 (let (last-statement)
2610 (idlwave-end-of-statement)
2611 ;; skip blank lines, label lines, include lines and line comments
2612 (while (and (= (forward-line 1) 0)
2613 ;; The current statement is the last statement until
2614 ;; we reach a new statement.
2615 (setq last-statement
2617 (looking-at idlwave-comment-line-start-skip
)
2618 (looking-at "[ \t]*$")
2619 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2620 (looking-at "^@")))))
2623 (defun idlwave-skip-multi-commands (&optional lim
)
2624 "Skip past multiple commands on a line (with `&')."
2625 (let ((save-point (point)))
2626 (when (re-search-forward ".*&" lim t
)
2627 (goto-char (match-end 0))
2628 (if (idlwave-quoted)
2629 (goto-char save-point
)
2630 (if (eq (char-after (- (point) 2)) ?
&) (goto-char save-point
))))
2633 (defun idlwave-skip-label-or-case ()
2634 "Skip label or case statement element.
2635 Returns position after label.
2636 If there is no label point is not moved and nil is returned."
2637 ;; Case expressions and labels are terminated by a colon.
2638 ;; So we find the first colon in the line and make sure
2639 ;; - no `?' is before it (might be a ? b : c)
2640 ;; - it is not in a comment
2641 ;; - not in a string constant
2642 ;; - not in parenthesis (like a[0:3])
2643 ;; - not followed by another ":" in explicit class, ala a->b::c
2644 ;; As many in this mode, this function is heuristic and not an exact
2646 (let* ((start (point))
2647 (eos (save-excursion (idlwave-end-of-statement) (point)))
2648 (end (idlwave-find-key ":" 1 'nomark eos
)))
2650 (= (nth 0 (parse-partial-sexp start end
)) 0)
2651 (not (string-match "\\?" (buffer-substring start end
)))
2652 (not (string-match "^::" (buffer-substring end eos
))))
2659 (defun idlwave-start-of-substatement (&optional pre
)
2660 "Move to start of next IDL substatement after point.
2661 Uses the type of the current IDL statement to determine if the next
2662 statement is on a new line or is a subpart of the current statement.
2663 Returns point at start of substatement modulo whitespace.
2664 If optional argument is non-nil move to beginning of current
2666 (let ((orig (point))
2667 (eos (idlwave-end-of-statement))
2670 (idlwave-beginning-of-statement)
2671 (idlwave-skip-label-or-case)
2672 (if (< (point) orig
)
2673 (idlwave-skip-multi-commands orig
))
2675 ;; Continue looking for substatements until we are past orig
2676 (while (and (<= (point) orig
) (not (eobp)))
2678 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2679 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2681 (idlwave-find-key nst
1 'nomark eos
))
2682 (goto-char (match-end 0)))
2683 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2684 (setq ifnest
(1- ifnest
))
2685 (goto-char (match-end 0)))
2687 (idlwave-next-statement))))
2688 (if pre
(goto-char last
))
2689 ;; If a continuation line starts here, move to next line
2690 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2691 (beginning-of-line 2))
2694 (defun idlwave-statement-type ()
2695 "Return the type of the current IDL statement.
2696 Uses `idlwave-statement-match' to return a cons of (type . point) with
2697 point the ending position where the type was determined. Type is the
2698 association from `idlwave-statement-match', i.e. the cons cell from the
2699 list not just the type symbol. Returns nil if not an identifiable
2702 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2703 ;; and possibly comments
2704 (while (looking-at "[ \t]*\\$")
2706 (skip-chars-forward " \t")
2707 (let ((st idlwave-statement-match
)
2708 (case-fold-search t
))
2709 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2710 (setq st
(cdr st
))))
2712 (append st
(match-end 0))))))
2714 (defun idlwave-expand-equal (&optional before after is-action
)
2715 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2716 assignment. Which case is determined using
2717 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2718 equal sign will be surrounded by BEFORE and AFTER blanks. If
2719 `idlwave-pad-keyword' is t then keyword assignment is treated just
2720 like assignment statements. When nil, spaces are removed for keyword
2721 assignment. Any other value keeps the current space around the `='.
2722 Limits in for loops are treated as keyword assignment.
2724 Starting with IDL 6.0, a number of op= assignments are available.
2725 Since ambiguities of the form:
2730 can occur, alphanumeric operator assignment will never be pre-padded,
2731 only post-padded. You must use a space before these to disambiguate
2732 \(not just for padding, but for proper parsing by IDL too!). Other
2733 operators, such as ##=, ^=, etc., will be pre-padded.
2735 IS-ACTION is ignored.
2737 See `idlwave-surround'."
2738 (if idlwave-surround-by-blank
2740 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2742 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2746 (let ((case-fold-search t
))
2749 (re-search-backward non-an-ops nil t
)
2750 ;; Why doesn't ##? work for both?
2751 (re-search-backward "\\(#\\)\\=" nil t
))
2752 (setq len
(1+ (length (match-string 1))))
2753 (when (re-search-backward an-ops nil t
)
2754 ;(setq begin nil) ; won't modify begin
2755 (setq len
(1+ (length (match-string 1))))))))
2757 (if (eq t idlwave-pad-keyword
)
2758 ;; Everything gets padded equally
2759 (idlwave-surround before after len
)
2760 ;; Treating keywords/for variables specially...
2761 (let ((st (save-excursion ; To catch "for" variables
2762 (idlwave-start-of-substatement t
)
2763 (idlwave-statement-type)))
2764 (what (save-excursion ; To catch keywords
2765 (skip-chars-backward "= \t")
2766 (nth 2 (idlwave-where)))))
2767 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2768 (memq (caar st
) '(for pdef
)))
2770 ((null idlwave-pad-keyword
)
2771 (idlwave-surround 0 0)
2773 (t))) ; leave any spaces alone
2774 (t (idlwave-surround before after len
))))))))
2777 (defun idlwave-indent-and-action (&optional arg
)
2778 "Call `idlwave-indent-line' and do expand actions.
2779 With prefix ARG non-nil, indent the entire sub-statement."
2782 (if (and idlwave-expand-generic-end
2783 (re-search-backward "\\<\\(end\\)\\s-*\\="
2784 (max 0 (- (point) 10)) t
)
2785 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2786 (progn (goto-char (match-end 1))
2787 ;;Expand the END abbreviation, just as RET or Space would have.
2788 (if abbrev-mode
(expand-abbrev)
2789 (idlwave-show-begin)))))
2790 (when (and (not arg
) current-prefix-arg
)
2791 (setq arg current-prefix-arg
)
2792 (setq current-prefix-arg nil
))
2794 (idlwave-indent-statement)
2795 (idlwave-indent-line t
)))
2797 (defun idlwave-indent-line (&optional expand
)
2798 "Indents current IDL line as code or as a comment.
2799 The actions in `idlwave-indent-action-table' are performed.
2800 If the optional argument EXPAND is non-nil then the actions in
2801 `idlwave-indent-expand-table' are performed."
2803 ;; Move point out of left margin.
2805 (skip-chars-backward " \t")
2807 (skip-chars-forward " \t"))
2808 (let ((mloc (point-marker)))
2811 (if (looking-at idlwave-comment-line-start-skip
)
2812 ;; Indentation for a line comment
2814 (skip-chars-forward " \t")
2815 (idlwave-indent-left-margin (idlwave-comment-hook)))
2819 ;; Before indenting, run action routines.
2821 (if (and expand idlwave-do-actions
)
2822 (mapc 'idlwave-do-action idlwave-indent-expand-table
))
2824 (if idlwave-do-actions
2825 (mapc 'idlwave-do-action idlwave-indent-action-table
))
2827 ;; No longer expand abbrevs on the line. The user can do this
2828 ;; manually using expand-region-abbrevs.
2830 ;; Indent for code line
2835 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2837 (looking-at "^[ \t]*@"))
2841 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2842 ;; Adjust parallel comment
2844 (if (idlwave-in-comment)
2845 ;; Emacs 21 is too smart with fill-column on comment indent
2846 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2849 (indent-for-comment)))))
2851 ;; Get rid of marker
2852 (set-marker mloc nil
)))
2854 (defun idlwave-do-action (action)
2855 "Perform an action repeatedly on a line. ACTION is a list (REG
2856 . FUNC). REG is a regular expression. FUNC is either a function name
2857 to be called with `funcall' or a list to be evaluated with `eval'.
2858 The action performed by FUNC should leave point after the match for
2859 REG - otherwise an infinite loop may be entered. FUNC is always
2860 passed a final argument of 'is-action, so it can discriminate between
2861 being run as an action, or a key binding"
2862 (let ((action-key (car action
))
2863 (action-routine (cdr action
)))
2865 (while (idlwave-look-at action-key
)
2866 (if (listp action-routine
)
2867 (eval (append action-routine
'('is-action
)))
2868 (funcall action-routine
'is-action
)))))
2870 (defun idlwave-indent-to (col &optional min
)
2871 "Indent from point with spaces until column COL.
2872 Inserts space before markers at point."
2873 (if (not min
) (setq min
0))
2874 (insert-before-markers
2875 (make-string (max min
(- col
(current-column))) ?\
)))
2877 (defun idlwave-indent-left-margin (col)
2878 "Indent the current line to column COL.
2879 Indents such that first non-whitespace character is at column COL
2880 Inserts spaces before markers at point."
2883 (delete-horizontal-space)
2884 (idlwave-indent-to col
)))
2886 (defun idlwave-indent-subprogram ()
2887 "Indents program unit which contains point."
2890 (idlwave-end-of-statement)
2891 (idlwave-beginning-of-subprogram)
2892 (let ((beg (point)))
2893 (idlwave-forward-block)
2894 (message "Indenting subprogram...")
2895 (indent-region beg
(point) nil
))
2896 (message "Indenting subprogram...done.")))
2898 (defun idlwave-indent-statement ()
2899 "Indent current statement, including all continuation lines."
2902 (idlwave-beginning-of-statement)
2903 (let ((beg (point)))
2904 (idlwave-end-of-statement)
2905 (indent-region beg
(point) nil
))))
2907 (defun idlwave-calculate-indent ()
2908 "Return appropriate indentation for current line as IDL code."
2912 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2914 ((idlwave-look-at idlwave-begin-unit-reg
)
2916 ;; Check for continuation line
2918 (and (= (forward-line -
1) 0)
2919 (idlwave-is-continuation-line)))
2920 (idlwave-calculate-cont-indent))
2921 ;; calculate indent based on previous and current statements
2922 (t (let* (beg-prev-pos
2924 ;; calculate indent based on previous statement
2927 ;; Beginning of file
2929 (idlwave-previous-statement)
2930 (setq beg-prev-pos
(point)))
2933 ((idlwave-look-at idlwave-begin-unit-reg t
)
2934 (+ (idlwave-current-statement-indent)
2935 idlwave-main-block-indent
))
2937 ((idlwave-look-at idlwave-begin-block-reg t
)
2938 (+ (idlwave-min-current-statement-indent)
2939 idlwave-block-indent
))
2941 ((idlwave-look-at idlwave-end-block-reg t
)
2943 ;; Match to the *beginning* of the block opener
2944 (goto-char beg-prev-pos
)
2945 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2946 (idlwave-min-current-statement-indent)))
2947 ;; idlwave-end-offset
2948 ;; idlwave-block-indent))
2950 ;; Default to current indent
2951 ((idlwave-current-statement-indent))))))
2952 ;; adjust the indentation based on the current statement
2955 ((idlwave-look-at idlwave-end-block-reg
)
2956 (+ the-indent idlwave-end-offset
))
2960 ;; Parentheses indent
2963 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2964 "Calculate the continuation indent inside a paren group.
2965 Returns a cons-cell with (open . indent), where open is the
2966 location of the open paren"
2967 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2968 ;; Found an innermost open paren.
2971 ;; Line up with next word unless this is a closing paren.
2974 ;; Plain Kernighan-style nested indent
2975 (idlwave-indent-parens-nested
2976 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2978 ;; This is a closed paren - line up under open paren.
2982 ;; Empty (or just comment) follows -- revert to basic indent
2986 (looking-at "[ \t$]*\\(;.*\\)?$"))
2989 ;; Line up with first word after any blank space
2991 (skip-chars-forward " \t")
2992 (current-column))))))))
2994 (defun idlwave-calculate-cont-indent ()
2995 "Calculates the IDL continuation indent column from the previous
2996 statement. Note that here previous statement usually means the
2997 beginning of the current statement if this statement is a continuation
2998 of the previous line. Various special types of continuations,
2999 including assignments, routine definitions, and parenthetical
3000 groupings, are treated separately."
3002 (let* ((case-fold-search t
)
3003 (end-reg (progn (beginning-of-line) (point)))
3004 (beg-last-statement (save-excursion (idlwave-previous-statement)
3006 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
3007 (if (eq (line-beginning-position) end-reg
)
3008 (goto-char beg-last-statement
)
3010 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
3011 idlwave-continuation-indent
))
3012 fancy-nonparen-indent fancy-paren-indent
)
3014 ;; Align then with its matching if, etc.
3015 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
3016 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
3017 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
3018 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3020 ("\\<case\\>" .
"[ \t]*of")))
3026 (while (setq match
(car matchers
))
3027 (if (looking-at (cdr match
))
3028 (throw 'exit
(car match
)))
3029 (setq matchers
(cdr matchers
)))))
3030 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
3031 (if (looking-at "end") ;; that one's special
3032 (- (idlwave-current-indent)
3033 (+ idlwave-block-indent idlwave-end-offset
))
3034 (idlwave-current-indent)))
3036 ;; Indent in from the previous line for continuing statements
3037 ((let ((matchers '("\\<then\\>"
3044 (if (/= (forward-line -
1) 0)
3046 (while (setq match
(car matchers
))
3047 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
3050 (setq matchers
(cdr matchers
)))))
3051 (+ idlwave-continuation-indent
(idlwave-current-indent)))
3053 ;; Parenthetical indent, either traditional or Kernighan style
3054 ((setq fancy-paren-indent
3055 (let* ((end-reg end-reg
)
3058 (skip-chars-forward " \t")
3059 (looking-at "\\s)")))
3062 (while (setq indent-cons
(idlwave-calculate-paren-indent
3063 beg-reg end-reg close-exp
))
3064 ;; First permitted containing paren
3066 idlwave-indent-to-open-paren
3067 idlwave-indent-parens-nested
3068 (null (cdr indent-cons
))
3069 (< (- (cdr indent-cons
) basic-indent
)
3070 idlwave-max-extra-continuation-indent
))
3071 (throw 'loop
(cdr indent-cons
)))
3072 (setq end-reg
(car indent-cons
))))))
3075 ;; A continued assignment, or procedure call/definition
3077 (> idlwave-max-extra-continuation-indent
0)
3078 (setq fancy-nonparen-indent
3081 (while (idlwave-look-at "&")) ; skip continued statements
3083 ;; A continued Procedure call or definition
3085 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3086 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3087 (goto-char (match-end 0))
3088 ;; Comment only, or blank line with "$"? Basic indent.
3089 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3093 ;; Continued assignment (with =):
3095 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3096 (goto-char (match-end 0))
3097 (if (null (idlwave-what-function beg-reg
))
3098 (throw 'assign t
))))
3101 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3103 (goto-char beg-last-statement
)
3104 (eq (caar (idlwave-statement-type)) 'for
)))
3105 (current-column))))))
3106 (< (- fancy-nonparen-indent basic-indent
)
3107 idlwave-max-extra-continuation-indent
))
3108 (if fancy-paren-indent
;calculated but disallowed paren indent
3109 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3110 fancy-nonparen-indent
))
3112 ;; Basic indent, by default
3113 (t basic-indent
)))))
3117 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3118 "Move to next match of the regular expression KEY-RE.
3119 Matches inside comments or string constants will be ignored.
3120 If DIR is negative, the search will be backwards.
3121 At a successful match, the mark is pushed unless NOMARK is non-nil.
3122 Searches are limited to LIMIT.
3123 Searches are case-insensitive and use a special syntax table which
3124 treats `$' and `_' as word characters.
3125 Return value is the beginning of the match or (in case of failure) nil."
3126 (setq dir
(or dir
0))
3127 (let ((case-fold-search t
)
3128 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3130 (idlwave-with-special-syntax
3133 (while (funcall search-func key-re limit t
)
3134 (if (not (idlwave-quoted))
3135 (throw 'exit
(setq found
(match-beginning 0)))
3136 (if (or (and (> dir
0) (eobp))
3137 (and (< dir
0) (bobp)))
3138 (throw 'exit nil
)))))))
3141 (if (not nomark
) (push-mark))
3146 (defun idlwave-block-jump-out (&optional dir nomark
)
3147 "When optional argument DIR is non-negative, move forward to end of
3148 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3149 regular expressions. When DIR is negative, move backwards to block beginning.
3150 Recursively calls itself to skip over nested blocks. DIR defaults to
3151 forward. Calls `push-mark' unless the optional argument NOMARK is
3152 non-nil. Movement is limited by the start of program units because of
3153 possibility of unbalanced blocks."
3155 (or dir
(setq dir
0))
3156 (let* ((here (point))
3157 (case-fold-search t
)
3158 (limit (if (>= dir
0) (point-max) (point-min)))
3159 (block-limit (if (>= dir
0)
3160 idlwave-begin-block-reg
3161 idlwave-end-block-reg
))
3163 (block-reg (concat idlwave-begin-block-reg
"\\|"
3164 idlwave-end-block-reg
))
3165 (unit-limit (or (save-excursion
3168 idlwave-begin-unit-reg dir t limit
)
3171 idlwave-end-unit-reg dir t limit
)))
3173 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3174 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3175 (while (and found
(looking-at block-limit
))
3176 (if (>= dir
0) (forward-word 1))
3177 (idlwave-block-jump-out dir t
)
3178 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3179 (if (not nomark
) (push-mark here
))
3180 (if (not found
) (goto-char unit-limit
)
3181 (if (>= dir
0) (forward-word 1)))))
3183 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3184 "The minimum indent in the current statement."
3185 (idlwave-beginning-of-statement)
3186 (if (not (idlwave-is-continuation-line))
3187 (idlwave-current-indent)
3188 (let ((min (idlwave-current-indent)) comm-or-empty
)
3189 (while (and (= (forward-line 1) 0)
3190 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3191 (idlwave-is-continuation-line))
3192 (or (null end-reg
) (< (point) end-reg
)))
3193 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3194 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3196 (min min
(idlwave-current-indent))))))
3198 (defun idlwave-current-statement-indent (&optional last-line
)
3199 "Return indentation of the current statement.
3200 If in a statement, moves to beginning of statement before finding indent."
3202 (idlwave-end-of-statement)
3203 (idlwave-beginning-of-statement))
3204 (idlwave-current-indent))
3206 (defun idlwave-current-indent ()
3207 "Return the column of the indentation of the current line.
3208 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3211 (skip-chars-forward " \t")
3212 ;; if we are at the end of blank line return 0
3214 ((current-column)))))
3216 (defun idlwave-is-continuation-line ()
3217 "Tests if current line is continuation line.
3218 Blank or comment-only lines following regular continuation lines (with
3219 `$') count as continuations too."
3223 (idlwave-look-at "\\<\\$")
3225 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3226 (eq (forward-line -
1) 0))
3227 (if (setq p
(idlwave-look-at "\\<\\$")) (throw 'loop p
))))))))
3229 (defun idlwave-is-comment-line ()
3230 "Tests if the current line is a comment line."
3232 (beginning-of-line 1)
3233 (looking-at "[ \t]*;")))
3235 (defun idlwave-is-comment-or-empty-line ()
3236 "Tests if the current line is a comment line."
3238 (beginning-of-line 1)
3239 (looking-at "[ \t]*[;\n]")))
3241 (defun idlwave-look-at (regexp &optional cont beg
)
3242 "Searches current line from current point for REGEXP.
3243 If optional argument CONT is non-nil, searches to the end of
3244 the current statement.
3245 If optional arg BEG is non-nil, search starts from the beginning of the
3247 Ignores matches that end in a comment or inside a string expression.
3248 Returns point if successful, nil otherwise.
3249 This function produces unexpected results if REGEXP contains quotes or
3250 a comment delimiter. The search is case insensitive.
3251 If successful leaves point after the match, otherwise, does not move point."
3252 (let ((here (point))
3253 (case-fold-search t
)
3254 (eos (save-excursion
3255 (if cont
(idlwave-end-of-statement) (end-of-line))
3258 (idlwave-with-special-syntax
3259 (if beg
(idlwave-beginning-of-statement))
3260 (while (and (setq found
(re-search-forward regexp eos t
))
3262 (if (not found
) (goto-char here
))
3265 (defun idlwave-fill-paragraph (&optional nohang
)
3266 "Fills paragraphs in comments.
3267 A paragraph is made up of all contiguous lines having the same comment
3268 leader (the leading whitespace before the comment delimiter and the
3269 comment delimiter). In addition, paragraphs are separated by blank
3270 line comments. The indentation is given by the hanging indent of the
3271 first line, otherwise by the minimum indentation of the lines after
3272 the first line. The indentation of the first line does not change.
3273 Does not effect code lines. Does not fill comments on the same line
3274 with code. The hanging indent is given by the end of the first match
3275 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3276 optional argument NOHANG is non-nil then the hanging indent is
3279 ;; check if this is a line comment
3282 (skip-chars-forward " \t")
3283 (looking-at comment-start
))
3286 pre here diff fill-prefix-reg bcl first-indent
3288 ;; Change tabs to spaces in the surrounding paragraph.
3289 ;; The surrounding paragraph will be the largest containing block of
3290 ;; contiguous line comments. Thus, we may be changing tabs in
3291 ;; a much larger area than is needed, but this is the easiest
3292 ;; brute force way to do it.
3294 ;; This has the undesirable side effect of replacing the tabs
3295 ;; permanently without the user's request or knowledge.
3297 (backward-paragraph)
3298 (setq start
(point)))
3302 (untabify start end
)
3308 (concat "^[ \t]*" comment-start
"+")
3309 (save-excursion (end-of-line) (point))
3311 ;; Get the comment leader on the line and its length
3312 (setq pre
(current-column))
3313 ;; the comment leader is the indentation plus exactly the
3314 ;; number of consecutive ";".
3315 (setq fill-prefix-reg
3319 (buffer-substring (save-excursion
3320 (beginning-of-line) (point))
3324 ;; Mark the beginning and end of the paragraph
3326 (while (and (looking-at fill-prefix-reg
)
3327 (not (looking-at paragraph-separate
))
3330 ;; Move to first line of paragraph
3331 (if (/= (point) bcl
)
3333 (setq start
(point))
3335 (while (and (looking-at fill-prefix-reg
)
3336 (not (looking-at paragraph-separate
))
3340 (if (or (not (looking-at fill-prefix-reg
))
3341 (looking-at paragraph-separate
))
3344 ;; if at end of buffer add a newline (need this because
3345 ;; fill-region needs END to be at the beginning of line after
3346 ;; the paragraph or it will add a line).
3348 (progn (insert ?
\n) (backward-char 1)))
3349 ;; Set END to the beginning of line after the paragraph
3350 ;; END is calculated as distance from end of buffer
3351 (setq end
(- (point-max) (point) 1))
3353 ;; Calculate the indentation for the paragraph.
3355 ;; In the following while statements, after one iteration
3356 ;; point will be at the beginning of a line in which case
3357 ;; the while will not be executed for the
3358 ;; the first paragraph line and thus will not affect the
3361 ;; First check to see if indentation is based on hanging indent.
3362 (if (and (not nohang
) idlwave-hanging-indent
3366 (idlwave-calc-hanging-indent))))
3367 ;; Adjust lines of paragraph by inserting spaces so that
3368 ;; each line's indent is at least as great as the hanging
3369 ;; indent. This is needed for fill-paragraph to work with
3374 (while (> (point) start
)
3375 (re-search-forward comment-start-skip
3376 (save-excursion (end-of-line) (point))
3378 (if (> (setq diff
(- indent
(current-column))) 0)
3380 (if (>= here
(point))
3381 ;; adjust the original location for the
3383 (setq here
(+ here diff
)))
3384 (insert (make-string diff ?\
))))
3388 ;; No hang. Instead find minimum indentation of paragraph
3389 ;; after first line.
3390 ;; For the following while statement, since START is at the
3391 ;; beginning of line and END is at the end of line
3392 ;; point is greater than START at least once (which would
3393 ;; be the case for a single line paragraph).
3394 (while (> (point) start
)
3401 (save-excursion (end-of-line) (point))
3406 (setq fill-prefix
(concat fill-prefix
3407 (make-string (- indent pre
)
3409 ;; first-line indent
3415 (save-excursion (end-of-line) (point))
3420 ;; try to keep point at its original place
3423 ;; In place of the more modern fill-region-as-paragraph, a hack
3424 ;; to keep whitespace untouched on the first line within the
3425 ;; indent length and to preserve any indent on the first line
3429 (buffer-substring start
(+ start first-indent -
1)))
3430 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3431 (fill-region-as-paragraph
3434 (current-justification)
3436 (delete-region start
(+ start first-indent -
1))
3439 ;; When we want the point at the beginning of the comment
3440 ;; body fill-region will put it at the beginning of the line.
3441 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3442 (setq fill-prefix nil
))))
3444 (defun idlwave-calc-hanging-indent ()
3445 "Calculate the position of the hanging indent for the comment
3446 paragraph. The hanging indent position is given by the first match
3447 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3448 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3450 If not found returns nil."
3451 (if idlwave-use-last-hang-indent
3454 (if (re-search-backward
3455 idlwave-hang-indent-regexp
3456 (save-excursion (beginning-of-line) (point))
3458 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3461 (if (re-search-forward
3462 idlwave-hang-indent-regexp
3463 (save-excursion (end-of-line) (point))
3465 (current-column)))))
3467 (defun idlwave-auto-fill ()
3468 "Called to break lines in auto fill mode.
3469 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3470 non-nil. Places a continuation character at the end of the line if
3471 not in a comment. Splits strings with IDL concatenation operator `+'
3472 if `idlwave-auto-fill-split-string' is non-nil."
3473 (if (<= (current-column) fill-column
)
3474 nil
; do not to fill
3475 (if (or (not idlwave-fill-comment-line-only
)
3477 ;; Check for comment line
3479 (looking-at idlwave-comment-line-start-skip
)))
3481 (idlwave-indent-line)
3482 ;; Prevent actions do-auto-fill which calls indent-line-function.
3483 (let (idlwave-do-actions
3484 (paragraph-separate ".")
3485 (fill-nobreak-predicate
3486 (if (and (idlwave-in-quote)
3487 idlwave-auto-fill-split-string
)
3488 (lambda () ;; We'll need 5 spaces for " ' + $"
3489 (<= (- fill-column
(current-column)) 5)
3494 ;; Indent the split line
3495 (idlwave-indent-line))
3498 (looking-at idlwave-comment-line-start-skip
))
3499 ;; A continued line comment
3500 ;; We treat continued line comments as part of a comment
3501 ;; paragraph. So we check for a hanging indent.
3502 (if idlwave-hanging-indent
3503 (let ((here (- (point-max) (point)))
3507 (idlwave-calc-hanging-indent))))
3510 ;; Remove whitespace between comment delimiter and
3511 ;; text, insert spaces for appropriate indentation.
3515 (save-excursion (end-of-line) (point)) t
)
3516 (delete-horizontal-space)
3517 (idlwave-indent-to indent
)
3518 (goto-char (- (point-max) here
)))
3520 ;; Split code or comment?
3523 (idlwave-in-comment))
3524 ;; Splitting a non-full-line comment.
3525 ;; Insert the comment delimiter from split line
3529 (skip-chars-forward " \t")
3530 ;; Insert blank to keep off beginning of line
3534 (buffer-substring (idlwave-goto-comment)
3536 (skip-chars-forward "; ")
3538 (idlwave-indent-line))
3539 ;; Split code line - add continuation character
3542 ;; Check to see if we split a string
3543 (if (and (setq beg
(idlwave-in-quote))
3544 idlwave-auto-fill-split-string
)
3545 ;; Split the string and concatenate.
3546 ;; The first extra space is for the space
3547 ;; the line was split. That space was removed.
3548 (insert " " (char-after beg
) " +"))
3551 (if idlwave-auto-fill-split-string
3552 ;; Make the second part of continued string
3555 (skip-chars-forward " \t")
3556 (insert (char-after beg
)))
3559 (message "Warning: continuation inside a string.")))
3560 ;; Although do-auto-fill (via indent-new-comment-line) calls
3561 ;; idlwave-indent-line for the new line, re-indent again
3562 ;; because of the addition of the continuation character.
3563 (idlwave-indent-line))
3566 (defun idlwave-auto-fill-mode (arg)
3567 "Toggle auto-fill mode for IDL mode.
3568 With arg, turn auto-fill mode on if arg is positive.
3569 In auto-fill mode, inserting a space at a column beyond `fill-column'
3570 automatically breaks the line at a previous space."
3572 (prog1 (set idlwave-fill-function
3574 (not (symbol-value idlwave-fill-function
))
3575 (> (prefix-numeric-value arg
) 0))
3579 (set-buffer-modified-p (buffer-modified-p))))
3581 ;(defun idlwave-fill-routine-call ()
3582 ; "Fill a routine definition or statement, indenting appropriately."
3583 ; (let ((where (idlwave-where)))))
3586 (defun idlwave-doc-header (&optional nomark
)
3587 "Insert a documentation header at the beginning of the unit.
3588 Inserts the value of the variable idlwave-file-header. Sets mark before
3589 moving to do insertion unless the optional prefix argument NOMARK
3592 (or nomark
(push-mark))
3593 ;; make sure we catch the current line if it begins the unit
3594 (if idlwave-header-to-beginning-of-file
3595 (goto-char (point-min))
3597 (idlwave-beginning-of-subprogram)
3599 ;; skip function or procedure line
3600 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3602 (idlwave-end-of-statement)
3603 (if (> (forward-line 1) 0) (insert "\n")))))
3604 (let ((pos (point)))
3605 (if idlwave-file-header
3606 (cond ((car idlwave-file-header
)
3607 (insert-file-contents (car idlwave-file-header
)))
3608 ((stringp (car (cdr idlwave-file-header
)))
3609 (insert (car (cdr idlwave-file-header
))))))
3612 (defun idlwave-default-insert-timestamp ()
3613 "Default timestamp insertion function"
3614 (insert (current-time-string))
3615 (insert ", " (user-full-name))
3616 (if (boundp 'user-mail-address
)
3617 (insert " <" user-mail-address
">")
3618 (insert " <" (user-login-name) "@" (system-name) ">"))
3619 ;; Remove extra spaces from line
3620 (idlwave-fill-paragraph)
3621 ;; Insert a blank line comment to separate from the date entry -
3622 ;; will keep the entry from flowing onto date line if re-filled.
3623 (insert "\n;\n;\t\t"))
3625 (defun idlwave-doc-modification ()
3626 "Insert a brief modification log at the beginning of the current program.
3627 Looks for an occurrence of the value of user variable
3628 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3629 and places the point for the user to add a log. Before moving, saves
3630 location on mark ring so that the user can return to previous point."
3634 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3636 (goto-char (point-min))
3637 (re-search-forward idlwave-doclib-start nil t
)))
3638 (setq beg
(match-beginning 0))
3639 (re-search-forward idlwave-doclib-end nil t
)
3640 (setq end
(match-end 0)))
3643 (if (re-search-forward
3644 (concat idlwave-doc-modifications-keyword
":")
3649 (insert "\n" comment-start
"\n")
3650 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3652 (run-hooks 'idlwave-timestamp-hook
))
3653 (error "No valid DOCLIB header"))))
3657 ;;; Interface to expand-region-abbrevs which did not work when the
3658 ;;; abbrev hook associated with an abbrev moves point backwards
3659 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3660 ;;; The original would enter an infinite loop in attempting to expand
3661 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3662 ;;; because the point would keep going back to the beginning of the
3663 ;;; abbrev instead of to the end of the abbrev). We now keep the
3664 ;;; abbrev hook from moving backwards.
3666 (defun idlwave-expand-region-abbrevs (start end
)
3667 "Expand each abbrev occurrence in the region.
3668 Calling from a program, arguments are START END."
3671 (goto-char (min start end
))
3672 (let ((idlwave-show-block nil
) ;Do not blink
3673 (idlwave-abbrev-move nil
)) ;Do not move
3674 (expand-region-abbrevs start end
'noquery
))))
3676 (defun idlwave-quoted ()
3677 "Returns t if point is in a comment or quoted string.
3679 (or (idlwave-in-comment) (idlwave-in-quote)))
3681 (defun idlwave-in-quote ()
3682 "Returns location of the opening quote
3683 if point is in a IDL string constant, nil otherwise.
3684 Ignores comment delimiters on the current line.
3685 Properly handles nested quotation marks and octal
3686 constants - a double quote followed by an octal digit."
3687 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3688 ;;; double quote followed by an octal digit to be an octal constant
3689 ;;; rather than a string. Therefore, there is no terminating double
3692 ;; Because single and double quotes can quote each other we must
3693 ;; search for the string start from the beginning of line.
3694 (let* ((start (point))
3695 (eol (progn (end-of-line) (point)))
3696 (bq (progn (beginning-of-line) (point)))
3701 (while (< endq start
)
3702 ;; Find string start
3703 ;; Don't find an octal constant beginning with a double quote
3704 (if (re-search-forward "[\"']" eol
'lim
)
3705 ;; Find the string end.
3706 ;; In IDL, two consecutive delimiters after the start of a
3708 ;; escape for the delimiter in the string.
3709 ;; Two consecutive delimiters alone (i.e., not after the
3710 ;; start of a string) is the null string.
3712 ;; Move to position after quote
3713 (goto-char (1+ (match-beginning 0)))
3714 (setq bq
(1- (point)))
3715 ;; Get the string delimiter
3716 (setq delim
(char-to-string (preceding-char)))
3717 ;; Check for null string
3718 (if (looking-at delim
)
3719 (progn (setq endq
(point)) (forward-char 1))
3720 ;; Look for next unpaired delimiter
3721 (setq found
(search-forward delim eol
'lim
))
3722 (while (looking-at delim
)
3724 (setq found
(search-forward delim eol
'lim
)))
3726 (setq endq
(- (point) 1))
3727 (setq endq
(point)))
3729 (progn (setq bq
(point)) (setq endq
(point)))))
3730 (store-match-data data
)
3731 ;; return string beginning position or nil
3732 (if (> start bq
) bq
))))
3734 (defun idlwave-is-pointer-dereference (&optional limit
)
3735 "Determines if the character after point is a pointer dereference *."
3736 (let ((pos (point)))
3738 (eq (char-after) ?\
*)
3739 (not (idlwave-in-quote))
3742 (re-search-backward (concat "\\(" idlwave-idl-keywords
3743 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3746 ;; Statement templates
3748 ;; Replace these with a general template function, something like
3749 ;; expand.el (I think there was also something with a name similar to
3752 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3753 "Build a template with optional prompt expression.
3755 Opens a line if point is not followed by a newline modulo intervening
3756 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3757 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3758 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3759 PROMPT is a string then it is displayed as a message in the
3760 minibuffer. The PROMPT serves as a reminder to the user of an
3761 expression to enter.
3763 The lines containing S1 and S2 are reindented using `indent-region'
3764 unless the optional second argument NOINDENT is non-nil."
3765 (if (eq major-mode
'idlwave-shell-mode
)
3766 ;; This is a gross hack to avoit template abbrev expansion
3767 ;; in the shell. FIXME: This is a dirty hack.
3768 (if (and (eq this-command
'self-insert-command
)
3769 (equal last-abbrev-location
(point)))
3770 (insert last-abbrev-text
)
3771 (error "No templates in idlwave-shell"))
3772 (cond ((eq idlwave-abbrev-change-case
'down
)
3773 (setq s1
(downcase s1
) s2
(downcase s2
)))
3774 (idlwave-abbrev-change-case
3775 (setq s1
(upcase s1
) s2
(upcase s2
))))
3776 (let ((beg (save-excursion (beginning-of-line) (point)))
3778 (if (not (looking-at "\\s-*\n"))
3785 (indent-region beg end nil
))
3786 (if (stringp prompt
)
3787 (message "%s" prompt
)))))
3789 (defun idlwave-rw-case (string)
3790 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3791 (if idlwave-reserved-word-upcase
3795 (defun idlwave-elif ()
3796 "Build skeleton IDL if-else block."
3799 (idlwave-rw-case "if")
3800 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3801 "Condition expression"))
3803 (defun idlwave-case ()
3804 "Build skeleton IDL case statement."
3807 (idlwave-rw-case "case")
3808 (idlwave-rw-case " of\n\nendcase")
3809 "Selector expression"))
3811 (defun idlwave-switch ()
3812 "Build skeleton IDL switch statement."
3815 (idlwave-rw-case "switch")
3816 (idlwave-rw-case " of\n\nendswitch")
3817 "Selector expression"))
3819 (defun idlwave-for ()
3820 "Build skeleton for loop statment."
3823 (idlwave-rw-case "for")
3824 (idlwave-rw-case " do begin\n\nendfor")
3827 (defun idlwave-if ()
3828 "Build skeleton for loop statment."
3831 (idlwave-rw-case "if")
3832 (idlwave-rw-case " then begin\n\nendif")
3833 "Scalar logical expression"))
3835 (defun idlwave-procedure ()
3838 (idlwave-rw-case "pro")
3839 (idlwave-rw-case "\n\nreturn\nend")
3842 (defun idlwave-function ()
3845 (idlwave-rw-case "function")
3846 (idlwave-rw-case "\n\nreturn\nend")
3849 (defun idlwave-repeat ()
3852 (idlwave-rw-case "repeat begin\n\nendrep until")
3853 (idlwave-rw-case "")
3856 (defun idlwave-while ()
3859 (idlwave-rw-case "while")
3860 (idlwave-rw-case " do begin\n\nendwhile")
3863 (defun idlwave-split-string (string &optional pattern
)
3864 "Return a list of substrings of STRING which are separated by PATTERN.
3865 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3867 (setq pattern
"[ \f\t\n\r\v]+"))
3868 (let (parts (start 0))
3869 (while (string-match pattern string start
)
3870 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3871 start
(match-end 0)))
3872 (nreverse (cons (substring string start
) parts
))))
3874 (defun idlwave-replace-string (string replace_string replace_with
)
3876 (last (length string
))
3879 (while (setq end
(string-match replace_string string start
))
3881 (concat ret_string
(substring string start end
) replace_with
))
3882 (setq start
(match-end 0)))
3883 (setq ret_string
(concat ret_string
(substring string start last
)))))
3885 (defun idlwave-get-buffer-visiting (file)
3886 ;; Return the buffer currently visiting FILE
3888 ((boundp 'find-file-compare-truenames
) ; XEmacs
3889 (let ((find-file-compare-truenames t
))
3890 (get-file-buffer file
)))
3891 ((fboundp 'find-buffer-visiting
) ; Emacs
3892 (find-buffer-visiting file
))
3893 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3895 (defvar idlwave-outlawed-buffers nil
3896 "List of buffer pulled up by idlwave for special reasons.
3897 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3899 (defun idlwave-find-file-noselect (file &optional why
)
3900 ;; Return a buffer visiting file.
3901 (or (idlwave-get-buffer-visiting file
)
3902 (let ((buf (find-file-noselect file
)))
3903 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3906 (defun idlwave-kill-autoloaded-buffers ()
3907 "Kill buffers created automatically by IDLWAVE.
3908 Function prompts for a letter to identify the buffers to kill.
3909 Possible letters are:
3911 f Buffers created by the command \\[idlwave-find-module] or mouse
3912 clicks in the routine info window.
3913 s Buffers created by the IDLWAVE Shell to display where execution
3914 stopped or an error was found.
3915 a Both of the above.
3917 Buffer containing unsaved changes require confirmation before they are killed."
3919 (if (null idlwave-outlawed-buffers
)
3920 (error "No IDLWAVE-created buffers available")
3921 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3922 (idlwave-count-outlawed-buffers 'find
)
3923 (idlwave-count-outlawed-buffers 'shell
)))
3924 (let ((c (read-char)))
3926 ((member c
'(?f ?\C-f
))
3927 (idlwave-do-kill-autoloaded-buffers 'find
))
3928 ((member c
'(?s ?\C-s
))
3929 (idlwave-do-kill-autoloaded-buffers 'shell
))
3930 ((member c
'(?a ?\C-a
))
3931 (idlwave-do-kill-autoloaded-buffers t
))
3932 (t (error "Abort"))))))
3934 (defun idlwave-count-outlawed-buffers (tag)
3935 "How many outlawed buffers have tag TAG?"
3938 (lambda (x) (eq (cdr x
) tag
))
3939 idlwave-outlawed-buffers
))))
3941 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3942 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3943 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3946 (while (setq entry
(pop list
))
3947 (if (buffer-live-p (car entry
))
3948 (and (or (memq t reasons
)
3949 (memq (cdr entry
) reasons
))
3950 (kill-buffer (car entry
))
3952 (setq idlwave-outlawed-buffers
3953 (delq entry idlwave-outlawed-buffers
)))
3954 (setq idlwave-outlawed-buffers
3955 (delq entry idlwave-outlawed-buffers
))))
3956 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3958 (defun idlwave-revoke-license-to-kill ()
3959 "Remove BUFFER from the buffers which may be killed.
3960 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3961 Intended for `after-save-hook'."
3962 (let* ((buf (current-buffer))
3963 (entry (assq buf idlwave-outlawed-buffers
)))
3966 (setq idlwave-outlawed-buffers
3967 (delq entry idlwave-outlawed-buffers
)))
3968 ;; Remove this function from the hook.
3969 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3971 (defvar idlwave-path-alist
)
3972 (defun idlwave-locate-lib-file (file)
3973 ;; Find FILE on the scanned lib path and return a buffer visiting it
3974 (let* ((dirs idlwave-path-alist
)
3977 (while (setq dir
(car (pop dirs
)))
3979 (setq efile
(expand-file-name file dir
)))
3980 (throw 'exit efile
))))))
3982 (defun idlwave-expand-lib-file-name (file)
3983 ;; Find FILE on the scanned lib path and return a buffer visiting it
3984 ;; This is for, e.g., finding source with no user catalog
3987 ((file-name-absolute-p file
) file
)
3988 (t (idlwave-locate-lib-file file
))))
3990 (defun idlwave-make-tags ()
3991 "Creates the IDL tags file IDLTAGS in the current directory from
3992 the list of directories specified in the minibuffer. Directories may be
3993 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3994 specified top directories are searched if the directory name is prefixed
3995 by @. Specify @ directories with care, it may take a long, long time if
3998 (let (directory directories cmd append status numdirs dir getsubdirs
3999 buffer save_buffer files numfiles item errbuf
)
4002 ;; Read list of directories
4003 (setq directory
(read-string "Tag Directories: " "."))
4004 (setq directories
(idlwave-split-string directory
"[ \t]+"))
4006 ;; Set etags command, vars
4007 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
4008 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4009 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4013 ;; For each directory
4015 (setq dir
(nth numdirs directories
))
4018 ;; Find the subdirectories
4019 (if (string-match "^[@]\\(.+\\)$" dir
)
4020 (setq getsubdirs t
) (setq getsubdirs nil
))
4021 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
4022 (setq dir
(expand-file-name dir
))
4023 (if (file-directory-p dir
)
4025 (if (and getsubdirs
)
4027 (setq buffer
(get-buffer-create "*idltags*"))
4028 (call-process "sh" nil buffer nil
"-c"
4029 (concat "find " dir
" -type d -print"))
4030 (setq save_buffer
(current-buffer))
4032 (setq files
(idlwave-split-string
4033 (idlwave-replace-string
4034 (buffer-substring 1 (point-max))
4037 (set-buffer save_buffer
)
4038 (kill-buffer buffer
))
4039 (setq files
(list (concat dir
"/*.pro"))))
4041 ;; For each subdirectory
4043 (setq item
(nth numfiles files
))
4047 (if (not (string-match "^[ \\t]*$" item
))
4049 (message "%s" (concat "Tagging " item
"..."))
4050 (setq errbuf
(get-buffer-create "*idltags-error*"))
4051 (setq status
(+ status
4052 (if (eq 0 (call-process
4053 "sh" nil errbuf nil
"-c"
4054 (concat cmd append item
)))
4058 ;; Append additional tags
4059 (setq append
" --append ")
4060 (setq numfiles
(1+ numfiles
))
4061 (setq item
(nth numfiles files
)))
4063 (setq numfiles
(1+ numfiles
))
4064 (setq item
(nth numfiles files
))
4067 (setq numdirs
(1+ numdirs
))
4068 (setq dir
(nth numdirs directories
)))
4070 (setq numdirs
(1+ numdirs
))
4071 (setq dir
(nth numdirs directories
)))))
4073 (setq errbuf
(get-buffer-create "*idltags-error*"))
4075 (kill-buffer errbuf
))
4079 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4080 "Comment the lines in the region if the first non-blank line is
4081 commented, and conversely, uncomment region. If optional prefix arg
4082 N is non-nil, then for N positive, add N comment delimiters or for N
4083 negative, remove N comment delimiters.
4084 Uses `comment-region' which does not place comment delimiters on
4086 (interactive "r\nP")
4088 (comment-region beg end
(prefix-numeric-value n
))
4093 (skip-chars-forward " \t\n")
4094 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4095 (if (fboundp 'uncomment-region
)
4096 (uncomment-region beg end
)
4097 (comment-region beg end
4098 (- (length (buffer-substring
4101 (comment-region beg end
)))))
4104 ;; ----------------------------------------------------------------------------
4105 ;; ----------------------------------------------------------------------------
4106 ;; ----------------------------------------------------------------------------
4107 ;; ----------------------------------------------------------------------------
4109 ;; Completion and Routine Info
4112 ;; String "intern" functions
4114 ;; For the completion and routine info function, we want to normalize
4115 ;; the case of procedure names etc. We do this by "interning" these
4116 ;; string is a hand-crafted way. Hashes are used to map the downcase
4117 ;; version of the strings to the cased versions. Most *-sint-*
4118 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4119 ;; system hash. The former is re-scanned, and the latter takes case
4122 ;; Since these cased versions are really lisp objects, we can use `eq'
4123 ;; to search, which is a large performance boost. All new strings
4124 ;; need to be "sinterned". We do this as early as possible after
4125 ;; getting these strings from completion or buffer substrings. So
4126 ;; most of the code can simply assume to deal with "sinterned"
4127 ;; strings. The only exception is that the functions which scan whole
4128 ;; buffers for routine information do not intern the grabbed strings.
4129 ;; This is only done afterwards. Therefore in these functions it is
4130 ;; *not* safe to assume the strings can be compared with `eq' and be
4131 ;; fed into the routine assq functions.
4133 ;; Here we define the hashing functions.
4135 ;; The variables which hold the hashes.
4136 (defvar idlwave-sint-routines
'(nil))
4137 (defvar idlwave-sint-keywords
'(nil))
4138 (defvar idlwave-sint-methods
'(nil))
4139 (defvar idlwave-sint-classes
'(nil))
4140 (defvar idlwave-sint-dirs
'(nil))
4141 (defvar idlwave-sint-libnames
'(nil))
4143 (defun idlwave-reset-sintern (&optional what
)
4144 "Reset all sintern hashes."
4145 ;; Make sure the hash functions are accessible.
4146 (if (or (not (fboundp 'gethash
))
4147 (not (fboundp 'puthash
)))
4150 (or (fboundp 'puthash
)
4151 (defalias 'puthash
'cl-puthash
))))
4152 (let ((entries '((idlwave-sint-routines 1000 10)
4153 (idlwave-sint-keywords 1000 10)
4154 (idlwave-sint-methods 100 10)
4155 (idlwave-sint-classes 10 10))))
4157 ;; Make sure these are lists
4158 (loop for entry in entries
4159 for var
= (car entry
)
4160 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4162 ;; Reset the system & library hash
4163 (when (or (eq what t
) (eq what
'syslib
)
4164 (null (cdr idlwave-sint-routines
)))
4165 (loop for entry in entries
4166 for var
= (car entry
) for size
= (nth 1 entry
)
4167 do
(setcdr (symbol-value var
)
4168 (make-hash-table ':size size
':test
'equal
)))
4169 (setq idlwave-sint-dirs nil
4170 idlwave-sint-libnames nil
))
4172 ;; Reset the buffer & shell hash
4173 (when (or (eq what t
) (eq what
'bufsh
)
4174 (null (car idlwave-sint-routines
)))
4175 (loop for entry in entries
4176 for var
= (car entry
) for size
= (nth 1 entry
)
4177 do
(setcar (symbol-value var
)
4178 (make-hash-table ':size size
':test
'equal
))))))
4180 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4182 (idlwave-sintern-method name set
)
4183 (idlwave-sintern-routine name set
)))
4185 (defun idlwave-sintern (stype &rest args
)
4186 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4188 ;;(defmacro idlwave-sintern (type var)
4189 ;; `(cond ((not (stringp name)) name)
4190 ;; ((gethash (downcase name) (cdr ,var)))
4191 ;; ((gethash (downcase name) (car ,var)))
4192 ;; (set (idlwave-sintern-set name ,type ,var set))
4195 (defun idlwave-sintern-routine (name &optional set
)
4196 (cond ((not (stringp name
)) name
)
4197 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4198 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4199 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4201 (defun idlwave-sintern-keyword (name &optional set
)
4202 (cond ((not (stringp name
)) name
)
4203 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4204 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4205 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4207 (defun idlwave-sintern-method (name &optional set
)
4208 (cond ((not (stringp name
)) name
)
4209 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4210 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4211 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4213 (defun idlwave-sintern-class (name &optional set
)
4214 (cond ((not (stringp name
)) name
)
4215 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4216 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4217 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4220 (defun idlwave-sintern-dir (dir &optional set
)
4221 (car (or (member dir idlwave-sint-dirs
)
4222 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4223 (defun idlwave-sintern-libname (name &optional set
)
4224 (car (or (member name idlwave-sint-libnames
)
4225 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4227 (defun idlwave-sintern-set (name type tables set
)
4228 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4230 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4231 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4232 (puthash (downcase name
) iname table
)
4235 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4236 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4238 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4242 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4243 "Sintern all strings in the rinfo LIST. With optional parameter
4244 SET: also set new patterns. Probably this will always have to be t.
4245 If DEFAULT-DIR is passed, it is used as the base of the directory"
4246 (let (entry name type class kwds res source call new
)
4248 (setq entry
(car list
)
4253 source
(nth 3 entry
)
4255 kwds
(nthcdr 5 entry
))
4257 ;; The class and name
4260 (if (symbolp class
) (setq class
(symbol-name class
)))
4261 (setq class
(idlwave-sintern-class class set
))
4262 (setq name
(idlwave-sintern-method name set
)))
4263 (setq name
(idlwave-sintern-routine name set
)))
4266 (let ((source-type (car source
))
4267 (source-file (nth 1 source
))
4268 (source-dir (if default-dir
4269 (file-name-as-directory default-dir
)
4271 (source-lib (nth 3 source
)))
4272 (if (stringp source-dir
)
4273 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4274 (if (stringp source-lib
)
4275 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4276 (setq source
(list source-type source-file source-dir source-lib
)))
4279 (setq kwds
(mapcar (lambda (x)
4280 (idlwave-sintern-keyword-list x set
))
4283 ;; Build a canonicalized list
4284 (setq new
(nconc (list name type class source call
) kwds
)
4285 res
(cons new res
)))
4288 ;; Creating new sintern tables
4290 (defun idlwave-new-sintern-type (tag)
4291 "Define a variable and a function to sintern the new type TAG.
4292 This defines the function `idlwave-sintern-TAG' and the variable
4293 `idlwave-sint-TAGs'."
4294 (let* ((name (symbol-name tag
))
4295 (names (concat name
"s"))
4296 (var (intern (concat "idlwave-sint-" names
)))
4297 (func (intern (concat "idlwave-sintern-" name
))))
4298 (set var nil
) ; initial value of the association list
4299 (fset func
; set the function
4300 `(lambda (name &optional set
)
4301 (cond ((not (stringp name
)) name
)
4302 ((cdr (assoc (downcase name
) ,var
)))
4304 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4308 (defun idlwave-reset-sintern-type (tag)
4309 "Reset the sintern variable associated with TAG."
4310 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4312 ;;---------------------------------------------------------------------------
4315 ;; The variables which hold the information
4316 (defvar idlwave-system-routines nil
4317 "Holds the routine-info obtained by scanning buffers.")
4318 (defvar idlwave-buffer-routines nil
4319 "Holds the routine-info obtained by scanning buffers.")
4320 (defvar idlwave-compiled-routines nil
4321 "Holds the routine-info obtained by asking the shell.")
4322 (defvar idlwave-unresolved-routines nil
4323 "Holds the unresolved routine-info obtained by asking the shell.")
4324 (defvar idlwave-user-catalog-routines nil
4325 "Holds the procedure routine-info from the user scan.")
4326 (defvar idlwave-library-catalog-routines nil
4327 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4328 (defvar idlwave-library-catalog-libname nil
4329 "Name of library catalog loaded from .idlwave_catalog files.")
4330 (defvar idlwave-path-alist nil
4331 "Alist with !PATH directories and zero or more flags if the dir has
4332 been scanned in a user catalog ('user) or discovered in a library
4334 (defvar idlwave-true-path-alist nil
4335 "Like `idlwave-path-alist', but with true filenames.")
4336 (defvar idlwave-routines nil
4337 "Holds the combined procedure/function/method routine-info.")
4338 (defvar idlwave-class-alist nil
4339 "Holds the class names known to IDLWAVE.")
4340 (defvar idlwave-class-history nil
4341 "The history of classes selected with the minibuffer.")
4342 (defvar idlwave-force-class-query nil
)
4343 (defvar idlwave-before-completion-wconf nil
4344 "The window configuration just before the completion buffer was displayed.")
4345 (defvar idlwave-last-system-routine-info-cons-cell nil
4346 "The last cons cell in the system routine info.")
4349 ;; The code to get routine info from different sources.
4351 (defvar idlwave-system-routines
)
4352 (defvar idlwave-catalog-process nil
4353 "The background process currently updating the catalog.")
4355 (defun idlwave-routines ()
4356 "Provide a list of IDL routines.
4357 This routine loads the builtin routines on the first call. Later it
4358 only returns the value of the variable."
4359 (if (and idlwave-catalog-process
4360 (processp idlwave-catalog-process
))
4363 ((equal (process-status idlwave-catalog-process
) 'exit
)
4364 (message "updating........")
4365 (setq idlwave-catalog-process nil
)
4366 (idlwave-update-routine-info '(4)))
4367 ((equal (process-status idlwave-catalog-process
) 'run
)
4368 ;; Keep it running...
4371 ;; Something is wrong, get rid of the process
4372 (message "Problem with catalog process") (beep)
4374 (kill-process idlwave-catalog-process
)
4376 (setq idlwave-catalog-process nil
)))))
4377 (or idlwave-routines
4379 (idlwave-update-routine-info)
4380 ;; return the current value
4383 (defvar idlwave-update-rinfo-hook nil
4384 "List of functions which should run after a global rinfo update.
4385 Does not run after automatic updates of buffer or the shell.")
4387 (defun idlwave-rescan-catalog-directories ()
4388 "Rescan the previously selected directories. For batch processing."
4389 (idlwave-update-routine-info '(16)))
4391 (defun idlwave-rescan-asynchronously ()
4392 "Dispatch another Emacs instance to update the idlwave catalog.
4393 After the process finishes normally, the first access to routine info
4394 will re-read the catalog."
4396 (if (processp idlwave-catalog-process
)
4397 (if (eq (process-status idlwave-catalog-process
) 'run
)
4398 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4401 (kill-process idlwave-catalog-process
)
4403 (error "Process killed, no new process started"))
4406 (kill-process idlwave-catalog-process
)
4408 (if (or (not idlwave-user-catalog-file
)
4409 (not (stringp idlwave-user-catalog-file
))
4410 (not (file-regular-p idlwave-user-catalog-file
)))
4411 (error "No catalog has been produced yet"))
4412 (let* ((emacs (concat invocation-directory invocation-name
))
4413 (args (list "-batch"
4414 "-l" (expand-file-name "~/.emacs")
4416 "-f" "idlwave-rescan-catalog-directories"))
4417 (process (apply 'start-process
"idlcat"
4419 (setq idlwave-catalog-process process
)
4420 (set-process-sentinel
4423 (when (string-match "finished" why
)
4424 (setq idlwave-routines nil
4425 idlwave-system-routines nil
4426 idlwave-catalog-process nil
)
4427 (or (idlwave-start-load-rinfo-timer)
4428 (idlwave-update-routine-info '(4))))))
4429 (message "Background job started to update catalog file")))
4432 ;; Format for all routine info user catalog, library catalogs, etc.:
4434 ;; ("ROUTINE" type class
4435 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4436 ;; (buffer pro_file dir) | (compiled pro_file dir)
4437 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4438 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4440 ;; DIR will be supplied dynamically while loading library catalogs,
4441 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4442 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4443 ;; be nil, as can LINK1, etc., if no HTML help is available.
4446 (defvar idlwave-load-rinfo-idle-timer
)
4447 (defvar idlwave-shell-path-query
)
4449 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4450 "Update the internal routine-info lists.
4451 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4452 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4453 about individual routines.
4455 The information can come from 4 sources:
4456 1. IDL programs in the current editing session
4457 2. Compiled modules in an IDL shell running as Emacs subprocess
4458 3. A list which covers the IDL system routines.
4459 4. A list which covers the prescanned library files.
4461 Scans all IDLWAVE-mode buffers of the current editing session (see
4462 `idlwave-scan-all-buffers-for-routine-info').
4463 When an IDL shell is running, this command also queries the IDL program
4464 for currently compiled routines.
4466 With prefix ARG, also reload the system and library lists.
4467 With two prefix ARG's, also rescans the chosen user catalog tree.
4468 With three prefix args, dispatch asynchronous process to do the update.
4470 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4471 lists, but instead wait for the shell query to complete and
4472 asynchronously finish updating routine info. This is set
4473 automatically when called interactively. When you need routine
4474 information updated immediately, leave NO-CONCATENATE nil."
4475 (interactive "P\np")
4476 ;; Stop any idle processing
4477 (if (or (and (fboundp 'itimerp
)
4478 (itimerp idlwave-load-rinfo-idle-timer
))
4479 (and (fboundp 'timerp
)
4480 (timerp idlwave-load-rinfo-idle-timer
)))
4481 (cancel-timer idlwave-load-rinfo-idle-timer
))
4484 ;; Start a background process which updates the catalog.
4485 (idlwave-rescan-asynchronously))
4487 ;; Update the user catalog now, and wait for them.
4488 (idlwave-create-user-catalog-file t
))
4490 (let* ((load (or arg
4491 idlwave-buffer-case-takes-precedence
4492 (null idlwave-routines
)))
4493 ;; The override-idle means, even if the idle timer has done some
4494 ;; preparing work, load and renormalize everything anyway.
4495 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4497 (setq idlwave-buffer-routines nil
4498 idlwave-compiled-routines nil
4499 idlwave-unresolved-routines nil
)
4500 ;; Reset the appropriate hashes
4501 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4502 ;; reset was already done in idle time, so skip this step now once
4503 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4504 (idlwave-reset-sintern (cond (load t
)
4505 ((null idlwave-system-routines
) t
)
4508 (if idlwave-buffer-case-takes-precedence
4509 ;; We can safely scan the buffer stuff first
4511 (idlwave-update-buffer-routine-info)
4512 (and load
(idlwave-load-all-rinfo override-idle
)))
4513 ;; We first do the system info, and then the buffers
4514 (and load
(idlwave-load-all-rinfo override-idle
))
4515 (idlwave-update-buffer-routine-info))
4517 ;; Let's see if there is a shell
4518 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4519 (idlwave-shell-is-running)))
4520 (ask-shell (and shell-is-running
4521 idlwave-query-shell-for-routine-info
)))
4523 ;; Load the library catalogs again, first re-scanning the path
4525 (if shell-is-running
4526 (idlwave-shell-send-command idlwave-shell-path-query
4528 (idlwave-shell-get-path-info)
4529 (idlwave-scan-library-catalogs))
4531 (idlwave-scan-library-catalogs)))
4533 (if (or (not ask-shell
)
4534 (not no-concatenate
))
4535 ;; 1. If we are not going to ask the shell, we need to do the
4536 ;; concatenation now.
4537 ;; 2. When this function is called non-interactively, it
4538 ;; means that someone needs routine info *now*. The
4539 ;; shell update causes the concatenation to be
4540 ;; *delayed*, so not in time for the current command.
4541 ;; Therefore, we do a concatenation now, even though
4542 ;; the shell might do it again.
4543 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4546 ;; Ask the shell about the routines it knows of.
4547 (message "Querying the shell")
4548 (idlwave-shell-update-routine-info nil t
)))))))
4551 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4552 (defvar idlwave-load-rinfo-idle-timer nil
)
4553 (defun idlwave-start-load-rinfo-timer ()
4554 (if (or (and (fboundp 'itimerp
)
4555 (itimerp idlwave-load-rinfo-idle-timer
))
4556 (and (fboundp 'timerp
)
4557 (timerp idlwave-load-rinfo-idle-timer
)))
4558 (cancel-timer idlwave-load-rinfo-idle-timer
))
4559 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4560 (setq idlwave-load-rinfo-idle-timer nil
)
4561 (if (and idlwave-init-rinfo-when-idle-after
4562 (numberp idlwave-init-rinfo-when-idle-after
)
4563 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4564 (not idlwave-routines
))
4567 (setq idlwave-load-rinfo-idle-timer
4568 (run-with-idle-timer
4569 idlwave-init-rinfo-when-idle-after
4570 nil
'idlwave-load-rinfo-next-step
)))
4573 (defvar idlwave-library-routines nil
"Obsolete variable.")
4575 ;;------ XML Help routine info system
4576 (defun idlwave-load-system-routine-info ()
4577 ;; Load the system routine info from the cached routine info file,
4578 ;; which, if necessary, will be re-created from the XML file on
4579 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4580 ;; file distributed with older IDLWAVE versions (<6.0)
4581 (unless (and (load idlwave-xml-system-rinfo-converted-file
4582 'noerror
'nomessage
)
4583 (idlwave-xml-system-routine-info-up-to-date))
4584 ;; See if we can create it from XML source
4586 (idlwave-convert-xml-system-routine-info)
4588 (unless (load idlwave-xml-system-rinfo-converted-file
4589 'noerror
'nomessage
)
4590 (if idlwave-system-routines
4592 "Failed to load converted routine info, using old conversion.")
4594 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4595 (if (not (load "idlw-rinfo" 'noerror
'nomessage
))
4597 "Could not locate any system routine information."))))))))
4599 (defun idlwave-xml-system-routine-info-up-to-date()
4600 (let* ((dir (file-name-as-directory
4601 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4602 (catalog-file (expand-file-name "idl_catalog.xml" dir
)))
4603 (file-newer-than-file-p ;converted file is newer than catalog
4604 idlwave-xml-system-rinfo-converted-file
4607 (defvar idlwave-system-class-info nil
) ; Gathered from idlw-rinfo
4608 (defvar idlwave-system-variables-alist nil
4609 "Alist of system variables and the associated structure tags.
4610 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4611 (defvar idlwave-executive-commands-alist nil
4612 "Alist of system variables and their help files.")
4613 (defvar idlwave-help-special-topic-words nil
)
4616 (defun idlwave-shorten-syntax (syntax name
&optional class
)
4617 ;; From a list of syntax statments, shorten with %s and group with "or"
4618 (let ((case-fold-search t
))
4621 (while (string-match name x
)
4622 (setq x
(replace-match "%s" t t x
)))
4624 (while (string-match class x
)
4625 (setq x
(replace-match "%s" t t x
))))
4630 (defun idlwave-xml-create-class-method-lists (xml-entry)
4631 ;; Create a class list entry from the xml parsed list., returning a
4632 ;; cons of form (class-entry method-entries).
4633 (let* ((nameblock (nth 1 xml-entry
))
4634 (class (cdr (assq 'name nameblock
)))
4635 (link (cdr (assq 'link nameblock
)))
4636 (params (cddr xml-entry
))
4637 (case-fold-search t
)
4639 method methods-entry extra-kwds
4640 props get-props set-props init-props inherits
4643 (setq pelem
(car params
))
4645 (setq ptype
(car pelem
)
4646 props
(car (cdr pelem
)))
4648 ((eq ptype
'SUPERCLASS
)
4649 (let ((pname (cdr (assq 'name props
)))
4650 (plink (cdr (assq 'link props
))))
4651 (unless (and (string= pname
"None")
4652 (string= plink
"None"))
4653 (push pname inherits
))))
4655 ((eq ptype
'PROPERTY
)
4656 (let ((pname (cdr (assq 'name props
)))
4657 (plink (cdr (assq 'link props
)))
4658 (get (string= (cdr (assq 'get props
)) "Yes"))
4659 (set (string= (cdr (assq 'set props
)) "Yes"))
4660 (init (string= (cdr (assq 'init props
)) "Yes")))
4661 (if get
(push (list pname plink
) get-props
))
4662 (if set
(push (list pname plink
) set-props
))
4663 (if init
(push (list pname plink
) init-props
))))
4666 (setq method
(cdr (assq 'name props
)))
4667 (setq extra-kwds
;;Assume all property keywords are gathered already
4669 ((string-match (concat class
"::Init") method
)
4670 (put 'init-props
'matched t
)
4672 ((string-match (concat class
"::GetProperty") method
)
4673 (put 'get-props
'matched t
)
4675 ((string-match (concat class
"::SetProperty") method
)
4676 (put 'set-props
'matched t
)
4680 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds
)
4683 (setq params
(cdr params
)))
4684 ;(unless (get 'init-props 'matched)
4685 ; (message "Failed to match Init in class %s" class))
4686 ;(unless (get 'get-props 'matched)
4687 ; (message "Failed to match GetProperty in class %s" class))
4688 ;(unless (get 'set-props 'matched)
4689 ; (message "Failed to match SetProperty in class %s" class))
4692 (list class
(append '(inherits) inherits
) (list 'link link
))
4693 (list class
(list 'link link
))))
4694 (cons class-entry methods-entry
)))
4696 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws
)
4697 ;; Create correctly structured list elements from ROUTINE or METHOD
4698 ;; XML list structures. Return a list of list elements, with more
4699 ;; than one sub-list possible if a routine can serve as both
4700 ;; procedure and function (e.g. call_method).
4701 (let* ((nameblock (nth 1 xml-entry
))
4702 (name (cdr (assq 'name nameblock
)))
4703 (link (cdr (assq 'link nameblock
)))
4704 (params (cddr xml-entry
))
4705 (syntax-vec (make-vector 3 nil
)) ; procedure, function, exec command
4706 (case-fold-search t
)
4707 syntax kwd klink pref-list kwds pelem ptype entry props result type
)
4708 (if class
;; strip out class name from class method name string
4709 (if (string-match (concat class
"::") name
)
4710 (setq name
(substring name
(match-end 0)))))
4712 (setq pelem
(car params
))
4714 (setq ptype
(car pelem
)
4715 props
(car (cdr pelem
)))
4718 (setq syntax
(cdr (assq 'name props
)))
4719 (if (string-match "->" syntax
)
4720 (setq syntax
(replace-match "->" t nil syntax
)))
4721 (setq type
(cdr (assq 'type props
)))
4723 (aref syntax-vec
(cond
4724 ((string-match "^pro" type
) 0)
4725 ((string-match "^fun" type
) 1)
4726 ((string-match "^exec" type
) 2)))))
4727 ((eq ptype
'KEYWORD
)
4728 (setq kwd
(cdr (assq 'name props
))
4729 klink
(cdr (assq 'link props
)))
4730 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd
)
4733 (if (match-string 1 kwd
) '("X" "Y" "Z") '("X" "Y"))
4734 kwd
(substring kwd
(match-end 0)))
4735 (loop for x in pref-list do
4736 (push (list (concat x kwd
) klink
) kwds
)))
4737 (push (list kwd klink
) kwds
)))
4739 (t))); Do nothing for the others
4740 (setq params
(cdr params
)))
4743 ; (if (and (null (aref syntax-vec 0))
4744 ; (null (aref syntax-vec 1))
4745 ; (null (aref syntax-vec 2)))
4746 ; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4748 ; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4749 ; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4751 ;; Executive commands are treated specially
4752 (if (aref syntax-vec
2)
4753 (cons (substring name
1) link
)
4754 (if extra-kws
(setq kwds
(nconc kwds extra-kws
)))
4755 (setq kwds
(idlwave-rinfo-group-keywords kwds link
))
4756 (loop for idx from
0 to
1 do
4757 (if (aref syntax-vec idx
)
4758 (push (append (list name
(if (eq idx
0) 'pro
'fun
)
4760 (idlwave-shorten-syntax
4761 (aref syntax-vec idx
) name class
))
4766 (defun idlwave-rinfo-group-keywords (kwds master-link
)
4767 ;; Group keywords by link file, as a list with elements
4768 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4769 (let (kwd link anchor linkfiles block master-elt
)
4771 (setq kwd
(car kwds
)
4772 link
(idlwave-split-link-target (nth 1 kwd
))
4776 (if (setq block
(assoc link linkfiles
))
4777 (push (cons kwd anchor
) (cdr block
))
4778 (push (list link
(cons kwd anchor
)) linkfiles
))
4779 (setq kwds
(cdr kwds
)))
4780 ;; Ensure the master link is there
4781 (if (setq master-elt
(assoc master-link linkfiles
))
4782 (if (eq (car linkfiles
) master-elt
)
4784 (cons master-elt
(delq master-elt linkfiles
)))
4785 (push (list master-link
) linkfiles
))))
4787 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4788 ;; Clean up the syntax of routines which are actually aliases by
4789 ;; removing the "OR" from the statements
4791 (loop for x in aliases do
4792 (setq entry
(assoc x idlwave-system-routines
))
4794 (while (string-match " +or +" (setq syntax
(nth 4 entry
)))
4795 (setf (nth 4 entry
) (replace-match ", " t t syntax
)))))))
4797 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4798 ;; Duplicate and trim original routine aliases from rinfo list
4799 ;; This if for, e.g. OPENR/OPENW/OPENU
4800 (let (alias remove-list new parts all-parts
)
4801 (loop for x in aliases do
4802 (when (setq parts
(split-string (cdr x
) "/"))
4803 (setq new
(assoc (cdr x
) all-parts
))
4805 (setq new
(cons (cdr x
) parts
))
4806 (push new all-parts
))
4807 (setcdr new
(delete (car x
) (cdr new
)))))
4809 ;; Add any missing aliases (separate by slashes)
4810 (loop for x in all-parts do
4812 (push (cons (nth 1 x
) (car x
)) aliases
)))
4814 (loop for x in aliases do
4815 (when (setq alias
(assoc (cdr x
) idlwave-system-routines
))
4816 (unless (memq alias remove-list
) (push alias remove-list
))
4817 (setq alias
(copy-sequence alias
))
4818 (setcar alias
(car x
))
4819 (push alias idlwave-system-routines
)))
4820 (loop for x in remove-list do
4821 (delq x idlwave-system-routines
))))
4823 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4824 ;; Duplicate and trim original routine aliases from rinfo list
4825 ;; This if for, e.g. !X, !Y, !Z.
4826 (let (alias remove-list new parts all-parts
)
4827 (loop for x in aliases do
4828 (when (setq alias
(assoc (cdr x
) idlwave-system-variables-alist
))
4829 (unless (memq alias remove-list
) (push alias remove-list
))
4830 (setq alias
(copy-sequence alias
))
4831 (setcar alias
(car x
))
4832 (push alias idlwave-system-variables-alist
)))
4833 (loop for x in remove-list do
4834 (delq x idlwave-system-variables-alist
))))
4837 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4838 ;; Create a sysvar list entry from the xml parsed list.
4839 (let* ((nameblock (nth 1 xml-entry
))
4840 (name (cdr (assq 'name nameblock
)))
4841 (sysvar (substring name
(progn (string-match "^ *!" name
)
4843 (link (cdr (assq 'link nameblock
)))
4844 (params (cddr xml-entry
))
4845 (case-fold-search t
)
4846 pelem ptype props fields tags
)
4848 (setq pelem
(car params
))
4850 (setq ptype
(car pelem
)
4851 props
(car (cdr pelem
)))
4854 (push (cons (cdr (assq 'name props
))
4856 (idlwave-split-link-target (cdr (assq 'link props
)))))
4858 (setq params
(cdr params
)))
4860 (list sysvar
(if tags
(cons 'tags tags
)) (list 'link link
)))))
4863 (defvar idlwave-xml-routine-info-file nil
)
4865 (defun idlwave-save-routine-info ()
4866 (if idlwave-xml-routine-info-file
4867 (with-temp-file idlwave-xml-system-rinfo-converted-file
4869 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4870 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version
")
4871 ;; Automatically generated from source file:
4872 ;; " idlwave-xml-routine-info-file
"
4873 ;; on " (current-time-string) "
4875 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4876 idlwave-xml-routine-info-file
))
4877 (insert "\n(setq idlwave-system-routines\n '")
4878 (prin1 idlwave-system-routines
(current-buffer))
4880 (insert "\n(setq idlwave-system-variables-alist\n '")
4881 (prin1 idlwave-system-variables-alist
(current-buffer))
4883 (insert "\n(setq idlwave-system-class-info\n '")
4884 (prin1 idlwave-system-class-info
(current-buffer))
4886 (insert "\n(setq idlwave-executive-commands-alist\n '")
4887 (prin1 idlwave-executive-commands-alist
(current-buffer))
4889 (insert "\n(setq idlwave-help-special-topic-words\n '")
4890 (prin1 idlwave-help-special-topic-words
(current-buffer))
4893 (defun idlwave-convert-xml-system-routine-info ()
4894 "Convert XML supplied IDL routine info into internal form.
4895 Cache to disk for quick recovery."
4897 (let* ((dir (file-name-as-directory
4898 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4899 (catalog-file (expand-file-name "idl_catalog.xml" dir
))
4901 props rinfo msg-cnt elem type nelem class-result alias
4902 routines routine-aliases statement-aliases sysvar-aliases
4904 (if (not (file-exists-p catalog-file
))
4905 (error "No such XML routine info file: %s" catalog-file
)
4906 (if (not (file-readable-p catalog-file
))
4907 (error "Cannot read XML routine info file: %s" catalog-file
)))
4908 (message "Reading XML routine info...")
4909 (setq rinfo
(xml-parse-file catalog-file
))
4910 (message "Reading XML routine info...done")
4911 (setq rinfo
(assq 'CATALOG rinfo
))
4912 (unless rinfo
(error "Failed to parse XML routine info"))
4913 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4915 (setq version-string
(cdr (assq 'version
(nth 1 rinfo
)))
4918 (setq nelem
(length rinfo
)
4919 msg-cnt
(/ nelem
20))
4921 (setq idlwave-xml-routine-info-file nil
)
4922 (message "Converting XML routine info...")
4923 (setq idlwave-system-routines nil
4924 idlwave-system-variables-alist nil
4925 idlwave-system-class-info nil
4926 idlwave-executive-commands-alist nil
4927 idlwave-help-special-topic-words nil
)
4930 (setq elem
(car rinfo
)
4934 (setq type
(car elem
)
4935 props
(car (cdr elem
)))
4936 (if (= (mod elem-cnt msg-cnt
) 0)
4937 (message "Converting XML routine info...%2d%%"
4938 (/ (* elem-cnt
100) nelem
)))
4941 (if (setq alias
(assq 'alias_to props
))
4942 (push (cons (cdr (assq 'name props
)) (cdr alias
))
4944 (setq routines
(idlwave-xml-create-rinfo-list elem
))
4945 (if (listp (cdr routines
))
4946 (setq idlwave-system-routines
4947 (nconc idlwave-system-routines routines
))
4948 ;; a cons cell is an executive commands
4949 (push routines idlwave-executive-commands-alist
))))
4952 (setq class-result
(idlwave-xml-create-class-method-lists elem
))
4953 (push (car class-result
) idlwave-system-class-info
)
4954 (setq idlwave-system-routines
4955 (nconc idlwave-system-routines
(cdr class-result
))))
4957 ((eq type
'STATEMENT
)
4958 (push (cons (cdr (assq 'name props
))
4959 (cdr (assq 'link props
)))
4960 idlwave-help-special-topic-words
)
4961 ;; Save the links to those which are statement aliases (not routines)
4962 (if (setq alias
(assq 'alias_to props
))
4963 (unless (member (cdr alias
) statement-aliases
)
4964 (push (cdr alias
) statement-aliases
))))
4967 (if (setq alias
(cdr (assq 'alias_to props
)))
4968 (push (cons (substring (cdr (assq 'name props
)) 1)
4969 (substring alias
1))
4971 (push (idlwave-xml-create-sysvar-alist elem
)
4972 idlwave-system-variables-alist
)))
4974 (idlwave-convert-xml-clean-routine-aliases routine-aliases
)
4975 (idlwave-convert-xml-clean-statement-aliases statement-aliases
)
4976 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases
)
4978 (setq idlwave-xml-routine-info-file catalog-file
)
4979 (idlwave-save-routine-info)
4980 (message "Converting XML routine info...done")))
4983 ;; ("ROUTINE" type class
4984 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4985 ;; (buffer pro_file dir) | (compiled pro_file dir)
4986 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4987 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4990 (defun idlwave-load-rinfo-next-step ()
4991 (let ((inhibit-quit t
)
4992 (arr idlwave-load-rinfo-steps-done
))
4994 (when (not (aref arr
0))
4995 (message "Loading system routine info in idle time...")
4996 (idlwave-load-system-routine-info)
4997 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4998 (message "Loading system routine info in idle time...done")
5002 (when (not (aref arr
1))
5003 (message "Normalizing idlwave-system-routines in idle time...")
5004 (idlwave-reset-sintern t
)
5005 (put 'idlwave-reset-sintern
'done-by-idle t
)
5006 (setq idlwave-system-routines
5007 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5008 (message "Normalizing idlwave-system-routines in idle time...done")
5012 (when (not (aref arr
2))
5013 (when (and (stringp idlwave-user-catalog-file
)
5014 (file-regular-p idlwave-user-catalog-file
))
5015 (message "Loading user catalog in idle time...")
5017 (load-file idlwave-user-catalog-file
)
5018 (error (throw 'exit nil
)))
5019 ;; Check for the old style catalog and warn
5021 (boundp 'idlwave-library-routines
)
5022 idlwave-library-routines
)
5024 (setq idlwave-library-routines nil
)
5026 (message "Outdated user catalog: %s... recreate"
5027 idlwave-user-catalog-file
))
5028 (message "Loading user catalog in idle time...done")))
5032 (when (not (aref arr
3))
5033 (when idlwave-user-catalog-routines
5034 (message "Normalizing user catalog routines in idle time...")
5035 (setq idlwave-user-catalog-routines
5036 (idlwave-sintern-rinfo-list
5037 idlwave-user-catalog-routines
'sys
))
5039 "Normalizing user catalog routines in idle time...done"))
5043 (when (not (aref arr
4))
5044 (idlwave-scan-library-catalogs
5045 "Loading and normalizing library catalogs in idle time...")
5048 (when (not (aref arr
5))
5049 (message "Finishing initialization in idle time...")
5051 (message "Finishing initialization in idle time...done")
5054 ;; restart the timer
5056 (idlwave-load-rinfo-next-step)
5057 (setq idlwave-load-rinfo-idle-timer
5058 (run-with-idle-timer
5059 idlwave-init-rinfo-when-idle-after
5060 nil
'idlwave-load-rinfo-next-step
))))))
5062 (defun idlwave-load-all-rinfo (&optional force
)
5063 ;; Load and case-treat the system, user catalog, and library routine
5067 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
5068 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5069 (idlwave-load-system-routine-info))
5070 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
5071 (message "Normalizing idlwave-system-routines...")
5072 (setq idlwave-system-routines
5073 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5074 (message "Normalizing idlwave-system-routines...done"))
5075 (when idlwave-system-routines
5076 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
5077 (setq idlwave-last-system-routine-info-cons-cell
5078 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
)))
5081 (when (and (stringp idlwave-user-catalog-file
)
5082 (file-regular-p idlwave-user-catalog-file
))
5084 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
5085 (load-file idlwave-user-catalog-file
))
5088 (boundp 'idlwave-library-routines
)
5089 idlwave-library-routines
)
5090 (setq idlwave-library-routines nil
)
5091 (error "Outdated user catalog: %s... recreate"
5092 idlwave-user-catalog-file
))
5093 (setq idlwave-true-path-alist nil
)
5094 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
5095 (message "Normalizing user catalog routines...")
5096 (setq idlwave-user-catalog-routines
5097 (idlwave-sintern-rinfo-list
5098 idlwave-user-catalog-routines
'sys
))
5099 (message "Normalizing user catalog routines...done")))
5102 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
5103 (idlwave-scan-library-catalogs
5104 "Loading and normalizing library catalogs..."))
5105 (run-hooks 'idlwave-after-load-rinfo-hook
))
5108 (defun idlwave-update-buffer-routine-info ()
5111 ((eq idlwave-scan-all-buffers-for-routine-info t
)
5112 ;; Scan all buffers, current buffer last
5113 (message "Scanning all buffers...")
5114 (setq res
(idlwave-get-routine-info-from-buffers
5115 (reverse (buffer-list)))))
5116 ((null idlwave-scan-all-buffers-for-routine-info
)
5117 ;; Don't scan any buffers
5120 ;; Just scan this buffer
5121 (if (eq major-mode
'idlwave-mode
)
5123 (message "Scanning current buffer...")
5124 (setq res
(idlwave-get-routine-info-from-buffers
5125 (list (current-buffer))))))))
5126 ;; Put the result into the correct variable
5127 (setq idlwave-buffer-routines
5128 (idlwave-sintern-rinfo-list res
'set
))))
5130 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
5131 "Put the different sources for routine information together."
5132 ;; The sequence here is important because earlier definitions shadow
5133 ;; later ones. We assume that if things in the buffers are newer
5134 ;; then in the shell of the system, they are meant to be different.
5135 (setcdr idlwave-last-system-routine-info-cons-cell
5136 (append idlwave-buffer-routines
5137 idlwave-compiled-routines
5138 idlwave-library-catalog-routines
5139 idlwave-user-catalog-routines
))
5140 (setq idlwave-class-alist nil
)
5142 ;; Give a message with information about the number of routines we have.
5145 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5146 (length idlwave-buffer-routines
)
5147 (length idlwave-compiled-routines
)
5148 (length idlwave-library-catalog-routines
)
5149 (length idlwave-user-catalog-routines
)
5150 (length idlwave-system-routines
)))
5152 (run-hooks 'idlwave-update-rinfo-hook
)))
5154 (defun idlwave-class-alist ()
5155 "Return the class alist - make it if necessary."
5156 (or idlwave-class-alist
5158 (loop for x in idlwave-routines do
5159 (when (and (setq class
(nth 2 x
))
5160 (not (assq class idlwave-class-alist
)))
5161 (push (list class
) idlwave-class-alist
)))
5162 idlwave-class-alist
)))
5164 ;; Three functions for the hooks
5165 (defun idlwave-save-buffer-update ()
5166 (idlwave-update-current-buffer-info 'save-buffer
))
5167 (defun idlwave-kill-buffer-update ()
5168 (idlwave-update-current-buffer-info 'kill-buffer
))
5169 (defun idlwave-new-buffer-update ()
5170 (idlwave-update-current-buffer-info 'find-file
))
5172 (defun idlwave-update-current-buffer-info (why)
5173 "Update idlwave-routines for current buffer. Can run from after-save-hook."
5174 (when (and (eq major-mode
'idlwave-mode
)
5175 (or (eq t idlwave-auto-routine-info-updates
)
5176 (memq why idlwave-auto-routine-info-updates
))
5177 idlwave-scan-all-buffers-for-routine-info
5181 (idlwave-replace-buffer-routine-info
5183 (if (eq why
'kill-buffer
)
5186 (idlwave-sintern-rinfo-list
5187 (idlwave-get-routine-info-from-buffers
5188 (list (current-buffer))) 'set
))))
5189 (idlwave-concatenate-rinfo-lists 'quiet
)
5193 (defun idlwave-replace-buffer-routine-info (file new
)
5194 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5195 (let ((list idlwave-buffer-routines
)
5198 ;; The following test uses eq to make sure it works correctly
5199 ;; when two buffers visit the same file. Then the file names
5200 ;; will be equal, but not eq.
5201 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
5206 ;; End of that section reached. Jump.
5208 (setq list
(cdr list
)))
5209 (setq idlwave-buffer-routines
5210 (append new
(delq nil idlwave-buffer-routines
)))))
5212 ;;----- Scanning buffers -------------------
5214 (defun idlwave-get-routine-info-from-buffers (buffers)
5215 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5216 (let (buf routine-lists res
)
5218 (while (setq buf
(pop buffers
))
5220 (if (and (eq major-mode
'idlwave-mode
)
5222 ;; yes, this buffer has the right mode.
5223 (progn (setq res
(condition-case nil
5224 (idlwave-get-buffer-routine-info)
5226 (push res routine-lists
)))))
5227 ;; Concatenate the individual lists and return the result
5228 (apply 'nconc routine-lists
)))
5230 (defun idlwave-get-buffer-routine-info ()
5231 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5232 (let* ((case-fold-search t
)
5233 routine-list string entry
)
5237 (goto-char (point-min))
5238 (while (re-search-forward
5239 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
5240 (setq string
(buffer-substring-no-properties
5243 (idlwave-end-of-statement)
5245 (setq entry
(idlwave-parse-definition string
))
5246 (push entry routine-list
))))
5249 (defvar idlwave-scanning-lib-dir
)
5250 (defun idlwave-parse-definition (string)
5251 "Parse a module definition."
5252 (let ((case-fold-search t
)
5253 start name args type keywords class
)
5255 (while (string-match ";.*" string
)
5256 (setq string
(replace-match "" t t string
)))
5257 ;; Remove the continuation line stuff
5258 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
5259 (setq string
(replace-match "\\1 " t nil string
)))
5260 (while (string-match "\n" string
)
5261 (setq string
(replace-match " " t nil string
)))
5262 ;; Match the name and type.
5264 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
5265 (setq start
(match-end 0))
5266 (setq type
(downcase (match-string 1 string
)))
5267 (if (match-beginning 3)
5268 (setq class
(match-string 3 string
)))
5269 (setq name
(match-string 4 string
)))
5270 ;; Match normal args and keyword args
5271 (while (string-match
5272 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5274 (setq start
(match-end 0))
5275 (if (match-beginning 3)
5276 (push (match-string 1 string
) keywords
)
5277 (push (match-string 1 string
) args
)))
5278 ;; Normalize and sort.
5279 (setq args
(nreverse args
))
5280 (setq keywords
(sort keywords
(lambda (a b
)
5281 (string< (downcase a
) (downcase b
)))))
5282 ;; Make and return the entry
5283 ;; We don't know which argument are optional, so this information
5284 ;; will not be contained in the calling sequence.
5286 (if (equal type
"pro") 'pro
'fun
)
5288 (cond ((not (boundp 'idlwave-scanning-lib
))
5289 (list 'buffer
(buffer-file-name)))
5290 ; ((string= (downcase
5291 ; (file-name-sans-extension
5292 ; (file-name-nondirectory (buffer-file-name))))
5295 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5296 (t (list 'user
(file-name-nondirectory (buffer-file-name))
5297 idlwave-scanning-lib-dir
"UserLib")))
5299 (if (string= type
"function") "Result = " "")
5300 (if class
"Obj ->[%s::]" "")
5304 (if (string= type
"function") "(" ", ")
5305 (mapconcat 'identity args
", ")
5306 (if (string= type
"function") ")" ""))))
5308 (cons nil
(mapcar 'list keywords
)) ;No help file
5312 ;;----- Scanning the user catalog -------------------
5314 (defun idlwave-sys-dir ()
5315 "Return the syslib directory, or a dummy that never matches."
5317 ((and idlwave-system-directory
5318 (not (string= idlwave-system-directory
"")))
5319 idlwave-system-directory
)
5320 ((getenv "IDL_DIR"))
5324 (defun idlwave-create-user-catalog-file (&optional arg
)
5325 "Scan all files on selected dirs of IDL search path for routine information.
5327 A widget checklist will allow you to choose the directories. Write
5328 the result as a file `idlwave-user-catalog-file'. When this file
5329 exists, will be automatically loaded to give routine information about
5330 library routines. With ARG, just rescan the same directories as last
5331 time - so no widget will pop up."
5333 ;; Make sure the file is loaded if it exists.
5334 (if (and (stringp idlwave-user-catalog-file
)
5335 (file-regular-p idlwave-user-catalog-file
))
5337 (load-file idlwave-user-catalog-file
)
5339 ;; Make sure the file name makes sense
5340 (unless (and (stringp idlwave-user-catalog-file
)
5341 (> (length idlwave-user-catalog-file
) 0)
5342 (file-accessible-directory-p
5343 (file-name-directory idlwave-user-catalog-file
))
5344 (not (string= "" (file-name-nondirectory
5345 idlwave-user-catalog-file
))))
5346 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5349 ;; Rescan the known directories
5350 ((and arg idlwave-path-alist
5351 (consp (car idlwave-path-alist
)))
5352 (idlwave-scan-user-lib-files idlwave-path-alist
))
5354 ;; Expand the directories from library-path and run the widget
5355 (idlwave-library-path
5356 (idlwave-display-user-catalog-widget
5357 (if idlwave-true-path-alist
5358 ;; Propagate any flags on the existing path-alist
5360 (let ((path-entry (assoc (file-truename x
)
5361 idlwave-true-path-alist
)))
5363 (cons x
(cdr path-entry
))
5365 (idlwave-expand-path idlwave-library-path
))
5366 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
5368 ;; Ask the shell for the path and then run the widget
5370 (message "Asking the shell for IDL path...")
5371 (require 'idlw-shell
)
5372 (idlwave-shell-send-command idlwave-shell-path-query
5373 '(idlwave-user-catalog-command-hook nil
)
5377 ;; Parse shell path information and select among it.
5378 (defun idlwave-user-catalog-command-hook (&optional arg
)
5379 ;; Command hook used by `idlwave-create-user-catalog-file'.
5382 (idlwave-scan-user-lib-files idlwave-path-alist
)
5383 ;; Set the path and display the widget
5384 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
5385 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
5386 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
5388 (defconst idlwave-user-catalog-widget-help-string
5389 "This is the front-end to the creation of the IDLWAVE user catalog.
5390 Please select the directories on IDL's search path from which you
5391 would like to extract routine information, to be stored in the file:
5395 If this is not the correct file, first set variable
5396 `idlwave-user-catalog-file', and call this command again.
5398 N.B. Many libraries include pre-scanned catalog files
5399 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5400 not be scanned. You can scan your own libraries off-line using the
5401 perl script `idlwave_catalog'.
5403 After selecting the directories, choose [Scan & Save] to scan the library
5404 directories and save the routine info.
5407 (defvar idlwave-widget
)
5408 (defvar widget-keymap
)
5409 (defun idlwave-display-user-catalog-widget (dirs-list)
5410 "Create the widget to select IDL search path directories for scanning."
5415 (error "Don't know IDL's search path"))
5417 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5418 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5419 (kill-all-local-variables)
5420 (make-local-variable 'idlwave-widget
)
5421 (widget-insert (format idlwave-user-catalog-widget-help-string
5422 idlwave-user-catalog-file
))
5424 (widget-create 'push-button
5425 :notify
'idlwave-widget-scan-user-lib-files
5428 (widget-create 'push-button
5429 :notify
'idlwave-delete-user-catalog-file
5432 (widget-create 'push-button
5434 '(lambda (&rest ignore
)
5435 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5437 (unless (memq 'lib
(cdr x
))
5438 (idlwave-path-alist-add-flag x
'user
)))
5440 (idlwave-display-user-catalog-widget path-list
)))
5441 "Select All Non-Lib")
5443 (widget-create 'push-button
5445 '(lambda (&rest ignore
)
5446 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5448 (idlwave-path-alist-remove-flag x
'user
))
5450 (idlwave-display-user-catalog-widget path-list
)))
5453 (widget-create 'push-button
5454 :notify
(lambda (&rest ignore
)
5455 (kill-buffer (current-buffer)))
5457 (widget-insert "\n\n")
5459 (widget-insert "Select Directories: \n")
5461 (setq idlwave-widget
5462 (apply 'widget-create
5464 :value
(delq nil
(mapcar (lambda (x)
5465 (if (memq 'user
(cdr x
))
5469 :tag
"List of directories"
5472 (if (memq 'lib
(cdr x
))
5473 (concat "[LIB] " (car x
) )
5474 (car x
)))) dirs-list
)))
5475 (widget-put idlwave-widget
:path-dirs dirs-list
)
5476 (widget-insert "\n")
5477 (use-local-map widget-keymap
)
5479 (goto-char (point-min))
5480 (delete-other-windows))
5482 (defun idlwave-delete-user-catalog-file (&rest ignore
)
5484 (format "Delete file %s " idlwave-user-catalog-file
))
5486 (delete-file idlwave-user-catalog-file
)
5487 (message "%s has been deleted" idlwave-user-catalog-file
))))
5489 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
5490 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5491 (let* ((widget idlwave-widget
)
5492 (selected-dirs (widget-value widget
))
5493 (path-alist (widget-get widget
:path-dirs
))
5494 (this-path-alist path-alist
)
5496 (while (setq dir-entry
(pop this-path-alist
))
5498 (if (memq 'lib
(cdr dir-entry
))
5499 (concat "[LIB] " (car dir-entry
))
5502 (idlwave-path-alist-add-flag dir-entry
'user
)
5503 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5504 (idlwave-scan-user-lib-files path-alist
)))
5506 (defvar font-lock-mode
)
5507 (defun idlwave-scan-user-lib-files (path-alist)
5508 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5509 (let* ((idlwave-scanning-lib t
)
5510 (idlwave-scanning-lib-dir "")
5511 (idlwave-completion-case nil
)
5512 dirs-alist dir files file
)
5513 (setq idlwave-user-catalog-routines nil
5514 idlwave-path-alist path-alist
; for library-path instead
5515 idlwave-true-path-alist nil
)
5516 (if idlwave-auto-write-paths
(idlwave-write-paths))
5518 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5520 (setq dirs-alist
(reverse path-alist
))
5521 (while (setq dir
(pop dirs-alist
))
5522 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5523 (setq dir
(car dir
))
5524 (setq idlwave-scanning-lib-dir dir
)
5525 (when (file-directory-p dir
)
5526 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5527 (while (setq file
(pop files
))
5528 (when (file-regular-p file
)
5529 (if (not (file-readable-p file
))
5530 (message "Skipping %s (no read permission)" file
)
5531 (message "Scanning %s..." file
)
5533 (insert-file-contents file
'visit
)
5534 (setq idlwave-user-catalog-routines
5535 (append (idlwave-get-routine-info-from-buffers
5536 (list (current-buffer)))
5537 idlwave-user-catalog-routines
)))))))))
5538 (message "Creating user catalog file...")
5539 (kill-buffer "*idlwave-scan.pro*")
5540 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5541 (let ((font-lock-maximum-size 0)
5542 (auto-mode-alist nil
))
5543 (find-file idlwave-user-catalog-file
))
5544 (if (and (boundp 'font-lock-mode
)
5548 (insert ";; IDLWAVE user catalog file\n")
5549 (insert (format ";; Created %s\n\n" (current-time-string)))
5551 ;; Define the routine info list
5552 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5553 (let ((standard-output (current-buffer)))
5557 (goto-char (point-max)))
5558 idlwave-user-catalog-routines
))
5559 (insert (format "))\n\n;;; %s ends here\n"
5560 (file-name-nondirectory idlwave-user-catalog-file
)))
5561 (goto-char (point-min))
5564 (kill-buffer (current-buffer)))
5565 (message "Creating user catalog file...done")
5566 (message "Info for %d routines saved in %s"
5567 (length idlwave-user-catalog-routines
)
5568 idlwave-user-catalog-file
)
5570 (idlwave-update-routine-info t
))
5572 (defun idlwave-read-paths ()
5573 (if (and (stringp idlwave-path-file
)
5574 (file-regular-p idlwave-path-file
))
5576 (load idlwave-path-file t t t
)
5579 (defun idlwave-write-paths ()
5581 (when (and idlwave-path-alist idlwave-system-directory
)
5582 (let ((font-lock-maximum-size 0)
5583 (auto-mode-alist nil
))
5584 (find-file idlwave-path-file
))
5585 (if (and (boundp 'font-lock-mode
)
5589 (insert ";; IDLWAVE paths\n")
5590 (insert (format ";; Created %s\n\n" (current-time-string)))
5591 ;; Define the variable which knows the value of "!DIR"
5592 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5593 idlwave-system-directory
))
5595 ;; Define the variable which contains a list of all scanned directories
5596 (insert "\n(setq idlwave-path-alist\n '(")
5597 (let ((standard-output (current-buffer)))
5601 (goto-char (point-max)))
5602 idlwave-path-alist
))
5605 (kill-buffer (current-buffer))))
5608 (defun idlwave-expand-path (path &optional default-dir
)
5609 ;; Expand parts of path starting with '+' recursively into directory list.
5610 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5611 (message "Expanding path...")
5612 (let (path1 dir recursive
)
5613 (while (setq dir
(pop path
))
5614 (if (setq recursive
(string= (substring dir
0 1) "+"))
5615 (setq dir
(substring dir
1)))
5617 (not (file-name-absolute-p dir
)))
5618 (setq dir
(expand-file-name dir default-dir
)))
5620 ;; Expand recursively
5621 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5624 (message "Expanding path...done")
5627 (defun idlwave-recursive-directory-list (dir)
5628 ;; Return a list of all directories below DIR, including DIR itself
5629 (let ((path (list dir
)) path1 file files
)
5630 (while (setq dir
(pop path
))
5631 (when (file-directory-p dir
)
5632 (setq files
(nreverse (directory-files dir t
"[^.]")))
5633 (while (setq file
(pop files
))
5634 (if (file-directory-p file
)
5635 (push (file-name-as-directory file
) path
)))
5640 ;;----- Scanning the library catalogs ------------------
5645 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5646 "Scan for library catalog files (.idlwave_catalog) and ingest.
5648 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5649 instead, if present) are searched. Print MESSAGE-BASE along with the
5650 libraries being loaded, if passed, and skip loading/normalizing if
5651 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5652 be set to nil to disable library catalog scanning."
5653 (when idlwave-use-library-catalogs
5655 (if idlwave-library-path
5656 (idlwave-expand-path idlwave-library-path
)
5657 (mapcar 'car idlwave-path-alist
)))
5659 dir-entry dir flags catalog all-routines
)
5660 (if message-base
(message message-base
))
5661 (while (setq dir
(pop dirs
))
5663 (when (file-readable-p
5664 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5666 (setq idlwave-library-catalog-routines nil
)
5667 ;; Load the catalog file
5669 (load catalog t t t
)
5670 (error (throw 'continue t
)))
5673 (not (string= idlwave-library-catalog-libname
5675 (message "%s" (concat message-base
5676 idlwave-library-catalog-libname
))
5677 (setq old-libname idlwave-library-catalog-libname
))
5678 (when idlwave-library-catalog-routines
5681 (idlwave-sintern-rinfo-list
5682 idlwave-library-catalog-routines
'sys dir
)
5685 ;; Add a 'lib flag if on path-alist
5686 (when (and idlwave-path-alist
5687 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5688 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5689 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5690 (if message-base
(message (concat message-base
"done"))))))
5692 ;;----- Communicating with the Shell -------------------
5694 ;; First, here is the idl program which can be used to query IDL for
5695 ;; defined routines.
5696 (defconst idlwave-routine-info.pro
5698 ;; START OF IDLWAVE SUPPORT ROUTINES
5699 pro idlwave_print_safe,item,limit
5701 if err ne 0 then begin
5702 print,'Could not print item.'
5705 if n_elements(item) gt limit then $
5706 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5710 pro idlwave_print_info_entry,name,func=func,separator=sep
5711 ;; See if it's an object method
5712 if name eq '' then return
5713 func = keyword_set(func)
5714 methsep = strpos(name,'::')
5715 meth = methsep ne -1
5718 pars = routine_info(name,/parameters,functions=func)
5719 source = routine_info(name,/source,functions=func)
5720 nargs = pars.num_args
5721 nkw = pars.num_kw_args
5722 if nargs gt 0 then args = pars.args
5723 if nkw gt 0 then kwargs = pars.kw_args
5725 ;; Trim the class, and make the name
5727 class = strmid(name,0,methsep)
5728 name = strmid(name,methsep+2,strlen(name)-1)
5729 if nargs gt 0 then begin
5730 ;; remove the self argument
5731 wh = where(args ne 'SELF',nargs)
5732 if nargs gt 0 then args = args[wh]
5735 ;; No class, just a normal routine.
5741 if func then cs = 'Result = '
5742 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5744 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5745 if nargs gt 0 then begin
5746 for j=0,nargs-1 do begin
5748 if j lt nargs-1 then cs = cs + ', '
5751 if func then cs = cs + ')'
5752 ;; Keyword arguments
5754 if nkw gt 0 then begin
5755 for j=0,nkw-1 do begin
5756 kwstring = kwstring + ' ' + kwargs[j]
5760 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5762 print,ret + ': ' + name + sep + class + sep + source[0].path $
5763 + sep + cs + sep + kwstring
5766 pro idlwave_routine_info,file
5769 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5770 all = routine_info()
5771 fileQ=n_elements(file) ne 0
5772 if fileQ then file=strtrim(file,2)
5773 for i=0L,n_elements(all)-1L do begin
5775 if (routine_info(all[i],/SOURCE)).path eq file then $
5776 idlwave_print_info_entry,all[i],separator=sep
5777 endif else idlwave_print_info_entry,all[i],separator=sep
5779 all = routine_info(/functions)
5780 for i=0L,n_elements(all)-1L do begin
5782 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5783 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5784 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5786 print,'>>>END OF IDLWAVE ROUTINE INFO'
5789 pro idlwave_get_sysvars
5792 if error_status ne 0 then begin
5793 print, 'Cannot get info about system variables'
5795 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5796 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5797 v = strsplit(s,' +',/regex,/extract) ; get variables
5798 for i=0L,n_elements(v)-1 do begin
5799 t = [''] ; get tag list
5800 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5801 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5806 pro idlwave_get_class_tags, class
5807 res = execute('tags=tag_names({'+class+'})')
5808 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5810 ;; END OF IDLWAVE SUPPORT ROUTINES
5812 "The idl programs to get info from the shell.")
5814 (defvar idlwave-idlwave_routine_info-compiled nil
5815 "Remembers if the routine info procedure is already compiled.")
5817 (defvar idlwave-shell-temp-pro-file
)
5818 (defvar idlwave-shell-temp-rinfo-save-file
)
5820 (defun idlwave-shell-compile-helper-routines (&optional wait
)
5821 (unless (and idlwave-idlwave_routine_info-compiled
5822 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5824 (set-buffer (idlwave-find-file-noselect
5825 (idlwave-shell-temp-file 'pro
)))
5827 (insert idlwave-routine-info.pro
)
5829 (idlwave-shell-send-command
5830 (concat ".run \"" idlwave-shell-temp-pro-file
"\"")
5832 (idlwave-shell-send-command
5833 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5834 (idlwave-shell-temp-file 'rinfo
))
5836 (setq idlwave-idlwave_routine_info-compiled t
))
5838 ;; Restore if necessary. Must use execute to hide lame routine_info
5839 ;; errors on undefinded routine
5840 (idlwave-shell-send-command
5841 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5842 idlwave-shell-temp-rinfo-save-file
5843 idlwave-shell-temp-rinfo-save-file
)
5847 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file
)
5848 "Query the shell for routine_info of compiled modules and update the lists."
5849 ;; Save and compile the procedure. The compiled procedure is then
5850 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5851 ;; need to test for and possibly RESTORE the procedure each time we
5852 ;; use it, since the user may have killed or redefined it. In
5853 ;; particular, .RESET_SESSION will kill all user procedures. If
5854 ;; FILE is set, only update routine info for routines in that file.
5856 (idlwave-shell-compile-helper-routines wait
)
5857 ; execute the routine_info procedure, and analyze the output
5858 (idlwave-shell-send-command
5859 (format "idlwave_routine_info%s" (if file
(concat ",'" file
"'") ""))
5861 (idlwave-shell-routine-info-filter)
5862 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5865 ;; ---------------------------------------------------------------------------
5867 ;; Completion and displaying routine calling sequences
5869 (defvar idlwave-completion-help-info nil
)
5870 (defvar idlwave-completion-help-links nil
)
5871 (defvar idlwave-current-obj_new-class nil
)
5872 (defvar idlwave-complete-special nil
)
5874 (defun idlwave-complete (&optional arg module class
)
5875 "Complete a function, procedure or keyword name at point.
5876 This function is smart and figures out what can be completed
5878 - At the beginning of a statement it completes procedure names.
5879 - In the middle of a statement it completes function names.
5880 - after a `(' or `,' in the argument list of a function or procedure,
5881 it completes a keyword of the relevant function or procedure.
5882 - In the first arg of `OBJ_NEW', it completes a class name.
5884 When several completions are possible, a list will be displayed in the
5885 *Completions* buffer. If this list is too long to fit into the
5886 window, scrolling can be achieved by repeatedly pressing
5887 \\[idlwave-complete].
5889 The function also knows about object methods. When it needs a class
5890 name, the action depends upon `idlwave-query-class', which see. You
5891 can force IDLWAVE to ask you for a class name with a
5892 \\[universal-argument] prefix argument to this command.
5894 See also the variables `idlwave-keyword-completion-adds-equal' and
5895 `idlwave-function-completion-adds-paren'.
5897 The optional ARG can be used to specify the completion type in order
5898 to override IDLWAVE's idea of what should be completed at point.
5899 Possible values are:
5901 0 <=> query for the completion type
5903 2 <=> 'procedure-keyword
5905 4 <=> 'function-keyword
5906 5 <=> 'procedure-method
5907 6 <=> 'procedure-method-keyword
5908 7 <=> 'function-method
5909 8 <=> 'function-method-keyword
5912 As a special case, the universal argument C-u forces completion of
5913 function names in places where the default would be a keyword.
5915 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5918 For Lisp programmers only:
5919 When we force a keyword, optional argument MODULE can contain the module name.
5920 When we force a method or a method keyword, CLASS can specify the class."
5925 (or (and (integerp arg
) (not (equal arg
'(16))))
5927 (idlwave-make-force-complete-where-list arg module class
)
5929 (what (nth 2 where-list
))
5930 (idlwave-force-class-query (equal arg
'(4)))
5931 (completion-regexp-list
5932 (if (equal arg
'(16))
5933 (list (read-string (concat "Completion Regexp: "))))))
5935 (if (and module
(string-match "::" module
))
5936 (setq class
(substring module
0 (match-beginning 0))
5937 module
(substring module
(match-end 0))))
5942 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5943 (get-buffer-window "*Completions*"))
5944 (setq this-command last-command
)
5945 (idlwave-scroll-completions))
5947 ;; Complete a filename in quotes
5948 ((and (idlwave-in-quote)
5949 (not (eq what
'class
)))
5950 (idlwave-complete-filename))
5952 ;; Check for any special completion functions
5953 ((and idlwave-complete-special
5954 (idlwave-call-special idlwave-complete-special
)))
5957 (error "Nothing to complete here"))
5961 (setq idlwave-completion-help-info
'(class))
5962 (idlwave-complete-class))
5964 ((eq what
'procedure
)
5965 ;; Complete a procedure name
5966 (let* ((cw-list (nth 3 where-list
))
5967 (class-selector (idlwave-determine-class cw-list
'pro
))
5968 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5969 (idlwave-all-class-inherits class-selector
)))
5970 (isa (concat "procedure" (if class-selector
"-method" "")))
5971 (type-selector 'pro
))
5972 (setq idlwave-completion-help-info
5973 (list 'routine nil type-selector class-selector nil super-classes
))
5974 (idlwave-complete-in-buffer
5975 'procedure
(if class-selector
'method
'routine
)
5976 (idlwave-routines) 'idlwave-selector
5977 (format "Select a %s name%s"
5980 (format " (class is %s)"
5981 (if (eq class-selector t
)
5982 "unknown" class-selector
))
5985 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5987 ((eq what
'function
)
5988 ;; Complete a function name
5989 (let* ((cw-list (nth 3 where-list
))
5990 (class-selector (idlwave-determine-class cw-list
'fun
))
5991 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5992 (idlwave-all-class-inherits class-selector
)))
5993 (isa (concat "function" (if class-selector
"-method" "")))
5994 (type-selector 'fun
))
5995 (setq idlwave-completion-help-info
5996 (list 'routine nil type-selector class-selector nil super-classes
))
5997 (idlwave-complete-in-buffer
5998 'function
(if class-selector
'method
'routine
)
5999 (idlwave-routines) 'idlwave-selector
6000 (format "Select a %s name%s"
6003 (format " (class is %s)"
6004 (if (eq class-selector t
)
6005 "unknown" class-selector
))
6008 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
6010 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
6012 (idlwave-complete 3))
6014 ((eq what
'procedure-keyword
)
6015 ;; Complete a procedure keyword
6016 (let* ((where (nth 3 where-list
))
6018 (method-selector name
)
6019 (type-selector 'pro
)
6020 (class (idlwave-determine-class where
'pro
))
6021 (class-selector class
)
6022 (super-classes (idlwave-all-class-inherits class-selector
))
6023 (isa (format "procedure%s-keyword" (if class
"-method" "")))
6024 (entry (idlwave-best-rinfo-assq
6025 name
'pro class
(idlwave-routines)))
6026 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6027 (list (idlwave-entry-keywords entry
'do-link
)))
6028 (unless (or entry
(eq class t
))
6029 (error "Nothing known about procedure %s"
6030 (idlwave-make-full-name class name
)))
6031 (setq list
(idlwave-fix-keywords name
'pro class list
6032 super-classes system
))
6033 (unless list
(error "No keywords available for procedure %s"
6034 (idlwave-make-full-name class name
)))
6035 (setq idlwave-completion-help-info
6036 (list 'keyword name type-selector class-selector entry super-classes
))
6037 (idlwave-complete-in-buffer
6038 'keyword
'keyword list nil
6039 (format "Select keyword for procedure %s%s"
6040 (idlwave-make-full-name class name
)
6041 (if (or (member '("_EXTRA") list
)
6042 (member '("_REF_EXTRA") list
))
6043 " (note _EXTRA)" ""))
6045 'idlwave-attach-keyword-classes
)))
6047 ((eq what
'function-keyword
)
6048 ;; Complete a function keyword
6049 (let* ((where (nth 3 where-list
))
6051 (method-selector name
)
6052 (type-selector 'fun
)
6053 (class (idlwave-determine-class where
'fun
))
6054 (class-selector class
)
6055 (super-classes (idlwave-all-class-inherits class-selector
))
6056 (isa (format "function%s-keyword" (if class
"-method" "")))
6057 (entry (idlwave-best-rinfo-assq
6058 name
'fun class
(idlwave-routines)))
6059 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6060 (list (idlwave-entry-keywords entry
'do-link
))
6062 (unless (or entry
(eq class t
))
6063 (error "Nothing known about function %s"
6064 (idlwave-make-full-name class name
)))
6065 (setq list
(idlwave-fix-keywords name
'fun class list
6066 super-classes system
))
6067 ;; OBJ_NEW: Messages mention the proper Init method
6068 (setq msg-name
(if (and (null class
)
6069 (string= (upcase name
) "OBJ_NEW"))
6070 (concat idlwave-current-obj_new-class
6071 "::Init (via OBJ_NEW)")
6072 (idlwave-make-full-name class name
)))
6073 (unless list
(error "No keywords available for function %s"
6075 (setq idlwave-completion-help-info
6076 (list 'keyword name type-selector class-selector nil super-classes
))
6077 (idlwave-complete-in-buffer
6078 'keyword
'keyword list nil
6079 (format "Select keyword for function %s%s" msg-name
6080 (if (or (member '("_EXTRA") list
)
6081 (member '("_REF_EXTRA") list
))
6082 " (note _EXTRA)" ""))
6084 'idlwave-attach-keyword-classes
)))
6086 (t (error "This should not happen (idlwave-complete)")))))
6088 (defvar idlwave-complete-special nil
6089 "List of special completion functions.
6090 These functions are called for each completion. Each function must
6091 check if its own special completion context is present. If yes, it
6092 should use `idlwave-complete-in-buffer' to do some completion and
6093 return t. If such a function returns t, *no further* attempts to
6094 complete other contexts will be done. If the function returns nil,
6095 other completions will be tried.")
6097 (defun idlwave-call-special (functions &rest args
)
6098 (let ((funcs functions
)
6101 (while (setq fun
(pop funcs
))
6102 (if (setq ret
(apply fun args
))
6106 (defun idlwave-make-force-complete-where-list (what &optional module class
)
6107 ;; Return an artificial WHERE specification to force the completion
6108 ;; routine to complete a specific item independent of context.
6109 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6110 ;; MODULE and CLASS can be used to specify the routine name and class.
6111 ;; The class name will also be found in MODULE if that is like "class::mod".
6112 (let* ((what-list '(("procedure") ("procedure-keyword")
6113 ("function") ("function-keyword")
6114 ("procedure-method") ("procedure-method-keyword")
6115 ("function-method") ("function-method-keyword")
6117 (module (idlwave-sintern-routine-or-method module class
))
6118 (class (idlwave-sintern-class class
))
6122 (intern (completing-read
6123 "Complete what? " what-list nil t
))))
6125 (setq what
(intern (car (nth (1- what
) what-list
)))))
6128 (assoc (symbol-name what
) what-list
))
6130 (t (error "Invalid WHAT"))))
6131 (nil-list '(nil nil nil nil
))
6132 (class-list (list nil nil
(or class t
) nil
)))
6136 ((eq what
'procedure
)
6137 (list nil-list nil-list
'procedure nil-list nil
))
6139 ((eq what
'procedure-keyword
)
6140 (let* ((class-selector nil
)
6142 (type-selector 'pro
)
6144 (idlwave-completing-read
6145 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
6146 (setq pro
(idlwave-sintern-routine pro
))
6147 (list nil-list nil-list
'procedure-keyword
6148 (list pro nil nil nil
) nil
)))
6150 ((eq what
'function
)
6151 (list nil-list nil-list
'function nil-list nil
))
6153 ((eq what
'function-keyword
)
6154 (let* ((class-selector nil
)
6156 (type-selector 'fun
)
6158 (idlwave-completing-read
6159 "Function: " (idlwave-routines) 'idlwave-selector
))))
6160 (setq func
(idlwave-sintern-routine func
))
6161 (list nil-list nil-list
'function-keyword
6162 (list func nil nil nil
) nil
)))
6164 ((eq what
'procedure-method
)
6165 (list nil-list nil-list
'procedure class-list nil
))
6167 ((eq what
'procedure-method-keyword
)
6168 (let* ((class (idlwave-determine-class class-list
'pro
))
6169 (class-selector class
)
6170 (super-classes (idlwave-all-class-inherits class-selector
))
6171 (type-selector 'pro
)
6173 (idlwave-completing-read
6174 (format "Procedure in %s class: " class-selector
)
6175 (idlwave-routines) 'idlwave-selector
))))
6176 (setq pro
(idlwave-sintern-method pro
))
6177 (list nil-list nil-list
'procedure-keyword
6178 (list pro nil class nil
) nil
)))
6180 ((eq what
'function-method
)
6181 (list nil-list nil-list
'function class-list nil
))
6183 ((eq what
'function-method-keyword
)
6184 (let* ((class (idlwave-determine-class class-list
'fun
))
6185 (class-selector class
)
6186 (super-classes (idlwave-all-class-inherits class-selector
))
6187 (type-selector 'fun
)
6189 (idlwave-completing-read
6190 (format "Function in %s class: " class-selector
)
6191 (idlwave-routines) 'idlwave-selector
))))
6192 (setq func
(idlwave-sintern-method func
))
6193 (list nil-list nil-list
'function-keyword
6194 (list func nil class nil
) nil
)))
6197 (list nil-list nil-list
'class nil-list nil
))
6199 (t (error "Invalid value for WHAT")))))
6201 (defun idlwave-completing-read (&rest args
)
6202 ;; Completing read, case insensitive
6203 (let ((old-value (default-value 'completion-ignore-case
)))
6206 (setq-default completion-ignore-case t
)
6207 (apply 'completing-read args
))
6208 (setq-default completion-ignore-case old-value
))))
6210 (defvar idlwave-shell-default-directory
)
6211 (defun idlwave-complete-filename ()
6212 "Use the comint stuff to complete a file name."
6214 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6215 (comint-completion-addsuffix nil
)
6217 (if (and (boundp 'idlwave-shell-default-directory
)
6218 (stringp idlwave-shell-default-directory
)
6219 (file-directory-p idlwave-shell-default-directory
))
6220 idlwave-shell-default-directory
6221 default-directory
)))
6222 (comint-dynamic-complete-filename)))
6224 (defun idlwave-make-full-name (class name
)
6225 ;; Make a fully qualified module name including the class name
6226 (concat (if class
(format "%s::" class
) "") name
))
6228 (defun idlwave-rinfo-assoc (name type class list
)
6229 "Like `idlwave-rinfo-assq', but sintern strings first."
6231 (idlwave-sintern-routine-or-method name class
)
6232 type
(idlwave-sintern-class class
) list
))
6234 (defun idlwave-rinfo-assq (name type class list
)
6235 ;; Works like assq, but also checks type and class
6238 (while (setq match
(assq name list
))
6239 (and (or (eq type t
)
6240 (eq (nth 1 match
) type
))
6241 (eq (nth 2 match
) class
)
6242 (throw 'exit match
))
6243 (setq list
(cdr (memq match list
)))))))
6245 (defun idlwave-rinfo-assq-any-class (name type class list
)
6246 ;; Return the first matching method on the inheritance list
6247 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
6250 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
6251 (setq classes nil
)))
6254 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
6256 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6257 If WITH-FILE is passed, find the best rinfo entry with a file
6258 included. If KEEP-SYSTEM is set, don't prune system for compiled
6260 (let ((twins (idlwave-routine-twins
6261 (idlwave-rinfo-assq-any-class name type class list
)
6264 (when (> (length twins
) 1)
6265 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
6266 (if (and (null keep-system
)
6267 (eq 'system
(car (nth 3 (car twins
))))
6268 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
6269 (not (equal 1 syslibp
)))
6270 ;; Its a compiled syslib, so we need to remove the system entry
6271 (setq twins
(cdr twins
)))
6273 (setq twins
(delq nil
6275 (if (nth 1 (nth 3 x
)) x
))
6279 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
6281 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6282 (idlwave-best-rinfo-assq
6283 (idlwave-sintern-routine-or-method name class
)
6284 type
(idlwave-sintern-class class
) list with-file keep-system
))
6286 (defun idlwave-any-syslib (entries)
6287 "Does the entry list ENTRIES contain a syslib entry?
6288 If yes, return the index (>=1)."
6293 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
6294 (if (and file
(idlwave-syslib-p file
))
6296 (setq entries
(cdr entries
))))
6299 (defun idlwave-all-assq (key list
)
6300 "Return a list of all associations of Key in LIST."
6302 (while (setq elt
(assq key list
))
6304 (setq list
(cdr (memq elt list
))))
6307 (defun idlwave-all-method-classes (method &optional type
)
6308 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
6309 When TYPE is not specified, both procedures and functions will be considered."
6311 (mapcar 'car
(idlwave-class-alist))
6316 (eq type
(nth 1 x
)))
6317 (push (nth 2 x
) rtn
)))
6318 (idlwave-all-assq method
(idlwave-routines)))
6319 (idlwave-uniquify rtn
))))
6321 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
6322 "Return all classes which have a method METHOD with keyword KEYWORD.
6323 TYPE is 'fun or 'pro.
6324 When TYPE is not specified, both procedures and functions will be considered."
6325 (if (or (null method
)
6330 (and (nth 2 x
) ; non-nil class
6331 (or (not type
) ; correct or unspecified type
6332 (eq type
(nth 1 x
)))
6333 (assoc keyword
(idlwave-entry-keywords x
))
6334 (push (nth 2 x
) rtn
)))
6335 (idlwave-all-assq method
(idlwave-routines)))
6336 (idlwave-uniquify rtn
))))
6338 (defun idlwave-members-only (list club
)
6339 "Return list of all elements in LIST which are also in CLUB."
6342 (if (member (car list
) club
)
6343 (setq rtn
(cons (car list
) rtn
)))
6344 (setq list
(cdr list
)))
6347 (defun idlwave-nonmembers-only (list club
)
6348 "Return list of all elements in LIST which are not in CLUB."
6351 (if (member (car list
) club
)
6353 (setq rtn
(cons (car list
) rtn
)))
6354 (setq list
(cdr list
)))
6357 (defun idlwave-explicit-class-listed (info)
6358 "Return whether or not the class is listed explicitly, ala a->b::c.
6359 INFO is as returned by idlwave-what-function or -procedure."
6360 (let ((apos (nth 3 info
)))
6362 (save-excursion (goto-char apos
)
6363 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6365 (defvar idlwave-determine-class-special nil
6366 "List of special functions for determining class.
6367 Must accept two arguments: `apos' and `info'")
6369 (defun idlwave-determine-class (info type
)
6370 ;; Determine the class of a routine call.
6371 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6372 ;; The second element in this structure is the class. When nil, we
6373 ;; return nil. When t, try to get the class from text properties at
6374 ;; the arrow. When the object is "self", we use the class of the
6375 ;; current routine. otherwise prompt the user for a class name.
6376 ;; Also stores the selected class as a text property at the arrow.
6377 ;; TYPE is 'fun or 'pro.
6378 (let* ((class (nth 2 info
))
6380 (nassoc (assoc (if (stringp (car info
))
6383 idlwave-query-class
))
6384 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
6385 idlwave-query-class
))
6386 (query (cond (nassoc (cdr nassoc
))
6387 (dassoc (cdr dassoc
))
6389 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
6392 (save-excursion (goto-char apos
)
6394 (let ((case-fold-search t
))
6395 (looking-at "self\\>")))))
6396 (force-query idlwave-force-class-query
)
6397 store special-class class-alist
)
6401 ;; There is an object which would like to know its class
6402 (if (and arrow
(get-text-property apos
'idlwave-class
)
6403 idlwave-store-inquired-class
6405 (setq class
(get-text-property apos
'idlwave-class
)
6406 class
(idlwave-sintern-class class
)))
6407 (if (and (eq t class
) is-self
)
6408 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
6410 ;; Before prompting, try any special class determination routines
6411 (when (and (eq t class
)
6412 idlwave-determine-class-special
6415 (idlwave-call-special idlwave-determine-class-special apos
))
6417 (setq class
(idlwave-sintern-class special-class
)
6418 store idlwave-store-inquired-class
)))
6420 ;; Prompt for a class, if we need to
6421 (when (and (eq class t
)
6422 (or force-query query
))
6424 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
6426 (idlwave-sintern-class
6428 ((and (= (length class-alist
) 0) (not force-query
))
6429 (error "No classes available with method %s" (car info
)))
6430 ((and (= (length class-alist
) 1) (not force-query
))
6431 (car (car class-alist
)))
6433 (setq store idlwave-store-inquired-class
)
6434 (idlwave-completing-read
6435 (format "Class%s: " (if (stringp (car info
))
6436 (format " for %s method %s"
6439 class-alist nil nil nil
'idlwave-class-history
))))))
6441 ;; Store it, if requested
6442 (when (and class
(not (eq t class
)))
6443 ;; We have a real class here
6444 (when (and store arrow
)
6446 (add-text-properties
6448 `(idlwave-class ,class face
,idlwave-class-arrow-face
6451 (setf (nth 2 info
) class
))
6454 ;; Default as fallback
6457 (defvar type-selector
)
6458 (defvar class-selector
)
6459 (defvar method-selector
)
6460 (defvar super-classes
)
6461 (defun idlwave-selector (a)
6462 (and (eq (nth 1 a
) type-selector
)
6463 (or (and (nth 2 a
) (eq class-selector t
))
6464 (eq (nth 2 a
) class-selector
)
6465 (memq (nth 2 a
) super-classes
))))
6467 (defun idlwave-add-file-link-selector (a)
6468 ;; Record a file link, if any, for the tested names during selection.
6469 (let ((sel (idlwave-selector a
)) file
)
6470 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
6471 (push (cons (car a
) file
) idlwave-completion-help-links
))
6475 (defun idlwave-where ()
6476 "Find out where we are.
6477 The return value is a list with the following stuff:
6478 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6480 PRO-LIST (PRO POINT CLASS ARROW)
6481 FUNC-LIST (FUNC POINT CLASS ARROW)
6482 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6483 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6485 LAST-CHAR last relevant character before point (non-white non-comment,
6486 not part of current identifier or leading slash).
6488 In the lists, we have these meanings:
6491 POINT: Where is this
6492 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6493 ARROW: Location of the arrow"
6495 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6496 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
6497 (func-entry (idlwave-what-function bos
))
6498 (func (car func-entry
))
6499 (func-class (nth 1 func-entry
))
6500 (func-arrow (nth 2 func-entry
))
6501 (func-point (or (nth 3 func-entry
) 0))
6502 (func-level (or (nth 4 func-entry
) 0))
6503 (pro-entry (idlwave-what-procedure bos
))
6504 (pro (car pro-entry
))
6505 (pro-class (nth 1 pro-entry
))
6506 (pro-arrow (nth 2 pro-entry
))
6507 (pro-point (or (nth 3 pro-entry
) 0))
6508 (last-char (idlwave-last-valid-char))
6509 (case-fold-search t
)
6510 (match-string (buffer-substring bos
(point)))
6511 cw cw-mod cw-arrow cw-class cw-point
)
6512 (if (< func-point pro-point
) (setq func nil
))
6514 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6518 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6520 (buffer-substring pro-point
(point))
6522 (setq cw
'procedure cw-class pro-class cw-point pro-point
6523 cw-arrow pro-arrow
))
6524 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6527 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6530 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6534 (> func-point pro-point
)
6536 (memq last-char
'(?\
( ?
,)))
6537 (setq cw
'function-keyword cw-mod func cw-point func-point
6538 cw-class func-class cw-arrow func-arrow
))
6539 ((and pro
(eq last-char ?
,))
6540 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
6541 cw-class pro-class cw-arrow pro-arrow
))
6542 ; ((member last-char '(?\' ?\) ?\] ?!))
6543 ; ;; after these chars, a function makes no sense
6544 ; ;; FIXME: I am sure there can be more in this list
6545 ; ;; FIXME: Do we want to do this at all?
6547 ;; Everywhere else we try a function.
6551 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6552 (setq cw-arrow
(copy-marker (match-beginning 0))
6553 cw-class
(if (match-end 4)
6554 (idlwave-sintern-class (match-string 4))
6556 (list (list pro pro-point pro-class pro-arrow
)
6557 (list func func-point func-class func-arrow
)
6559 (list cw-mod cw-point cw-class cw-arrow
)
6562 (defun idlwave-this-word (&optional class
)
6563 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6564 (setq class
(or class
"a-zA-Z0-9$_."))
6567 (progn (skip-chars-backward class
) (point))
6568 (progn (skip-chars-forward class
) (point)))))
6570 (defun idlwave-what-function (&optional bound
)
6571 ;; Find out if point is within the argument list of a function.
6572 ;; The return value is ("function-name" class arrow-start (point) level).
6573 ;; Level is 1 on the top level parentheses, higher further down.
6575 ;; If the optional BOUND is an integer, bound backwards directed
6576 ;; searches to this point.
6582 func arrow-start class
)
6583 (idlwave-with-special-syntax
6586 (narrow-to-region (max 1 (or bound
0)) (point-max))
6587 ;; move back out of the current parenthesis
6588 (while (condition-case nil
6589 (progn (up-list -
1) t
)
6593 (when (and (= (following-char) ?\
()
6595 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6597 (setq func
(match-string 2)
6598 func-point
(goto-char (match-beginning 2))
6600 (if (re-search-backward
6601 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6602 (setq arrow-start
(copy-marker (match-beginning 0))
6603 class
(or (match-string 2) t
)))
6607 (idlwave-sintern-routine-or-method func class
)
6608 (idlwave-sintern-class class
)
6609 arrow-start func-point cnt
)))
6611 (throw 'exit nil
)))))))
6613 (defun idlwave-what-procedure (&optional bound
)
6614 ;; Find out if point is within the argument list of a procedure.
6615 ;; The return value is ("procedure-name" class arrow-pos (point)).
6617 ;; If the optional BOUND is an integer, bound backwards directed
6618 ;; searches to this point.
6619 (let ((pos (point)) pro-point
6620 pro class arrow-start string
)
6622 ;;(idlwave-beginning-of-statement)
6623 (idlwave-start-of-substatement 'pre
)
6624 (setq string
(buffer-substring (point) pos
))
6626 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6627 (setq pro
(match-string 1 string
)
6628 pro-point
(+ (point) (match-beginning 1)))
6629 (if (and (idlwave-skip-object)
6630 (setq string
(buffer-substring (point) pos
))
6632 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6634 (setq pro
(if (match-beginning 4)
6635 (match-string 4 string
))
6636 pro-point
(if (match-beginning 4)
6637 (+ (point) (match-beginning 4))
6639 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6640 class
(or (match-string 3 string
) t
)))))
6641 (list (idlwave-sintern-routine-or-method pro class
)
6642 (idlwave-sintern-class class
)
6646 (defun idlwave-skip-object ()
6647 ;; If there is an object at point, move over it and return t.
6648 (let ((pos (point)))
6651 (skip-chars-forward " ") ; white space
6652 (skip-chars-forward "*") ; de-reference
6654 ((looking-at idlwave-identifier
)
6655 (goto-char (match-end 0)))
6656 ((eq (following-char) ?\
()
6658 (t (throw 'exit nil
)))
6661 (cond ((eq (following-char) ?.
)
6663 (if (not (looking-at idlwave-identifier
))
6665 (goto-char (match-end 0)))
6666 ((memq (following-char) '(?\
( ?\
[))
6669 (error (throw 'exit nil
))))
6670 (t (throw 'endwhile t
)))))
6671 (if (looking-at "[ \t]*->")
6672 (throw 'exit
(setq pos
(match-beginning 0)))
6673 (throw 'exit nil
))))
6677 (defun idlwave-last-valid-char ()
6678 "Return the last character before point which is not white or a comment
6679 and also not part of the current identifier. Since we do this in
6680 order to identify places where keywords are, we consider the initial
6681 `/' of a keyword as part of the identifier.
6682 This function is not general, can only be used for completion stuff."
6685 ;; skip the current identifier
6686 (skip-chars-backward "a-zA-Z0-9_$")
6687 ;; also skip a leading slash which might be belong to the keyword
6688 (if (eq (preceding-char) ?
/)
6690 ;; FIXME: does not check if this is a valid identifier
6692 (skip-chars-backward " \t")
6694 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6695 ((eq (preceding-char) ?
\n)
6696 (beginning-of-line 0)
6697 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6698 ;; continuation line
6699 (goto-char (match-end 1))
6701 (t (throw 'exit
(preceding-char))))))))
6703 (defvar idlwave-complete-after-success-form nil
6704 "A form to evaluate after successful completion.")
6705 (defvar idlwave-complete-after-success-form-force nil
6706 "A form to evaluate after completion selection in *Completions* buffer.")
6707 (defconst idlwave-completion-mark
(make-marker)
6708 "A mark pointing to the beginning of the completion string.")
6710 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6711 &optional prepare-display-function
6713 "Perform TYPE completion of word before point against LIST.
6714 SELECTOR is the PREDICATE argument for the completion function. Show
6715 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6716 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6717 used only once, for `all-completions', and can be used to, e.g.,
6718 accumulate information on matching completions."
6719 (let* ((completion-ignore-case t
)
6720 beg
(end (point)) slash part spart completion all-completions
6724 (error (concat prompt
": No completions available")))
6726 ;; What is already in the buffer?
6728 (skip-chars-backward "a-zA-Z0-9_$")
6729 (setq slash
(eq (preceding-char) ?
/)
6731 idlwave-complete-after-success-form
6732 (list 'idlwave-after-successful-completion
6733 (list 'quote type
) slash beg
)
6734 idlwave-complete-after-success-form-force
6735 (list 'idlwave-after-successful-completion
6736 (list 'quote type
) slash
(list 'quote
'force
))))
6739 (setq part
(buffer-substring beg end
)
6740 dpart
(downcase part
)
6741 spart
(idlwave-sintern stype part
)
6742 completion
(try-completion part list selector
)
6743 dcompletion
(if (stringp completion
) (downcase completion
))
6744 idlwave-completion-help-links nil
)
6747 ;; nothing available.
6748 (error (concat prompt
": no completion for \"%s\"") part
))
6749 ((and (not (equal dpart dcompletion
))
6750 (not (eq t completion
)))
6751 ;; We can add something
6752 (delete-region beg end
)
6753 (if (and (string= part dpart
)
6754 (or (not (string= part
""))
6755 idlwave-complete-empty-string-as-lower-case
)
6756 (not idlwave-completion-force-default-case
))
6757 (insert dcompletion
)
6758 (insert completion
))
6759 (if (eq t
(try-completion completion list selector
))
6760 ;; Now this is a unique match
6761 (idlwave-after-successful-completion type slash beg
))
6763 ((or (eq completion t
)
6764 (and (= 1 (length (setq all-completions
6766 (all-completions part list
6767 (or special-selector
6769 (equal dpart dcompletion
)))
6770 ;; This is already complete
6771 (idlwave-after-successful-completion type slash beg
)
6772 (message "%s is already the complete %s" part isa
)
6775 ;; We cannot add something - offer a list.
6776 (message "Making completion list...")
6778 (unless idlwave-completion-help-links
; already set somewhere?
6779 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6780 (let ((link (get-text-property 0 'link
(car x
))))
6782 (push (cons (car x
) link
)
6783 idlwave-completion-help-links
))))
6785 (let* ((list all-completions
)
6786 ;; "complete" means, this is already a valid completion
6787 (complete (memq spart all-completions
))
6788 (completion-highlight-first-word-only t
)) ; XEmacs
6789 ; (completion-fixup-function ; Emacs
6790 ; (lambda () (and (eq (preceding-char) ?>)
6791 ; (re-search-backward " <" beg t)))))
6793 (setq list
(sort list
(lambda (a b
)
6794 (string< (downcase a
) (downcase b
)))))
6795 (if prepare-display-function
6796 (setq list
(funcall prepare-display-function list
)))
6797 (if (and (string= part dpart
)
6798 (or (not (string= part
""))
6799 idlwave-complete-empty-string-as-lower-case
)
6800 (not idlwave-completion-force-default-case
))
6801 (setq list
(mapcar (lambda (x)
6803 (setcar x
(downcase (car x
)))
6804 (setq x
(downcase x
)))
6807 (idlwave-display-completion-list list prompt beg complete
))
6810 (defun idlwave-complete-class ()
6811 "Complete a class at point."
6813 ;; Call `idlwave-routines' to make sure the class list will be available
6815 ;; Check for the special case of completing empty string after pro/function
6816 (if (let ((case-fold-search t
))
6819 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6821 (goto-char (point-min))
6823 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6824 ;; Yank the full class specification
6825 (insert (match-string 2))
6826 ;; Do the completion, using list gathered from `idlwave-routines'
6827 (idlwave-complete-in-buffer
6828 'class
'class
(idlwave-class-alist) nil
6829 "Select a class" "class"
6830 '(lambda (list) ;; Push it to help-links if system help available
6832 (let* ((entry (idlwave-class-info x
))
6833 (link (nth 1 (assq 'link entry
))))
6834 (if link
(push (cons x link
)
6835 idlwave-completion-help-links
))
6839 (defun idlwave-attach-classes (list type show-classes
)
6840 ;; Attach the proper class list to a LIST of completion items.
6841 ;; TYPE, when 'kwd, shows classes for method keywords, when
6842 ;; 'class-tag, for class tags, and otherwise for methods.
6843 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6844 (if (or (null show-classes
) ; don't want to see classes
6845 (null class-selector
) ; not a method call
6847 (stringp class-selector
) ; the class is already known
6848 (not super-classes
))) ; no possibilities for inheritance
6849 ;; In these cases, we do not have to do anything
6851 (let* ((do-prop (and (>= show-classes
0)
6852 (>= emacs-major-version
21)))
6853 (do-buf (not (= show-classes
0)))
6854 ;; (do-dots (featurep 'xemacs))
6856 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6857 (cons class-selector super-classes
)))
6858 (max (abs show-classes
))
6859 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6860 classes nclasses class-info space
)
6864 (if (eq type
'class-tag
)
6865 ;; Just one class for tags
6868 (idlwave-class-or-superclass-with-tag class-selector x
)))
6869 ;; Multiple classes for method or method-keyword
6872 (idlwave-all-method-keyword-classes
6873 method-selector x type-selector
)
6874 (idlwave-all-method-classes x type-selector
)))
6878 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6880 (setq nclasses
(length classes
))
6881 ;; Make the separator between item and class-info
6883 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6886 ;; We do want info in the buffer
6887 (if (<= nclasses max
)
6888 (setq class-info
(concat
6890 "<" (mapconcat 'identity classes
",") ">"))
6891 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6892 (setq class-info nil
))
6894 ;; We do want properties
6895 (setq x
(copy-sequence x
))
6896 (put-text-property 0 (length x
)
6897 'help-echo
(mapconcat 'identity classes
" ")
6904 (defun idlwave-attach-method-classes (list)
6905 ;; Call idlwave-attach-classes with method parameters
6906 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6907 (defun idlwave-attach-keyword-classes (list)
6908 ;; Call idlwave-attach-classes with keyword parameters
6909 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6910 (defun idlwave-attach-class-tag-classes (list)
6911 ;; Call idlwave-attach-classes with class structure tags
6912 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6915 ;;----------------------------------------------------------------------
6916 ;;----------------------------------------------------------------------
6917 ;;----------------------------------------------------------------------
6918 ;;----------------------------------------------------------------------
6919 ;;----------------------------------------------------------------------
6921 (defun idlwave-pset (item)
6924 (defun idlwave-popup-select (ev list title
&optional sort
)
6925 "Select an item in LIST with a popup menu.
6926 TITLE is the title to put atop the popup. If SORT is non-nil,
6927 sort the list before displaying"
6928 (let ((maxpopup idlwave-max-popup-menu-items
)
6931 ((= 1 (length list
))
6932 (setq rtn
(car list
)))
6934 (if sort
(setq list
(sort list
(lambda (a b
)
6935 (string< (upcase a
) (upcase b
))))))
6937 (append (list title
)
6938 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6941 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6942 (setq resp
(get-popup-menu-response menu
))
6943 (funcall (event-function resp
) (event-object resp
)))
6945 (if sort
(setq list
(sort list
(lambda (a b
)
6946 (string< (upcase a
) (upcase b
))))))
6947 (setq menu
(cons title
6950 (mapcar (lambda(x) (cons x x
)) list
)))))
6951 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6952 (setq rtn
(x-popup-menu ev menu
))))
6955 (defun idlwave-split-menu-xemacs (menu N
)
6956 "Split the MENU into submenus of maximum length N."
6957 (if (<= (length menu
) (1+ N
))
6958 ;; No splitting needed
6960 (let* ((title (car menu
))
6961 (entries (cdr menu
))
6966 (while (and entries
(< cnt N
))
6968 nextmenu
(cons (car entries
) nextmenu
)
6969 entries
(cdr entries
)))
6970 (setq nextmenu
(nreverse nextmenu
))
6971 (setq nextmenu
(cons (format "%s...%s"
6972 (aref (car nextmenu
) 0)
6973 (aref (nth (1- cnt
) nextmenu
) 0))
6975 (setq menu
(cons nextmenu menu
)
6980 (defun idlwave-split-menu-emacs (menu N
)
6981 "Split the MENU into submenus of maximum length N."
6982 (if (<= (length (nth 1 menu
)) (1+ N
))
6983 ;; No splitting needed
6985 (let* ((title (car menu
))
6986 (entries (cdr (nth 1 menu
)))
6991 (while (and entries
(< cnt N
))
6993 nextmenu
(cons (car entries
) nextmenu
)
6994 entries
(cdr entries
)))
6995 (setq nextmenu
(nreverse nextmenu
))
6997 (setq nextmenu
(cons (format "%s...%s"
6998 (car (car nextmenu
))
6999 (car (nth (1- cnt
) nextmenu
)))
7001 (setq menu
(cons nextmenu menu
)
7004 (setq menu
(nreverse menu
))
7005 (setq menu
(cons title menu
))
7008 (defvar idlwave-completion-setup-hook nil
)
7010 (defun idlwave-scroll-completions (&optional message
)
7011 "Scroll the completion window on this frame."
7012 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
7013 (win (selected-window)))
7016 (select-window cwin
)
7019 (error (if (and (listp last-command
)
7020 (nth 2 last-command
))
7023 (eval idlwave-complete-after-success-form
))
7024 (set-window-start cwin
(point-min)))))
7025 (and message
(message "%s" message
)))
7026 (select-window win
))))
7028 (defun idlwave-display-completion-list (list &optional message beg complete
)
7029 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7030 (unless (and (get-buffer-window "*Completions*")
7031 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
7032 (move-marker idlwave-completion-mark beg
)
7033 (setq idlwave-before-completion-wconf
(current-window-configuration)))
7035 (if (featurep 'xemacs
)
7036 (idlwave-display-completion-list-xemacs
7038 (idlwave-display-completion-list-emacs list
))
7040 ;; Store a special value in `this-command'. When `idlwave-complete'
7041 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7042 (setq this-command
(list 'idlwave-display-completion-list message complete
))
7044 ;; Mark the completions buffer as created by cib
7045 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
7047 ;; Fontify the classes
7048 (if (and idlwave-completion-fontify-classes
7050 (idlwave-completion-fontify-classes))
7053 (run-hooks 'idlwave-completion-setup-hook
)
7055 ;; Display the message
7056 (message "%s" (or message
"Making completion list...done")))
7058 (defun idlwave-choose (function &rest args
)
7059 "Call FUNCTION as a completion chooser and pass ARGS to it."
7060 (let ((completion-ignore-case t
)) ; install correct value
7061 (apply function args
))
7062 (if (and (eq major-mode
'idlwave-shell-mode
)
7063 (boundp 'font-lock-mode
)
7064 (not font-lock-mode
))
7065 ;; For the shell, remove the fontification of the word before point
7066 (let ((beg (save-excursion
7067 (skip-chars-backward "a-zA-Z0-9_")
7069 (remove-text-properties beg
(point) '(face nil
))))
7070 (eval idlwave-complete-after-success-form-force
))
7072 (defun idlwave-keyboard-quit ()
7075 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
7076 (idlwave-restore-wconf-after-completion))
7079 (defun idlwave-restore-wconf-after-completion ()
7080 "Restore the old (before completion) window configuration."
7081 (and idlwave-completion-restore-window-configuration
7082 idlwave-before-completion-wconf
7083 (set-window-configuration idlwave-before-completion-wconf
)))
7085 (defun idlwave-one-key-select (sym prompt delay
)
7086 "Make the user select an element from the alist in the variable SYM.
7087 The keys of the alist are expected to be strings. The function returns the
7088 car of the selected association.
7089 To do this, PROMPT is displayed and the user must hit a letter key to
7090 select an entry. If the user does not reply within DELAY seconds, a help
7091 window with the options is displayed automatically.
7092 The key which is associated with each option is generated automatically.
7093 First, the strings are checked for preselected keys, like in \"[P]rint\".
7094 If these don't exist, a letter in the string is automatically selected."
7095 (let* ((alist (symbol-value sym
))
7096 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
7097 '(fit-window-to-buffer)))
7099 ;; First check the cache
7100 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
7101 (setq keys-alist
(get sym
:one-key-alist-cache
))
7102 ;; Need to make new list
7103 (setq keys-alist
(idlwave-make-one-key-alist alist
))
7104 (put sym
:one-key-alist-cache keys-alist
)
7105 (put sym
:one-key-alist-last alist
))
7106 ;; Display prompt and wait for quick reply
7107 (message "%s[%s]" prompt
7108 (mapconcat (lambda(x) (char-to-string (car x
)))
7111 ;; No quick reply: Show help
7112 (save-window-excursion
7113 (with-output-to-temp-buffer "*Completions*"
7118 (setq char
(read-char)))
7119 (setq char
(read-char)))
7121 ;; Return the selected result
7122 (nth 2 (assoc char keys-alist
))))
7124 ;; Used for, e.g., electric debug super-examine.
7125 (defun idlwave-make-one-key-alist (alist)
7126 "Make an alist for single key selection."
7127 (let ((l alist
) keys-alist name start char help
7129 (case-fold-search nil
))
7131 (setq name
(car (car l
))
7134 ;; First check if the configuration predetermined a key
7135 (if (string-match "\\[\\(.\\)\\]" name
)
7137 (setq char
(string-to-char (downcase (match-string 1 name
)))
7138 help
(format "%c: %s" char name
)
7139 keys-alist
(cons (list char help name
) keys-alist
))
7141 ;; Then check for capital letters
7143 (while (string-match "[A-Z]" name start
)
7144 (setq start
(match-end 0)
7145 char
(string-to-char (downcase (match-string 0 name
))))
7146 (if (not (assoc char keys-alist
))
7148 (setq help
(format "%c: %s" char
7150 (concat "[" (match-string 0 name
) "]")
7152 keys-alist
(cons (list char help name
) keys-alist
))
7154 ;; Now check for lowercase letters
7156 (while (string-match "[a-z]" name start
)
7157 (setq start
(match-end 0)
7158 char
(string-to-char (match-string 0 name
)))
7159 (if (not (assoc char keys-alist
))
7161 (setq help
(format "%c: %s" char
7163 (concat "[" (match-string 0 name
) "]")
7165 keys-alist
(cons (list char help name
) keys-alist
))
7167 ;; Bummer, nothing found! Use a stupid number
7168 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
7169 help
(format "%c: %s" char name
)
7170 keys-alist
(cons (list char help name
) keys-alist
))))
7171 (nreverse keys-alist
)))
7173 (defun idlwave-set-local (var value
&optional buffer
)
7174 "Set the buffer-local value of VAR in BUFFER to VALUE."
7176 (set-buffer (or buffer
(current-buffer)))
7177 (set (make-local-variable var
) value
)))
7179 (defun idlwave-local-value (var &optional buffer
)
7180 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7182 (set-buffer (or buffer
(current-buffer)))
7183 (and (local-variable-p var
(current-buffer))
7184 (symbol-value var
))))
7186 ;; In XEmacs, we can use :activate-callback directly to advice the
7187 ;; choose functions. We use the private keymap only for the online
7190 (defvar idlwave-completion-map nil
7191 "Keymap for completion-list-mode with idlwave-complete.")
7193 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
7194 (with-output-to-temp-buffer "*Completions*"
7195 (apply 'display-completion-list list
7196 ':activate-callback
'idlwave-default-choose-completion
7199 (set-buffer "*Completions*")
7201 (or idlwave-completion-map
7202 (setq idlwave-completion-map
7203 (idlwave-make-modified-completion-map-xemacs
7204 (current-local-map)))))))
7206 (defun idlwave-default-choose-completion (&rest args
)
7207 "Execute `default-choose-completion' and then restore the win-conf."
7208 (apply 'idlwave-choose
'default-choose-completion args
))
7210 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7211 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7212 (let ((new-map (copy-keymap old-map
)))
7213 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
7214 (define-key new-map [button3] (lambda ()
7216 (setq this-command last-command)))
7219 ;; In Emacs we also replace keybindings in the completion
7220 ;; map in order to install our wrappers.
7222 (defun idlwave-display-completion-list-emacs (list)
7223 "Display completion list and install the choose wrappers."
7224 (with-output-to-temp-buffer "*Completions*"
7225 (display-completion-list list))
7227 (set-buffer "*Completions*")
7229 (or idlwave-completion-map
7230 (setq idlwave-completion-map
7231 (idlwave-make-modified-completion-map-emacs
7232 (current-local-map)))))))
7234 (defun idlwave-make-modified-completion-map-emacs (old-map)
7235 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7236 (let ((new-map (copy-keymap old-map)))
7237 (substitute-key-definition
7238 'choose-completion 'idlwave-choose-completion new-map)
7239 (substitute-key-definition
7240 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7241 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7244 (defun idlwave-choose-completion (&rest args)
7245 "Choose the completion that point is in or next to."
7247 (apply 'idlwave-choose 'choose-completion args))
7249 (defun idlwave-mouse-choose-completion (&rest args)
7250 "Click on an alternative in the `*Completions*' buffer to choose it."
7252 (apply 'idlwave-choose 'mouse-choose-completion args))
7254 ;;----------------------------------------------------------------------
7255 ;;----------------------------------------------------------------------
7257 ;;; ------------------------------------------------------------------------
7258 ;;; Stucture parsing code, and code to manage class info
7261 ;; - Go again over the documentation how to write a completion
7262 ;; plugin. It is in self.el, but currently still very bad.
7263 ;; This could be in a separate file in the distribution, or
7264 ;; in an appendix for the manual.
7266 (defvar idlwave-struct-skip
7267 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7268 "Regexp for skipping continued blank or comment-only lines in
7271 (defvar idlwave-struct-tag-regexp
7272 (concat "[{,]" ;leading comma/brace
7273 idlwave-struct-skip ; 4 groups
7274 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7275 "[ \t]*:") ; the final colon
7276 "Regexp for structure tags.")
7278 (defun idlwave-struct-tags ()
7279 "Return a list of all tags in the structure defined at point.
7280 Point is expected just before the opening `{' of the struct definition."
7282 (let* ((borders (idlwave-struct-borders))
7288 (narrow-to-region beg end)
7289 (while (re-search-forward idlwave-struct-tag-regexp end t)
7290 ;; Check if we are still on the top level of the structure.
7291 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7293 (push (match-string-no-properties 5) tags))
7294 (goto-char (match-end 0))))
7297 (defun idlwave-find-struct-tag (tag)
7298 "Find a given TAG in the structure defined at point."
7299 (let* ((borders (idlwave-struct-borders))
7302 (case-fold-search t))
7303 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7306 (defun idlwave-struct-inherits ()
7307 "Return a list of all `inherits' names in the struct at point.
7308 Point is expected just before the opening `{' of the struct definition."
7310 (let* ((borders (idlwave-struct-borders))
7313 (case-fold-search t)
7317 (narrow-to-region beg end)
7318 (while (re-search-forward
7319 (concat "[{,]" ;leading comma/brace
7320 idlwave-struct-skip ; 4 groups
7321 "inherits" ; The INHERITS tag
7322 idlwave-struct-skip ; 4 more
7323 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7325 ;; Check if we are still on the top level of the structure.
7326 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7328 (push (match-string-no-properties 9) names))
7329 (goto-char (match-end 0))))
7332 (defun idlwave-in-structure ()
7333 "Return t if point is inside an IDL structure definition."
7334 (let ((beg (point)))
7336 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7337 (if (idlwave-find-structure-definition nil nil 'back)
7338 (let ((borders (idlwave-struct-borders)))
7339 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7340 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7342 (defun idlwave-struct-borders ()
7343 "Return the borders of the {...} after point as a cons cell."
7346 (skip-chars-forward "^{")
7348 (condition-case nil (forward-list 1)
7349 (error (goto-char beg)))
7350 (cons beg (point)))))
7352 (defun idlwave-find-structure-definition (&optional var name bound)
7353 "Search forward for a structure definition. If VAR is non-nil,
7354 search for a structure assigned to variable VAR. If NAME is non-nil,
7355 search for a named structure NAME, if a string, or a generic named
7356 structure otherwise. If BOUND is an integer, limit the search. If
7357 BOUND is the symbol `all', we search first back and then forward
7358 through the entire file. If BOUND is the symbol `back' we search only
7360 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7361 (case-fold-search t)
7362 (lim (if (integerp bound) bound nil))
7365 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7370 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7371 ;; Just a generic name
7372 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7374 (if (or (and (or (eq bound 'all) (eq bound 'back))
7375 (re-search-backward re nil t))
7376 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7378 (goto-char (match-beginning 3))
7379 (match-string-no-properties 5)))))
7381 (defvar idlwave-class-info nil)
7382 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7384 (add-hook 'idlwave-update-rinfo-hook
7385 (lambda () (setq idlwave-class-reset t)))
7386 (add-hook 'idlwave-after-load-rinfo-hook
7387 (lambda () (setq idlwave-class-info nil)))
7389 (defun idlwave-class-info (class)
7391 (if idlwave-class-info
7392 (if idlwave-class-reset
7394 idlwave-class-reset nil
7395 idlwave-class-info ; Remove any visited in a buffer
7399 (idlwave-class-file-or-buffer
7400 (or (cdr (assq 'found-in x)) (car x)))))
7404 idlwave-class-info))))
7405 ;; Info is nil, put in the system stuff to start.
7406 (setq idlwave-class-info idlwave-system-class-info)
7407 (setq list idlwave-class-info)
7408 (while (setq entry (pop list))
7409 (idlwave-sintern-class-info entry)))
7410 (setq class (idlwave-sintern-class class))
7411 (or (assq class idlwave-class-info)
7412 (progn (idlwave-scan-class-info class)
7413 (assq class idlwave-class-info)))))
7415 (defun idlwave-sintern-class-info (entry)
7416 "Sintern the class names in a class-info entry."
7417 (let ((taglist (assq 'tags entry))
7418 (inherits (assq 'inherits entry)))
7419 (setcar entry (idlwave-sintern-class (car entry) 'set))
7421 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7424 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7425 "Find class structure definition(s)
7426 If ALL-HOOK is set, find all named structure definitions in a given
7427 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7428 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7429 class/struct definition"
7430 (let ((case-fold-search t) end-lim list name)
7431 (when (re-search-forward
7432 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7435 ;; For everything there
7436 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7438 (idlwave-find-structure-definition nil t end-lim))
7439 (funcall all-hook name)))
7440 (idlwave-find-structure-definition nil (or alt-class class))))))
7443 (defun idlwave-class-file-or-buffer (class)
7444 "Find buffer visiting CLASS definition"
7445 (let* ((pro (concat (downcase class) "__define"))
7446 (file (idlwave-routine-source-file
7447 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7448 (idlwave-routines))))))
7449 (cons file (if file (idlwave-get-buffer-visiting file)))))
7452 (defun idlwave-scan-class-info (class)
7453 "Scan all class and named structure info in the class__define pro"
7454 (let* ((idlwave-auto-routine-info-updates nil)
7455 (filebuf (idlwave-class-file-or-buffer class))
7456 (file (car filebuf))
7458 (class (idlwave-sintern-class class)))
7461 (and ;; neither a regular file nor a visited buffer
7463 (not (file-regular-p file))))
7464 nil ; Cannot find the file/buffer to get any info
7466 (if buf (set-buffer buf)
7467 ;; Read the file in temporarily
7468 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7470 (unless (eq major-mode 'idlwave-mode)
7472 (insert-file-contents file))
7475 (idlwave-find-class-definition class
7476 ;; Scan all of the structures found there
7478 (let* ((this-class (idlwave-sintern-class name))
7481 (cons 'tags (idlwave-struct-tags))
7482 (cons 'inherits (idlwave-struct-inherits)))))
7483 (if (not (eq this-class class))
7484 (setq entry (nconc entry (list (cons 'found-in class)))))
7485 (idlwave-sintern-class-info entry)
7486 (push entry idlwave-class-info)))))))))
7488 (defun idlwave-class-found-in (class)
7489 "Return the FOUND-IN property of the class."
7490 (cdr (assq 'found-in (idlwave-class-info class))))
7491 (defun idlwave-class-tags (class)
7492 "Return the native tags in CLASS."
7493 (cdr (assq 'tags (idlwave-class-info class))))
7494 (defun idlwave-class-inherits (class)
7495 "Return the direct superclasses of CLASS."
7496 (cdr (assq 'inherits (idlwave-class-info class))))
7499 (defun idlwave-all-class-tags (class)
7500 "Return a list of native and inherited tags in CLASS."
7502 (apply 'append (mapcar 'idlwave-class-tags
7503 (cons class (idlwave-all-class-inherits class))))
7505 (idlwave-class-tag-reset)
7506 (error "%s" (error-message-string err)))))
7509 (defun idlwave-all-class-inherits (class)
7510 "Return a list of all superclasses of CLASS (recursively expanded).
7511 The list is cached in `idlwave-class-info' for faster access."
7513 ((not idlwave-support-inheritance) nil)
7514 ((eq class nil) nil)
7517 (let ((info (idlwave-class-info class))
7519 (if (setq entry (assq 'all-inherits info))
7521 ;; Save the depth of inheritance scan to check for circular references
7522 (let ((inherits (mapcar (lambda (x) (cons x 0))
7523 (idlwave-class-inherits class)))
7524 rtn all-inherits cl)
7526 (setq cl (pop inherits)
7527 rtn (cons (car cl) rtn)
7528 inherits (append (mapcar (lambda (x)
7529 (cons x (1+ (cdr cl))))
7530 (idlwave-class-inherits (car cl)))
7532 (if (> (cdr cl) 999)
7534 "Class scan: inheritance depth exceeded. Circular inheritance?")
7536 (setq all-inherits (nreverse rtn))
7537 (nconc info (list (cons 'all-inherits all-inherits)))
7540 (defun idlwave-entry-keywords (entry &optional record-link)
7541 "Return the flat entry keywords alist from routine-info entry.
7542 If RECORD-LINK is non-nil, the keyword text is copied and a text
7543 property indicating the link is added."
7547 (let ((file (car key-list)))
7548 (mapcar (lambda (key-cons)
7549 (let ((key (car key-cons))
7550 (link (cdr key-cons)))
7551 (when (and record-link file)
7552 (setq key (copy-sequence key))
7559 (concat idlwave-html-link-sep
7560 (number-to-string link))))
7562 (push (list key) kwds)))
7567 (defun idlwave-entry-find-keyword (entry keyword)
7568 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7572 (let ((file (car key-list))
7573 (kwd (assoc keyword (cdr key-list))))
7575 (setq kwd (cons (car kwd)
7576 (if (and file (cdr kwd))
7578 idlwave-html-link-sep
7579 (number-to-string (cdr kwd)))
7581 (throw 'exit kwd))))
7584 ;;==========================================================================
7586 ;; Completing class structure tags. This is a completion plugin.
7587 ;; The necessary taglist is constructed dynamically
7589 (defvar idlwave-current-tags-class nil)
7590 (defvar idlwave-current-class-tags nil)
7591 (defvar idlwave-current-native-class-tags nil)
7592 (defvar idlwave-sint-class-tags nil)
7593 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7594 (idlwave-new-sintern-type 'class-tag)
7595 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7596 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7598 (defun idlwave-complete-class-structure-tag ()
7599 "Complete a structure tag on a `self' argument in an object method."
7602 (case-fold-search t))
7604 ;; Check if the context is right
7605 (skip-chars-backward "a-zA-Z0-9._$")
7606 (and (< (point) (- pos 4))
7607 (looking-at "self\\.")))
7608 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7609 (super-classes (idlwave-all-class-inherits class-selector)))
7610 ;; Check if we are in a class routine
7611 (unless class-selector
7612 (error "Not in a method procedure or function"))
7613 ;; Check if we need to update the "current" class
7614 (if (not (equal class-selector idlwave-current-tags-class))
7615 (idlwave-prepare-class-tag-completion class-selector))
7616 (setq idlwave-completion-help-info
7617 (list 'idlwave-complete-class-structure-tag-help
7618 (idlwave-sintern-routine
7619 (concat class-selector "__define"))
7621 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7622 (idlwave-complete-in-buffer
7623 'class-tag 'class-tag
7624 idlwave-current-class-tags nil
7625 (format "Select a tag of class %s" class-selector)
7627 'idlwave-attach-class-tag-classes))
7628 t) ; return t to skip other completions
7631 (defun idlwave-class-tag-reset ()
7632 (setq idlwave-current-tags-class nil))
7634 (defun idlwave-prepare-class-tag-completion (class)
7635 "Find and parse the necessary class definitions for class structure tags."
7636 (setq idlwave-sint-class-tags nil)
7637 (setq idlwave-current-tags-class class)
7638 (setq idlwave-current-class-tags
7640 (list (idlwave-sintern-class-tag x 'set)))
7641 (idlwave-all-class-tags class)))
7642 (setq idlwave-current-native-class-tags
7643 (mapcar 'downcase (idlwave-class-tags class))))
7645 ;===========================================================================
7647 ;; Completing system variables and their structure fields
7648 ;; This is also a plugin.
7650 (defvar idlwave-sint-sysvars nil)
7651 (defvar idlwave-sint-sysvartags nil)
7652 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7653 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7654 (idlwave-new-sintern-type 'sysvar)
7655 (idlwave-new-sintern-type 'sysvartag)
7656 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7657 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7658 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7661 (defun idlwave-complete-sysvar-or-tag ()
7662 "Complete a system variable."
7665 (case-fold-search t))
7666 (cond ((save-excursion
7667 ;; Check if the context is right for system variable
7668 (skip-chars-backward "[a-zA-Z0-9_$]")
7669 (equal (char-before) ?!))
7670 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7671 (idlwave-complete-in-buffer 'sysvar 'sysvar
7672 idlwave-system-variables-alist nil
7673 "Select a system variable"
7675 t) ; return t to skip other completions
7677 ;; Check if the context is right for sysvar tag
7678 (skip-chars-backward "a-zA-Z0-9_$.")
7679 (and (equal (char-before) ?!)
7680 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7681 (<= (match-end 0) pos)))
7682 ;; Complete a system variable tag
7683 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7684 (entry (assq var idlwave-system-variables-alist))
7685 (tags (cdr (assq 'tags entry))))
7686 (or entry (error "!%s is not a known system variable" var))
7687 (or tags (error "System variable !%s is not a structure" var))
7688 (setq idlwave-completion-help-info
7689 (list 'idlwave-complete-sysvar-tag-help var))
7690 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7692 "Select a system variable tag"
7693 "system variable tag")
7694 t)) ; return t to skip other completions
7697 (defvar link) ;dynamic variables set by help callback
7699 (defun idlwave-complete-sysvar-help (mode word)
7700 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7701 (entry (assoc word idlwave-system-variables-alist)))
7704 (and (stringp word) entry (nth 1 (assq 'link entry))))
7706 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7707 (t (error "This should not happen")))))
7709 (defun idlwave-complete-sysvar-tag-help (mode word)
7710 (let* ((var (nth 1 idlwave-completion-help-info))
7711 (entry (assoc var idlwave-system-variables-alist))
7712 (tags (cdr (assq 'tags entry)))
7713 (main (nth 1 (assq 'link entry)))
7716 ((eq mode 'test) ; we can at least link the main
7717 (and (stringp word) entry main))
7721 (if (setq target (cdr (assoc-string word tags t)))
7722 (idlwave-substitute-link-target main target)
7723 main)))) ;; setting dynamic!!!
7724 (t (error "This should not happen")))))
7726 (defun idlwave-split-link-target (link)
7727 "Split a given link into link file and anchor."
7728 (if (string-match idlwave-html-link-sep link)
7729 (cons (substring link 0 (match-beginning 0))
7730 (string-to-number (substring link (match-end 0))))))
7732 (defun idlwave-substitute-link-target (link target)
7733 "Substitute the target anchor for the given link."
7735 (setq main-base (if (string-match "#" link)
7736 (substring link 0 (match-beginning 0))
7739 (concat main-base idlwave-html-link-sep (number-to-string target))
7742 ;; Fake help in the source buffer for class structure tags.
7743 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7746 (defvar idlwave-help-do-class-struct-tag nil)
7747 (defun idlwave-complete-class-structure-tag-help (mode word)
7749 ((eq mode 'test) ; nothing gets fontified for class tags
7752 (let (class-with found-in)
7753 (when (setq class-with
7754 (idlwave-class-or-superclass-with-tag
7755 idlwave-current-tags-class
7757 (if (assq (idlwave-sintern-class class-with)
7758 idlwave-system-class-info)
7759 (error "No help available for system class tags"))
7760 (if (setq found-in (idlwave-class-found-in class-with))
7761 (setq name (cons (concat found-in "__define") class-with))
7762 (setq name (concat class-with "__define")))))
7764 idlwave-help-do-class-struct-tag t))
7765 (t (error "This should not happen"))))
7767 (defun idlwave-class-or-superclass-with-tag (class tag)
7768 "Find and return the CLASS or one of its superclass with the
7769 associated TAG, if any."
7770 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7774 (setq cl (pop sclasses))
7775 (let ((tags (idlwave-class-tags cl)))
7777 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7779 (setq tags (cdr tags))))))))
7782 (defun idlwave-sysvars-reset ()
7783 (if (and (fboundp 'idlwave-shell-is-running)
7784 (idlwave-shell-is-running)
7785 idlwave-idlwave_routine_info-compiled)
7786 (idlwave-shell-send-command "idlwave_get_sysvars"
7787 'idlwave-process-sysvars 'hide)))
7789 (defun idlwave-process-sysvars ()
7790 (idlwave-shell-filter-sysvars)
7791 (setq idlwave-sint-sysvars nil
7792 idlwave-sint-sysvartags nil)
7793 (idlwave-sintern-sysvar-alist))
7795 (defun idlwave-sintern-sysvar-alist ()
7796 (let ((list idlwave-system-variables-alist) entry tags)
7797 (while (setq entry (pop list))
7798 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7799 (setq tags (assq 'tags entry))
7803 (cons (idlwave-sintern-sysvartag (car x) 'set)
7807 (defvar idlwave-shell-command-output)
7808 (defun idlwave-shell-filter-sysvars ()
7809 "Get any new system variables and tags."
7810 (let ((text idlwave-shell-command-output)
7812 (old idlwave-system-variables-alist)
7813 var tags type name class link old-entry)
7814 (setq idlwave-system-variables-alist nil)
7815 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7817 (setq start (match-end 0)
7818 var (match-string 1 text)
7819 tags (if (match-end 3)
7820 (idlwave-split-string (match-string 3 text))))
7821 ;; Maintain old links, if present
7822 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7823 (setq link (assq 'link old-entry))
7824 (setq idlwave-system-variables-alist
7831 (idlwave-sintern-sysvartag x)
7832 (cdr (assq 'tags old-entry))))))
7834 idlwave-system-variables-alist)))
7835 ;; Keep the old value if query was not successful
7836 (setq idlwave-system-variables-alist
7837 (or idlwave-system-variables-alist old))))
7839 (defun idlwave-completion-fontify-classes ()
7840 "Goto the *Completions* buffer and fontify the class info."
7841 (when (featurep 'font-lock)
7843 (set-buffer "*Completions*")
7845 (goto-char (point-min))
7846 (let ((buffer-read-only nil))
7847 (while (re-search-forward "\\.*<[^>]+>" nil t)
7848 (put-text-property (match-beginning 0) (match-end 0)
7849 'face 'font-lock-string-face)))))))
7851 (defun idlwave-uniquify (list)
7852 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7855 (unless (gethash x ht)
7860 (defun idlwave-after-successful-completion (type slash &optional verify)
7861 "Add `=' or `(' after successful completion of keyword and function.
7862 Restore the pre-completion window configuration if possible."
7864 ((eq type 'procedure)
7866 ((eq type 'function)
7868 ((equal idlwave-function-completion-adds-paren nil) nil)
7869 ((or (equal idlwave-function-completion-adds-paren t)
7870 (equal idlwave-function-completion-adds-paren 1))
7872 ((equal idlwave-function-completion-adds-paren 2)
7877 (if (and idlwave-keyword-completion-adds-equal
7879 (progn (insert "=") t)
7882 ;; Restore the pre-completion window configuration if this is safe.
7884 (if (or (eq verify 'force) ; force
7886 (get-buffer-window "*Completions*") ; visible
7887 (idlwave-local-value 'idlwave-completion-p
7888 "*Completions*") ; cib-buffer
7889 (eq (marker-buffer idlwave-completion-mark)
7890 (current-buffer)) ; buffer OK
7891 (equal (marker-position idlwave-completion-mark)
7893 (idlwave-restore-wconf-after-completion))
7894 (move-marker idlwave-completion-mark nil)
7895 (setq idlwave-before-completion-wconf nil))
7897 (defun idlwave-mouse-context-help (ev &optional arg)
7898 "Call `idlwave-context-help' on the clicked location."
7900 (mouse-set-point ev)
7901 (idlwave-context-help arg))
7903 (defvar idlwave-last-context-help-pos nil)
7904 (defun idlwave-context-help (&optional arg)
7905 "Display IDL Online Help on context.
7906 If point is on a keyword, help for that keyword will be shown. If
7907 point is on a routine name or in the argument list of a routine, help
7908 for that routine will be displayed. Works for system routines and
7909 keywords, it pulls up text help. For other routies and keywords,
7910 visits the source file, finding help in the header (if
7911 `idlwave-help-source-try-header' is non-nil) or the routine definition
7914 (idlwave-do-context-help arg))
7916 (defun idlwave-mouse-completion-help (ev)
7917 "Display online help about the completion at point."
7919 ;; Restore last-command for next command, to make
7920 ;; scrolling/cancelling of completions work.
7921 (setq this-command last-command)
7922 (idlwave-do-mouse-completion-help ev))
7924 (defun idlwave-routine-info (&optional arg external)
7925 "Display a routines calling sequence and list of keywords. When
7926 point is on the name a function or procedure, or in the argument list
7927 of a function or procedure, this command displays a help buffer with
7928 the information. When called with prefix arg, enforce class query.
7930 When point is on an object operator `->', display the class stored in
7931 this arrow, if any (see `idlwave-store-inquired-class'). With a
7932 prefix arg, the class property is cleared out."
7936 (if (string-match "->" (buffer-substring
7937 (max (point-min) (1- (point)))
7938 (min (+ 2 (point)) (point-max))))
7939 ;; Cursor is on an arrow
7940 (if (get-text-property (point) 'idlwave-class)
7941 ;; arrow has class property
7946 (when (looking-at ".?\\(->\\)")
7947 (remove-text-properties (match-beginning 1) (match-end 1)
7948 '(idlwave-class nil face nil))
7949 (message "Class property removed from arrow")))
7950 ;; Echo class property
7951 (message "Arrow has text property identifying object to be class %s"
7952 (get-text-property (point) 'idlwave-class)))
7953 ;; No property found
7954 (message "Arrow has no class text property"))
7956 ;; Not on an arrow...
7957 (let* ((idlwave-query-class nil)
7958 (idlwave-force-class-query (equal arg '(4)))
7959 (module (idlwave-what-module)))
7961 (apply 'idlwave-display-calling-sequence
7962 (idlwave-fix-module-if-obj_new module))
7963 (error "Don't know which calling sequence to show")))))
7965 (defun idlwave-resolve (&optional arg)
7966 "Call RESOLVE_ROUTINE on the module name at point.
7967 Like `idlwave-routine-info', this looks for a routine call at point.
7968 After confirmation in the minibuffer, it will use the shell to issue
7969 a RESOLVE call for this routine, to attempt to make it defined and its
7970 routine info available for IDLWAVE. If the routine is a method call,
7971 both `class__method' and `class__define' will be tried.
7972 With ARG, enforce query for the class of object methods."
7974 (let* ((idlwave-query-class nil)
7975 (idlwave-force-class-query (equal arg '(4)))
7976 (module (idlwave-what-module))
7977 (name (idlwave-make-full-name (nth 2 module) (car module)))
7978 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7979 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7982 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7984 (setq type (match-string 1 resolve)
7985 class (if (match-beginning 2)
7986 (match-string 3 resolve)
7988 name (match-string 4 resolve)))
7989 (if (string= (downcase type) "function")
7990 (setq kwd ",/is_function"))
7994 (idlwave-shell-send-command
7995 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7996 'idlwave-update-routine-info
7999 (idlwave-shell-send-command
8000 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
8001 (list 'idlwave-shell-send-command
8002 (format "resolve_routine,'%s__%s'%s"
8003 (downcase class) (downcase name) kwd)
8004 '(idlwave-update-routine-info)
8007 (defun idlwave-find-module-this-file ()
8009 (idlwave-find-module '(4)))
8011 (defun idlwave-find-module (&optional arg)
8012 "Find the source code of an IDL module.
8013 Works for modules for which IDLWAVE has routine info available. The
8014 function offers as default the module name `idlwave-routine-info'
8015 would use. With ARG limit to this buffer. With two prefix ARG's
8016 force class query for object methods."
8018 (let* ((idlwave-query-class nil)
8019 (idlwave-force-class-query (equal arg '(16)))
8020 (this-buffer (equal arg '(4)))
8021 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
8023 (concat (idlwave-make-full-name
8024 (nth 2 module) (car module))
8025 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8031 (if (eq 'system (car-safe (nth 3 x)))
8032 ;; Take out system routines with no source.
8035 (concat (idlwave-make-full-name
8037 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8039 (idlwave-save-buffer-update)
8040 (idlwave-routines))))))
8041 (name (idlwave-completing-read
8042 (if (or (not this-buffer)
8043 (assoc default list))
8044 (format "Module (Default %s): " default)
8045 (format "Module in this file: "))
8048 (if (string-match "\\`\\s-*\\'" name)
8049 ;; Nothing, use the default.
8050 (setq name default))
8051 (if (string-match "<[fp]>" name)
8052 (setq type (substring name -2 -1)
8053 name (substring name 0 -3)))
8054 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8055 (setq class (match-string 1 name)
8056 name (match-string 2 name)))
8057 (setq name (idlwave-sintern-routine-or-method name class)
8058 class (idlwave-sintern-class class)
8059 type (cond ((equal type "f") 'fun)
8060 ((equal type "p") 'pro)
8062 (idlwave-do-find-module name type class nil this-buffer)))
8064 (defun idlwave-do-find-module (name type class
8065 &optional force-source this-buffer)
8066 (let ((name1 (idlwave-make-full-name class name))
8068 (buf (current-buffer))
8071 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8073 source (or force-source (nth 3 entry))
8074 name2 (if (nth 2 entry)
8075 (idlwave-make-full-name (nth 2 entry) name)
8078 (setq file (idlwave-routine-source-file source)))
8079 (unless file ; Try to find it on the path.
8081 (idlwave-expand-lib-file-name
8083 (format "%s__define.pro" (downcase class))
8084 (format "%s.pro" (downcase name))))))
8086 ((or (null name) (equal name ""))
8088 ((eq (car source) 'system)
8089 (error "Source code for system routine %s is not available"
8091 ((or (not file) (not (file-regular-p file)))
8092 (error "Source code for routine %s is not available"
8095 (when (not this-buffer)
8097 (idlwave-find-file-noselect file 'find))
8098 (pop-to-buffer buf1 t))
8099 (goto-char (point-max))
8100 (let ((case-fold-search t))
8101 (if (re-search-backward
8102 (concat "^[ \t]*\\<"
8103 (cond ((eq type 'fun) "function")
8104 ((eq type 'pro) "pro")
8105 (t "\\(pro\\|function\\)"))
8107 (regexp-quote (downcase name2))
8110 (goto-char (match-beginning 0))
8113 (error "Could not find routine %s" name2)))))))
8115 (defun idlwave-what-module ()
8116 "Return a default module for stuff near point.
8117 Used by `idlwave-routine-info' and `idlwave-find-module'."
8119 (if (let ((case-fold-search t))
8121 (idlwave-beginning-of-statement)
8122 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8123 ;; This is a function or procedure definition statement
8124 ;; We return the defined routine as module.
8126 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8127 (match-string-no-properties 2))
8128 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8129 (idlwave-sintern-class (match-string 3)))
8131 ;; Not a definition statement - analyze precise position.
8132 (let* ((where (idlwave-where))
8134 (pro (car (nth 0 where)))
8135 (func (car (nth 1 where)))
8136 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8137 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8141 ((and (eq cw 'procedure)
8142 (not (equal this-word "")))
8143 (setq this-word (idlwave-sintern-routine-or-method
8144 this-word (nth 2 (nth 3 where))))
8145 (list this-word 'pro
8146 (idlwave-determine-class
8147 (cons this-word (cdr (nth 3 where)))
8149 ((and (eq cw 'function)
8150 (not (equal this-word ""))
8151 (or (eq next-char ?\() ; exclude arrays, vars.
8152 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8153 (setq this-word (idlwave-sintern-routine-or-method
8154 this-word (nth 2 (nth 3 where))))
8155 (list this-word 'fun
8156 (idlwave-determine-class
8157 (cons this-word (cdr (nth 3 where)))
8159 ((and (memq cw '(function-keyword procedure-keyword))
8160 (not (equal this-word ""))
8161 (eq next-char ?\()) ; A function!
8162 (setq this-word (idlwave-sintern-routine this-word))
8163 (list this-word 'fun nil))
8165 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8167 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8170 (defun idlwave-what-module-find-class ()
8171 "Call idlwave-what-module and find the inherited class if necessary."
8172 (let* ((module (idlwave-what-module))
8173 (class (nth 2 module))
8175 (if (and (= (length module) 3)
8179 (apply 'idlwave-find-inherited-class module))
8182 (defun idlwave-find-inherited-class (name type class)
8183 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8184 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8189 (defun idlwave-fix-module-if-obj_new (module)
8190 "Check if MODULE points to obj_new.
8191 If yes, and if the cursor is in the keyword region, change to the
8192 appropriate Init method."
8193 (let* ((name (car module))
8195 (case-fold-search t)
8197 (if (and (stringp name)
8198 (equal (downcase name) "obj_new")
8200 (idlwave-beginning-of-statement)
8201 (setq string (buffer-substring (point) pos))
8202 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8205 (class (match-string 1 string)))
8206 (setq module (list (idlwave-sintern-method "Init")
8208 (idlwave-sintern-class class)))))
8211 (defun idlwave-fix-keywords (name type class keywords
8212 &optional super-classes system)
8213 "Update a list of keywords.
8214 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8215 from all classes if class equals t. If SYSTEM is non-nil, don't
8216 demand _EXTRA in the keyword list."
8217 (let ((case-fold-search t))
8219 ;; If this is the OBJ_NEW function, try to figure out the class and use
8220 ;; the keywords from the corresponding INIT method.
8221 (if (and (equal (upcase name) "OBJ_NEW")
8222 (or (eq major-mode 'idlwave-mode)
8223 (eq major-mode 'idlwave-shell-mode)))
8224 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8225 (string (buffer-substring bos (point)))
8226 (case-fold-search t)
8228 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8230 (setq class (idlwave-sintern-class (match-string 1 string)))
8231 (setq idlwave-current-obj_new-class class)
8234 (idlwave-entry-keywords
8236 (idlwave-sintern-method "INIT")
8239 (idlwave-routines)) 'do-link))))))
8241 ;; If the class is `t', combine all keywords of all methods NAME
8243 (mapc (lambda (entry)
8245 (nth 2 entry) ; non-nil class
8246 (eq (nth 1 entry) type) ; correct type
8249 (idlwave-entry-keywords entry 'do-link)))))
8250 (idlwave-all-assq name (idlwave-routines)))
8251 (setq keywords (idlwave-uniquify keywords)))
8253 ;; If we have inheritance, add all keywords from superclasses, if
8254 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8257 idlwave-keyword-class-inheritance
8261 (assq (idlwave-sintern-keyword "_extra") keywords)
8262 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8263 ;; Check if one of the keyword-class regexps matches the name
8264 (let ((regexps idlwave-keyword-class-inheritance) re)
8266 (while (setq re (pop regexps))
8267 (if (string-match re name) (throw 'exit t))))))
8269 (loop for entry in (idlwave-routines) do
8270 (and (nth 2 entry) ; non-nil class
8271 (memq (nth 2 entry) super-classes) ; an inherited class
8272 (eq (nth 1 entry) type) ; correct type
8273 (eq (car entry) name) ; correct name
8274 (mapc (lambda (k) (add-to-list 'keywords k))
8275 (idlwave-entry-keywords entry 'do-link))))
8276 (setq keywords (idlwave-uniquify keywords)))
8278 ;; Return the final list
8281 (defun idlwave-expand-keyword (keyword module)
8282 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8283 KEYWORD may be an exact match or an abbreviation of a keyword.
8284 If the match is exact, KEYWORD itself is returned, even if there may be other
8285 keywords of which KEYWORD is an abbreviation. This is necessary because some
8286 system routines have keywords which are prefixes of other keywords.
8287 If KEYWORD is an abbreviation of several keywords, a list of all possible
8288 completions is returned.
8289 If the abbreviation was unique, the correct keyword is returned.
8290 If it cannot be a keyword, the function return nil.
8291 If we do not know about MODULE, just return KEYWORD literally."
8292 (let* ((name (car module))
8293 (type (nth 1 module))
8294 (class (nth 2 module))
8295 (kwd (idlwave-sintern-keyword keyword))
8296 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8297 (kwd-alist (idlwave-entry-keywords entry))
8298 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8299 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8300 (completion-ignore-case t)
8302 (cond ((assq kwd kwd-alist)
8304 ((setq candidates (all-completions kwd kwd-alist))
8305 (if (= (length candidates) 1)
8309 ;; Inheritance may cause this keyword to be correct
8312 ;; We do know the function, which does not have the keyword.
8315 ;; We do not know the function, so this just might be a correct
8316 ;; keyword - return it as it is.
8319 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8320 (defvar idlwave-rinfo-map (make-sparse-keymap))
8321 (define-key idlwave-rinfo-mouse-map
8322 (if (featurep 'xemacs) [button2] [mouse-2])
8323 'idlwave-mouse-active-rinfo)
8324 (define-key idlwave-rinfo-mouse-map
8325 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8326 'idlwave-mouse-active-rinfo-shift)
8327 (define-key idlwave-rinfo-mouse-map
8328 (if (featurep 'xemacs) [button3] [mouse-3])
8329 'idlwave-mouse-active-rinfo-right)
8330 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8331 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8332 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8333 (defvar idlwave-popup-source nil)
8334 (defvar idlwave-rinfo-marker (make-marker))
8336 (defun idlwave-quit-help ()
8338 (let ((ri-window (get-buffer-window "*Help*"))
8339 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8340 (when (and olh-window
8341 (fboundp 'idlwave-help-quit))
8342 (select-window olh-window)
8343 (idlwave-help-quit))
8344 (when (window-live-p ri-window)
8345 (delete-window ri-window))))
8347 (defun idlwave-display-calling-sequence (name type class
8348 &optional initial-class)
8349 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8350 (let* ((initial-class (or initial-class class))
8351 (entry (or (idlwave-best-rinfo-assq name type class
8353 (idlwave-rinfo-assq name type class
8354 idlwave-unresolved-routines)))
8355 (name (or (car entry) name))
8356 (class (or (nth 2 entry) class))
8357 (superclasses (idlwave-all-class-inherits initial-class))
8358 (twins (idlwave-routine-twins entry))
8359 (dtwins (idlwave-study-twins twins))
8361 (system (eq (car (nth 3 entry)) 'system))
8362 (calling-seq (nth 4 entry))
8363 (keywords (idlwave-entry-keywords entry 'do-link))
8364 (html-file (car (nth 5 entry)))
8366 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8368 "Button2/3: Online Help")
8370 "Button2: Jump to source and back | Button3: Source in Help window.")
8372 "Button2: Display info about same method in superclass")
8374 (data (list name type class (current-buffer) nil initial-class))
8375 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8376 (face 'idlwave-help-link)
8377 beg props win cnt total)
8378 ;; Fix keywords, but don't add chained super-classes, since these
8379 ;; are shown separately for that super-class
8380 (setq keywords (idlwave-fix-keywords name type class keywords))
8383 (error "No %s %s known %s" type name
8384 (if initial-class (concat "in class " initial-class) "")))
8385 ((or (null name) (equal name ""))
8386 (error "No function or procedure call at point"))
8388 (error "Calling sequence of %s %s not available" type name))
8391 (move-marker idlwave-rinfo-marker (point))
8392 (set-buffer (get-buffer-create "*Help*"))
8393 (use-local-map idlwave-rinfo-map)
8394 (setq buffer-read-only nil)
8396 (set (make-local-variable 'idlwave-popup-source) nil)
8397 (set (make-local-variable 'idlwave-current-obj_new-class)
8398 idlwave-current-obj_new-class)
8400 (setq props (list 'mouse-face 'highlight
8401 km-prop idlwave-rinfo-mouse-map
8402 'help-echo help-echo-class
8403 'data (cons 'class data)))
8404 (let ((classes (cons initial-class superclasses)) c)
8405 (insert "Classes: ")
8406 (while (setq c (pop classes))
8410 (if (equal (downcase c) (downcase class))
8411 (add-text-properties beg (point) (list 'face 'bold))
8412 ;; If Method exists in a different class link it
8413 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8414 (add-text-properties beg (point) props))))
8416 (setq props (list 'mouse-face 'highlight
8417 km-prop idlwave-rinfo-mouse-map
8418 'help-echo help-echo-use
8419 'data (cons 'usage data)))
8420 (if html-file (setq props (append (list 'face face 'link html-file)
8425 (format calling-seq class name class name class name)
8426 (format calling-seq name name name name))
8428 (add-text-properties beg (point) props)
8430 (insert "Keywords:")
8432 (insert " No keywords accepted.")
8436 (if (>= (+ col 1 (length (car x)))
8443 ;; Relevant keywords already have link property attached
8444 props (list 'mouse-face 'highlight
8445 km-prop idlwave-rinfo-mouse-map
8446 'data (cons 'keyword data)
8447 'help-echo help-echo-kwd
8449 (if system (setq props (append (list 'face face) props)))
8451 (add-text-properties beg (point) props)
8452 (setq col (+ col 1 (length (car x)))))
8455 (setq cnt 1 total (length all))
8456 ;; Here entry is (key file (list of type-conses))
8457 (while (setq entry (pop all))
8458 (setq props (list 'mouse-face 'highlight
8459 km-prop idlwave-rinfo-mouse-map
8460 'help-echo help-echo-src
8461 'source (list (car (car (nth 2 entry))) ;type
8464 (cdr (car (nth 2 entry))))
8465 'data (cons 'source data)))
8466 (idlwave-insert-source-location
8469 (if (> total 1) "Sources:" "Source:")
8471 (if (> total 1) "- " ""))
8474 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8475 ;; No more source lines, please
8477 "\n Source information truncated to %d entries."
8478 idlwave-rinfo-max-source-lines))
8480 (goto-char (point-min))
8481 (setq buffer-read-only t))
8482 (display-buffer "*Help*")
8483 (if (and (setq win (get-buffer-window "*Help*"))
8484 idlwave-resize-routine-help-window)
8486 (let ((ww (selected-window)))
8490 (enlarge-window (- (/ (frame-height) 2)
8492 (shrink-window-if-larger-than-buffer))
8493 (select-window ww)))))))))
8495 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8496 "Insert a source location into the routine info buffer.
8497 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
8499 (let* ((key (car entry))
8500 (file (nth 1 entry))
8501 (types (nth 2 entry))
8502 (shell-flag (assq 'compiled types))
8503 (buffer-flag (assq 'buffer types))
8504 (user-flag (assq 'user types))
8505 (lib-flag (assq 'lib types))
8506 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8507 (and user-flag (idlwave-count-memq 'user types))
8508 (and lib-flag (idlwave-count-memq 'lib types))
8522 (insert "Builtin "))
8524 ((and (not file) shell-flag)
8525 (insert "Unresolved"))
8530 ((idlwave-syslib-p file)
8531 (if (string-match "obsolete" (file-name-directory file))
8532 (insert "Obsolete ")
8533 (insert "SystemLib ")))
8535 ;; New special syntax: taken directly from routine-info for
8536 ;; library catalog routines
8537 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8538 (insert (format "%-10s" special)))
8540 ;; Old special syntax: a matching regexp
8541 ((setq special (idlwave-special-lib-test file))
8542 (insert (format "%-10s" special)))
8544 ;; Catch-all with file
8545 ((idlwave-lib-p file) (insert "Library "))
8548 (t (insert "Other ")))
8553 (if lib-flag "L" "-")
8554 (if user-flag "C" "-")
8555 (if shell-flag "S" "-")
8556 (if buffer-flag "B" "-")
8560 (insert (format "(%dx) " ndupl))
8561 (add-text-properties beg (point) (list 'face 'bold)))
8562 (when (and file (not (equal file "")))
8564 (insert (apply 'abbreviate-file-name
8565 (if (featurep 'xemacs) (list file t) (list file))))
8567 (add-text-properties beg (point) file-props)))))
8569 (defun idlwave-special-lib-test (file)
8570 "Check the path of FILE against the regexps which define special libs.
8571 Return the name of the special lib if there is a match."
8572 (let ((alist idlwave-special-lib-alist)
8576 (while (setq entry (pop alist))
8577 (if (string-match (car entry) file)
8578 (setq rtn (cdr entry)
8583 (defun idlwave-mouse-active-rinfo-right (ev)
8585 (idlwave-mouse-active-rinfo ev 'right))
8587 (defun idlwave-mouse-active-rinfo-shift (ev)
8589 (idlwave-mouse-active-rinfo ev nil 'shift))
8591 (defun idlwave-active-rinfo-space ()
8593 (idlwave-mouse-active-rinfo nil 'right))
8595 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8596 "Does the mouse actions in the routine info buffer.
8597 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8600 (if ev (mouse-set-point ev))
8601 (let (data id name type class buf bufwin source link keyword
8603 (setq data (get-text-property (point) 'data)
8604 source (get-text-property (point) 'source)
8605 keyword (get-text-property (point) 'keyword)
8606 link (get-text-property (point) 'link)
8608 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8610 initial-class (nth 6 data)
8611 word (idlwave-this-word)
8612 bufwin (get-buffer-window buf t))
8614 (cond ((eq id 'class) ; Switch class being displayed
8615 (if (window-live-p bufwin) (select-window bufwin))
8616 (idlwave-display-calling-sequence
8617 (idlwave-sintern-method name)
8618 type (idlwave-sintern-class word)
8620 ((eq id 'usage) ; Online help on this routine
8621 (idlwave-online-help link name type class))
8622 ((eq id 'source) ; Source in help or buffer
8624 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8625 (idlwave-help-source-try-header nil)
8626 ;; Fake idlwave-routines so help will find the right entry
8628 (list (list name type class source ""))))
8629 (idlwave-help-get-special-help name type class nil))
8630 ;; Otherwise just pop to the source
8631 (setq idlwave-popup-source (not idlwave-popup-source))
8632 (if idlwave-popup-source
8634 (idlwave-do-find-module name type class source)
8636 (setq idlwave-popup-source nil)
8637 (if (window-live-p bufwin) (select-window bufwin))
8638 (error (nth 1 err))))
8640 (select-window bufwin)
8641 (pop-to-buffer buf))
8642 (goto-char (marker-position idlwave-rinfo-marker)))))
8645 (idlwave-online-help link name type class keyword)
8646 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8648 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8649 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8650 (let ((bwin (get-buffer-window buffer)))
8651 (if idlwave-complete-empty-string-as-lower-case
8652 (setq keyword (downcase keyword)))
8654 (select-window bwin)
8655 (pop-to-buffer buffer)
8656 (setq bwin (get-buffer-window buffer)))
8657 (if (eq (preceding-char) ?/)
8659 (unless (save-excursion
8661 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8662 (min (- (point) 100) (point-min)) t))
8664 (if shift (insert "/"))
8666 (if (and (not shift)
8667 idlwave-keyword-completion-adds-equal)
8670 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8671 "List the load path shadows of all routines defined in current buffer."
8674 (if (eq major-mode 'idlwave-mode)
8675 (idlwave-list-load-path-shadows
8676 nil (idlwave-update-current-buffer-info 'save-buffer)
8677 "in current buffer")
8678 (error "Current buffer is not in idlwave-mode")))
8680 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8681 "List the load path shadows of all routines compiled under the shell.
8682 This is very useful for checking an IDL application. Just compile the
8683 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8684 routines and update IDLWAVE internal info. Then check for shadowing
8688 ((or (not (fboundp 'idlwave-shell-is-running))
8689 (not (idlwave-shell-is-running)))
8690 (error "Shell is not running"))
8691 ((null idlwave-compiled-routines)
8692 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8694 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8697 (defun idlwave-list-all-load-path-shadows (&optional arg)
8698 "List the load path shadows of all routines known to IDLWAVE."
8700 (idlwave-list-load-path-shadows nil nil "globally"))
8702 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8703 "List the routines which are defined multiple times.
8704 Search the information IDLWAVE has about IDL routines for multiple
8706 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8708 When IDL hits a routine call which is not defined, it will search on
8709 the load path in order to find a definition. The output of this
8710 command can be used to detect possible name clashes during this process."
8711 (idlwave-routines) ; Make sure everything is loaded.
8712 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8714 "You don't have any user or library catalogs. Continue anyway? ")
8716 (let* ((routines (append idlwave-system-routines
8717 idlwave-compiled-routines
8718 idlwave-library-catalog-routines
8719 idlwave-user-catalog-routines
8720 idlwave-buffer-routines
8722 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8723 (keymap (make-sparse-keymap))
8724 (props (list 'mouse-face 'highlight
8726 'help-echo "Mouse2: Find source"))
8727 (nroutines (length (or special-routines routines)))
8728 (step (/ nroutines 100))
8731 (idlwave-sort-prefer-buffer-info nil)
8732 routine twins dtwins twin done props1 lroutines)
8734 (if special-routines
8735 ;; Just looking for shadows of a few special routines
8736 (setq lroutines routines
8737 routines special-routines))
8739 (message "Sorting routines...")
8740 (setq routines (sort routines
8742 (string< (downcase (idlwave-make-full-name
8744 (downcase (idlwave-make-full-name
8745 (nth 2 b) (car b)))))))
8746 (message "Sorting routines...done")
8748 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8751 (mouse-set-point ev)
8752 (apply 'idlwave-do-find-module
8753 (get-text-property (point) 'find-args))))
8754 (define-key keymap [(return)]
8757 (apply 'idlwave-do-find-module
8758 (get-text-property (point) 'find-args))))
8759 (message "Compiling list...( 0%%)")
8761 (set-buffer (get-buffer-create "*Shadows*"))
8762 (setq buffer-read-only nil)
8764 (while (setq routine (pop routines))
8765 (if (= (mod (setq n (1+ n)) step) 0)
8766 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8768 ;; Get a list of all twins
8769 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8770 (if (memq routine done)
8772 (setq dtwins (idlwave-study-twins twins)))
8773 ;; Mark all twins as dealt with
8774 (setq done (append twins done))
8775 (when (or (> (length dtwins) 1)
8776 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8777 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8778 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8780 (insert (format "\n%s%s"
8781 (idlwave-make-full-name (nth 2 routine)
8783 (if (eq (nth 1 routine) 'fun) "()" "")))
8784 (while (setq twin (pop dtwins))
8785 (setq props1 (append (list 'find-args
8786 (list (nth 0 routine)
8790 (idlwave-insert-source-location "\n - " twin props1))))
8791 (goto-char (point-min))
8792 (setq buffer-read-only t))
8793 (setq loc (or loc ""))
8796 (display-buffer (get-buffer "*Shadows*"))
8797 (message "%d case%s of shadowing found %s"
8798 cnt (if (= cnt 1) "" "s") loc))
8799 (message "No shadowing conflicts found %s" loc))))
8801 (defun idlwave-print-source (routine)
8802 (let* ((source (nth 3 routine))
8803 (stype (car source))
8804 (sfile (idlwave-routine-source-file source)))
8805 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8806 (if (and (eq stype 'compiled)
8807 (or (not (stringp sfile))
8808 (not (string-match "\\S-" sfile))))
8809 (setq stype 'unresolved))
8810 (princ (format " %-10s %s\n"
8812 (if sfile sfile "No source code available")))))
8814 (defun idlwave-routine-twins (entry &optional list)
8815 "Return all twin entries of ENTRY in LIST.
8816 LIST defaults to `idlwave-routines'.
8817 Twin entries are those which have the same name, type, and class.
8818 ENTRY will also be returned, as the first item of this list."
8819 (let* ((name (car entry))
8820 (type (nth 1 entry))
8821 (class (nth 2 entry))
8822 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8824 (while (setq candidate (pop candidates))
8825 (if (and (not (eq candidate entry))
8826 (eq type (nth 1 candidate))
8827 (eq class (nth 2 candidate)))
8828 (push candidate twins)))
8829 (if (setq candidate (idlwave-rinfo-assq name type class
8830 idlwave-unresolved-routines))
8831 (push candidate twins))
8832 (cons entry (nreverse twins))))
8834 (defun idlwave-study-twins (entries)
8835 "Return dangerous twins of first entry in ENTRIES.
8836 Dangerous twins are routines with same name, but in different files on
8837 the load path. If a file is in the system library and has an entry in
8838 the `idlwave-system-routines' list, we omit the latter as
8839 non-dangerous because many IDL routines are implemented as library
8840 routines, and may have been scanned."
8841 (let* ((entry (car entries))
8842 (name (car entry)) ;
8843 (type (nth 1 entry)) ; Must be bound for
8844 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8846 source type type-cons file alist syslibp key)
8847 (while (setq entry (pop entries))
8849 (setq source (nth 3 entry)
8851 type-cons (cons type (nth 3 source))
8852 file (idlwave-routine-source-file source))
8854 ;; Make KEY to index entry properly
8855 (setq key (cond ((eq type 'system) type)
8856 (file (file-truename file))
8859 ;; Check for an entry in the system library
8862 (idlwave-syslib-p file))
8865 ;; If there's more than one matching entry for the same file, just
8866 ;; append the type-cons to the type list.
8867 (if (setq entry (assoc key alist))
8868 (push type-cons (nth 2 entry))
8869 (push (list key file (list type-cons)) alist)))
8871 (setq alist (nreverse alist))
8874 ;; File is in system *library* - remove any 'system entry
8875 (setq alist (delq (assq 'system alist) alist)))
8877 ;; If 'system remains and we've scanned the syslib, it's a builtin
8878 ;; (rather than a !DIR/lib/.pro file bundled as source).
8879 (when (and (idlwave-syslib-scanned-p)
8880 (setq entry (assoc 'system alist)))
8881 (setcar entry 'builtin))
8882 (sort alist 'idlwave-routine-twin-compare)))
8886 (defvar idlwave-sort-prefer-buffer-info t
8887 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8889 (defmacro idlwave-xor (a b)
8893 (defun idlwave-routine-entry-compare (a b)
8894 "Compare two routine info entries for sortiung. This is the general case.
8895 It first compates class, names, and type. If it turns out that A and B
8896 are twins (same name, class, and type), calls another routine which
8897 compares twins on the basis of their file names and path locations."
8898 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8900 ((not (equal (idlwave-downcase-safe class)
8901 (idlwave-downcase-safe (nth 2 b))))
8903 (cond ((null (nth 2 b)) nil)
8905 (t (string< (downcase class) (downcase (nth 2 b))))))
8906 ((not (equal (downcase name) (downcase (car b))))
8908 (string< (downcase name) (downcase (car b))))
8909 ((not (eq type (nth 1 b)))
8911 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8913 ;; A and B are twins - so the decision is more complicated.
8914 ;; Call twin-compare with the proper arguments.
8915 (idlwave-routine-entry-compare-twins a b)))))
8917 (defun idlwave-routine-entry-compare-twins (a b)
8918 "Compare two routine entries, under the assumption that they are
8919 twins. This basically calls `idlwave-routine-twin-compare' with the
8921 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8926 (afile (idlwave-routine-source-file asrc))
8927 (bfile (idlwave-routine-source-file bsrc)))
8928 (idlwave-routine-twin-compare
8930 (list (file-truename afile) afile (list atype))
8931 (list atype afile (list atype)))
8933 (list (file-truename bfile) bfile (list btype))
8934 (list btype bfile (list btype))))
8937 (defun idlwave-routine-twin-compare (a b)
8938 "Compare two routine twin entries for sorting.
8939 In here, A and B are not normal routine info entries, but special
8940 lists (KEY FILENAME (TYPES...)).
8941 This expects NAME TYPE CLASS to be bound to the right values."
8942 (let* (;; Dis-assemble entries
8943 (akey (car a)) (bkey (car b))
8944 (afile (nth 1 a)) (bfile (nth 1 b))
8945 (atypes (nth 2 a)) (btypes (nth 2 b))
8947 (asysp (memq akey '(builtin system)))
8948 (bsysp (memq bkey '(builtin system)))
8949 ;; Compiled routines?
8950 (acompp (memq 'compiled atypes))
8951 (bcompp (memq 'compiled btypes))
8953 (aunresp (or (eq akey 'unresolved)
8954 (and acompp (not afile))))
8955 (bunresp (or (eq bkey 'unresolved)
8956 (and bcompp (not bfile))))
8957 ;; Buffer info available?
8958 (abufp (memq 'buffer atypes))
8959 (bbufp (memq 'buffer btypes))
8961 (tpath-alist (idlwave-true-path-alist))
8962 (apathp (and (stringp akey)
8963 (assoc (file-name-directory akey) tpath-alist)))
8964 (bpathp (and (stringp bkey)
8965 (assoc (file-name-directory bkey) tpath-alist)))
8966 ;; How early on search path? High number means early since we
8967 ;; measure the tail of the path list
8968 (anpath (length (memq apathp tpath-alist)))
8969 (bnpath (length (memq bpathp tpath-alist)))
8970 ;; Look at file names
8971 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8972 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8973 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8974 (regexp-quote (downcase class))
8975 (regexp-quote (downcase name)))
8976 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8977 ;; Is file name derived from the routine name?
8978 ;; Method file or class definition file?
8979 (anamep (string-match fname-re aname))
8980 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8981 (bnamep (string-match fname-re bname))
8982 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8984 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8985 ;; doesn't it? The difficult stuff is hidden above...
8987 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8988 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8989 ((and idlwave-sort-prefer-buffer-info
8990 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8991 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8992 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8993 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8994 ((and class anamep bnamep ; both file names match ->
8995 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8996 ((> anpath bnpath) t) ; Who is first on path?
8997 (t nil)))) ; Default
8999 (defun idlwave-routine-source-file (source)
9001 (expand-file-name (nth 1 source) (nth 2 source))
9004 (defun idlwave-downcase-safe (string)
9005 "Donwcase if string, else return unchanged."
9006 (if (stringp string)
9010 (defun idlwave-count-eq (elt list)
9011 "How often is ELT in LIST?"
9012 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9014 (defun idlwave-count-memq (elt alist)
9015 "How often is ELT a key in ALIST?"
9016 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9018 (defun idlwave-syslib-p (file)
9019 "Non-nil if FILE is in the system library."
9020 (let* ((true-syslib (file-name-as-directory
9022 (expand-file-name "lib" (idlwave-sys-dir)))))
9023 (true-file (file-truename file)))
9024 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9026 (defun idlwave-lib-p (file)
9027 "Non-nil if file is in the library"
9028 (let ((true-dir (file-name-directory (file-truename file))))
9029 (assoc true-dir (idlwave-true-path-alist))))
9031 (defun idlwave-path-alist-add-flag (list-entry flag)
9032 "Add a flag to the path list entry, if not set."
9033 (let ((flags (cdr list-entry)))
9034 (add-to-list 'flags flag)
9035 (setcdr list-entry flags)))
9037 (defun idlwave-path-alist-remove-flag (list-entry flag)
9038 "Remove a flag to the path list entry, if set."
9039 (let ((flags (delq flag (cdr list-entry))))
9040 (setcdr list-entry flags)))
9042 (defun idlwave-true-path-alist ()
9043 "Return `idlwave-path-alist' alist with true-names.
9044 Info is cached, but relies on the functions setting `idlwave-path-alist'
9045 to reset the variable `idlwave-true-path-alist' to nil."
9046 (or idlwave-true-path-alist
9047 (setq idlwave-true-path-alist
9048 (mapcar (lambda(x) (cons
9049 (file-name-as-directory
9051 (directory-file-name
9054 idlwave-path-alist))))
9056 (defun idlwave-syslib-scanned-p ()
9057 "Non-nil if the system lib file !DIR/lib has been scanned."
9058 (let* ((true-syslib (file-name-as-directory
9060 (expand-file-name "lib" (idlwave-sys-dir))))))
9061 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9063 ;; ----------------------------------------------------------------------------
9065 ;; Online Help display
9068 ;; ----------------------------------------------------------------------------
9070 ;; Additions for use with imenu.el and func-menu.el
9071 ;; (pop-up a list of IDL units in the current file).
9074 (defun idlwave-prev-index-position ()
9075 "Search for the previous procedure or function.
9076 Return nil if not found. For use with imenu.el."
9079 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9080 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9083 (defun idlwave-unit-name ()
9084 "Return the unit name.
9085 Assumes that point is at the beginning of the unit as found by
9086 `idlwave-prev-index-position'."
9089 (let ((begin (point)))
9091 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9092 (if (fboundp 'buffer-substring-no-properties)
9093 (buffer-substring-no-properties begin (point))
9094 (buffer-substring begin (point)))))
9096 (defalias 'idlwave-function-menu
9099 (require 'func-menu)
9101 (error (condition-case nil
9107 ;; Here we hack func-menu.el in order to support this new mode.
9108 ;; The latest versions of func-menu.el already have this stuff in, so
9109 ;; we hack only if it is not already there.
9110 (when (fboundp 'eval-after-load)
9111 (eval-after-load "func-menu"
9113 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9114 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9115 (setq fume-function-name-regexp-alist
9116 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9117 fume-function-name-regexp-alist)))
9118 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9119 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9120 (setq fume-find-function-name-method-alist
9121 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9122 fume-find-function-name-method-alist))))))
9124 (defun idlwave-edit-in-idlde ()
9125 "Edit the current file in IDL Development environment."
9127 (start-process "idldeclient" nil
9128 idlwave-shell-explicit-file-name "-c" "-e"
9129 (buffer-file-name)))
9131 (defvar idlwave-help-use-assistant)
9132 (defun idlwave-launch-idlhelp ()
9133 "Start the IDLhelp application."
9135 (if idlwave-help-use-assistant
9136 (idlwave-help-assistant-raise)
9137 (start-process "idlhelp" nil idlwave-help-application)))
9139 ;; Menus - using easymenu.el
9140 (defvar idlwave-mode-menu-def
9142 ["PRO/FUNC menu" idlwave-function-menu t]
9144 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9145 ["Subprogram End" idlwave-end-of-subprogram t]
9146 ["Block Start" idlwave-beginning-of-block t]
9147 ["Block End" idlwave-end-of-block t]
9148 ["Up Block" idlwave-backward-up-block t]
9149 ["Down Block" idlwave-down-block t]
9150 ["Skip Block Backward" idlwave-backward-block t]
9151 ["Skip Block Forward" idlwave-forward-block t])
9153 ["Subprogram" idlwave-mark-subprogram t]
9154 ["Block" idlwave-mark-block t]
9155 ["Header" idlwave-mark-doclib t])
9157 ["Indent Entire Statement" idlwave-indent-statement
9158 :active t :keys "C-u \\[indent-for-tab-command]" ]
9159 ["Indent Subprogram" idlwave-indent-subprogram t]
9160 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9161 ["Continue/Split line" idlwave-split-line t]
9163 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9164 :selected (symbol-value idlwave-fill-function)])
9166 ["Procedure" idlwave-procedure t]
9167 ["Function" idlwave-function t]
9168 ["Doc Header" idlwave-doc-header t]
9169 ["Log" idlwave-doc-modification t]
9171 ["Case" idlwave-case t]
9172 ["For" idlwave-for t]
9173 ["Repeat" idlwave-repeat t]
9174 ["While" idlwave-while t]
9176 ["Close Block" idlwave-close-block t])
9178 ["Complete" idlwave-complete t]
9179 ("Complete Specific"
9180 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9181 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9183 ["3 Function Name" (idlwave-complete 'function) t]
9184 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9186 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9187 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9189 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9190 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9192 ["9 Class Name" idlwave-complete-class t]))
9194 ["Show Routine Info" idlwave-routine-info t]
9195 ["Online Context Help" idlwave-context-help t]
9197 ["Find Routine Source" idlwave-find-module t]
9198 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9200 ["Update Routine Info" idlwave-update-routine-info t]
9201 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9204 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9205 ["Scan Directories" (idlwave-update-routine-info '(16))
9206 (and idlwave-path-alist (not idlwave-catalog-process))]
9207 ["Scan Directories &" (idlwave-update-routine-info '(64))
9208 (and idlwave-path-alist (not idlwave-catalog-process))]
9211 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9212 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9213 ["Check Everything" idlwave-list-all-load-path-shadows t])
9215 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9217 ["Insert TAB character" idlwave-hard-tab t])
9220 ["Start IDL shell" idlwave-shell t]
9221 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9222 ["Launch IDL Help" idlwave-launch-idlhelp t])
9225 ["Browse IDLWAVE Group" idlwave-customize t]
9227 ["Build Full Customize Menu" idlwave-create-customize-menu
9228 (fboundp 'customize-menu-create)])
9230 ["Describe Mode" describe-mode t]
9231 ["Abbreviation List" idlwave-list-abbrevs t]
9233 ["Commentary in idlwave.el" idlwave-show-commentary t]
9234 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9236 ["Info" idlwave-info t]
9238 ["Help with Topic" idlwave-help-assistant-help-with-topic
9239 idlwave-help-use-assistant]
9240 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9242 (defvar idlwave-mode-debug-menu-def
9244 ["Start IDL shell" idlwave-shell t]
9245 ["Save and .RUN buffer" idlwave-shell-save-and-run
9246 (and (boundp 'idlwave-shell-automatic-start)
9247 idlwave-shell-automatic-start)]))
9249 (if (or (featurep 'easymenu) (load "easymenu" t))
9251 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9252 "IDL and WAVE CL editing menu"
9253 idlwave-mode-menu-def)
9254 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9255 "IDL and WAVE CL editing menu"
9256 idlwave-mode-debug-menu-def)))
9258 (defun idlwave-customize ()
9259 "Call the customize function with idlwave as argument."
9261 ;; Try to load the code for the shell, so that we can customize it
9263 (or (featurep 'idlw-shell)
9264 (load "idlw-shell" t))
9265 (customize-browse 'idlwave))
9267 (defun idlwave-create-customize-menu ()
9268 "Create a full customization menu for IDLWAVE, insert it into the menu."
9270 (if (fboundp 'customize-menu-create)
9272 ;; Try to load the code for the shell, so that we can customize it
9274 (or (featurep 'idlw-shell)
9275 (load "idlw-shell" t))
9277 '("IDLWAVE") "Customize"
9278 `(["Browse IDLWAVE group" idlwave-customize t]
9280 ,(customize-menu-create 'idlwave)
9281 ["Set" Custom-set t]
9282 ["Save" Custom-save t]
9283 ["Reset to Current" Custom-reset-current t]
9284 ["Reset to Saved" Custom-reset-saved t]
9285 ["Reset to Standard Settings" Custom-reset-standard t]))
9286 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9287 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9289 (defun idlwave-show-commentary ()
9290 "Use the finder to view the file documentation from `idlwave.el'."
9292 (finder-commentary "idlwave.el"))
9294 (defun idlwave-shell-show-commentary ()
9295 "Use the finder to view the file documentation from `idlw-shell.el'."
9297 (finder-commentary "idlw-shell.el"))
9299 (defun idlwave-info ()
9300 "Read documentation for IDLWAVE in the info system."
9304 (defun idlwave-list-abbrevs (arg)
9305 "Show the code abbreviations define in IDLWAVE mode.
9306 This lists all abbrevs where the replacement text differs from the input text.
9307 These are the ones the users want to learn to speed up their writing.
9309 The function does *not* list abbrevs which replace a word with itself
9310 to call a hook. These hooks are used to change the case of words or
9311 to blink the matching `begin', and the user does not need to know them.
9313 With arg, list all abbrevs with the corresponding hook.
9315 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9318 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9320 str rpl func fmt (len-str 0) (len-rpl 0))
9323 (if (symbol-value sym)
9325 (setq str (symbol-name sym)
9326 rpl (symbol-value sym)
9327 func (symbol-function sym))
9329 (setq func (prin1-to-string func))
9330 (if (and (listp func) (stringp (nth 2 func)))
9331 (setq rpl (concat "EVAL: " (nth 2 func))
9334 (if (or arg (not (string= rpl str)))
9336 (setq len-str (max len-str (length str)))
9337 (setq len-rpl (max len-rpl (length rpl)))
9338 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9341 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9343 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9344 (with-output-to-temp-buffer "*Help*"
9347 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9348 (princ "=========================================\n\n")
9349 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9350 (princ (format fmt "---" "-------" "----")))
9351 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9352 (princ "================================================\n\n")
9353 (princ (format fmt "KEY" "ACTION" ""))
9354 (princ (format fmt "---" "------" "")))
9357 (setq str (car list)
9360 (princ (format fmt str rpl func)))
9362 ;; Make sure each abbreviation uses only one display line
9364 (set-buffer "*Help*")
9365 (setq truncate-lines t)))
9367 ;; Add .pro files to speedbar for support, if it's loaded
9368 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9370 ;; Set an idle timer to load the routine info.
9371 ;; Will only work on systems which support this.
9372 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9374 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
9377 (run-hooks 'idlwave-load-hook)
9381 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
9382 ;;; idlwave.el ends here