1 ;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; Keywords: languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; In the remotely distant past, based on pascal.el, though bears
32 ;; little resemblance to it now.
34 ;; Incorporates many ideas, such as abbrevs, action routines, and
35 ;; continuation line indenting, from wave.el.
36 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
38 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
39 ;; for features, key bindings, and info.
40 ;; Also, Info format documentation is available with `M-x idlwave-info'
42 ;; New versions of IDLWAVE, documentation, and more information
49 ;; Follow the instructions in the INSTALL file of the distribution.
50 ;; In short, put this file on your load path and add the following
51 ;; lines to your .emacs file:
53 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
54 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
55 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
61 ;; The newest version of this file is available from the maintainer's
69 ;; IDLWAVE is documented online in info format. A printable version
70 ;; of the documentation is available from the maintainers webpage (see
77 ;; Thanks to the following people for their contributions and comments:
79 ;; Ulrik Dickow <dickow_at_nbi.dk>
80 ;; Eric E. Dors <edors_at_lanl.gov>
81 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
82 ;; David Huenemoerder <dph_at_space.mit.edu>
83 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
84 ;; Dick Jackson <dick_at_d-jackson.com>
85 ;; Xuyong Liu <liu_at_stsci.edu>
86 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
87 ;; Laurent Mugnier <mugnier_at_onera.fr>
88 ;; Lubos Pochman <lubos_at_rsinc.com>
89 ;; Bob Portmann <portmann_at_al.noaa.gov>
90 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
91 ;; Marty Ryba <ryba_at_ll.mit.edu>
92 ;; Paul Sorenson <aardvark62_at_msn.com>
93 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
94 ;; Phil Williams <williams_at_irc.chmcc.org>
99 ;; IDLWAVE has extensive customize support; to learn about the
100 ;; variables which control the mode's behavior, use `M-x
101 ;; idlwave-customize'.
103 ;; You can set your own preferred values with Customize, or with Lisp
104 ;; code in .emacs. For an example of what to put into .emacs, check
105 ;; the TexInfo documentation or see a complete .emacs available at the
111 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
112 ;; Numerics, Inc. is growing less and less complete as the two
113 ;; languages grow increasingly apart. The mode probably shouldn't
114 ;; even have "WAVE" in it's title, but it's catchy, and was required
115 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
117 ;; Moving the point backwards in conjunction with abbrev expansion
118 ;; does not work as I would like it, but this is a problem with
119 ;; emacs abbrev expansion done by the self-insert-command. It ends
120 ;; up inserting the character that expanded the abbrev after moving
121 ;; point backward, e.g., "\cl" expanded with a space becomes
122 ;; "LONG( )" with point before the close paren. This is solved by
123 ;; using a temporary function in `post-command-hook' - not pretty,
126 ;; Tabs and spaces are treated equally as whitespace when filling a
127 ;; comment paragraph. To accomplish this, tabs are permanently
128 ;; replaced by spaces in the text surrounding the paragraph, which
129 ;; may be an undesirable side-effect. Replacing tabs with spaces is
130 ;; limited to comments only and occurs only when a comment
131 ;; paragraph is filled via `idlwave-fill-paragraph'.
133 ;; Muti-statement lines (using "&") on block begin and end lines can
134 ;; ruin the formatting. For example, multiple end statements on a
135 ;; line: endif & endif. Using "&" outside of block begin/end lines
138 ;; Determining the expression at point for printing and other
139 ;; examination commands is somewhat rough: currently only fairly
140 ;; simple entities are found. You can always drag-select or examine
141 ;; a pre-selected region.
143 ;; When forcing completion of method keywords, the initial
144 ;; query for a method has multiple entries for some methods. Would
145 ;; be too difficult to fix this hardly used case.
151 (eval-when-compile (require 'cl
))
155 (unless (fboundp 'line-beginning-position
)
156 (defalias 'line-beginning-position
'point-at-bol
))
157 (unless (fboundp 'line-end-position
)
158 (defalias 'line-end-position
'point-at-eol
))
159 (unless (fboundp 'char-valid-p
)
160 (defalias 'char-valid-p
'characterp
))
163 ;; Kludge to allow `defcustom' for Emacs 19.
164 (condition-case () (require 'custom
) (error nil
))
165 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
166 nil
;; We've got what we needed
167 ;; We have the old or no custom-library, hack around it!
168 (defmacro defgroup
(&rest args
) nil
)
169 (defmacro defcustom
(var value doc
&rest args
)
170 `(defvar ,var
,value
,doc
))))
172 (defgroup idlwave nil
173 "Major mode for editing IDL .pro files"
175 :link
'(url-link :tag
"Home Page"
176 "http://idlwave.org")
177 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
179 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
180 :link
'(custom-manual "(idlwave)Top")
185 ;;; Variables for indentation behavior ---------------------------------------
187 (defgroup idlwave-code-formatting nil
188 "Indentation and formatting options for IDLWAVE mode."
191 (defcustom idlwave-main-block-indent
0
192 "*Extra indentation for the main block of code.
193 That is the block between the FUNCTION/PRO statement and the END
194 statement for that program unit."
195 :group
'idlwave-code-formatting
198 (defcustom idlwave-block-indent
4
199 "*Extra indentation applied to block lines.
200 If you change this, you probably also want to change `idlwave-end-offset'."
201 :group
'idlwave-code-formatting
204 (defcustom idlwave-end-offset -
4
205 "*Extra indentation applied to block END lines.
206 A value equal to negative `idlwave-block-indent' will make END lines
207 line up with the block BEGIN lines."
208 :group
'idlwave-code-formatting
211 (defcustom idlwave-continuation-indent
2
212 "*Extra indentation applied to continuation lines.
213 This extra offset applies to the first of a set of continuation lines.
214 The following lines receive the same indentation as the first."
215 :group
'idlwave-code-formatting
218 (defcustom idlwave-max-extra-continuation-indent
20
219 "*Maximum additional indentation for special continuation indent.
220 Several special indentations are tried to help line up continuation
221 lines in routine calls or definitions, other statements with
222 parentheses, or assignment statements. This variable specifies a
223 maximum amount by which this special indentation can exceed the
224 standard continuation indentation, otherwise defaulting to a fixed
225 offset. Set to 0 to effectively disable all special continuation
226 indentation, or to a large number (like 100) to enable it in all
227 cases. See also `idlwave-indent-to-open-paren', which can override
229 :group
'idlwave-code-formatting
232 (defcustom idlwave-indent-to-open-paren t
233 "*Non-nil means, indent continuation lines to innermost open
234 parenthesis. This indentation occurs even if otherwise disallowed by
235 `idlwave-max-extra-continuation-indent'. Matching parens and the
236 interleaving args are lined up. Example:
238 x = function_a(function_b(function_c( a, b, [1,2,3, $
244 When this variable is nil, paren alignment may still occur, based on
245 the value of `max-extra-continuation-indent', which, if zero, would
248 x = function_a(function_b(function_c( a, b, [1,2,3, $
253 :group
'idlwave-code-formatting
256 (defcustom idlwave-indent-parens-nested nil
257 "*Non-nil means, indent continuation lines with parens by nesting
258 lines at consecutively deeper levels."
259 :group
'idlwave-code-formatting
263 (defcustom idlwave-hanging-indent t
264 "*If set non-nil then comment paragraphs are indented under the
265 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
267 :group
'idlwave-code-formatting
270 (defcustom idlwave-hang-indent-regexp
"- "
271 "*Regular expression matching the position of the hanging indent
272 in the first line of a comment paragraph. The size of the indent
273 extends to the end of the match for the regular expression."
274 :group
'idlwave-code-formatting
277 (defcustom idlwave-use-last-hang-indent nil
278 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
279 :group
'idlwave-code-formatting
282 (defcustom idlwave-fill-comment-line-only t
283 "*If non-nil then auto fill will only operate on comment lines."
284 :group
'idlwave-code-formatting
287 (defcustom idlwave-auto-fill-split-string t
288 "*If non-nil then auto fill will split strings with the IDL `+' operator.
289 When the line end falls within a string, string concatenation with the
290 '+' operator will be used to distribute a long string over lines.
291 If nil and a string is split then a terminal beep and warning are issued.
293 This variable is ignored when `idlwave-fill-comment-line-only' is
294 non-nil, since in this case code is not auto-filled."
295 :group
'idlwave-code-formatting
298 (defcustom idlwave-split-line-string t
299 "*If non-nil then `idlwave-split-line' will split strings with `+'.
300 When the splitting point of a line falls inside a string, split the string
301 using the `+' string concatenation operator. If nil and a string is
302 split then a terminal beep and warning are issued."
303 :group
'idlwave-code-formatting
306 (defcustom idlwave-no-change-comment
";;;"
307 "*The indentation of a comment that starts with this regular
308 expression will not be changed. Note that the indentation of a comment
309 at the beginning of a line is never changed."
310 :group
'idlwave-code-formatting
313 (defcustom idlwave-begin-line-comment nil
314 "*A comment anchored at the beginning of line.
315 A comment matching this regular expression will not have its
316 indentation changed. If nil the default is \"^;\", i.e., any line
317 beginning with a \";\". Expressions for comments at the beginning of
318 the line should begin with \"^\"."
319 :group
'idlwave-code-formatting
320 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
323 (defcustom idlwave-code-comment
";;[^;]"
324 "*A comment that starts with this regular expression on a line by
325 itself is indented as if it is a part of IDL code. As a result if
326 the comment is not preceded by whitespace it is unchanged."
327 :group
'idlwave-code-formatting
330 ;; Comments not matching any of the above will be indented as a
331 ;; right-margin comment, i.e., to a minimum of `comment-column'.
333 ;;; Routine Info and Completion ---------------------------------------
335 (defgroup idlwave-routine-info nil
336 "Routine Info options for IDLWAVE mode."
339 (defcustom idlwave-use-library-catalogs t
340 "*Non-nil means search the IDL path for library catalog files.
342 These files, named .idlwave_catalog, document routine information for
343 individual directories and libraries of IDL .pro files. Many popular
344 libraries come with catalog files by default, so leaving this on is a
345 usually a good idea.."
346 :group
'idlwave-routine-info
349 (defcustom idlwave-init-rinfo-when-idle-after
10
350 "*Seconds of idle time before routine info is automatically initialized.
351 Initializing the routine info can take long, in particular if a large
352 library catalog is involved. When Emacs is idle for more than the number
353 of seconds specified by this variable, it starts the initialization.
354 The process is split into five steps, in order to keep possible work
355 interruption as short as possible. If one of the steps finishes, and no
356 user input has arrived in the mean time, initialization proceeds immediately
358 A good value for this variable is about 1/3 of the time initialization
359 take in you setup. So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
360 A Value of 0 means, don't initialize automatically."
361 :group
'idlwave-routine-info
364 (defcustom idlwave-scan-all-buffers-for-routine-info t
365 "*Non-nil means, scan buffers for IDL programs when updating info.
366 The scanning is done by the command `idlwave-update-routine-info'.
367 The following values are allowed:
369 nil Don't scan any buffers.
370 t Scan all idlwave-mode buffers in the current editing session.
371 current Scan only the current buffer, but no other buffers."
372 :group
'idlwave-routine-info
374 (const :tag
"No buffer" nil
)
375 (const :tag
"All buffers" t
)
376 (const :tag
"Current buffer only" 'current
)))
378 (defcustom idlwave-query-shell-for-routine-info t
379 "*Non-nil means query the shell for info about compiled routines.
380 Querying the shell is useful to get information about compiled modules,
381 and it is turned on by default. However, when you have a complete library
382 scan, this is not necessary."
383 :group
'idlwave-routine-info
386 (defcustom idlwave-auto-routine-info-updates
387 '(find-file save-buffer kill-buffer compile-buffer
)
388 "*Controls under what circumstances routine info is updated automatically.
392 \(...) A list of circumstances. Allowed members are:
393 find-file Add info for new IDLWAVE buffers.
394 save-buffer Update buffer info when buffer is saved
395 kill-buffer Remove buffer info when buffer gets killed
396 compile-buffer Update shell info after `idlwave-shell-save-and...'"
397 :group
'idlwave-routine-info
399 (const :tag
"Never" nil
)
400 (const :tag
"As often as possible" t
)
401 (set :tag
"Checklist" :greedy t
402 (const :tag
"When visiting a file" find-file
)
403 (const :tag
"When saving a buffer" save-buffer
)
404 (const :tag
"After a buffer was killed" kill-buffer
)
405 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
407 (defcustom idlwave-rinfo-max-source-lines
5
408 "*Maximum number of source files displayed in the Routine Info window.
409 When an integer, it is the maximum number of source files displayed.
410 t means to show all source files."
411 :group
'idlwave-routine-info
414 (defcustom idlwave-library-path nil
415 "Library path for Windows and MacOS. Not needed under Unix. When
416 selecting the directories to scan for IDL user catalog routine info,
417 IDLWAVE can, under UNIX, query the shell for the exact search path
418 \(the value of !PATH). However, under Windows and MacOS (pre-OSX),
419 the IDLWAVE shell does not work. In this case, this variable can be
420 set to specify the paths where IDLWAVE can find PRO files. The shell
421 will only be asked for a list of paths when this variable is nil. The
422 value is a list of directories. A directory preceeded by a `+' will
423 be searched recursively. If you set this variable on a UNIX system,
424 the shell will not be queried. See also `idlwave-system-directory'."
425 :group
'idlwave-routine-info
426 :type
'(repeat (directory)))
428 (defcustom idlwave-system-directory
""
429 "The IDL system directory for Windows and MacOS. Not needed under
430 UNIX. Set this to the value of the `!DIR' system variable in IDL.
431 IDLWAVE uses this to find out which of the library routines belong to
432 the official system library. All files inside the `lib' subdirectory
433 are considered system library files - so don't install private stuff
434 in this directory. On UNIX systems, IDLWAVE queries the shell for the
435 value of `!DIR'. See also `idlwave-library-path'."
436 :group
'idlwave-routine-info
439 (defcustom idlwave-config-directory
440 (convert-standard-filename "~/.idlwave")
441 "*Directory for configuration files and user-library catalog."
442 :group
'idlwave-routine-info
445 (defvar idlwave-user-catalog-file
"idlusercat.el")
446 (defvar idlwave-path-file
"idlpath.el")
448 (defvar idlwave-libinfo-file nil
449 "*Obsolete variable, no longer used.")
451 (defcustom idlwave-special-lib-alist nil
452 "Alist of regular expressions matching special library directories.
453 When listing routine source locations, IDLWAVE gives a short hint where
454 the file defining the routine is located. By default it lists `SystemLib'
455 for routines in the system library `!DIR/lib' and `Library' for anything
456 else. This variable can define additional types. The car of each entry
457 is a regular expression matching the file name (they normally will match
458 on the path). The cdr is the string to be used as identifier. Max 10
460 :group
'idlwave-routine-info
462 (cons regexp string
)))
464 (defcustom idlwave-auto-write-paths t
465 "Write out path (!PATH) and system directory (!DIR) info automatically.
466 Path info is needed to locate library catalog files. If non-nil,
467 whenever the path-list changes as a result of shell-query, etc., it is
468 written to file. Otherwise, the menu option \"Write Paths\" can be
469 used to force a write."
470 :group
'idlwave-routine-info
473 (defgroup idlwave-completion nil
474 "Completion options for IDLWAVE mode."
479 (defconst idlwave-tmp
480 '(choice :tag
"by applying the function"
485 (symbol :tag
"Other"))))
487 (defcustom idlwave-completion-case
'((routine . upcase
)
491 "Association list setting the case of completed words.
493 This variable determines the case (UPPER/lower/Capitalized...) of
494 words inserted into the buffer by completion. The preferred case can
495 be specified separately for routine names, keywords, classes and
497 This alist should therefore have entries for `routine' (normal
498 functions and procedures, i.e. non-methods), `keyword', `class', and
499 `method'. Plausible values are
501 upcase upcase whole word, like `BOX_CURSOR'
502 downcase downcase whole word, like `read_ppm'
503 capitalize capitalize each part, like `Widget_Control'
504 preserve preserve case as is, like `IDLgrView'
506 The value can also be any Emacs Lisp function which transforms the
507 case of characters in a string.
509 A value of `preserve' means that the case of the completed word is
510 identical to the way it was written in the definition statement of the
511 routine. This was implemented to allow for mixed-case completion, in
512 particular of object classes and methods.
513 If a completable word is defined in multiple locations, the meaning of
514 `preserve' is not unique since the different definitions might be
515 cased differently. Therefore IDLWAVE always takes the case of the
516 *first* definition it encounters during routine info collection and
517 uses the case derived from it consistently.
519 Note that a lowercase-only string in the buffer will always be completed in
520 lower case (but see the variable `idlwave-completion-force-default-case').
522 After changing this variable, you need to either restart Emacs or press
523 `C-u C-c C-i' to update the internal lists."
524 :group
'idlwave-completion
526 (cons (symbol :tag
"Derive completion case for")
529 (defcustom idlwave-completion-force-default-case nil
530 "*Non-nil means, completion will always honor `idlwave-completion-case'.
531 When nil, only the completion of a mixed case or upper case string
532 will honor the default settings in `idlwave-completion-case', while
533 the completion of lower case strings will be completed entirely in
535 :group
'idlwave-completion
538 (defcustom idlwave-complete-empty-string-as-lower-case nil
539 "*Non-nil means, the empty string is considered downcase for completion.
540 The case of what is already in the buffer determines the case of completions.
541 When this variable is non-nil, the empty string is considered to be downcase.
542 Completing on the empty string then offers downcase versions of the possible
544 :group
'idlwave-completion
547 (defvar idlwave-default-completion-case-is-down nil
548 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
549 `idlwave-completion-case'.")
551 (defcustom idlwave-buffer-case-takes-precedence nil
552 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
553 To make this possible, we need to re-case everything each time we update
554 the routine info from the buffers. This is slow.
555 The default is to consider the case given in the system and library files
556 first which makes updating much faster."
557 :group
'idlwave-completion
560 (defcustom idlwave-highlight-help-links-in-completion t
561 "*Non-nil means, highlight completions for which system help is available.
562 Help can then be accessed with mouse-3.
563 This option is only effective when the online help system is installed."
564 :group
'idlwave-completion
567 (defcustom idlwave-support-inheritance t
568 "Non-nil means, treat inheritance with completion, online help etc.
569 When nil, IDLWAVE only knows about the native methods and tags of a class,
570 not about inherited ones."
571 :group
'idlwave-routine-info
574 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
575 "List of regular expressions for class-driven keyword inheritance.
576 Keyword inheritance is often tied to class inheritance by \"chaining\"
577 up the class tree. While it cannot be assumed that the presence of an
578 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
579 certain methods this assumption is almost always true. The methods
580 for which to assume this can be set here."
581 :group
'idlwave-routine-info
582 :type
'(repeat (regexp :tag
"Match method:")))
585 (defcustom idlwave-completion-show-classes
1
586 "*Number of classes to show when completing object methods and keywords.
587 When completing methods or keywords for an object with unknown class,
588 the *Completions* buffer will show the valid classes for each completion
591 MyMethod <Class1,Class2,Class3>
593 The value of this variable may be nil to inhibit display, or an integer to
594 indicate the maximum number of classes to display.
596 On XEmacs, a full list of classes will also be placed into a `help-echo'
597 property on the competion items, so that the list of classes for the current
598 item is displayed in the echo area. If the value of this variable is a
599 negative integer, the `help-echo' property will be suppressed."
600 :group
'idlwave-completion
601 :type
'(choice (const :tag
"Don't show" nil
)
602 (integer :tag
"Number of classes shown" 1)))
604 (defcustom idlwave-completion-fontify-classes t
605 "*Non-nil means, fontify the classes in completions buffer.
606 This makes it easier to distinguish the completion items from the extra
607 class info listed. See `idlwave-completion-show-classes'."
608 :group
'idlwave-completion
611 (defcustom idlwave-query-class
'((method-default . nil
)
612 (keyword-default . nil
))
613 "Association list governing specification of object classes for completion.
615 When IDLWAVE tries to complete object-oriented methods, it usually
616 cannot determine the class of a given object from context. In order
617 to provide the user with a correct list of methods or keywords, it
618 needs to determine the appropriate class. IDLWAVE has two ways of
619 doing this (well, three ways if you count the shell... see
620 `idlwave-shell-query-for-class'):
622 1. Combine the items of all available classes which contain this
623 method for the purpose of completion. So when completing a method,
624 all methods of all known classes are available, and when completing
625 a keyword, all keywords allowed for this method in any class are
626 shown. This behavior is very much like normal completion and is
627 therefore the default. It works much better than one might think -
628 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
629 become uncomfortably long. See also
630 `idlwave-completion-show-classes'.
632 2. The second possibility is to ask the user on each occasion. To
633 make this less interruptive, IDLWAVE can store the class as a text
634 property on the object operator `->'. For a given object in the
635 source code, class selection will then be needed only once
636 - for example to complete the method. Keywords to the method can
637 then be completed directly, because the class is already known.
638 You will have to turn on the storage of the selected class
639 explicitly with the variable `idlwave-store-inquired-class'.
641 This variable allows you to configure IDLWAVE's method and
642 method-keyword completion behavior. Its value is an alist, which
643 should contain at least two elements: (method-default . VALUE) and
644 \(keyword-default . VALUE), where VALUE is either t or nil. These
645 specify if the class should be found during method and keyword
646 completion, respectively.
648 The alist may have additional entries specifying exceptions from the
649 keyword completion rule for specific methods, like INIT or
650 GETPROPERTY. In order to turn on class specification for the INIT
651 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
652 :group
'idlwave-completion
654 (cons (const method-default
)
655 (boolean :tag
"Determine class when completing METHODS "))
656 (cons (const keyword-default
)
657 (boolean :tag
"Determine class when completing KEYWORDS "))
659 :tag
"Exceptions to defaults"
661 (cons (string :tag
"MODULE" :value
"")
662 (boolean :tag
"Determine class for this method")))))
664 (defcustom idlwave-store-inquired-class nil
665 "*Non-nil means, store class of a method call as text property on `->'.
666 IDLWAVE sometimes has to ask the user for the class associated with a
667 particular object method call. This happens during the commands
668 `idlwave-routine-info' and `idlwave-complete', depending upon the
669 value of the variable `idlwave-query-class'.
671 When you specify a class, this information can be stored as a text
672 property on the `->' arrow in the source code, so that during the same
673 editing session, IDLWAVE will not have to ask again. When this
674 variable is non-nil, IDLWAVE will store and reuse the class information.
675 The class stored can be checked and removed with `\\[idlwave-routine-info]'
678 The default of this variable is nil, since the result of commands then
679 is more predictable. However, if you know what you are doing, it can
680 be nice to turn this on.
682 An arrow which knows the class will be highlighted with
683 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
684 displays (with prefix arg: deletes) the class stored on the arrow
686 :group
'idlwave-completion
689 (defcustom idlwave-class-arrow-face
'bold
690 "*Face to highlight object operator arrows `->' which carry a class property.
691 When IDLWAVE stores a class name as text property on an object arrow
692 \(see variable `idlwave-store-inquired-class', it highlights the arrow
693 with this font in order to remind the user that this arrow is special."
694 :group
'idlwave-completion
697 (defcustom idlwave-resize-routine-help-window t
698 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
699 :group
'idlwave-completion
702 (defcustom idlwave-keyword-completion-adds-equal t
703 "*Non-nil means, completion automatically adds `=' after completed keywords."
704 :group
'idlwave-completion
707 (defcustom idlwave-function-completion-adds-paren t
708 "*Non-nil means, completion automatically adds `(' after completed function.
709 nil means, don't add anything.
710 A value of `2' means, also add the closing parenthesis and position cursor
712 :group
'idlwave-completion
713 :type
'(choice (const :tag
"Nothing" nil
)
715 (const :tag
"()" 2)))
717 (defcustom idlwave-completion-restore-window-configuration t
718 "*Non-nil means, try to restore the window configuration after completion.
719 When completion is not unique, Emacs displays a list of completions.
720 This messes up your window configuration. With this variable set, IDLWAVE
721 restores the old configuration after successful completion."
722 :group
'idlwave-completion
725 ;;; Variables for abbrev and action behavior -----------------------------
727 (defgroup idlwave-abbrev-and-indent-action nil
728 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
729 The variables in this group govern this."
732 (defcustom idlwave-do-actions nil
733 "*Non-nil means performs actions when indenting.
734 The actions that can be performed are listed in `idlwave-indent-action-table'."
735 :group
'idlwave-abbrev-and-indent-action
738 (defcustom idlwave-abbrev-start-char
"\\"
739 "*A single character string used to start abbreviations in abbrev mode.
740 Possible characters to chose from: ~`\%
741 or even '?'. '.' is not a good choice because it can make structure
742 field names act like abbrevs in certain circumstances.
744 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
745 must set it directly using `setq' in the .emacs file before idlwave.el
747 :group
'idlwave-abbrev-and-indent-action
750 (defcustom idlwave-surround-by-blank nil
751 "*Non-nil means, enable `idlwave-surround'.
752 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
754 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
756 Also see the default key bindings for keys using `idlwave-surround'.
757 Keys are bound and made into actions calling `idlwave-surround' with
758 `idlwave-action-and-binding'.
759 See help for `idlwave-action-and-binding' for examples.
761 Also see help for `idlwave-surround'."
762 :group
'idlwave-abbrev-and-indent-action
765 (defcustom idlwave-pad-keyword t
766 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
767 Whenever `idlwave-surround' is non-nil then this affects how '=' is
768 padded for keywords and for variables. If t, pad the same as for
769 assignments. If nil then spaces are removed. With any other value,
770 spaces are left unchanged."
771 :group
'idlwave-abbrev-and-indent-action
773 (const :tag
"Pad like assignments" t
)
774 (const :tag
"Remove space near `='" nil
)
775 (const :tag
"Keep space near `='" 'keep
)))
777 (defcustom idlwave-show-block t
778 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
779 :group
'idlwave-abbrev-and-indent-action
782 (defcustom idlwave-expand-generic-end nil
783 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
784 :group
'idlwave-abbrev-and-indent-action
787 (defcustom idlwave-reindent-end t
788 "*Non-nil means re-indent line after END was typed."
789 :group
'idlwave-abbrev-and-indent-action
792 (defcustom idlwave-abbrev-move t
793 "*Non-nil means the abbrev hook can move point.
794 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
795 definitions, use the command `list-abbrevs', for abbrevs that move
796 point. Moving point is useful, for example, to place point between
797 parentheses of expanded functions.
799 See `idlwave-check-abbrev'."
800 :group
'idlwave-abbrev-and-indent-action
803 (defcustom idlwave-abbrev-change-case nil
804 "*Non-nil means all abbrevs will be forced to either upper or lower case.
805 If the value t, all expanded abbrevs will be upper case.
806 If the value is 'down then abbrevs will be forced to lower case.
807 If nil, the case will not change.
808 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
809 upper case, regardless of this variable."
810 :group
'idlwave-abbrev-and-indent-action
813 (defcustom idlwave-reserved-word-upcase nil
814 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
815 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
816 Has effect only if in abbrev-mode."
817 :group
'idlwave-abbrev-and-indent-action
820 ;;; Action/Expand Tables.
822 ;; The average user may have difficulty modifying this directly. It
823 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
824 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
825 ;; examples of how to add an action.
827 ;; The action table is used by `idlwave-indent-line' whereas both the
828 ;; action and expand tables are used by `idlwave-indent-and-action'. In
829 ;; general, the expand table is only used when a line is explicitly
830 ;; indented. Whereas, in addition to being used when the expand table
831 ;; is used, the action table is used when a line is indirectly
832 ;; indented via line splitting, auto-filling or a new line creation.
836 ;; Capitalize system vars
837 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
839 ;; Capitalize procedure name
840 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
841 ;; '(capitalize-word 1) t)
843 ;; Capitalize common block name
844 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
845 ;; '(capitalize-word 1) t)
847 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
848 ;; '(capitalize-word -1) t)
850 (defvar idlwave-indent-action-table nil
851 "*Associated array containing action lists of search string (car),
852 and function as a cdr. This table is used by `idlwave-indent-line'.
853 See documentation for `idlwave-do-action' for a complete description of
856 Additions to the table are made with `idlwave-action-and-binding' when a
857 binding is not requested.
858 See help on `idlwave-action-and-binding' for examples.")
860 (defvar idlwave-indent-expand-table nil
861 "*Associated array containing action lists of search string (car),
862 and function as a cdr. The table is used by the
863 `idlwave-indent-and-action' function. See documentation for
864 `idlwave-do-action' for a complete description of the action lists.
866 Additions to the table are made with `idlwave-action-and-binding' when a
867 binding is requested.
868 See help on `idlwave-action-and-binding' for examples.")
870 ;;; Documentation header and history keyword ---------------------------------
872 (defgroup idlwave-documentation nil
873 "Options for documenting IDLWAVE files."
876 ;; FIXME: make defcustom?
877 (defvar idlwave-file-header
904 ; KEYWORD PARAMETERS:
936 ; MODIFICATION HISTORY:
940 "*A list (PATHNAME STRING) specifying the doc-header template to use for
941 summarizing a file. If PATHNAME is non-nil then this file will be included.
942 Otherwise STRING is used. If nil, the file summary will be omitted.
943 For example you might set PATHNAME to the path for the
944 lib_template.pro file included in the IDL distribution.")
946 (defcustom idlwave-header-to-beginning-of-file nil
947 "*Non-nil means, the documentation header will always be at start of file.
948 When nil, the header is positioned between the PRO/FUNCTION line of
949 the current routine and the code, allowing several routine headers in
951 :group
'idlwave-documentation
954 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
955 "*The hook function used to update the timestamp of a function."
956 :group
'idlwave-documentation
959 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
960 "*The modifications keyword to use with the log documentation commands.
961 A ':' is added to the keyword end.
962 Inserted by doc-header and used to position logs by doc-modification.
963 If nil it will not be inserted."
964 :group
'idlwave-documentation
967 (defcustom idlwave-doclib-start
"^;+\\+"
968 "*Regexp matching the start of a document library header."
969 :group
'idlwave-documentation
972 (defcustom idlwave-doclib-end
"^;+-"
973 "*Regexp matching the end of a document library header."
974 :group
'idlwave-documentation
977 ;;; External Programs -------------------------------------------------------
979 (defgroup idlwave-external-programs nil
980 "Path locations of external commands used by IDLWAVE."
983 ;; WARNING: The following variable has recently been moved from
984 ;; idlw-shell.el to this file. I hope this does not break
987 (defcustom idlwave-shell-explicit-file-name
"idl"
988 "*If non-nil, this is the command to run IDL.
989 Should be an absolute file path or path relative to the current environment
990 execution search path. If you want to specify command line switches
991 for the idl program, use `idlwave-shell-command-line-options'.
993 I know the name of this variable is badly chosen, but I cannot change
994 it without compromizing backwards-compatibility."
995 :group
'idlwave-external-programs
998 (defcustom idlwave-shell-command-line-options nil
999 "*A list of command line options for calling the IDL program.
1000 Since IDL is executed directly without going through a shell like /bin/sh,
1001 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1002 string for each argument. But you may also give a single string which
1003 contains the options whitespace-separated. Emacs will be kind enough to
1007 (repeat (string :value
"")))
1008 :group
'idlwave-external-programs
)
1010 (defcustom idlwave-help-application
"idlhelp"
1011 "*The external application providing reference help for programming."
1012 :group
'idlwave-external-programs
1015 ;;; Some Shell variables which must be defined here.-----------------------
1017 (defcustom idlwave-shell-debug-modifiers
'()
1018 "List of modifiers to be used for the debugging commands.
1019 Will be used to bind debugging commands in the shell buffer and in all
1020 source buffers. These are additional convenience bindings, the debugging
1021 commands are always available with the `C-c C-d' prefix.
1022 If you set this to '(control shift), this means setting a breakpoint will
1023 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1024 are `control', `meta', `super', `hyper', `alt', and `shift'."
1025 :group
'idlwave-shell-general-setup
1026 :type
'(set :tag
"Specify modifiers"
1034 (defcustom idlwave-shell-automatic-start nil
1035 "*If non-nil attempt invoke idlwave-shell if not already running.
1036 This is checked when an attempt to send a command to an
1037 IDL process is made."
1038 :group
'idlwave-shell-general-setup
1041 ;;; Miscellaneous variables -------------------------------------------------
1043 (defgroup idlwave-misc nil
1044 "Miscellaneous options for IDLWAVE mode."
1047 (defcustom idlwave-startup-message t
1048 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1049 :group
'idlwave-misc
1052 (defcustom idlwave-default-font-lock-items
1053 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1054 common-blocks class-arrows
)
1055 "Items which should be fontified on the default fontification level 2.
1056 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1057 is everything and level 2 is specified by this list.
1058 This variable must be set before IDLWAVE gets loaded. It is
1059 a list of symbols, the following symbols are allowed.
1061 pros-and-functions Procedure and Function definitions
1062 batch-files Batch Files
1063 idlwave-idl-keywords IDL Keywords
1064 label Statement Labels
1065 goto Goto Statements
1066 common-blocks Common Blocks
1067 keyword-parameters Keyword Parameters in routine definitions and calls
1068 system-variables System Variables
1069 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1070 class-arrows Object Arrows with class property"
1071 :group
'idlwave-misc
1074 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1075 (const :tag
"Batch Files" batch-files
)
1076 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1077 (const :tag
"Statement Labels" label
)
1078 (const :tag
"Goto Statements" goto
)
1079 (const :tag
"Tags in Structure Definition" structtag
)
1080 (const :tag
"Structure Name" structname
)
1081 (const :tag
"Common Blocks" common-blocks
)
1082 (const :tag
"Keyword Parameters" keyword-parameters
)
1083 (const :tag
"System Variables" system-variables
)
1084 (const :tag
"FIXME: Warning" fixme
)
1085 (const :tag
"Object Arrows with class property " class-arrows
)))
1087 (defcustom idlwave-mode-hook nil
1088 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1089 :group
'idlwave-misc
1092 (defcustom idlwave-load-hook nil
1093 "Normal hook. Executed when idlwave.el is loaded."
1094 :group
'idlwave-misc
1097 (defvar idlwave-experimental nil
1098 "Non-nil means turn on a few experimental features.
1099 This variable is only for the maintainer, to test difficult stuff,
1100 while still distributing stable releases.
1101 As a user, you should not set this to t.")
1104 ;;; End customization variables section
1107 ;;; Non customization variables
1109 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1110 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1111 ;;; and Carsten Dominik...
1113 ;; The following are the reserved words in IDL. Maybe we should
1114 ;; highlight some more stuff as well?
1115 ;; Procedure declarations. Fontify keyword plus procedure name.
1116 (defvar idlwave-idl-keywords
1117 ;; To update this regexp, update the list of keywords and
1118 ;; evaluate the form.
1124 ;; '("||" "&&" "and" "or" "xor" "not"
1125 ;; "eq" "ge" "gt" "le" "lt" "ne"
1126 ;; "for" "do" "endfor"
1127 ;; "if" "then" "endif" "else" "endelse"
1128 ;; "case" "of" "endcase"
1129 ;; "switch" "break" "continue" "endswitch"
1131 ;; "repeat" "until" "endrep"
1132 ;; "while" "endwhile"
1135 ;; "compile_opt" "forward_function"
1136 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1138 "\\<\\(&&\\|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\\|||\\)\\>")
1141 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1142 ;; Function declarations. Fontify keyword plus function name.
1144 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1145 (1 font-lock-keyword-face
)
1146 (2 font-lock-function-name-face nil t
)))
1150 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1151 (1 font-lock-keyword-face
) ; "common"
1152 (2 font-lock-reference-face nil t
) ; block name
1153 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1154 ;; Start with point after block name and comma
1155 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1157 (1 font-lock-variable-name-face
) ; variable names
1162 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1166 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1170 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1172 ;; The goto statement and its label
1174 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1175 (1 font-lock-keyword-face
)
1176 (2 font-lock-reference-face
)))
1178 ;; Tags in structure definitions. Note that this definition
1179 ;; actually collides with labels, so we have to use the same
1180 ;; face. It also matches named subscript ranges,
1181 ;; e.g. vec{bottom:top]. No good way around this.
1183 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1187 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1188 (2 font-lock-function-name-face
)))
1190 ;; Keyword parameters, like /xlog or ,xrange=[]
1191 ;; This is anchored to the comma preceeding the keyword.
1192 ;; Treats continuation lines, works only during whole buffer
1193 ;; fontification. Slow, use it only in fancy fontification.
1195 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1196 (5 font-lock-reference-face
)))
1198 ;; System variables start with a bang.
1200 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1201 (1 font-lock-variable-name-face
)))
1203 ;; Special and unusual operators (not used because too noisy)
1205 '("[<>#]" (0 font-lock-keyword-face
)))
1207 ;; All operators (not used because too noisy)
1209 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1211 ;; Arrows with text property `idlwave-class'
1213 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1215 (defconst idlwave-font-lock-keywords-1
1216 (list pros-and-functions batch-files
)
1217 "Subdued level highlighting for IDLWAVE mode.")
1219 (defconst idlwave-font-lock-keywords-2
1220 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1221 "Medium level highlighting for IDLWAVE mode.")
1223 (defconst idlwave-font-lock-keywords-3
1224 (list pros-and-functions
1226 idlwave-idl-keywords
1234 "Gaudy level highlighting for IDLWAVE mode."))
1236 (defun idlwave-match-class-arrows (limit)
1237 ;; Match an object arrow with class property
1238 (and idlwave-store-inquired-class
1239 (re-search-forward "->" limit
'limit
)
1240 (get-text-property (match-beginning 0) 'idlwave-class
)))
1242 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1243 "Default expressions to highlight in IDLWAVE mode.")
1245 (defvar idlwave-font-lock-defaults
1246 '((idlwave-font-lock-keywords
1247 idlwave-font-lock-keywords-1
1248 idlwave-font-lock-keywords-2
1249 idlwave-font-lock-keywords-3
)
1251 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1254 (put 'idlwave-mode
'font-lock-defaults
1255 idlwave-font-lock-defaults
) ; XEmacs
1257 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1258 "Regexp to match the start of a full-line comment.
1259 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1260 only by whitespace.")
1262 (defconst idlwave-begin-block-reg
1263 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1264 "Regular expression to find the beginning of a block. The case does
1265 not matter. The search skips matches in comments.")
1267 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1268 "Regular expression to find the beginning of a unit. The case does
1271 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1272 "Regular expression to find the line that indicates the end of unit.
1273 This line is the end of buffer or the start of another unit. The case does
1274 not matter. The search skips matches in comments.")
1276 (defconst idlwave-continue-line-reg
"\\<\\$"
1277 "Regular expression to match a continued line.")
1279 (defconst idlwave-end-block-reg
1280 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1281 "Regular expression to find the end of a block. The case does
1282 not matter. The search skips matches found in comments.")
1284 (defconst idlwave-block-matches
1286 ("function" .
"end")
1287 ("case" .
"endcase")
1288 ("else" .
"endelse")
1291 ("repeat" .
"endrep")
1292 ("switch" .
"endswitch")
1293 ("while" .
"endwhile"))
1294 "Matches between statements and the corresponding END variant.
1295 The cars are the reserved words starting a block. If the block really
1296 begins with BEGIN, the cars are the reserved words before the begin
1297 which can be used to identify the block type.
1298 This is used to check for the correct END type, to close blocks and
1299 to expand generic end statements to their detailed form.")
1301 (defconst idlwave-block-match-regexp
1302 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1303 "Regular expression matching reserved words which can stand before
1304 blocks starting with a BEGIN statement. The matches must have associations
1305 `idlwave-block-matches'")
1307 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1308 "Regular expression matching an IDL identifier.")
1310 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1311 "Regular expression matching IDL system variables.")
1313 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1314 "Regular expression matching IDL variable names.")
1316 (defconst idlwave-label
(concat idlwave-identifier
":")
1317 "Regular expression matching IDL labels.")
1319 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1320 "\\(\\s *" idlwave-identifier
"::\\)?"
1323 (defconst idlwave-statement-match
1325 ;; "endif else" is the only possible "end" that can be
1326 ;; followed by a statement on the same line.
1327 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1328 ;; all other "end"s can not be followed by a statement.
1329 (cons 'end
(list idlwave-end-block-reg nil
))
1330 '(if .
("if\\>" "then"))
1331 '(for .
("for\\>" "do"))
1332 '(begin .
("begin\\>" nil
))
1333 '(pdef .
("pro\\>\\|function\\>" nil
))
1334 '(while .
("while\\>" "do"))
1335 '(repeat .
("repeat\\>" "repeat"))
1336 '(goto .
("goto\\>" nil
))
1337 '(case .
("case\\>" nil
))
1338 '(switch .
("switch\\>" nil
))
1339 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1340 "\\(" idlwave-method-call
"\\s *\\)?"
1343 (cons 'call
(list (concat
1344 "\\(" idlwave-method-call
"\\s *\\)?"
1346 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1347 (cons 'assign
(list (concat
1348 "\\(" idlwave-variable
"\\) *=") nil
)))
1350 "Associated list of statement matching regular expressions.
1351 Each regular expression matches the start of an IDL statement. The
1352 first element of each association is a symbol giving the statement
1353 type. The associated value is a list. The first element of this list
1354 is a regular expression matching the start of an IDL statement for
1355 identifying the statement type. The second element of this list is a
1356 regular expression for finding a substatement for the type. The
1357 substatement starts after the end of the found match modulo
1358 whitespace. If it is nil then the statement has no substatement. The
1359 list order matters since matching an assignment statement exactly is
1360 not possible without parsing. Thus assignment statement become just
1361 the leftover unidentified statements containing an equal sign." )
1363 (defvar idlwave-fill-function
'auto-fill-function
1364 "IDL mode auto fill function.")
1366 (defvar idlwave-comment-indent-function
'comment-indent-function
1367 "IDL mode comment indent function.")
1369 ;; Note that this is documented in the v18 manuals as being a string
1370 ;; of length one rather than a single character.
1371 ;; The code in this file accepts either format for compatibility.
1372 (defvar idlwave-comment-indent-char ?\
1373 "Character to be inserted for IDL comment indentation.
1376 (defconst idlwave-continuation-char ?$
1377 "Character which is inserted as a last character on previous line by
1378 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1380 (defconst idlwave-mode-version
"5.5")
1382 (defmacro idlwave-keyword-abbrev
(&rest args
)
1383 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1385 ,(append '(idlwave-check-abbrev) args
))))
1387 ;; If I take the time I can replace idlwave-keyword-abbrev with
1388 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1389 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1390 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1391 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1393 (defmacro idlwave-code-abbrev
(&rest args
)
1394 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1395 Specifically, if the abbrev is in a comment or string it is unexpanded.
1396 Otherwise ARGS forms a list that is evaluated."
1398 ,(prin1-to-string args
) ;; Puts the code in the doc string
1399 (if (idlwave-quoted)
1400 (progn (unexpand-abbrev) nil
)
1403 (defvar idlwave-mode-map
(make-sparse-keymap)
1404 "Keymap used in IDL mode.")
1406 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1407 "Syntax table in use in `idlwave-mode' buffers.")
1409 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
1410 (modify-syntax-entry ?-
"." idlwave-mode-syntax-table
)
1411 (modify-syntax-entry ?
* "." idlwave-mode-syntax-table
)
1412 (modify-syntax-entry ?
/ "." idlwave-mode-syntax-table
)
1413 (modify-syntax-entry ?^
"." idlwave-mode-syntax-table
)
1414 (modify-syntax-entry ?
# "." idlwave-mode-syntax-table
)
1415 (modify-syntax-entry ?
= "." idlwave-mode-syntax-table
)
1416 (modify-syntax-entry ?%
"." idlwave-mode-syntax-table
)
1417 (modify-syntax-entry ?
< "." idlwave-mode-syntax-table
)
1418 (modify-syntax-entry ?
> "." idlwave-mode-syntax-table
)
1419 (modify-syntax-entry ?
\' "\"" idlwave-mode-syntax-table
)
1420 (modify-syntax-entry ?
\" "\"" idlwave-mode-syntax-table
)
1421 (modify-syntax-entry ?
\\ "." idlwave-mode-syntax-table
)
1422 (modify-syntax-entry ?_
"_" idlwave-mode-syntax-table
)
1423 (modify-syntax-entry ?
{ "(}" idlwave-mode-syntax-table
)
1424 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1425 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1426 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1427 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1428 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1429 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1431 (defvar idlwave-find-symbol-syntax-table
1432 (copy-syntax-table idlwave-mode-syntax-table
)
1433 "Syntax table that treats symbol characters as word characters.")
1435 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1436 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1437 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1438 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1440 (defmacro idlwave-with-special-syntax
(&rest body
)
1441 "Execute BODY with a different syntax table."
1442 `(let ((saved-syntax (syntax-table)))
1445 (set-syntax-table idlwave-find-symbol-syntax-table
)
1447 (set-syntax-table saved-syntax
))))
1449 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1450 ; "Execute BODY with a different syntax table."
1451 ; `(let ((saved-syntax (syntax-table)))
1454 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1456 ; (set-syntax-table saved-syntax))))
1458 (defun idlwave-action-and-binding (key cmd
&optional select
)
1459 "KEY and CMD are made into a key binding and an indent action.
1460 KEY is a string - same as for the `define-key' function. CMD is a
1461 function of no arguments or a list to be evaluated. CMD is bound to
1462 KEY in `idlwave-mode-map' by defining an anonymous function calling
1463 `self-insert-command' followed by CMD. If KEY contains more than one
1464 character a binding will only be set if SELECT is 'both.
1466 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1467 replacing any previous value for KEY. If a binding is not set then it
1468 will instead be placed in `idlwave-indent-action-table'.
1470 If the optional argument SELECT is nil then an action and binding are
1471 created. If SELECT is 'noaction, then a binding is always set and no
1472 action is created. If SELECT is 'both then an action and binding
1473 will both be created even if KEY contains more than one character.
1474 Otherwise, if SELECT is non-nil then only an action is created.
1477 No spaces before and 1 after a comma
1478 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1479 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1480 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1481 Capitalize system variables - action only
1482 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1483 (if (not (equal select
'noaction
))
1485 (let* ((table (if select
'idlwave-indent-action-table
1486 'idlwave-indent-expand-table
))
1487 (cell (assoc key
(eval table
))))
1489 ;; Replace action command
1492 (set table
(append (eval table
) (list (cons key cmd
)))))))
1493 ;; Make key binding for action
1494 (if (or (and (null select
) (= (length key
) 1))
1495 (equal select
'noaction
)
1496 (equal select
'both
))
1497 (define-key idlwave-mode-map key
1500 (self-insert-command 1))
1501 (list (if (listp cmd
)
1505 (fset 'idlwave-debug-map
(make-sparse-keymap))
1507 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1508 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1509 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1510 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1511 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1512 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1513 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1514 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1515 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1516 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1517 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1518 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1519 (define-key idlwave-mode-map
"\M-\C-h" 'idlwave-mark-subprogram
)
1520 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1521 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1522 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1523 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1524 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1525 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1526 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1527 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1528 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1529 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1530 (define-key idlwave-mode-map
[(shift tab
)] 'idlwave-indent-statement
)
1531 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1532 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1533 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1534 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1535 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1536 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1537 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1538 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1539 (listp idlwave-shell-debug-modifiers
)
1540 (not (equal idlwave-shell-debug-modifiers
'())))
1541 ;; Bind the debug commands also with the special modifiers.
1542 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1543 (mods-noshift (delq 'shift
1544 (copy-sequence idlwave-shell-debug-modifiers
))))
1545 (define-key idlwave-mode-map
1546 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1547 'idlwave-shell-save-and-run
)
1548 (define-key idlwave-mode-map
1549 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1550 'idlwave-shell-break-here
)
1551 (define-key idlwave-mode-map
1552 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1553 'idlwave-shell-run-region
)))
1554 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1555 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1556 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1557 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1558 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1559 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1560 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1561 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1562 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1563 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1564 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1565 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1566 (autoload 'idlwave-shell
"idlw-shell"
1567 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1568 (autoload 'idlwave-shell-send-command
"idlw-shell")
1569 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1570 "Run `idlwave-shell' and switch back to current window" t
)
1571 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1572 "Save and run buffer under the shell." t
)
1573 (autoload 'idlwave-shell-break-here
"idlw-shell"
1574 "Set breakpoint in current line." t
)
1575 (autoload 'idlwave-shell-run-region
"idlw-shell"
1576 "Compile and run the region." t
)
1577 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1578 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1579 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1580 (define-key idlwave-mode-map
[(control meta ?
\?)] 'idlwave-online-help
)
1581 ;; Pickup both forms of Esc/Meta binding
1582 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1583 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1584 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1585 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1586 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1587 (define-key idlwave-mode-map
1588 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1589 'idlwave-mouse-context-help
)
1591 ;; Set action and key bindings.
1592 ;; See description of the function `idlwave-action-and-binding'.
1593 ;; Automatically add spaces for the following characters
1594 ;(idlwave-action-and-binding "&" '(idlwave-surround -1 -1 '(?&) 1
1595 ; (lambda (char) 0)))
1596 (idlwave-action-and-binding "<" '(idlwave-surround -
1 -
1))
1597 ;; Binding works for both > and ->, by changing the length of the token.
1598 (idlwave-action-and-binding ">" '(idlwave-surround -
1 -
1 '(?-
) 1
1599 'idlwave-gtr-pad-hook
))
1600 (idlwave-action-and-binding "->" '(idlwave-surround -
1 -
1 nil
2) t
)
1601 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1))
1603 ;; Automatically add spaces to equal sign if not keyword
1604 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1609 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1610 ;;; space is inserted (this is the space typed by the user to expanded
1613 (defvar idlwave-mode-abbrev-table nil
1614 "Abbreviation table used for IDLWAVE mode")
1615 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1617 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1618 "Define-abbrev with backward compatibility.
1620 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1621 idlwave-mode-abbrev-table unless TABLE is non-nil."
1622 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1623 (args (list (or table idlwave-mode-abbrev-table
)
1624 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1628 (apply 'define-abbrev
(append args
'(0 t
)))
1629 (error (apply 'define-abbrev args
)))))
1632 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1633 "w" idlwave-mode-syntax-table
)
1639 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1640 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1641 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1642 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1643 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1644 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1645 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1646 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1647 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1649 ;; Keywords, system functions, conversion routines
1651 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1652 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1653 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1654 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1655 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1656 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1657 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1658 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1659 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1660 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1661 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1662 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1663 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1664 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1665 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1666 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1667 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1668 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1669 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1670 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1671 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1672 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1673 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1676 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1677 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1678 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1679 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1680 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1681 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1682 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1683 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1684 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1685 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1686 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1687 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1688 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1689 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1690 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1691 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1692 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1695 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1696 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1698 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1699 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1700 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1701 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1704 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1706 ;; This section is reserved words only. (From IDL user manual)
1708 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1709 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1710 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1711 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1712 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1713 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1714 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1715 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1716 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1717 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1718 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1719 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1720 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1721 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1722 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1723 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1724 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1725 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1726 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1727 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1728 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1729 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1730 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1735 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1736 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1737 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1738 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1739 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1740 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1741 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1742 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1743 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1744 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1745 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1746 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1748 (defvar imenu-create-index-function
)
1749 (defvar extract-index-name-function
)
1750 (defvar prev-index-position-function
)
1751 (defvar imenu-extract-index-name-function
)
1752 (defvar imenu-prev-index-position-function
)
1753 ;; defined later - so just make the compiler hush
1754 (defvar idlwave-mode-menu
)
1755 (defvar idlwave-mode-debug-menu
)
1758 (defun idlwave-mode ()
1759 "Major mode for editing IDL source files (version 5.5).
1761 The main features of this mode are
1763 1. Indentation and Formatting
1764 --------------------------
1765 Like other Emacs programming modes, C-j inserts a newline and indents.
1766 TAB is used for explicit indentation of the current line.
1768 To start a continuation line, use \\[idlwave-split-line]. This
1769 function can also be used in the middle of a line to split the line
1770 at that point. When used inside a long constant string, the string
1771 is split at that point with the `+' concatenation operator.
1773 Comments are indented as follows:
1775 `;;;' Indentation remains unchanged.
1776 `;;' Indent like the surrounding code
1777 `;' Indent to a minimum column.
1779 The indentation of comments starting in column 0 is never changed.
1781 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1782 comment. The indentation of the second line of the paragraph
1783 relative to the first will be retained. Use
1784 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1785 comments. When the variable `idlwave-fill-comment-line-only' is
1786 nil, code can also be auto-filled and auto-indented.
1788 To convert pre-existing IDL code to your formatting style, mark the
1789 entire buffer with \\[mark-whole-buffer] and execute
1790 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1791 again followed by \\[indent-region] (`indent-region').
1795 IDLWAVE displays information about the calling sequence and the
1796 accepted keyword parameters of a procedure or function with
1797 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1798 source file of a module. These commands know about system
1799 routines, all routines in idlwave-mode buffers and (when the
1800 idlwave-shell is active) about all modules currently compiled under
1801 this shell. It also makes use of pre-compiled or custom-scanned
1802 user and library catalogs many popular libraries ship with by
1803 default. Use \\[idlwave-update-routine-info] to update this
1804 information, which is also used for completion (see item 4).
1808 \\[idlwave-context-help] displays the IDL documentation relevant
1809 for the system variable, keyword, or routine at point. A single
1810 key stroke gets you directly to the right place in the docs. The
1811 HTML help files package must be installed for this to work -- check
1812 the IDLWAVE webpage for the correct package for your version. See
1813 the manual to configure where and how the HTML help is displayed.
1817 \\[idlwave-complete] completes the names of procedures, functions
1818 class names, keyword parameters, system variables and tags, class
1819 tags, structure tags, filenames and much more. It is context
1820 sensitive and figures out what is expected at point. Lower case
1821 strings are completed in lower case, other strings in mixed or
1824 5. Code Templates and Abbreviations
1825 --------------------------------
1826 Many Abbreviations are predefined to expand to code fragments and templates.
1827 The abbreviations start generally with a `\\`. Some examples
1829 \\pr PROCEDURE template
1830 \\fu FUNCTION template
1831 \\c CASE statement template
1832 \\sw SWITCH statement template
1833 \\f FOR loop template
1834 \\r REPEAT Loop template
1835 \\w WHILE loop template
1836 \\i IF statement template
1837 \\elif IF-ELSE statement template
1840 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1841 have direct keybindings - see the list of keybindings below.
1843 \\[idlwave-doc-header] inserts a documentation header at the
1844 beginning of the current program unit (pro, function or main).
1845 Change log entries can be added to the current program unit with
1846 \\[idlwave-doc-modification].
1848 6. Automatic Case Conversion
1849 -------------------------
1850 The case of reserved words and some abbrevs is controlled by
1851 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1853 7. Automatic END completion
1854 ------------------------
1855 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1856 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1860 Loading idlwave.el runs `idlwave-load-hook'.
1861 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1863 9. Documentation and Customization
1864 -------------------------------
1865 Info documentation for this package is available. Use
1866 \\[idlwave-info] to display (complain to your sysadmin if that does
1867 not work). For Postscript, PDF, and HTML versions of the
1868 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1869 IDLWAVE has customize support - see the group `idlwave'.
1873 Here is a list of all keybindings of this mode.
1874 If some of the key bindings below show with ??, use \\[describe-key]
1875 followed by the key sequence to see what the key sequence does.
1877 \\{idlwave-mode-map}"
1880 (kill-all-local-variables)
1882 (if idlwave-startup-message
1883 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1884 (setq idlwave-startup-message nil
)
1886 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1887 (set-syntax-table idlwave-mode-syntax-table
)
1889 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1891 (make-local-variable idlwave-comment-indent-function
)
1892 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1894 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1895 (set (make-local-variable 'comment-start
) ";")
1896 (set (make-local-variable 'require-final-newline
) mode-require-final-newline
)
1897 (set (make-local-variable 'abbrev-all-caps
) t
)
1898 (set (make-local-variable 'indent-tabs-mode
) nil
)
1899 (set (make-local-variable 'completion-ignore-case
) t
)
1901 (use-local-map idlwave-mode-map
)
1903 (when (featurep 'easymenu
)
1904 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1905 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1907 (setq mode-name
"IDLWAVE")
1908 (setq major-mode
'idlwave-mode
)
1909 (setq abbrev-mode t
)
1911 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1912 (setq comment-end
"")
1913 (set (make-local-variable 'comment-multi-line
) nil
)
1914 (set (make-local-variable 'paragraph-separate
)
1915 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1916 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1917 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1918 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1920 ;; Set tag table list to use IDLTAGS as file name.
1921 (if (boundp 'tag-table-alist
)
1922 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1924 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1925 ;; Following line is for Emacs - XEmacs uses the corresponding property
1926 ;; on the `idlwave-mode' symbol.
1927 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1930 (set (make-local-variable 'imenu-create-index-function
)
1931 'imenu-default-create-index-function
)
1932 (set (make-local-variable 'imenu-extract-index-name-function
)
1934 (set (make-local-variable 'imenu-prev-index-position-function
)
1935 'idlwave-prev-index-position
)
1937 ;; Make a local post-command-hook and add our hook to it
1938 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1939 (make-local-hook 'post-command-hook
)
1940 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1942 ;; Make local hooks for buffer updates
1943 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1944 (make-local-hook 'kill-buffer-hook
)
1945 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1946 (make-local-hook 'after-save-hook
)
1947 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1948 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1950 ;; Setup directories and file, if necessary
1953 ;; Update the routine info with info about current buffer?
1954 (idlwave-new-buffer-update)
1956 ;; Run the mode hook
1957 (run-mode-hooks 'idlwave-mode-hook
))
1959 (defvar idlwave-setup-done nil
)
1960 (defun idlwave-setup ()
1961 (unless idlwave-setup-done
1962 (if (not (file-directory-p idlwave-config-directory
))
1963 (make-directory idlwave-config-directory
))
1964 (setq idlwave-user-catalog-file
(expand-file-name
1965 idlwave-user-catalog-file
1966 idlwave-config-directory
)
1967 idlwave-path-file
(expand-file-name
1969 idlwave-config-directory
))
1970 (idlwave-read-paths) ; we may need these early
1971 (setq idlwave-setup-done t
)))
1974 ;; Code Formatting ----------------------------------------------------
1977 (defun idlwave-push-mark (&rest rest
)
1978 "Push mark for compatibility with Emacs 18/19."
1979 (if (fboundp 'iconify-frame
)
1980 (apply 'push-mark rest
)
1983 (defun idlwave-hard-tab ()
1984 "Inserts TAB in buffer in current position."
1988 ;;; This stuff is experimental
1990 (defvar idlwave-command-hook nil
1991 "If non-nil, a list that can be evaluated using `eval'.
1992 It is evaluated in the lisp function `idlwave-command-hook' which is
1993 placed in `post-command-hook'.")
1995 (defun idlwave-command-hook ()
1996 "Command run after every command.
1997 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
1998 sets the variable to zero afterwards."
1999 (and idlwave-command-hook
2000 (listp idlwave-command-hook
)
2002 (eval idlwave-command-hook
)
2004 (setq idlwave-command-hook nil
))
2008 ;; It would be better to use expand.el for better abbrev handling and
2011 (defun idlwave-check-abbrev (arg &optional reserved
)
2012 "Reverses abbrev expansion if in comment or string.
2013 Argument ARG is the number of characters to move point
2014 backward if `idlwave-abbrev-move' is non-nil.
2015 If optional argument RESERVED is non-nil then the expansion
2016 consists of reserved words, which will be capitalized if
2017 `idlwave-reserved-word-upcase' is non-nil.
2018 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2019 is non-nil, unless its value is \`down in which case the abbrev will be
2020 made into all lowercase.
2021 Returns non-nil if abbrev is left expanded."
2022 (if (idlwave-quoted)
2023 (progn (unexpand-abbrev)
2025 (if (and reserved idlwave-reserved-word-upcase
)
2026 (upcase-region last-abbrev-location
(point))
2028 ((equal idlwave-abbrev-change-case
'down
)
2029 (downcase-region last-abbrev-location
(point)))
2030 (idlwave-abbrev-change-case
2031 (upcase-region last-abbrev-location
(point)))))
2032 (if (and idlwave-abbrev-move
(> arg
0))
2033 (if (boundp 'post-command-hook
)
2034 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2035 (backward-char arg
)))
2038 (defun idlwave-in-comment ()
2039 "Returns t if point is inside a comment, nil otherwise."
2041 (let ((here (point)))
2042 (and (idlwave-goto-comment) (> here
(point))))))
2044 (defun idlwave-goto-comment ()
2045 "Move to start of comment delimiter on current line.
2046 Moves to end of line if there is no comment delimiter.
2047 Ignores comment delimiters in strings.
2048 Returns point if comment found and nil otherwise."
2049 (let ((eos (progn (end-of-line) (point)))
2052 ;; Look for first comment delimiter not in a string
2054 (setq found
(search-forward comment-start eos
'lim
))
2055 (while (and found
(idlwave-in-quote))
2056 (setq found
(search-forward comment-start eos
'lim
)))
2057 (store-match-data data
)
2058 (and found
(not (idlwave-in-quote))
2063 (defvar transient-mark-mode
)
2064 (defvar zmacs-regions
)
2065 (defvar mark-active
)
2066 (defun idlwave-region-active-p ()
2067 "Is transient-mark-mode on and the region active?
2068 Works on both Emacs and XEmacs."
2069 (if (featurep 'xemacs
)
2070 (and zmacs-regions
(region-active-p))
2071 (and transient-mark-mode mark-active
)))
2073 (defun idlwave-show-matching-quote ()
2074 "Insert quote and show matching quote if this is end of a string."
2076 (let ((bq (idlwave-in-quote))
2077 (inq last-command-char
))
2078 (if (and bq
(not (idlwave-in-comment)))
2079 (let ((delim (char-after bq
)))
2085 ;; Not the end of a string
2088 (defun idlwave-show-begin-check ()
2089 "Ensure that the previous word was a token before `idlwave-show-begin'.
2090 An END token must be preceded by whitespace."
2091 (if (not (idlwave-quoted))
2096 (looking-at "[ \t\n\f]"))
2097 (idlwave-show-begin))))
2099 (defun idlwave-show-begin ()
2100 "Finds the start of current block and blinks to it for a second.
2101 Also checks if the correct end statement has been used."
2102 ;; All end statements are reserved words
2103 ;; Re-indent end line
2104 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2106 (let* ((pos (point-marker))
2107 (last-abbrev-marker (copy-marker last-abbrev-location
))
2108 (eol-pos (save-excursion (end-of-line) (point)))
2109 begin-pos end-pos end end1
)
2110 (if idlwave-reindent-end
(idlwave-indent-line))
2111 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2112 (when (and (idlwave-check-abbrev 0 t
)
2115 ;; Move inside current block
2116 (goto-char last-abbrev-marker
)
2117 (idlwave-block-jump-out -
1 'nomark
)
2118 (setq begin-pos
(point))
2119 (idlwave-block-jump-out 1 'nomark
)
2120 (setq end-pos
(point))
2121 (if (> end-pos eol-pos
)
2124 (setq end
(buffer-substring
2126 (skip-chars-backward "a-zA-Z")
2129 (goto-char begin-pos
)
2130 (when (setq end1
(cdr (idlwave-block-master)))
2132 ((null end1
)) ; no-operation
2133 ((string= (downcase end
) (downcase end1
))
2135 ((string= (downcase end
) "end")
2137 (if idlwave-expand-generic-end
2141 (insert (if (string= end
"END") (upcase end1
) end1
))
2146 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2151 (defun idlwave-block-master ()
2152 (let ((case-fold-search t
))
2155 ((looking-at "pro\\|case\\|switch\\|function\\>")
2156 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2157 ((looking-at "begin\\>")
2158 (let ((limit (save-excursion
2159 (idlwave-beginning-of-statement)
2162 ((re-search-backward ":[ \t]*\\=" limit t
)
2163 ;; seems to be a case thing
2165 ((re-search-backward idlwave-block-match-regexp limit t
)
2166 (assoc (downcase (match-string 1))
2167 idlwave-block-matches
))
2169 ;; Just a normal block
2170 '("begin" .
"end")))))
2173 (defun idlwave-close-block ()
2174 "Terminate the current block with the correct END statement."
2177 ;; Start new line if we are not in a new line
2178 (unless (save-excursion
2179 (skip-chars-backward " \t")
2181 (let ((idlwave-show-block nil
))
2182 (newline-and-indent)))
2183 (let ((last-abbrev-location (point))) ; for upcasing
2185 (idlwave-show-begin)))
2187 (defun idlwave-gtr-pad-hook (char)
2188 "Let the > symbol expand around -> if present. The new token length
2192 (defun idlwave-surround (&optional before after escape-chars length ec-hook
)
2193 "Surround the LENGTH characters before point with blanks.
2194 LENGTH defaults to 1.
2195 Optional arguments BEFORE and AFTER affect the behavior before and
2196 after the characters (see also description of `idlwave-make-space'):
2200 integer > 0 force exactly n spaces
2201 integer < 0 at least |n| spaces
2203 The function does nothing if any of the following conditions is true:
2204 - `idlwave-surround-by-blank' is nil
2205 - the character before point is inside a string or comment
2206 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2207 This hack is used to avoid padding of `>' when it is part of
2208 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2210 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2211 the named function will be called with a single argument of the
2212 preceeding character. Then idlwave-surround will run as usual if
2213 EC-HOOK returns non-nil, and a new length will be taken from the
2215 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2216 (let* ((length (or length
1)) ; establish a default for LENGTH
2217 (prev-char (char-after (- (point) (1+ length
)))))
2218 (when (or (not (memq prev-char escape-chars
))
2219 (and (fboundp ec-hook
)
2221 (save-excursion (funcall ec-hook prev-char
)))))
2222 (backward-char length
)
2224 (let ((here (point)))
2225 (skip-chars-backward " \t")
2227 ;; avoid clobbering indent
2229 (move-to-column (idlwave-calculate-indent))
2230 (if (<= (point) here
)
2231 (narrow-to-region (point) here
))
2233 (idlwave-make-space before
))
2234 (skip-chars-forward " \t"))
2235 (forward-char length
)
2236 (idlwave-make-space after
)
2237 ;; Check to see if the line should auto wrap
2238 (if (and (equal (char-after (1- (point))) ?\
)
2239 (> (current-column) fill-column
))
2240 (funcall auto-fill-function
))))))
2242 (defun idlwave-make-space (n)
2243 "Make space at point.
2244 The space affected is all the spaces and tabs around point.
2245 If n is non-nil then point is left abs(n) spaces from the beginning of
2246 the contiguous space.
2247 The amount of space at point is determined by N.
2248 If the value of N is:
2250 > 0 - exactly N spaces.
2251 < 0 - a minimum of -N spaces, i.e., do not change if there are
2253 0 - no spaces (i.e. remove any existing space)."
2256 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2258 (end-col (progn (skip-chars-forward " \t") (current-column))))
2259 (delete-horizontal-space)
2262 (idlwave-indent-to (+ start-col n
))
2263 (goto-char (+ left n
)))
2265 (idlwave-indent-to end-col
(- n
))
2266 (goto-char (- left n
)))
2270 (defun idlwave-newline ()
2271 "Inserts a newline and indents the current and previous line."
2274 ;; Handle unterminated single and double quotes
2275 ;; If not in a comment and in a string then insertion of a newline
2276 ;; will mean unbalanced quotes.
2278 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2280 (message "Warning: unbalanced quotes?")))
2283 ;; The current line is being split, the cursor should be at the
2284 ;; beginning of the new line skipping the leading indentation.
2286 ;; The reason we insert the new line before indenting is that the
2287 ;; indenting could be confused by keywords (e.g. END) on the line
2288 ;; after the split point. This prevents us from just using
2289 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2291 (beginning-of-line 0)
2292 (idlwave-indent-line)
2294 (idlwave-indent-line))
2297 ;; Use global variable 'comment-column' to set parallel comment
2299 ;; Modeled on lisp.el
2300 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2301 (defun idlwave-comment-hook ()
2302 "Compute indent for the beginning of the IDL comment delimiter."
2303 (if (or (looking-at idlwave-no-change-comment
)
2304 (if idlwave-begin-line-comment
2305 (looking-at idlwave-begin-line-comment
)
2308 (if (looking-at idlwave-code-comment
)
2309 (if (save-excursion (skip-chars-backward " \t") (bolp))
2310 ;; On line by itself, indent as code
2311 (let ((tem (idlwave-calculate-indent)))
2312 (if (listp tem
) (car tem
) tem
))
2313 ;; after code - do not change
2315 (skip-chars-backward " \t")
2316 (max (if (bolp) 0 (1+ (current-column)))
2319 (defun idlwave-split-line ()
2320 "Continue line by breaking line at point and indent the lines.
2321 For a code line insert continuation marker. If the line is a line comment
2322 then the new line will contain a comment with the same indentation.
2323 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2326 ;; Expand abbreviation, just like normal RET would.
2327 (and abbrev-mode
(expand-abbrev))
2329 (if (not (idlwave-in-comment))
2330 ;; For code line add continuation.
2331 ;; Check if splitting a string.
2333 (if (setq beg
(idlwave-in-quote))
2334 (if idlwave-split-line-string
2335 ;; Split the string.
2336 (progn (insert (setq beg
(char-after beg
)) " + "
2337 idlwave-continuation-char beg
)
2339 (newline-and-indent)
2341 ;; Do not split the string.
2343 (message "Warning: continuation inside string!!")
2344 (insert " " idlwave-continuation-char
))
2345 ;; Not splitting a string.
2346 (if (not (member (char-before) '(?\ ?
\t)))
2348 (insert idlwave-continuation-char
)
2349 (newline-and-indent)))
2350 (indent-new-comment-line))
2351 ;; Indent previous line
2352 (setq beg
(- (point-max) (point)))
2354 (idlwave-indent-line)
2355 (goto-char (- (point-max) beg
))
2356 ;; Reindent new line
2357 (idlwave-indent-line)))
2359 (defun idlwave-beginning-of-subprogram ()
2360 "Moves point to the beginning of the current program unit."
2362 (idlwave-find-key idlwave-begin-unit-reg -
1))
2364 (defun idlwave-end-of-subprogram ()
2365 "Moves point to the start of the next program unit."
2367 (idlwave-end-of-statement)
2368 (idlwave-find-key idlwave-end-unit-reg
1))
2370 (defun idlwave-mark-statement ()
2371 "Mark current IDL statement."
2373 (idlwave-end-of-statement)
2374 (let ((end (point)))
2375 (idlwave-beginning-of-statement)
2376 (idlwave-push-mark end nil t
)))
2378 (defun idlwave-mark-block ()
2379 "Mark containing block."
2381 (idlwave-end-of-statement)
2382 (idlwave-backward-up-block -
1)
2383 (idlwave-end-of-statement)
2384 (let ((end (point)))
2385 (idlwave-backward-block)
2386 (idlwave-beginning-of-statement)
2387 (idlwave-push-mark end nil t
)))
2390 (defun idlwave-mark-subprogram ()
2391 "Put mark at beginning of program, point at end.
2392 The marks are pushed."
2394 (idlwave-end-of-statement)
2395 (idlwave-beginning-of-subprogram)
2396 (let ((beg (point)))
2397 (idlwave-forward-block)
2398 (idlwave-push-mark beg nil t
))
2399 (exchange-point-and-mark))
2401 (defun idlwave-backward-up-block (&optional arg
)
2402 "Move to beginning of enclosing block if prefix ARG >= 0.
2403 If prefix ARG < 0 then move forward to enclosing block end."
2405 (idlwave-block-jump-out (- arg
) 'nomark
))
2407 (defun idlwave-beginning-of-block ()
2408 "Go to the beginning of the current block."
2410 (idlwave-block-jump-out -
1 'nomark
)
2413 (defun idlwave-end-of-block ()
2414 "Go to the beginning of the current block."
2416 (idlwave-block-jump-out 1 'nomark
)
2419 (defun idlwave-forward-block ()
2420 "Move across next nested block."
2422 (if (idlwave-down-block 1)
2423 (idlwave-block-jump-out 1 'nomark
)))
2425 (defun idlwave-backward-block ()
2426 "Move backward across previous nested block."
2428 (if (idlwave-down-block -
1)
2429 (idlwave-block-jump-out -
1 'nomark
)))
2431 (defun idlwave-down-block (&optional arg
)
2433 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2434 Returns non-nil if successfull."
2439 (let ((eos (save-excursion
2440 (idlwave-block-jump-out -
1 'nomark
)
2442 (if (setq status
(idlwave-find-key
2443 idlwave-end-block-reg -
1 'nomark eos
))
2444 (idlwave-beginning-of-statement)
2445 (message "No nested block before beginning of containing block.")))
2447 (let ((eos (save-excursion
2448 (idlwave-block-jump-out 1 'nomark
)
2450 (if (setq status
(idlwave-find-key
2451 idlwave-begin-block-reg
1 'nomark eos
))
2452 (idlwave-end-of-statement)
2453 (message "No nested block before end of containing block."))))
2456 (defun idlwave-mark-doclib ()
2457 "Put point at beginning of doc library header, mark at end.
2458 The marks are pushed."
2462 (goto-char (point-max))
2463 (if (re-search-backward idlwave-doclib-start nil t
)
2465 (setq beg
(progn (beginning-of-line) (point)))
2466 (if (re-search-forward idlwave-doclib-end nil t
)
2469 (idlwave-push-mark beg nil t
)
2470 (message "Could not find end of doc library header.")))
2471 (message "Could not find doc library header start.")
2472 (goto-char here
)))))
2475 (defun idlwave-current-routine ()
2476 "Return (NAME TYPE CLASS) of current routine."
2479 (idlwave-beginning-of-subprogram)
2480 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2481 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2483 (class (idlwave-sintern-class (match-string 3)))
2484 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2485 (list name type class
)))))
2487 (defvar idlwave-shell-prompt-pattern
)
2488 (defun idlwave-beginning-of-statement ()
2489 "Move to beginning of the current statement.
2490 Skips back past statement continuations.
2491 Point is placed at the beginning of the line whether or not this is an
2495 ((eq major-mode
'idlwave-shell-mode
)
2496 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2497 (goto-char (match-end 0))))
2499 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2500 (idlwave-previous-statement)
2501 (beginning-of-line)))))
2503 (defun idlwave-previous-statement ()
2504 "Moves point to beginning of the previous statement.
2505 Returns t if the current line before moving is the beginning of
2506 the first non-comment statement in the file, and nil otherwise."
2508 (let (first-statement)
2509 (if (not (= (forward-line -
1) 0))
2510 ;; first line in file
2512 ;; skip blank lines, label lines, include lines and line comments
2514 ;; The current statement is the first statement until we
2515 ;; reach another statement.
2516 (setq first-statement
2518 (looking-at idlwave-comment-line-start-skip
)
2519 (looking-at "[ \t]*$")
2520 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2522 (= (forward-line -
1) 0)))
2523 ;; skip continuation lines
2527 (idlwave-is-continuation-line))
2528 (= (forward-line -
1) 0)))
2531 (defun idlwave-end-of-statement ()
2532 "Moves point to the end of the current IDL statement.
2533 If not in a statement just moves to end of line. Returns position."
2535 (while (and (idlwave-is-continuation-line)
2536 (= (forward-line 1) 0))
2537 (while (and (idlwave-is-comment-or-empty-line)
2538 (= (forward-line 1) 0))))
2542 (defun idlwave-end-of-statement0 ()
2543 "Moves point to the end of the current IDL statement.
2544 If not in a statement just moves to end of line. Returns position."
2546 (while (and (idlwave-is-continuation-line)
2547 (= (forward-line 1) 0)))
2551 (defun idlwave-next-statement ()
2552 "Moves point to beginning of the next IDL statement.
2553 Returns t if that statement is the last
2554 non-comment IDL statement in the file, and nil otherwise."
2556 (let (last-statement)
2557 (idlwave-end-of-statement)
2558 ;; skip blank lines, label lines, include lines and line comments
2559 (while (and (= (forward-line 1) 0)
2560 ;; The current statement is the last statement until
2561 ;; we reach a new statement.
2562 (setq last-statement
2564 (looking-at idlwave-comment-line-start-skip
)
2565 (looking-at "[ \t]*$")
2566 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2567 (looking-at "^@")))))
2570 (defun idlwave-skip-multi-commands (&optional lim
)
2571 "Skip past multiple commands on a line (with `&')."
2572 (let ((save-point (point)))
2573 (when (re-search-forward ".*&" lim t
)
2574 (goto-char (match-end 0))
2575 (if (idlwave-quoted)
2576 (goto-char save-point
)
2577 (if (eq (char-after (- (point) 2)) ?
&) (goto-char save-point
))))
2580 (defun idlwave-skip-label-or-case ()
2581 "Skip label or case statement element.
2582 Returns position after label.
2583 If there is no label point is not moved and nil is returned."
2584 ;; Case expressions and labels are terminated by a colon.
2585 ;; So we find the first colon in the line and make sure
2586 ;; - no `?' is before it (might be a ? b : c)
2587 ;; - it is not in a comment
2588 ;; - not in a string constant
2589 ;; - not in parenthesis (like a[0:3])
2590 ;; - not followed by another ":" in explicit class, ala a->b::c
2591 ;; As many in this mode, this function is heuristic and not an exact
2593 (let* ((start (point))
2594 (eos (save-excursion (idlwave-end-of-statement) (point)))
2595 (end (idlwave-find-key ":" 1 'nomark eos
)))
2597 (= (nth 0 (parse-partial-sexp start end
)) 0)
2598 (not (string-match "\\?" (buffer-substring start end
)))
2599 (not (string-match "^::" (buffer-substring end eos
))))
2606 (defun idlwave-start-of-substatement (&optional pre
)
2607 "Move to start of next IDL substatement after point.
2608 Uses the type of the current IDL statement to determine if the next
2609 statement is on a new line or is a subpart of the current statement.
2610 Returns point at start of substatement modulo whitespace.
2611 If optional argument is non-nil move to beginning of current
2613 (let ((orig (point))
2614 (eos (idlwave-end-of-statement))
2617 (idlwave-beginning-of-statement)
2618 (idlwave-skip-label-or-case)
2619 (if (< (point) orig
)
2620 (idlwave-skip-multi-commands orig
))
2622 ;; Continue looking for substatements until we are past orig
2623 (while (and (<= (point) orig
) (not (eobp)))
2625 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2626 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2628 (idlwave-find-key nst
1 'nomark eos
))
2629 (goto-char (match-end 0)))
2630 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2631 (setq ifnest
(1- ifnest
))
2632 (goto-char (match-end 0)))
2634 (idlwave-next-statement))))
2635 (if pre
(goto-char last
))
2636 ;; If a continuation line starts here, move to next line
2637 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2638 (beginning-of-line 2))
2641 (defun idlwave-statement-type ()
2642 "Return the type of the current IDL statement.
2643 Uses `idlwave-statement-match' to return a cons of (type . point) with
2644 point the ending position where the type was determined. Type is the
2645 association from `idlwave-statement-match', i.e. the cons cell from the
2646 list not just the type symbol. Returns nil if not an identifiable
2649 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2650 ;; and possibly comments
2651 (while (looking-at "[ \t]*\\$")
2653 (skip-chars-forward " \t")
2654 (let ((st idlwave-statement-match
)
2655 (case-fold-search t
))
2656 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2657 (setq st
(cdr st
))))
2659 (append st
(match-end 0))))))
2661 (defun idlwave-expand-equal (&optional before after
)
2662 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2663 assignment. Which case is determined using
2664 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2665 equal sign will be surrounded by BEFORE and AFTER blanks. If
2666 `idlwave-pad-keyword' is t then keyword assignment is treated just
2667 like assignment statements. When nil, spaces are removed for keyword
2668 assignment. Any other value keeps the current space around the `='.
2669 Limits in for loops are treated as keyword assignment.
2671 Starting with IDL 6.0, a number of op= assignments are available.
2672 Since ambiguities of the form:
2677 can occur, alphanumeric operator assignment will never be pre-padded,
2678 only post-padded. You must use a space before these to disambiguate
2679 \(not just for padding, but for proper parsing by IDL too!). Other
2680 operators, such as ##=, ^=, etc., will be pre-padded.
2682 See `idlwave-surround'."
2683 (if idlwave-surround-by-blank
2685 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2687 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2691 (let ((case-fold-search t
))
2694 (re-search-backward non-an-ops nil t
)
2695 ;; Why doesn't ##? work for both?
2696 (re-search-backward "\\(#\\)\\=" nil t
))
2697 (setq len
(1+ (length (match-string 1))))
2698 (when (re-search-backward an-ops nil t
)
2699 (setq begin nil
) ; won't modify begin
2700 (setq len
(1+ (length (match-string 1))))))))
2702 (if (eq t idlwave-pad-keyword
)
2703 ;; Everything gets padded equally
2704 (idlwave-surround before after nil len
)
2705 ;; Treating keywords/for variables specially...
2706 (let ((st (save-excursion ; To catch "for" variables
2707 (idlwave-start-of-substatement t
)
2708 (idlwave-statement-type)))
2709 (what (save-excursion ; To catch keywords
2710 (skip-chars-backward "= \t")
2711 (nth 2 (idlwave-where)))))
2712 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2713 (memq (caar st
) '(for pdef
)))
2715 ((null idlwave-pad-keyword
)
2716 (idlwave-surround 0 0)
2718 (t))) ; leave any spaces alone
2719 (t (idlwave-surround before after nil len
))))))))
2722 (defun idlwave-indent-and-action (&optional arg
)
2723 "Call `idlwave-indent-line' and do expand actions.
2724 With prefix ARG non-nil, indent the entire sub-statement."
2727 (if (and idlwave-expand-generic-end
2728 (re-search-backward "\\<\\(end\\)\\s-*\\="
2729 (max 0 (- (point) 10)) t
)
2730 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2731 (progn (goto-char (match-end 1))
2732 ;;Expand the END abbreviation, just as RET or Space would have.
2733 (if abbrev-mode
(expand-abbrev)
2734 (idlwave-show-begin)))))
2735 (when (and (not arg
) current-prefix-arg
)
2736 (setq arg current-prefix-arg
)
2737 (setq current-prefix-arg nil
))
2739 (idlwave-indent-statement)
2740 (idlwave-indent-line t
)))
2742 (defun idlwave-indent-line (&optional expand
)
2743 "Indents current IDL line as code or as a comment.
2744 The actions in `idlwave-indent-action-table' are performed.
2745 If the optional argument EXPAND is non-nil then the actions in
2746 `idlwave-indent-expand-table' are performed."
2748 ;; Move point out of left margin.
2750 (skip-chars-backward " \t")
2752 (skip-chars-forward " \t"))
2753 (let ((mloc (point-marker)))
2756 (if (looking-at idlwave-comment-line-start-skip
)
2757 ;; Indentation for a line comment
2759 (skip-chars-forward " \t")
2760 (idlwave-indent-left-margin (idlwave-comment-hook)))
2764 ;; Before indenting, run action routines.
2766 (if (and expand idlwave-do-actions
)
2767 (mapcar 'idlwave-do-action idlwave-indent-expand-table
))
2769 (if idlwave-do-actions
2770 (mapcar 'idlwave-do-action idlwave-indent-action-table
))
2772 ;; No longer expand abbrevs on the line. The user can do this
2773 ;; manually using expand-region-abbrevs.
2775 ;; Indent for code line
2780 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2782 (looking-at "^[ \t]*@"))
2786 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2787 ;; Adjust parallel comment
2789 (if (idlwave-in-comment)
2790 ;; Emacs 21 is too smart with fill-column on comment indent
2791 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2794 (indent-for-comment)))))
2796 ;; Get rid of marker
2797 (set-marker mloc nil
)))
2799 (defun idlwave-do-action (action)
2800 "Perform an action repeatedly on a line.
2801 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2802 either a function name to be called with `funcall' or a list to be
2803 evaluated with `eval'. The action performed by FUNC should leave point
2804 after the match for REG - otherwise an infinite loop may be entered."
2805 (let ((action-key (car action
))
2806 (action-routine (cdr action
)))
2808 (while (idlwave-look-at action-key
)
2809 (if (listp action-routine
)
2810 (eval action-routine
)
2811 (funcall action-routine
)))))
2813 (defun idlwave-indent-to (col &optional min
)
2814 "Indent from point with spaces until column COL.
2815 Inserts space before markers at point."
2816 (if (not min
) (setq min
0))
2817 (insert-before-markers
2818 (make-string (max min
(- col
(current-column))) ?\
)))
2820 (defun idlwave-indent-left-margin (col)
2821 "Indent the current line to column COL.
2822 Indents such that first non-whitespace character is at column COL
2823 Inserts spaces before markers at point."
2826 (delete-horizontal-space)
2827 (idlwave-indent-to col
)))
2829 (defun idlwave-indent-subprogram ()
2830 "Indents program unit which contains point."
2833 (idlwave-end-of-statement)
2834 (idlwave-beginning-of-subprogram)
2835 (let ((beg (point)))
2836 (idlwave-forward-block)
2837 (message "Indenting subprogram...")
2838 (indent-region beg
(point) nil
))
2839 (message "Indenting subprogram...done.")))
2841 (defun idlwave-indent-statement ()
2842 "Indent current statement, including all continuation lines."
2845 (idlwave-beginning-of-statement)
2846 (let ((beg (point)))
2847 (idlwave-end-of-statement)
2848 (indent-region beg
(point) nil
))))
2850 (defun idlwave-calculate-indent ()
2851 "Return appropriate indentation for current line as IDL code."
2855 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2857 ((idlwave-look-at idlwave-begin-unit-reg
)
2859 ;; Check for continuation line
2861 (and (= (forward-line -
1) 0)
2862 (idlwave-is-continuation-line)))
2863 (idlwave-calculate-cont-indent))
2864 ;; calculate indent based on previous and current statements
2865 (t (let* (beg-prev-pos
2867 ;; calculate indent based on previous statement
2870 ;; Beginning of file
2872 (idlwave-previous-statement)
2873 (setq beg-prev-pos
(point)))
2876 ((idlwave-look-at idlwave-begin-unit-reg t
)
2877 (+ (idlwave-current-statement-indent)
2878 idlwave-main-block-indent
))
2880 ((idlwave-look-at idlwave-begin-block-reg t
)
2881 (+ (idlwave-min-current-statement-indent)
2882 idlwave-block-indent
))
2884 ((idlwave-look-at idlwave-end-block-reg t
)
2886 ;; Match to the *beginning* of the block opener
2887 (goto-char beg-prev-pos
)
2888 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2889 (idlwave-min-current-statement-indent)))
2890 ;; idlwave-end-offset
2891 ;; idlwave-block-indent))
2893 ;; Default to current indent
2894 ((idlwave-current-statement-indent))))))
2895 ;; adjust the indentation based on the current statement
2898 ((idlwave-look-at idlwave-end-block-reg
)
2899 (+ the-indent idlwave-end-offset
))
2903 ;; Parentheses indent
2906 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2907 "Calculate the continuation indent inside a paren group.
2908 Returns a cons-cell with (open . indent), where open is the
2909 location of the open paren"
2910 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2911 ;; Found an innermost open paren.
2914 ;; Line up with next word unless this is a closing paren.
2917 ;; Plain Kernighan-style nested indent
2918 (idlwave-indent-parens-nested
2919 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2921 ;; This is a closed paren - line up under open paren.
2925 ;; Empty (or just comment) follows -- revert to basic indent
2929 (looking-at "[ \t$]*\\(;.*\\)?$"))
2932 ;; Line up with first word after any blank space
2934 (skip-chars-forward " \t")
2935 (current-column))))))))
2937 (defun idlwave-calculate-cont-indent ()
2938 "Calculates the IDL continuation indent column from the previous
2939 statement. Note that here previous statement usually means the
2940 beginning of the current statement if this statement is a continuation
2941 of the previous line. Various special types of continuations,
2942 including assignments, routine definitions, and parenthetical
2943 groupings, are treated separately."
2945 (let* ((case-fold-search t
)
2946 (end-reg (progn (beginning-of-line) (point)))
2947 (beg-last-statement (save-excursion (idlwave-previous-statement)
2949 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
2950 (if (eq (line-beginning-position) end-reg
)
2951 (goto-char beg-last-statement
)
2953 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
2954 idlwave-continuation-indent
))
2955 fancy-nonparen-indent fancy-paren-indent
)
2957 ;; Align then with its matching if, etc.
2958 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
2959 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
2960 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
2961 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2963 ("\\<case\\>" .
"[ \t]*of")))
2969 (while (setq match
(car matchers
))
2970 (if (looking-at (cdr match
))
2971 (throw 'exit
(car match
)))
2972 (setq matchers
(cdr matchers
)))))
2973 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
2974 (if (looking-at "end") ;; that one's special
2975 (- (idlwave-current-indent)
2976 (+ idlwave-block-indent idlwave-end-offset
))
2977 (idlwave-current-indent)))
2979 ;; Indent in from the previous line for continuing statements
2980 ((let ((matchers '("\\<then\\>"
2987 (if (/= (forward-line -
1) 0)
2989 (while (setq match
(car matchers
))
2990 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
2993 (setq matchers
(cdr matchers
)))))
2994 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2996 ;; Parenthetical indent, either traditional or Kernighan style
2997 ((setq fancy-paren-indent
2998 (let* ((end-reg end-reg
)
3001 (skip-chars-forward " \t")
3002 (looking-at "\\s)")))
3005 (while (setq indent-cons
(idlwave-calculate-paren-indent
3006 beg-reg end-reg close-exp
))
3007 ;; First permitted containing paren
3009 idlwave-indent-to-open-paren
3010 idlwave-indent-parens-nested
3011 (null (cdr indent-cons
))
3012 (< (- (cdr indent-cons
) basic-indent
)
3013 idlwave-max-extra-continuation-indent
))
3014 (throw 'loop
(cdr indent-cons
)))
3015 (setq end-reg
(car indent-cons
))))))
3018 ;; A continued assignment, or procedure call/definition
3020 (> idlwave-max-extra-continuation-indent
0)
3021 (setq fancy-nonparen-indent
3024 (while (idlwave-look-at "&")) ; skip continued statements
3026 ;; A continued Procedure call or definition
3028 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3029 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3030 (goto-char (match-end 0))
3031 ;; Comment only, or blank line with "$"? Basic indent.
3032 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3036 ;; Continued assignment (with =):
3038 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3039 (goto-char (match-end 0))
3040 (if (null (idlwave-what-function beg-reg
))
3041 (throw 'assign t
))))
3044 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3046 (goto-char beg-last-statement
)
3047 (eq (caar (idlwave-statement-type)) 'for
)))
3048 (current-column))))))
3049 (< (- fancy-nonparen-indent basic-indent
)
3050 idlwave-max-extra-continuation-indent
))
3051 (if fancy-paren-indent
;calculated but disallowed paren indent
3052 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3053 fancy-nonparen-indent
))
3055 ;; Basic indent, by default
3056 (t basic-indent
)))))
3060 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3061 "Move to next match of the regular expression KEY-RE.
3062 Matches inside comments or string constants will be ignored.
3063 If DIR is negative, the search will be backwards.
3064 At a successful match, the mark is pushed unless NOMARK is non-nil.
3065 Searches are limited to LIMIT.
3066 Searches are case-insensitive and use a special syntax table which
3067 treats `$' and `_' as word characters.
3068 Return value is the beginning of the match or (in case of failure) nil."
3069 (setq dir
(or dir
0))
3070 (let ((case-fold-search t
)
3071 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3073 (idlwave-with-special-syntax
3076 (while (funcall search-func key-re limit t
)
3077 (if (not (idlwave-quoted))
3078 (throw 'exit
(setq found
(match-beginning 0)))
3079 (if (or (and (> dir
0) (eobp))
3080 (and (< dir
0) (bobp)))
3081 (throw 'exit nil
)))))))
3084 (if (not nomark
) (push-mark))
3089 (defun idlwave-block-jump-out (&optional dir nomark
)
3090 "When optional argument DIR is non-negative, move forward to end of
3091 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3092 regular expressions. When DIR is negative, move backwards to block beginning.
3093 Recursively calls itself to skip over nested blocks. DIR defaults to
3094 forward. Calls `push-mark' unless the optional argument NOMARK is
3095 non-nil. Movement is limited by the start of program units because of
3096 possibility of unbalanced blocks."
3098 (or dir
(setq dir
0))
3099 (let* ((here (point))
3100 (case-fold-search t
)
3101 (limit (if (>= dir
0) (point-max) (point-min)))
3102 (block-limit (if (>= dir
0)
3103 idlwave-begin-block-reg
3104 idlwave-end-block-reg
))
3106 (block-reg (concat idlwave-begin-block-reg
"\\|"
3107 idlwave-end-block-reg
))
3108 (unit-limit (or (save-excursion
3111 idlwave-begin-unit-reg dir t limit
)
3114 idlwave-end-unit-reg dir t limit
)))
3116 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3117 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3118 (while (and found
(looking-at block-limit
))
3119 (if (>= dir
0) (forward-word 1))
3120 (idlwave-block-jump-out dir t
)
3121 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3122 (if (not nomark
) (push-mark here
))
3123 (if (not found
) (goto-char unit-limit
)
3124 (if (>= dir
0) (forward-word 1)))))
3126 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3127 "The minimum indent in the current statement."
3128 (idlwave-beginning-of-statement)
3129 (if (not (idlwave-is-continuation-line))
3130 (idlwave-current-indent)
3131 (let ((min (idlwave-current-indent)) comm-or-empty
)
3132 (while (and (= (forward-line 1) 0)
3133 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3134 (idlwave-is-continuation-line))
3135 (or (null end-reg
) (< (point) end-reg
)))
3136 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3137 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3139 (min min
(idlwave-current-indent))))))
3141 (defun idlwave-current-statement-indent (&optional last-line
)
3142 "Return indentation of the current statement.
3143 If in a statement, moves to beginning of statement before finding indent."
3145 (idlwave-end-of-statement)
3146 (idlwave-beginning-of-statement))
3147 (idlwave-current-indent))
3149 (defun idlwave-current-indent ()
3150 "Return the column of the indentation of the current line.
3151 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3154 (skip-chars-forward " \t")
3155 ;; if we are at the end of blank line return 0
3157 ((current-column)))))
3159 (defun idlwave-is-continuation-line ()
3160 "Tests if current line is continuation line.
3161 Blank or comment-only lines following regular continuation lines (with
3162 `$') count as continuations too."
3165 (idlwave-look-at "\\<\\$")
3167 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3168 (eq (forward-line -
1) 0))
3169 (if (idlwave-look-at "\\<\\$") (throw 'loop t
)))))))
3171 (defun idlwave-is-comment-line ()
3172 "Tests if the current line is a comment line."
3174 (beginning-of-line 1)
3175 (looking-at "[ \t]*;")))
3177 (defun idlwave-is-comment-or-empty-line ()
3178 "Tests if the current line is a comment line."
3180 (beginning-of-line 1)
3181 (looking-at "[ \t]*[;\n]")))
3183 (defun idlwave-look-at (regexp &optional cont beg
)
3184 "Searches current line from current point for REGEXP.
3185 If optional argument CONT is non-nil, searches to the end of
3186 the current statement.
3187 If optional arg BEG is non-nil, search starts from the beginning of the
3189 Ignores matches that end in a comment or inside a string expression.
3190 Returns point if successful, nil otherwise.
3191 This function produces unexpected results if REGEXP contains quotes or
3192 a comment delimiter. The search is case insensitive.
3193 If successful leaves point after the match, otherwise, does not move point."
3194 (let ((here (point))
3195 (case-fold-search t
)
3196 (eos (save-excursion
3197 (if cont
(idlwave-end-of-statement) (end-of-line))
3200 (idlwave-with-special-syntax
3201 (if beg
(idlwave-beginning-of-statement))
3202 (while (and (setq found
(re-search-forward regexp eos t
))
3204 (if (not found
) (goto-char here
))
3207 (defun idlwave-fill-paragraph (&optional nohang
)
3208 "Fills paragraphs in comments.
3209 A paragraph is made up of all contiguous lines having the same comment
3210 leader (the leading whitespace before the comment delimiter and the
3211 comment delimiter). In addition, paragraphs are separated by blank
3212 line comments. The indentation is given by the hanging indent of the
3213 first line, otherwise by the minimum indentation of the lines after
3214 the first line. The indentation of the first line does not change.
3215 Does not effect code lines. Does not fill comments on the same line
3216 with code. The hanging indent is given by the end of the first match
3217 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3218 optional argument NOHANG is non-nil then the hanging indent is
3221 ;; check if this is a line comment
3224 (skip-chars-forward " \t")
3225 (looking-at comment-start
))
3228 pre here diff fill-prefix-reg bcl first-indent
3230 ;; Change tabs to spaces in the surrounding paragraph.
3231 ;; The surrounding paragraph will be the largest containing block of
3232 ;; contiguous line comments. Thus, we may be changing tabs in
3233 ;; a much larger area than is needed, but this is the easiest
3234 ;; brute force way to do it.
3236 ;; This has the undesirable side effect of replacing the tabs
3237 ;; permanently without the user's request or knowledge.
3239 (backward-paragraph)
3240 (setq start
(point)))
3244 (untabify start end
)
3250 (concat "^[ \t]*" comment-start
"+")
3251 (save-excursion (end-of-line) (point))
3253 ;; Get the comment leader on the line and its length
3254 (setq pre
(current-column))
3255 ;; the comment leader is the indentation plus exactly the
3256 ;; number of consecutive ";".
3257 (setq fill-prefix-reg
3261 (buffer-substring (save-excursion
3262 (beginning-of-line) (point))
3266 ;; Mark the beginning and end of the paragraph
3268 (while (and (looking-at fill-prefix-reg
)
3269 (not (looking-at paragraph-separate
))
3272 ;; Move to first line of paragraph
3273 (if (/= (point) bcl
)
3275 (setq start
(point))
3277 (while (and (looking-at fill-prefix-reg
)
3278 (not (looking-at paragraph-separate
))
3282 (if (or (not (looking-at fill-prefix-reg
))
3283 (looking-at paragraph-separate
))
3286 ;; if at end of buffer add a newline (need this because
3287 ;; fill-region needs END to be at the beginning of line after
3288 ;; the paragraph or it will add a line).
3290 (progn (insert ?
\n) (backward-char 1)))
3291 ;; Set END to the beginning of line after the paragraph
3292 ;; END is calculated as distance from end of buffer
3293 (setq end
(- (point-max) (point) 1))
3295 ;; Calculate the indentation for the paragraph.
3297 ;; In the following while statements, after one iteration
3298 ;; point will be at the beginning of a line in which case
3299 ;; the while will not be executed for the
3300 ;; the first paragraph line and thus will not affect the
3303 ;; First check to see if indentation is based on hanging indent.
3304 (if (and (not nohang
) idlwave-hanging-indent
3308 (idlwave-calc-hanging-indent))))
3309 ;; Adjust lines of paragraph by inserting spaces so that
3310 ;; each line's indent is at least as great as the hanging
3311 ;; indent. This is needed for fill-paragraph to work with
3316 (while (> (point) start
)
3317 (re-search-forward comment-start-skip
3318 (save-excursion (end-of-line) (point))
3320 (if (> (setq diff
(- indent
(current-column))) 0)
3322 (if (>= here
(point))
3323 ;; adjust the original location for the
3325 (setq here
(+ here diff
)))
3326 (insert (make-string diff ?\
))))
3330 ;; No hang. Instead find minimum indentation of paragraph
3331 ;; after first line.
3332 ;; For the following while statement, since START is at the
3333 ;; beginning of line and END is at the end of line
3334 ;; point is greater than START at least once (which would
3335 ;; be the case for a single line paragraph).
3336 (while (> (point) start
)
3343 (save-excursion (end-of-line) (point))
3348 (setq fill-prefix
(concat fill-prefix
3349 (make-string (- indent pre
)
3351 ;; first-line indent
3357 (save-excursion (end-of-line) (point))
3362 ;; try to keep point at its original place
3365 ;; In place of the more modern fill-region-as-paragraph, a hack
3366 ;; to keep whitespace untouched on the first line within the
3367 ;; indent length and to preserve any indent on the first line
3371 (buffer-substring start
(+ start first-indent -
1)))
3372 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3373 (fill-region-as-paragraph
3376 (current-justification)
3378 (delete-region start
(+ start first-indent -
1))
3381 ;; When we want the point at the beginning of the comment
3382 ;; body fill-region will put it at the beginning of the line.
3383 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3384 (setq fill-prefix nil
))))
3386 (defun idlwave-calc-hanging-indent ()
3387 "Calculate the position of the hanging indent for the comment
3388 paragraph. The hanging indent position is given by the first match
3389 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3390 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3392 If not found returns nil."
3393 (if idlwave-use-last-hang-indent
3396 (if (re-search-backward
3397 idlwave-hang-indent-regexp
3398 (save-excursion (beginning-of-line) (point))
3400 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3403 (if (re-search-forward
3404 idlwave-hang-indent-regexp
3405 (save-excursion (end-of-line) (point))
3407 (current-column)))))
3409 (defun idlwave-auto-fill ()
3410 "Called to break lines in auto fill mode.
3411 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3412 non-nil. Places a continuation character at the end of the line if
3413 not in a comment. Splits strings with IDL concatenation operator `+'
3414 if `idlwave-auto-fill-split-string' is non-nil."
3415 (if (<= (current-column) fill-column
)
3416 nil
; do not to fill
3417 (if (or (not idlwave-fill-comment-line-only
)
3419 ;; Check for comment line
3421 (looking-at idlwave-comment-line-start-skip
)))
3423 (idlwave-indent-line)
3424 ;; Prevent actions do-auto-fill which calls indent-line-function.
3425 (let (idlwave-do-actions
3426 (paragraph-start ".")
3427 (paragraph-separate ".")
3428 (fill-nobreak-predicate
3429 (if (and (idlwave-in-quote)
3430 idlwave-auto-fill-split-string
)
3431 (lambda () ;; We'll need 5 spaces for " ' + $"
3432 (<= (- fill-column
(current-column)) 5)
3437 ;; Indent the split line
3438 (idlwave-indent-line)
3442 (looking-at idlwave-comment-line-start-skip
))
3443 ;; A continued line comment
3444 ;; We treat continued line comments as part of a comment
3445 ;; paragraph. So we check for a hanging indent.
3446 (if idlwave-hanging-indent
3447 (let ((here (- (point-max) (point)))
3451 (idlwave-calc-hanging-indent))))
3454 ;; Remove whitespace between comment delimiter and
3455 ;; text, insert spaces for appropriate indentation.
3459 (save-excursion (end-of-line) (point)) t
)
3460 (delete-horizontal-space)
3461 (idlwave-indent-to indent
)
3462 (goto-char (- (point-max) here
)))
3464 ;; Split code or comment?
3467 (idlwave-in-comment))
3468 ;; Splitting a non-full-line comment.
3469 ;; Insert the comment delimiter from split line
3473 (skip-chars-forward " \t")
3474 ;; Insert blank to keep off beginning of line
3478 (buffer-substring (idlwave-goto-comment)
3480 (skip-chars-forward "; ")
3482 (idlwave-indent-line))
3483 ;; Split code line - add continuation character
3486 ;; Check to see if we split a string
3487 (if (and (setq beg
(idlwave-in-quote))
3488 idlwave-auto-fill-split-string
)
3489 ;; Split the string and concatenate.
3490 ;; The first extra space is for the space
3491 ;; the line was split. That space was removed.
3492 (insert " " (char-after beg
) " +"))
3495 (if idlwave-auto-fill-split-string
3496 ;; Make the second part of continued string
3499 (skip-chars-forward " \t")
3500 (insert (char-after beg
)))
3503 (message "Warning: continuation inside a string.")))
3504 ;; Although do-auto-fill (via indent-new-comment-line) calls
3505 ;; idlwave-indent-line for the new line, re-indent again
3506 ;; because of the addition of the continuation character.
3507 (idlwave-indent-line))
3510 (defun idlwave-auto-fill-mode (arg)
3511 "Toggle auto-fill mode for IDL mode.
3512 With arg, turn auto-fill mode on if arg is positive.
3513 In auto-fill mode, inserting a space at a column beyond `fill-column'
3514 automatically breaks the line at a previous space."
3516 (prog1 (set idlwave-fill-function
3518 (not (symbol-value idlwave-fill-function
))
3519 (> (prefix-numeric-value arg
) 0))
3523 (set-buffer-modified-p (buffer-modified-p))))
3525 ;(defun idlwave-fill-routine-call ()
3526 ; "Fill a routine definition or statement, indenting appropriately."
3527 ; (let ((where (idlwave-where)))))
3530 (defun idlwave-doc-header (&optional nomark
)
3531 "Insert a documentation header at the beginning of the unit.
3532 Inserts the value of the variable idlwave-file-header. Sets mark before
3533 moving to do insertion unless the optional prefix argument NOMARK
3536 (or nomark
(push-mark))
3537 ;; make sure we catch the current line if it begins the unit
3538 (if idlwave-header-to-beginning-of-file
3539 (goto-char (point-min))
3541 (idlwave-beginning-of-subprogram)
3543 ;; skip function or procedure line
3544 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3546 (idlwave-end-of-statement)
3547 (if (> (forward-line 1) 0) (insert "\n")))))
3548 (let ((pos (point)))
3549 (if idlwave-file-header
3550 (cond ((car idlwave-file-header
)
3551 (insert-file-contents (car idlwave-file-header
)))
3552 ((stringp (car (cdr idlwave-file-header
)))
3553 (insert (car (cdr idlwave-file-header
))))))
3556 (defun idlwave-default-insert-timestamp ()
3557 "Default timestamp insertion function"
3558 (insert (current-time-string))
3559 (insert ", " (user-full-name))
3560 (if (boundp 'user-mail-address
)
3561 (insert " <" user-mail-address
">")
3562 (insert " <" (user-login-name) "@" (system-name) ">"))
3563 ;; Remove extra spaces from line
3564 (idlwave-fill-paragraph)
3565 ;; Insert a blank line comment to separate from the date entry -
3566 ;; will keep the entry from flowing onto date line if re-filled.
3567 (insert "\n;\n;\t\t"))
3569 (defun idlwave-doc-modification ()
3570 "Insert a brief modification log at the beginning of the current program.
3571 Looks for an occurrence of the value of user variable
3572 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3573 and places the point for the user to add a log. Before moving, saves
3574 location on mark ring so that the user can return to previous point."
3578 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3580 (goto-char (point-min))
3581 (re-search-forward idlwave-doclib-start nil t
)))
3582 (setq beg
(match-beginning 0))
3583 (re-search-forward idlwave-doclib-end nil t
)
3584 (setq end
(match-end 0)))
3587 (if (re-search-forward
3588 (concat idlwave-doc-modifications-keyword
":")
3593 (insert "\n" comment-start
"\n")
3594 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3596 (run-hooks 'idlwave-timestamp-hook
))
3597 (error "No valid DOCLIB header"))))
3600 ;;; Interface to expand-region-abbrevs which did not work when the
3601 ;;; abbrev hook associated with an abbrev moves point backwards
3602 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3603 ;;; The original would enter an infinite loop in attempting to expand
3604 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3605 ;;; because the point would keep going back to the beginning of the
3606 ;;; abbrev instead of to the end of the abbrev). We now keep the
3607 ;;; abbrev hook from moving backwards.
3609 (defun idlwave-expand-region-abbrevs (start end
)
3610 "Expand each abbrev occurrence in the region.
3611 Calling from a program, arguments are START END."
3614 (goto-char (min start end
))
3615 (let ((idlwave-show-block nil
) ;Do not blink
3616 (idlwave-abbrev-move nil
)) ;Do not move
3617 (expand-region-abbrevs start end
'noquery
))))
3619 (defun idlwave-quoted ()
3620 "Returns t if point is in a comment or quoted string.
3622 (or (idlwave-in-comment) (idlwave-in-quote)))
3624 (defun idlwave-in-quote ()
3625 "Returns location of the opening quote
3626 if point is in a IDL string constant, nil otherwise.
3627 Ignores comment delimiters on the current line.
3628 Properly handles nested quotation marks and octal
3629 constants - a double quote followed by an octal digit."
3630 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3631 ;;; double quote followed by an octal digit to be an octal constant
3632 ;;; rather than a string. Therefore, there is no terminating double
3635 ;; Because single and double quotes can quote each other we must
3636 ;; search for the string start from the beginning of line.
3637 (let* ((start (point))
3638 (eol (progn (end-of-line) (point)))
3639 (bq (progn (beginning-of-line) (point)))
3644 (while (< endq start
)
3645 ;; Find string start
3646 ;; Don't find an octal constant beginning with a double quote
3647 (if (re-search-forward "[\"']" eol
'lim
)
3648 ;; Find the string end.
3649 ;; In IDL, two consecutive delimiters after the start of a
3651 ;; escape for the delimiter in the string.
3652 ;; Two consecutive delimiters alone (i.e., not after the
3653 ;; start of a string) is the null string.
3655 ;; Move to position after quote
3656 (goto-char (1+ (match-beginning 0)))
3657 (setq bq
(1- (point)))
3658 ;; Get the string delimiter
3659 (setq delim
(char-to-string (preceding-char)))
3660 ;; Check for null string
3661 (if (looking-at delim
)
3662 (progn (setq endq
(point)) (forward-char 1))
3663 ;; Look for next unpaired delimiter
3664 (setq found
(search-forward delim eol
'lim
))
3665 (while (looking-at delim
)
3667 (setq found
(search-forward delim eol
'lim
)))
3669 (setq endq
(- (point) 1))
3670 (setq endq
(point)))
3672 (progn (setq bq
(point)) (setq endq
(point)))))
3673 (store-match-data data
)
3674 ;; return string beginning position or nil
3675 (if (> start bq
) bq
))))
3677 (defun idlwave-is-pointer-dereference (&optional limit
)
3678 "Determines if the character after point is a pointer dereference *."
3679 (let ((pos (point)))
3681 (eq (char-after) ?\
*)
3682 (not (idlwave-in-quote))
3685 (re-search-backward (concat "\\(" idlwave-idl-keywords
3686 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3689 ;; Statement templates
3691 ;; Replace these with a general template function, something like
3692 ;; expand.el (I think there was also something with a name similar to
3695 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3696 "Build a template with optional prompt expression.
3698 Opens a line if point is not followed by a newline modulo intervening
3699 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3700 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3701 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3702 PROMPT is a string then it is displayed as a message in the
3703 minibuffer. The PROMPT serves as a reminder to the user of an
3704 expression to enter.
3706 The lines containing S1 and S2 are reindented using `indent-region'
3707 unless the optional second argument NOINDENT is non-nil."
3708 (if (eq major-mode
'idlwave-shell-mode
)
3709 ;; This is a gross hack to avoit template abbrev expansion
3710 ;; in the shell. FIXME: This is a dirty hack.
3711 (if (and (eq this-command
'self-insert-command
)
3712 (equal last-abbrev-location
(point)))
3713 (insert last-abbrev-text
)
3714 (error "No templates in idlwave-shell"))
3715 (cond ((eq idlwave-abbrev-change-case
'down
)
3716 (setq s1
(downcase s1
) s2
(downcase s2
)))
3717 (idlwave-abbrev-change-case
3718 (setq s1
(upcase s1
) s2
(upcase s2
))))
3719 (let ((beg (save-excursion (beginning-of-line) (point)))
3721 (if (not (looking-at "\\s-*\n"))
3728 (indent-region beg end nil
))
3729 (if (stringp prompt
)
3730 (message prompt
)))))
3732 (defun idlwave-rw-case (string)
3733 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3734 (if idlwave-reserved-word-upcase
3738 (defun idlwave-elif ()
3739 "Build skeleton IDL if-else block."
3742 (idlwave-rw-case "if")
3743 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3744 "Condition expression"))
3746 (defun idlwave-case ()
3747 "Build skeleton IDL case statement."
3750 (idlwave-rw-case "case")
3751 (idlwave-rw-case " of\n\nendcase")
3752 "Selector expression"))
3754 (defun idlwave-switch ()
3755 "Build skeleton IDL switch statement."
3758 (idlwave-rw-case "switch")
3759 (idlwave-rw-case " of\n\nendswitch")
3760 "Selector expression"))
3762 (defun idlwave-for ()
3763 "Build skeleton for loop statment."
3766 (idlwave-rw-case "for")
3767 (idlwave-rw-case " do begin\n\nendfor")
3770 (defun idlwave-if ()
3771 "Build skeleton for loop statment."
3774 (idlwave-rw-case "if")
3775 (idlwave-rw-case " then begin\n\nendif")
3776 "Scalar logical expression"))
3778 (defun idlwave-procedure ()
3781 (idlwave-rw-case "pro")
3782 (idlwave-rw-case "\n\nreturn\nend")
3785 (defun idlwave-function ()
3788 (idlwave-rw-case "function")
3789 (idlwave-rw-case "\n\nreturn\nend")
3792 (defun idlwave-repeat ()
3795 (idlwave-rw-case "repeat begin\n\nendrep until")
3796 (idlwave-rw-case "")
3799 (defun idlwave-while ()
3802 (idlwave-rw-case "while")
3803 (idlwave-rw-case " do begin\n\nendwhile")
3806 (defun idlwave-split-string (string &optional pattern
)
3807 "Return a list of substrings of STRING which are separated by PATTERN.
3808 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3810 (setq pattern
"[ \f\t\n\r\v]+"))
3811 (let (parts (start 0))
3812 (while (string-match pattern string start
)
3813 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3814 start
(match-end 0)))
3815 (nreverse (cons (substring string start
) parts
))))
3817 (defun idlwave-replace-string (string replace_string replace_with
)
3819 (last (length string
))
3822 (while (setq end
(string-match replace_string string start
))
3824 (concat ret_string
(substring string start end
) replace_with
))
3825 (setq start
(match-end 0)))
3826 (setq ret_string
(concat ret_string
(substring string start last
)))))
3828 (defun idlwave-get-buffer-visiting (file)
3829 ;; Return the buffer currently visiting FILE
3831 ((boundp 'find-file-compare-truenames
) ; XEmacs
3832 (let ((find-file-compare-truenames t
))
3833 (get-file-buffer file
)))
3834 ((fboundp 'find-buffer-visiting
) ; Emacs
3835 (find-buffer-visiting file
))
3836 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3838 (defvar idlwave-outlawed-buffers nil
3839 "List of buffer pulled up by idlwave for special reasons.
3840 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3842 (defun idlwave-find-file-noselect (file &optional why
)
3843 ;; Return a buffer visiting file.
3844 (or (idlwave-get-buffer-visiting file
)
3845 (let ((buf (find-file-noselect file
)))
3846 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3849 (defun idlwave-kill-autoloaded-buffers ()
3850 "Kill buffers created automatically by IDLWAVE.
3851 Function prompts for a letter to identify the buffers to kill.
3852 Possible letters are:
3854 f Buffers created by the command \\[idlwave-find-module] or mouse
3855 clicks in the routine info window.
3856 s Buffers created by the IDLWAVE Shell to display where execution
3857 stopped or an error was found.
3858 a Both of the above.
3860 Buffer containing unsaved changes require confirmation before they are killed."
3862 (if (null idlwave-outlawed-buffers
)
3863 (error "No IDLWAVE-created buffers available")
3864 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3865 (idlwave-count-outlawed-buffers 'find
)
3866 (idlwave-count-outlawed-buffers 'shell
)))
3867 (let ((c (read-char)))
3869 ((member c
'(?f ?\C-f
))
3870 (idlwave-do-kill-autoloaded-buffers 'find
))
3871 ((member c
'(?s ?\C-s
))
3872 (idlwave-do-kill-autoloaded-buffers 'shell
))
3873 ((member c
'(?a ?\C-a
))
3874 (idlwave-do-kill-autoloaded-buffers t
))
3875 (t (error "Abort"))))))
3877 (defun idlwave-count-outlawed-buffers (tag)
3878 "How many outlawed buffers have tag TAG?"
3881 (lambda (x) (eq (cdr x
) tag
))
3882 idlwave-outlawed-buffers
))))
3884 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3885 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3886 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3889 (while (setq entry
(pop list
))
3890 (if (buffer-live-p (car entry
))
3891 (and (or (memq t reasons
)
3892 (memq (cdr entry
) reasons
))
3893 (kill-buffer (car entry
))
3895 (setq idlwave-outlawed-buffers
3896 (delq entry idlwave-outlawed-buffers
)))
3897 (setq idlwave-outlawed-buffers
3898 (delq entry idlwave-outlawed-buffers
))))
3899 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3901 (defun idlwave-revoke-license-to-kill ()
3902 "Remove BUFFER from the buffers which may be killed.
3903 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3904 Intended for `after-save-hook'."
3905 (let* ((buf (current-buffer))
3906 (entry (assq buf idlwave-outlawed-buffers
)))
3909 (setq idlwave-outlawed-buffers
3910 (delq entry idlwave-outlawed-buffers
)))
3911 ;; Remove this function from the hook.
3912 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3914 (defvar idlwave-path-alist
)
3915 (defun idlwave-locate-lib-file (file)
3916 ;; Find FILE on the scanned lib path and return a buffer visiting it
3917 (let* ((dirs idlwave-path-alist
)
3920 (while (setq dir
(car (pop dirs
)))
3922 (setq efile
(expand-file-name file dir
)))
3923 (throw 'exit efile
))))))
3925 (defun idlwave-expand-lib-file-name (file)
3926 ;; Find FILE on the scanned lib path and return a buffer visiting it
3927 ;; This is for, e.g., finding source with no user catalog
3930 ((file-name-absolute-p file
) file
)
3931 (t (idlwave-locate-lib-file file
))))
3933 (defun idlwave-make-tags ()
3934 "Creates the IDL tags file IDLTAGS in the current directory from
3935 the list of directories specified in the minibuffer. Directories may be
3936 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3937 specified top directories are searched if the directory name is prefixed
3938 by @. Specify @ directories with care, it may take a long, long time if
3941 (let (directory directories cmd append status numdirs dir getsubdirs
3942 buffer save_buffer files numfiles item errbuf
)
3945 ;; Read list of directories
3946 (setq directory
(read-string "Tag Directories: " "."))
3947 (setq directories
(idlwave-split-string directory
"[ \t]+"))
3949 ;; Set etags command, vars
3950 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
3951 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3952 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3956 ;; For each directory
3958 (setq dir
(nth numdirs directories
))
3961 ;; Find the subdirectories
3962 (if (string-match "^[@]\\(.+\\)$" dir
)
3963 (setq getsubdirs t
) (setq getsubdirs nil
))
3964 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
3965 (setq dir
(expand-file-name dir
))
3966 (if (file-directory-p dir
)
3968 (if (and getsubdirs
)
3970 (setq buffer
(get-buffer-create "*idltags*"))
3971 (call-process "sh" nil buffer nil
"-c"
3972 (concat "find " dir
" -type d -print"))
3973 (setq save_buffer
(current-buffer))
3975 (setq files
(idlwave-split-string
3976 (idlwave-replace-string
3977 (buffer-substring 1 (point-max))
3980 (set-buffer save_buffer
)
3981 (kill-buffer buffer
))
3982 (setq files
(list (concat dir
"/*.pro"))))
3984 ;; For each subdirectory
3986 (setq item
(nth numfiles files
))
3990 (if (not (string-match "^[ \\t]*$" item
))
3992 (message (concat "Tagging " item
"..."))
3993 (setq errbuf
(get-buffer-create "*idltags-error*"))
3994 (setq status
(+ status
3995 (if (eq 0 (call-process
3996 "sh" nil errbuf nil
"-c"
3997 (concat cmd append item
)))
4001 ;; Append additional tags
4002 (setq append
" --append ")
4003 (setq numfiles
(1+ numfiles
))
4004 (setq item
(nth numfiles files
)))
4006 (setq numfiles
(1+ numfiles
))
4007 (setq item
(nth numfiles files
))
4010 (setq numdirs
(1+ numdirs
))
4011 (setq dir
(nth numdirs directories
)))
4013 (setq numdirs
(1+ numdirs
))
4014 (setq dir
(nth numdirs directories
)))))
4016 (setq errbuf
(get-buffer-create "*idltags-error*"))
4018 (kill-buffer errbuf
))
4022 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4023 "Comment the lines in the region if the first non-blank line is
4024 commented, and conversely, uncomment region. If optional prefix arg
4025 N is non-nil, then for N positive, add N comment delimiters or for N
4026 negative, remove N comment delimiters.
4027 Uses `comment-region' which does not place comment delimiters on
4029 (interactive "r\nP")
4031 (comment-region beg end
(prefix-numeric-value n
))
4036 (skip-chars-forward " \t\n")
4037 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4038 (if (fboundp 'uncomment-region
)
4039 (uncomment-region beg end
)
4040 (comment-region beg end
4041 (- (length (buffer-substring
4044 (comment-region beg end
)))))
4047 ;; ----------------------------------------------------------------------------
4048 ;; ----------------------------------------------------------------------------
4049 ;; ----------------------------------------------------------------------------
4050 ;; ----------------------------------------------------------------------------
4052 ;; Completion and Routine Info
4055 ;; String "intern" functions
4057 ;; For the completion and routine info function, we want to normalize
4058 ;; the case of procedure names etc. We do this by "interning" these
4059 ;; string is a hand-crafted way. Hashes are used to map the downcase
4060 ;; version of the strings to the cased versions. Most *-sint-*
4061 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4062 ;; system hash. The former is re-scanned, and the latter takes case
4065 ;; Since these cased versions are really lisp objects, we can use `eq'
4066 ;; to search, which is a large performance boost. All new strings
4067 ;; need to be "sinterned". We do this as early as possible after
4068 ;; getting these strings from completion or buffer substrings. So
4069 ;; most of the code can simply assume to deal with "sinterned"
4070 ;; strings. The only exception is that the functions which scan whole
4071 ;; buffers for routine information do not intern the grabbed strings.
4072 ;; This is only done afterwards. Therefore in these functions it is
4073 ;; *not* safe to assume the strings can be compared with `eq' and be
4074 ;; fed into the routine assq functions.
4076 ;; Here we define the hashing functions.
4078 ;; The variables which hold the hashes.
4079 (defvar idlwave-sint-routines
'(nil))
4080 (defvar idlwave-sint-keywords
'(nil))
4081 (defvar idlwave-sint-methods
'(nil))
4082 (defvar idlwave-sint-classes
'(nil))
4083 (defvar idlwave-sint-dirs
'(nil))
4084 (defvar idlwave-sint-libnames
'(nil))
4086 (defun idlwave-reset-sintern (&optional what
)
4087 "Reset all sintern hashes."
4088 ;; Make sure the hash functions are accessible.
4089 (if (or (not (fboundp 'gethash
))
4090 (not (fboundp 'puthash
)))
4093 (or (fboundp 'puthash
)
4094 (defalias 'puthash
'cl-puthash
))))
4095 (let ((entries '((idlwave-sint-routines 1000 10)
4096 (idlwave-sint-keywords 1000 10)
4097 (idlwave-sint-methods 100 10)
4098 (idlwave-sint-classes 10 10))))
4100 ;; Make sure these are lists
4101 (loop for entry in entries
4102 for var
= (car entry
)
4103 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4105 (when (or (eq what t
) (eq what
'syslib
)
4106 (null (cdr idlwave-sint-routines
)))
4107 ;; Reset the system & library hash
4108 (loop for entry in entries
4109 for var
= (car entry
) for size
= (nth 1 entry
)
4110 do
(setcdr (symbol-value var
)
4111 (make-hash-table ':size size
':test
'equal
)))
4112 (setq idlwave-sint-dirs nil
4113 idlwave-sint-libnames nil
))
4115 (when (or (eq what t
) (eq what
'bufsh
)
4116 (null (car idlwave-sint-routines
)))
4117 ;; Reset the buffer & shell hash
4118 (loop for entry in entries
4119 for var
= (car entry
) for size
= (nth 1 entry
)
4120 do
(setcar (symbol-value var
)
4121 (make-hash-table ':size size
':test
'equal
))))))
4123 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4125 (idlwave-sintern-method name set
)
4126 (idlwave-sintern-routine name set
)))
4128 (defun idlwave-sintern (stype &rest args
)
4129 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4131 ;;(defmacro idlwave-sintern (type var)
4132 ;; `(cond ((not (stringp name)) name)
4133 ;; ((gethash (downcase name) (cdr ,var)))
4134 ;; ((gethash (downcase name) (car ,var)))
4135 ;; (set (idlwave-sintern-set name ,type ,var set))
4138 (defun idlwave-sintern-routine (name &optional set
)
4139 (cond ((not (stringp name
)) name
)
4140 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4141 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4142 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4144 (defun idlwave-sintern-keyword (name &optional set
)
4145 (cond ((not (stringp name
)) name
)
4146 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4147 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4148 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4150 (defun idlwave-sintern-method (name &optional set
)
4151 (cond ((not (stringp name
)) name
)
4152 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4153 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4154 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4156 (defun idlwave-sintern-class (name &optional set
)
4157 (cond ((not (stringp name
)) name
)
4158 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4159 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4160 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4163 (defun idlwave-sintern-dir (dir &optional set
)
4164 (car (or (member dir idlwave-sint-dirs
)
4165 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4166 (defun idlwave-sintern-libname (name &optional set
)
4167 (car (or (member name idlwave-sint-libnames
)
4168 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4170 (defun idlwave-sintern-set (name type tables set
)
4171 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4173 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4174 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4175 (puthash (downcase name
) iname table
)
4178 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4179 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4181 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4185 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4186 "Sintern all strings in the rinfo LIST. With optional parameter
4187 SET: also set new patterns. Probably this will always have to be t.
4188 If DEFAULT-DIR is passed, it is used as the base of the directory"
4189 (let (entry name type class kwds res source call new
)
4191 (setq entry
(car list
)
4196 source
(nth 3 entry
)
4198 kwds
(nthcdr 5 entry
))
4200 ;; The class and name
4203 (if (symbolp class
) (setq class
(symbol-name class
)))
4204 (setq class
(idlwave-sintern-class class set
))
4205 (setq name
(idlwave-sintern-method name set
)))
4206 (setq name
(idlwave-sintern-routine name set
)))
4209 (let ((source-type (car source
))
4210 (source-file (nth 1 source
))
4211 (source-dir (if default-dir
4212 (file-name-as-directory default-dir
)
4214 (source-lib (nth 3 source
)))
4215 (if (stringp source-dir
)
4216 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4217 (if (stringp source-lib
)
4218 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4219 (setq source
(list source-type source-file source-dir source-lib
)))
4222 (setq kwds
(mapcar (lambda (x)
4223 (idlwave-sintern-keyword-list x set
))
4226 ;; Build a canonicalized list
4227 (setq new
(nconc (list name type class source call
) kwds
)
4228 res
(cons new res
)))
4231 ;; Creating new sintern tables
4233 (defun idlwave-new-sintern-type (tag)
4234 "Define a variable and a function to sintern the new type TAG.
4235 This defines the function `idlwave-sintern-TAG' and the variable
4236 `idlwave-sint-TAGs'."
4237 (let* ((name (symbol-name tag
))
4238 (names (concat name
"s"))
4239 (var (intern (concat "idlwave-sint-" names
)))
4240 (func (intern (concat "idlwave-sintern-" name
))))
4241 (set var nil
) ; initial value of the association list
4242 (fset func
; set the function
4243 `(lambda (name &optional set
)
4244 (cond ((not (stringp name
)) name
)
4245 ((cdr (assoc (downcase name
) ,var
)))
4247 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4251 (defun idlwave-reset-sintern-type (tag)
4252 "Reset the sintern variable associated with TAG."
4253 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4255 ;;---------------------------------------------------------------------------
4258 ;; The variables which hold the information
4259 (defvar idlwave-system-routines nil
4260 "Holds the routine-info obtained by scanning buffers.")
4261 (defvar idlwave-buffer-routines nil
4262 "Holds the routine-info obtained by scanning buffers.")
4263 (defvar idlwave-compiled-routines nil
4264 "Holds the routine-info obtained by asking the shell.")
4265 (defvar idlwave-unresolved-routines nil
4266 "Holds the unresolved routine-info obtained by asking the shell.")
4267 (defvar idlwave-user-catalog-routines nil
4268 "Holds the procedure routine-info from the user scan.")
4269 (defvar idlwave-library-catalog-routines nil
4270 "Holds the procedure routine-info from the library catalog files.")
4271 (defvar idlwave-path-alist nil
4272 "Alist with !PATH directories and zero or more flags if the dir has
4273 been scanned in a user catalog ('user) or discovered in a library
4275 (defvar idlwave-true-path-alist nil
4276 "Like `idlwave-path-alist', but with true filenames.")
4277 (defvar idlwave-routines nil
4278 "Holds the combinded procedure/function/method routine-info.")
4279 (defvar idlwave-class-alist nil
4280 "Holds the class names known to IDLWAVE.")
4281 (defvar idlwave-class-history nil
4282 "The history of classes selected with the minibuffer.")
4283 (defvar idlwave-force-class-query nil
)
4284 (defvar idlwave-before-completion-wconf nil
4285 "The window configuration just before the completion buffer was displayed.")
4286 (defvar idlwave-last-system-routine-info-cons-cell nil
4287 "The last cons cell in the system routine info.")
4290 ;; The code to get routine info from different sources.
4292 (defvar idlwave-system-routines
)
4293 (defvar idlwave-catalog-process nil
4294 "The background process currently updating the catalog.")
4296 (defun idlwave-routines ()
4297 "Provide a list of IDL routines.
4298 This routine loads the builtin routines on the first call. Later it
4299 only returns the value of the variable."
4300 (if (and idlwave-catalog-process
4301 (processp idlwave-catalog-process
))
4304 ((equal (process-status idlwave-catalog-process
) 'exit
)
4305 (message "updating........")
4306 (setq idlwave-catalog-process nil
)
4307 (idlwave-update-routine-info '(4)))
4308 ((equal (process-status idlwave-catalog-process
) 'run
)
4309 ;; Keep it running...
4312 ;; Something is wrong, get rid of the process
4313 (message "Problem with catalog process") (beep)
4315 (kill-process idlwave-catalog-process
)
4317 (setq idlwave-catalog-process nil
)))))
4318 (or idlwave-routines
4320 (idlwave-update-routine-info)
4321 ;; return the current value
4324 (defvar idlwave-update-rinfo-hook nil
4325 "List of functions which should run after a global rinfo update.
4326 Does not run after automatic updates of buffer or the shell.")
4328 (defun idlwave-rescan-catalog-directories ()
4329 "Rescan the previously selected directories. For batch processing."
4330 (idlwave-update-routine-info '(16)))
4332 (defun idlwave-rescan-asynchronously ()
4333 "Dispatch another emacs instance to update the idlwave catalog.
4334 After the process finishes normally, the first access to routine info
4335 will re-read the catalog."
4337 (if (processp idlwave-catalog-process
)
4338 (if (eq (process-status idlwave-catalog-process
) 'run
)
4339 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4342 (kill-process idlwave-catalog-process
)
4344 (error "Process killed, no new process started"))
4347 (kill-process idlwave-catalog-process
)
4349 (if (or (not idlwave-user-catalog-file
)
4350 (not (stringp idlwave-user-catalog-file
))
4351 (not (file-regular-p idlwave-user-catalog-file
)))
4352 (error "No catalog has been produced yet"))
4353 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4354 (args (list "-batch"
4355 "-l" (expand-file-name "~/.emacs")
4357 "-f" "idlwave-rescan-catalog-directories"))
4358 (process (apply 'start-process
"idlcat"
4360 (setq idlwave-catalog-process process
)
4361 (set-process-sentinel
4364 (when (string-match "finished" why
)
4365 (setq idlwave-routines nil
4366 idlwave-system-routines nil
4367 idlwave-catalog-process nil
)
4368 (or (idlwave-start-load-rinfo-timer)
4369 (idlwave-update-routine-info '(4))))))
4370 (message "Background job started to update catalog file")))
4373 ;; Format for all routine info user catalog, library catalogs, etc.:
4375 ;; ("ROUTINE" type class
4376 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4377 ;; (buffer pro_file dir) | (compiled pro_file dir)
4378 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
4380 ;; DIR will be supplied dynamically while loading library catalogs,
4381 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4382 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4383 ;; be nil, as can LINK1, etc., if no HTML help is available.
4386 (defvar idlwave-load-rinfo-idle-timer
)
4387 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4388 "Update the internal routine-info lists.
4389 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4390 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4391 about individual routines.
4393 The information can come from 4 sources:
4394 1. IDL programs in the current editing session
4395 2. Compiled modules in an IDL shell running as Emacs subprocess
4396 3. A list which covers the IDL system routines.
4397 4. A list which covers the prescanned library files.
4399 Scans all IDLWAVE-mode buffers of the current editing session (see
4400 `idlwave-scan-all-buffers-for-routine-info').
4401 When an IDL shell is running, this command also queries the IDL program
4402 for currently compiled routines.
4404 With prefix ARG, also reload the system and library lists.
4405 With two prefix ARG's, also rescans the chosen user catalog tree.
4406 With three prefix args, dispatch asynchronous process to do the update.
4408 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4409 lists, but instead wait for the shell query to complete and
4410 asynchronously finish updating routine info. This is set
4411 automatically when called interactively. When you need routine
4412 information updated immediately, leave NO-CONCATENATE nil."
4413 (interactive "P\np")
4414 ;; Stop any idle processing
4415 (if (or (and (fboundp 'itimerp
)
4416 (itimerp idlwave-load-rinfo-idle-timer
))
4417 (and (fboundp 'timerp
)
4418 (timerp idlwave-load-rinfo-idle-timer
)))
4419 (cancel-timer idlwave-load-rinfo-idle-timer
))
4422 ;; Start a background process which updates the catalog.
4423 (idlwave-rescan-asynchronously))
4425 ;; Update the user catalog now, and wait for them.
4426 (idlwave-create-user-catalog-file t
))
4428 (let* ((load (or arg
4429 idlwave-buffer-case-takes-precedence
4430 (null idlwave-routines
)))
4431 ;; The override-idle means, even if the idle timer has done some
4432 ;; preparing work, load and renormalize everything anyway.
4433 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4435 (setq idlwave-buffer-routines nil
4436 idlwave-compiled-routines nil
4437 idlwave-unresolved-routines nil
)
4438 ;; Reset the appropriate hashes
4439 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4440 ;; reset was already done in idle time, so skip this step now once
4441 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4442 (idlwave-reset-sintern (cond (load t
)
4443 ((null idlwave-system-routines
) t
)
4446 (if idlwave-buffer-case-takes-precedence
4447 ;; We can safely scan the buffer stuff first
4449 (idlwave-update-buffer-routine-info)
4450 (and load
(idlwave-load-system-rinfo override-idle
)))
4451 ;; We first do the system info, and then the buffers
4452 (and load
(idlwave-load-system-rinfo override-idle
))
4453 (idlwave-update-buffer-routine-info))
4455 ;; Let's see if there is a shell
4456 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4457 (idlwave-shell-is-running)))
4458 (ask-shell (and shell-is-running
4459 idlwave-query-shell-for-routine-info
)))
4461 ;; Load the library catalogs again, first re-scanning the path
4463 (if shell-is-running
4464 (idlwave-shell-send-command idlwave-shell-path-query
4466 (idlwave-shell-get-path-info)
4467 (idlwave-scan-library-catalogs))
4469 (idlwave-scan-library-catalogs)))
4471 (if (or (not ask-shell
)
4472 (not no-concatenate
))
4473 ;; 1. If we are not going to ask the shell, we need to do the
4474 ;; concatenation now.
4475 ;; 2. When this function is called non-interactively, it
4476 ;; means that someone needs routine info *now*. The
4477 ;; shell update causes the concatenation to be
4478 ;; *delayed*, so not in time for the current command.
4479 ;; Therefore, we do a concatenation now, even though
4480 ;; the shell might do it again.
4481 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4484 ;; Ask the shell about the routines it knows of.
4485 (message "Querying the shell")
4486 (idlwave-shell-update-routine-info nil t
)))))))
4489 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4490 (defvar idlwave-load-rinfo-idle-timer nil
)
4491 (defun idlwave-start-load-rinfo-timer ()
4492 (if (or (and (fboundp 'itimerp
)
4493 (itimerp idlwave-load-rinfo-idle-timer
))
4494 (and (fboundp 'timerp
)
4495 (timerp idlwave-load-rinfo-idle-timer
)))
4496 (cancel-timer idlwave-load-rinfo-idle-timer
))
4497 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4498 (setq idlwave-load-rinfo-idle-timer nil
)
4499 (if (and idlwave-init-rinfo-when-idle-after
4500 (numberp idlwave-init-rinfo-when-idle-after
)
4501 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4502 (not idlwave-routines
))
4505 (setq idlwave-load-rinfo-idle-timer
4506 (run-with-idle-timer
4507 idlwave-init-rinfo-when-idle-after
4508 nil
'idlwave-load-rinfo-next-step
)))
4511 (defun idlwave-load-rinfo-next-step ()
4512 (let ((inhibit-quit t
)
4513 (arr idlwave-load-rinfo-steps-done
))
4515 (when (not (aref arr
0))
4516 (message "Loading idlw-rinfo.el in idle time...")
4517 (load "idlw-rinfo" 'noerror
'nomessage
)
4518 (message "Loading idlw-rinfo.el in idle time...done")
4521 (when (not (aref arr
1))
4522 (message "Normalizing idlwave-system-routines in idle time...")
4523 (idlwave-reset-sintern t
)
4524 (put 'idlwave-reset-sintern
'done-by-idle t
)
4525 (setq idlwave-system-routines
4526 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4527 (message "Normalizing idlwave-system-routines in idle time...done")
4530 (when (not (aref arr
2))
4531 (when (and (stringp idlwave-user-catalog-file
)
4532 (file-regular-p idlwave-user-catalog-file
))
4533 (message "Loading user catalog in idle time...")
4535 (load-file idlwave-user-catalog-file
)
4536 (error (throw 'exit nil
)))
4537 ;; Check for the old style catalog and warn
4539 (boundp 'idlwave-library-routines
)
4540 idlwave-library-routines
)
4542 (setq idlwave-library-routines nil
)
4544 (message "Outdated user catalog: %s... recreate"
4545 idlwave-user-catalog-file
))
4546 (message "Loading user catalog in idle time...done"))
4549 (when (not (aref arr
3))
4550 (when idlwave-user-catalog-routines
4551 (message "Normalizing user catalog routines in idle time...")
4552 (setq idlwave-user-catalog-routines
4553 (idlwave-sintern-rinfo-list
4554 idlwave-user-catalog-routines
'sys
))
4556 "Normalizing user catalog routines in idle time...done"))
4559 (when (not (aref arr
4))
4560 (idlwave-scan-library-catalogs
4561 "Loading and normalizing library catalogs in idle time...")
4564 (when (not (aref arr
5))
4565 (message "Finishing initialization in idle time...")
4567 (message "Finishing initialization in idle time...done")
4569 ;; restart the timer
4571 (idlwave-load-rinfo-next-step)
4572 (setq idlwave-load-rinfo-idle-timer
4573 (run-with-idle-timer
4574 idlwave-init-rinfo-when-idle-after
4575 nil
'idlwave-load-rinfo-next-step
))))))
4577 (defun idlwave-load-system-rinfo (&optional force
)
4578 ;; Load and case-treat the system and catalog files.
4579 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
4580 (load "idlw-rinfo" 'noerror
'nomessage
))
4581 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
4582 (message "Normalizing idlwave-system-routines...")
4583 (setq idlwave-system-routines
4584 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4585 (message "Normalizing idlwave-system-routines...done"))
4586 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
4587 (setq idlwave-last-system-routine-info-cons-cell
4588 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
))
4589 (when (and (stringp idlwave-user-catalog-file
)
4590 (file-regular-p idlwave-user-catalog-file
))
4592 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
4593 (load-file idlwave-user-catalog-file
))
4595 (when (boundp 'idlwave-library-routines
)
4596 (setq idlwave-library-routines nil
)
4597 (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file
))
4598 (setq idlwave-true-path-alist nil
)
4599 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
4600 (message "Normalizing user catalog routines...")
4601 (setq idlwave-user-catalog-routines
4602 (idlwave-sintern-rinfo-list
4603 idlwave-user-catalog-routines
'sys
))
4604 (message "Normalizing user catalog routines...done")))
4605 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
4606 (idlwave-scan-library-catalogs
4607 "Loading and normalizing library catalogs..."))
4608 (run-hooks 'idlwave-after-load-rinfo-hook
))
4611 (defun idlwave-update-buffer-routine-info ()
4614 ((eq idlwave-scan-all-buffers-for-routine-info t
)
4615 ;; Scan all buffers, current buffer last
4616 (message "Scanning all buffers...")
4617 (setq res
(idlwave-get-routine-info-from-buffers
4618 (reverse (buffer-list)))))
4619 ((null idlwave-scan-all-buffers-for-routine-info
)
4620 ;; Don't scan any buffers
4623 ;; Just scan this buffer
4624 (if (eq major-mode
'idlwave-mode
)
4626 (message "Scanning current buffer...")
4627 (setq res
(idlwave-get-routine-info-from-buffers
4628 (list (current-buffer))))))))
4629 ;; Put the result into the correct variable
4630 (setq idlwave-buffer-routines
4631 (idlwave-sintern-rinfo-list res
'set
))))
4633 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
4634 "Put the different sources for routine information together."
4635 ;; The sequence here is important because earlier definitions shadow
4636 ;; later ones. We assume that if things in the buffers are newer
4637 ;; then in the shell of the system, they are meant to be different.
4638 (setcdr idlwave-last-system-routine-info-cons-cell
4639 (append idlwave-buffer-routines
4640 idlwave-compiled-routines
4641 idlwave-library-catalog-routines
4642 idlwave-user-catalog-routines
))
4643 (setq idlwave-class-alist nil
)
4645 ;; Give a message with information about the number of routines we have.
4648 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
4649 (length idlwave-buffer-routines
)
4650 (length idlwave-compiled-routines
)
4651 (length idlwave-library-catalog-routines
)
4652 (length idlwave-user-catalog-routines
)
4653 (length idlwave-system-routines
)))
4655 (run-hooks 'idlwave-update-rinfo-hook
)))
4657 (defun idlwave-class-alist ()
4658 "Return the class alist - make it if necessary."
4659 (or idlwave-class-alist
4661 (loop for x in idlwave-routines do
4662 (when (and (setq class
(nth 2 x
))
4663 (not (assq class idlwave-class-alist
)))
4664 (push (list class
) idlwave-class-alist
)))
4665 idlwave-class-alist
)))
4667 ;; Three functions for the hooks
4668 (defun idlwave-save-buffer-update ()
4669 (idlwave-update-current-buffer-info 'save-buffer
))
4670 (defun idlwave-kill-buffer-update ()
4671 (idlwave-update-current-buffer-info 'kill-buffer
))
4672 (defun idlwave-new-buffer-update ()
4673 (idlwave-update-current-buffer-info 'find-file
))
4675 (defun idlwave-update-current-buffer-info (why)
4676 "Update idlwave-routines for current buffer. Can run from after-save-hook."
4677 (when (and (eq major-mode
'idlwave-mode
)
4678 (or (eq t idlwave-auto-routine-info-updates
)
4679 (memq why idlwave-auto-routine-info-updates
))
4680 idlwave-scan-all-buffers-for-routine-info
4684 (idlwave-replace-buffer-routine-info
4686 (if (eq why
'kill-buffer
)
4689 (idlwave-sintern-rinfo-list
4690 (idlwave-get-routine-info-from-buffers
4691 (list (current-buffer))) 'set
))))
4692 (idlwave-concatenate-rinfo-lists 'quiet
)
4696 (defun idlwave-replace-buffer-routine-info (file new
)
4697 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4698 (let ((list idlwave-buffer-routines
)
4701 ;; The following test uses eq to make sure it works correctly
4702 ;; when two buffers visit the same file. Then the file names
4703 ;; will be equal, but not eq.
4704 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
4709 ;; End of that section reached. Jump.
4711 (setq list
(cdr list
)))
4712 (setq idlwave-buffer-routines
4713 (append new
(delq nil idlwave-buffer-routines
)))))
4715 ;;----- Scanning buffers -------------------
4717 (defun idlwave-get-routine-info-from-buffers (buffers)
4718 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4719 (let (buf routine-lists res
)
4721 (while (setq buf
(pop buffers
))
4723 (if (and (eq major-mode
'idlwave-mode
)
4725 ;; yes, this buffer has the right mode.
4726 (progn (setq res
(condition-case nil
4727 (idlwave-get-buffer-routine-info)
4729 (push res routine-lists
)))))
4730 ;; Concatenate the individual lists and return the result
4731 (apply 'nconc routine-lists
)))
4733 (defun idlwave-get-buffer-routine-info ()
4734 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4735 (let* ((case-fold-search t
)
4736 routine-list string entry
)
4740 (goto-char (point-min))
4741 (while (re-search-forward
4742 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
4743 (setq string
(buffer-substring-no-properties
4746 (idlwave-end-of-statement)
4748 (setq entry
(idlwave-parse-definition string
))
4749 (push entry routine-list
))))
4752 (defvar idlwave-scanning-lib-dir
)
4753 (defun idlwave-parse-definition (string)
4754 "Parse a module definition."
4755 (let ((case-fold-search t
)
4756 start name args type keywords class
)
4758 (while (string-match ";.*" string
)
4759 (setq string
(replace-match "" t t string
)))
4760 ;; Remove the continuation line stuff
4761 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
4762 (setq string
(replace-match "\\1 " t nil string
)))
4763 (while (string-match "\n" string
)
4764 (setq string
(replace-match " " t nil string
)))
4765 ;; Match the name and type.
4767 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
4768 (setq start
(match-end 0))
4769 (setq type
(downcase (match-string 1 string
)))
4770 (if (match-beginning 3)
4771 (setq class
(match-string 3 string
)))
4772 (setq name
(match-string 4 string
)))
4773 ;; Match normal args and keyword args
4774 (while (string-match
4775 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4777 (setq start
(match-end 0))
4778 (if (match-beginning 3)
4779 (push (match-string 1 string
) keywords
)
4780 (push (match-string 1 string
) args
)))
4781 ;; Normalize and sort.
4782 (setq args
(nreverse args
))
4783 (setq keywords
(sort keywords
(lambda (a b
)
4784 (string< (downcase a
) (downcase b
)))))
4785 ;; Make and return the entry
4786 ;; We don't know which argument are optional, so this information
4787 ;; will not be contained in the calling sequence.
4789 (if (equal type
"pro") 'pro
'fun
)
4791 (cond ((not (boundp 'idlwave-scanning-lib
))
4792 (list 'buffer
(buffer-file-name)))
4793 ; ((string= (downcase
4794 ; (file-name-sans-extension
4795 ; (file-name-nondirectory (buffer-file-name))))
4798 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4799 (t (list 'user
(file-name-nondirectory (buffer-file-name))
4800 idlwave-scanning-lib-dir
"UserLib")))
4802 (if (string= type
"function") "Result = " "")
4803 (if class
"Obj ->[%s::]" "")
4807 (if (string= type
"function") "(" ", ")
4808 (mapconcat 'identity args
", ")
4809 (if (string= type
"function") ")" ""))))
4811 (cons nil
(mapcar 'list keywords
)) ;No help file
4815 ;;----- Scanning the user catalog -------------------
4817 (defun idlwave-sys-dir ()
4818 "Return the syslib directory, or a dummy that never matches."
4819 (if (string= idlwave-system-directory
"")
4821 idlwave-system-directory
))
4824 (defvar idlwave-shell-path-query
)
4825 (defun idlwave-create-user-catalog-file (&optional arg
)
4826 "Scan all files on selected dirs of IDL search path for routine information.
4828 A widget checklist will allow you to choose the directories. Write
4829 the result as a file `idlwave-user-catalog-file'. When this file
4830 exists, will be automatically loaded to give routine information about
4831 library routines. With ARG, just rescan the same directories as last
4832 time - so no widget will pop up."
4834 ;; Make sure the file is loaded if it exists.
4835 (if (and (stringp idlwave-user-catalog-file
)
4836 (file-regular-p idlwave-user-catalog-file
))
4838 (load-file idlwave-user-catalog-file
)
4840 ;; Make sure the file name makes sense
4841 (unless (and (stringp idlwave-user-catalog-file
)
4842 (> (length idlwave-user-catalog-file
) 0)
4843 (file-accessible-directory-p
4844 (file-name-directory idlwave-user-catalog-file
))
4845 (not (string= "" (file-name-nondirectory
4846 idlwave-user-catalog-file
))))
4847 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
4850 ;; Rescan the known directories
4851 ((and arg idlwave-path-alist
4852 (consp (car idlwave-path-alist
)))
4853 (idlwave-scan-user-lib-files idlwave-path-alist
))
4855 ;; Expand the directories from library-path and run the widget
4856 (idlwave-library-path
4857 (idlwave-display-user-catalog-widget
4858 (if idlwave-true-path-alist
4859 ;; Propagate any flags on the existing path-alist
4861 (let ((path-entry (assoc (file-truename x
)
4862 idlwave-true-path-alist
)))
4864 (cons x
(cdr path-entry
))
4866 (idlwave-expand-path idlwave-library-path
))
4867 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
4869 ;; Ask the shell for the path and then run the widget
4871 (message "Asking the shell for IDL path...")
4872 (require 'idlw-shell
)
4873 (idlwave-shell-send-command idlwave-shell-path-query
4874 '(idlwave-user-catalog-command-hook nil
)
4878 ;; Parse shell path information and select among it.
4879 (defun idlwave-user-catalog-command-hook (&optional arg
)
4880 ;; Command hook used by `idlwave-create-user-catalog-file'.
4883 (idlwave-scan-user-lib-files idlwave-path-alist
)
4884 ;; Set the path and display the widget
4885 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
4886 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
4887 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
4889 (defconst idlwave-user-catalog-widget-help-string
4890 "This is the front-end to the creation of the IDLWAVE user catalog.
4891 Please select the directories on IDL's search path from which you
4892 would like to extract routine information, to be stored in the file:
4896 If this is not the correct file, first set variable
4897 `idlwave-user-catalog-file', and call this command again.
4899 N.B. Many libraries include pre-scanned catalog files
4900 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
4901 not be scanned. You can scan your own libraries off-line using the
4902 perl script `idlwave_catalog'.
4904 After selecting the directories, choose [Scan & Save] to scan the library
4905 directories and save the routine info.
4908 (defvar idlwave-widget
)
4909 (defvar widget-keymap
)
4910 (defun idlwave-display-user-catalog-widget (dirs-list)
4911 "Create the widget to select IDL search path directories for scanning."
4916 (error "Don't know IDL's search path"))
4918 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4919 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4920 (kill-all-local-variables)
4921 (make-local-variable 'idlwave-widget
)
4922 (widget-insert (format idlwave-user-catalog-widget-help-string
4923 idlwave-user-catalog-file
))
4925 (widget-create 'push-button
4926 :notify
'idlwave-widget-scan-user-lib-files
4929 (widget-create 'push-button
4930 :notify
'idlwave-delete-user-catalog-file
4933 (widget-create 'push-button
4935 '(lambda (&rest ignore
)
4936 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4938 (unless (memq 'lib
(cdr x
))
4939 (idlwave-path-alist-add-flag x
'user
)))
4941 (idlwave-display-user-catalog-widget path-list
)))
4942 "Select All Non-Lib")
4944 (widget-create 'push-button
4946 '(lambda (&rest ignore
)
4947 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4949 (idlwave-path-alist-remove-flag x
'user
))
4951 (idlwave-display-user-catalog-widget path-list
)))
4954 (widget-create 'push-button
4955 :notify
(lambda (&rest ignore
)
4956 (kill-buffer (current-buffer)))
4958 (widget-insert "\n\n")
4960 (widget-insert "Select Directories: \n")
4962 (setq idlwave-widget
4963 (apply 'widget-create
4965 :value
(delq nil
(mapcar (lambda (x)
4966 (if (memq 'user
(cdr x
))
4970 :tag
"List of directories"
4973 (if (memq 'lib
(cdr x
))
4974 (concat "[LIB] " (car x
) )
4975 (car x
)))) dirs-list
)))
4976 (widget-put idlwave-widget
:path-dirs dirs-list
)
4977 (widget-insert "\n")
4978 (use-local-map widget-keymap
)
4980 (goto-char (point-min))
4981 (delete-other-windows))
4983 (defun idlwave-delete-user-catalog-file (&rest ignore
)
4985 (format "Delete file %s " idlwave-user-catalog-file
))
4987 (delete-file idlwave-user-catalog-file
)
4988 (message "%s has been deleted" idlwave-user-catalog-file
))))
4990 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
4991 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
4992 (let* ((widget idlwave-widget
)
4993 (selected-dirs (widget-value widget
))
4994 (path-alist (widget-get widget
:path-dirs
))
4995 (this-path-alist path-alist
)
4997 (while (setq dir-entry
(pop this-path-alist
))
4999 (if (memq 'lib
(cdr dir-entry
))
5000 (concat "[LIB] " (car dir-entry
))
5003 (idlwave-path-alist-add-flag dir-entry
'user
)
5004 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5005 (idlwave-scan-user-lib-files path-alist
)))
5007 (defvar font-lock-mode
)
5008 (defun idlwave-scan-user-lib-files (path-alist)
5009 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5010 (let* ((idlwave-scanning-lib t
)
5011 (idlwave-scanning-lib-dir "")
5012 (idlwave-completion-case nil
)
5013 dirs-alist dir files file
)
5014 (setq idlwave-user-catalog-routines nil
5015 idlwave-path-alist path-alist
; for library-path instead
5016 idlwave-true-path-alist nil
)
5017 (if idlwave-auto-write-paths
(idlwave-write-paths))
5019 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5021 (setq dirs-alist
(reverse path-alist
))
5022 (while (setq dir
(pop dirs-alist
))
5023 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5024 (setq dir
(car dir
))
5025 (setq idlwave-scanning-lib-dir dir
)
5026 (when (file-directory-p dir
)
5027 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5028 (while (setq file
(pop files
))
5029 (when (file-regular-p file
)
5030 (if (not (file-readable-p file
))
5031 (message "Skipping %s (no read permission)" file
)
5032 (message "Scanning %s..." file
)
5034 (insert-file-contents file
'visit
)
5035 (setq idlwave-user-catalog-routines
5036 (append (idlwave-get-routine-info-from-buffers
5037 (list (current-buffer)))
5038 idlwave-user-catalog-routines
)))))))))
5039 (message "Creating user catalog file...")
5040 (kill-buffer "*idlwave-scan.pro*")
5041 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5042 (let ((font-lock-maximum-size 0)
5043 (auto-mode-alist nil
))
5044 (find-file idlwave-user-catalog-file
))
5045 (if (and (boundp 'font-lock-mode
)
5049 (insert ";; IDLWAVE user catalog file\n")
5050 (insert (format ";; Created %s\n\n" (current-time-string)))
5052 ;; Define the routine info list
5053 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5054 (let ((standard-output (current-buffer)))
5058 (goto-char (point-max)))
5059 idlwave-user-catalog-routines
))
5060 (insert (format "))\n\n;;; %s ends here\n"
5061 (file-name-nondirectory idlwave-user-catalog-file
)))
5062 (goto-char (point-min))
5065 (kill-buffer (current-buffer)))
5066 (message "Creating user catalog file...done")
5067 (message "Info for %d routines saved in %s"
5068 (length idlwave-user-catalog-routines
)
5069 idlwave-user-catalog-file
)
5071 (idlwave-update-routine-info t
))
5073 (defun idlwave-read-paths ()
5074 (if (and (stringp idlwave-path-file
)
5075 (file-regular-p idlwave-path-file
))
5077 (load idlwave-path-file t t t
)
5080 (defun idlwave-write-paths ()
5082 (when (and idlwave-path-alist idlwave-system-directory
)
5083 (let ((font-lock-maximum-size 0)
5084 (auto-mode-alist nil
))
5085 (find-file idlwave-path-file
))
5086 (if (and (boundp 'font-lock-mode
)
5090 (insert ";; IDLWAVE paths\n")
5091 (insert (format ";; Created %s\n\n" (current-time-string)))
5092 ;; Define the variable which knows the value of "!DIR"
5093 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5094 idlwave-system-directory
))
5096 ;; Define the variable which contains a list of all scanned directories
5097 (insert "\n(setq idlwave-path-alist\n '(")
5098 (let ((standard-output (current-buffer)))
5102 (goto-char (point-max)))
5103 idlwave-path-alist
))
5106 (kill-buffer (current-buffer))))
5109 (defun idlwave-expand-path (path &optional default-dir
)
5110 ;; Expand parts of path starting with '+' recursively into directory list.
5111 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5112 (message "Expanding path...")
5113 (let (path1 dir recursive
)
5114 (while (setq dir
(pop path
))
5115 (if (setq recursive
(string= (substring dir
0 1) "+"))
5116 (setq dir
(substring dir
1)))
5118 (not (file-name-absolute-p dir
)))
5119 (setq dir
(expand-file-name dir default-dir
)))
5121 ;; Expand recursively
5122 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5125 (message "Expanding path...done")
5128 (defun idlwave-recursive-directory-list (dir)
5129 ;; Return a list of all directories below DIR, including DIR itself
5130 (let ((path (list dir
)) path1 file files
)
5131 (while (setq dir
(pop path
))
5132 (when (file-directory-p dir
)
5133 (setq files
(nreverse (directory-files dir t
"[^.]")))
5134 (while (setq file
(pop files
))
5135 (if (file-directory-p file
)
5136 (push (file-name-as-directory file
) path
)))
5141 ;;----- Scanning the library catalogs ------------------
5143 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5144 "Scan for library catalog files (.idlwave_catalog) and ingest.
5146 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5147 instead, if present) are searched. Print MESSAGE-BASE along with the
5148 libraries being loaded, if passed, and skip loading/normalizing if
5149 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5150 be set to nil to disable library catalog scanning."
5151 (when idlwave-use-library-catalogs
5153 (if idlwave-library-path
5154 (idlwave-expand-path idlwave-library-path
)
5155 (mapcar 'car idlwave-path-alist
)))
5157 dir-entry dir flags catalog all-routines
)
5158 (if message-base
(message message-base
))
5159 (while (setq dir
(pop dirs
))
5161 (when (file-readable-p
5162 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5164 (setq idlwave-library-catalog-routines nil
)
5165 ;; Load the catalog file
5167 (load catalog t t t
)
5168 (error (throw 'continue t
)))
5171 (not (string= idlwave-library-catalog-libname
5173 (message (concat message-base
5174 idlwave-library-catalog-libname
))
5175 (setq old-libname idlwave-library-catalog-libname
))
5176 (when idlwave-library-catalog-routines
5179 (idlwave-sintern-rinfo-list
5180 idlwave-library-catalog-routines
'sys dir
)
5183 ;; Add a 'lib flag if on path-alist
5184 (when (and idlwave-path-alist
5185 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5186 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5187 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5188 (if message-base
(message (concat message-base
"done"))))))
5190 ;;----- Communicating with the Shell -------------------
5192 ;; First, here is the idl program which can be used to query IDL for
5193 ;; defined routines.
5194 (defconst idlwave-routine-info.pro
5196 ;; START OF IDLWAVE SUPPORT ROUTINES
5197 pro idlwave_print_info_entry,name,func=func,separator=sep
5198 ;; See if it's an object method
5199 if name eq '' then return
5200 func = keyword_set(func)
5201 methsep = strpos(name,'::')
5202 meth = methsep ne -1
5205 pars = routine_info(name,/parameters,functions=func)
5206 source = routine_info(name,/source,functions=func)
5207 nargs = pars.num_args
5208 nkw = pars.num_kw_args
5209 if nargs gt 0 then args = pars.args
5210 if nkw gt 0 then kwargs = pars.kw_args
5212 ;; Trim the class, and make the name
5214 class = strmid(name,0,methsep)
5215 name = strmid(name,methsep+2,strlen(name)-1)
5216 if nargs gt 0 then begin
5217 ;; remove the self argument
5218 wh = where(args ne 'SELF',nargs)
5219 if nargs gt 0 then args = args[wh]
5222 ;; No class, just a normal routine.
5228 if func then cs = 'Result = '
5229 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5231 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5232 if nargs gt 0 then begin
5233 for j=0,nargs-1 do begin
5235 if j lt nargs-1 then cs = cs + ', '
5238 if func then cs = cs + ')'
5239 ;; Keyword arguments
5241 if nkw gt 0 then begin
5242 for j=0,nkw-1 do begin
5243 kwstring = kwstring + ' ' + kwargs[j]
5247 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5249 print,ret + ': ' + name + sep + class + sep + source[0].path $
5250 + sep + cs + sep + kwstring
5253 pro idlwave_routine_info
5256 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5257 all = routine_info()
5258 for i=0,n_elements(all)-1 do $
5259 idlwave_print_info_entry,all[i],separator=sep
5260 all = routine_info(/functions)
5261 for i=0,n_elements(all)-1 do $
5262 idlwave_print_info_entry,all[i],/func,separator=sep
5263 print,'>>>END OF IDLWAVE ROUTINE INFO'
5266 pro idlwave_get_sysvars
5269 if error_status ne 0 then begin
5270 print, 'Cannot get info about system variables'
5272 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5273 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5274 v = strsplit(s,' +',/regex,/extract) ; get variables
5275 for i=0,n_elements(v)-1 do begin
5276 t = [''] ; get tag list
5277 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5278 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5283 pro idlwave_get_class_tags, class
5284 res = execute('tags=tag_names({'+class+'})')
5285 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5287 ;; END OF IDLWAVE SUPPORT ROUTINES
5289 "The idl programs to get info from the shell.")
5291 (defvar idlwave-idlwave_routine_info-compiled nil
5292 "Remembers if the routine info procedure is already compiled.")
5294 (defvar idlwave-shell-temp-pro-file
)
5295 (defvar idlwave-shell-temp-rinfo-save-file
)
5296 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait
)
5297 "Query the shell for routine_info of compiled modules and update the lists."
5298 ;; Save and compile the procedure. The compiled procedure is then
5299 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5300 ;; We need to RESTORE the procedure each time we use it, since
5301 ;; the user may have killed or redefined it. In particular,
5302 ;; .RESET_SESSION will kill all user procedures.
5303 (unless (and idlwave-idlwave_routine_info-compiled
5304 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5306 (set-buffer (idlwave-find-file-noselect
5307 (idlwave-shell-temp-file 'pro
)))
5309 (insert idlwave-routine-info.pro
)
5311 (idlwave-shell-send-command
5312 (concat ".run " idlwave-shell-temp-pro-file
)
5314 ; (message "SENDING SAVE") ; ????????????????????????
5315 (idlwave-shell-send-command
5316 (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5317 (idlwave-shell-temp-file 'rinfo
))
5320 ;; Restore and execute the procedure, analyze the output
5321 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5322 (idlwave-shell-send-command
5323 (format "RESTORE, '%s' & idlwave_routine_info"
5324 idlwave-shell-temp-rinfo-save-file
)
5326 (idlwave-shell-routine-info-filter)
5327 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5330 ;; ---------------------------------------------------------------------------
5332 ;; Completion and displaying routine calling sequences
5334 (defvar idlwave-completion-help-info nil
)
5335 (defvar idlwave-completion-help-links nil
)
5336 (defvar idlwave-current-obj_new-class nil
)
5337 (defvar idlwave-complete-special nil
)
5339 (defun idlwave-complete (&optional arg module class
)
5340 "Complete a function, procedure or keyword name at point.
5341 This function is smart and figures out what can be completed
5343 - At the beginning of a statement it completes procedure names.
5344 - In the middle of a statement it completes function names.
5345 - after a `(' or `,' in the argument list of a function or procedure,
5346 it completes a keyword of the relevant function or procedure.
5347 - In the first arg of `OBJ_NEW', it completes a class name.
5349 When several completions are possible, a list will be displayed in the
5350 *Completions* buffer. If this list is too long to fit into the
5351 window, scrolling can be achieved by repeatedly pressing
5352 \\[idlwave-complete].
5354 The function also knows about object methods. When it needs a class
5355 name, the action depends upon `idlwave-query-class', which see. You
5356 can force IDLWAVE to ask you for a class name with a
5357 \\[universal-argument] prefix argument to this command.
5359 See also the variables `idlwave-keyword-completion-adds-equal' and
5360 `idlwave-function-completion-adds-paren'.
5362 The optional ARG can be used to specify the completion type in order
5363 to override IDLWAVE's idea of what should be completed at point.
5364 Possible values are:
5366 0 <=> query for the completion type
5368 2 <=> 'procedure-keyword
5370 4 <=> 'function-keyword
5371 5 <=> 'procedure-method
5372 6 <=> 'procedure-method-keyword
5373 7 <=> 'function-method
5374 8 <=> 'function-method-keyword
5377 As a special case, the universal argument C-u forces completion of
5378 function names in places where the default would be a keyword.
5380 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5383 For Lisp programmers only:
5384 When we force a keyword, optional argument MODULE can contain the module name.
5385 When we force a method or a method keyword, CLASS can specify the class."
5390 (or (and (integerp arg
) (not (equal arg
'(16))))
5392 (idlwave-make-force-complete-where-list arg module class
)
5394 (what (nth 2 where-list
))
5395 (idlwave-force-class-query (equal arg
'(4)))
5396 (completion-regexp-list
5397 (if (equal arg
'(16))
5398 (list (read-string (concat "Completion Regexp: "))))))
5400 (if (and module
(string-match "::" module
))
5401 (setq class
(substring module
0 (match-beginning 0))
5402 module
(substring module
(match-end 0))))
5407 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5408 (get-buffer-window "*Completions*"))
5409 (setq this-command last-command
)
5410 (idlwave-scroll-completions))
5412 ;; Complete a filename in quotes
5413 ((and (idlwave-in-quote)
5414 (not (eq what
'class
)))
5415 (idlwave-complete-filename))
5417 ;; Check for any special completion functions
5418 ((and idlwave-complete-special
5419 (idlwave-call-special idlwave-complete-special
)))
5422 (error "Nothing to complete here"))
5426 (setq idlwave-completion-help-info
'(class))
5427 (idlwave-complete-class))
5429 ((eq what
'procedure
)
5430 ;; Complete a procedure name
5431 (let* ((cw-list (nth 3 where-list
))
5432 (class-selector (idlwave-determine-class cw-list
'pro
))
5433 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5434 (idlwave-all-class-inherits class-selector
)))
5435 (isa (concat "procedure" (if class-selector
"-method" "")))
5436 (type-selector 'pro
))
5437 (setq idlwave-completion-help-info
5438 (list 'routine nil type-selector class-selector nil super-classes
))
5439 (idlwave-complete-in-buffer
5440 'procedure
(if class-selector
'method
'routine
)
5441 (idlwave-routines) 'idlwave-selector
5442 (format "Select a %s name%s"
5445 (format " (class is %s)"
5446 (if (eq class-selector t
)
5447 "unknown" class-selector
))
5450 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5452 ((eq what
'function
)
5453 ;; Complete a function name
5454 (let* ((cw-list (nth 3 where-list
))
5455 (class-selector (idlwave-determine-class cw-list
'fun
))
5456 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5457 (idlwave-all-class-inherits class-selector
)))
5458 (isa (concat "function" (if class-selector
"-method" "")))
5459 (type-selector 'fun
))
5460 (setq idlwave-completion-help-info
5461 (list 'routine nil type-selector class-selector nil super-classes
))
5462 (idlwave-complete-in-buffer
5463 'function
(if class-selector
'method
'routine
)
5464 (idlwave-routines) 'idlwave-selector
5465 (format "Select a %s name%s"
5468 (format " (class is %s)"
5469 (if (eq class-selector t
)
5470 "unknown" class-selector
))
5473 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5475 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
5477 (idlwave-complete 3))
5479 ((eq what
'procedure-keyword
)
5480 ;; Complete a procedure keyword
5481 (let* ((where (nth 3 where-list
))
5483 (method-selector name
)
5484 (type-selector 'pro
)
5485 (class (idlwave-determine-class where
'pro
))
5486 (class-selector class
)
5487 (super-classes (idlwave-all-class-inherits class-selector
))
5488 (isa (format "procedure%s-keyword" (if class
"-method" "")))
5489 (entry (idlwave-best-rinfo-assq
5490 name
'pro class
(idlwave-routines)))
5491 (list (idlwave-entry-keywords entry
'do-link
)))
5492 (unless (or entry
(eq class t
))
5493 (error "Nothing known about procedure %s"
5494 (idlwave-make-full-name class name
)))
5495 (setq list
(idlwave-fix-keywords name
'pro class list super-classes
))
5496 (unless list
(error (format "No keywords available for procedure %s"
5497 (idlwave-make-full-name class name
))))
5498 (setq idlwave-completion-help-info
5499 (list 'keyword name type-selector class-selector entry super-classes
))
5500 (idlwave-complete-in-buffer
5501 'keyword
'keyword list nil
5502 (format "Select keyword for procedure %s%s"
5503 (idlwave-make-full-name class name
)
5504 (if (or (member '("_EXTRA") list
)
5505 (member '("_REF_EXTRA") list
))
5506 " (note _EXTRA)" ""))
5508 'idlwave-attach-keyword-classes
)))
5510 ((eq what
'function-keyword
)
5511 ;; Complete a function keyword
5512 (let* ((where (nth 3 where-list
))
5514 (method-selector name
)
5515 (type-selector 'fun
)
5516 (class (idlwave-determine-class where
'fun
))
5517 (class-selector class
)
5518 (super-classes (idlwave-all-class-inherits class-selector
))
5519 (isa (format "function%s-keyword" (if class
"-method" "")))
5520 (entry (idlwave-best-rinfo-assq
5521 name
'fun class
(idlwave-routines)))
5522 (list (idlwave-entry-keywords entry
'do-link
))
5524 (unless (or entry
(eq class t
))
5525 (error "Nothing known about function %s"
5526 (idlwave-make-full-name class name
)))
5527 (setq list
(idlwave-fix-keywords name
'fun class list super-classes
))
5528 ;; OBJ_NEW: Messages mention the proper Init method
5529 (setq msg-name
(if (and (null class
)
5530 (string= (upcase name
) "OBJ_NEW"))
5531 (concat idlwave-current-obj_new-class
5532 "::Init (via OBJ_NEW)")
5533 (idlwave-make-full-name class name
)))
5534 (unless list
(error (format "No keywords available for function %s"
5536 (setq idlwave-completion-help-info
5537 (list 'keyword name type-selector class-selector nil super-classes
))
5538 (idlwave-complete-in-buffer
5539 'keyword
'keyword list nil
5540 (format "Select keyword for function %s%s" msg-name
5541 (if (or (member '("_EXTRA") list
)
5542 (member '("_REF_EXTRA") list
))
5543 " (note _EXTRA)" ""))
5545 'idlwave-attach-keyword-classes
)))
5547 (t (error "This should not happen (idlwave-complete)")))))
5549 (defvar idlwave-complete-special nil
5550 "List of special completion functions.
5551 These functions are called for each completion. Each function must
5552 check if its own special completion context is present. If yes, it
5553 should use `idlwave-complete-in-buffer' to do some completion and
5554 return t. If such a function returns t, *no further* attempts to
5555 complete other contexts will be done. If the function returns nil,
5556 other completions will be tried.")
5558 (defun idlwave-call-special (functions &rest args
)
5559 (let ((funcs functions
)
5562 (while (setq fun
(pop funcs
))
5563 (if (setq ret
(apply fun args
))
5567 (defun idlwave-make-force-complete-where-list (what &optional module class
)
5568 ;; Return an artificial WHERE specification to force the completion
5569 ;; routine to complete a specific item independent of context.
5570 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5571 ;; MODULE and CLASS can be used to specify the routine name and class.
5572 ;; The class name will also be found in MODULE if that is like "class::mod".
5573 (let* ((what-list '(("procedure") ("procedure-keyword")
5574 ("function") ("function-keyword")
5575 ("procedure-method") ("procedure-method-keyword")
5576 ("function-method") ("function-method-keyword")
5578 (module (idlwave-sintern-routine-or-method module class
))
5579 (class (idlwave-sintern-class class
))
5583 (intern (completing-read
5584 "Complete what? " what-list nil t
))))
5586 (setq what
(intern (car (nth (1- what
) what-list
)))))
5589 (assoc (symbol-name what
) what-list
))
5591 (t (error "Invalid WHAT"))))
5592 (nil-list '(nil nil nil nil
))
5593 (class-list (list nil nil
(or class t
) nil
)))
5597 ((eq what
'procedure
)
5598 (list nil-list nil-list
'procedure nil-list nil
))
5600 ((eq what
'procedure-keyword
)
5601 (let* ((class-selector nil
)
5603 (type-selector 'pro
)
5605 (idlwave-completing-read
5606 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
5607 (setq pro
(idlwave-sintern-routine pro
))
5608 (list nil-list nil-list
'procedure-keyword
5609 (list pro nil nil nil
) nil
)))
5611 ((eq what
'function
)
5612 (list nil-list nil-list
'function nil-list nil
))
5614 ((eq what
'function-keyword
)
5615 (let* ((class-selector nil
)
5617 (type-selector 'fun
)
5619 (idlwave-completing-read
5620 "Function: " (idlwave-routines) 'idlwave-selector
))))
5621 (setq func
(idlwave-sintern-routine func
))
5622 (list nil-list nil-list
'function-keyword
5623 (list func nil nil nil
) nil
)))
5625 ((eq what
'procedure-method
)
5626 (list nil-list nil-list
'procedure class-list nil
))
5628 ((eq what
'procedure-method-keyword
)
5629 (let* ((class (idlwave-determine-class class-list
'pro
))
5630 (class-selector class
)
5631 (super-classes (idlwave-all-class-inherits class-selector
))
5632 (type-selector 'pro
)
5634 (idlwave-completing-read
5635 (format "Procedure in %s class: " class-selector
)
5636 (idlwave-routines) 'idlwave-selector
))))
5637 (setq pro
(idlwave-sintern-method pro
))
5638 (list nil-list nil-list
'procedure-keyword
5639 (list pro nil class nil
) nil
)))
5641 ((eq what
'function-method
)
5642 (list nil-list nil-list
'function class-list nil
))
5644 ((eq what
'function-method-keyword
)
5645 (let* ((class (idlwave-determine-class class-list
'fun
))
5646 (class-selector class
)
5647 (super-classes (idlwave-all-class-inherits class-selector
))
5648 (type-selector 'fun
)
5650 (idlwave-completing-read
5651 (format "Function in %s class: " class-selector
)
5652 (idlwave-routines) 'idlwave-selector
))))
5653 (setq func
(idlwave-sintern-method func
))
5654 (list nil-list nil-list
'function-keyword
5655 (list func nil class nil
) nil
)))
5658 (list nil-list nil-list
'class nil-list nil
))
5660 (t (error "Invalid value for WHAT")))))
5662 (defun idlwave-completing-read (&rest args
)
5663 ;; Completing read, case insensitive
5664 (let ((old-value (default-value 'completion-ignore-case
)))
5667 (setq-default completion-ignore-case t
)
5668 (apply 'completing-read args
))
5669 (setq-default completion-ignore-case old-value
))))
5671 (defvar idlwave-shell-default-directory
)
5672 (defun idlwave-complete-filename ()
5673 "Use the comint stuff to complete a file name."
5675 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5676 (comint-completion-addsuffix nil
)
5678 (if (and (boundp 'idlwave-shell-default-directory
)
5679 (stringp idlwave-shell-default-directory
)
5680 (file-directory-p idlwave-shell-default-directory
))
5681 idlwave-shell-default-directory
5682 default-directory
)))
5683 (comint-dynamic-complete-filename)))
5685 (defun idlwave-make-full-name (class name
)
5686 ;; Make a fully qualified module name including the class name
5687 (concat (if class
(format "%s::" class
) "") name
))
5689 (defun idlwave-rinfo-assoc (name type class list
)
5690 "Like `idlwave-rinfo-assq', but sintern strings first."
5692 (idlwave-sintern-routine-or-method name class
)
5693 type
(idlwave-sintern-class class
) list
))
5695 (defun idlwave-rinfo-assq (name type class list
)
5696 ;; Works like assq, but also checks type and class
5699 (while (setq match
(assq name list
))
5700 (and (or (eq type t
)
5701 (eq (nth 1 match
) type
))
5702 (eq (nth 2 match
) class
)
5703 (throw 'exit match
))
5704 (setq list
(cdr (memq match list
)))))))
5706 (defun idlwave-rinfo-assq-any-class (name type class list
)
5707 ;; Return the first matching method on the inheritance list
5708 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
5711 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
5712 (setq classes nil
)))
5715 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
5717 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
5718 If WITH-FILE is passed, find the best rinfo entry with a file
5719 included. If KEEP-SYSTEM is set, don't prune system for compiled
5721 (let ((twins (idlwave-routine-twins
5722 (idlwave-rinfo-assq-any-class name type class list
)
5725 (when (> (length twins
) 1)
5726 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
5727 (if (and (null keep-system
)
5728 (eq 'system
(car (nth 3 (car twins
))))
5729 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
5730 (not (equal 1 syslibp
)))
5731 ;; Its a compiled syslib, so we need to remove the system entry
5732 (setq twins
(cdr twins
)))
5734 (setq twins
(delq nil
5736 (if (nth 1 (nth 3 x
)) x
))
5740 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
5742 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5743 (idlwave-best-rinfo-assq
5744 (idlwave-sintern-routine-or-method name class
)
5745 type
(idlwave-sintern-class class
) list with-file keep-system
))
5747 (defun idlwave-any-syslib (entries)
5748 "Does the entry list ENTRIES contain a syslib entry?
5749 If yes, return the index (>=1)."
5754 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
5755 (if (and file
(idlwave-syslib-p file
))
5757 (setq entries
(cdr entries
))))
5760 (defun idlwave-all-assq (key list
)
5761 "Return a list of all associations of Key in LIST."
5763 (while (setq elt
(assq key list
))
5765 (setq list
(cdr (memq elt list
))))
5768 (defun idlwave-all-method-classes (method &optional type
)
5769 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5770 When TYPE is not specified, both procedures and functions will be considered."
5772 (mapcar 'car
(idlwave-class-alist))
5777 (eq type
(nth 1 x
)))
5778 (push (nth 2 x
) rtn
)))
5779 (idlwave-all-assq method
(idlwave-routines)))
5780 (idlwave-uniquify rtn
))))
5782 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
5783 "Return all classes which have a method METHOD with keyword KEYWORD.
5784 TYPE is 'fun or 'pro.
5785 When TYPE is not specified, both procedures and functions will be considered."
5786 (if (or (null method
)
5791 (and (nth 2 x
) ; non-nil class
5792 (or (not type
) ; correct or unspecified type
5793 (eq type
(nth 1 x
)))
5794 (assoc keyword
(idlwave-entry-keywords x
))
5795 (push (nth 2 x
) rtn
)))
5796 (idlwave-all-assq method
(idlwave-routines)))
5797 (idlwave-uniquify rtn
))))
5799 (defun idlwave-members-only (list club
)
5800 "Return list of all elements in LIST which are also in CLUB."
5803 (if (member (car list
) club
)
5804 (setq rtn
(cons (car list
) rtn
)))
5805 (setq list
(cdr list
)))
5808 (defun idlwave-nonmembers-only (list club
)
5809 "Return list of all elements in LIST which are not in CLUB."
5812 (if (member (car list
) club
)
5814 (setq rtn
(cons (car list
) rtn
)))
5815 (setq list
(cdr list
)))
5818 (defun idlwave-explicit-class-listed (info)
5819 "Return whether or not the class is listed explicitly, ala a->b::c.
5820 INFO is as returned by idlwave-what-function or -procedure."
5821 (let ((apos (nth 3 info
)))
5823 (save-excursion (goto-char apos
)
5824 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5826 (defvar idlwave-determine-class-special nil
5827 "List of special functions for determining class.
5828 Must accept two arguments: `apos' and `info'")
5830 (defun idlwave-determine-class (info type
)
5831 ;; Determine the class of a routine call.
5832 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5833 ;; The second element in this structure is the class. When nil, we
5834 ;; return nil. When t, try to get the class from text properties at
5835 ;; the arrow. When the object is "self", we use the class of the
5836 ;; current routine. otherwise prompt the user for a class name.
5837 ;; Also stores the selected class as a text property at the arrow.
5838 ;; TYPE is 'fun or 'pro.
5839 (let* ((class (nth 2 info
))
5841 (nassoc (assoc (if (stringp (car info
))
5844 idlwave-query-class
))
5845 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
5846 idlwave-query-class
))
5847 (query (cond (nassoc (cdr nassoc
))
5848 (dassoc (cdr dassoc
))
5850 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
5853 (save-excursion (goto-char apos
)
5855 (let ((case-fold-search t
))
5856 (looking-at "self\\>")))))
5857 (force-query idlwave-force-class-query
)
5858 store special-class class-alist
)
5862 ;; There is an object which would like to know its class
5863 (if (and arrow
(get-text-property apos
'idlwave-class
)
5864 idlwave-store-inquired-class
5866 (setq class
(get-text-property apos
'idlwave-class
)
5867 class
(idlwave-sintern-class class
)))
5868 (if (and (eq t class
) is-self
)
5869 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
5871 ;; Before prompting, try any special class determination routines
5872 (when (and (eq t class
)
5873 idlwave-determine-class-special
5876 (idlwave-call-special idlwave-determine-class-special apos
))
5878 (setq class
(idlwave-sintern-class special-class
)
5879 store idlwave-store-inquired-class
)))
5881 ;; Prompt for a class, if we need to
5882 (when (and (eq class t
)
5883 (or force-query query
))
5885 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
5887 (idlwave-sintern-class
5889 ((and (= (length class-alist
) 0) (not force-query
))
5890 (error "No classes available with method %s" (car info
)))
5891 ((and (= (length class-alist
) 1) (not force-query
))
5892 (car (car class-alist
)))
5894 (setq store idlwave-store-inquired-class
)
5895 (idlwave-completing-read
5896 (format "Class%s: " (if (stringp (car info
))
5897 (format " for %s method %s"
5900 class-alist nil nil nil
'idlwave-class-history
))))))
5902 ;; Store it, if requested
5903 (when (and class
(not (eq t class
)))
5904 ;; We have a real class here
5905 (when (and store arrow
)
5907 (add-text-properties
5909 `(idlwave-class ,class face
,idlwave-class-arrow-face
5912 (setf (nth 2 info
) class
))
5915 ;; Default as fallback
5918 (defvar type-selector
)
5919 (defvar class-selector
)
5920 (defvar method-selector
)
5921 (defvar super-classes
)
5922 (defun idlwave-selector (a)
5923 (and (eq (nth 1 a
) type-selector
)
5924 (or (and (nth 2 a
) (eq class-selector t
))
5925 (eq (nth 2 a
) class-selector
)
5926 (memq (nth 2 a
) super-classes
))))
5928 (defun idlwave-add-file-link-selector (a)
5929 ;; Record a file link, if any, for the tested names during selection.
5930 (let ((sel (idlwave-selector a
)) file
)
5931 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
5932 (push (cons (car a
) file
) idlwave-completion-help-links
))
5936 (defun idlwave-where ()
5937 "Find out where we are.
5938 The return value is a list with the following stuff:
5939 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5941 PRO-LIST (PRO POINT CLASS ARROW)
5942 FUNC-LIST (FUNC POINT CLASS ARROW)
5943 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5944 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5946 LAST-CHAR last relevant character before point (non-white non-comment,
5947 not part of current identifier or leading slash).
5949 In the lists, we have these meanings:
5952 POINT: Where is this
5953 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5954 ARROW: Location of the arrow"
5956 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5957 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
5958 (func-entry (idlwave-what-function bos
))
5959 (func (car func-entry
))
5960 (func-class (nth 1 func-entry
))
5961 (func-arrow (nth 2 func-entry
))
5962 (func-point (or (nth 3 func-entry
) 0))
5963 (func-level (or (nth 4 func-entry
) 0))
5964 (pro-entry (idlwave-what-procedure bos
))
5965 (pro (car pro-entry
))
5966 (pro-class (nth 1 pro-entry
))
5967 (pro-arrow (nth 2 pro-entry
))
5968 (pro-point (or (nth 3 pro-entry
) 0))
5969 (last-char (idlwave-last-valid-char))
5970 (case-fold-search t
)
5971 (match-string (buffer-substring bos
(point)))
5972 cw cw-mod cw-arrow cw-class cw-point
)
5973 (if (< func-point pro-point
) (setq func nil
))
5975 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
5979 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
5981 (buffer-substring pro-point
(point))
5983 (setq cw
'procedure cw-class pro-class cw-point pro-point
5984 cw-arrow pro-arrow
))
5985 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
5988 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
5991 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
5995 (> func-point pro-point
)
5997 (memq last-char
'(?\
( ?
,)))
5998 (setq cw
'function-keyword cw-mod func cw-point func-point
5999 cw-class func-class cw-arrow func-arrow
))
6000 ((and pro
(eq last-char ?
,))
6001 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
6002 cw-class pro-class cw-arrow pro-arrow
))
6003 ; ((member last-char '(?\' ?\) ?\] ?!))
6004 ; ;; after these chars, a function makes no sense
6005 ; ;; FIXME: I am sure there can be more in this list
6006 ; ;; FIXME: Do we want to do this at all?
6008 ;; Everywhere else we try a function.
6012 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6013 (setq cw-arrow
(copy-marker (match-beginning 0))
6014 cw-class
(if (match-end 4)
6015 (idlwave-sintern-class (match-string 4))
6017 (list (list pro pro-point pro-class pro-arrow
)
6018 (list func func-point func-class func-arrow
)
6020 (list cw-mod cw-point cw-class cw-arrow
)
6023 (defun idlwave-this-word (&optional class
)
6024 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6025 (setq class
(or class
"a-zA-Z0-9$_."))
6028 (progn (skip-chars-backward class
) (point))
6029 (progn (skip-chars-forward class
) (point)))))
6031 (defun idlwave-what-function (&optional bound
)
6032 ;; Find out if point is within the argument list of a function.
6033 ;; The return value is ("function-name" class arrow-start (point) level).
6034 ;; Level is 1 on the top level parentheses, higher further down.
6036 ;; If the optional BOUND is an integer, bound backwards directed
6037 ;; searches to this point.
6043 func arrow-start class
)
6044 (idlwave-with-special-syntax
6047 (narrow-to-region (max 1 (or bound
0)) (point-max))
6048 ;; move back out of the current parenthesis
6049 (while (condition-case nil
6050 (progn (up-list -
1) t
)
6054 (when (and (= (following-char) ?\
()
6056 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6058 (setq func
(match-string 2)
6059 func-point
(goto-char (match-beginning 2))
6061 (if (re-search-backward
6062 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6063 (setq arrow-start
(copy-marker (match-beginning 0))
6064 class
(or (match-string 2) t
)))
6068 (idlwave-sintern-routine-or-method func class
)
6069 (idlwave-sintern-class class
)
6070 arrow-start func-point cnt
)))
6072 (throw 'exit nil
)))))))
6074 (defun idlwave-what-procedure (&optional bound
)
6075 ;; Find out if point is within the argument list of a procedure.
6076 ;; The return value is ("procedure-name" class arrow-pos (point)).
6078 ;; If the optional BOUND is an integer, bound backwards directed
6079 ;; searches to this point.
6080 (let ((pos (point)) pro-point
6081 pro class arrow-start string
)
6083 ;;(idlwave-beginning-of-statement)
6084 (idlwave-start-of-substatement 'pre
)
6085 (setq string
(buffer-substring (point) pos
))
6087 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6088 (setq pro
(match-string 1 string
)
6089 pro-point
(+ (point) (match-beginning 1)))
6090 (if (and (idlwave-skip-object)
6091 (setq string
(buffer-substring (point) pos
))
6093 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6095 (setq pro
(if (match-beginning 4)
6096 (match-string 4 string
))
6097 pro-point
(if (match-beginning 4)
6098 (+ (point) (match-beginning 4))
6100 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6101 class
(or (match-string 3 string
) t
)))))
6102 (list (idlwave-sintern-routine-or-method pro class
)
6103 (idlwave-sintern-class class
)
6107 (defun idlwave-skip-object ()
6108 ;; If there is an object at point, move over it and return t.
6109 (let ((pos (point)))
6112 (skip-chars-forward " ") ; white space
6113 (skip-chars-forward "*") ; de-reference
6115 ((looking-at idlwave-identifier
)
6116 (goto-char (match-end 0)))
6117 ((eq (following-char) ?\
()
6119 (t (throw 'exit nil
)))
6122 (cond ((eq (following-char) ?.
)
6124 (if (not (looking-at idlwave-identifier
))
6126 (goto-char (match-end 0)))
6127 ((memq (following-char) '(?\
( ?\
[))
6130 (error (throw 'exit nil
))))
6131 (t (throw 'endwhile t
)))))
6132 (if (looking-at "[ \t]*->")
6133 (throw 'exit
(setq pos
(match-beginning 0)))
6134 (throw 'exit nil
))))
6138 (defun idlwave-last-valid-char ()
6139 "Return the last character before point which is not white or a comment
6140 and also not part of the current identifier. Since we do this in
6141 order to identify places where keywords are, we consider the initial
6142 `/' of a keyword as part of the identifier.
6143 This function is not general, can only be used for completion stuff."
6146 ;; skip the current identifier
6147 (skip-chars-backward "a-zA-Z0-9_$")
6148 ;; also skip a leading slash which might be belong to the keyword
6149 (if (eq (preceding-char) ?
/)
6151 ;; FIXME: does not check if this is a valid identifier
6153 (skip-chars-backward " \t")
6155 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6156 ((eq (preceding-char) ?
\n)
6157 (beginning-of-line 0)
6158 (if (looking-at "\\([^;\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6159 ;; continuation line
6160 (goto-char (match-end 1))
6162 (t (throw 'exit
(preceding-char))))))))
6164 (defvar idlwave-complete-after-success-form nil
6165 "A form to evaluate after successful completion.")
6166 (defvar idlwave-complete-after-success-form-force nil
6167 "A form to evaluate after completion selection in *Completions* buffer.")
6168 (defconst idlwave-completion-mark
(make-marker)
6169 "A mark pointing to the beginning of the completion string.")
6171 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6172 &optional prepare-display-function
6174 "Perform TYPE completion of word before point against LIST.
6175 SELECTOR is the PREDICATE argument for the completion function. Show
6176 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6177 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6178 used only once, for `all-completions', and can be used to, e.g.,
6179 accumulate information on matching completions."
6180 (let* ((completion-ignore-case t
)
6181 beg
(end (point)) slash part spart completion all-completions
6185 (error (concat prompt
": No completions available")))
6187 ;; What is already in the buffer?
6189 (skip-chars-backward "a-zA-Z0-9_$")
6190 (setq slash
(eq (preceding-char) ?
/)
6192 idlwave-complete-after-success-form
6193 (list 'idlwave-after-successful-completion
6194 (list 'quote type
) slash beg
)
6195 idlwave-complete-after-success-form-force
6196 (list 'idlwave-after-successful-completion
6197 (list 'quote type
) slash
(list 'quote
'force
))))
6200 (setq part
(buffer-substring beg end
)
6201 dpart
(downcase part
)
6202 spart
(idlwave-sintern stype part
)
6203 completion
(try-completion part list selector
)
6204 dcompletion
(if (stringp completion
) (downcase completion
))
6205 idlwave-completion-help-links nil
)
6208 ;; nothing available.
6209 (error (concat prompt
": no completion for \"%s\"") part
))
6210 ((and (not (equal dpart dcompletion
))
6211 (not (eq t completion
)))
6212 ;; We can add something
6213 (delete-region beg end
)
6214 (if (and (string= part dpart
)
6215 (or (not (string= part
""))
6216 idlwave-complete-empty-string-as-lower-case
)
6217 (not idlwave-completion-force-default-case
))
6218 (insert dcompletion
)
6219 (insert completion
))
6220 (if (eq t
(try-completion completion list selector
))
6221 ;; Now this is a unique match
6222 (idlwave-after-successful-completion type slash beg
))
6224 ((or (eq completion t
)
6225 (and (= 1 (length (setq all-completions
6227 (all-completions part list
6228 (or special-selector
6230 (equal dpart dcompletion
)))
6231 ;; This is already complete
6232 (idlwave-after-successful-completion type slash beg
)
6233 (message "%s is already the complete %s" part isa
)
6236 ;; We cannot add something - offer a list.
6237 (message "Making completion list...")
6239 (unless idlwave-completion-help-links
; already set somewhere?
6240 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6241 (let ((link (get-text-property 0 'link
(car x
))))
6243 (push (cons (car x
) link
)
6244 idlwave-completion-help-links
))))
6246 (let* ((list all-completions
)
6247 ;; "complete" means, this is already a valid completion
6248 (complete (memq spart all-completions
))
6249 (completion-highlight-first-word-only t
)) ; XEmacs
6250 ; (completion-fixup-function ; Emacs
6251 ; (lambda () (and (eq (preceding-char) ?>)
6252 ; (re-search-backward " <" beg t)))))
6254 (setq list
(sort list
(lambda (a b
)
6255 (string< (downcase a
) (downcase b
)))))
6256 (if prepare-display-function
6257 (setq list
(funcall prepare-display-function list
)))
6258 (if (and (string= part dpart
)
6259 (or (not (string= part
""))
6260 idlwave-complete-empty-string-as-lower-case
)
6261 (not idlwave-completion-force-default-case
))
6262 (setq list
(mapcar (lambda (x)
6264 (setcar x
(downcase (car x
)))
6265 (setq x
(downcase x
)))
6268 (idlwave-display-completion-list list prompt beg complete
))
6271 (defun idlwave-complete-class ()
6272 "Complete a class at point."
6274 ;; Call `idlwave-routines' to make sure the class list will be available
6276 ;; Check for the special case of completing empty string after pro/function
6277 (if (let ((case-fold-search t
))
6280 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6282 (goto-char (point-min))
6284 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6285 ;; Yank the full class specification
6286 (insert (match-string 2))
6287 ;; Do the completion, using list gathered from `idlwave-routines'
6288 (idlwave-complete-in-buffer
6289 'class
'class
(idlwave-class-alist) nil
6290 "Select a class" "class"
6291 '(lambda (list) ;; Push it to help-links if system help available
6293 (let* ((entry (idlwave-class-info x
))
6294 (link (nth 1 (assq 'link entry
))))
6295 (if link
(push (cons x link
)
6296 idlwave-completion-help-links
))
6300 (defun idlwave-attach-classes (list type show-classes
)
6301 ;; Attach the proper class list to a LIST of completion items.
6302 ;; TYPE, when 'kwd, shows classes for method keywords, when
6303 ;; 'class-tag, for class tags, and otherwise for methods.
6304 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6305 (if (or (null show-classes
) ; don't want to see classes
6306 (null class-selector
) ; not a method call
6308 (stringp class-selector
) ; the class is already known
6309 (not super-classes
))) ; no possibilities for inheritance
6310 ;; In these cases, we do not have to do anything
6312 (let* ((do-prop (and (>= show-classes
0)
6313 (>= emacs-major-version
21)))
6314 (do-buf (not (= show-classes
0)))
6315 ;; (do-dots (featurep 'xemacs))
6317 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6318 (cons class-selector super-classes
)))
6319 (max (abs show-classes
))
6320 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6321 classes nclasses class-info space
)
6325 (if (eq type
'class-tag
)
6326 ;; Just one class for tags
6329 (idlwave-class-or-superclass-with-tag class-selector x
)))
6330 ;; Multiple classes for method or method-keyword
6333 (idlwave-all-method-keyword-classes
6334 method-selector x type-selector
)
6335 (idlwave-all-method-classes x type-selector
)))
6339 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6341 (setq nclasses
(length classes
))
6342 ;; Make the separator between item and class-info
6344 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6347 ;; We do want info in the buffer
6348 (if (<= nclasses max
)
6349 (setq class-info
(concat
6351 "<" (mapconcat 'identity classes
",") ">"))
6352 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6353 (setq class-info nil
))
6355 ;; We do want properties
6356 (setq x
(copy-sequence x
))
6357 (put-text-property 0 (length x
)
6358 'help-echo
(mapconcat 'identity classes
" ")
6365 (defun idlwave-attach-method-classes (list)
6366 ;; Call idlwave-attach-classes with method parameters
6367 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6368 (defun idlwave-attach-keyword-classes (list)
6369 ;; Call idlwave-attach-classes with keyword parameters
6370 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6371 (defun idlwave-attach-class-tag-classes (list)
6372 ;; Call idlwave-attach-classes with class structure tags
6373 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6376 ;;----------------------------------------------------------------------
6377 ;;----------------------------------------------------------------------
6378 ;;----------------------------------------------------------------------
6379 ;;----------------------------------------------------------------------
6380 ;;----------------------------------------------------------------------
6382 (defun idlwave-pset (item)
6385 (defun idlwave-popup-select (ev list title
&optional sort
)
6386 "Select an item in LIST with a popup menu.
6387 TITLE is the title to put atop the popup. If SORT is non-nil,
6388 sort the list before displaying"
6389 (let ((maxpopup idlwave-max-popup-menu-items
)
6392 ((= 1 (length list
))
6393 (setq rtn
(car list
)))
6395 (if sort
(setq list
(sort list
(lambda (a b
)
6396 (string< (upcase a
) (upcase b
))))))
6398 (append (list title
)
6399 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6402 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6403 (setq resp
(get-popup-menu-response menu
))
6404 (funcall (event-function resp
) (event-object resp
)))
6406 (if sort
(setq list
(sort list
(lambda (a b
)
6407 (string< (upcase a
) (upcase b
))))))
6408 (setq menu
(cons title
6411 (mapcar (lambda(x) (cons x x
)) list
)))))
6412 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6413 (setq rtn
(x-popup-menu ev menu
))))
6416 (defun idlwave-split-menu-xemacs (menu N
)
6417 "Split the MENU into submenus of maximum length N."
6418 (if (<= (length menu
) (1+ N
))
6419 ;; No splitting needed
6421 (let* ((title (car menu
))
6422 (entries (cdr menu
))
6427 (while (and entries
(< cnt N
))
6429 nextmenu
(cons (car entries
) nextmenu
)
6430 entries
(cdr entries
)))
6431 (setq nextmenu
(nreverse nextmenu
))
6432 (setq nextmenu
(cons (format "%s...%s"
6433 (aref (car nextmenu
) 0)
6434 (aref (nth (1- cnt
) nextmenu
) 0))
6436 (setq menu
(cons nextmenu menu
)
6441 (defun idlwave-split-menu-emacs (menu N
)
6442 "Split the MENU into submenus of maximum length N."
6443 (if (<= (length (nth 1 menu
)) (1+ N
))
6444 ;; No splitting needed
6446 (let* ((title (car menu
))
6447 (entries (cdr (nth 1 menu
)))
6452 (while (and entries
(< cnt N
))
6454 nextmenu
(cons (car entries
) nextmenu
)
6455 entries
(cdr entries
)))
6456 (setq nextmenu
(nreverse nextmenu
))
6458 (setq nextmenu
(cons (format "%s...%s"
6459 (car (car nextmenu
))
6460 (car (nth (1- cnt
) nextmenu
)))
6462 (setq menu
(cons nextmenu menu
)
6465 (setq menu
(nreverse menu
))
6466 (setq menu
(cons title menu
))
6469 (defvar idlwave-completion-setup-hook nil
)
6471 (defun idlwave-scroll-completions (&optional message
)
6472 "Scroll the completion window on this frame."
6473 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
6474 (win (selected-window)))
6477 (select-window cwin
)
6480 (error (if (and (listp last-command
)
6481 (nth 2 last-command
))
6484 (eval idlwave-complete-after-success-form
))
6485 (set-window-start cwin
(point-min)))))
6486 (and message
(message message
)))
6487 (select-window win
))))
6489 (defun idlwave-display-completion-list (list &optional message beg complete
)
6490 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6491 (unless (and (get-buffer-window "*Completions*")
6492 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
6493 (move-marker idlwave-completion-mark beg
)
6494 (setq idlwave-before-completion-wconf
(current-window-configuration)))
6496 (if (featurep 'xemacs
)
6497 (idlwave-display-completion-list-xemacs
6499 (idlwave-display-completion-list-emacs list
))
6501 ;; Store a special value in `this-command'. When `idlwave-complete'
6502 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6503 (setq this-command
(list 'idlwave-display-completion-list message complete
))
6505 ;; Mark the completions buffer as created by cib
6506 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
6508 ;; Fontify the classes
6509 (if (and idlwave-completion-fontify-classes
6511 (idlwave-completion-fontify-classes))
6514 (run-hooks 'idlwave-completion-setup-hook
)
6516 ;; Display the message
6517 (message (or message
"Making completion list...done")))
6519 (defun idlwave-choose (function &rest args
)
6520 "Call FUNCTION as a completion chooser and pass ARGS to it."
6521 (let ((completion-ignore-case t
)) ; install correct value
6522 (apply function args
))
6523 (if (and (eq major-mode
'idlwave-shell-mode
)
6524 (boundp 'font-lock-mode
)
6525 (not font-lock-mode
))
6526 ;; For the shell, remove the fontification of the word before point
6527 (let ((beg (save-excursion
6528 (skip-chars-backward "a-zA-Z0-9_")
6530 (remove-text-properties beg
(point) '(face nil
))))
6531 (eval idlwave-complete-after-success-form-force
))
6533 (defun idlwave-keyboard-quit ()
6536 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
6537 (idlwave-restore-wconf-after-completion))
6540 (defun idlwave-restore-wconf-after-completion ()
6541 "Restore the old (before completion) window configuration."
6542 (and idlwave-completion-restore-window-configuration
6543 idlwave-before-completion-wconf
6544 (set-window-configuration idlwave-before-completion-wconf
)))
6546 (defun idlwave-one-key-select (sym prompt delay
)
6547 "Make the user select an element from the alist in the variable SYM.
6548 The keys of the alist are expected to be strings. The function returns the
6549 car of the selected association.
6550 To do this, PROMPT is displayed and and the user must hit a letter key to
6551 select an entry. If the user does not reply within DELAY seconds, a help
6552 window with the options is displayed automatically.
6553 The key which is associated with each option is generated automatically.
6554 First, the strings are checked for preselected keys, like in \"[P]rint\".
6555 If these don't exist, a letter in the string is automatically selected."
6556 (let* ((alist (symbol-value sym
))
6557 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
6558 '(fit-window-to-buffer)))
6560 ;; First check the cache
6561 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
6562 (setq keys-alist
(get sym
:one-key-alist-cache
))
6563 ;; Need to make new list
6564 (setq keys-alist
(idlwave-make-one-key-alist alist
))
6565 (put sym
:one-key-alist-cache keys-alist
)
6566 (put sym
:one-key-alist-last alist
))
6567 ;; Display prompt and wait for quick reply
6568 (message "%s[%s]" prompt
6569 (mapconcat (lambda(x) (char-to-string (car x
)))
6572 ;; No quick reply: Show help
6573 (save-window-excursion
6574 (with-output-to-temp-buffer "*Completions*"
6579 (setq char
(read-char)))
6580 (setq char
(read-char)))
6582 ;; Return the selected result
6583 (nth 2 (assoc char keys-alist
))))
6585 ;; Used for, e.g., electric debug super-examine.
6586 (defun idlwave-make-one-key-alist (alist)
6587 "Make an alist for single key selection."
6588 (let ((l alist
) keys-alist name start char help
6590 (case-fold-search nil
))
6592 (setq name
(car (car l
))
6595 ;; First check if the configuration predetermined a key
6596 (if (string-match "\\[\\(.\\)\\]" name
)
6598 (setq char
(string-to-char (downcase (match-string 1 name
)))
6599 help
(format "%c: %s" char name
)
6600 keys-alist
(cons (list char help name
) keys-alist
))
6602 ;; Then check for capital letters
6604 (while (string-match "[A-Z]" name start
)
6605 (setq start
(match-end 0)
6606 char
(string-to-char (downcase (match-string 0 name
))))
6607 (if (not (assoc char keys-alist
))
6609 (setq help
(format "%c: %s" char
6611 (concat "[" (match-string 0 name
) "]")
6613 keys-alist
(cons (list char help name
) keys-alist
))
6615 ;; Now check for lowercase letters
6617 (while (string-match "[a-z]" name start
)
6618 (setq start
(match-end 0)
6619 char
(string-to-char (match-string 0 name
)))
6620 (if (not (assoc char keys-alist
))
6622 (setq help
(format "%c: %s" char
6624 (concat "[" (match-string 0 name
) "]")
6626 keys-alist
(cons (list char help name
) keys-alist
))
6628 ;; Bummer, nothing found! Use a stupid number
6629 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
6630 help
(format "%c: %s" char name
)
6631 keys-alist
(cons (list char help name
) keys-alist
))))
6632 (nreverse keys-alist
)))
6634 (defun idlwave-set-local (var value
&optional buffer
)
6635 "Set the buffer-local value of VAR in BUFFER to VALUE."
6637 (set-buffer (or buffer
(current-buffer)))
6638 (set (make-local-variable var
) value
)))
6640 (defun idlwave-local-value (var &optional buffer
)
6641 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6643 (set-buffer (or buffer
(current-buffer)))
6644 (and (local-variable-p var
(current-buffer))
6645 (symbol-value var
))))
6647 ;; In XEmacs, we can use :activate-callback directly to advice the
6648 ;; choose functions. We use the private keymap only for the online
6651 (defvar idlwave-completion-map nil
6652 "Keymap for completion-list-mode with idlwave-complete.")
6654 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
6655 (with-output-to-temp-buffer "*Completions*"
6656 (apply 'display-completion-list list
6657 ':activate-callback
'idlwave-default-choose-completion
6660 (set-buffer "*Completions*")
6662 (or idlwave-completion-map
6663 (setq idlwave-completion-map
6664 (idlwave-make-modified-completion-map-xemacs
6665 (current-local-map)))))))
6667 (defun idlwave-default-choose-completion (&rest args
)
6668 "Execute `default-choose-completion' and then restore the win-conf."
6669 (apply 'idlwave-choose
'default-choose-completion args
))
6671 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6672 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6673 (let ((new-map (copy-keymap old-map
)))
6674 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
6675 (define-key new-map [button3] (lambda ()
6677 (setq this-command last-command)))
6680 ;; In Emacs we also replace keybindings in the completion
6681 ;; map in order to install our wrappers.
6683 (defun idlwave-display-completion-list-emacs (list)
6684 "Display completion list and install the choose wrappers."
6685 (with-output-to-temp-buffer "*Completions*"
6686 (display-completion-list list))
6688 (set-buffer "*Completions*")
6690 (or idlwave-completion-map
6691 (setq idlwave-completion-map
6692 (idlwave-make-modified-completion-map-emacs
6693 (current-local-map)))))))
6695 (defun idlwave-make-modified-completion-map-emacs (old-map)
6696 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6697 (let ((new-map (copy-keymap old-map)))
6698 (substitute-key-definition
6699 'choose-completion 'idlwave-choose-completion new-map)
6700 (substitute-key-definition
6701 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6702 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6705 (defun idlwave-choose-completion (&rest args)
6706 "Choose the completion that point is in or next to."
6708 (apply 'idlwave-choose 'choose-completion args))
6710 (defun idlwave-mouse-choose-completion (&rest args)
6711 "Click on an alternative in the `*Completions*' buffer to choose it."
6713 (apply 'idlwave-choose 'mouse-choose-completion args))
6715 ;;----------------------------------------------------------------------
6716 ;;----------------------------------------------------------------------
6718 ;;; ------------------------------------------------------------------------
6719 ;;; Stucture parsing code, and code to manage class info
6722 ;; - Go again over the documentation how to write a completion
6723 ;; plugin. It is in self.el, but currently still very bad.
6724 ;; This could be in a separate file in the distribution, or
6725 ;; in an appendix for the manual.
6727 (defvar idlwave-struct-skip
6728 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
6729 "Regexp for skipping continued blank or comment-only lines in
6732 (defvar idlwave-struct-tag-regexp
6733 (concat "[{,]" ;leading comma/brace
6734 idlwave-struct-skip ; 4 groups
6735 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
6736 "[ \t]*:") ; the final colon
6737 "Regexp for structure tags.")
6739 (defun idlwave-struct-tags ()
6740 "Return a list of all tags in the structure defined at point.
6741 Point is expected just before the opening `{' of the struct definition."
6743 (let* ((borders (idlwave-struct-borders))
6749 (narrow-to-region beg end)
6750 (while (re-search-forward idlwave-struct-tag-regexp end t)
6751 ;; Check if we are still on the top level of the structure.
6752 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6754 (push (match-string-no-properties 5) tags))
6755 (goto-char (match-end 0))))
6758 (defun idlwave-find-struct-tag (tag)
6759 "Find a given TAG in the structure defined at point."
6760 (let* ((borders (idlwave-struct-borders))
6763 (case-fold-search t))
6764 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6767 (defun idlwave-struct-inherits ()
6768 "Return a list of all `inherits' names in the struct at point.
6769 Point is expected just before the opening `{' of the struct definition."
6771 (let* ((borders (idlwave-struct-borders))
6774 (case-fold-search t)
6778 (narrow-to-region beg end)
6779 (while (re-search-forward
6780 (concat "[{,]" ;leading comma/brace
6781 idlwave-struct-skip ; 4 groups
6782 "inherits" ; The INHERITS tag
6783 idlwave-struct-skip ; 4 more
6784 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
6786 ;; Check if we are still on the top level of the structure.
6787 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6789 (push (match-string-no-properties 9) names))
6790 (goto-char (match-end 0))))
6793 (defun idlwave-in-structure ()
6794 "Return t if point is inside an IDL structure definition."
6795 (let ((beg (point)))
6797 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6798 (if (idlwave-find-structure-definition nil nil 'back)
6799 (let ((borders (idlwave-struct-borders)))
6800 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6801 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6803 (defun idlwave-struct-borders ()
6804 "Return the borders of the {...} after point as a cons cell."
6807 (skip-chars-forward "^{")
6809 (condition-case nil (forward-list 1)
6810 (error (goto-char beg)))
6811 (cons beg (point)))))
6813 (defun idlwave-find-structure-definition (&optional var name bound)
6814 "Search forward for a structure definition. If VAR is non-nil,
6815 search for a structure assigned to variable VAR. If NAME is non-nil,
6816 search for a named structure NAME, if a string, or a generic named
6817 structure otherwise. If BOUND is an integer, limit the search. If
6818 BOUND is the symbol `all', we search first back and then forward
6819 through the entire file. If BOUND is the symbol `back' we search only
6821 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6822 (case-fold-search t)
6823 (lim (if (integerp bound) bound nil))
6826 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6831 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
6832 ;; Just a generic name
6833 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
6835 (if (or (and (or (eq bound 'all) (eq bound 'back))
6836 (re-search-backward re nil t))
6837 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6839 (goto-char (match-beginning 3))
6840 (match-string-no-properties 5)))))
6842 (defvar idlwave-class-info nil)
6843 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
6844 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
6846 (add-hook 'idlwave-update-rinfo-hook
6847 (lambda () (setq idlwave-class-reset t)))
6848 (add-hook 'idlwave-after-load-rinfo-hook
6849 (lambda () (setq idlwave-class-info nil)))
6851 (defun idlwave-class-info (class)
6853 (if idlwave-class-info
6854 (if idlwave-class-reset
6856 idlwave-class-reset nil
6857 idlwave-class-info ; Remove any visited in a buffer
6861 (idlwave-class-file-or-buffer
6862 (or (cdr (assq 'found-in x)) (car x)))))
6866 idlwave-class-info))))
6867 ;; Info is nil, put in the system stuff to start.
6868 (setq idlwave-class-info idlwave-system-class-info)
6869 (setq list idlwave-class-info)
6870 (while (setq entry (pop list))
6871 (idlwave-sintern-class-info entry)))
6872 (setq class (idlwave-sintern-class class))
6873 (or (assq class idlwave-class-info)
6874 (progn (idlwave-scan-class-info class)
6875 (assq class idlwave-class-info)))))
6877 (defun idlwave-sintern-class-info (entry)
6878 "Sintern the class names in a class-info entry."
6879 (let ((taglist (assq 'tags entry))
6880 (inherits (assq 'inherits entry)))
6881 (setcar entry (idlwave-sintern-class (car entry) 'set))
6883 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6886 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
6887 "Find class structure definition(s)
6888 If ALL-HOOK is set, find all named structure definitions in a given
6889 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
6890 set, look for the name__define pro, and inside of it, for the ALT-CLASS
6891 class/struct definition"
6892 (let ((case-fold-search t) end-lim list name)
6893 (when (re-search-forward
6894 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6897 ;; For everything there
6898 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
6900 (idlwave-find-structure-definition nil t end-lim))
6901 (funcall all-hook name)))
6902 (idlwave-find-structure-definition nil (or alt-class class))))))
6905 (defun idlwave-class-file-or-buffer (class)
6906 "Find buffer visiting CLASS definition"
6907 (let* ((pro (concat (downcase class) "__define"))
6908 (file (idlwave-routine-source-file
6909 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6910 (idlwave-routines))))))
6911 (cons file (if file (idlwave-get-buffer-visiting file)))))
6914 (defun idlwave-scan-class-info (class)
6915 "Scan all class and named structure info in the class__define pro"
6916 (let* ((idlwave-auto-routine-info-updates nil)
6917 (filebuf (idlwave-class-file-or-buffer class))
6918 (file (car filebuf))
6920 (class (idlwave-sintern-class class)))
6923 (and ;; neither a regular file nor a visited buffer
6925 (not (file-regular-p file))))
6926 nil ; Cannot find the file/buffer to get any info
6928 (if buf (set-buffer buf)
6929 ;; Read the file in temporarily
6930 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6932 (unless (eq major-mode 'idlwave-mode)
6934 (insert-file-contents file))
6937 (idlwave-find-class-definition class
6938 ;; Scan all of the structures found there
6940 (let* ((this-class (idlwave-sintern-class name))
6943 (cons 'tags (idlwave-struct-tags))
6944 (cons 'inherits (idlwave-struct-inherits)))))
6945 (if (not (eq this-class class))
6946 (setq entry (nconc entry (list (cons 'found-in class)))))
6947 (idlwave-sintern-class-info entry)
6948 (push entry idlwave-class-info)))))))))
6950 (defun idlwave-class-found-in (class)
6951 "Return the FOUND-IN property of the class."
6952 (cdr (assq 'found-in (idlwave-class-info class))))
6953 (defun idlwave-class-tags (class)
6954 "Return the native tags in CLASS."
6955 (cdr (assq 'tags (idlwave-class-info class))))
6956 (defun idlwave-class-inherits (class)
6957 "Return the direct superclasses of CLASS."
6958 (cdr (assq 'inherits (idlwave-class-info class))))
6961 (defun idlwave-all-class-tags (class)
6962 "Return a list of native and inherited tags in CLASS."
6964 (apply 'append (mapcar 'idlwave-class-tags
6965 (cons class (idlwave-all-class-inherits class))))
6967 (idlwave-class-tag-reset)
6968 (error "%s" (error-message-string err)))))
6971 (defun idlwave-all-class-inherits (class)
6972 "Return a list of all superclasses of CLASS (recursively expanded).
6973 The list is cached in `idlwave-class-info' for faster access."
6975 ((not idlwave-support-inheritance) nil)
6976 ((eq class nil) nil)
6979 (let ((info (idlwave-class-info class))
6981 (if (setq entry (assq 'all-inherits info))
6983 ;; Save the depth of inheritance scan to check for circular references
6984 (let ((inherits (mapcar (lambda (x) (cons x 0))
6985 (idlwave-class-inherits class)))
6986 rtn all-inherits cl)
6988 (setq cl (pop inherits)
6989 rtn (cons (car cl) rtn)
6990 inherits (append (mapcar (lambda (x)
6991 (cons x (1+ (cdr cl))))
6992 (idlwave-class-inherits (car cl)))
6994 (if (> (cdr cl) 999)
6996 "Class scan: inheritance depth exceeded. Circular inheritance?")
6998 (setq all-inherits (nreverse rtn))
6999 (nconc info (list (cons 'all-inherits all-inherits)))
7002 (defun idlwave-entry-keywords (entry &optional record-link)
7003 "Return the flat entry keywords alist from routine-info entry.
7004 If RECORD-LINK is non-nil, the keyword text is copied and a text
7005 property indicating the link is added."
7009 (let ((file (car key-list)))
7010 (mapcar (lambda (key-cons)
7011 (let ((key (car key-cons))
7012 (link (cdr key-cons)))
7013 (when (and record-link file)
7014 (setq key (copy-sequence key))
7021 (concat idlwave-html-link-sep
7022 (number-to-string link))))
7024 (push (list key) kwds)))
7029 (defun idlwave-entry-find-keyword (entry keyword)
7030 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7034 (let ((file (car key-list))
7035 (kwd (assoc keyword (cdr key-list))))
7037 (setq kwd (cons (car kwd)
7038 (if (and file (cdr kwd))
7040 idlwave-html-link-sep
7041 (number-to-string (cdr kwd)))
7043 (throw 'exit kwd))))
7046 ;;==========================================================================
7048 ;; Completing class structure tags. This is a completion plugin.
7049 ;; The necessary taglist is constructed dynamically
7051 (defvar idlwave-current-tags-class nil)
7052 (defvar idlwave-current-class-tags nil)
7053 (defvar idlwave-current-native-class-tags nil)
7054 (defvar idlwave-sint-class-tags nil)
7055 (idlwave-new-sintern-type 'class-tag)
7056 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7057 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7059 (defun idlwave-complete-class-structure-tag ()
7060 "Complete a structure tag on a `self' argument in an object method."
7063 (case-fold-search t))
7065 ;; Check if the context is right
7066 (skip-chars-backward "a-zA-Z0-9._$")
7067 (and (< (point) (- pos 4))
7068 (looking-at "self\\.")))
7069 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7070 (super-classes (idlwave-all-class-inherits class-selector)))
7071 ;; Check if we are in a class routine
7072 (unless class-selector
7073 (error "Not in a method procedure or function"))
7074 ;; Check if we need to update the "current" class
7075 (if (not (equal class-selector idlwave-current-tags-class))
7076 (idlwave-prepare-class-tag-completion class-selector))
7077 (setq idlwave-completion-help-info
7078 (list 'idlwave-complete-class-structure-tag-help
7079 (idlwave-sintern-routine
7080 (concat class-selector "__define"))
7082 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7083 (idlwave-complete-in-buffer
7084 'class-tag 'class-tag
7085 idlwave-current-class-tags nil
7086 (format "Select a tag of class %s" class-selector)
7088 'idlwave-attach-class-tag-classes))
7089 t) ; return t to skip other completions
7092 (defun idlwave-class-tag-reset ()
7093 (setq idlwave-current-tags-class nil))
7095 (defun idlwave-prepare-class-tag-completion (class)
7096 "Find and parse the necessary class definitions for class structure tags."
7097 (setq idlwave-sint-class-tags nil)
7098 (setq idlwave-current-tags-class class)
7099 (setq idlwave-current-class-tags
7101 (list (idlwave-sintern-class-tag x 'set)))
7102 (idlwave-all-class-tags class)))
7103 (setq idlwave-current-native-class-tags
7104 (mapcar 'downcase (idlwave-class-tags class))))
7106 ;===========================================================================
7108 ;; Completing system variables and their structure fields
7109 ;; This is also a plugin.
7111 (defvar idlwave-sint-sysvars nil)
7112 (defvar idlwave-sint-sysvartags nil)
7113 (idlwave-new-sintern-type 'sysvar)
7114 (idlwave-new-sintern-type 'sysvartag)
7115 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7116 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7117 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7119 (defvar idlwave-executive-commands-alist nil
7120 "Alist of system variables and their help files.")
7122 (defvar idlwave-system-variables-alist nil
7123 "Alist of system variables and the associated structure tags.
7124 Gets set in `idlw-rinfo.el'.")
7126 (defun idlwave-complete-sysvar-or-tag ()
7127 "Complete a system variable."
7130 (case-fold-search t))
7131 (cond ((save-excursion
7132 ;; Check if the context is right for system variable
7133 (skip-chars-backward "[a-zA-Z0-9_$]")
7134 (equal (char-before) ?!))
7135 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7136 (idlwave-complete-in-buffer 'sysvar 'sysvar
7137 idlwave-system-variables-alist nil
7138 "Select a system variable"
7140 t) ; return t to skip other completions
7142 ;; Check if the context is right for sysvar tag
7143 (skip-chars-backward "a-zA-Z0-9_$.")
7144 (and (equal (char-before) ?!)
7145 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7146 (<= (match-end 0) pos)))
7147 ;; Complete a system variable tag
7148 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7149 (entry (assq var idlwave-system-variables-alist))
7150 (tags (cdr (assq 'tags entry))))
7151 (or entry (error "!%s is not a known system variable" var))
7152 (or tags (error "System variable !%s is not a structure" var))
7153 (setq idlwave-completion-help-info
7154 (list 'idlwave-complete-sysvar-tag-help var))
7155 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7157 "Select a system variable tag"
7158 "system variable tag")
7159 t)) ; return t to skip other completions
7162 (defun idlwave-complete-sysvar-help (mode word)
7163 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7164 (entry (assoc word idlwave-system-variables-alist)))
7167 (and (stringp word) entry (nth 1 (assq 'link entry))))
7169 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7170 (t (error "This should not happen")))))
7172 (defun idlwave-complete-sysvar-tag-help (mode word)
7173 (let* ((var (nth 1 idlwave-completion-help-info))
7174 (entry (assoc var idlwave-system-variables-alist))
7175 (tags (cdr (assq 'tags entry)))
7176 (main (nth 1 (assq 'link entry)))
7179 ((eq mode 'test) ; we can at least link the main
7180 (and (stringp word) entry main))
7184 (if (setq target (cdr (assoc word tags)))
7185 (idlwave-substitute-link-target main target)
7186 main)))) ;; setting dynamic!!!
7187 (t (error "This should not happen")))))
7189 (defun idlwave-substitute-link-target (link target)
7190 "Substitute the target anchor for the given link."
7192 (setq main-base (if (string-match "#" link)
7193 (substring link 0 (match-beginning 0))
7196 (concat main-base idlwave-html-link-sep (number-to-string target))
7199 ;; Fake help in the source buffer for class structure tags.
7200 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7203 (defvar idlwave-help-do-class-struct-tag nil)
7204 (defun idlwave-complete-class-structure-tag-help (mode word)
7206 ((eq mode 'test) ; nothing gets fontified for class tags
7209 (let (class-with found-in)
7210 (when (setq class-with
7211 (idlwave-class-or-superclass-with-tag
7212 idlwave-current-tags-class
7214 (if (assq (idlwave-sintern-class class-with)
7215 idlwave-system-class-info)
7216 (error "No help available for system class tags."))
7217 (if (setq found-in (idlwave-class-found-in class-with))
7218 (setq name (cons (concat found-in "__define") class-with))
7219 (setq name (concat class-with "__define")))))
7221 idlwave-help-do-class-struct-tag t))
7222 (t (error "This should not happen"))))
7224 (defun idlwave-class-or-superclass-with-tag (class tag)
7225 "Find and return the CLASS or one of its superclass with the
7226 associated TAG, if any."
7227 (let ((sclasses (cons class (cdr (assq 'all-inherits
7228 (idlwave-class-info class)))))
7232 (setq cl (pop sclasses))
7233 (let ((tags (idlwave-class-tags cl)))
7235 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7237 (setq tags (cdr tags))))))))
7240 (defun idlwave-sysvars-reset ()
7241 (if (and (fboundp 'idlwave-shell-is-running)
7242 (idlwave-shell-is-running)
7243 idlwave-idlwave_routine_info-compiled)
7244 (idlwave-shell-send-command "idlwave_get_sysvars"
7245 'idlwave-process-sysvars 'hide)))
7247 (defun idlwave-process-sysvars ()
7248 (idlwave-shell-filter-sysvars)
7249 (setq idlwave-sint-sysvars nil
7250 idlwave-sint-sysvartags nil)
7251 (idlwave-sintern-sysvar-alist))
7253 (defun idlwave-sintern-sysvar-alist ()
7254 (let ((list idlwave-system-variables-alist) entry tags)
7255 (while (setq entry (pop list))
7256 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7257 (setq tags (assq 'tags entry))
7261 (cons (idlwave-sintern-sysvartag (car x) 'set)
7265 (defvar idlwave-shell-command-output)
7266 (defun idlwave-shell-filter-sysvars ()
7267 "Get any new system variables and tags."
7268 (let ((text idlwave-shell-command-output)
7270 (old idlwave-system-variables-alist)
7271 var tags type name class link old-entry)
7272 (setq idlwave-system-variables-alist nil)
7273 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7275 (setq start (match-end 0)
7276 var (match-string 1 text)
7277 tags (if (match-end 3)
7278 (idlwave-split-string (match-string 3 text))))
7279 ;; Maintain old links, if present
7280 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7281 (setq link (assq 'link old-entry))
7282 (setq idlwave-system-variables-alist
7289 (idlwave-sintern-sysvartag x)
7290 (cdr (assq 'tags old-entry))))))
7292 idlwave-system-variables-alist)))
7293 ;; Keep the old value if query was not successful
7294 (setq idlwave-system-variables-alist
7295 (or idlwave-system-variables-alist old))))
7297 (defun idlwave-completion-fontify-classes ()
7298 "Goto the *Completions* buffer and fontify the class info."
7299 (when (featurep 'font-lock)
7301 (set-buffer "*Completions*")
7303 (goto-char (point-min))
7304 (let ((buffer-read-only nil))
7305 (while (re-search-forward "\\.*<[^>]+>" nil t)
7306 (put-text-property (match-beginning 0) (match-end 0)
7307 'face 'font-lock-string-face)))))))
7309 (defun idlwave-uniquify (list)
7310 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7313 (unless (gethash x ht)
7318 (defun idlwave-after-successful-completion (type slash &optional verify)
7319 "Add `=' or `(' after successful completion of keyword and function.
7320 Restore the pre-completion window configuration if possible."
7322 ((eq type 'procedure)
7324 ((eq type 'function)
7326 ((equal idlwave-function-completion-adds-paren nil) nil)
7327 ((or (equal idlwave-function-completion-adds-paren t)
7328 (equal idlwave-function-completion-adds-paren 1))
7330 ((equal idlwave-function-completion-adds-paren 2)
7335 (if (and idlwave-keyword-completion-adds-equal
7337 (progn (insert "=") t)
7340 ;; Restore the pre-completion window configuration if this is safe.
7342 (if (or (eq verify 'force) ; force
7344 (get-buffer-window "*Completions*") ; visible
7345 (idlwave-local-value 'idlwave-completion-p
7346 "*Completions*") ; cib-buffer
7347 (eq (marker-buffer idlwave-completion-mark)
7348 (current-buffer)) ; buffer OK
7349 (equal (marker-position idlwave-completion-mark)
7351 (idlwave-restore-wconf-after-completion))
7352 (move-marker idlwave-completion-mark nil)
7353 (setq idlwave-before-completion-wconf nil))
7355 (defun idlwave-mouse-context-help (ev &optional arg)
7356 "Call `idlwave-context-help' on the clicked location."
7358 (mouse-set-point ev)
7359 (idlwave-context-help arg))
7361 (defvar idlwave-last-context-help-pos nil)
7362 (defun idlwave-context-help (&optional arg)
7363 "Display IDL Online Help on context.
7364 If point is on a keyword, help for that keyword will be shown. If
7365 point is on a routine name or in the argument list of a routine, help
7366 for that routine will be displayed. Works for system routines and
7367 keywords, it pulls up text help. For other routies and keywords,
7368 visits the source file, finding help in the header (if
7369 `idlwave-help-source-try-header' is non-nil) or the routine definition
7372 (idlwave-do-context-help arg))
7374 (defun idlwave-mouse-completion-help (ev)
7375 "Display online help about the completion at point."
7377 ;; Restore last-command for next command, to make
7378 ;; scrolling/cancelling of completions work.
7379 (setq this-command last-command)
7380 (idlwave-do-mouse-completion-help ev))
7382 (defun idlwave-routine-info (&optional arg external)
7383 "Display a routines calling sequence and list of keywords. When
7384 point is on the name a function or procedure, or in the argument list
7385 of a function or procedure, this command displays a help buffer with
7386 the information. When called with prefix arg, enforce class query.
7388 When point is on an object operator `->', display the class stored in
7389 this arrow, if any (see `idlwave-store-inquired-class'). With a
7390 prefix arg, the class property is cleared out."
7394 (if (string-match "->" (buffer-substring
7395 (max (point-min) (1- (point)))
7396 (min (+ 2 (point)) (point-max))))
7397 ;; Cursor is on an arrow
7398 (if (get-text-property (point) 'idlwave-class)
7399 ;; arrow has class property
7404 (when (looking-at ".?\\(->\\)")
7405 (remove-text-properties (match-beginning 1) (match-end 1)
7406 '(idlwave-class nil face nil))
7407 (message "Class property removed from arrow")))
7408 ;; Echo class property
7409 (message "Arrow has text property identifying object to be class %s"
7410 (get-text-property (point) 'idlwave-class)))
7411 ;; No property found
7412 (message "Arrow has no class text property"))
7414 ;; Not on an arrow...
7415 (let* ((idlwave-query-class nil)
7416 (idlwave-force-class-query (equal arg '(4)))
7417 (module (idlwave-what-module)))
7419 (apply 'idlwave-display-calling-sequence
7420 (idlwave-fix-module-if-obj_new module))
7421 (error "Don't know which calling sequence to show")))))
7423 (defun idlwave-resolve (&optional arg)
7424 "Call RESOLVE_ROUTINE on the module name at point.
7425 Like `idlwave-routine-info', this looks for a routine call at point.
7426 After confirmation in the minibuffer, it will use the shell to issue
7427 a RESOLVE call for this routine, to attempt to make it defined and its
7428 routine info available for IDLWAVE. If the routine is a method call,
7429 both `class__method' and `class__define' will be tried.
7430 With ARG, enforce query for the class of object methods."
7432 (let* ((idlwave-query-class nil)
7433 (idlwave-force-class-query (equal arg '(4)))
7434 (module (idlwave-what-module))
7435 (name (idlwave-make-full-name (nth 2 module) (car module)))
7436 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7437 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7440 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7442 (setq type (match-string 1 resolve)
7443 class (if (match-beginning 2)
7444 (match-string 3 resolve)
7446 name (match-string 4 resolve)))
7447 (if (string= (downcase type) "function")
7448 (setq kwd ",/is_function"))
7452 (idlwave-shell-send-command
7453 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7454 'idlwave-update-routine-info
7457 (idlwave-shell-send-command
7458 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7459 (list 'idlwave-shell-send-command
7460 (format "resolve_routine,'%s__%s'%s"
7461 (downcase class) (downcase name) kwd)
7462 '(idlwave-update-routine-info)
7465 (defun idlwave-find-module (&optional arg)
7466 "Find the source code of an IDL module.
7467 Works for modules for which IDLWAVE has routine info available. The
7468 function offers as default the module name `idlwave-routine-info'
7469 would use. With ARG limit to this buffer. With two prefix ARG's
7470 force class query for object methods."
7472 (let* ((idlwave-query-class nil)
7473 (idlwave-force-class-query (equal arg '(16)))
7474 (this-buffer (equal arg '(4)))
7475 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7477 (concat (idlwave-make-full-name
7478 (nth 2 module) (car module))
7479 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7485 (if (eq 'system (car-safe (nth 3 x)))
7486 ;; Take out system routines with no source.
7489 (concat (idlwave-make-full-name
7491 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7493 (idlwave-save-buffer-update)
7494 (idlwave-routines))))))
7495 (name (idlwave-completing-read
7496 (if (or (not this-buffer)
7497 (assoc default list))
7498 (format "Module (Default %s): " default)
7499 (format "Module in this file: "))
7502 (if (string-match "\\`\\s-*\\'" name)
7503 ;; Nothing, use the default.
7504 (setq name default))
7505 (if (string-match "<[fp]>" name)
7506 (setq type (substring name -2 -1)
7507 name (substring name 0 -3)))
7508 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7509 (setq class (match-string 1 name)
7510 name (match-string 2 name)))
7511 (setq name (idlwave-sintern-routine-or-method name class)
7512 class (idlwave-sintern-class class)
7513 type (cond ((equal type "f") 'fun)
7514 ((equal type "p") 'pro)
7516 (idlwave-do-find-module name type class nil this-buffer)))
7518 (defun idlwave-do-find-module (name type class
7519 &optional force-source this-buffer)
7520 (let ((name1 (idlwave-make-full-name class name))
7522 (buf (current-buffer))
7525 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7527 source (or force-source (nth 3 entry))
7528 name2 (if (nth 2 entry)
7529 (idlwave-make-full-name (nth 2 entry) name)
7532 (setq file (idlwave-routine-source-file source)))
7533 (unless file ; Try to find it on the path.
7535 (idlwave-expand-lib-file-name
7537 (format "%s__define.pro" (downcase class))
7538 (format "%s.pro" (downcase name))))))
7540 ((or (null name) (equal name ""))
7542 ((eq (car source) 'system)
7543 (error "Source code for system routine %s is not available"
7545 ((or (not file) (not (file-regular-p file)))
7546 (error "Source code for routine %s is not available"
7549 (when (not this-buffer)
7551 (idlwave-find-file-noselect file 'find))
7552 (pop-to-buffer buf1 t))
7553 (goto-char (point-max))
7554 (let ((case-fold-search t))
7555 (if (re-search-backward
7556 (concat "^[ \t]*\\<"
7557 (cond ((eq type 'fun) "function")
7558 ((eq type 'pro) "pro")
7559 (t "\\(pro\\|function\\)"))
7561 (regexp-quote (downcase name2))
7564 (goto-char (match-beginning 0))
7567 (error "Could not find routine %s" name2)))))))
7569 (defun idlwave-what-module ()
7570 "Return a default module for stuff near point.
7571 Used by `idlwave-routine-info' and `idlwave-find-module'."
7573 (if (let ((case-fold-search t))
7575 (idlwave-beginning-of-statement)
7576 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7577 ;; This is a function or procedure definition statement
7578 ;; We return the defined routine as module.
7580 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
7581 (match-string-no-properties 2))
7582 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7583 (idlwave-sintern-class (match-string 3)))
7585 ;; Not a definition statement - analyze precise position.
7586 (let* ((where (idlwave-where))
7588 (pro (car (nth 0 where)))
7589 (func (car (nth 1 where)))
7590 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7591 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7595 ((and (eq cw 'procedure)
7596 (not (equal this-word "")))
7597 (setq this-word (idlwave-sintern-routine-or-method
7598 this-word (nth 2 (nth 3 where))))
7599 (list this-word 'pro
7600 (idlwave-determine-class
7601 (cons this-word (cdr (nth 3 where)))
7603 ((and (eq cw 'function)
7604 (not (equal this-word ""))
7605 (or (eq next-char ?\() ; exclude arrays, vars.
7606 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7607 (setq this-word (idlwave-sintern-routine-or-method
7608 this-word (nth 2 (nth 3 where))))
7609 (list this-word 'fun
7610 (idlwave-determine-class
7611 (cons this-word (cdr (nth 3 where)))
7613 ((and (memq cw '(function-keyword procedure-keyword))
7614 (not (equal this-word ""))
7615 (eq next-char ?\()) ; A function!
7616 (setq this-word (idlwave-sintern-routine this-word))
7617 (list this-word 'fun nil))
7619 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7621 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7624 (defun idlwave-what-module-find-class ()
7625 "Call idlwave-what-module and find the inherited class if necessary."
7626 (let* ((module (idlwave-what-module))
7627 (class (nth 2 module))
7629 (if (and (= (length module) 3)
7633 (apply 'idlwave-find-inherited-class module))
7636 (defun idlwave-find-inherited-class (name type class)
7637 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7638 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7643 (defun idlwave-fix-module-if-obj_new (module)
7644 "Check if MODULE points to obj_new.
7645 If yes, and if the cursor is in the keyword region, change to the
7646 appropriate Init method."
7647 (let* ((name (car module))
7649 (case-fold-search t)
7651 (if (and (stringp name)
7652 (equal (downcase name) "obj_new")
7654 (idlwave-beginning-of-statement)
7655 (setq string (buffer-substring (point) pos))
7656 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7659 (class (match-string 1 string)))
7660 (setq module (list (idlwave-sintern-method "Init")
7662 (idlwave-sintern-class class)))))
7665 (defun idlwave-fix-keywords (name type class keywords &optional super-classes)
7666 "Update a list of keywords.
7667 Translate OBJ_NEW, adding all super-class keywords, or all keywords
7668 from all classes if class equals t."
7669 (let ((case-fold-search t))
7671 ;; If this is the OBJ_NEW function, try to figure out the class and use
7672 ;; the keywords from the corresponding INIT method.
7673 (if (and (equal (upcase name) "OBJ_NEW")
7674 (or (eq major-mode 'idlwave-mode)
7675 (eq major-mode 'idlwave-shell-mode)))
7676 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7677 (string (buffer-substring bos (point)))
7678 (case-fold-search t)
7680 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7682 (setq class (idlwave-sintern-class (match-string 1 string)))
7683 (setq idlwave-current-obj_new-class class)
7686 (idlwave-entry-keywords
7688 (idlwave-sintern-method "INIT")
7691 (idlwave-routines)) 'do-link))))))
7693 ;; If the class is `t', combine all keywords of all methods NAME
7695 (mapc (lambda (entry)
7697 (nth 2 entry) ; non-nil class
7698 (eq (nth 1 entry) type) ; correct type
7701 (idlwave-entry-keywords entry 'do-link)))))
7702 (idlwave-all-assq name (idlwave-routines)))
7703 (setq keywords (idlwave-uniquify keywords)))
7705 ;; If we have inheritance, add all keywords from superclasses, if
7706 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
7709 idlwave-keyword-class-inheritance
7711 (or (assq (idlwave-sintern-keyword "_extra") keywords)
7712 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7713 ;; Check if one of the keyword-class regexps matches the name
7714 (let ((regexps idlwave-keyword-class-inheritance) re)
7716 (while (setq re (pop regexps))
7717 (if (string-match re name) (throw 'exit t))))))
7719 (loop for entry in (idlwave-routines) do
7720 (and (nth 2 entry) ; non-nil class
7721 (memq (nth 2 entry) super-classes) ; an inherited class
7722 (eq (nth 1 entry) type) ; correct type
7723 (eq (car entry) name) ; correct name
7724 (mapcar (lambda (k) (add-to-list 'keywords k))
7725 (idlwave-entry-keywords entry 'do-link))))
7726 (setq keywords (idlwave-uniquify keywords)))
7728 ;; Return the final list
7731 (defun idlwave-expand-keyword (keyword module)
7732 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
7733 KEYWORD may be an exact match or an abbreviation of a keyword.
7734 If the match is exact, KEYWORD itself is returned, even if there may be other
7735 keywords of which KEYWORD is an abbreviation. This is necessary because some
7736 system routines have keywords which are prefixes of other keywords.
7737 If KEYWORD is an abbreviation of several keywords, a list of all possible
7738 completions is returned.
7739 If the abbreviation was unique, the correct keyword is returned.
7740 If it cannot be a keyword, the function return nil.
7741 If we do not know about MODULE, just return KEYWORD literally."
7742 (let* ((name (car module))
7743 (type (nth 1 module))
7744 (class (nth 2 module))
7745 (kwd (idlwave-sintern-keyword keyword))
7746 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7747 (kwd-alist (idlwave-entry-keywords entry))
7748 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7749 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7750 (completion-ignore-case t)
7752 (cond ((assq kwd kwd-alist)
7754 ((setq candidates (all-completions kwd kwd-alist))
7755 (if (= (length candidates) 1)
7759 ;; Inheritance may cause this keyword to be correct
7762 ;; We do know the function, which does not have the keyword.
7765 ;; We do not know the function, so this just might be a correct
7766 ;; keyword - return it as it is.
7769 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7770 (defvar idlwave-rinfo-map (make-sparse-keymap))
7771 (define-key idlwave-rinfo-mouse-map
7772 (if (featurep 'xemacs) [button2] [mouse-2])
7773 'idlwave-mouse-active-rinfo)
7774 (define-key idlwave-rinfo-mouse-map
7775 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7776 'idlwave-mouse-active-rinfo-shift)
7777 (define-key idlwave-rinfo-mouse-map
7778 (if (featurep 'xemacs) [button3] [mouse-3])
7779 'idlwave-mouse-active-rinfo-right)
7780 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7781 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7782 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7783 (defvar idlwave-popup-source nil)
7784 (defvar idlwave-rinfo-marker (make-marker))
7786 (defun idlwave-quit-help ()
7788 (let ((ri-window (get-buffer-window "*Help*"))
7789 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7790 (when (and olh-window
7791 (fboundp 'idlwave-help-quit))
7792 (select-window olh-window)
7793 (idlwave-help-quit))
7794 (when (window-live-p ri-window)
7795 (delete-window ri-window))))
7797 (defun idlwave-display-calling-sequence (name type class
7798 &optional initial-class)
7799 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7800 (let* ((initial-class (or initial-class class))
7801 (entry (or (idlwave-best-rinfo-assq name type class
7803 (idlwave-rinfo-assq name type class
7804 idlwave-unresolved-routines)))
7805 (name (or (car entry) name))
7806 (class (or (nth 2 entry) class))
7807 (superclasses (idlwave-all-class-inherits initial-class))
7808 (twins (idlwave-routine-twins entry))
7809 (dtwins (idlwave-study-twins twins))
7811 (system (eq (car (nth 3 entry)) 'system))
7812 (calling-seq (nth 4 entry))
7813 (keywords (idlwave-entry-keywords entry 'do-link))
7814 (html-file (car (nth 5 entry)))
7816 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
7818 "Button2/3: Online Help")
7820 "Button2: Jump to source and back | Button3: Source in Help window.")
7822 "Button2: Display info about same method in superclass")
7824 (data (list name type class (current-buffer) nil initial-class))
7825 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7826 (face 'idlwave-help-link-face)
7827 beg props win cnt total)
7828 ;; Fix keywords, but don't add chained super-classes, since these
7829 ;; are shown separately for that super-class
7830 (setq keywords (idlwave-fix-keywords name type class keywords))
7833 (error "No %s %s known %s" type name
7834 (if initial-class (concat "in class " initial-class) "")))
7835 ((or (null name) (equal name ""))
7836 (error "No function or procedure call at point"))
7838 (error "Calling sequence of %s %s not available" type name))
7841 (move-marker idlwave-rinfo-marker (point))
7842 (set-buffer (get-buffer-create "*Help*"))
7843 (use-local-map idlwave-rinfo-map)
7844 (setq buffer-read-only nil)
7846 (set (make-local-variable 'idlwave-popup-source) nil)
7847 (set (make-local-variable 'idlwave-current-obj_new-class)
7848 idlwave-current-obj_new-class)
7850 (setq props (list 'mouse-face 'highlight
7851 km-prop idlwave-rinfo-mouse-map
7852 'help-echo help-echo-class
7853 'data (cons 'class data)))
7854 (let ((classes (cons initial-class superclasses)) c)
7855 (insert "Classes: ")
7856 (while (setq c (pop classes))
7860 (if (equal (downcase c) (downcase class))
7861 (add-text-properties beg (point) (list 'face 'bold))
7862 ;; If Method exists in a different class link it
7863 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7864 (add-text-properties beg (point) props))))
7866 (setq props (list 'mouse-face 'highlight
7867 km-prop idlwave-rinfo-mouse-map
7868 'help-echo help-echo-use
7869 'data (cons 'usage data)))
7870 (if html-file (setq props (append (list 'face face 'link html-file)
7875 (format calling-seq class name class name class name)
7876 (format calling-seq name name name name))
7878 (add-text-properties beg (point) props)
7880 (insert "Keywords:")
7882 (insert " No keywords accepted.")
7886 (if (>= (+ col 1 (length (car x)))
7893 ;; Relevant keywords already have link property attached
7894 props (list 'mouse-face 'highlight
7895 km-prop idlwave-rinfo-mouse-map
7896 'data (cons 'keyword data)
7897 'help-echo help-echo-kwd
7899 (if system (setq props (append (list 'face face) props)))
7901 (add-text-properties beg (point) props)
7902 (setq col (+ col 1 (length (car x)))))
7905 (setq cnt 1 total (length all))
7906 ;; Here entry is (key file (list of type-conses))
7907 (while (setq entry (pop all))
7908 (setq props (list 'mouse-face 'highlight
7909 km-prop idlwave-rinfo-mouse-map
7910 'help-echo help-echo-src
7911 'source (list (car (car (nth 2 entry))) ;type
7914 (cdr (car (nth 2 entry))))
7915 'data (cons 'source data)))
7916 (idlwave-insert-source-location
7919 (if (> total 1) "Sources:" "Source:")
7921 (if (> total 1) "- " ""))
7924 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7925 ;; No more source lines, please
7927 "\n Source information truncated to %d entries."
7928 idlwave-rinfo-max-source-lines))
7930 (goto-char (point-min))
7931 (setq buffer-read-only t))
7932 (display-buffer "*Help*")
7933 (if (and (setq win (get-buffer-window "*Help*"))
7934 idlwave-resize-routine-help-window)
7936 (let ((ww (selected-window)))
7940 (enlarge-window (- (/ (frame-height) 2)
7942 (shrink-window-if-larger-than-buffer))
7943 (select-window ww)))))))))
7945 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7946 "Insert a source location into the routine info buffer.
7947 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
7949 (let* ((key (car entry))
7950 (file (nth 1 entry))
7951 (types (nth 2 entry))
7952 (shell-flag (assq 'compiled types))
7953 (buffer-flag (assq 'buffer types))
7954 (user-flag (assq 'user types))
7955 (lib-flag (assq 'lib types))
7956 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
7957 (and user-flag (idlwave-count-memq 'user types))
7958 (and lib-flag (idlwave-count-memq 'lib types))
7972 (insert "Builtin "))
7974 ((and (not file) shell-flag)
7975 (insert "Unresolved"))
7980 ((idlwave-syslib-p file)
7981 (if (string-match "obsolete" (file-name-directory file))
7982 (insert "Obsolete ")
7983 (insert "SystemLib ")))
7985 ;; New special syntax: taken directly from routine-info for
7986 ;; library catalog routines
7987 ((setq special (or (cdr lib-flag) (cdr user-flag)))
7988 (insert (format "%-10s" special)))
7990 ;; Old special syntax: a matching regexp
7991 ((setq special (idlwave-special-lib-test file))
7992 (insert (format "%-10s" special)))
7994 ;; Catch-all with file
7995 ((idlwave-lib-p file) (insert "Library "))
7998 (t (insert "Other ")))
8003 (if lib-flag "L" "-")
8004 (if user-flag "C" "-")
8005 (if shell-flag "S" "-")
8006 (if buffer-flag "B" "-")
8010 (insert (format "(%dx) " ndupl))
8011 (add-text-properties beg (point) (list 'face 'bold)))
8012 (when (and file (not (equal file "")))
8014 (insert (apply 'abbreviate-file-name
8015 (if (featurep 'xemacs) (list file t) (list file))))
8017 (add-text-properties beg (point) file-props)))))
8019 (defun idlwave-special-lib-test (file)
8020 "Check the path of FILE against the regexps which define special libs.
8021 Return the name of the special lib if there is a match."
8022 (let ((alist idlwave-special-lib-alist)
8026 (while (setq entry (pop alist))
8027 (if (string-match (car entry) file)
8028 (setq rtn (cdr entry)
8033 (defun idlwave-mouse-active-rinfo-right (ev)
8035 (idlwave-mouse-active-rinfo ev 'right))
8037 (defun idlwave-mouse-active-rinfo-shift (ev)
8039 (idlwave-mouse-active-rinfo ev nil 'shift))
8041 (defun idlwave-active-rinfo-space ()
8043 (idlwave-mouse-active-rinfo nil 'right))
8045 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8046 "Does the mouse actions in the routine info buffer.
8047 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8050 (if ev (mouse-set-point ev))
8051 (let (data id name type class buf bufwin source word initial-class)
8052 (setq data (get-text-property (point) 'data)
8053 source (get-text-property (point) 'source)
8054 keyword (get-text-property (point) 'keyword)
8055 link (get-text-property (point) 'link)
8057 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8059 initial-class (nth 6 data)
8060 word (idlwave-this-word)
8061 bufwin (get-buffer-window buf t))
8063 (cond ((eq id 'class) ; Switch class being displayed
8064 (if (window-live-p bufwin) (select-window bufwin))
8065 (idlwave-display-calling-sequence
8066 (idlwave-sintern-method name)
8067 type (idlwave-sintern-class word)
8069 ((eq id 'usage) ; Online help on this routine
8070 (idlwave-online-help link name type class))
8071 ((eq id 'source) ; Source in help or buffer
8073 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8074 (idlwave-help-source-try-header nil)
8075 ;; Fake idlwave-routines so help will find the right entry
8077 (list (list name type class source ""))))
8078 (idlwave-help-get-special-help name type class nil))
8079 ;; Otherwise just pop to the source
8080 (setq idlwave-popup-source (not idlwave-popup-source))
8081 (if idlwave-popup-source
8083 (idlwave-do-find-module name type class source)
8085 (setq idlwave-popup-source nil)
8086 (if (window-live-p bufwin) (select-window bufwin))
8087 (error (nth 1 err))))
8089 (select-window bufwin)
8090 (pop-to-buffer buf))
8091 (goto-char (marker-position idlwave-rinfo-marker)))))
8094 (idlwave-online-help link name type class keyword)
8095 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8097 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8098 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8099 (let ((bwin (get-buffer-window buffer)))
8100 (if idlwave-complete-empty-string-as-lower-case
8101 (setq keyword (downcase keyword)))
8103 (select-window bwin)
8104 (pop-to-buffer buffer)
8105 (setq bwin (get-buffer-window buffer)))
8106 (if (eq (preceding-char) ?/)
8108 (unless (save-excursion
8110 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8111 (min (- (point) 100) (point-min)) t))
8113 (if shift (insert "/"))
8115 (if (and (not shift)
8116 idlwave-keyword-completion-adds-equal)
8119 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8120 "List the load path shadows of all routines defined in current buffer."
8123 (if (eq major-mode 'idlwave-mode)
8124 (idlwave-list-load-path-shadows
8125 nil (idlwave-update-current-buffer-info 'save-buffer)
8126 "in current buffer")
8127 (error "Current buffer is not in idlwave-mode")))
8129 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8130 "List the load path shadows of all routines compiled under the shell.
8131 This is very useful for checking an IDL application. Just compile the
8132 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8133 routines and update IDLWAVE internal info. Then check for shadowing
8137 ((or (not (fboundp 'idlwave-shell-is-running))
8138 (not (idlwave-shell-is-running)))
8139 (error "Shell is not running"))
8140 ((null idlwave-compiled-routines)
8141 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8143 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8146 (defun idlwave-list-all-load-path-shadows (&optional arg)
8147 "List the load path shadows of all routines known to IDLWAVE."
8149 (idlwave-list-load-path-shadows nil nil "globally"))
8151 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8152 "List the routines which are defined multiple times.
8153 Search the information IDLWAVE has about IDL routines for multiple
8155 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8157 When IDL hits a routine call which is not defined, it will search on
8158 the load path in order to find a definition. The output of this
8159 command can be used to detect possible name clashes during this process."
8160 (idlwave-routines) ; Make sure everything is loaded.
8161 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8163 "You don't have any user or library catalogs. Continue anyway? ")
8165 (let* ((routines (append idlwave-system-routines
8166 idlwave-compiled-routines
8167 idlwave-library-catalog-routines
8168 idlwave-user-catalog-routines
8169 idlwave-buffer-routines
8171 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8172 (keymap (make-sparse-keymap))
8173 (props (list 'mouse-face 'highlight
8175 'help-echo "Mouse2: Find source"))
8176 (nroutines (length (or special-routines routines)))
8177 (step (/ nroutines 99))
8181 (idlwave-sort-prefer-buffer-info nil)
8182 routine twins dtwins twin done props1 lroutines)
8184 (if special-routines
8185 ;; Just looking for shadows of a few special routines
8186 (setq lroutines routines
8187 routines special-routines))
8189 (message "Sorting routines...")
8190 (setq routines (sort routines
8192 (string< (downcase (idlwave-make-full-name
8194 (downcase (idlwave-make-full-name
8195 (nth 2 b) (car b)))))))
8196 (message "Sorting routines...done")
8198 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8201 (mouse-set-point ev)
8202 (apply 'idlwave-do-find-module
8203 (get-text-property (point) 'find-args))))
8204 (define-key keymap [(return)]
8207 (apply 'idlwave-do-find-module
8208 (get-text-property (point) 'find-args))))
8209 (message "Compiling list...( 0%%)")
8211 (set-buffer (get-buffer-create "*Shadows*"))
8212 (setq buffer-read-only nil)
8214 (while (setq routine (pop routines))
8216 (if (= (* next-perc step) n)
8218 (message "Compiling list...(%2d%%)" next-perc)
8219 (setq next-perc (1+ next-perc))))
8220 ;; Get a list of all twins
8221 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8222 (if (memq routine done)
8224 (setq dtwins (idlwave-study-twins twins)))
8225 ;; Mark all twins as dealt with
8226 (setq done (append twins done))
8227 (when (or (> (length dtwins) 1)
8228 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8229 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8230 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8232 (insert (format "\n%s%s"
8233 (idlwave-make-full-name (nth 2 routine)
8235 (if (eq (nth 1 routine) 'fun) "()" "")))
8236 (while (setq twin (pop dtwins))
8237 (setq props1 (append (list 'find-args
8238 (list (nth 0 routine)
8242 (idlwave-insert-source-location "\n - " twin props1))))
8243 (goto-char (point-min))
8244 (setq buffer-read-only t))
8245 (setq loc (or loc ""))
8248 (display-buffer (get-buffer "*Shadows*"))
8249 (message "%d case%s of shadowing found %s"
8250 cnt (if (= cnt 1) "" "s") loc))
8251 (message "No shadowing conflicts found %s" loc))))
8253 (defun idlwave-print-source (routine)
8254 (let* ((source (nth 3 routine))
8255 (stype (car source))
8256 (sfile (idlwave-routine-source-file source)))
8257 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8258 (if (and (eq stype 'compiled)
8259 (or (not (stringp sfile))
8260 (not (string-match "\\S-" sfile))))
8261 (setq stype 'unresolved))
8262 (princ (format " %-10s %s\n"
8264 (if sfile sfile "No source code available")))))
8266 (defun idlwave-routine-twins (entry &optional list)
8267 "Return all twin entries of ENTRY in LIST.
8268 LIST defaults to `idlwave-routines'.
8269 Twin entries are those which have the same name, type, and class.
8270 ENTRY will also be returned, as the first item of this list."
8271 (let* ((name (car entry))
8272 (type (nth 1 entry))
8273 (class (nth 2 entry))
8274 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8276 (while (setq candidate (pop candidates))
8277 (if (and (not (eq candidate entry))
8278 (eq type (nth 1 candidate))
8279 (eq class (nth 2 candidate)))
8280 (push candidate twins)))
8281 (if (setq candidate (idlwave-rinfo-assq name type class
8282 idlwave-unresolved-routines))
8283 (push candidate twins))
8284 (cons entry (nreverse twins))))
8286 (defun idlwave-study-twins (entries)
8287 "Return dangerous twins of first entry in ENTRIES.
8288 Dangerous twins are routines with same name, but in different files on
8289 the load path. If a file is in the system library and has an entry in
8290 the `idlwave-system-routines' list, we omit the latter as
8291 non-dangerous because many IDL routines are implemented as library
8292 routines, and may have been scanned."
8293 (let* ((entry (car entries))
8294 (name (car entry)) ;
8295 (type (nth 1 entry)) ; Must be bound for
8296 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8298 source type type-cons file alist syslibp key)
8299 (while (setq entry (pop entries))
8301 (setq source (nth 3 entry)
8303 type-cons (cons type (nth 3 source))
8304 file (idlwave-routine-source-file source))
8306 ;; Make KEY to index entry properly
8307 (setq key (cond ((eq type 'system) type)
8308 (file (file-truename file))
8311 ;; Check for an entry in the system library
8314 (idlwave-syslib-p file))
8317 ;; If there's more than one matching entry for the same file, just
8318 ;; append the type-cons to the type list.
8319 (if (setq entry (assoc key alist))
8320 (push type-cons (nth 2 entry))
8321 (push (list key file (list type-cons)) alist)))
8323 (setq alist (nreverse alist))
8326 ;; File is in system *library* - remove any 'system entry
8327 (setq alist (delq (assq 'system alist) alist)))
8329 ;; If 'system remains and we've scanned the syslib, it's a builtin
8330 ;; (rather than a !DIR/lib/.pro file bundled as source).
8331 (when (and (idlwave-syslib-scanned-p)
8332 (setq entry (assoc 'system alist)))
8333 (setcar entry 'builtin))
8334 (sort alist 'idlwave-routine-twin-compare)))
8339 (defvar idlwave-sort-prefer-buffer-info t
8340 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8342 (defmacro idlwave-xor (a b)
8346 (defun idlwave-routine-entry-compare (a b)
8347 "Compare two routine info entries for sortiung. This is the general case.
8348 It first compates class, names, and type. If it turns out that A and B
8349 are twins (same name, class, and type), calls another routine which
8350 compares twins on the basis of their file names and path locations."
8351 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8353 ((not (equal (idlwave-downcase-safe class)
8354 (idlwave-downcase-safe (nth 2 b))))
8356 (cond ((null (nth 2 b)) nil)
8358 (t (string< (downcase class) (downcase (nth 2 b))))))
8359 ((not (equal (downcase name) (downcase (car b))))
8361 (string< (downcase name) (downcase (car b))))
8362 ((not (eq type (nth 1 b)))
8364 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8366 ;; A and B are twins - so the decision is more complicated.
8367 ;; Call twin-compare with the proper arguments.
8368 (idlwave-routine-entry-compare-twins a b)))))
8370 (defun idlwave-routine-entry-compare-twins (a b)
8371 "Compare two routine entries, under the assumption that they are
8372 twins. This basically calls `idlwave-routine-twin-compare' with the
8374 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8379 (afile (idlwave-routine-source-file asrc))
8380 (bfile (idlwave-routine-source-file bsrc)))
8381 (idlwave-routine-twin-compare
8383 (list (file-truename afile) afile (list atype))
8384 (list atype afile (list atype)))
8386 (list (file-truename bfile) bfile (list btype))
8387 (list btype bfile (list btype))))
8390 (defun idlwave-routine-twin-compare (a b)
8391 "Compare two routine twin entries for sorting.
8392 In here, A and B are not normal routine info entries, but special
8393 lists (KEY FILENAME (TYPES...)).
8394 This expects NAME TYPE CLASS to be bound to the right values."
8395 (let* (;; Dis-assemble entries
8396 (akey (car a)) (bkey (car b))
8397 (afile (nth 1 a)) (bfile (nth 1 b))
8398 (atypes (nth 2 a)) (btypes (nth 2 b))
8400 (asysp (memq akey '(builtin system)))
8401 (bsysp (memq bkey '(builtin system)))
8402 ;; Compiled routines?
8403 (acompp (memq 'compiled atypes))
8404 (bcompp (memq 'compiled btypes))
8406 (aunresp (or (eq akey 'unresolved)
8407 (and acompp (not afile))))
8408 (bunresp (or (eq bkey 'unresolved)
8409 (and bcompp (not bfile))))
8410 ;; Buffer info available?
8411 (abufp (memq 'buffer atypes))
8412 (bbufp (memq 'buffer btypes))
8414 (tpath-alist (idlwave-true-path-alist))
8415 (apathp (and (stringp akey)
8416 (assoc (file-name-directory akey) tpath-alist)))
8417 (bpathp (and (stringp bkey)
8418 (assoc (file-name-directory bkey) tpath-alist)))
8419 ;; How early on search path? High number means early since we
8420 ;; measure the tail of the path list
8421 (anpath (length (memq apathp tpath-alist)))
8422 (bnpath (length (memq bpathp tpath-alist)))
8423 ;; Look at file names
8424 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8425 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8426 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8427 (regexp-quote (downcase class))
8428 (regexp-quote (downcase name)))
8429 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8430 ;; Is file name derived from the routine name?
8431 ;; Method file or class definition file?
8432 (anamep (string-match fname-re aname))
8433 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8434 (bnamep (string-match fname-re bname))
8435 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8437 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8438 ;; doesn't it? The difficult stuff is hidden above...
8440 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8441 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8442 ((and idlwave-sort-prefer-buffer-info
8443 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8444 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8445 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8446 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8447 ((and class anamep bnamep ; both file names match ->
8448 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8449 ((> anpath bnpath) t) ; Who is first on path?
8450 (t nil)))) ; Default
8452 (defun idlwave-routine-source-file (source)
8454 (expand-file-name (nth 1 source) (nth 2 source))
8457 (defun idlwave-downcase-safe (string)
8458 "Donwcase if string, else return unchanged."
8459 (if (stringp string)
8463 (defun idlwave-count-eq (elt list)
8464 "How often is ELT in LIST?"
8465 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8467 (defun idlwave-count-memq (elt alist)
8468 "How often is ELT a key in ALIST?"
8469 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8471 (defun idlwave-syslib-p (file)
8472 "Non-nil if FILE is in the system library."
8473 (let* ((true-syslib (file-name-as-directory
8475 (expand-file-name "lib" (idlwave-sys-dir)))))
8476 (true-file (file-truename file)))
8477 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8479 (defun idlwave-lib-p (file)
8480 "Non-nil if file is in the library"
8481 (let ((true-dir (file-name-directory (file-truename file))))
8482 (assoc true-dir (idlwave-true-path-alist))))
8484 (defun idlwave-path-alist-add-flag (list-entry flag)
8485 "Add a flag to the path list entry, if not set."
8486 (let ((flags (cdr list-entry)))
8487 (add-to-list 'flags flag)
8488 (setcdr list-entry flags)))
8490 (defun idlwave-path-alist-remove-flag (list-entry flag)
8491 "Remove a flag to the path list entry, if set."
8492 (let ((flags (delq flag (cdr list-entry))))
8493 (setcdr list-entry flags)))
8495 (defun idlwave-true-path-alist ()
8496 "Return `idlwave-path-alist' alist with true-names.
8497 Info is cached, but relies on the functions setting `idlwave-path-alist'
8498 to reset the variable `idlwave-true-path-alist' to nil."
8499 (or idlwave-true-path-alist
8500 (setq idlwave-true-path-alist
8501 (mapcar (lambda(x) (cons
8502 (file-name-as-directory
8504 (directory-file-name
8507 idlwave-path-alist))))
8509 (defun idlwave-syslib-scanned-p ()
8510 "Non-nil if the system lib file !DIR/lib has been scanned."
8511 (let* ((true-syslib (file-name-as-directory
8513 (expand-file-name "lib" (idlwave-sys-dir))))))
8514 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8516 ;; ----------------------------------------------------------------------------
8518 ;; Online Help display
8521 ;; ----------------------------------------------------------------------------
8523 ;; Additions for use with imenu.el and func-menu.el
8524 ;; (pop-up a list of IDL units in the current file).
8527 (defun idlwave-prev-index-position ()
8528 "Search for the previous procedure or function.
8529 Return nil if not found. For use with imenu.el."
8532 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
8533 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
8536 (defun idlwave-unit-name ()
8537 "Return the unit name.
8538 Assumes that point is at the beginning of the unit as found by
8539 `idlwave-prev-index-position'."
8542 (let ((begin (point)))
8544 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
8545 (if (fboundp 'buffer-substring-no-properties)
8546 (buffer-substring-no-properties begin (point))
8547 (buffer-substring begin (point)))))
8549 (defalias 'idlwave-function-menu
8552 (require 'func-menu)
8554 (error (condition-case nil
8560 ;; Here we hack func-menu.el in order to support this new mode.
8561 ;; The latest versions of func-menu.el already have this stuff in, so
8562 ;; we hack only if it is not already there.
8563 (when (fboundp 'eval-after-load)
8564 (eval-after-load "func-menu"
8566 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
8567 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
8568 (setq fume-function-name-regexp-alist
8569 (cons '(idlwave-mode . fume-function-name-regexp-idl)
8570 fume-function-name-regexp-alist)))
8571 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
8572 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
8573 (setq fume-find-function-name-method-alist
8574 (cons '(idlwave-mode . fume-find-next-idl-function-name)
8575 fume-find-function-name-method-alist))))))
8577 (defun idlwave-edit-in-idlde ()
8578 "Edit the current file in IDL Development environment."
8580 (start-process "idldeclient" nil
8581 idlwave-shell-explicit-file-name "-c" "-e"
8582 (buffer-file-name) "&"))
8584 (defun idlwave-launch-idlhelp ()
8585 "Start the IDLhelp application."
8587 (start-process "idlhelp" nil idlwave-help-application))
8589 ;; Menus - using easymenu.el
8590 (defvar idlwave-mode-menu-def
8592 ["PRO/FUNC menu" idlwave-function-menu t]
8594 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8595 ["Subprogram End" idlwave-end-of-subprogram t]
8596 ["Block Start" idlwave-beginning-of-block t]
8597 ["Block End" idlwave-end-of-block t]
8598 ["Up Block" idlwave-backward-up-block t]
8599 ["Down Block" idlwave-down-block t]
8600 ["Skip Block Backward" idlwave-backward-block t]
8601 ["Skip Block Forward" idlwave-forward-block t])
8603 ["Subprogram" idlwave-mark-subprogram t]
8604 ["Block" idlwave-mark-block t]
8605 ["Header" idlwave-mark-doclib t])
8607 ["Indent Subprogram" idlwave-indent-subprogram t]
8608 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8609 ["Continue/Split line" idlwave-split-line t]
8611 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8612 :selected (symbol-value idlwave-fill-function)])
8614 ["Procedure" idlwave-procedure t]
8615 ["Function" idlwave-function t]
8616 ["Doc Header" idlwave-doc-header t]
8617 ["Log" idlwave-doc-modification t]
8619 ["Case" idlwave-case t]
8620 ["For" idlwave-for t]
8621 ["Repeat" idlwave-repeat t]
8622 ["While" idlwave-while t]
8624 ["Close Block" idlwave-close-block t])
8626 ["Complete" idlwave-complete t]
8628 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8629 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8631 ["3 Function Name" (idlwave-complete 'function) t]
8632 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8634 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8635 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8637 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8638 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8640 ["9 Class Name" idlwave-complete-class t]))
8642 ["Show Routine Info" idlwave-routine-info t]
8643 ["Online Context Help" idlwave-context-help t]
8645 ["Find Routine Source" idlwave-find-module t]
8646 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8648 ["Update Routine Info" idlwave-update-routine-info t]
8651 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
8652 ["Scan Directories" (idlwave-update-routine-info '(16))
8653 (and idlwave-path-alist (not idlwave-catalog-process))]
8654 ["Scan Directories &" (idlwave-update-routine-info '(64))
8655 (and idlwave-path-alist (not idlwave-catalog-process))]
8658 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8659 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8660 ["Check Everything" idlwave-list-all-load-path-shadows t])
8662 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8664 ["Insert TAB character" idlwave-hard-tab t])
8667 ["Generate IDL tags" idlwave-make-tags t]
8668 ["Start IDL shell" idlwave-shell t]
8669 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8670 ["Launch IDL Help" idlwave-launch-idlhelp t])
8673 ["Browse IDLWAVE Group" idlwave-customize t]
8675 ["Build Full Customize Menu" idlwave-create-customize-menu
8676 (fboundp 'customize-menu-create)])
8678 ["Describe Mode" describe-mode t]
8679 ["Abbreviation List" idlwave-list-abbrevs t]
8681 ["Commentary in idlwave.el" idlwave-show-commentary t]
8682 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8684 ["Info" idlwave-info t]
8686 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8688 (defvar idlwave-mode-debug-menu-def
8690 ["Start IDL shell" idlwave-shell t]
8691 ["Save and .RUN buffer" idlwave-shell-save-and-run
8692 (and (boundp 'idlwave-shell-automatic-start)
8693 idlwave-shell-automatic-start)]))
8695 (if (or (featurep 'easymenu) (load "easymenu" t))
8697 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8698 "IDL and WAVE CL editing menu"
8699 idlwave-mode-menu-def)
8700 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8701 "IDL and WAVE CL editing menu"
8702 idlwave-mode-debug-menu-def)))
8704 (defun idlwave-customize ()
8705 "Call the customize function with idlwave as argument."
8707 ;; Try to load the code for the shell, so that we can customize it
8709 (or (featurep 'idlw-shell)
8710 (load "idlw-shell" t))
8711 (customize-browse 'idlwave))
8713 (defun idlwave-create-customize-menu ()
8714 "Create a full customization menu for IDLWAVE, insert it into the menu."
8716 (if (fboundp 'customize-menu-create)
8718 ;; Try to load the code for the shell, so that we can customize it
8720 (or (featurep 'idlw-shell)
8721 (load "idlw-shell" t))
8723 '("IDLWAVE") "Customize"
8724 `(["Browse IDLWAVE group" idlwave-customize t]
8726 ,(customize-menu-create 'idlwave)
8727 ["Set" Custom-set t]
8728 ["Save" Custom-save t]
8729 ["Reset to Current" Custom-reset-current t]
8730 ["Reset to Saved" Custom-reset-saved t]
8731 ["Reset to Standard Settings" Custom-reset-standard t]))
8732 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8733 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8735 (defun idlwave-show-commentary ()
8736 "Use the finder to view the file documentation from `idlwave.el'."
8739 (finder-commentary "idlwave.el"))
8741 (defun idlwave-shell-show-commentary ()
8742 "Use the finder to view the file documentation from `idlw-shell.el'."
8745 (finder-commentary "idlw-shell.el"))
8747 (defun idlwave-info ()
8748 "Read documentation for IDLWAVE in the info system."
8751 (Info-goto-node "(idlwave)"))
8753 (defun idlwave-list-abbrevs (arg)
8754 "Show the code abbreviations define in IDLWAVE mode.
8755 This lists all abbrevs where the replacement text differs from the input text.
8756 These are the ones the users want to learn to speed up their writing.
8758 The function does *not* list abbrevs which replace a word with itself
8759 to call a hook. These hooks are used to change the case of words or
8760 to blink the matching `begin', and the user does not need to know them.
8762 With arg, list all abbrevs with the corresponding hook.
8764 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8767 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8769 str rpl func fmt (len-str 0) (len-rpl 0))
8772 (if (symbol-value sym)
8774 (setq str (symbol-name sym)
8775 rpl (symbol-value sym)
8776 func (symbol-function sym))
8778 (setq func (prin1-to-string func))
8779 (if (and (listp func) (stringp (nth 2 func)))
8780 (setq rpl (concat "EVAL: " (nth 2 func))
8783 (if (or arg (not (string= rpl str)))
8785 (setq len-str (max len-str (length str)))
8786 (setq len-rpl (max len-rpl (length rpl)))
8787 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8790 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8792 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8793 (with-output-to-temp-buffer "*Help*"
8796 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8797 (princ "=========================================\n\n")
8798 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8799 (princ (format fmt "---" "-------" "----")))
8800 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8801 (princ "================================================\n\n")
8802 (princ (format fmt "KEY" "ACTION" ""))
8803 (princ (format fmt "---" "------" "")))
8806 (setq str (car list)
8809 (princ (format fmt str rpl func)))
8811 ;; Make sure each abbreviation uses only one display line
8813 (set-buffer "*Help*")
8814 (setq truncate-lines t)))
8816 ;; Add .pro files to speedbar for support, if it's loaded
8817 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8819 ;; Set an idle timer to load the routine info.
8820 ;; Will only work on systems which support this.
8821 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8823 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
8826 (run-hooks 'idlwave-load-hook)
8830 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
8831 ;;; idlwave.el ends here