1 ;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation
4 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
5 ;; Carsten Dominik <dominik@astro.uva.nl>
6 ;; Chris Chase <chase@att.com>
7 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; In the remotely distant past, based on pascal.el, though bears
31 ;; little resemblance to it now.
33 ;; Incorporates many ideas, such as abbrevs, action routines, and
34 ;; continuation line indenting, from wave.el.
35 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
37 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
38 ;; for features, key bindings, and info.
39 ;; Also, Info format documentation is available with `M-x idlwave-info'
41 ;; New versions of IDLWAVE, documentation, and more information
48 ;; Follow the instructions in the INSTALL file of the distribution.
49 ;; In short, put this file on your load path and add the following
50 ;; lines to your .emacs file:
52 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
53 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
54 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
60 ;; The newest version of this file is available from the maintainer's
68 ;; IDLWAVE is documented online in info format. A printable version
69 ;; of the documentation is available from the maintainers webpage (see
76 ;; Thanks to the following people for their contributions and comments:
78 ;; Ulrik Dickow <dickow_at_nbi.dk>
79 ;; Eric E. Dors <edors_at_lanl.gov>
80 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
81 ;; David Huenemoerder <dph_at_space.mit.edu>
82 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
83 ;; Dick Jackson <dick_at_d-jackson.com>
84 ;; Xuyong Liu <liu_at_stsci.edu>
85 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
86 ;; Laurent Mugnier <mugnier_at_onera.fr>
87 ;; Lubos Pochman <lubos_at_rsinc.com>
88 ;; Bob Portmann <portmann_at_al.noaa.gov>
89 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
90 ;; Marty Ryba <ryba_at_ll.mit.edu>
91 ;; Paul Sorenson <aardvark62_at_msn.com>
92 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
93 ;; Phil Williams <williams_at_irc.chmcc.org>
98 ;; IDLWAVE has extensive customize support; to learn about the
99 ;; variables which control the mode's behavior, use `M-x
100 ;; idlwave-customize'.
102 ;; You can set your own preferred values with Customize, or with Lisp
103 ;; code in .emacs. For an example of what to put into .emacs, check
104 ;; the TexInfo documentation or see a complete .emacs available at the
110 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
111 ;; Numerics, Inc. is growing less and less complete as the two
112 ;; languages grow increasingly apart. The mode probably shouldn't
113 ;; even have "WAVE" in it's title, but it's catchy, and was required
114 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
116 ;; Moving the point backwards in conjunction with abbrev expansion
117 ;; does not work as I would like it, but this is a problem with
118 ;; emacs abbrev expansion done by the self-insert-command. It ends
119 ;; up inserting the character that expanded the abbrev after moving
120 ;; point backward, e.g., "\cl" expanded with a space becomes
121 ;; "LONG( )" with point before the close paren. This is solved by
122 ;; using a temporary function in `post-command-hook' - not pretty,
125 ;; Tabs and spaces are treated equally as whitespace when filling a
126 ;; comment paragraph. To accomplish this, tabs are permanently
127 ;; replaced by spaces in the text surrounding the paragraph, which
128 ;; may be an undesirable side-effect. Replacing tabs with spaces is
129 ;; limited to comments only and occurs only when a comment
130 ;; paragraph is filled via `idlwave-fill-paragraph'.
132 ;; Muti-statement lines (using "&") on block begin and end lines can
133 ;; ruin the formatting. For example, multiple end statements on a
134 ;; line: endif & endif. Using "&" outside of block begin/end lines
137 ;; Determining the expression at point for printing and other
138 ;; examination commands is somewhat rough: currently only fairly
139 ;; simple entities are found. You can always drag-select or examine
140 ;; a pre-selected region.
142 ;; When forcing completion of method keywords, the initial
143 ;; query for a method has multiple entries for some methods. Would
144 ;; be too difficult to fix this hardly used case.
150 (eval-when-compile (require 'cl
))
154 (unless (fboundp 'line-beginning-position
)
155 (defalias 'line-beginning-position
'point-at-bol
))
156 (unless (fboundp 'line-end-position
)
157 (defalias 'line-end-position
'point-at-eol
))
158 (unless (fboundp 'char-valid-p
)
159 (defalias 'char-valid-p
'characterp
))
162 ;; Kludge to allow `defcustom' for Emacs 19.
163 (condition-case () (require 'custom
) (error nil
))
164 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
165 nil
;; We've got what we needed
166 ;; We have the old or no custom-library, hack around it!
167 (defmacro defgroup
(&rest args
) nil
)
168 (defmacro defcustom
(var value doc
&rest args
)
169 `(defvar ,var
,value
,doc
))))
171 (defgroup idlwave nil
172 "Major mode for editing IDL .pro files"
174 :link
'(url-link :tag
"Home Page"
175 "http://idlwave.org")
176 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
178 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
179 :link
'(custom-manual "(idlwave)Top")
184 ;;; Variables for indentation behavior ---------------------------------------
186 (defgroup idlwave-code-formatting nil
187 "Indentation and formatting options for IDLWAVE mode."
190 (defcustom idlwave-main-block-indent
0
191 "*Extra indentation for the main block of code.
192 That is the block between the FUNCTION/PRO statement and the END
193 statement for that program unit."
194 :group
'idlwave-code-formatting
197 (defcustom idlwave-block-indent
4
198 "*Extra indentation applied to block lines.
199 If you change this, you probably also want to change `idlwave-end-offset'."
200 :group
'idlwave-code-formatting
203 (defcustom idlwave-end-offset -
4
204 "*Extra indentation applied to block END lines.
205 A value equal to negative `idlwave-block-indent' will make END lines
206 line up with the block BEGIN lines."
207 :group
'idlwave-code-formatting
210 (defcustom idlwave-continuation-indent
2
211 "*Extra indentation applied to continuation lines.
212 This extra offset applies to the first of a set of continuation lines.
213 The following lines receive the same indentation as the first."
214 :group
'idlwave-code-formatting
217 (defcustom idlwave-max-extra-continuation-indent
20
218 "*Maximum additional indentation for special continuation indent.
219 Several special indentations are tried to help line up continuation
220 lines in routine calls or definitions, other statements with
221 parentheses, or assignment statements. This variable specifies a
222 maximum amount by which this special indentation can exceed the
223 standard continuation indentation, otherwise defaulting to a fixed
224 offset. Set to 0 to effectively disable all special continuation
225 indentation, or to a large number (like 100) to enable it in all
226 cases. See also `idlwave-indent-to-open-paren', which can override
228 :group
'idlwave-code-formatting
231 (defcustom idlwave-indent-to-open-paren t
232 "*Non-nil means, indent continuation lines to innermost open
233 parenthesis. This indentation occurs even if otherwise disallowed by
234 `idlwave-max-extra-continuation-indent'. Matching parens and the
235 interleaving args are lined up. Example:
237 x = function_a(function_b(function_c( a, b, [1,2,3, $
243 When this variable is nil, paren alignment may still occur, based on
244 the value of `max-extra-continuation-indent', which, if zero, would
247 x = function_a(function_b(function_c( a, b, [1,2,3, $
252 :group
'idlwave-code-formatting
255 (defcustom idlwave-indent-parens-nested nil
256 "*Non-nil means, indent continuation lines with parens by nesting
257 lines at consecutively deeper levels."
258 :group
'idlwave-code-formatting
262 (defcustom idlwave-hanging-indent t
263 "*If set non-nil then comment paragraphs are indented under the
264 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
266 :group
'idlwave-code-formatting
269 (defcustom idlwave-hang-indent-regexp
"- "
270 "*Regular expression matching the position of the hanging indent
271 in the first line of a comment paragraph. The size of the indent
272 extends to the end of the match for the regular expression."
273 :group
'idlwave-code-formatting
276 (defcustom idlwave-use-last-hang-indent nil
277 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
278 :group
'idlwave-code-formatting
281 (defcustom idlwave-fill-comment-line-only t
282 "*If non-nil then auto fill will only operate on comment lines."
283 :group
'idlwave-code-formatting
286 (defcustom idlwave-auto-fill-split-string t
287 "*If non-nil then auto fill will split strings with the IDL `+' operator.
288 When the line end falls within a string, string concatenation with the
289 '+' operator will be used to distribute a long string over lines.
290 If nil and a string is split then a terminal beep and warning are issued.
292 This variable is ignored when `idlwave-fill-comment-line-only' is
293 non-nil, since in this case code is not auto-filled."
294 :group
'idlwave-code-formatting
297 (defcustom idlwave-split-line-string t
298 "*If non-nil then `idlwave-split-line' will split strings with `+'.
299 When the splitting point of a line falls inside a string, split the string
300 using the `+' string concatenation operator. If nil and a string is
301 split then a terminal beep and warning are issued."
302 :group
'idlwave-code-formatting
305 (defcustom idlwave-no-change-comment
";;;"
306 "*The indentation of a comment that starts with this regular
307 expression will not be changed. Note that the indentation of a comment
308 at the beginning of a line is never changed."
309 :group
'idlwave-code-formatting
312 (defcustom idlwave-begin-line-comment nil
313 "*A comment anchored at the beginning of line.
314 A comment matching this regular expression will not have its
315 indentation changed. If nil the default is \"^;\", i.e., any line
316 beginning with a \";\". Expressions for comments at the beginning of
317 the line should begin with \"^\"."
318 :group
'idlwave-code-formatting
319 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
322 (defcustom idlwave-code-comment
";;[^;]"
323 "*A comment that starts with this regular expression on a line by
324 itself is indented as if it is a part of IDL code. As a result if
325 the comment is not preceded by whitespace it is unchanged."
326 :group
'idlwave-code-formatting
329 ;; Comments not matching any of the above will be indented as a
330 ;; right-margin comment, i.e., to a minimum of `comment-column'.
332 ;;; Routine Info and Completion ---------------------------------------
334 (defgroup idlwave-routine-info nil
335 "Routine Info options for IDLWAVE mode."
338 (defcustom idlwave-use-library-catalogs t
339 "*Non-nil means search the IDL path for library catalog files.
341 These files, named .idlwave_catalog, document routine information for
342 individual directories and libraries of IDL .pro files. Many popular
343 libraries come with catalog files by default, so leaving this on is a
344 usually a good idea.."
345 :group
'idlwave-routine-info
348 (defcustom idlwave-init-rinfo-when-idle-after
10
349 "*Seconds of idle time before routine info is automatically initialized.
350 Initializing the routine info can take long, in particular if a large
351 library catalog is involved. When Emacs is idle for more than the number
352 of seconds specified by this variable, it starts the initialization.
353 The process is split into five steps, in order to keep possible work
354 interruption as short as possible. If one of the steps finishes, and no
355 user input has arrived in the mean time, initialization proceeds immediately
357 A good value for this variable is about 1/3 of the time initialization
358 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.
359 A Value of 0 means, don't initialize automatically."
360 :group
'idlwave-routine-info
363 (defcustom idlwave-scan-all-buffers-for-routine-info t
364 "*Non-nil means, scan buffers for IDL programs when updating info.
365 The scanning is done by the command `idlwave-update-routine-info'.
366 The following values are allowed:
368 nil Don't scan any buffers.
369 t Scan all idlwave-mode buffers in the current editing session.
370 current Scan only the current buffer, but no other buffers."
371 :group
'idlwave-routine-info
373 (const :tag
"No buffer" nil
)
374 (const :tag
"All buffers" t
)
375 (const :tag
"Current buffer only" 'current
)))
377 (defcustom idlwave-query-shell-for-routine-info t
378 "*Non-nil means query the shell for info about compiled routines.
379 Querying the shell is useful to get information about compiled modules,
380 and it is turned on by default. However, when you have a complete library
381 scan, this is not necessary."
382 :group
'idlwave-routine-info
385 (defcustom idlwave-auto-routine-info-updates
386 '(find-file save-buffer kill-buffer compile-buffer
)
387 "*Controls under what circumstances routine info is updated automatically.
391 \(...) A list of circumstances. Allowed members are:
392 find-file Add info for new IDLWAVE buffers.
393 save-buffer Update buffer info when buffer is saved
394 kill-buffer Remove buffer info when buffer gets killed
395 compile-buffer Update shell info after `idlwave-shell-save-and...'"
396 :group
'idlwave-routine-info
398 (const :tag
"Never" nil
)
399 (const :tag
"As often as possible" t
)
400 (set :tag
"Checklist" :greedy t
401 (const :tag
"When visiting a file" find-file
)
402 (const :tag
"When saving a buffer" save-buffer
)
403 (const :tag
"After a buffer was killed" kill-buffer
)
404 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
406 (defcustom idlwave-rinfo-max-source-lines
5
407 "*Maximum number of source files displayed in the Routine Info window.
408 When an integer, it is the maximum number of source files displayed.
409 t means to show all source files."
410 :group
'idlwave-routine-info
413 (defcustom idlwave-library-path nil
414 "Library path for Windows and MacOS. Not needed under Unix. When
415 selecting the directories to scan for IDL user catalog routine info,
416 IDLWAVE can, under UNIX, query the shell for the exact search path
417 \(the value of !PATH). However, under Windows and MacOS (pre-OSX),
418 the IDLWAVE shell does not work. In this case, this variable can be
419 set to specify the paths where IDLWAVE can find PRO files. The shell
420 will only be asked for a list of paths when this variable is nil. The
421 value is a list of directories. A directory preceeded by a `+' will
422 be searched recursively. If you set this variable on a UNIX system,
423 the shell will not be queried. See also `idlwave-system-directory'."
424 :group
'idlwave-routine-info
425 :type
'(repeat (directory)))
427 (defcustom idlwave-system-directory
""
428 "The IDL system directory for Windows and MacOS. Not needed under
429 UNIX. Set this to the value of the `!DIR' system variable in IDL.
430 IDLWAVE uses this to find out which of the library routines belong to
431 the official system library. All files inside the `lib' subdirectory
432 are considered system library files - so don't install private stuff
433 in this directory. On UNIX systems, IDLWAVE queries the shell for the
434 value of `!DIR'. See also `idlwave-library-path'."
435 :group
'idlwave-routine-info
438 (defcustom idlwave-config-directory
439 (convert-standard-filename "~/.idlwave")
440 "*Directory for configuration files and user-library catalog."
441 :group
'idlwave-routine-info
444 (defvar idlwave-user-catalog-file
"idlusercat.el")
445 (defvar idlwave-path-file
"idlpath.el")
447 (defvar idlwave-libinfo-file nil
448 "*Obsolete variable, no longer used.")
450 (defcustom idlwave-special-lib-alist nil
451 "Alist of regular expressions matching special library directories.
452 When listing routine source locations, IDLWAVE gives a short hint where
453 the file defining the routine is located. By default it lists `SystemLib'
454 for routines in the system library `!DIR/lib' and `Library' for anything
455 else. This variable can define additional types. The car of each entry
456 is a regular expression matching the file name (they normally will match
457 on the path). The cdr is the string to be used as identifier. Max 10
459 :group
'idlwave-routine-info
461 (cons regexp string
)))
463 (defcustom idlwave-auto-write-paths t
464 "Write out path (!PATH) and system directory (!DIR) info automatically.
465 Path info is needed to locate library catalog files. If non-nil,
466 whenever the path-list changes as a result of shell-query, etc., it is
467 written to file. Otherwise, the menu option \"Write Paths\" can be
468 used to force a write."
469 :group
'idlwave-routine-info
472 (defgroup idlwave-completion nil
473 "Completion options for IDLWAVE mode."
478 (defconst idlwave-tmp
479 '(choice :tag
"by applying the function"
484 (symbol :tag
"Other"))))
486 (defcustom idlwave-completion-case
'((routine . upcase
)
490 "Association list setting the case of completed words.
492 This variable determines the case (UPPER/lower/Capitalized...) of
493 words inserted into the buffer by completion. The preferred case can
494 be specified separately for routine names, keywords, classes and
496 This alist should therefore have entries for `routine' (normal
497 functions and procedures, i.e. non-methods), `keyword', `class', and
498 `method'. Plausible values are
500 upcase upcase whole word, like `BOX_CURSOR'
501 downcase downcase whole word, like `read_ppm'
502 capitalize capitalize each part, like `Widget_Control'
503 preserve preserve case as is, like `IDLgrView'
505 The value can also be any Emacs Lisp function which transforms the
506 case of characters in a string.
508 A value of `preserve' means that the case of the completed word is
509 identical to the way it was written in the definition statement of the
510 routine. This was implemented to allow for mixed-case completion, in
511 particular of object classes and methods.
512 If a completable word is defined in multiple locations, the meaning of
513 `preserve' is not unique since the different definitions might be
514 cased differently. Therefore IDLWAVE always takes the case of the
515 *first* definition it encounters during routine info collection and
516 uses the case derived from it consistently.
518 Note that a lowercase-only string in the buffer will always be completed in
519 lower case (but see the variable `idlwave-completion-force-default-case').
521 After changing this variable, you need to either restart Emacs or press
522 `C-u C-c C-i' to update the internal lists."
523 :group
'idlwave-completion
525 (cons (symbol :tag
"Derive completion case for")
528 (defcustom idlwave-completion-force-default-case nil
529 "*Non-nil means, completion will always honor `idlwave-completion-case'.
530 When nil, only the completion of a mixed case or upper case string
531 will honor the default settings in `idlwave-completion-case', while
532 the completion of lower case strings will be completed entirely in
534 :group
'idlwave-completion
537 (defcustom idlwave-complete-empty-string-as-lower-case nil
538 "*Non-nil means, the empty string is considered downcase for completion.
539 The case of what is already in the buffer determines the case of completions.
540 When this variable is non-nil, the empty string is considered to be downcase.
541 Completing on the empty string then offers downcase versions of the possible
543 :group
'idlwave-completion
546 (defvar idlwave-default-completion-case-is-down nil
547 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
548 `idlwave-completion-case'.")
550 (defcustom idlwave-buffer-case-takes-precedence nil
551 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
552 To make this possible, we need to re-case everything each time we update
553 the routine info from the buffers. This is slow.
554 The default is to consider the case given in the system and library files
555 first which makes updating much faster."
556 :group
'idlwave-completion
559 (defcustom idlwave-highlight-help-links-in-completion t
560 "*Non-nil means, highlight completions for which system help is available.
561 Help can then be accessed with mouse-3.
562 This option is only effective when the online help system is installed."
563 :group
'idlwave-completion
566 (defcustom idlwave-support-inheritance t
567 "Non-nil means, treat inheritance with completion, online help etc.
568 When nil, IDLWAVE only knows about the native methods and tags of a class,
569 not about inherited ones."
570 :group
'idlwave-routine-info
573 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
574 "List of regular expressions for class-driven keyword inheritance.
575 Keyword inheritance is often tied to class inheritance by \"chaining\"
576 up the class tree. While it cannot be assumed that the presence of an
577 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
578 certain methods this assumption is almost always true. The methods
579 for which to assume this can be set here."
580 :group
'idlwave-routine-info
581 :type
'(repeat (regexp :tag
"Match method:")))
584 (defcustom idlwave-completion-show-classes
1
585 "*Number of classes to show when completing object methods and keywords.
586 When completing methods or keywords for an object with unknown class,
587 the *Completions* buffer will show the legal classes for each completion
590 MyMethod <Class1,Class2,Class3>
592 The value of this variable may be nil to inhibit display, or an integer to
593 indicate the maximum number of classes to display.
595 On XEmacs, a full list of classes will also be placed into a `help-echo'
596 property on the competion items, so that the list of classes for the current
597 item is displayed in the echo area. If the value of this variable is a
598 negative integer, the `help-echo' property will be suppressed."
599 :group
'idlwave-completion
600 :type
'(choice (const :tag
"Don't show" nil
)
601 (integer :tag
"Number of classes shown" 1)))
603 (defcustom idlwave-completion-fontify-classes t
604 "*Non-nil means, fontify the classes in completions buffer.
605 This makes it easier to distinguish the completion items from the extra
606 class info listed. See `idlwave-completion-show-classes'."
607 :group
'idlwave-completion
610 (defcustom idlwave-query-class
'((method-default . nil
)
611 (keyword-default . nil
))
612 "Association list governing specification of object classes for completion.
614 When IDLWAVE tries to complete object-oriented methods, it usually
615 cannot determine the class of a given object from context. In order
616 to provide the user with a correct list of methods or keywords, it
617 needs to determine the appropriate class. IDLWAVE has two ways of
618 doing this (well, three ways if you count the shell... see
619 `idlwave-shell-query-for-class'):
621 1. Combine the items of all available classes which contain this
622 method for the purpose of completion. So when completing a method,
623 all methods of all known classes are available, and when completing
624 a keyword, all keywords allowed for this method in any class are
625 shown. This behavior is very much like normal completion and is
626 therefore the default. It works much better than one might think -
627 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
628 become uncomfortably long. See also
629 `idlwave-completion-show-classes'.
631 2. The second possibility is to ask the user on each occasion. To
632 make this less interruptive, IDLWAVE can store the class as a text
633 property on the object operator `->'. For a given object in the
634 source code, class selection will then be needed only once
635 - for example to complete the method. Keywords to the method can
636 then be completed directly, because the class is already known.
637 You will have to turn on the storage of the selected class
638 explicitly with the variable `idlwave-store-inquired-class'.
640 This variable allows you to configure IDLWAVE's method and
641 method-keyword completion behavior. Its value is an alist, which
642 should contain at least two elements: (method-default . VALUE) and
643 \(keyword-default . VALUE), where VALUE is either t or nil. These
644 specify if the class should be found during method and keyword
645 completion, respectively.
647 The alist may have additional entries specifying exceptions from the
648 keyword completion rule for specific methods, like INIT or
649 GETPROPERTY. In order to turn on class specification for the INIT
650 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
651 :group
'idlwave-completion
653 (cons (const method-default
)
654 (boolean :tag
"Determine class when completing METHODS "))
655 (cons (const keyword-default
)
656 (boolean :tag
"Determine class when completing KEYWORDS "))
658 :tag
"Exceptions to defaults"
660 (cons (string :tag
"MODULE" :value
"")
661 (boolean :tag
"Determine class for this method")))))
663 (defcustom idlwave-store-inquired-class nil
664 "*Non-nil means, store class of a method call as text property on `->'.
665 IDLWAVE sometimes has to ask the user for the class associated with a
666 particular object method call. This happens during the commands
667 `idlwave-routine-info' and `idlwave-complete', depending upon the
668 value of the variable `idlwave-query-class'.
670 When you specify a class, this information can be stored as a text
671 property on the `->' arrow in the source code, so that during the same
672 editing session, IDLWAVE will not have to ask again. When this
673 variable is non-nil, IDLWAVE will store and reuse the class information.
674 The class stored can be checked and removed with `\\[idlwave-routine-info]'
677 The default of this variable is nil, since the result of commands then
678 is more predictable. However, if you know what you are doing, it can
679 be nice to turn this on.
681 An arrow which knows the class will be highlighted with
682 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
683 displays (with prefix arg: deletes) the class stored on the arrow
685 :group
'idlwave-completion
688 (defcustom idlwave-class-arrow-face
'bold
689 "*Face to highlight object operator arrows `->' which carry a class property.
690 When IDLWAVE stores a class name as text property on an object arrow
691 \(see variable `idlwave-store-inquired-class', it highlights the arrow
692 with this font in order to remind the user that this arrow is special."
693 :group
'idlwave-completion
696 (defcustom idlwave-resize-routine-help-window t
697 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
698 :group
'idlwave-completion
701 (defcustom idlwave-keyword-completion-adds-equal t
702 "*Non-nil means, completion automatically adds `=' after completed keywords."
703 :group
'idlwave-completion
706 (defcustom idlwave-function-completion-adds-paren t
707 "*Non-nil means, completion automatically adds `(' after completed function.
708 nil means, don't add anything.
709 A value of `2' means, also add the closing parenthesis and position cursor
711 :group
'idlwave-completion
712 :type
'(choice (const :tag
"Nothing" nil
)
714 (const :tag
"()" 2)))
716 (defcustom idlwave-completion-restore-window-configuration t
717 "*Non-nil means, try to restore the window configuration after completion.
718 When completion is not unique, Emacs displays a list of completions.
719 This messes up your window configuration. With this variable set, IDLWAVE
720 restores the old configuration after successful completion."
721 :group
'idlwave-completion
724 ;;; Variables for abbrev and action behavior -----------------------------
726 (defgroup idlwave-abbrev-and-indent-action nil
727 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
728 The variables in this group govern this."
731 (defcustom idlwave-do-actions nil
732 "*Non-nil means performs actions when indenting.
733 The actions that can be performed are listed in `idlwave-indent-action-table'."
734 :group
'idlwave-abbrev-and-indent-action
737 (defcustom idlwave-abbrev-start-char
"\\"
738 "*A single character string used to start abbreviations in abbrev mode.
739 Possible characters to chose from: ~`\%
740 or even '?'. '.' is not a good choice because it can make structure
741 field names act like abbrevs in certain circumstances.
743 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
744 must set it directly using `setq' in the .emacs file before idlwave.el
746 :group
'idlwave-abbrev-and-indent-action
749 (defcustom idlwave-surround-by-blank nil
750 "*Non-nil means, enable `idlwave-surround'.
751 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
753 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
755 Also see the default key bindings for keys using `idlwave-surround'.
756 Keys are bound and made into actions calling `idlwave-surround' with
757 `idlwave-action-and-binding'.
758 See help for `idlwave-action-and-binding' for examples.
760 Also see help for `idlwave-surround'."
761 :group
'idlwave-abbrev-and-indent-action
764 (defcustom idlwave-pad-keyword t
765 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
766 Whenever `idlwave-surround' is non-nil then this affects how '=' is
767 padded for keywords and for variables. If t, pad the same as for
768 assignments. If nil then spaces are removed. With any other value,
769 spaces are left unchanged."
770 :group
'idlwave-abbrev-and-indent-action
772 (const :tag
"Pad like assignments" t
)
773 (const :tag
"Remove space near `='" nil
)
774 (const :tag
"Keep space near `='" 'keep
)))
776 (defcustom idlwave-show-block t
777 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
778 :group
'idlwave-abbrev-and-indent-action
781 (defcustom idlwave-expand-generic-end nil
782 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
783 :group
'idlwave-abbrev-and-indent-action
786 (defcustom idlwave-reindent-end t
787 "*Non-nil means re-indent line after END was typed."
788 :group
'idlwave-abbrev-and-indent-action
791 (defcustom idlwave-abbrev-move t
792 "*Non-nil means the abbrev hook can move point.
793 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
794 definitions, use the command `list-abbrevs', for abbrevs that move
795 point. Moving point is useful, for example, to place point between
796 parentheses of expanded functions.
798 See `idlwave-check-abbrev'."
799 :group
'idlwave-abbrev-and-indent-action
802 (defcustom idlwave-abbrev-change-case nil
803 "*Non-nil means all abbrevs will be forced to either upper or lower case.
804 If the value t, all expanded abbrevs will be upper case.
805 If the value is 'down then abbrevs will be forced to lower case.
806 If nil, the case will not change.
807 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
808 upper case, regardless of this variable."
809 :group
'idlwave-abbrev-and-indent-action
812 (defcustom idlwave-reserved-word-upcase nil
813 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
814 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
815 Has effect only if in abbrev-mode."
816 :group
'idlwave-abbrev-and-indent-action
819 ;;; Action/Expand Tables.
821 ;; The average user may have difficulty modifying this directly. It
822 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
823 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
824 ;; examples of how to add an action.
826 ;; The action table is used by `idlwave-indent-line' whereas both the
827 ;; action and expand tables are used by `idlwave-indent-and-action'. In
828 ;; general, the expand table is only used when a line is explicitly
829 ;; indented. Whereas, in addition to being used when the expand table
830 ;; is used, the action table is used when a line is indirectly
831 ;; indented via line splitting, auto-filling or a new line creation.
835 ;; Capitalize system vars
836 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
838 ;; Capitalize procedure name
839 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
840 ;; '(capitalize-word 1) t)
842 ;; Capitalize common block name
843 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
844 ;; '(capitalize-word 1) t)
846 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
847 ;; '(capitalize-word -1) t)
849 (defvar idlwave-indent-action-table nil
850 "*Associated array containing action lists of search string (car),
851 and function as a cdr. This table is used by `idlwave-indent-line'.
852 See documentation for `idlwave-do-action' for a complete description of
855 Additions to the table are made with `idlwave-action-and-binding' when a
856 binding is not requested.
857 See help on `idlwave-action-and-binding' for examples.")
859 (defvar idlwave-indent-expand-table nil
860 "*Associated array containing action lists of search string (car),
861 and function as a cdr. The table is used by the
862 `idlwave-indent-and-action' function. See documentation for
863 `idlwave-do-action' for a complete description of the action lists.
865 Additions to the table are made with `idlwave-action-and-binding' when a
866 binding is requested.
867 See help on `idlwave-action-and-binding' for examples.")
869 ;;; Documentation header and history keyword ---------------------------------
871 (defgroup idlwave-documentation nil
872 "Options for documenting IDLWAVE files."
875 ;; FIXME: make defcustom?
876 (defvar idlwave-file-header
903 ; KEYWORD PARAMETERS:
935 ; MODIFICATION HISTORY:
939 "*A list (PATHNAME STRING) specifying the doc-header template to use for
940 summarizing a file. If PATHNAME is non-nil then this file will be included.
941 Otherwise STRING is used. If nil, the file summary will be omitted.
942 For example you might set PATHNAME to the path for the
943 lib_template.pro file included in the IDL distribution.")
945 (defcustom idlwave-header-to-beginning-of-file nil
946 "*Non-nil means, the documentation header will always be at start of file.
947 When nil, the header is positioned between the PRO/FUNCTION line of
948 the current routine and the code, allowing several routine headers in
950 :group
'idlwave-documentation
953 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
954 "*The hook function used to update the timestamp of a function."
955 :group
'idlwave-documentation
958 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
959 "*The modifications keyword to use with the log documentation commands.
960 A ':' is added to the keyword end.
961 Inserted by doc-header and used to position logs by doc-modification.
962 If nil it will not be inserted."
963 :group
'idlwave-documentation
966 (defcustom idlwave-doclib-start
"^;+\\+"
967 "*Regexp matching the start of a document library header."
968 :group
'idlwave-documentation
971 (defcustom idlwave-doclib-end
"^;+-"
972 "*Regexp matching the end of a document library header."
973 :group
'idlwave-documentation
976 ;;; External Programs -------------------------------------------------------
978 (defgroup idlwave-external-programs nil
979 "Path locations of external commands used by IDLWAVE."
982 ;; WARNING: The following variable has recently been moved from
983 ;; idlw-shell.el to this file. I hope this does not break
986 (defcustom idlwave-shell-explicit-file-name
"idl"
987 "*If non-nil, this is the command to run IDL.
988 Should be an absolute file path or path relative to the current environment
989 execution search path. If you want to specify command line switches
990 for the idl program, use `idlwave-shell-command-line-options'.
992 I know the name of this variable is badly chosen, but I cannot change
993 it without compromizing backwards-compatibility."
994 :group
'idlwave-external-programs
997 (defcustom idlwave-shell-command-line-options nil
998 "*A list of command line options for calling the IDL program.
999 Since IDL is executed directly without going through a shell like /bin/sh,
1000 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1001 string for each argument. But you may also give a single string which
1002 contains the options whitespace-separated. Emacs will be kind enough to
1006 (repeat (string :value
"")))
1007 :group
'idlwave-external-programs
)
1009 (defcustom idlwave-help-application
"idlhelp"
1010 "*The external application providing reference help for programming."
1011 :group
'idlwave-external-programs
1014 ;;; Some Shell variables which must be defined here.-----------------------
1016 (defcustom idlwave-shell-debug-modifiers
'()
1017 "List of modifiers to be used for the debugging commands.
1018 Will be used to bind debugging commands in the shell buffer and in all
1019 source buffers. These are additional convenience bindings, the debugging
1020 commands are always available with the `C-c C-d' prefix.
1021 If you set this to '(control shift), this means setting a breakpoint will
1022 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1023 are `control', `meta', `super', `hyper', `alt', and `shift'."
1024 :group
'idlwave-shell-general-setup
1025 :type
'(set :tag
"Specify modifiers"
1033 (defcustom idlwave-shell-automatic-start nil
1034 "*If non-nil attempt invoke idlwave-shell if not already running.
1035 This is checked when an attempt to send a command to an
1036 IDL process is made."
1037 :group
'idlwave-shell-general-setup
1040 ;;; Miscellaneous variables -------------------------------------------------
1042 (defgroup idlwave-misc nil
1043 "Miscellaneous options for IDLWAVE mode."
1046 (defcustom idlwave-startup-message t
1047 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1048 :group
'idlwave-misc
1051 (defcustom idlwave-default-font-lock-items
1052 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1053 common-blocks class-arrows
)
1054 "Items which should be fontified on the default fontification level 2.
1055 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1056 is everything and level 2 is specified by this list.
1057 This variable must be set before IDLWAVE gets loaded. It is
1058 a list of symbols, the following symbols are allowed.
1060 pros-and-functions Procedure and Function definitions
1061 batch-files Batch Files
1062 idlwave-idl-keywords IDL Keywords
1063 label Statement Labels
1064 goto Goto Statements
1065 common-blocks Common Blocks
1066 keyword-parameters Keyword Parameters in routine definitions and calls
1067 system-variables System Variables
1068 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1069 class-arrows Object Arrows with class property"
1070 :group
'idlwave-misc
1073 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1074 (const :tag
"Batch Files" batch-files
)
1075 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1076 (const :tag
"Statement Labels" label
)
1077 (const :tag
"Goto Statements" goto
)
1078 (const :tag
"Tags in Structure Definition" structtag
)
1079 (const :tag
"Structure Name" structname
)
1080 (const :tag
"Common Blocks" common-blocks
)
1081 (const :tag
"Keyword Parameters" keyword-parameters
)
1082 (const :tag
"System Variables" system-variables
)
1083 (const :tag
"FIXME: Warning" fixme
)
1084 (const :tag
"Object Arrows with class property " class-arrows
)))
1086 (defcustom idlwave-mode-hook nil
1087 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1088 :group
'idlwave-misc
1091 (defcustom idlwave-load-hook nil
1092 "Normal hook. Executed when idlwave.el is loaded."
1093 :group
'idlwave-misc
1096 (defvar idlwave-experimental nil
1097 "Non-nil means turn on a few experimental features.
1098 This variable is only for the maintainer, to test difficult stuff,
1099 while still distributing stable releases.
1100 As a user, you should not set this to t.")
1103 ;;; End customization variables section
1106 ;;; Non customization variables
1108 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1109 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1110 ;;; and Carsten Dominik...
1112 ;; The following are the reserved words in IDL. Maybe we should
1113 ;; highlight some more stuff as well?
1114 ;; Procedure declarations. Fontify keyword plus procedure name.
1115 (defvar idlwave-idl-keywords
1116 ;; To update this regexp, update the list of keywords and
1117 ;; evaluate the form.
1123 ;; '("||" "&&" "and" "or" "xor" "not"
1124 ;; "eq" "ge" "gt" "le" "lt" "ne"
1125 ;; "for" "do" "endfor"
1126 ;; "if" "then" "endif" "else" "endelse"
1127 ;; "case" "of" "endcase"
1128 ;; "switch" "break" "continue" "endswitch"
1130 ;; "repeat" "until" "endrep"
1131 ;; "while" "endwhile"
1134 ;; "compile_opt" "forward_function"
1135 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1137 "\\<\\(&&\\|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\\|||\\)\\>")
1140 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1141 ;; Function declarations. Fontify keyword plus function name.
1143 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1144 (1 font-lock-keyword-face
)
1145 (2 font-lock-function-name-face nil t
)))
1149 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1150 (1 font-lock-keyword-face
) ; "common"
1151 (2 font-lock-reference-face nil t
) ; block name
1152 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1153 ;; Start with point after block name and comma
1154 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1156 (1 font-lock-variable-name-face
) ; variable names
1161 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1165 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1169 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1171 ;; The goto statement and its label
1173 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1174 (1 font-lock-keyword-face
)
1175 (2 font-lock-reference-face
)))
1177 ;; Tags in structure definitions. Note that this definition
1178 ;; actually collides with labels, so we have to use the same
1179 ;; face. It also matches named subscript ranges,
1180 ;; e.g. vec{bottom:top]. No good way around this.
1182 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1186 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1187 (2 font-lock-function-name-face
)))
1189 ;; Keyword parameters, like /xlog or ,xrange=[]
1190 ;; This is anchored to the comma preceeding the keyword.
1191 ;; Treats continuation lines, works only during whole buffer
1192 ;; fontification. Slow, use it only in fancy fontification.
1194 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1195 (5 font-lock-reference-face
)))
1197 ;; System variables start with a bang.
1199 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1200 (1 font-lock-variable-name-face
)))
1202 ;; Special and unusual operators (not used because too noisy)
1204 '("[<>#]" (0 font-lock-keyword-face
)))
1206 ;; All operators (not used because too noisy)
1208 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1210 ;; Arrows with text property `idlwave-class'
1212 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1214 (defconst idlwave-font-lock-keywords-1
1215 (list pros-and-functions batch-files
)
1216 "Subdued level highlighting for IDLWAVE mode.")
1218 (defconst idlwave-font-lock-keywords-2
1219 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1220 "Medium level highlighting for IDLWAVE mode.")
1222 (defconst idlwave-font-lock-keywords-3
1223 (list pros-and-functions
1225 idlwave-idl-keywords
1233 "Gaudy level highlighting for IDLWAVE mode."))
1235 (defun idlwave-match-class-arrows (limit)
1236 ;; Match an object arrow with class property
1237 (and idlwave-store-inquired-class
1238 (re-search-forward "->" limit
'limit
)
1239 (get-text-property (match-beginning 0) 'idlwave-class
)))
1241 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1242 "Default expressions to highlight in IDLWAVE mode.")
1244 (defvar idlwave-font-lock-defaults
1245 '((idlwave-font-lock-keywords
1246 idlwave-font-lock-keywords-1
1247 idlwave-font-lock-keywords-2
1248 idlwave-font-lock-keywords-3
)
1250 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1253 (put 'idlwave-mode
'font-lock-defaults
1254 idlwave-font-lock-defaults
) ; XEmacs
1256 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1257 "Regexp to match the start of a full-line comment.
1258 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1259 only by whitespace.")
1261 (defconst idlwave-begin-block-reg
1262 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1263 "Regular expression to find the beginning of a block. The case does
1264 not matter. The search skips matches in comments.")
1266 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1267 "Regular expression to find the beginning of a unit. The case does
1270 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1271 "Regular expression to find the line that indicates the end of unit.
1272 This line is the end of buffer or the start of another unit. The case does
1273 not matter. The search skips matches in comments.")
1275 (defconst idlwave-continue-line-reg
"\\<\\$"
1276 "Regular expression to match a continued line.")
1278 (defconst idlwave-end-block-reg
1279 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1280 "Regular expression to find the end of a block. The case does
1281 not matter. The search skips matches found in comments.")
1283 (defconst idlwave-block-matches
1285 ("function" .
"end")
1286 ("case" .
"endcase")
1287 ("else" .
"endelse")
1290 ("repeat" .
"endrep")
1291 ("switch" .
"endswitch")
1292 ("while" .
"endwhile"))
1293 "Matches between statements and the corresponding END variant.
1294 The cars are the reserved words starting a block. If the block really
1295 begins with BEGIN, the cars are the reserved words before the begin
1296 which can be used to identify the block type.
1297 This is used to check for the correct END type, to close blocks and
1298 to expand generic end statements to their detailed form.")
1300 (defconst idlwave-block-match-regexp
1301 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1302 "Regular expression matching reserved words which can stand before
1303 blocks starting with a BEGIN statement. The matches must have associations
1304 `idlwave-block-matches'")
1306 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1307 "Regular expression matching an IDL identifier.")
1309 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1310 "Regular expression matching IDL system variables.")
1312 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1313 "Regular expression matching IDL variable names.")
1315 (defconst idlwave-label
(concat idlwave-identifier
":")
1316 "Regular expression matching IDL labels.")
1318 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1319 "\\(\\s *" idlwave-identifier
"::\\)?"
1322 (defconst idlwave-statement-match
1324 ;; "endif else" is the only possible "end" that can be
1325 ;; followed by a statement on the same line.
1326 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1327 ;; all other "end"s can not be followed by a statement.
1328 (cons 'end
(list idlwave-end-block-reg nil
))
1329 '(if .
("if\\>" "then"))
1330 '(for .
("for\\>" "do"))
1331 '(begin .
("begin\\>" nil
))
1332 '(pdef .
("pro\\>\\|function\\>" nil
))
1333 '(while .
("while\\>" "do"))
1334 '(repeat .
("repeat\\>" "repeat"))
1335 '(goto .
("goto\\>" nil
))
1336 '(case .
("case\\>" nil
))
1337 '(switch .
("switch\\>" nil
))
1338 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1339 "\\(" idlwave-method-call
"\\s *\\)?"
1342 (cons 'call
(list (concat
1343 "\\(" idlwave-method-call
"\\s *\\)?"
1345 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1346 (cons 'assign
(list (concat
1347 "\\(" idlwave-variable
"\\) *=") nil
)))
1349 "Associated list of statement matching regular expressions.
1350 Each regular expression matches the start of an IDL statement. The
1351 first element of each association is a symbol giving the statement
1352 type. The associated value is a list. The first element of this list
1353 is a regular expression matching the start of an IDL statement for
1354 identifying the statement type. The second element of this list is a
1355 regular expression for finding a substatement for the type. The
1356 substatement starts after the end of the found match modulo
1357 whitespace. If it is nil then the statement has no substatement. The
1358 list order matters since matching an assignment statement exactly is
1359 not possible without parsing. Thus assignment statement become just
1360 the leftover unidentified statements containing an equal sign." )
1362 (defvar idlwave-fill-function
'auto-fill-function
1363 "IDL mode auto fill function.")
1365 (defvar idlwave-comment-indent-function
'comment-indent-function
1366 "IDL mode comment indent function.")
1368 ;; Note that this is documented in the v18 manuals as being a string
1369 ;; of length one rather than a single character.
1370 ;; The code in this file accepts either format for compatibility.
1371 (defvar idlwave-comment-indent-char ?\
1372 "Character to be inserted for IDL comment indentation.
1375 (defconst idlwave-continuation-char ?$
1376 "Character which is inserted as a last character on previous line by
1377 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1379 (defconst idlwave-mode-version
"5.5")
1381 (defmacro idlwave-keyword-abbrev
(&rest args
)
1382 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1384 ,(append '(idlwave-check-abbrev) args
))))
1386 ;; If I take the time I can replace idlwave-keyword-abbrev with
1387 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1388 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1389 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1390 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1392 (defmacro idlwave-code-abbrev
(&rest args
)
1393 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1394 Specifically, if the abbrev is in a comment or string it is unexpanded.
1395 Otherwise ARGS forms a list that is evaluated."
1397 ,(prin1-to-string args
) ;; Puts the code in the doc string
1398 (if (idlwave-quoted)
1399 (progn (unexpand-abbrev) nil
)
1402 (defvar idlwave-mode-map
(make-sparse-keymap)
1403 "Keymap used in IDL mode.")
1405 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1406 "Syntax table in use in `idlwave-mode' buffers.")
1408 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
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 ?
\n ">" idlwave-mode-syntax-table
)
1428 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1430 (defvar idlwave-find-symbol-syntax-table
1431 (copy-syntax-table idlwave-mode-syntax-table
)
1432 "Syntax table that treats symbol characters as word characters.")
1434 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
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
)
1439 (defmacro idlwave-with-special-syntax
(&rest body
)
1440 "Execute BODY with a different syntax table."
1441 `(let ((saved-syntax (syntax-table)))
1444 (set-syntax-table idlwave-find-symbol-syntax-table
)
1446 (set-syntax-table saved-syntax
))))
1448 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1449 ; "Execute BODY with a different syntax table."
1450 ; `(let ((saved-syntax (syntax-table)))
1453 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1455 ; (set-syntax-table saved-syntax))))
1457 (defun idlwave-action-and-binding (key cmd
&optional select
)
1458 "KEY and CMD are made into a key binding and an indent action.
1459 KEY is a string - same as for the `define-key' function. CMD is a
1460 function of no arguments or a list to be evaluated. CMD is bound to
1461 KEY in `idlwave-mode-map' by defining an anonymous function calling
1462 `self-insert-command' followed by CMD. If KEY contains more than one
1463 character a binding will only be set if SELECT is 'both.
1465 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1466 replacing any previous value for KEY. If a binding is not set then it
1467 will instead be placed in `idlwave-indent-action-table'.
1469 If the optional argument SELECT is nil then an action and binding are
1470 created. If SELECT is 'noaction, then a binding is always set and no
1471 action is created. If SELECT is 'both then an action and binding
1472 will both be created even if KEY contains more than one character.
1473 Otherwise, if SELECT is non-nil then only an action is created.
1476 No spaces before and 1 after a comma
1477 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1478 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1479 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1480 Capitalize system variables - action only
1481 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1482 (if (not (equal select
'noaction
))
1484 (let* ((table (if select
'idlwave-indent-action-table
1485 'idlwave-indent-expand-table
))
1486 (cell (assoc key
(eval table
))))
1488 ;; Replace action command
1491 (set table
(append (eval table
) (list (cons key cmd
)))))))
1492 ;; Make key binding for action
1493 (if (or (and (null select
) (= (length key
) 1))
1494 (equal select
'noaction
)
1495 (equal select
'both
))
1496 (define-key idlwave-mode-map key
1499 (self-insert-command 1))
1500 (list (if (listp cmd
)
1504 (fset 'idlwave-debug-map
(make-sparse-keymap))
1506 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1507 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1508 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1509 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1510 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1511 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1512 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1513 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1514 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1515 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1516 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1517 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1518 (define-key idlwave-mode-map
"\M-\C-h" 'idlwave-mark-subprogram
)
1519 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1520 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1521 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1522 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1523 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1524 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1525 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1526 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1527 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1528 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1529 (define-key idlwave-mode-map
[(shift tab
)] 'idlwave-indent-statement
)
1530 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1531 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1532 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1533 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1534 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1535 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1536 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1537 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1538 (listp idlwave-shell-debug-modifiers
)
1539 (not (equal idlwave-shell-debug-modifiers
'())))
1540 ;; Bind the debug commands also with the special modifiers.
1541 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1542 (mods-noshift (delq 'shift
1543 (copy-sequence idlwave-shell-debug-modifiers
))))
1544 (define-key idlwave-mode-map
1545 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1546 'idlwave-shell-save-and-run
)
1547 (define-key idlwave-mode-map
1548 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1549 'idlwave-shell-break-here
)
1550 (define-key idlwave-mode-map
1551 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1552 'idlwave-shell-run-region
)))
1553 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1554 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1555 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1556 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1557 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1558 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1559 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1560 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1561 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1562 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1563 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1564 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1565 (autoload 'idlwave-shell
"idlw-shell"
1566 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1567 (autoload 'idlwave-shell-send-command
"idlw-shell")
1568 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1569 "Run `idlwave-shell' and switch back to current window" t
)
1570 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1571 "Save and run buffer under the shell." t
)
1572 (autoload 'idlwave-shell-break-here
"idlw-shell"
1573 "Set breakpoint in current line." t
)
1574 (autoload 'idlwave-shell-run-region
"idlw-shell"
1575 "Compile and run the region." t
)
1576 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1577 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1578 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1579 (define-key idlwave-mode-map
[(control meta ?
\?)] 'idlwave-online-help
)
1580 ;; Pickup both forms of Esc/Meta binding
1581 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1582 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1583 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1584 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1585 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1586 (define-key idlwave-mode-map
1587 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1588 'idlwave-mouse-context-help
)
1590 ;; Set action and key bindings.
1591 ;; See description of the function `idlwave-action-and-binding'.
1592 ;; Automatically add spaces for the following characters
1593 ;(idlwave-action-and-binding "&" '(idlwave-surround -1 -1 '(?&) 1
1594 ; (lambda (char) 0)))
1595 (idlwave-action-and-binding "<" '(idlwave-surround -
1 -
1))
1596 ;; Binding works for both > and ->, by changing the length of the token.
1597 (idlwave-action-and-binding ">" '(idlwave-surround -
1 -
1 '(?-
) 1
1598 'idlwave-gtr-pad-hook
))
1599 (idlwave-action-and-binding "->" '(idlwave-surround -
1 -
1 nil
2) t
)
1600 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1))
1602 ;; Automatically add spaces to equal sign if not keyword
1603 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1608 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1609 ;;; space is inserted (this is the space typed by the user to expanded
1612 (defvar idlwave-mode-abbrev-table nil
1613 "Abbreviation table used for IDLWAVE mode")
1614 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1616 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1617 "Define-abbrev with backward compatibility.
1619 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1620 idlwave-mode-abbrev-table unless TABLE is non-nil."
1621 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1622 (args (list (or table idlwave-mode-abbrev-table
)
1623 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1627 (apply 'define-abbrev
(append args
'(0 t
)))
1628 (error (apply 'define-abbrev args
)))))
1631 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1632 "w" idlwave-mode-syntax-table
)
1638 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1639 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1640 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1641 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1642 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1643 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1644 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1645 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1646 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1648 ;; Keywords, system functions, conversion routines
1650 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1651 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1652 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1653 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1654 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1655 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1656 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1657 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1658 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1659 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1660 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1661 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1662 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1663 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1664 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1665 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1666 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1667 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1668 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1669 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1670 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1671 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1672 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1673 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1675 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1676 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1677 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1678 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1679 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1680 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1681 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1682 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1683 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1684 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1685 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1686 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1687 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1688 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1689 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1690 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1691 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1692 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1694 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1695 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1697 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1698 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1699 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1700 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1702 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1705 ;; This section is reserved words only. (From IDL user manual)
1707 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1708 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1709 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1710 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1711 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1712 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1713 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1714 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1715 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1716 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1717 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1718 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1719 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1720 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1721 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1722 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1723 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1724 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1725 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1726 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1727 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1728 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1729 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1730 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1735 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1736 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1737 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1738 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1739 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1740 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1741 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1742 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1743 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1744 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1745 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1747 (defvar imenu-create-index-function
)
1748 (defvar extract-index-name-function
)
1749 (defvar prev-index-position-function
)
1750 (defvar imenu-extract-index-name-function
)
1751 (defvar imenu-prev-index-position-function
)
1752 ;; defined later - so just make the compiler hush
1753 (defvar idlwave-mode-menu
)
1754 (defvar idlwave-mode-debug-menu
)
1757 (defun idlwave-mode ()
1758 "Major mode for editing IDL source files (version 5.5).
1760 The main features of this mode are
1762 1. Indentation and Formatting
1763 --------------------------
1764 Like other Emacs programming modes, C-j inserts a newline and indents.
1765 TAB is used for explicit indentation of the current line.
1767 To start a continuation line, use \\[idlwave-split-line]. This
1768 function can also be used in the middle of a line to split the line
1769 at that point. When used inside a long constant string, the string
1770 is split at that point with the `+' concatenation operator.
1772 Comments are indented as follows:
1774 `;;;' Indentation remains unchanged.
1775 `;;' Indent like the surrounding code
1776 `;' Indent to a minimum column.
1778 The indentation of comments starting in column 0 is never changed.
1780 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1781 comment. The indentation of the second line of the paragraph
1782 relative to the first will be retained. Use
1783 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1784 comments. When the variable `idlwave-fill-comment-line-only' is
1785 nil, code can also be auto-filled and auto-indented.
1787 To convert pre-existing IDL code to your formatting style, mark the
1788 entire buffer with \\[mark-whole-buffer] and execute
1789 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1790 again followed by \\[indent-region] (`indent-region').
1794 IDLWAVE displays information about the calling sequence and the
1795 accepted keyword parameters of a procedure or function with
1796 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1797 source file of a module. These commands know about system
1798 routines, all routines in idlwave-mode buffers and (when the
1799 idlwave-shell is active) about all modules currently compiled under
1800 this shell. It also makes use of pre-compiled or custom-scanned
1801 user and library catalogs many popular libraries ship with by
1802 default. Use \\[idlwave-update-routine-info] to update this
1803 information, which is also used for completion (see item 4).
1807 \\[idlwave-context-help] displays the IDL documentation relevant
1808 for the system variable, keyword, or routine at point. A single
1809 key stroke gets you directly to the right place in the docs. The
1810 HTML help files package must be installed for this to work -- check
1811 the IDLWAVE webpage for the correct package for your version. See
1812 the manual to configure where and how the HTML help is displayed.
1816 \\[idlwave-complete] completes the names of procedures, functions
1817 class names, keyword parameters, system variables and tags, class
1818 tags, structure tags, filenames and much more. It is context
1819 sensitive and figures out what is expected at point. Lower case
1820 strings are completed in lower case, other strings in mixed or
1823 5. Code Templates and Abbreviations
1824 --------------------------------
1825 Many Abbreviations are predefined to expand to code fragments and templates.
1826 The abbreviations start generally with a `\\`. Some examples
1828 \\pr PROCEDURE template
1829 \\fu FUNCTION template
1830 \\c CASE statement template
1831 \\sw SWITCH statement template
1832 \\f FOR loop template
1833 \\r REPEAT Loop template
1834 \\w WHILE loop template
1835 \\i IF statement template
1836 \\elif IF-ELSE statement template
1839 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1840 have direct keybindings - see the list of keybindings below.
1842 \\[idlwave-doc-header] inserts a documentation header at the
1843 beginning of the current program unit (pro, function or main).
1844 Change log entries can be added to the current program unit with
1845 \\[idlwave-doc-modification].
1847 6. Automatic Case Conversion
1848 -------------------------
1849 The case of reserved words and some abbrevs is controlled by
1850 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1852 7. Automatic END completion
1853 ------------------------
1854 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1855 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1859 Loading idlwave.el runs `idlwave-load-hook'.
1860 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1862 9. Documentation and Customization
1863 -------------------------------
1864 Info documentation for this package is available. Use
1865 \\[idlwave-info] to display (complain to your sysadmin if that does
1866 not work). For Postscript, PDF, and HTML versions of the
1867 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1868 IDLWAVE has customize support - see the group `idlwave'.
1872 Here is a list of all keybindings of this mode.
1873 If some of the key bindings below show with ??, use \\[describe-key]
1874 followed by the key sequence to see what the key sequence does.
1876 \\{idlwave-mode-map}"
1879 (kill-all-local-variables)
1881 (if idlwave-startup-message
1882 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1883 (setq idlwave-startup-message nil
)
1885 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1886 (set-syntax-table idlwave-mode-syntax-table
)
1888 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1890 (make-local-variable idlwave-comment-indent-function
)
1891 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1893 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1894 (set (make-local-variable 'comment-start
) ";")
1895 (set (make-local-variable 'require-final-newline
) t
)
1896 (set (make-local-variable 'abbrev-all-caps
) t
)
1897 (set (make-local-variable 'indent-tabs-mode
) nil
)
1898 (set (make-local-variable 'completion-ignore-case
) t
)
1900 (use-local-map idlwave-mode-map
)
1902 (when (featurep 'easymenu
)
1903 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1904 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1906 (setq mode-name
"IDLWAVE")
1907 (setq major-mode
'idlwave-mode
)
1908 (setq abbrev-mode t
)
1910 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1911 (setq comment-end
"")
1912 (set (make-local-variable 'comment-multi-line
) nil
)
1913 (set (make-local-variable 'paragraph-separate
)
1914 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1915 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1916 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1917 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1919 ;; Set tag table list to use IDLTAGS as file name.
1920 (if (boundp 'tag-table-alist
)
1921 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1923 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1924 ;; Following line is for Emacs - XEmacs uses the corresponding property
1925 ;; on the `idlwave-mode' symbol.
1926 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1929 (set (make-local-variable 'imenu-create-index-function
)
1930 'imenu-default-create-index-function
)
1931 (set (make-local-variable 'imenu-extract-index-name-function
)
1933 (set (make-local-variable 'imenu-prev-index-position-function
)
1934 'idlwave-prev-index-position
)
1936 ;; Make a local post-command-hook and add our hook to it
1937 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1938 (make-local-hook 'post-command-hook
)
1939 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1941 ;; Make local hooks for buffer updates
1942 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1943 (make-local-hook 'kill-buffer-hook
)
1944 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1945 (make-local-hook 'after-save-hook
)
1946 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1947 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1949 ;; Setup directories and file, if necessary
1952 ;; Update the routine info with info about current buffer?
1953 (idlwave-new-buffer-update)
1955 ;; Run the mode hook
1956 (run-hooks 'idlwave-mode-hook
))
1958 (defvar idlwave-setup-done nil
)
1959 (defun idlwave-setup ()
1960 (unless idlwave-setup-done
1961 (if (not (file-directory-p idlwave-config-directory
))
1962 (make-directory idlwave-config-directory
))
1963 (setq idlwave-user-catalog-file
(expand-file-name
1964 idlwave-user-catalog-file
1965 idlwave-config-directory
)
1966 idlwave-path-file
(expand-file-name
1968 idlwave-config-directory
))
1969 (idlwave-read-paths) ; we may need these early
1970 (setq idlwave-setup-done t
)))
1973 ;; Code Formatting ----------------------------------------------------
1976 (defun idlwave-push-mark (&rest rest
)
1977 "Push mark for compatibility with Emacs 18/19."
1978 (if (fboundp 'iconify-frame
)
1979 (apply 'push-mark rest
)
1982 (defun idlwave-hard-tab ()
1983 "Inserts TAB in buffer in current position."
1987 ;;; This stuff is experimental
1989 (defvar idlwave-command-hook nil
1990 "If non-nil, a list that can be evaluated using `eval'.
1991 It is evaluated in the lisp function `idlwave-command-hook' which is
1992 placed in `post-command-hook'.")
1994 (defun idlwave-command-hook ()
1995 "Command run after every command.
1996 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
1997 sets the variable to zero afterwards."
1998 (and idlwave-command-hook
1999 (listp idlwave-command-hook
)
2001 (eval idlwave-command-hook
)
2003 (setq idlwave-command-hook nil
))
2007 ;; It would be better to use expand.el for better abbrev handling and
2010 (defun idlwave-check-abbrev (arg &optional reserved
)
2011 "Reverses abbrev expansion if in comment or string.
2012 Argument ARG is the number of characters to move point
2013 backward if `idlwave-abbrev-move' is non-nil.
2014 If optional argument RESERVED is non-nil then the expansion
2015 consists of reserved words, which will be capitalized if
2016 `idlwave-reserved-word-upcase' is non-nil.
2017 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2018 is non-nil, unless its value is \`down in which case the abbrev will be
2019 made into all lowercase.
2020 Returns non-nil if abbrev is left expanded."
2021 (if (idlwave-quoted)
2022 (progn (unexpand-abbrev)
2024 (if (and reserved idlwave-reserved-word-upcase
)
2025 (upcase-region last-abbrev-location
(point))
2027 ((equal idlwave-abbrev-change-case
'down
)
2028 (downcase-region last-abbrev-location
(point)))
2029 (idlwave-abbrev-change-case
2030 (upcase-region last-abbrev-location
(point)))))
2031 (if (and idlwave-abbrev-move
(> arg
0))
2032 (if (boundp 'post-command-hook
)
2033 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2034 (backward-char arg
)))
2037 (defun idlwave-in-comment ()
2038 "Returns t if point is inside a comment, nil otherwise."
2040 (let ((here (point)))
2041 (and (idlwave-goto-comment) (> here
(point))))))
2043 (defun idlwave-goto-comment ()
2044 "Move to start of comment delimiter on current line.
2045 Moves to end of line if there is no comment delimiter.
2046 Ignores comment delimiters in strings.
2047 Returns point if comment found and nil otherwise."
2048 (let ((eos (progn (end-of-line) (point)))
2051 ;; Look for first comment delimiter not in a string
2053 (setq found
(search-forward comment-start eos
'lim
))
2054 (while (and found
(idlwave-in-quote))
2055 (setq found
(search-forward comment-start eos
'lim
)))
2056 (store-match-data data
)
2057 (and found
(not (idlwave-in-quote))
2062 (defvar transient-mark-mode
)
2063 (defvar zmacs-regions
)
2064 (defvar mark-active
)
2065 (defun idlwave-region-active-p ()
2066 "Is transient-mark-mode on and the region active?
2067 Works on both Emacs and XEmacs."
2068 (if (featurep 'xemacs
)
2069 (and zmacs-regions
(region-active-p))
2070 (and transient-mark-mode mark-active
)))
2072 (defun idlwave-show-matching-quote ()
2073 "Insert quote and show matching quote if this is end of a string."
2075 (let ((bq (idlwave-in-quote))
2076 (inq last-command-char
))
2077 (if (and bq
(not (idlwave-in-comment)))
2078 (let ((delim (char-after bq
)))
2084 ;; Not the end of a string
2087 (defun idlwave-show-begin-check ()
2088 "Ensure that the previous word was a token before `idlwave-show-begin'.
2089 An END token must be preceded by whitespace."
2090 (if (not (idlwave-quoted))
2095 (looking-at "[ \t\n\f]"))
2096 (idlwave-show-begin))))
2098 (defun idlwave-show-begin ()
2099 "Finds the start of current block and blinks to it for a second.
2100 Also checks if the correct end statement has been used."
2101 ;; All end statements are reserved words
2102 ;; Re-indent end line
2103 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2105 (let* ((pos (point-marker))
2106 (last-abbrev-marker (copy-marker last-abbrev-location
))
2107 (eol-pos (save-excursion (end-of-line) (point)))
2108 begin-pos end-pos end end1
)
2109 (if idlwave-reindent-end
(idlwave-indent-line))
2110 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2111 (when (and (idlwave-check-abbrev 0 t
)
2114 ;; Move inside current block
2115 (goto-char last-abbrev-marker
)
2116 (idlwave-block-jump-out -
1 'nomark
)
2117 (setq begin-pos
(point))
2118 (idlwave-block-jump-out 1 'nomark
)
2119 (setq end-pos
(point))
2120 (if (> end-pos eol-pos
)
2123 (setq end
(buffer-substring
2125 (skip-chars-backward "a-zA-Z")
2128 (goto-char begin-pos
)
2129 (when (setq end1
(cdr (idlwave-block-master)))
2131 ((null end1
)) ; no-operation
2132 ((string= (downcase end
) (downcase end1
))
2134 ((string= (downcase end
) "end")
2136 (if idlwave-expand-generic-end
2140 (insert (if (string= end
"END") (upcase end1
) end1
))
2145 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2150 (defun idlwave-block-master ()
2151 (let ((case-fold-search t
))
2154 ((looking-at "pro\\|case\\|switch\\|function\\>")
2155 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2156 ((looking-at "begin\\>")
2157 (let ((limit (save-excursion
2158 (idlwave-beginning-of-statement)
2161 ((re-search-backward ":[ \t]*\\=" limit t
)
2162 ;; seems to be a case thing
2164 ((re-search-backward idlwave-block-match-regexp limit t
)
2165 (assoc (downcase (match-string 1))
2166 idlwave-block-matches
))
2168 ;; Just a normal block
2169 '("begin" .
"end")))))
2172 (defun idlwave-close-block ()
2173 "Terminate the current block with the correct END statement."
2176 ;; Start new line if we are not in a new line
2177 (unless (save-excursion
2178 (skip-chars-backward " \t")
2180 (let ((idlwave-show-block nil
))
2181 (newline-and-indent)))
2182 (let ((last-abbrev-location (point))) ; for upcasing
2184 (idlwave-show-begin)))
2186 (defun idlwave-gtr-pad-hook (char)
2187 "Let the > symbol expand around -> if present. The new token length
2191 (defun idlwave-surround (&optional before after escape-chars length ec-hook
)
2192 "Surround the LENGTH characters before point with blanks.
2193 LENGTH defaults to 1.
2194 Optional arguments BEFORE and AFTER affect the behavior before and
2195 after the characters (see also description of `idlwave-make-space'):
2199 integer > 0 force exactly n spaces
2200 integer < 0 at least |n| spaces
2202 The function does nothing if any of the following conditions is true:
2203 - `idlwave-surround-by-blank' is nil
2204 - the character before point is inside a string or comment
2205 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2206 This hack is used to avoid padding of `>' when it is part of
2207 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2209 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2210 the named function will be called with a single argument of the
2211 preceeding character. Then idlwave-surround will run as usual if
2212 EC-HOOK returns non-nil, and a new length will be taken from the
2214 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2215 (let* ((length (or length
1)) ; establish a default for LENGTH
2216 (prev-char (char-after (- (point) (1+ length
)))))
2217 (when (or (not (memq prev-char escape-chars
))
2218 (and (fboundp ec-hook
)
2220 (save-excursion (funcall ec-hook prev-char
)))))
2221 (backward-char length
)
2223 (let ((here (point)))
2224 (skip-chars-backward " \t")
2226 ;; avoid clobbering indent
2228 (move-to-column (idlwave-calculate-indent))
2229 (if (<= (point) here
)
2230 (narrow-to-region (point) here
))
2232 (idlwave-make-space before
))
2233 (skip-chars-forward " \t"))
2234 (forward-char length
)
2235 (idlwave-make-space after
)
2236 ;; Check to see if the line should auto wrap
2237 (if (and (equal (char-after (1- (point))) ?\
)
2238 (> (current-column) fill-column
))
2239 (funcall auto-fill-function
))))))
2241 (defun idlwave-make-space (n)
2242 "Make space at point.
2243 The space affected is all the spaces and tabs around point.
2244 If n is non-nil then point is left abs(n) spaces from the beginning of
2245 the contiguous space.
2246 The amount of space at point is determined by N.
2247 If the value of N is:
2249 > 0 - exactly N spaces.
2250 < 0 - a minimum of -N spaces, i.e., do not change if there are
2252 0 - no spaces (i.e. remove any existing space)."
2255 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2257 (end-col (progn (skip-chars-forward " \t") (current-column))))
2258 (delete-horizontal-space)
2261 (idlwave-indent-to (+ start-col n
))
2262 (goto-char (+ left n
)))
2264 (idlwave-indent-to end-col
(- n
))
2265 (goto-char (- left n
)))
2269 (defun idlwave-newline ()
2270 "Inserts a newline and indents the current and previous line."
2273 ;; Handle unterminated single and double quotes
2274 ;; If not in a comment and in a string then insertion of a newline
2275 ;; will mean unbalanced quotes.
2277 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2279 (message "Warning: unbalanced quotes?")))
2282 ;; The current line is being split, the cursor should be at the
2283 ;; beginning of the new line skipping the leading indentation.
2285 ;; The reason we insert the new line before indenting is that the
2286 ;; indenting could be confused by keywords (e.g. END) on the line
2287 ;; after the split point. This prevents us from just using
2288 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2290 (beginning-of-line 0)
2291 (idlwave-indent-line)
2293 (idlwave-indent-line))
2296 ;; Use global variable 'comment-column' to set parallel comment
2298 ;; Modeled on lisp.el
2299 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2300 (defun idlwave-comment-hook ()
2301 "Compute indent for the beginning of the IDL comment delimiter."
2302 (if (or (looking-at idlwave-no-change-comment
)
2303 (if idlwave-begin-line-comment
2304 (looking-at idlwave-begin-line-comment
)
2307 (if (looking-at idlwave-code-comment
)
2308 (if (save-excursion (skip-chars-backward " \t") (bolp))
2309 ;; On line by itself, indent as code
2310 (let ((tem (idlwave-calculate-indent)))
2311 (if (listp tem
) (car tem
) tem
))
2312 ;; after code - do not change
2314 (skip-chars-backward " \t")
2315 (max (if (bolp) 0 (1+ (current-column)))
2318 (defun idlwave-split-line ()
2319 "Continue line by breaking line at point and indent the lines.
2320 For a code line insert continuation marker. If the line is a line comment
2321 then the new line will contain a comment with the same indentation.
2322 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2325 ;; Expand abbreviation, just like normal RET would.
2326 (and abbrev-mode
(expand-abbrev))
2328 (if (not (idlwave-in-comment))
2329 ;; For code line add continuation.
2330 ;; Check if splitting a string.
2332 (if (setq beg
(idlwave-in-quote))
2333 (if idlwave-split-line-string
2334 ;; Split the string.
2335 (progn (insert (setq beg
(char-after beg
)) " + "
2336 idlwave-continuation-char beg
)
2338 (newline-and-indent)
2340 ;; Do not split the string.
2342 (message "Warning: continuation inside string!!")
2343 (insert " " idlwave-continuation-char
))
2344 ;; Not splitting a string.
2345 (if (not (member (char-before) '(?\ ?
\t)))
2347 (insert idlwave-continuation-char
)
2348 (newline-and-indent)))
2349 (indent-new-comment-line))
2350 ;; Indent previous line
2351 (setq beg
(- (point-max) (point)))
2353 (idlwave-indent-line)
2354 (goto-char (- (point-max) beg
))
2355 ;; Reindent new line
2356 (idlwave-indent-line)))
2358 (defun idlwave-beginning-of-subprogram ()
2359 "Moves point to the beginning of the current program unit."
2361 (idlwave-find-key idlwave-begin-unit-reg -
1))
2363 (defun idlwave-end-of-subprogram ()
2364 "Moves point to the start of the next program unit."
2366 (idlwave-end-of-statement)
2367 (idlwave-find-key idlwave-end-unit-reg
1))
2369 (defun idlwave-mark-statement ()
2370 "Mark current IDL statement."
2372 (idlwave-end-of-statement)
2373 (let ((end (point)))
2374 (idlwave-beginning-of-statement)
2375 (idlwave-push-mark end nil t
)))
2377 (defun idlwave-mark-block ()
2378 "Mark containing block."
2380 (idlwave-end-of-statement)
2381 (idlwave-backward-up-block -
1)
2382 (idlwave-end-of-statement)
2383 (let ((end (point)))
2384 (idlwave-backward-block)
2385 (idlwave-beginning-of-statement)
2386 (idlwave-push-mark end nil t
)))
2389 (defun idlwave-mark-subprogram ()
2390 "Put mark at beginning of program, point at end.
2391 The marks are pushed."
2393 (idlwave-end-of-statement)
2394 (idlwave-beginning-of-subprogram)
2395 (let ((beg (point)))
2396 (idlwave-forward-block)
2397 (idlwave-push-mark beg nil t
))
2398 (exchange-point-and-mark))
2400 (defun idlwave-backward-up-block (&optional arg
)
2401 "Move to beginning of enclosing block if prefix ARG >= 0.
2402 If prefix ARG < 0 then move forward to enclosing block end."
2404 (idlwave-block-jump-out (- arg
) 'nomark
))
2406 (defun idlwave-beginning-of-block ()
2407 "Go to the beginning of the current block."
2409 (idlwave-block-jump-out -
1 'nomark
)
2412 (defun idlwave-end-of-block ()
2413 "Go to the beginning of the current block."
2415 (idlwave-block-jump-out 1 'nomark
)
2418 (defun idlwave-forward-block ()
2419 "Move across next nested block."
2421 (if (idlwave-down-block 1)
2422 (idlwave-block-jump-out 1 'nomark
)))
2424 (defun idlwave-backward-block ()
2425 "Move backward across previous nested block."
2427 (if (idlwave-down-block -
1)
2428 (idlwave-block-jump-out -
1 'nomark
)))
2430 (defun idlwave-down-block (&optional arg
)
2432 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2433 Returns non-nil if successfull."
2438 (let ((eos (save-excursion
2439 (idlwave-block-jump-out -
1 'nomark
)
2441 (if (setq status
(idlwave-find-key
2442 idlwave-end-block-reg -
1 'nomark eos
))
2443 (idlwave-beginning-of-statement)
2444 (message "No nested block before beginning of containing block.")))
2446 (let ((eos (save-excursion
2447 (idlwave-block-jump-out 1 'nomark
)
2449 (if (setq status
(idlwave-find-key
2450 idlwave-begin-block-reg
1 'nomark eos
))
2451 (idlwave-end-of-statement)
2452 (message "No nested block before end of containing block."))))
2455 (defun idlwave-mark-doclib ()
2456 "Put point at beginning of doc library header, mark at end.
2457 The marks are pushed."
2461 (goto-char (point-max))
2462 (if (re-search-backward idlwave-doclib-start nil t
)
2464 (setq beg
(progn (beginning-of-line) (point)))
2465 (if (re-search-forward idlwave-doclib-end nil t
)
2468 (idlwave-push-mark beg nil t
)
2469 (message "Could not find end of doc library header.")))
2470 (message "Could not find doc library header start.")
2471 (goto-char here
)))))
2474 (defun idlwave-current-routine ()
2475 "Return (NAME TYPE CLASS) of current routine."
2478 (idlwave-beginning-of-subprogram)
2479 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2480 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2482 (class (idlwave-sintern-class (match-string 3)))
2483 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2484 (list name type class
)))))
2486 (defvar idlwave-shell-prompt-pattern
)
2487 (defun idlwave-beginning-of-statement ()
2488 "Move to beginning of the current statement.
2489 Skips back past statement continuations.
2490 Point is placed at the beginning of the line whether or not this is an
2494 ((eq major-mode
'idlwave-shell-mode
)
2495 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2496 (goto-char (match-end 0))))
2498 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2499 (idlwave-previous-statement)
2500 (beginning-of-line)))))
2502 (defun idlwave-previous-statement ()
2503 "Moves point to beginning of the previous statement.
2504 Returns t if the current line before moving is the beginning of
2505 the first non-comment statement in the file, and nil otherwise."
2507 (let (first-statement)
2508 (if (not (= (forward-line -
1) 0))
2509 ;; first line in file
2511 ;; skip blank lines, label lines, include lines and line comments
2513 ;; The current statement is the first statement until we
2514 ;; reach another statement.
2515 (setq first-statement
2517 (looking-at idlwave-comment-line-start-skip
)
2518 (looking-at "[ \t]*$")
2519 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2521 (= (forward-line -
1) 0)))
2522 ;; skip continuation lines
2526 (idlwave-is-continuation-line))
2527 (= (forward-line -
1) 0)))
2530 (defun idlwave-end-of-statement ()
2531 "Moves point to the end of the current IDL statement.
2532 If not in a statement just moves to end of line. Returns position."
2534 (while (and (idlwave-is-continuation-line)
2535 (= (forward-line 1) 0))
2536 (while (and (idlwave-is-comment-or-empty-line)
2537 (= (forward-line 1) 0))))
2541 (defun idlwave-end-of-statement0 ()
2542 "Moves point to the end of the current IDL statement.
2543 If not in a statement just moves to end of line. Returns position."
2545 (while (and (idlwave-is-continuation-line)
2546 (= (forward-line 1) 0)))
2550 (defun idlwave-next-statement ()
2551 "Moves point to beginning of the next IDL statement.
2552 Returns t if that statement is the last
2553 non-comment IDL statement in the file, and nil otherwise."
2555 (let (last-statement)
2556 (idlwave-end-of-statement)
2557 ;; skip blank lines, label lines, include lines and line comments
2558 (while (and (= (forward-line 1) 0)
2559 ;; The current statement is the last statement until
2560 ;; we reach a new statement.
2561 (setq last-statement
2563 (looking-at idlwave-comment-line-start-skip
)
2564 (looking-at "[ \t]*$")
2565 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2566 (looking-at "^@")))))
2569 (defun idlwave-skip-multi-commands (&optional lim
)
2570 "Skip past multiple commands on a line (with `&')."
2571 (let ((save-point (point)))
2572 (when (re-search-forward ".*&" lim t
)
2573 (goto-char (match-end 0))
2574 (if (idlwave-quoted) (goto-char save-point
)))
2577 (defun idlwave-skip-label-or-case ()
2578 "Skip label or case statement element.
2579 Returns position after label.
2580 If there is no label point is not moved and nil is returned."
2581 ;; Case expressions and labels are terminated by a colon.
2582 ;; So we find the first colon in the line and make sure
2583 ;; - no `?' is before it (might be a ? b : c)
2584 ;; - it is not in a comment
2585 ;; - not in a string constant
2586 ;; - not in parenthesis (like a[0:3])
2587 ;; - not followed by another ":" in explicit class, ala a->b::c
2588 ;; As many in this mode, this function is heuristic and not an exact
2590 (let* ((start (point))
2591 (eos (save-excursion (idlwave-end-of-statement) (point)))
2592 (end (idlwave-find-key ":" 1 'nomark eos
)))
2594 (= (nth 0 (parse-partial-sexp start end
)) 0)
2595 (not (string-match "\\?" (buffer-substring start end
)))
2596 (not (string-match "^::" (buffer-substring end eos
))))
2603 (defun idlwave-start-of-substatement (&optional pre
)
2604 "Move to start of next IDL substatement after point.
2605 Uses the type of the current IDL statement to determine if the next
2606 statement is on a new line or is a subpart of the current statement.
2607 Returns point at start of substatement modulo whitespace.
2608 If optional argument is non-nil move to beginning of current
2610 (let ((orig (point))
2611 (eos (idlwave-end-of-statement))
2614 (idlwave-beginning-of-statement)
2615 (idlwave-skip-label-or-case)
2616 (if (< (point) orig
)
2617 (idlwave-skip-multi-commands orig
))
2619 ;; Continue looking for substatements until we are past orig
2620 (while (and (<= (point) orig
) (not (eobp)))
2622 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2623 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2625 (idlwave-find-key nst
1 'nomark eos
))
2626 (goto-char (match-end 0)))
2627 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2628 (setq ifnest
(1- ifnest
))
2629 (goto-char (match-end 0)))
2631 (idlwave-next-statement))))
2632 (if pre
(goto-char last
))
2633 ;; If a continuation line starts here, move to next line
2634 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2635 (beginning-of-line 2))
2638 (defun idlwave-statement-type ()
2639 "Return the type of the current IDL statement.
2640 Uses `idlwave-statement-match' to return a cons of (type . point) with
2641 point the ending position where the type was determined. Type is the
2642 association from `idlwave-statement-match', i.e. the cons cell from the
2643 list not just the type symbol. Returns nil if not an identifiable
2646 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2647 ;; and possibly comments
2648 (while (looking-at "[ \t]*\\$")
2650 (skip-chars-forward " \t")
2651 (let ((st idlwave-statement-match
)
2652 (case-fold-search t
))
2653 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2654 (setq st
(cdr st
))))
2656 (append st
(match-end 0))))))
2658 (defun idlwave-expand-equal (&optional before after
)
2659 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2660 assignment. Which case is determined using
2661 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2662 equal sign will be surrounded by BEFORE and AFTER blanks. If
2663 `idlwave-pad-keyword' is t then keyword assignment is treated just
2664 like assignment statements. When nil, spaces are removed for keyword
2665 assignment. Any other value keeps the current space around the `='.
2666 Limits in for loops are treated as keyword assignment.
2668 Starting with IDL 6.0, a number of op= assignments are available.
2669 Since ambiguities of the form:
2674 can occur, alphanumeric operator assignment will never be pre-padded,
2675 only post-padded. You must use a space before these to disambiguate
2676 \(not just for padding, but for proper parsing by IDL too!). Other
2677 operators, such as ##=, ^=, etc., will be pre-padded.
2679 See `idlwave-surround'."
2680 (if idlwave-surround-by-blank
2682 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2684 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2688 (let ((case-fold-search t
))
2691 (re-search-backward non-an-ops nil t
)
2692 ;; Why doesn't ##? work for both?
2693 (re-search-backward "\\(#\\)\\=" nil t
))
2694 (setq len
(1+ (length (match-string 1))))
2695 (when (re-search-backward an-ops nil t
)
2696 (setq begin nil
) ; won't modify begin
2697 (setq len
(1+ (length (match-string 1))))))))
2699 (if (eq t idlwave-pad-keyword
)
2700 ;; Everything gets padded equally
2701 (idlwave-surround before after nil len
)
2702 ;; Treating keywords/for variables specially...
2703 (let ((st (save-excursion ; To catch "for" variables
2704 (idlwave-start-of-substatement t
)
2705 (idlwave-statement-type)))
2706 (what (save-excursion ; To catch keywords
2707 (skip-chars-backward "= \t")
2708 (nth 2 (idlwave-where)))))
2709 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2710 (memq (caar st
) '(for pdef
)))
2712 ((null idlwave-pad-keyword
)
2713 (idlwave-surround 0 0)
2715 (t))) ; leave any spaces alone
2716 (t (idlwave-surround before after nil len
))))))))
2719 (defun idlwave-indent-and-action (&optional arg
)
2720 "Call `idlwave-indent-line' and do expand actions.
2721 With prefix ARG non-nil, indent the entire sub-statement."
2724 (if (and idlwave-expand-generic-end
2725 (re-search-backward "\\<\\(end\\)\\s-*\\="
2726 (max 0 (- (point) 10)) t
)
2727 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2728 (progn (goto-char (match-end 1))
2729 ;;Expand the END abbreviation, just as RET or Space would have.
2730 (if abbrev-mode
(expand-abbrev)
2731 (idlwave-show-begin)))))
2732 (when (and (not arg
) current-prefix-arg
)
2733 (setq arg current-prefix-arg
)
2734 (setq current-prefix-arg nil
))
2736 (idlwave-indent-statement)
2737 (idlwave-indent-line t
)))
2739 (defun idlwave-indent-line (&optional expand
)
2740 "Indents current IDL line as code or as a comment.
2741 The actions in `idlwave-indent-action-table' are performed.
2742 If the optional argument EXPAND is non-nil then the actions in
2743 `idlwave-indent-expand-table' are performed."
2745 ;; Move point out of left margin.
2747 (skip-chars-backward " \t")
2749 (skip-chars-forward " \t"))
2750 (let ((mloc (point-marker)))
2753 (if (looking-at idlwave-comment-line-start-skip
)
2754 ;; Indentation for a line comment
2756 (skip-chars-forward " \t")
2757 (idlwave-indent-left-margin (idlwave-comment-hook)))
2761 ;; Before indenting, run action routines.
2763 (if (and expand idlwave-do-actions
)
2764 (mapcar 'idlwave-do-action idlwave-indent-expand-table
))
2766 (if idlwave-do-actions
2767 (mapcar 'idlwave-do-action idlwave-indent-action-table
))
2769 ;; No longer expand abbrevs on the line. The user can do this
2770 ;; manually using expand-region-abbrevs.
2772 ;; Indent for code line
2777 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2779 (looking-at "^[ \t]*@"))
2783 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2784 ;; Adjust parallel comment
2786 (if (idlwave-in-comment)
2787 ;; Emacs 21 is too smart with fill-column on comment indent
2788 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2791 (indent-for-comment)))))
2793 ;; Get rid of marker
2794 (set-marker mloc nil
)))
2796 (defun idlwave-do-action (action)
2797 "Perform an action repeatedly on a line.
2798 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2799 either a function name to be called with `funcall' or a list to be
2800 evaluated with `eval'. The action performed by FUNC should leave point
2801 after the match for REG - otherwise an infinite loop may be entered."
2802 (let ((action-key (car action
))
2803 (action-routine (cdr action
)))
2805 (while (idlwave-look-at action-key
)
2806 (if (listp action-routine
)
2807 (eval action-routine
)
2808 (funcall action-routine
)))))
2810 (defun idlwave-indent-to (col &optional min
)
2811 "Indent from point with spaces until column COL.
2812 Inserts space before markers at point."
2813 (if (not min
) (setq min
0))
2814 (insert-before-markers
2815 (make-string (max min
(- col
(current-column))) ?\
)))
2817 (defun idlwave-indent-left-margin (col)
2818 "Indent the current line to column COL.
2819 Indents such that first non-whitespace character is at column COL
2820 Inserts spaces before markers at point."
2823 (delete-horizontal-space)
2824 (idlwave-indent-to col
)))
2826 (defun idlwave-indent-subprogram ()
2827 "Indents program unit which contains point."
2830 (idlwave-end-of-statement)
2831 (idlwave-beginning-of-subprogram)
2832 (let ((beg (point)))
2833 (idlwave-forward-block)
2834 (message "Indenting subprogram...")
2835 (indent-region beg
(point) nil
))
2836 (message "Indenting subprogram...done.")))
2838 (defun idlwave-indent-statement ()
2839 "Indent current statement, including all continuation lines."
2842 (idlwave-beginning-of-statement)
2843 (let ((beg (point)))
2844 (idlwave-end-of-statement)
2845 (indent-region beg
(point) nil
))))
2847 (defun idlwave-calculate-indent ()
2848 "Return appropriate indentation for current line as IDL code."
2852 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2854 ((idlwave-look-at idlwave-begin-unit-reg
)
2856 ;; Check for continuation line
2858 (and (= (forward-line -
1) 0)
2859 (idlwave-is-continuation-line)))
2860 (idlwave-calculate-cont-indent))
2861 ;; calculate indent based on previous and current statements
2862 (t (let* (beg-prev-pos
2864 ;; calculate indent based on previous statement
2867 ;; Beginning of file
2869 (idlwave-previous-statement)
2870 (setq beg-prev-pos
(point)))
2873 ((idlwave-look-at idlwave-begin-unit-reg t
)
2874 (+ (idlwave-current-statement-indent)
2875 idlwave-main-block-indent
))
2877 ((idlwave-look-at idlwave-begin-block-reg t
)
2878 (+ (idlwave-min-current-statement-indent)
2879 idlwave-block-indent
))
2881 ((idlwave-look-at idlwave-end-block-reg t
)
2883 ;; Match to the *beginning* of the block opener
2884 (goto-char beg-prev-pos
)
2885 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2886 (idlwave-min-current-statement-indent)))
2887 ;; idlwave-end-offset
2888 ;; idlwave-block-indent))
2890 ;; Default to current indent
2891 ((idlwave-current-statement-indent))))))
2892 ;; adjust the indentation based on the current statement
2895 ((idlwave-look-at idlwave-end-block-reg
)
2896 (+ the-indent idlwave-end-offset
))
2900 ;; Parentheses indent
2903 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2904 "Calculate the continuation indent inside a paren group.
2905 Returns a cons-cell with (open . indent), where open is the
2906 location of the open paren"
2907 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2908 ;; Found an innermost open paren.
2911 ;; Line up with next word unless this is a closing paren.
2914 ;; Plain Kernighan-style nested indent
2915 (idlwave-indent-parens-nested
2916 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2918 ;; This is a closed paren - line up under open paren.
2922 ;; Empty (or just comment) follows -- revert to basic indent
2926 (looking-at "[ \t$]*\\(;.*\\)?$"))
2929 ;; Line up with first word after any blank space
2931 (skip-chars-forward " \t")
2932 (current-column))))))))
2934 (defun idlwave-calculate-cont-indent ()
2935 "Calculates the IDL continuation indent column from the previous
2936 statement. Note that here previous statement usually means the
2937 beginning of the current statement if this statement is a continuation
2938 of the previous line. Various special types of continuations,
2939 including assignments, routine definitions, and parenthetical
2940 groupings, are treated separately."
2942 (let* ((case-fold-search t
)
2943 (end-reg (progn (beginning-of-line) (point)))
2944 (beg-last-statement (save-excursion (idlwave-previous-statement)
2946 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
2947 (if (eq (line-beginning-position) end-reg
)
2948 (goto-char beg-last-statement
)
2950 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
2951 idlwave-continuation-indent
))
2952 fancy-nonparen-indent fancy-paren-indent
)
2954 ;; Align then with its matching if, etc.
2955 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
2956 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
2957 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
2958 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2960 ("\\<case\\>" .
"[ \t]*of")))
2966 (while (setq match
(car matchers
))
2967 (if (looking-at (cdr match
))
2968 (throw 'exit
(car match
)))
2969 (setq matchers
(cdr matchers
)))))
2970 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
2971 (if (looking-at "end") ;; that one's special
2972 (- (idlwave-current-indent)
2973 (+ idlwave-block-indent idlwave-end-offset
))
2974 (idlwave-current-indent)))
2976 ;; Indent in from the previous line for continuing statements
2977 ((let ((matchers '("\\<then\\>"
2984 (if (/= (forward-line -
1) 0)
2986 (while (setq match
(car matchers
))
2987 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
2990 (setq matchers
(cdr matchers
)))))
2991 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2993 ;; Parenthetical indent, either traditional or Kernighan style
2994 ((setq fancy-paren-indent
2995 (let* ((end-reg end-reg
)
2998 (skip-chars-forward " \t")
2999 (looking-at "\\s)")))
3002 (while (setq indent-cons
(idlwave-calculate-paren-indent
3003 beg-reg end-reg close-exp
))
3004 ;; First permitted containing paren
3006 idlwave-indent-to-open-paren
3007 idlwave-indent-parens-nested
3008 (null (cdr indent-cons
))
3009 (< (- (cdr indent-cons
) basic-indent
)
3010 idlwave-max-extra-continuation-indent
))
3011 (throw 'loop
(cdr indent-cons
)))
3012 (setq end-reg
(car indent-cons
))))))
3015 ;; A continued assignment, or procedure call/definition
3017 (> idlwave-max-extra-continuation-indent
0)
3018 (setq fancy-nonparen-indent
3021 (while (idlwave-look-at "&")) ; skip continued statements
3023 ;; A continued Procedure call or definition
3025 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3026 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3027 (goto-char (match-end 0))
3028 ;; Comment only, or blank line with "$"? Basic indent.
3029 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3033 ;; Continued assignment (with =):
3035 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3036 (goto-char (match-end 0))
3037 (if (null (idlwave-what-function beg-reg
))
3038 (throw 'assign t
))))
3041 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3043 (goto-char beg-last-statement
)
3044 (eq (caar (idlwave-statement-type)) 'for
)))
3045 (current-column))))))
3046 (< (- fancy-nonparen-indent basic-indent
)
3047 idlwave-max-extra-continuation-indent
))
3048 (if fancy-paren-indent
;calculated but disallowed paren indent
3049 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3050 fancy-nonparen-indent
))
3052 ;; Basic indent, by default
3053 (t basic-indent
)))))
3057 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3058 "Move to next match of the regular expression KEY-RE.
3059 Matches inside comments or string constants will be ignored.
3060 If DIR is negative, the search will be backwards.
3061 At a successful match, the mark is pushed unless NOMARK is non-nil.
3062 Searches are limited to LIMIT.
3063 Searches are case-insensitive and use a special syntax table which
3064 treats `$' and `_' as word characters.
3065 Return value is the beginning of the match or (in case of failure) nil."
3066 (setq dir
(or dir
0))
3067 (let ((case-fold-search t
)
3068 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3070 (idlwave-with-special-syntax
3073 (while (funcall search-func key-re limit t
)
3074 (if (not (idlwave-quoted))
3075 (throw 'exit
(setq found
(match-beginning 0)))
3076 (if (or (and (> dir
0) (eobp))
3077 (and (< dir
0) (bobp)))
3078 (throw 'exit nil
)))))))
3081 (if (not nomark
) (push-mark))
3086 (defun idlwave-block-jump-out (&optional dir nomark
)
3087 "When optional argument DIR is non-negative, move forward to end of
3088 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3089 regular expressions. When DIR is negative, move backwards to block beginning.
3090 Recursively calls itself to skip over nested blocks. DIR defaults to
3091 forward. Calls `push-mark' unless the optional argument NOMARK is
3092 non-nil. Movement is limited by the start of program units because of
3093 possibility of unbalanced blocks."
3095 (or dir
(setq dir
0))
3096 (let* ((here (point))
3097 (case-fold-search t
)
3098 (limit (if (>= dir
0) (point-max) (point-min)))
3099 (block-limit (if (>= dir
0)
3100 idlwave-begin-block-reg
3101 idlwave-end-block-reg
))
3103 (block-reg (concat idlwave-begin-block-reg
"\\|"
3104 idlwave-end-block-reg
))
3105 (unit-limit (or (save-excursion
3108 idlwave-begin-unit-reg dir t limit
)
3111 idlwave-end-unit-reg dir t limit
)))
3113 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3114 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3115 (while (and found
(looking-at block-limit
))
3116 (if (>= dir
0) (forward-word 1))
3117 (idlwave-block-jump-out dir t
)
3118 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3119 (if (not nomark
) (push-mark here
))
3120 (if (not found
) (goto-char unit-limit
)
3121 (if (>= dir
0) (forward-word 1)))))
3123 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3124 "The minimum indent in the current statement."
3125 (idlwave-beginning-of-statement)
3126 (if (not (idlwave-is-continuation-line))
3127 (idlwave-current-indent)
3128 (let ((min (idlwave-current-indent)) comm-or-empty
)
3129 (while (and (= (forward-line 1) 0)
3130 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3131 (idlwave-is-continuation-line))
3132 (or (null end-reg
) (< (point) end-reg
)))
3133 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3134 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3136 (min min
(idlwave-current-indent))))))
3138 (defun idlwave-current-statement-indent (&optional last-line
)
3139 "Return indentation of the current statement.
3140 If in a statement, moves to beginning of statement before finding indent."
3142 (idlwave-end-of-statement)
3143 (idlwave-beginning-of-statement))
3144 (idlwave-current-indent))
3146 (defun idlwave-current-indent ()
3147 "Return the column of the indentation of the current line.
3148 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3151 (skip-chars-forward " \t")
3152 ;; if we are at the end of blank line return 0
3154 ((current-column)))))
3156 (defun idlwave-is-continuation-line ()
3157 "Tests if current line is continuation line.
3158 Blank or comment-only lines following regular continuation lines (with
3159 `$') count as continuations too."
3162 (idlwave-look-at "\\<\\$")
3164 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3165 (eq (forward-line -
1) 0))
3166 (if (idlwave-look-at "\\<\\$") (throw 'loop t
)))))))
3168 (defun idlwave-is-comment-line ()
3169 "Tests if the current line is a comment line."
3171 (beginning-of-line 1)
3172 (looking-at "[ \t]*;")))
3174 (defun idlwave-is-comment-or-empty-line ()
3175 "Tests if the current line is a comment line."
3177 (beginning-of-line 1)
3178 (looking-at "[ \t]*[;\n]")))
3180 (defun idlwave-look-at (regexp &optional cont beg
)
3181 "Searches current line from current point for REGEXP.
3182 If optional argument CONT is non-nil, searches to the end of
3183 the current statement.
3184 If optional arg BEG is non-nil, search starts from the beginning of the
3186 Ignores matches that end in a comment or inside a string expression.
3187 Returns point if successful, nil otherwise.
3188 This function produces unexpected results if REGEXP contains quotes or
3189 a comment delimiter. The search is case insensitive.
3190 If successful leaves point after the match, otherwise, does not move point."
3191 (let ((here (point))
3192 (case-fold-search t
)
3193 (eos (save-excursion
3194 (if cont
(idlwave-end-of-statement) (end-of-line))
3197 (idlwave-with-special-syntax
3198 (if beg
(idlwave-beginning-of-statement))
3199 (while (and (setq found
(re-search-forward regexp eos t
))
3201 (if (not found
) (goto-char here
))
3204 (defun idlwave-fill-paragraph (&optional nohang
)
3205 "Fills paragraphs in comments.
3206 A paragraph is made up of all contiguous lines having the same comment
3207 leader (the leading whitespace before the comment delimiter and the
3208 comment delimiter). In addition, paragraphs are separated by blank
3209 line comments. The indentation is given by the hanging indent of the
3210 first line, otherwise by the minimum indentation of the lines after
3211 the first line. The indentation of the first line does not change.
3212 Does not effect code lines. Does not fill comments on the same line
3213 with code. The hanging indent is given by the end of the first match
3214 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3215 optional argument NOHANG is non-nil then the hanging indent is
3218 ;; check if this is a line comment
3221 (skip-chars-forward " \t")
3222 (looking-at comment-start
))
3225 pre here diff fill-prefix-reg bcl first-indent
3227 ;; Change tabs to spaces in the surrounding paragraph.
3228 ;; The surrounding paragraph will be the largest containing block of
3229 ;; contiguous line comments. Thus, we may be changing tabs in
3230 ;; a much larger area than is needed, but this is the easiest
3231 ;; brute force way to do it.
3233 ;; This has the undesirable side effect of replacing the tabs
3234 ;; permanently without the user's request or knowledge.
3236 (backward-paragraph)
3237 (setq start
(point)))
3241 (untabify start end
)
3247 (concat "^[ \t]*" comment-start
"+")
3248 (save-excursion (end-of-line) (point))
3250 ;; Get the comment leader on the line and its length
3251 (setq pre
(current-column))
3252 ;; the comment leader is the indentation plus exactly the
3253 ;; number of consecutive ";".
3254 (setq fill-prefix-reg
3258 (buffer-substring (save-excursion
3259 (beginning-of-line) (point))
3263 ;; Mark the beginning and end of the paragraph
3265 (while (and (looking-at fill-prefix-reg
)
3266 (not (looking-at paragraph-separate
))
3269 ;; Move to first line of paragraph
3270 (if (/= (point) bcl
)
3272 (setq start
(point))
3274 (while (and (looking-at fill-prefix-reg
)
3275 (not (looking-at paragraph-separate
))
3279 (if (or (not (looking-at fill-prefix-reg
))
3280 (looking-at paragraph-separate
))
3283 ;; if at end of buffer add a newline (need this because
3284 ;; fill-region needs END to be at the beginning of line after
3285 ;; the paragraph or it will add a line).
3287 (progn (insert ?
\n) (backward-char 1)))
3288 ;; Set END to the beginning of line after the paragraph
3289 ;; END is calculated as distance from end of buffer
3290 (setq end
(- (point-max) (point) 1))
3292 ;; Calculate the indentation for the paragraph.
3294 ;; In the following while statements, after one iteration
3295 ;; point will be at the beginning of a line in which case
3296 ;; the while will not be executed for the
3297 ;; the first paragraph line and thus will not affect the
3300 ;; First check to see if indentation is based on hanging indent.
3301 (if (and (not nohang
) idlwave-hanging-indent
3305 (idlwave-calc-hanging-indent))))
3306 ;; Adjust lines of paragraph by inserting spaces so that
3307 ;; each line's indent is at least as great as the hanging
3308 ;; indent. This is needed for fill-paragraph to work with
3313 (while (> (point) start
)
3314 (re-search-forward comment-start-skip
3315 (save-excursion (end-of-line) (point))
3317 (if (> (setq diff
(- indent
(current-column))) 0)
3319 (if (>= here
(point))
3320 ;; adjust the original location for the
3322 (setq here
(+ here diff
)))
3323 (insert (make-string diff ?\
))))
3327 ;; No hang. Instead find minimum indentation of paragraph
3328 ;; after first line.
3329 ;; For the following while statement, since START is at the
3330 ;; beginning of line and END is at the end of line
3331 ;; point is greater than START at least once (which would
3332 ;; be the case for a single line paragraph).
3333 (while (> (point) start
)
3340 (save-excursion (end-of-line) (point))
3345 (setq fill-prefix
(concat fill-prefix
3346 (make-string (- indent pre
)
3348 ;; first-line indent
3354 (save-excursion (end-of-line) (point))
3359 ;; try to keep point at its original place
3362 ;; In place of the more modern fill-region-as-paragraph, a hack
3363 ;; to keep whitespace untouched on the first line within the
3364 ;; indent length and to preserve any indent on the first line
3368 (buffer-substring start
(+ start first-indent -
1)))
3369 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3370 (fill-region-as-paragraph
3373 (current-justification)
3375 (delete-region start
(+ start first-indent -
1))
3378 ;; When we want the point at the beginning of the comment
3379 ;; body fill-region will put it at the beginning of the line.
3380 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3381 (setq fill-prefix nil
))))
3383 (defun idlwave-calc-hanging-indent ()
3384 "Calculate the position of the hanging indent for the comment
3385 paragraph. The hanging indent position is given by the first match
3386 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3387 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3389 If not found returns nil."
3390 (if idlwave-use-last-hang-indent
3393 (if (re-search-backward
3394 idlwave-hang-indent-regexp
3395 (save-excursion (beginning-of-line) (point))
3397 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3400 (if (re-search-forward
3401 idlwave-hang-indent-regexp
3402 (save-excursion (end-of-line) (point))
3404 (current-column)))))
3406 (defun idlwave-auto-fill ()
3407 "Called to break lines in auto fill mode.
3408 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3409 non-nil. Places a continuation character at the end of the line if
3410 not in a comment. Splits strings with IDL concatenation operator `+'
3411 if `idlwave-auto-fill-split-string' is non-nil."
3412 (if (<= (current-column) fill-column
)
3413 nil
; do not to fill
3414 (if (or (not idlwave-fill-comment-line-only
)
3416 ;; Check for comment line
3418 (looking-at idlwave-comment-line-start-skip
)))
3420 (idlwave-indent-line)
3421 ;; Prevent actions do-auto-fill which calls indent-line-function.
3422 (let (idlwave-do-actions
3423 (paragraph-start ".")
3424 (paragraph-separate ".")
3425 (fill-nobreak-predicate
3426 (if (and (idlwave-in-quote)
3427 idlwave-auto-fill-split-string
)
3428 (lambda () ;; We'll need 5 spaces for " ' + $"
3429 (<= (- fill-column
(current-column)) 5)
3434 ;; Indent the split line
3435 (idlwave-indent-line)
3439 (looking-at idlwave-comment-line-start-skip
))
3440 ;; A continued line comment
3441 ;; We treat continued line comments as part of a comment
3442 ;; paragraph. So we check for a hanging indent.
3443 (if idlwave-hanging-indent
3444 (let ((here (- (point-max) (point)))
3448 (idlwave-calc-hanging-indent))))
3451 ;; Remove whitespace between comment delimiter and
3452 ;; text, insert spaces for appropriate indentation.
3456 (save-excursion (end-of-line) (point)) t
)
3457 (delete-horizontal-space)
3458 (idlwave-indent-to indent
)
3459 (goto-char (- (point-max) here
)))
3461 ;; Split code or comment?
3464 (idlwave-in-comment))
3465 ;; Splitting a non-full-line comment.
3466 ;; Insert the comment delimiter from split line
3470 (skip-chars-forward " \t")
3471 ;; Insert blank to keep off beginning of line
3475 (buffer-substring (idlwave-goto-comment)
3477 (skip-chars-forward "; ")
3479 (idlwave-indent-line))
3480 ;; Split code line - add continuation character
3483 ;; Check to see if we split a string
3484 (if (and (setq beg
(idlwave-in-quote))
3485 idlwave-auto-fill-split-string
)
3486 ;; Split the string and concatenate.
3487 ;; The first extra space is for the space
3488 ;; the line was split. That space was removed.
3489 (insert " " (char-after beg
) " +"))
3492 (if idlwave-auto-fill-split-string
3493 ;; Make the second part of continued string
3496 (skip-chars-forward " \t")
3497 (insert (char-after beg
)))
3500 (message "Warning: continuation inside a string.")))
3501 ;; Although do-auto-fill (via indent-new-comment-line) calls
3502 ;; idlwave-indent-line for the new line, re-indent again
3503 ;; because of the addition of the continuation character.
3504 (idlwave-indent-line))
3507 (defun idlwave-auto-fill-mode (arg)
3508 "Toggle auto-fill mode for IDL mode.
3509 With arg, turn auto-fill mode on if arg is positive.
3510 In auto-fill mode, inserting a space at a column beyond `fill-column'
3511 automatically breaks the line at a previous space."
3513 (prog1 (set idlwave-fill-function
3515 (not (symbol-value idlwave-fill-function
))
3516 (> (prefix-numeric-value arg
) 0))
3520 (set-buffer-modified-p (buffer-modified-p))))
3522 ;(defun idlwave-fill-routine-call ()
3523 ; "Fill a routine definition or statement, indenting appropriately."
3524 ; (let ((where (idlwave-where)))))
3527 (defun idlwave-doc-header (&optional nomark
)
3528 "Insert a documentation header at the beginning of the unit.
3529 Inserts the value of the variable idlwave-file-header. Sets mark before
3530 moving to do insertion unless the optional prefix argument NOMARK
3533 (or nomark
(push-mark))
3534 ;; make sure we catch the current line if it begins the unit
3535 (if idlwave-header-to-beginning-of-file
3536 (goto-char (point-min))
3538 (idlwave-beginning-of-subprogram)
3540 ;; skip function or procedure line
3541 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3543 (idlwave-end-of-statement)
3544 (if (> (forward-line 1) 0) (insert "\n")))))
3545 (let ((pos (point)))
3546 (if idlwave-file-header
3547 (cond ((car idlwave-file-header
)
3548 (insert-file (car idlwave-file-header
)))
3549 ((stringp (car (cdr idlwave-file-header
)))
3550 (insert (car (cdr idlwave-file-header
))))))
3553 (defun idlwave-default-insert-timestamp ()
3554 "Default timestamp insertion function"
3555 (insert (current-time-string))
3556 (insert ", " (user-full-name))
3557 (if (boundp 'user-mail-address
)
3558 (insert " <" user-mail-address
">")
3559 (insert " <" (user-login-name) "@" (system-name) ">"))
3560 ;; Remove extra spaces from line
3561 (idlwave-fill-paragraph)
3562 ;; Insert a blank line comment to separate from the date entry -
3563 ;; will keep the entry from flowing onto date line if re-filled.
3564 (insert "\n;\n;\t\t"))
3566 (defun idlwave-doc-modification ()
3567 "Insert a brief modification log at the beginning of the current program.
3568 Looks for an occurrence of the value of user variable
3569 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3570 and places the point for the user to add a log. Before moving, saves
3571 location on mark ring so that the user can return to previous point."
3575 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3577 (goto-char (point-min))
3578 (re-search-forward idlwave-doclib-start nil t
)))
3579 (setq beg
(match-beginning 0))
3580 (re-search-forward idlwave-doclib-end nil t
)
3581 (setq end
(match-end 0)))
3584 (if (re-search-forward
3585 (concat idlwave-doc-modifications-keyword
":")
3590 (insert "\n" comment-start
"\n")
3591 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3593 (run-hooks 'idlwave-timestamp-hook
))
3594 (error "No valid DOCLIB header"))))
3597 ;;; Interface to expand-region-abbrevs which did not work when the
3598 ;;; abbrev hook associated with an abbrev moves point backwards
3599 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3600 ;;; The original would enter an infinite loop in attempting to expand
3601 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3602 ;;; because the point would keep going back to the beginning of the
3603 ;;; abbrev instead of to the end of the abbrev). We now keep the
3604 ;;; abbrev hook from moving backwards.
3606 (defun idlwave-expand-region-abbrevs (start end
)
3607 "Expand each abbrev occurrence in the region.
3608 Calling from a program, arguments are START END."
3611 (goto-char (min start end
))
3612 (let ((idlwave-show-block nil
) ;Do not blink
3613 (idlwave-abbrev-move nil
)) ;Do not move
3614 (expand-region-abbrevs start end
'noquery
))))
3616 (defun idlwave-quoted ()
3617 "Returns t if point is in a comment or quoted string.
3619 (or (idlwave-in-comment) (idlwave-in-quote)))
3621 (defun idlwave-in-quote ()
3622 "Returns location of the opening quote
3623 if point is in a IDL string constant, nil otherwise.
3624 Ignores comment delimiters on the current line.
3625 Properly handles nested quotation marks and octal
3626 constants - a double quote followed by an octal digit."
3627 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3628 ;;; double quote followed by an octal digit to be an octal constant
3629 ;;; rather than a string. Therefore, there is no terminating double
3632 ;; Because single and double quotes can quote each other we must
3633 ;; search for the string start from the beginning of line.
3634 (let* ((start (point))
3635 (eol (progn (end-of-line) (point)))
3636 (bq (progn (beginning-of-line) (point)))
3641 (while (< endq start
)
3642 ;; Find string start
3643 ;; Don't find an octal constant beginning with a double quote
3644 (if (re-search-forward "[\"']" eol
'lim
)
3645 ;; Find the string end.
3646 ;; In IDL, two consecutive delimiters after the start of a
3648 ;; escape for the delimiter in the string.
3649 ;; Two consecutive delimiters alone (i.e., not after the
3650 ;; start of a string) is the null string.
3652 ;; Move to position after quote
3653 (goto-char (1+ (match-beginning 0)))
3654 (setq bq
(1- (point)))
3655 ;; Get the string delimiter
3656 (setq delim
(char-to-string (preceding-char)))
3657 ;; Check for null string
3658 (if (looking-at delim
)
3659 (progn (setq endq
(point)) (forward-char 1))
3660 ;; Look for next unpaired delimiter
3661 (setq found
(search-forward delim eol
'lim
))
3662 (while (looking-at delim
)
3664 (setq found
(search-forward delim eol
'lim
)))
3666 (setq endq
(- (point) 1))
3667 (setq endq
(point)))
3669 (progn (setq bq
(point)) (setq endq
(point)))))
3670 (store-match-data data
)
3671 ;; return string beginning position or nil
3672 (if (> start bq
) bq
))))
3674 (defun idlwave-is-pointer-dereference (&optional limit
)
3675 "Determines if the character after point is a pointer dereference *."
3676 (let ((pos (point)))
3678 (eq (char-after) ?\
*)
3679 (not (idlwave-in-quote))
3682 (re-search-backward (concat "\\(" idlwave-idl-keywords
3683 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3686 ;; Statement templates
3688 ;; Replace these with a general template function, something like
3689 ;; expand.el (I think there was also something with a name similar to
3692 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3693 "Build a template with optional prompt expression.
3695 Opens a line if point is not followed by a newline modulo intervening
3696 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3697 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3698 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3699 PROMPT is a string then it is displayed as a message in the
3700 minibuffer. The PROMPT serves as a reminder to the user of an
3701 expression to enter.
3703 The lines containing S1 and S2 are reindented using `indent-region'
3704 unless the optional second argument NOINDENT is non-nil."
3705 (if (eq major-mode
'idlwave-shell-mode
)
3706 ;; This is a gross hack to avoit template abbrev expansion
3707 ;; in the shell. FIXME: This is a dirty hack.
3708 (if (and (eq this-command
'self-insert-command
)
3709 (equal last-abbrev-location
(point)))
3710 (insert last-abbrev-text
)
3711 (error "No templates in idlwave-shell"))
3712 (cond ((eq idlwave-abbrev-change-case
'down
)
3713 (setq s1
(downcase s1
) s2
(downcase s2
)))
3714 (idlwave-abbrev-change-case
3715 (setq s1
(upcase s1
) s2
(upcase s2
))))
3716 (let ((beg (save-excursion (beginning-of-line) (point)))
3718 (if (not (looking-at "\\s-*\n"))
3725 (indent-region beg end nil
))
3726 (if (stringp prompt
)
3727 (message prompt
)))))
3729 (defun idlwave-rw-case (string)
3730 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3731 (if idlwave-reserved-word-upcase
3735 (defun idlwave-elif ()
3736 "Build skeleton IDL if-else block."
3739 (idlwave-rw-case "if")
3740 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3741 "Condition expression"))
3743 (defun idlwave-case ()
3744 "Build skeleton IDL case statement."
3747 (idlwave-rw-case "case")
3748 (idlwave-rw-case " of\n\nendcase")
3749 "Selector expression"))
3751 (defun idlwave-switch ()
3752 "Build skeleton IDL switch statement."
3755 (idlwave-rw-case "switch")
3756 (idlwave-rw-case " of\n\nendswitch")
3757 "Selector expression"))
3759 (defun idlwave-for ()
3760 "Build skeleton for loop statment."
3763 (idlwave-rw-case "for")
3764 (idlwave-rw-case " do begin\n\nendfor")
3767 (defun idlwave-if ()
3768 "Build skeleton for loop statment."
3771 (idlwave-rw-case "if")
3772 (idlwave-rw-case " then begin\n\nendif")
3773 "Scalar logical expression"))
3775 (defun idlwave-procedure ()
3778 (idlwave-rw-case "pro")
3779 (idlwave-rw-case "\n\nreturn\nend")
3782 (defun idlwave-function ()
3785 (idlwave-rw-case "function")
3786 (idlwave-rw-case "\n\nreturn\nend")
3789 (defun idlwave-repeat ()
3792 (idlwave-rw-case "repeat begin\n\nendrep until")
3793 (idlwave-rw-case "")
3796 (defun idlwave-while ()
3799 (idlwave-rw-case "while")
3800 (idlwave-rw-case " do begin\n\nendwhile")
3803 (defun idlwave-split-string (string &optional pattern
)
3804 "Return a list of substrings of STRING which are separated by PATTERN.
3805 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3807 (setq pattern
"[ \f\t\n\r\v]+"))
3808 (let (parts (start 0))
3809 (while (string-match pattern string start
)
3810 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3811 start
(match-end 0)))
3812 (nreverse (cons (substring string start
) parts
))))
3814 (defun idlwave-replace-string (string replace_string replace_with
)
3816 (last (length string
))
3819 (while (setq end
(string-match replace_string string start
))
3821 (concat ret_string
(substring string start end
) replace_with
))
3822 (setq start
(match-end 0)))
3823 (setq ret_string
(concat ret_string
(substring string start last
)))))
3825 (defun idlwave-get-buffer-visiting (file)
3826 ;; Return the buffer currently visiting FILE
3828 ((boundp 'find-file-compare-truenames
) ; XEmacs
3829 (let ((find-file-compare-truenames t
))
3830 (get-file-buffer file
)))
3831 ((fboundp 'find-buffer-visiting
) ; Emacs
3832 (find-buffer-visiting file
))
3833 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3835 (defvar idlwave-outlawed-buffers nil
3836 "List of buffer pulled up by idlwave for special reasons.
3837 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3839 (defun idlwave-find-file-noselect (file &optional why
)
3840 ;; Return a buffer visiting file.
3841 (or (idlwave-get-buffer-visiting file
)
3842 (let ((buf (find-file-noselect file
)))
3843 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3846 (defun idlwave-kill-autoloaded-buffers ()
3847 "Kill buffers created automatically by IDLWAVE.
3848 Function prompts for a letter to identify the buffers to kill.
3849 Possible letters are:
3851 f Buffers created by the command \\[idlwave-find-module] or mouse
3852 clicks in the routine info window.
3853 s Buffers created by the IDLWAVE Shell to display where execution
3854 stopped or an error was found.
3855 a Both of the above.
3857 Buffer containing unsaved changes require confirmation before they are killed."
3859 (if (null idlwave-outlawed-buffers
)
3860 (error "No IDLWAVE-created buffers available")
3861 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3862 (idlwave-count-outlawed-buffers 'find
)
3863 (idlwave-count-outlawed-buffers 'shell
)))
3864 (let ((c (read-char)))
3866 ((member c
'(?f ?\C-f
))
3867 (idlwave-do-kill-autoloaded-buffers 'find
))
3868 ((member c
'(?s ?\C-s
))
3869 (idlwave-do-kill-autoloaded-buffers 'shell
))
3870 ((member c
'(?a ?\C-a
))
3871 (idlwave-do-kill-autoloaded-buffers t
))
3872 (t (error "Abort"))))))
3874 (defun idlwave-count-outlawed-buffers (tag)
3875 "How many outlawed buffers have tag TAG?"
3878 (lambda (x) (eq (cdr x
) tag
))
3879 idlwave-outlawed-buffers
))))
3881 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3882 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3883 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3886 (while (setq entry
(pop list
))
3887 (if (buffer-live-p (car entry
))
3888 (and (or (memq t reasons
)
3889 (memq (cdr entry
) reasons
))
3890 (kill-buffer (car entry
))
3892 (setq idlwave-outlawed-buffers
3893 (delq entry idlwave-outlawed-buffers
)))
3894 (setq idlwave-outlawed-buffers
3895 (delq entry idlwave-outlawed-buffers
))))
3896 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3898 (defun idlwave-revoke-license-to-kill ()
3899 "Remove BUFFER from the buffers which may be killed.
3900 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3901 Intended for `after-save-hook'."
3902 (let* ((buf (current-buffer))
3903 (entry (assq buf idlwave-outlawed-buffers
)))
3906 (setq idlwave-outlawed-buffers
3907 (delq entry idlwave-outlawed-buffers
)))
3908 ;; Remove this function from the hook.
3909 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3911 (defvar idlwave-path-alist
)
3912 (defun idlwave-locate-lib-file (file)
3913 ;; Find FILE on the scanned lib path and return a buffer visiting it
3914 (let* ((dirs idlwave-path-alist
)
3917 (while (setq dir
(car (pop dirs
)))
3919 (setq efile
(expand-file-name file dir
)))
3920 (throw 'exit efile
))))))
3922 (defun idlwave-expand-lib-file-name (file)
3923 ;; Find FILE on the scanned lib path and return a buffer visiting it
3924 ;; This is for, e.g., finding source with no user catalog
3927 ((file-name-absolute-p file
) file
)
3928 (t (idlwave-locate-lib-file file
))))
3930 (defun idlwave-make-tags ()
3931 "Creates the IDL tags file IDLTAGS in the current directory from
3932 the list of directories specified in the minibuffer. Directories may be
3933 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3934 specified top directories are searched if the directory name is prefixed
3935 by @. Specify @ directories with care, it may take a long, long time if
3938 (let (directory directories cmd append status numdirs dir getsubdirs
3939 buffer save_buffer files numfiles item errbuf
)
3942 ;; Read list of directories
3943 (setq directory
(read-string "Tag Directories: " "."))
3944 (setq directories
(idlwave-split-string directory
"[ \t]+"))
3946 ;; Set etags command, vars
3947 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
3948 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3949 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3953 ;; For each directory
3955 (setq dir
(nth numdirs directories
))
3958 ;; Find the subdirectories
3959 (if (string-match "^[@]\\(.+\\)$" dir
)
3960 (setq getsubdirs t
) (setq getsubdirs nil
))
3961 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
3962 (setq dir
(expand-file-name dir
))
3963 (if (file-directory-p dir
)
3965 (if (and getsubdirs
)
3967 (setq buffer
(get-buffer-create "*idltags*"))
3968 (call-process "sh" nil buffer nil
"-c"
3969 (concat "find " dir
" -type d -print"))
3970 (setq save_buffer
(current-buffer))
3972 (setq files
(idlwave-split-string
3973 (idlwave-replace-string
3974 (buffer-substring 1 (point-max))
3977 (set-buffer save_buffer
)
3978 (kill-buffer buffer
))
3979 (setq files
(list (concat dir
"/*.pro"))))
3981 ;; For each subdirectory
3983 (setq item
(nth numfiles files
))
3987 (if (not (string-match "^[ \\t]*$" item
))
3989 (message (concat "Tagging " item
"..."))
3990 (setq errbuf
(get-buffer-create "*idltags-error*"))
3991 (setq status
(+ status
3992 (if (eq 0 (call-process
3993 "sh" nil errbuf nil
"-c"
3994 (concat cmd append item
)))
3998 ;; Append additional tags
3999 (setq append
" --append ")
4000 (setq numfiles
(1+ numfiles
))
4001 (setq item
(nth numfiles files
)))
4003 (setq numfiles
(1+ numfiles
))
4004 (setq item
(nth numfiles files
))
4007 (setq numdirs
(1+ numdirs
))
4008 (setq dir
(nth numdirs directories
)))
4010 (setq numdirs
(1+ numdirs
))
4011 (setq dir
(nth numdirs directories
)))))
4013 (setq errbuf
(get-buffer-create "*idltags-error*"))
4015 (kill-buffer errbuf
))
4019 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4020 "Comment the lines in the region if the first non-blank line is
4021 commented, and conversely, uncomment region. If optional prefix arg
4022 N is non-nil, then for N positive, add N comment delimiters or for N
4023 negative, remove N comment delimiters.
4024 Uses `comment-region' which does not place comment delimiters on
4026 (interactive "r\nP")
4028 (comment-region beg end
(prefix-numeric-value n
))
4033 (skip-chars-forward " \t\n")
4034 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4035 (if (fboundp 'uncomment-region
)
4036 (uncomment-region beg end
)
4037 (comment-region beg end
4038 (- (length (buffer-substring
4041 (comment-region beg end
)))))
4044 ;; ----------------------------------------------------------------------------
4045 ;; ----------------------------------------------------------------------------
4046 ;; ----------------------------------------------------------------------------
4047 ;; ----------------------------------------------------------------------------
4049 ;; Completion and Routine Info
4052 ;; String "intern" functions
4054 ;; For the completion and routine info function, we want to normalize
4055 ;; the case of procedure names etc. We do this by "interning" these
4056 ;; string is a hand-crafted way. Hashes are used to map the downcase
4057 ;; version of the strings to the cased versions. Most *-sint-*
4058 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4059 ;; system hash. The former is re-scanned, and the latter takes case
4062 ;; Since these cased versions are really lisp objects, we can use `eq'
4063 ;; to search, which is a large performance boost. All new strings
4064 ;; need to be "sinterned". We do this as early as possible after
4065 ;; getting these strings from completion or buffer substrings. So
4066 ;; most of the code can simply assume to deal with "sinterned"
4067 ;; strings. The only exception is that the functions which scan whole
4068 ;; buffers for routine information do not intern the grabbed strings.
4069 ;; This is only done afterwards. Therefore in these functions it is
4070 ;; *not* safe to assume the strings can be compared with `eq' and be
4071 ;; fed into the routine assq functions.
4073 ;; Here we define the hashing functions.
4075 ;; The variables which hold the hashes.
4076 (defvar idlwave-sint-routines
'(nil))
4077 (defvar idlwave-sint-keywords
'(nil))
4078 (defvar idlwave-sint-methods
'(nil))
4079 (defvar idlwave-sint-classes
'(nil))
4080 (defvar idlwave-sint-dirs
'(nil))
4081 (defvar idlwave-sint-libnames
'(nil))
4083 (defun idlwave-reset-sintern (&optional what
)
4084 "Reset all sintern hashes."
4085 ;; Make sure the hash functions are accessible.
4086 (if (or (not (fboundp 'gethash
))
4087 (not (fboundp 'puthash
)))
4090 (or (fboundp 'puthash
)
4091 (defalias 'puthash
'cl-puthash
))))
4092 (let ((entries '((idlwave-sint-routines 1000 10)
4093 (idlwave-sint-keywords 1000 10)
4094 (idlwave-sint-methods 100 10)
4095 (idlwave-sint-classes 10 10))))
4097 ;; Make sure these are lists
4098 (loop for entry in entries
4099 for var
= (car entry
)
4100 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4102 (when (or (eq what t
) (eq what
'syslib
)
4103 (null (cdr idlwave-sint-routines
)))
4104 ;; Reset the system & library hash
4105 (loop for entry in entries
4106 for var
= (car entry
) for size
= (nth 1 entry
)
4107 do
(setcdr (symbol-value var
)
4108 (make-hash-table ':size size
':test
'equal
)))
4109 (setq idlwave-sint-dirs nil
4110 idlwave-sint-libnames nil
))
4112 (when (or (eq what t
) (eq what
'bufsh
)
4113 (null (car idlwave-sint-routines
)))
4114 ;; Reset the buffer & shell hash
4115 (loop for entry in entries
4116 for var
= (car entry
) for size
= (nth 1 entry
)
4117 do
(setcar (symbol-value var
)
4118 (make-hash-table ':size size
':test
'equal
))))))
4120 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4122 (idlwave-sintern-method name set
)
4123 (idlwave-sintern-routine name set
)))
4125 (defun idlwave-sintern (stype &rest args
)
4126 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4128 ;;(defmacro idlwave-sintern (type var)
4129 ;; `(cond ((not (stringp name)) name)
4130 ;; ((gethash (downcase name) (cdr ,var)))
4131 ;; ((gethash (downcase name) (car ,var)))
4132 ;; (set (idlwave-sintern-set name ,type ,var set))
4135 (defun idlwave-sintern-routine (name &optional set
)
4136 (cond ((not (stringp name
)) name
)
4137 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4138 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4139 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4141 (defun idlwave-sintern-keyword (name &optional set
)
4142 (cond ((not (stringp name
)) name
)
4143 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4144 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4145 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4147 (defun idlwave-sintern-method (name &optional set
)
4148 (cond ((not (stringp name
)) name
)
4149 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4150 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4151 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4153 (defun idlwave-sintern-class (name &optional set
)
4154 (cond ((not (stringp name
)) name
)
4155 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4156 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4157 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4160 (defun idlwave-sintern-dir (dir &optional set
)
4161 (car (or (member dir idlwave-sint-dirs
)
4162 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4163 (defun idlwave-sintern-libname (name &optional set
)
4164 (car (or (member name idlwave-sint-libnames
)
4165 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4167 (defun idlwave-sintern-set (name type tables set
)
4168 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4170 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4171 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4172 (puthash (downcase name
) iname table
)
4175 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4176 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4178 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4182 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4183 "Sintern all strings in the rinfo LIST. With optional parameter
4184 SET: also set new patterns. Probably this will always have to be t.
4185 If DEFAULT-DIR is passed, it is used as the base of the directory"
4186 (let (entry name type class kwds res source call new
)
4188 (setq entry
(car list
)
4193 source
(nth 3 entry
)
4195 kwds
(nthcdr 5 entry
))
4197 ;; The class and name
4200 (if (symbolp class
) (setq class
(symbol-name class
)))
4201 (setq class
(idlwave-sintern-class class set
))
4202 (setq name
(idlwave-sintern-method name set
)))
4203 (setq name
(idlwave-sintern-routine name set
)))
4206 (let ((source-type (car source
))
4207 (source-file (nth 1 source
))
4208 (source-dir (if default-dir
4209 (file-name-as-directory default-dir
)
4211 (source-lib (nth 3 source
)))
4212 (if (stringp source-dir
)
4213 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4214 (if (stringp source-lib
)
4215 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4216 (setq source
(list source-type source-file source-dir source-lib
)))
4219 (setq kwds
(mapcar (lambda (x)
4220 (idlwave-sintern-keyword-list x set
))
4223 ;; Build a canonicalized list
4224 (setq new
(nconc (list name type class source call
) kwds
)
4225 res
(cons new res
)))
4228 ;; Creating new sintern tables
4230 (defun idlwave-new-sintern-type (tag)
4231 "Define a variable and a function to sintern the new type TAG.
4232 This defines the function `idlwave-sintern-TAG' and the variable
4233 `idlwave-sint-TAGs'."
4234 (let* ((name (symbol-name tag
))
4235 (names (concat name
"s"))
4236 (var (intern (concat "idlwave-sint-" names
)))
4237 (func (intern (concat "idlwave-sintern-" name
))))
4238 (set var nil
) ; initial value of the association list
4239 (fset func
; set the function
4240 `(lambda (name &optional set
)
4241 (cond ((not (stringp name
)) name
)
4242 ((cdr (assoc (downcase name
) ,var
)))
4244 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4248 (defun idlwave-reset-sintern-type (tag)
4249 "Reset the sintern variable associated with TAG."
4250 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4252 ;;---------------------------------------------------------------------------
4255 ;; The variables which hold the information
4256 (defvar idlwave-system-routines nil
4257 "Holds the routine-info obtained by scanning buffers.")
4258 (defvar idlwave-buffer-routines nil
4259 "Holds the routine-info obtained by scanning buffers.")
4260 (defvar idlwave-compiled-routines nil
4261 "Holds the routine-info obtained by asking the shell.")
4262 (defvar idlwave-unresolved-routines nil
4263 "Holds the unresolved routine-info obtained by asking the shell.")
4264 (defvar idlwave-user-catalog-routines nil
4265 "Holds the procedure routine-info from the user scan.")
4266 (defvar idlwave-library-catalog-routines nil
4267 "Holds the procedure routine-info from the library catalog files.")
4268 (defvar idlwave-path-alist nil
4269 "Alist with !PATH directories and zero or more flags if the dir has
4270 been scanned in a user catalog ('user) or discovered in a library
4272 (defvar idlwave-true-path-alist nil
4273 "Like `idlwave-path-alist', but with true filenames.")
4274 (defvar idlwave-routines nil
4275 "Holds the combinded procedure/function/method routine-info.")
4276 (defvar idlwave-class-alist nil
4277 "Holds the class names known to IDLWAVE.")
4278 (defvar idlwave-class-history nil
4279 "The history of classes selected with the minibuffer.")
4280 (defvar idlwave-force-class-query nil
)
4281 (defvar idlwave-before-completion-wconf nil
4282 "The window configuration just before the completion buffer was displayed.")
4283 (defvar idlwave-last-system-routine-info-cons-cell nil
4284 "The last cons cell in the system routine info.")
4287 ;; The code to get routine info from different sources.
4289 (defvar idlwave-system-routines
)
4290 (defvar idlwave-catalog-process nil
4291 "The background process currently updating the catalog.")
4293 (defun idlwave-routines ()
4294 "Provide a list of IDL routines.
4295 This routine loads the builtin routines on the first call. Later it
4296 only returns the value of the variable."
4297 (if (and idlwave-catalog-process
4298 (processp idlwave-catalog-process
))
4301 ((equal (process-status idlwave-catalog-process
) 'exit
)
4302 (message "updating........")
4303 (setq idlwave-catalog-process nil
)
4304 (idlwave-update-routine-info '(4)))
4305 ((equal (process-status idlwave-catalog-process
) 'run
)
4306 ;; Keep it running...
4309 ;; Something is wrong, get rid of the process
4310 (message "Problem with catalog process") (beep)
4312 (kill-process idlwave-catalog-process
)
4314 (setq idlwave-catalog-process nil
)))))
4315 (or idlwave-routines
4317 (idlwave-update-routine-info)
4318 ;; return the current value
4321 (defvar idlwave-update-rinfo-hook nil
4322 "List of functions which should run after a global rinfo update.
4323 Does not run after automatic updates of buffer or the shell.")
4325 (defun idlwave-rescan-catalog-directories ()
4326 "Rescan the previously selected directories. For batch processing."
4327 (idlwave-update-routine-info '(16)))
4329 (defun idlwave-rescan-asynchronously ()
4330 "Dispatch another emacs instance to update the idlwave catalog.
4331 After the process finishes normally, the first access to routine info
4332 will re-read the catalog."
4334 (if (processp idlwave-catalog-process
)
4335 (if (eq (process-status idlwave-catalog-process
) 'run
)
4336 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4339 (kill-process idlwave-catalog-process
)
4341 (error "Process killed, no new process started"))
4344 (kill-process idlwave-catalog-process
)
4346 (if (or (not idlwave-user-catalog-file
)
4347 (not (stringp idlwave-user-catalog-file
))
4348 (not (file-regular-p idlwave-user-catalog-file
)))
4349 (error "No catalog has been produced yet"))
4350 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4351 (args (list "-batch"
4352 "-l" (expand-file-name "~/.emacs")
4354 "-f" "idlwave-rescan-catalog-directories"))
4355 (process (apply 'start-process
"idlcat"
4357 (setq idlwave-catalog-process process
)
4358 (set-process-sentinel
4361 (when (string-match "finished" why
)
4362 (setq idlwave-routines nil
4363 idlwave-system-routines nil
4364 idlwave-catalog-process nil
)
4365 (or (idlwave-start-load-rinfo-timer)
4366 (idlwave-update-routine-info '(4))))))
4367 (message "Background job started to update catalog file")))
4370 ;; Format for all routine info user catalog, library catalogs, etc.:
4372 ;; ("ROUTINE" type class
4373 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4374 ;; (buffer pro_file dir) | (compiled pro_file dir)
4375 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
4377 ;; DIR will be supplied dynamically while loading library catalogs,
4378 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4379 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4380 ;; be nil, as can LINK1, etc., if no HTML help is available.
4383 (defvar idlwave-load-rinfo-idle-timer
)
4384 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4385 "Update the internal routine-info lists.
4386 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4387 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4388 about individual routines.
4390 The information can come from 4 sources:
4391 1. IDL programs in the current editing session
4392 2. Compiled modules in an IDL shell running as Emacs subprocess
4393 3. A list which covers the IDL system routines.
4394 4. A list which covers the prescanned library files.
4396 Scans all IDLWAVE-mode buffers of the current editing session (see
4397 `idlwave-scan-all-buffers-for-routine-info').
4398 When an IDL shell is running, this command also queries the IDL program
4399 for currently compiled routines.
4401 With prefix ARG, also reload the system and library lists.
4402 With two prefix ARG's, also rescans the chosen user catalog tree.
4403 With three prefix args, dispatch asynchronous process to do the update.
4405 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4406 lists, but instead wait for the shell query to complete and
4407 asynchronously finish updating routine info. This is set
4408 automatically when called interactively. When you need routine
4409 information updated immediately, leave NO-CONCATENATE nil."
4410 (interactive "P\np")
4411 ;; Stop any idle processing
4412 (if (or (and (fboundp 'itimerp
)
4413 (itimerp idlwave-load-rinfo-idle-timer
))
4414 (and (fboundp 'timerp
)
4415 (timerp idlwave-load-rinfo-idle-timer
)))
4416 (cancel-timer idlwave-load-rinfo-idle-timer
))
4419 ;; Start a background process which updates the catalog.
4420 (idlwave-rescan-asynchronously))
4422 ;; Update the user catalog now, and wait for them.
4423 (idlwave-create-user-catalog-file t
))
4425 (let* ((load (or arg
4426 idlwave-buffer-case-takes-precedence
4427 (null idlwave-routines
)))
4428 ;; The override-idle means, even if the idle timer has done some
4429 ;; preparing work, load and renormalize everything anyway.
4430 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4432 (setq idlwave-buffer-routines nil
4433 idlwave-compiled-routines nil
4434 idlwave-unresolved-routines nil
)
4435 ;; Reset the appropriate hashes
4436 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4437 ;; reset was already done in idle time, so skip this step now once
4438 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4439 (idlwave-reset-sintern (cond (load t
)
4440 ((null idlwave-system-routines
) t
)
4443 (if idlwave-buffer-case-takes-precedence
4444 ;; We can safely scan the buffer stuff first
4446 (idlwave-update-buffer-routine-info)
4447 (and load
(idlwave-load-system-rinfo override-idle
)))
4448 ;; We first do the system info, and then the buffers
4449 (and load
(idlwave-load-system-rinfo override-idle
))
4450 (idlwave-update-buffer-routine-info))
4452 ;; Let's see if there is a shell
4453 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4454 (idlwave-shell-is-running)))
4455 (ask-shell (and shell-is-running
4456 idlwave-query-shell-for-routine-info
)))
4458 ;; Load the library catalogs again, first re-scanning the path
4460 (if shell-is-running
4461 (idlwave-shell-send-command idlwave-shell-path-query
4463 (idlwave-shell-get-path-info)
4464 (idlwave-scan-library-catalogs))
4466 (idlwave-scan-library-catalogs)))
4468 (if (or (not ask-shell
)
4469 (not no-concatenate
))
4470 ;; 1. If we are not going to ask the shell, we need to do the
4471 ;; concatenation now.
4472 ;; 2. When this function is called non-interactively, it
4473 ;; means that someone needs routine info *now*. The
4474 ;; shell update causes the concatenation to be
4475 ;; *delayed*, so not in time for the current command.
4476 ;; Therefore, we do a concatenation now, even though
4477 ;; the shell might do it again.
4478 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4481 ;; Ask the shell about the routines it knows of.
4482 (message "Querying the shell")
4483 (idlwave-shell-update-routine-info nil t
)))))))
4486 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4487 (defvar idlwave-load-rinfo-idle-timer nil
)
4488 (defun idlwave-start-load-rinfo-timer ()
4489 (if (or (and (fboundp 'itimerp
)
4490 (itimerp idlwave-load-rinfo-idle-timer
))
4491 (and (fboundp 'timerp
)
4492 (timerp idlwave-load-rinfo-idle-timer
)))
4493 (cancel-timer idlwave-load-rinfo-idle-timer
))
4494 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4495 (setq idlwave-load-rinfo-idle-timer nil
)
4496 (if (and idlwave-init-rinfo-when-idle-after
4497 (numberp idlwave-init-rinfo-when-idle-after
)
4498 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4499 (not idlwave-routines
))
4502 (setq idlwave-load-rinfo-idle-timer
4503 (run-with-idle-timer
4504 idlwave-init-rinfo-when-idle-after
4505 nil
'idlwave-load-rinfo-next-step
)))
4508 (defun idlwave-load-rinfo-next-step ()
4509 (let ((inhibit-quit t
)
4510 (arr idlwave-load-rinfo-steps-done
))
4512 (when (not (aref arr
0))
4513 (message "Loading idlw-rinfo.el in idle time...")
4514 (load "idlw-rinfo" 'noerror
'nomessage
)
4515 (message "Loading idlw-rinfo.el in idle time...done")
4518 (when (not (aref arr
1))
4519 (message "Normalizing idlwave-system-routines in idle time...")
4520 (idlwave-reset-sintern t
)
4521 (put 'idlwave-reset-sintern
'done-by-idle t
)
4522 (setq idlwave-system-routines
4523 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4524 (message "Normalizing idlwave-system-routines in idle time...done")
4527 (when (not (aref arr
2))
4528 (when (and (stringp idlwave-user-catalog-file
)
4529 (file-regular-p idlwave-user-catalog-file
))
4530 (message "Loading user catalog in idle time...")
4532 (load-file idlwave-user-catalog-file
)
4533 (error (throw 'exit nil
)))
4534 ;; Check for the old style catalog and warn
4536 (boundp 'idlwave-library-routines
)
4537 idlwave-library-routines
)
4539 (setq idlwave-library-routines nil
)
4541 (message "Outdated user catalog: %s... recreate"
4542 idlwave-user-catalog-file
))
4543 (message "Loading user catalog in idle time...done"))
4546 (when (not (aref arr
3))
4547 (when idlwave-user-catalog-routines
4548 (message "Normalizing user catalog routines in idle time...")
4549 (setq idlwave-user-catalog-routines
4550 (idlwave-sintern-rinfo-list
4551 idlwave-user-catalog-routines
'sys
))
4553 "Normalizing user catalog routines in idle time...done"))
4556 (when (not (aref arr
4))
4557 (idlwave-scan-library-catalogs
4558 "Loading and normalizing library catalogs in idle time...")
4561 (when (not (aref arr
5))
4562 (message "Finishing initialization in idle time...")
4564 (message "Finishing initialization in idle time...done")
4566 ;; restart the timer
4568 (idlwave-load-rinfo-next-step)
4569 (setq idlwave-load-rinfo-idle-timer
4570 (run-with-idle-timer
4571 idlwave-init-rinfo-when-idle-after
4572 nil
'idlwave-load-rinfo-next-step
))))))
4574 (defun idlwave-load-system-rinfo (&optional force
)
4575 ;; Load and case-treat the system and catalog files.
4576 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
4577 (load "idlw-rinfo" 'noerror
'nomessage
))
4578 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
4579 (message "Normalizing idlwave-system-routines...")
4580 (setq idlwave-system-routines
4581 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4582 (message "Normalizing idlwave-system-routines...done"))
4583 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
4584 (setq idlwave-last-system-routine-info-cons-cell
4585 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
))
4586 (when (and (stringp idlwave-user-catalog-file
)
4587 (file-regular-p idlwave-user-catalog-file
))
4589 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
4590 (load-file idlwave-user-catalog-file
))
4592 (when (boundp 'idlwave-library-routines
)
4593 (setq idlwave-library-routines nil
)
4594 (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file
))
4595 (setq idlwave-true-path-alist nil
)
4596 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
4597 (message "Normalizing user catalog routines...")
4598 (setq idlwave-user-catalog-routines
4599 (idlwave-sintern-rinfo-list
4600 idlwave-user-catalog-routines
'sys
))
4601 (message "Normalizing user catalog routines...done")))
4602 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
4603 (idlwave-scan-library-catalogs
4604 "Loading and normalizing library catalogs..."))
4605 (run-hooks 'idlwave-after-load-rinfo-hook
))
4608 (defun idlwave-update-buffer-routine-info ()
4611 ((eq idlwave-scan-all-buffers-for-routine-info t
)
4612 ;; Scan all buffers, current buffer last
4613 (message "Scanning all buffers...")
4614 (setq res
(idlwave-get-routine-info-from-buffers
4615 (reverse (buffer-list)))))
4616 ((null idlwave-scan-all-buffers-for-routine-info
)
4617 ;; Don't scan any buffers
4620 ;; Just scan this buffer
4621 (if (eq major-mode
'idlwave-mode
)
4623 (message "Scanning current buffer...")
4624 (setq res
(idlwave-get-routine-info-from-buffers
4625 (list (current-buffer))))))))
4626 ;; Put the result into the correct variable
4627 (setq idlwave-buffer-routines
4628 (idlwave-sintern-rinfo-list res
'set
))))
4630 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
4631 "Put the different sources for routine information together."
4632 ;; The sequence here is important because earlier definitions shadow
4633 ;; later ones. We assume that if things in the buffers are newer
4634 ;; then in the shell of the system, they are meant to be different.
4635 (setcdr idlwave-last-system-routine-info-cons-cell
4636 (append idlwave-buffer-routines
4637 idlwave-compiled-routines
4638 idlwave-library-catalog-routines
4639 idlwave-user-catalog-routines
))
4640 (setq idlwave-class-alist nil
)
4642 ;; Give a message with information about the number of routines we have.
4645 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
4646 (length idlwave-buffer-routines
)
4647 (length idlwave-compiled-routines
)
4648 (length idlwave-library-catalog-routines
)
4649 (length idlwave-user-catalog-routines
)
4650 (length idlwave-system-routines
)))
4652 (run-hooks 'idlwave-update-rinfo-hook
)))
4654 (defun idlwave-class-alist ()
4655 "Return the class alist - make it if necessary."
4656 (or idlwave-class-alist
4658 (loop for x in idlwave-routines do
4659 (when (and (setq class
(nth 2 x
))
4660 (not (assq class idlwave-class-alist
)))
4661 (push (list class
) idlwave-class-alist
)))
4662 idlwave-class-alist
)))
4664 ;; Three functions for the hooks
4665 (defun idlwave-save-buffer-update ()
4666 (idlwave-update-current-buffer-info 'save-buffer
))
4667 (defun idlwave-kill-buffer-update ()
4668 (idlwave-update-current-buffer-info 'kill-buffer
))
4669 (defun idlwave-new-buffer-update ()
4670 (idlwave-update-current-buffer-info 'find-file
))
4672 (defun idlwave-update-current-buffer-info (why)
4673 "Update idlwave-routines for current buffer. Can run from after-save-hook."
4674 (when (and (eq major-mode
'idlwave-mode
)
4675 (or (eq t idlwave-auto-routine-info-updates
)
4676 (memq why idlwave-auto-routine-info-updates
))
4677 idlwave-scan-all-buffers-for-routine-info
4681 (idlwave-replace-buffer-routine-info
4683 (if (eq why
'kill-buffer
)
4686 (idlwave-sintern-rinfo-list
4687 (idlwave-get-routine-info-from-buffers
4688 (list (current-buffer))) 'set
))))
4689 (idlwave-concatenate-rinfo-lists 'quiet
)
4693 (defun idlwave-replace-buffer-routine-info (file new
)
4694 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4695 (let ((list idlwave-buffer-routines
)
4698 ;; The following test uses eq to make sure it works correctly
4699 ;; when two buffers visit the same file. Then the file names
4700 ;; will be equal, but not eq.
4701 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
4706 ;; End of that section reached. Jump.
4708 (setq list
(cdr list
)))
4709 (setq idlwave-buffer-routines
4710 (append new
(delq nil idlwave-buffer-routines
)))))
4712 ;;----- Scanning buffers -------------------
4714 (defun idlwave-get-routine-info-from-buffers (buffers)
4715 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4716 (let (buf routine-lists res
)
4718 (while (setq buf
(pop buffers
))
4720 (if (and (eq major-mode
'idlwave-mode
)
4722 ;; yes, this buffer has the right mode.
4723 (progn (setq res
(condition-case nil
4724 (idlwave-get-buffer-routine-info)
4726 (push res routine-lists
)))))
4727 ;; Concatenate the individual lists and return the result
4728 (apply 'nconc routine-lists
)))
4730 (defun idlwave-get-buffer-routine-info ()
4731 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4732 (let* ((case-fold-search t
)
4733 routine-list string entry
)
4737 (goto-char (point-min))
4738 (while (re-search-forward
4739 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
4740 (setq string
(buffer-substring-no-properties
4743 (idlwave-end-of-statement)
4745 (setq entry
(idlwave-parse-definition string
))
4746 (push entry routine-list
))))
4749 (defvar idlwave-scanning-lib-dir
)
4750 (defun idlwave-parse-definition (string)
4751 "Parse a module definition."
4752 (let ((case-fold-search t
)
4753 start name args type keywords class
)
4755 (while (string-match ";.*" string
)
4756 (setq string
(replace-match "" t t string
)))
4757 ;; Remove the continuation line stuff
4758 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
4759 (setq string
(replace-match "\\1 " t nil string
)))
4760 (while (string-match "\n" string
)
4761 (setq string
(replace-match " " t nil string
)))
4762 ;; Match the name and type.
4764 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
4765 (setq start
(match-end 0))
4766 (setq type
(downcase (match-string 1 string
)))
4767 (if (match-beginning 3)
4768 (setq class
(match-string 3 string
)))
4769 (setq name
(match-string 4 string
)))
4770 ;; Match normal args and keyword args
4771 (while (string-match
4772 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4774 (setq start
(match-end 0))
4775 (if (match-beginning 3)
4776 (push (match-string 1 string
) keywords
)
4777 (push (match-string 1 string
) args
)))
4778 ;; Normalize and sort.
4779 (setq args
(nreverse args
))
4780 (setq keywords
(sort keywords
(lambda (a b
)
4781 (string< (downcase a
) (downcase b
)))))
4782 ;; Make and return the entry
4783 ;; We don't know which argument are optional, so this information
4784 ;; will not be contained in the calling sequence.
4786 (if (equal type
"pro") 'pro
'fun
)
4788 (cond ((not (boundp 'idlwave-scanning-lib
))
4789 (list 'buffer
(buffer-file-name)))
4790 ; ((string= (downcase
4791 ; (file-name-sans-extension
4792 ; (file-name-nondirectory (buffer-file-name))))
4795 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4796 (t (list 'user
(file-name-nondirectory (buffer-file-name))
4797 idlwave-scanning-lib-dir
"UserLib")))
4799 (if (string= type
"function") "Result = " "")
4800 (if class
"Obj ->[%s::]" "")
4804 (if (string= type
"function") "(" ", ")
4805 (mapconcat 'identity args
", ")
4806 (if (string= type
"function") ")" ""))))
4808 (cons nil
(mapcar 'list keywords
)) ;No help file
4812 ;;----- Scanning the user catalog -------------------
4814 (defun idlwave-sys-dir ()
4815 "Return the syslib directory, or a dummy that never matches."
4816 (if (string= idlwave-system-directory
"")
4818 idlwave-system-directory
))
4821 (defvar idlwave-shell-path-query
)
4822 (defun idlwave-create-user-catalog-file (&optional arg
)
4823 "Scan all files on selected dirs of IDL search path for routine information.
4825 A widget checklist will allow you to choose the directories. Write
4826 the result as a file `idlwave-user-catalog-file'. When this file
4827 exists, will be automatically loaded to give routine information about
4828 library routines. With ARG, just rescan the same directories as last
4829 time - so no widget will pop up."
4831 ;; Make sure the file is loaded if it exists.
4832 (if (and (stringp idlwave-user-catalog-file
)
4833 (file-regular-p idlwave-user-catalog-file
))
4835 (load-file idlwave-user-catalog-file
)
4837 ;; Make sure the file name makes sense
4838 (unless (and (stringp idlwave-user-catalog-file
)
4839 (> (length idlwave-user-catalog-file
) 0)
4840 (file-accessible-directory-p
4841 (file-name-directory idlwave-user-catalog-file
))
4842 (not (string= "" (file-name-nondirectory
4843 idlwave-user-catalog-file
))))
4844 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
4847 ;; Rescan the known directories
4848 ((and arg idlwave-path-alist
4849 (consp (car idlwave-path-alist
)))
4850 (idlwave-scan-user-lib-files idlwave-path-alist
))
4852 ;; Expand the directories from library-path and run the widget
4853 (idlwave-library-path
4854 (idlwave-display-user-catalog-widget
4855 (if idlwave-true-path-alist
4856 ;; Propagate any flags on the existing path-alist
4858 (let ((path-entry (assoc (file-truename x
)
4859 idlwave-true-path-alist
)))
4861 (cons x
(cdr path-entry
))
4863 (idlwave-expand-path idlwave-library-path
))
4864 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
4866 ;; Ask the shell for the path and then run the widget
4868 (message "Asking the shell for IDL path...")
4869 (require 'idlw-shell
)
4870 (idlwave-shell-send-command idlwave-shell-path-query
4871 '(idlwave-user-catalog-command-hook nil
)
4875 ;; Parse shell path information and select among it.
4876 (defun idlwave-user-catalog-command-hook (&optional arg
)
4877 ;; Command hook used by `idlwave-create-user-catalog-file'.
4880 (idlwave-scan-user-lib-files idlwave-path-alist
)
4881 ;; Set the path and display the widget
4882 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
4883 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
4884 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
4886 (defconst idlwave-user-catalog-widget-help-string
4887 "This is the front-end to the creation of the IDLWAVE user catalog.
4888 Please select the directories on IDL's search path from which you
4889 would like to extract routine information, to be stored in the file:
4893 If this is not the correct file, first set variable
4894 `idlwave-user-catalog-file', and call this command again.
4896 N.B. Many libraries include pre-scanned catalog files
4897 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
4898 not be scanned. You can scan your own libraries off-line using the
4899 perl script `idlwave_catalog'.
4901 After selecting the directories, choose [Scan & Save] to scan the library
4902 directories and save the routine info.
4905 (defvar idlwave-widget
)
4906 (defvar widget-keymap
)
4907 (defun idlwave-display-user-catalog-widget (dirs-list)
4908 "Create the widget to select IDL search path directories for scanning."
4913 (error "Don't know IDL's search path"))
4915 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4916 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4917 (kill-all-local-variables)
4918 (make-local-variable 'idlwave-widget
)
4919 (widget-insert (format idlwave-user-catalog-widget-help-string
4920 idlwave-user-catalog-file
))
4922 (widget-create 'push-button
4923 :notify
'idlwave-widget-scan-user-lib-files
4926 (widget-create 'push-button
4927 :notify
'idlwave-delete-user-catalog-file
4930 (widget-create 'push-button
4932 '(lambda (&rest ignore
)
4933 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4935 (unless (memq 'lib
(cdr x
))
4936 (idlwave-path-alist-add-flag x
'user
)))
4938 (idlwave-display-user-catalog-widget path-list
)))
4939 "Select All Non-Lib")
4941 (widget-create 'push-button
4943 '(lambda (&rest ignore
)
4944 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4946 (idlwave-path-alist-remove-flag x
'user
))
4948 (idlwave-display-user-catalog-widget path-list
)))
4951 (widget-create 'push-button
4952 :notify
(lambda (&rest ignore
)
4953 (kill-buffer (current-buffer)))
4955 (widget-insert "\n\n")
4957 (widget-insert "Select Directories: \n")
4959 (setq idlwave-widget
4960 (apply 'widget-create
4962 :value
(delq nil
(mapcar (lambda (x)
4963 (if (memq 'user
(cdr x
))
4967 :tag
"List of directories"
4970 (if (memq 'lib
(cdr x
))
4971 (concat "[LIB] " (car x
) )
4972 (car x
)))) dirs-list
)))
4973 (widget-put idlwave-widget
:path-dirs dirs-list
)
4974 (widget-insert "\n")
4975 (use-local-map widget-keymap
)
4977 (goto-char (point-min))
4978 (delete-other-windows))
4980 (defun idlwave-delete-user-catalog-file (&rest ignore
)
4982 (format "Delete file %s " idlwave-user-catalog-file
))
4984 (delete-file idlwave-user-catalog-file
)
4985 (message "%s has been deleted" idlwave-user-catalog-file
))))
4987 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
4988 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
4989 (let* ((widget idlwave-widget
)
4990 (selected-dirs (widget-value widget
))
4991 (path-alist (widget-get widget
:path-dirs
))
4992 (this-path-alist path-alist
)
4994 (while (setq dir-entry
(pop this-path-alist
))
4996 (if (memq 'lib
(cdr dir-entry
))
4997 (concat "[LIB] " (car dir-entry
))
5000 (idlwave-path-alist-add-flag dir-entry
'user
)
5001 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5002 (idlwave-scan-user-lib-files path-alist
)))
5004 (defvar font-lock-mode
)
5005 (defun idlwave-scan-user-lib-files (path-alist)
5006 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5007 (let* ((idlwave-scanning-lib t
)
5008 (idlwave-scanning-lib-dir "")
5009 (idlwave-completion-case nil
)
5010 dirs-alist dir files file
)
5011 (setq idlwave-user-catalog-routines nil
5012 idlwave-path-alist path-alist
; for library-path instead
5013 idlwave-true-path-alist nil
)
5014 (if idlwave-auto-write-paths
(idlwave-write-paths))
5016 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5018 (setq dirs-alist
(reverse path-alist
))
5019 (while (setq dir
(pop dirs-alist
))
5020 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5021 (setq dir
(car dir
))
5022 (setq idlwave-scanning-lib-dir dir
)
5023 (when (file-directory-p dir
)
5024 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5025 (while (setq file
(pop files
))
5026 (when (file-regular-p file
)
5027 (if (not (file-readable-p file
))
5028 (message "Skipping %s (no read permission)" file
)
5029 (message "Scanning %s..." file
)
5031 (insert-file-contents file
'visit
)
5032 (setq idlwave-user-catalog-routines
5033 (append (idlwave-get-routine-info-from-buffers
5034 (list (current-buffer)))
5035 idlwave-user-catalog-routines
)))))))))
5036 (message "Creating user catalog file...")
5037 (kill-buffer "*idlwave-scan.pro*")
5038 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5039 (let ((font-lock-maximum-size 0)
5040 (auto-mode-alist nil
))
5041 (find-file idlwave-user-catalog-file
))
5042 (if (and (boundp 'font-lock-mode
)
5046 (insert ";; IDLWAVE user catalog file\n")
5047 (insert (format ";; Created %s\n\n" (current-time-string)))
5049 ;; Define the routine info list
5050 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5051 (let ((standard-output (current-buffer)))
5055 (goto-char (point-max)))
5056 idlwave-user-catalog-routines
))
5057 (insert (format "))\n\n;;; %s ends here\n"
5058 (file-name-nondirectory idlwave-user-catalog-file
)))
5059 (goto-char (point-min))
5062 (kill-buffer (current-buffer)))
5063 (message "Creating user catalog file...done")
5064 (message "Info for %d routines saved in %s"
5065 (length idlwave-user-catalog-routines
)
5066 idlwave-user-catalog-file
)
5068 (idlwave-update-routine-info t
))
5070 (defun idlwave-read-paths ()
5071 (if (and (stringp idlwave-path-file
)
5072 (file-regular-p idlwave-path-file
))
5074 (load idlwave-path-file t t t
)
5077 (defun idlwave-write-paths ()
5079 (when (and idlwave-path-alist idlwave-system-directory
)
5080 (let ((font-lock-maximum-size 0)
5081 (auto-mode-alist nil
))
5082 (find-file idlwave-path-file
))
5083 (if (and (boundp 'font-lock-mode
)
5087 (insert ";; IDLWAVE paths\n")
5088 (insert (format ";; Created %s\n\n" (current-time-string)))
5089 ;; Define the variable which knows the value of "!DIR"
5090 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5091 idlwave-system-directory
))
5093 ;; Define the variable which contains a list of all scanned directories
5094 (insert "\n(setq idlwave-path-alist\n '(")
5095 (let ((standard-output (current-buffer)))
5099 (goto-char (point-max)))
5100 idlwave-path-alist
))
5103 (kill-buffer (current-buffer))))
5106 (defun idlwave-expand-path (path &optional default-dir
)
5107 ;; Expand parts of path starting with '+' recursively into directory list.
5108 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5109 (message "Expanding path...")
5110 (let (path1 dir recursive
)
5111 (while (setq dir
(pop path
))
5112 (if (setq recursive
(string= (substring dir
0 1) "+"))
5113 (setq dir
(substring dir
1)))
5115 (not (file-name-absolute-p dir
)))
5116 (setq dir
(expand-file-name dir default-dir
)))
5118 ;; Expand recursively
5119 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5122 (message "Expanding path...done")
5125 (defun idlwave-recursive-directory-list (dir)
5126 ;; Return a list of all directories below DIR, including DIR itself
5127 (let ((path (list dir
)) path1 file files
)
5128 (while (setq dir
(pop path
))
5129 (when (file-directory-p dir
)
5130 (setq files
(nreverse (directory-files dir t
"[^.]")))
5131 (while (setq file
(pop files
))
5132 (if (file-directory-p file
)
5133 (push (file-name-as-directory file
) path
)))
5138 ;;----- Scanning the library catalogs ------------------
5140 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5141 "Scan for library catalog files (.idlwave_catalog) and ingest.
5143 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5144 instead, if present) are searched. Print MESSAGE-BASE along with the
5145 libraries being loaded, if passed, and skip loading/normalizing if
5146 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5147 be set to nil to disable library catalog scanning."
5148 (when idlwave-use-library-catalogs
5150 (if idlwave-library-path
5151 (idlwave-expand-path idlwave-library-path
)
5152 (mapcar 'car idlwave-path-alist
)))
5154 dir-entry dir flags catalog all-routines
)
5155 (if message-base
(message message-base
))
5156 (while (setq dir
(pop dirs
))
5158 (when (file-readable-p
5159 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5161 (setq idlwave-library-catalog-routines nil
)
5162 ;; Load the catalog file
5164 (load catalog t t t
)
5165 (error (throw 'continue t
)))
5168 (not (string= idlwave-library-catalog-libname
5170 (message (concat message-base
5171 idlwave-library-catalog-libname
))
5172 (setq old-libname idlwave-library-catalog-libname
))
5173 (when idlwave-library-catalog-routines
5176 (idlwave-sintern-rinfo-list
5177 idlwave-library-catalog-routines
'sys dir
)
5180 ;; Add a 'lib flag if on path-alist
5181 (when (and idlwave-path-alist
5182 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5183 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5184 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5185 (if message-base
(message (concat message-base
"done"))))))
5187 ;;----- Communicating with the Shell -------------------
5189 ;; First, here is the idl program which can be used to query IDL for
5190 ;; defined routines.
5191 (defconst idlwave-routine-info.pro
5193 ;; START OF IDLWAVE SUPPORT ROUTINES
5194 pro idlwave_print_info_entry,name,func=func,separator=sep
5195 ;; See if it's an object method
5196 if name eq '' then return
5197 func = keyword_set(func)
5198 methsep = strpos(name,'::')
5199 meth = methsep ne -1
5202 pars = routine_info(name,/parameters,functions=func)
5203 source = routine_info(name,/source,functions=func)
5204 nargs = pars.num_args
5205 nkw = pars.num_kw_args
5206 if nargs gt 0 then args = pars.args
5207 if nkw gt 0 then kwargs = pars.kw_args
5209 ;; Trim the class, and make the name
5211 class = strmid(name,0,methsep)
5212 name = strmid(name,methsep+2,strlen(name)-1)
5213 if nargs gt 0 then begin
5214 ;; remove the self argument
5215 wh = where(args ne 'SELF',nargs)
5216 if nargs gt 0 then args = args[wh]
5219 ;; No class, just a normal routine.
5225 if func then cs = 'Result = '
5226 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5228 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5229 if nargs gt 0 then begin
5230 for j=0,nargs-1 do begin
5232 if j lt nargs-1 then cs = cs + ', '
5235 if func then cs = cs + ')'
5236 ;; Keyword arguments
5238 if nkw gt 0 then begin
5239 for j=0,nkw-1 do begin
5240 kwstring = kwstring + ' ' + kwargs[j]
5244 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5246 print,ret + ': ' + name + sep + class + sep + source[0].path $
5247 + sep + cs + sep + kwstring
5250 pro idlwave_routine_info
5253 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5254 all = routine_info()
5255 for i=0,n_elements(all)-1 do $
5256 idlwave_print_info_entry,all[i],separator=sep
5257 all = routine_info(/functions)
5258 for i=0,n_elements(all)-1 do $
5259 idlwave_print_info_entry,all[i],/func,separator=sep
5260 print,'>>>END OF IDLWAVE ROUTINE INFO'
5263 pro idlwave_get_sysvars
5266 if error_status ne 0 then begin
5267 print, 'Cannot get info about system variables'
5269 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5270 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5271 v = strsplit(s,' +',/regex,/extract) ; get variables
5272 for i=0,n_elements(v)-1 do begin
5273 t = [''] ; get tag list
5274 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5275 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5280 pro idlwave_get_class_tags, class
5281 res = execute('tags=tag_names({'+class+'})')
5282 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5284 ;; END OF IDLWAVE SUPPORT ROUTINES
5286 "The idl programs to get info from the shell.")
5288 (defvar idlwave-idlwave_routine_info-compiled nil
5289 "Remembers if the routine info procedure is already compiled.")
5291 (defvar idlwave-shell-temp-pro-file
)
5292 (defvar idlwave-shell-temp-rinfo-save-file
)
5293 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait
)
5294 "Query the shell for routine_info of compiled modules and update the lists."
5295 ;; Save and compile the procedure. The compiled procedure is then
5296 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5297 ;; We need to RESTORE the procedure each time we use it, since
5298 ;; the user may have killed or redefined it. In particular,
5299 ;; .RESET_SESSION will kill all user procedures.
5300 (unless (and idlwave-idlwave_routine_info-compiled
5301 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5303 (set-buffer (idlwave-find-file-noselect
5304 (idlwave-shell-temp-file 'pro
)))
5306 (insert idlwave-routine-info.pro
)
5308 (idlwave-shell-send-command
5309 (concat ".run " idlwave-shell-temp-pro-file
)
5311 ; (message "SENDING SAVE") ; ????????????????????????
5312 (idlwave-shell-send-command
5313 (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5314 (idlwave-shell-temp-file 'rinfo
))
5317 ;; Restore and execute the procedure, analyze the output
5318 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5319 (idlwave-shell-send-command
5320 (format "RESTORE, '%s' & idlwave_routine_info"
5321 idlwave-shell-temp-rinfo-save-file
)
5323 (idlwave-shell-routine-info-filter)
5324 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5327 ;; ---------------------------------------------------------------------------
5329 ;; Completion and displaying routine calling sequences
5331 (defvar idlwave-completion-help-info nil
)
5332 (defvar idlwave-completion-help-links nil
)
5333 (defvar idlwave-current-obj_new-class nil
)
5334 (defvar idlwave-complete-special nil
)
5336 (defun idlwave-complete (&optional arg module class
)
5337 "Complete a function, procedure or keyword name at point.
5338 This function is smart and figures out what can be legally completed
5340 - At the beginning of a statement it completes procedure names.
5341 - In the middle of a statement it completes function names.
5342 - after a `(' or `,' in the argument list of a function or procedure,
5343 it completes a keyword of the relevant function or procedure.
5344 - In the first arg of `OBJ_NEW', it completes a class name.
5346 When several completions are possible, a list will be displayed in the
5347 *Completions* buffer. If this list is too long to fit into the
5348 window, scrolling can be achieved by repeatedly pressing
5349 \\[idlwave-complete].
5351 The function also knows about object methods. When it needs a class
5352 name, the action depends upon `idlwave-query-class', which see. You
5353 can force IDLWAVE to ask you for a class name with a
5354 \\[universal-argument] prefix argument to this command.
5356 See also the variables `idlwave-keyword-completion-adds-equal' and
5357 `idlwave-function-completion-adds-paren'.
5359 The optional ARG can be used to specify the completion type in order
5360 to override IDLWAVE's idea of what should be completed at point.
5361 Possible values are:
5363 0 <=> query for the completion type
5365 2 <=> 'procedure-keyword
5367 4 <=> 'function-keyword
5368 5 <=> 'procedure-method
5369 6 <=> 'procedure-method-keyword
5370 7 <=> 'function-method
5371 8 <=> 'function-method-keyword
5374 As a special case, the universal argument C-u forces completion of
5375 function names in places where the default would be a keyword.
5377 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5380 For Lisp programmers only:
5381 When we force a keyword, optional argument MODULE can contain the module name.
5382 When we force a method or a method keyword, CLASS can specify the class."
5387 (or (and (integerp arg
) (not (equal arg
'(16))))
5389 (idlwave-make-force-complete-where-list arg module class
)
5391 (what (nth 2 where-list
))
5392 (idlwave-force-class-query (equal arg
'(4)))
5393 (completion-regexp-list
5394 (if (equal arg
'(16))
5395 (list (read-string (concat "Completion Regexp: "))))))
5397 (if (and module
(string-match "::" module
))
5398 (setq class
(substring module
0 (match-beginning 0))
5399 module
(substring module
(match-end 0))))
5404 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5405 (get-buffer-window "*Completions*"))
5406 (setq this-command last-command
)
5407 (idlwave-scroll-completions))
5409 ;; Complete a filename in quotes
5410 ((and (idlwave-in-quote)
5411 (not (eq what
'class
)))
5412 (idlwave-complete-filename))
5414 ;; Check for any special completion functions
5415 ((and idlwave-complete-special
5416 (idlwave-call-special idlwave-complete-special
)))
5419 (error "Nothing to complete here"))
5423 (setq idlwave-completion-help-info
'(class))
5424 (idlwave-complete-class))
5426 ((eq what
'procedure
)
5427 ;; Complete a procedure name
5428 (let* ((cw-list (nth 3 where-list
))
5429 (class-selector (idlwave-determine-class cw-list
'pro
))
5430 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5431 (idlwave-all-class-inherits class-selector
)))
5432 (isa (concat "procedure" (if class-selector
"-method" "")))
5433 (type-selector 'pro
))
5434 (setq idlwave-completion-help-info
5435 (list 'routine nil type-selector class-selector nil super-classes
))
5436 (idlwave-complete-in-buffer
5437 'procedure
(if class-selector
'method
'routine
)
5438 (idlwave-routines) 'idlwave-selector
5439 (format "Select a %s name%s"
5442 (format " (class is %s)"
5443 (if (eq class-selector t
)
5444 "unknown" class-selector
))
5447 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5449 ((eq what
'function
)
5450 ;; Complete a function name
5451 (let* ((cw-list (nth 3 where-list
))
5452 (class-selector (idlwave-determine-class cw-list
'fun
))
5453 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5454 (idlwave-all-class-inherits class-selector
)))
5455 (isa (concat "function" (if class-selector
"-method" "")))
5456 (type-selector 'fun
))
5457 (setq idlwave-completion-help-info
5458 (list 'routine nil type-selector class-selector nil super-classes
))
5459 (idlwave-complete-in-buffer
5460 'function
(if class-selector
'method
'routine
)
5461 (idlwave-routines) 'idlwave-selector
5462 (format "Select a %s name%s"
5465 (format " (class is %s)"
5466 (if (eq class-selector t
)
5467 "unknown" class-selector
))
5470 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5472 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
5474 (idlwave-complete 3))
5476 ((eq what
'procedure-keyword
)
5477 ;; Complete a procedure keyword
5478 (let* ((where (nth 3 where-list
))
5480 (method-selector name
)
5481 (type-selector 'pro
)
5482 (class (idlwave-determine-class where
'pro
))
5483 (class-selector class
)
5484 (super-classes (idlwave-all-class-inherits class-selector
))
5485 (isa (format "procedure%s-keyword" (if class
"-method" "")))
5486 (entry (idlwave-best-rinfo-assq
5487 name
'pro class
(idlwave-routines)))
5488 (list (idlwave-entry-keywords entry
'do-link
)))
5489 (unless (or entry
(eq class t
))
5490 (error "Nothing known about procedure %s"
5491 (idlwave-make-full-name class name
)))
5492 (setq list
(idlwave-fix-keywords name
'pro class list super-classes
))
5493 (unless list
(error (format "No keywords available for procedure %s"
5494 (idlwave-make-full-name class name
))))
5495 (setq idlwave-completion-help-info
5496 (list 'keyword name type-selector class-selector entry super-classes
))
5497 (idlwave-complete-in-buffer
5498 'keyword
'keyword list nil
5499 (format "Select keyword for procedure %s%s"
5500 (idlwave-make-full-name class name
)
5501 (if (or (member '("_EXTRA") list
)
5502 (member '("_REF_EXTRA") list
))
5503 " (note _EXTRA)" ""))
5505 'idlwave-attach-keyword-classes
)))
5507 ((eq what
'function-keyword
)
5508 ;; Complete a function keyword
5509 (let* ((where (nth 3 where-list
))
5511 (method-selector name
)
5512 (type-selector 'fun
)
5513 (class (idlwave-determine-class where
'fun
))
5514 (class-selector class
)
5515 (super-classes (idlwave-all-class-inherits class-selector
))
5516 (isa (format "function%s-keyword" (if class
"-method" "")))
5517 (entry (idlwave-best-rinfo-assq
5518 name
'fun class
(idlwave-routines)))
5519 (list (idlwave-entry-keywords entry
'do-link
))
5521 (unless (or entry
(eq class t
))
5522 (error "Nothing known about function %s"
5523 (idlwave-make-full-name class name
)))
5524 (setq list
(idlwave-fix-keywords name
'fun class list super-classes
))
5525 ;; OBJ_NEW: Messages mention the proper Init method
5526 (setq msg-name
(if (and (null class
)
5527 (string= (upcase name
) "OBJ_NEW"))
5528 (concat idlwave-current-obj_new-class
5529 "::Init (via OBJ_NEW)")
5530 (idlwave-make-full-name class name
)))
5531 (unless list
(error (format "No keywords available for function %s"
5533 (setq idlwave-completion-help-info
5534 (list 'keyword name type-selector class-selector nil super-classes
))
5535 (idlwave-complete-in-buffer
5536 'keyword
'keyword list nil
5537 (format "Select keyword for function %s%s" msg-name
5538 (if (or (member '("_EXTRA") list
)
5539 (member '("_REF_EXTRA") list
))
5540 " (note _EXTRA)" ""))
5542 'idlwave-attach-keyword-classes
)))
5544 (t (error "This should not happen (idlwave-complete)")))))
5546 (defvar idlwave-complete-special nil
5547 "List of special completion functions.
5548 These functions are called for each completion. Each function must
5549 check if its own special completion context is present. If yes, it
5550 should use `idlwave-complete-in-buffer' to do some completion and
5551 return t. If such a function returns t, *no further* attempts to
5552 complete other contexts will be done. If the function returns nil,
5553 other completions will be tried.")
5555 (defun idlwave-call-special (functions &rest args
)
5556 (let ((funcs functions
)
5559 (while (setq fun
(pop funcs
))
5560 (if (setq ret
(apply fun args
))
5564 (defun idlwave-make-force-complete-where-list (what &optional module class
)
5565 ;; Return an artificial WHERE specification to force the completion
5566 ;; routine to complete a specific item independent of context.
5567 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5568 ;; MODULE and CLASS can be used to specify the routine name and class.
5569 ;; The class name will also be found in MODULE if that is like "class::mod".
5570 (let* ((what-list '(("procedure") ("procedure-keyword")
5571 ("function") ("function-keyword")
5572 ("procedure-method") ("procedure-method-keyword")
5573 ("function-method") ("function-method-keyword")
5575 (module (idlwave-sintern-routine-or-method module class
))
5576 (class (idlwave-sintern-class class
))
5580 (intern (completing-read
5581 "Complete what? " what-list nil t
))))
5583 (setq what
(intern (car (nth (1- what
) what-list
)))))
5586 (assoc (symbol-name what
) what-list
))
5588 (t (error "Illegal WHAT"))))
5589 (nil-list '(nil nil nil nil
))
5590 (class-list (list nil nil
(or class t
) nil
)))
5594 ((eq what
'procedure
)
5595 (list nil-list nil-list
'procedure nil-list nil
))
5597 ((eq what
'procedure-keyword
)
5598 (let* ((class-selector nil
)
5600 (type-selector 'pro
)
5602 (idlwave-completing-read
5603 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
5604 (setq pro
(idlwave-sintern-routine pro
))
5605 (list nil-list nil-list
'procedure-keyword
5606 (list pro nil nil nil
) nil
)))
5608 ((eq what
'function
)
5609 (list nil-list nil-list
'function nil-list nil
))
5611 ((eq what
'function-keyword
)
5612 (let* ((class-selector nil
)
5614 (type-selector 'fun
)
5616 (idlwave-completing-read
5617 "Function: " (idlwave-routines) 'idlwave-selector
))))
5618 (setq func
(idlwave-sintern-routine func
))
5619 (list nil-list nil-list
'function-keyword
5620 (list func nil nil nil
) nil
)))
5622 ((eq what
'procedure-method
)
5623 (list nil-list nil-list
'procedure class-list nil
))
5625 ((eq what
'procedure-method-keyword
)
5626 (let* ((class (idlwave-determine-class class-list
'pro
))
5627 (class-selector class
)
5628 (super-classes (idlwave-all-class-inherits class-selector
))
5629 (type-selector 'pro
)
5631 (idlwave-completing-read
5632 (format "Procedure in %s class: " class-selector
)
5633 (idlwave-routines) 'idlwave-selector
))))
5634 (setq pro
(idlwave-sintern-method pro
))
5635 (list nil-list nil-list
'procedure-keyword
5636 (list pro nil class nil
) nil
)))
5638 ((eq what
'function-method
)
5639 (list nil-list nil-list
'function class-list nil
))
5641 ((eq what
'function-method-keyword
)
5642 (let* ((class (idlwave-determine-class class-list
'fun
))
5643 (class-selector class
)
5644 (super-classes (idlwave-all-class-inherits class-selector
))
5645 (type-selector 'fun
)
5647 (idlwave-completing-read
5648 (format "Function in %s class: " class-selector
)
5649 (idlwave-routines) 'idlwave-selector
))))
5650 (setq func
(idlwave-sintern-method func
))
5651 (list nil-list nil-list
'function-keyword
5652 (list func nil class nil
) nil
)))
5655 (list nil-list nil-list
'class nil-list nil
))
5657 (t (error "Illegal value for WHAT")))))
5659 (defun idlwave-completing-read (&rest args
)
5660 ;; Completing read, case insensitive
5661 (let ((old-value (default-value 'completion-ignore-case
)))
5664 (setq-default completion-ignore-case t
)
5665 (apply 'completing-read args
))
5666 (setq-default completion-ignore-case old-value
))))
5668 (defvar idlwave-shell-default-directory
)
5669 (defun idlwave-complete-filename ()
5670 "Use the comint stuff to complete a file name."
5672 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5673 (comint-completion-addsuffix nil
)
5675 (if (and (boundp 'idlwave-shell-default-directory
)
5676 (stringp idlwave-shell-default-directory
)
5677 (file-directory-p idlwave-shell-default-directory
))
5678 idlwave-shell-default-directory
5679 default-directory
)))
5680 (comint-dynamic-complete-filename)))
5682 (defun idlwave-make-full-name (class name
)
5683 ;; Make a fully qualified module name including the class name
5684 (concat (if class
(format "%s::" class
) "") name
))
5686 (defun idlwave-rinfo-assoc (name type class list
)
5687 "Like `idlwave-rinfo-assq', but sintern strings first."
5689 (idlwave-sintern-routine-or-method name class
)
5690 type
(idlwave-sintern-class class
) list
))
5692 (defun idlwave-rinfo-assq (name type class list
)
5693 ;; Works like assq, but also checks type and class
5696 (while (setq match
(assq name list
))
5697 (and (or (eq type t
)
5698 (eq (nth 1 match
) type
))
5699 (eq (nth 2 match
) class
)
5700 (throw 'exit match
))
5701 (setq list
(cdr (memq match list
)))))))
5703 (defun idlwave-rinfo-assq-any-class (name type class list
)
5704 ;; Return the first matching method on the inheritance list
5705 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
5708 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
5709 (setq classes nil
)))
5712 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
5714 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
5715 If WITH-FILE is passed, find the best rinfo entry with a file
5716 included. If KEEP-SYSTEM is set, don't prune system for compiled
5718 (let ((twins (idlwave-routine-twins
5719 (idlwave-rinfo-assq-any-class name type class list
)
5722 (when (> (length twins
) 1)
5723 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
5724 (if (and (null keep-system
)
5725 (eq 'system
(car (nth 3 (car twins
))))
5726 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
5727 (not (equal 1 syslibp
)))
5728 ;; Its a compiled syslib, so we need to remove the system entry
5729 (setq twins
(cdr twins
)))
5731 (setq twins
(delq nil
5733 (if (nth 1 (nth 3 x
)) x
))
5737 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
5739 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5740 (idlwave-best-rinfo-assq
5741 (idlwave-sintern-routine-or-method name class
)
5742 type
(idlwave-sintern-class class
) list with-file keep-system
))
5744 (defun idlwave-any-syslib (entries)
5745 "Does the entry list ENTRIES contain a syslib entry?
5746 If yes, return the index (>=1)."
5751 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
5752 (if (and file
(idlwave-syslib-p file
))
5754 (setq entries
(cdr entries
))))
5757 (defun idlwave-all-assq (key list
)
5758 "Return a list of all associations of Key in LIST."
5760 (while (setq elt
(assq key list
))
5762 (setq list
(cdr (memq elt list
))))
5765 (defun idlwave-all-method-classes (method &optional type
)
5766 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5767 When TYPE is not specified, both procedures and functions will be considered."
5769 (mapcar 'car
(idlwave-class-alist))
5774 (eq type
(nth 1 x
)))
5775 (push (nth 2 x
) rtn
)))
5776 (idlwave-all-assq method
(idlwave-routines)))
5777 (idlwave-uniquify rtn
))))
5779 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
5780 "Return all classes which have a method METHOD with keyword KEYWORD.
5781 TYPE is 'fun or 'pro.
5782 When TYPE is not specified, both procedures and functions will be considered."
5783 (if (or (null method
)
5788 (and (nth 2 x
) ; non-nil class
5789 (or (not type
) ; correct or unspecified type
5790 (eq type
(nth 1 x
)))
5791 (assoc keyword
(idlwave-entry-keywords x
))
5792 (push (nth 2 x
) rtn
)))
5793 (idlwave-all-assq method
(idlwave-routines)))
5794 (idlwave-uniquify rtn
))))
5796 (defun idlwave-members-only (list club
)
5797 "Return list of all elements in LIST which are also in CLUB."
5800 (if (member (car list
) club
)
5801 (setq rtn
(cons (car list
) rtn
)))
5802 (setq list
(cdr list
)))
5805 (defun idlwave-nonmembers-only (list club
)
5806 "Return list of all elements in LIST which are not in CLUB."
5809 (if (member (car list
) club
)
5811 (setq rtn
(cons (car list
) rtn
)))
5812 (setq list
(cdr list
)))
5815 (defun idlwave-explicit-class-listed (info)
5816 "Return whether or not the class is listed explicitly, ala a->b::c.
5817 INFO is as returned by idlwave-what-function or -procedure."
5818 (let ((apos (nth 3 info
)))
5820 (save-excursion (goto-char apos
)
5821 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5823 (defvar idlwave-determine-class-special nil
5824 "List of special functions for determining class.
5825 Must accept two arguments: `apos' and `info'")
5827 (defun idlwave-determine-class (info type
)
5828 ;; Determine the class of a routine call.
5829 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5830 ;; The second element in this structure is the class. When nil, we
5831 ;; return nil. When t, try to get the class from text properties at
5832 ;; the arrow. When the object is "self", we use the class of the
5833 ;; current routine. otherwise prompt the user for a class name.
5834 ;; Also stores the selected class as a text property at the arrow.
5835 ;; TYPE is 'fun or 'pro.
5836 (let* ((class (nth 2 info
))
5838 (nassoc (assoc (if (stringp (car info
))
5841 idlwave-query-class
))
5842 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
5843 idlwave-query-class
))
5844 (query (cond (nassoc (cdr nassoc
))
5845 (dassoc (cdr dassoc
))
5847 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
5850 (save-excursion (goto-char apos
)
5852 (let ((case-fold-search t
))
5853 (looking-at "self\\>")))))
5854 (force-query idlwave-force-class-query
)
5855 store special-class class-alist
)
5859 ;; There is an object which would like to know its class
5860 (if (and arrow
(get-text-property apos
'idlwave-class
)
5861 idlwave-store-inquired-class
5863 (setq class
(get-text-property apos
'idlwave-class
)
5864 class
(idlwave-sintern-class class
)))
5865 (if (and (eq t class
) is-self
)
5866 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
5868 ;; Before prompting, try any special class determination routines
5869 (when (and (eq t class
)
5870 idlwave-determine-class-special
5873 (idlwave-call-special idlwave-determine-class-special apos
))
5875 (setq class
(idlwave-sintern-class special-class
)
5876 store idlwave-store-inquired-class
)))
5878 ;; Prompt for a class, if we need to
5879 (when (and (eq class t
)
5880 (or force-query query
))
5882 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
5884 (idlwave-sintern-class
5886 ((and (= (length class-alist
) 0) (not force-query
))
5887 (error "No classes available with method %s" (car info
)))
5888 ((and (= (length class-alist
) 1) (not force-query
))
5889 (car (car class-alist
)))
5891 (setq store idlwave-store-inquired-class
)
5892 (idlwave-completing-read
5893 (format "Class%s: " (if (stringp (car info
))
5894 (format " for %s method %s"
5897 class-alist nil nil nil
'idlwave-class-history
))))))
5899 ;; Store it, if requested
5900 (when (and class
(not (eq t class
)))
5901 ;; We have a real class here
5902 (when (and store arrow
)
5904 (add-text-properties
5906 `(idlwave-class ,class face
,idlwave-class-arrow-face
5909 (setf (nth 2 info
) class
))
5912 ;; Default as fallback
5915 (defvar type-selector
)
5916 (defvar class-selector
)
5917 (defvar method-selector
)
5918 (defvar super-classes
)
5919 (defun idlwave-selector (a)
5920 (and (eq (nth 1 a
) type-selector
)
5921 (or (and (nth 2 a
) (eq class-selector t
))
5922 (eq (nth 2 a
) class-selector
)
5923 (memq (nth 2 a
) super-classes
))))
5925 (defun idlwave-add-file-link-selector (a)
5926 ;; Record a file link, if any, for the tested names during selection.
5927 (let ((sel (idlwave-selector a
)) file
)
5928 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
5929 (push (cons (car a
) file
) idlwave-completion-help-links
))
5933 (defun idlwave-where ()
5934 "Find out where we are.
5935 The return value is a list with the following stuff:
5936 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5938 PRO-LIST (PRO POINT CLASS ARROW)
5939 FUNC-LIST (FUNC POINT CLASS ARROW)
5940 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5941 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5943 LAST-CHAR last relevant character before point (non-white non-comment,
5944 not part of current identifier or leading slash).
5946 In the lists, we have these meanings:
5949 POINT: Where is this
5950 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5951 ARROW: Location of the arrow"
5953 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5954 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
5955 (func-entry (idlwave-what-function bos
))
5956 (func (car func-entry
))
5957 (func-class (nth 1 func-entry
))
5958 (func-arrow (nth 2 func-entry
))
5959 (func-point (or (nth 3 func-entry
) 0))
5960 (func-level (or (nth 4 func-entry
) 0))
5961 (pro-entry (idlwave-what-procedure bos
))
5962 (pro (car pro-entry
))
5963 (pro-class (nth 1 pro-entry
))
5964 (pro-arrow (nth 2 pro-entry
))
5965 (pro-point (or (nth 3 pro-entry
) 0))
5966 (last-char (idlwave-last-valid-char))
5967 (case-fold-search t
)
5968 (match-string (buffer-substring bos
(point)))
5969 cw cw-mod cw-arrow cw-class cw-point
)
5970 (if (< func-point pro-point
) (setq func nil
))
5972 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
5976 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
5978 (buffer-substring pro-point
(point))
5980 (setq cw
'procedure cw-class pro-class cw-point pro-point
5981 cw-arrow pro-arrow
))
5982 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
5985 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
5988 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
5992 (> func-point pro-point
)
5994 (memq last-char
'(?\
( ?
,)))
5995 (setq cw
'function-keyword cw-mod func cw-point func-point
5996 cw-class func-class cw-arrow func-arrow
))
5997 ((and pro
(eq last-char ?
,))
5998 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
5999 cw-class pro-class cw-arrow pro-arrow
))
6000 ; ((member last-char '(?\' ?\) ?\] ?!))
6001 ; ;; after these chars, a function makes no sense
6002 ; ;; FIXME: I am sure there can be more in this list
6003 ; ;; FIXME: Do we want to do this at all?
6005 ;; Everywhere else we try a function.
6009 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6010 (setq cw-arrow
(copy-marker (match-beginning 0))
6011 cw-class
(if (match-end 4)
6012 (idlwave-sintern-class (match-string 4))
6014 (list (list pro pro-point pro-class pro-arrow
)
6015 (list func func-point func-class func-arrow
)
6017 (list cw-mod cw-point cw-class cw-arrow
)
6020 (defun idlwave-this-word (&optional class
)
6021 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6022 (setq class
(or class
"a-zA-Z0-9$_."))
6025 (progn (skip-chars-backward class
) (point))
6026 (progn (skip-chars-forward class
) (point)))))
6028 (defun idlwave-what-function (&optional bound
)
6029 ;; Find out if point is within the argument list of a function.
6030 ;; The return value is ("function-name" class arrow-start (point) level).
6031 ;; Level is 1 on the top level parentheses, higher further down.
6033 ;; If the optional BOUND is an integer, bound backwards directed
6034 ;; searches to this point.
6040 func arrow-start class
)
6041 (idlwave-with-special-syntax
6044 (narrow-to-region (max 1 (or bound
0)) (point-max))
6045 ;; move back out of the current parenthesis
6046 (while (condition-case nil
6047 (progn (up-list -
1) t
)
6051 (when (and (= (following-char) ?\
()
6053 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6055 (setq func
(match-string 2)
6056 func-point
(goto-char (match-beginning 2))
6058 (if (re-search-backward
6059 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6060 (setq arrow-start
(copy-marker (match-beginning 0))
6061 class
(or (match-string 2) t
)))
6065 (idlwave-sintern-routine-or-method func class
)
6066 (idlwave-sintern-class class
)
6067 arrow-start func-point cnt
)))
6069 (throw 'exit nil
)))))))
6071 (defun idlwave-what-procedure (&optional bound
)
6072 ;; Find out if point is within the argument list of a procedure.
6073 ;; The return value is ("procedure-name" class arrow-pos (point)).
6075 ;; If the optional BOUND is an integer, bound backwards directed
6076 ;; searches to this point.
6077 (let ((pos (point)) pro-point
6078 pro class arrow-start string
)
6080 ;;(idlwave-beginning-of-statement)
6081 (idlwave-start-of-substatement 'pre
)
6082 (setq string
(buffer-substring (point) pos
))
6084 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6085 (setq pro
(match-string 1 string
)
6086 pro-point
(+ (point) (match-beginning 1)))
6087 (if (and (idlwave-skip-object)
6088 (setq string
(buffer-substring (point) pos
))
6090 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6092 (setq pro
(if (match-beginning 4)
6093 (match-string 4 string
))
6094 pro-point
(if (match-beginning 4)
6095 (+ (point) (match-beginning 4))
6097 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6098 class
(or (match-string 3 string
) t
)))))
6099 (list (idlwave-sintern-routine-or-method pro class
)
6100 (idlwave-sintern-class class
)
6104 (defun idlwave-skip-object ()
6105 ;; If there is an object at point, move over it and return t.
6106 (let ((pos (point)))
6109 (skip-chars-forward " ") ; white space
6110 (skip-chars-forward "*") ; de-reference
6112 ((looking-at idlwave-identifier
)
6113 (goto-char (match-end 0)))
6114 ((eq (following-char) ?\
()
6116 (t (throw 'exit nil
)))
6119 (cond ((eq (following-char) ?.
)
6121 (if (not (looking-at idlwave-identifier
))
6123 (goto-char (match-end 0)))
6124 ((memq (following-char) '(?\
( ?\
[))
6127 (error (throw 'exit nil
))))
6128 (t (throw 'endwhile t
)))))
6129 (if (looking-at "[ \t]*->")
6130 (throw 'exit
(setq pos
(match-beginning 0)))
6131 (throw 'exit nil
))))
6135 (defun idlwave-last-valid-char ()
6136 "Return the last character before point which is not white or a comment
6137 and also not part of the current identifier. Since we do this in
6138 order to identify places where keywords are, we consider the initial
6139 `/' of a keyword as part of the identifier.
6140 This function is not general, can only be used for completion stuff."
6143 ;; skip the current identifier
6144 (skip-chars-backward "a-zA-Z0-9_$")
6145 ;; also skip a leading slash which might be belong to the keyword
6146 (if (eq (preceding-char) ?
/)
6148 ;; FIXME: does not check if this is a valid identifier
6150 (skip-chars-backward " \t")
6152 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6153 ((eq (preceding-char) ?
\n)
6154 (beginning-of-line 0)
6155 (if (looking-at "\\([^;\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6156 ;; continuation line
6157 (goto-char (match-end 1))
6159 (t (throw 'exit
(preceding-char))))))))
6161 (defvar idlwave-complete-after-success-form nil
6162 "A form to evaluate after successful completion.")
6163 (defvar idlwave-complete-after-success-form-force nil
6164 "A form to evaluate after completion selection in *Completions* buffer.")
6165 (defconst idlwave-completion-mark
(make-marker)
6166 "A mark pointing to the beginning of the completion string.")
6168 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6169 &optional prepare-display-function
6171 "Perform TYPE completion of word before point against LIST.
6172 SELECTOR is the PREDICATE argument for the completion function. Show
6173 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6174 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6175 used only once, for `all-completions', and can be used to, e.g.,
6176 accumulate information on matching completions."
6177 (let* ((completion-ignore-case t
)
6178 beg
(end (point)) slash part spart completion all-completions
6182 (error (concat prompt
": No completions available")))
6184 ;; What is already in the buffer?
6186 (skip-chars-backward "a-zA-Z0-9_$")
6187 (setq slash
(eq (preceding-char) ?
/)
6189 idlwave-complete-after-success-form
6190 (list 'idlwave-after-successful-completion
6191 (list 'quote type
) slash beg
)
6192 idlwave-complete-after-success-form-force
6193 (list 'idlwave-after-successful-completion
6194 (list 'quote type
) slash
(list 'quote
'force
))))
6197 (setq part
(buffer-substring beg end
)
6198 dpart
(downcase part
)
6199 spart
(idlwave-sintern stype part
)
6200 completion
(try-completion part list selector
)
6201 dcompletion
(if (stringp completion
) (downcase completion
))
6202 idlwave-completion-help-links nil
)
6205 ;; nothing available.
6206 (error (concat prompt
": no completion for \"%s\"") part
))
6207 ((and (not (equal dpart dcompletion
))
6208 (not (eq t completion
)))
6209 ;; We can add something
6210 (delete-region beg end
)
6211 (if (and (string= part dpart
)
6212 (or (not (string= part
""))
6213 idlwave-complete-empty-string-as-lower-case
)
6214 (not idlwave-completion-force-default-case
))
6215 (insert dcompletion
)
6216 (insert completion
))
6217 (if (eq t
(try-completion completion list selector
))
6218 ;; Now this is a unique match
6219 (idlwave-after-successful-completion type slash beg
))
6221 ((or (eq completion t
)
6222 (and (= 1 (length (setq all-completions
6224 (all-completions part list
6225 (or special-selector
6227 (equal dpart dcompletion
)))
6228 ;; This is already complete
6229 (idlwave-after-successful-completion type slash beg
)
6230 (message "%s is already the complete %s" part isa
)
6233 ;; We cannot add something - offer a list.
6234 (message "Making completion list...")
6236 (unless idlwave-completion-help-links
; already set somewhere?
6237 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6238 (let ((link (get-text-property 0 'link
(car x
))))
6240 (push (cons (car x
) link
)
6241 idlwave-completion-help-links
))))
6243 (let* ((list all-completions
)
6244 ;; "complete" means, this is already a valid completion
6245 (complete (memq spart all-completions
))
6246 (completion-highlight-first-word-only t
)) ; XEmacs
6247 ; (completion-fixup-function ; Emacs
6248 ; (lambda () (and (eq (preceding-char) ?>)
6249 ; (re-search-backward " <" beg t)))))
6251 (setq list
(sort list
(lambda (a b
)
6252 (string< (downcase a
) (downcase b
)))))
6253 (if prepare-display-function
6254 (setq list
(funcall prepare-display-function list
)))
6255 (if (and (string= part dpart
)
6256 (or (not (string= part
""))
6257 idlwave-complete-empty-string-as-lower-case
)
6258 (not idlwave-completion-force-default-case
))
6259 (setq list
(mapcar (lambda (x)
6261 (setcar x
(downcase (car x
)))
6262 (setq x
(downcase x
)))
6265 (idlwave-display-completion-list list prompt beg complete
))
6268 (defun idlwave-complete-class ()
6269 "Complete a class at point."
6271 ;; Call `idlwave-routines' to make sure the class list will be available
6273 ;; Check for the special case of completing empty string after pro/function
6274 (if (let ((case-fold-search t
))
6277 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6279 (goto-char (point-min))
6281 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6282 ;; Yank the full class specification
6283 (insert (match-string 2))
6284 ;; Do the completion, using list gathered from `idlwave-routines'
6285 (idlwave-complete-in-buffer
6286 'class
'class
(idlwave-class-alist) nil
6287 "Select a class" "class"
6288 '(lambda (list) ;; Push it to help-links if system help available
6290 (let* ((entry (idlwave-class-info x
))
6291 (link (nth 1 (assq 'link entry
))))
6292 (if link
(push (cons x link
)
6293 idlwave-completion-help-links
))
6297 (defun idlwave-attach-classes (list type show-classes
)
6298 ;; Attach the proper class list to a LIST of completion items.
6299 ;; TYPE, when 'kwd, shows classes for method keywords, when
6300 ;; 'class-tag, for class tags, and otherwise for methods.
6301 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6302 (if (or (null show-classes
) ; don't want to see classes
6303 (null class-selector
) ; not a method call
6305 (stringp class-selector
) ; the class is already known
6306 (not super-classes
))) ; no possibilities for inheritance
6307 ;; In these cases, we do not have to do anything
6309 (let* ((do-prop (and (>= show-classes
0)
6310 (>= emacs-major-version
21)))
6311 (do-buf (not (= show-classes
0)))
6312 ;; (do-dots (featurep 'xemacs))
6314 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6315 (cons class-selector super-classes
)))
6316 (max (abs show-classes
))
6317 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6318 classes nclasses class-info space
)
6322 (if (eq type
'class-tag
)
6323 ;; Just one class for tags
6326 (idlwave-class-or-superclass-with-tag class-selector x
)))
6327 ;; Multiple classes for method or method-keyword
6330 (idlwave-all-method-keyword-classes
6331 method-selector x type-selector
)
6332 (idlwave-all-method-classes x type-selector
)))
6336 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6338 (setq nclasses
(length classes
))
6339 ;; Make the separator between item and class-info
6341 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6344 ;; We do want info in the buffer
6345 (if (<= nclasses max
)
6346 (setq class-info
(concat
6348 "<" (mapconcat 'identity classes
",") ">"))
6349 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6350 (setq class-info nil
))
6352 ;; We do want properties
6353 (setq x
(copy-sequence x
))
6354 (put-text-property 0 (length x
)
6355 'help-echo
(mapconcat 'identity classes
" ")
6362 (defun idlwave-attach-method-classes (list)
6363 ;; Call idlwave-attach-classes with method parameters
6364 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6365 (defun idlwave-attach-keyword-classes (list)
6366 ;; Call idlwave-attach-classes with keyword parameters
6367 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6368 (defun idlwave-attach-class-tag-classes (list)
6369 ;; Call idlwave-attach-classes with class structure tags
6370 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6373 ;;----------------------------------------------------------------------
6374 ;;----------------------------------------------------------------------
6375 ;;----------------------------------------------------------------------
6376 ;;----------------------------------------------------------------------
6377 ;;----------------------------------------------------------------------
6379 (defun idlwave-pset (item)
6382 (defun idlwave-popup-select (ev list title
&optional sort
)
6383 "Select an item in LIST with a popup menu.
6384 TITLE is the title to put atop the popup. If SORT is non-nil,
6385 sort the list before displaying"
6386 (let ((maxpopup idlwave-max-popup-menu-items
)
6389 ((= 1 (length list
))
6390 (setq rtn
(car list
)))
6392 (if sort
(setq list
(sort list
(lambda (a b
)
6393 (string< (upcase a
) (upcase b
))))))
6395 (append (list title
)
6396 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6399 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6400 (setq resp
(get-popup-menu-response menu
))
6401 (funcall (event-function resp
) (event-object resp
)))
6403 (if sort
(setq list
(sort list
(lambda (a b
)
6404 (string< (upcase a
) (upcase b
))))))
6405 (setq menu
(cons title
6408 (mapcar (lambda(x) (cons x x
)) list
)))))
6409 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6410 (setq rtn
(x-popup-menu ev menu
))))
6413 (defun idlwave-split-menu-xemacs (menu N
)
6414 "Split the MENU into submenus of maximum length N."
6415 (if (<= (length menu
) (1+ N
))
6416 ;; No splitting needed
6418 (let* ((title (car menu
))
6419 (entries (cdr menu
))
6424 (while (and entries
(< cnt N
))
6426 nextmenu
(cons (car entries
) nextmenu
)
6427 entries
(cdr entries
)))
6428 (setq nextmenu
(nreverse nextmenu
))
6429 (setq nextmenu
(cons (format "%s...%s"
6430 (aref (car nextmenu
) 0)
6431 (aref (nth (1- cnt
) nextmenu
) 0))
6433 (setq menu
(cons nextmenu menu
)
6438 (defun idlwave-split-menu-emacs (menu N
)
6439 "Split the MENU into submenus of maximum length N."
6440 (if (<= (length (nth 1 menu
)) (1+ N
))
6441 ;; No splitting needed
6443 (let* ((title (car menu
))
6444 (entries (cdr (nth 1 menu
)))
6449 (while (and entries
(< cnt N
))
6451 nextmenu
(cons (car entries
) nextmenu
)
6452 entries
(cdr entries
)))
6453 (setq nextmenu
(nreverse nextmenu
))
6455 (setq nextmenu
(cons (format "%s...%s"
6456 (car (car nextmenu
))
6457 (car (nth (1- cnt
) nextmenu
)))
6459 (setq menu
(cons nextmenu menu
)
6462 (setq menu
(nreverse menu
))
6463 (setq menu
(cons title menu
))
6466 (defvar idlwave-completion-setup-hook nil
)
6468 (defun idlwave-scroll-completions (&optional message
)
6469 "Scroll the completion window on this frame."
6470 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
6471 (win (selected-window)))
6474 (select-window cwin
)
6477 (error (if (and (listp last-command
)
6478 (nth 2 last-command
))
6481 (eval idlwave-complete-after-success-form
))
6482 (set-window-start cwin
(point-min)))))
6483 (and message
(message message
)))
6484 (select-window win
))))
6486 (defun idlwave-display-completion-list (list &optional message beg complete
)
6487 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6488 (unless (and (get-buffer-window "*Completions*")
6489 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
6490 (move-marker idlwave-completion-mark beg
)
6491 (setq idlwave-before-completion-wconf
(current-window-configuration)))
6493 (if (featurep 'xemacs
)
6494 (idlwave-display-completion-list-xemacs
6496 (idlwave-display-completion-list-emacs list
))
6498 ;; Store a special value in `this-command'. When `idlwave-complete'
6499 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6500 (setq this-command
(list 'idlwave-display-completion-list message complete
))
6502 ;; Mark the completions buffer as created by cib
6503 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
6505 ;; Fontify the classes
6506 (if (and idlwave-completion-fontify-classes
6508 (idlwave-completion-fontify-classes))
6511 (run-hooks 'idlwave-completion-setup-hook
)
6513 ;; Display the message
6514 (message (or message
"Making completion list...done")))
6516 (defun idlwave-choose (function &rest args
)
6517 "Call FUNCTION as a completion chooser and pass ARGS to it."
6518 (let ((completion-ignore-case t
)) ; install correct value
6519 (apply function args
))
6520 (if (and (eq major-mode
'idlwave-shell-mode
)
6521 (boundp 'font-lock-mode
)
6522 (not font-lock-mode
))
6523 ;; For the shell, remove the fontification of the word before point
6524 (let ((beg (save-excursion
6525 (skip-chars-backward "a-zA-Z0-9_")
6527 (remove-text-properties beg
(point) '(face nil
))))
6528 (eval idlwave-complete-after-success-form-force
))
6530 (defun idlwave-keyboard-quit ()
6533 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
6534 (idlwave-restore-wconf-after-completion))
6537 (defun idlwave-restore-wconf-after-completion ()
6538 "Restore the old (before completion) window configuration."
6539 (and idlwave-completion-restore-window-configuration
6540 idlwave-before-completion-wconf
6541 (set-window-configuration idlwave-before-completion-wconf
)))
6543 (defun idlwave-one-key-select (sym prompt delay
)
6544 "Make the user select an element from the alist in the variable SYM.
6545 The keys of the alist are expected to be strings. The function returns the
6546 car of the selected association.
6547 To do this, PROMPT is displayed and and the user must hit a letter key to
6548 select an entry. If the user does not reply within DELAY seconds, a help
6549 window with the options is displayed automatically.
6550 The key which is associated with each option is generated automatically.
6551 First, the strings are checked for preselected keys, like in \"[P]rint\".
6552 If these don't exist, a letter in the string is automatically selected."
6553 (let* ((alist (symbol-value sym
))
6554 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
6555 '(fit-window-to-buffer)))
6557 ;; First check the cache
6558 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
6559 (setq keys-alist
(get sym
:one-key-alist-cache
))
6560 ;; Need to make new list
6561 (setq keys-alist
(idlwave-make-one-key-alist alist
))
6562 (put sym
:one-key-alist-cache keys-alist
)
6563 (put sym
:one-key-alist-last alist
))
6564 ;; Display prompt and wait for quick reply
6565 (message "%s[%s]" prompt
6566 (mapconcat (lambda(x) (char-to-string (car x
)))
6569 ;; No quick reply: Show help
6570 (save-window-excursion
6571 (with-output-to-temp-buffer "*Completions*"
6576 (setq char
(read-char)))
6577 (setq char
(read-char)))
6579 ;; Return the selected result
6580 (nth 2 (assoc char keys-alist
))))
6582 ;; Used for, e.g., electric debug super-examine.
6583 (defun idlwave-make-one-key-alist (alist)
6584 "Make an alist for single key selection."
6585 (let ((l alist
) keys-alist name start char help
6587 (case-fold-search nil
))
6589 (setq name
(car (car l
))
6592 ;; First check if the configuration predetermined a key
6593 (if (string-match "\\[\\(.\\)\\]" name
)
6595 (setq char
(string-to-char (downcase (match-string 1 name
)))
6596 help
(format "%c: %s" char name
)
6597 keys-alist
(cons (list char help name
) keys-alist
))
6599 ;; Then check for capital letters
6601 (while (string-match "[A-Z]" name start
)
6602 (setq start
(match-end 0)
6603 char
(string-to-char (downcase (match-string 0 name
))))
6604 (if (not (assoc char keys-alist
))
6606 (setq help
(format "%c: %s" char
6608 (concat "[" (match-string 0 name
) "]")
6610 keys-alist
(cons (list char help name
) keys-alist
))
6612 ;; Now check for lowercase letters
6614 (while (string-match "[a-z]" name start
)
6615 (setq start
(match-end 0)
6616 char
(string-to-char (match-string 0 name
)))
6617 (if (not (assoc char keys-alist
))
6619 (setq help
(format "%c: %s" char
6621 (concat "[" (match-string 0 name
) "]")
6623 keys-alist
(cons (list char help name
) keys-alist
))
6625 ;; Bummer, nothing found! Use a stupid number
6626 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
6627 help
(format "%c: %s" char name
)
6628 keys-alist
(cons (list char help name
) keys-alist
))))
6629 (nreverse keys-alist
)))
6631 (defun idlwave-set-local (var value
&optional buffer
)
6632 "Set the buffer-local value of VAR in BUFFER to VALUE."
6634 (set-buffer (or buffer
(current-buffer)))
6635 (set (make-local-variable var
) value
)))
6637 (defun idlwave-local-value (var &optional buffer
)
6638 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6640 (set-buffer (or buffer
(current-buffer)))
6641 (and (local-variable-p var
(current-buffer))
6642 (symbol-value var
))))
6644 ;; In XEmacs, we can use :activate-callback directly to advice the
6645 ;; choose functions. We use the private keymap only for the online
6648 (defvar idlwave-completion-map nil
6649 "Keymap for completion-list-mode with idlwave-complete.")
6651 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
6652 (with-output-to-temp-buffer "*Completions*"
6653 (apply 'display-completion-list list
6654 ':activate-callback
'idlwave-default-choose-completion
6657 (set-buffer "*Completions*")
6659 (or idlwave-completion-map
6660 (setq idlwave-completion-map
6661 (idlwave-make-modified-completion-map-xemacs
6662 (current-local-map)))))))
6664 (defun idlwave-default-choose-completion (&rest args
)
6665 "Execute `default-choose-completion' and then restore the win-conf."
6666 (apply 'idlwave-choose
'default-choose-completion args
))
6668 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6669 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6670 (let ((new-map (copy-keymap old-map
)))
6671 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
6672 (define-key new-map [button3] (lambda ()
6674 (setq this-command last-command)))
6677 ;; In Emacs we also replace keybindings in the completion
6678 ;; map in order to install our wrappers.
6680 (defun idlwave-display-completion-list-emacs (list)
6681 "Display completion list and install the choose wrappers."
6682 (with-output-to-temp-buffer "*Completions*"
6683 (display-completion-list list))
6685 (set-buffer "*Completions*")
6687 (or idlwave-completion-map
6688 (setq idlwave-completion-map
6689 (idlwave-make-modified-completion-map-emacs
6690 (current-local-map)))))))
6692 (defun idlwave-make-modified-completion-map-emacs (old-map)
6693 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6694 (let ((new-map (copy-keymap old-map)))
6695 (substitute-key-definition
6696 'choose-completion 'idlwave-choose-completion new-map)
6697 (substitute-key-definition
6698 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6699 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6702 (defun idlwave-choose-completion (&rest args)
6703 "Choose the completion that point is in or next to."
6705 (apply 'idlwave-choose 'choose-completion args))
6707 (defun idlwave-mouse-choose-completion (&rest args)
6708 "Click on an alternative in the `*Completions*' buffer to choose it."
6710 (apply 'idlwave-choose 'mouse-choose-completion args))
6712 ;;----------------------------------------------------------------------
6713 ;;----------------------------------------------------------------------
6715 ;;; ------------------------------------------------------------------------
6716 ;;; Stucture parsing code, and code to manage class info
6719 ;; - Go again over the documentation how to write a completion
6720 ;; plugin. It is in self.el, but currently still very bad.
6721 ;; This could be in a separate file in the distribution, or
6722 ;; in an appendix for the manual.
6724 (defvar idlwave-struct-skip
6725 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
6726 "Regexp for skipping continued blank or comment-only lines in
6729 (defvar idlwave-struct-tag-regexp
6730 (concat "[{,]" ;leading comma/brace
6731 idlwave-struct-skip ; 4 groups
6732 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
6733 "[ \t]*:") ; the final colon
6734 "Regexp for structure tags.")
6736 (defun idlwave-struct-tags ()
6737 "Return a list of all tags in the structure defined at point.
6738 Point is expected just before the opening `{' of the struct definition."
6740 (let* ((borders (idlwave-struct-borders))
6746 (narrow-to-region beg end)
6747 (while (re-search-forward idlwave-struct-tag-regexp end t)
6748 ;; Check if we are still on the top level of the structure.
6749 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6751 (push (match-string-no-properties 5) tags))
6752 (goto-char (match-end 0))))
6755 (defun idlwave-find-struct-tag (tag)
6756 "Find a given TAG in the structure defined at point."
6757 (let* ((borders (idlwave-struct-borders))
6760 (case-fold-search t))
6761 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6764 (defun idlwave-struct-inherits ()
6765 "Return a list of all `inherits' names in the struct at point.
6766 Point is expected just before the opening `{' of the struct definition."
6768 (let* ((borders (idlwave-struct-borders))
6771 (case-fold-search t)
6775 (narrow-to-region beg end)
6776 (while (re-search-forward
6777 (concat "[{,]" ;leading comma/brace
6778 idlwave-struct-skip ; 4 groups
6779 "inherits" ; The INHERITS tag
6780 idlwave-struct-skip ; 4 more
6781 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
6783 ;; Check if we are still on the top level of the structure.
6784 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6786 (push (match-string-no-properties 9) names))
6787 (goto-char (match-end 0))))
6790 (defun idlwave-in-structure ()
6791 "Return t if point is inside an IDL structure definition."
6792 (let ((beg (point)))
6794 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6795 (if (idlwave-find-structure-definition nil nil 'back)
6796 (let ((borders (idlwave-struct-borders)))
6797 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6798 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6800 (defun idlwave-struct-borders ()
6801 "Return the borders of the {...} after point as a cons cell."
6804 (skip-chars-forward "^{")
6806 (condition-case nil (forward-list 1)
6807 (error (goto-char beg)))
6808 (cons beg (point)))))
6810 (defun idlwave-find-structure-definition (&optional var name bound)
6811 "Search forward for a structure definition. If VAR is non-nil,
6812 search for a structure assigned to variable VAR. If NAME is non-nil,
6813 search for a named structure NAME, if a string, or a generic named
6814 structure otherwise. If BOUND is an integer, limit the search. If
6815 BOUND is the symbol `all', we search first back and then forward
6816 through the entire file. If BOUND is the symbol `back' we search only
6818 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6819 (case-fold-search t)
6820 (lim (if (integerp bound) bound nil))
6823 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6828 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
6829 ;; Just a generic name
6830 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
6832 (if (or (and (or (eq bound 'all) (eq bound 'back))
6833 (re-search-backward re nil t))
6834 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6836 (goto-char (match-beginning 3))
6837 (match-string-no-properties 5)))))
6839 (defvar idlwave-class-info nil)
6840 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
6841 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
6843 (add-hook 'idlwave-update-rinfo-hook
6844 (lambda () (setq idlwave-class-reset t)))
6845 (add-hook 'idlwave-after-load-rinfo-hook
6846 (lambda () (setq idlwave-class-info nil)))
6848 (defun idlwave-class-info (class)
6850 (if idlwave-class-info
6851 (if idlwave-class-reset
6853 idlwave-class-reset nil
6854 idlwave-class-info ; Remove any visited in a buffer
6858 (idlwave-class-file-or-buffer
6859 (or (cdr (assq 'found-in x)) (car x)))))
6863 idlwave-class-info))))
6864 ;; Info is nil, put in the system stuff to start.
6865 (setq idlwave-class-info idlwave-system-class-info)
6866 (setq list idlwave-class-info)
6867 (while (setq entry (pop list))
6868 (idlwave-sintern-class-info entry)))
6869 (setq class (idlwave-sintern-class class))
6870 (or (assq class idlwave-class-info)
6871 (progn (idlwave-scan-class-info class)
6872 (assq class idlwave-class-info)))))
6874 (defun idlwave-sintern-class-info (entry)
6875 "Sintern the class names in a class-info entry."
6876 (let ((taglist (assq 'tags entry))
6877 (inherits (assq 'inherits entry)))
6878 (setcar entry (idlwave-sintern-class (car entry) 'set))
6880 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6883 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
6884 "Find class structure definition(s)
6885 If ALL-HOOK is set, find all named structure definitions in a given
6886 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
6887 set, look for the name__define pro, and inside of it, for the ALT-CLASS
6888 class/struct definition"
6889 (let ((case-fold-search t) end-lim list name)
6890 (when (re-search-forward
6891 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6894 ;; For everything there
6895 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
6897 (idlwave-find-structure-definition nil t end-lim))
6898 (funcall all-hook name)))
6899 (idlwave-find-structure-definition nil (or alt-class class))))))
6902 (defun idlwave-class-file-or-buffer (class)
6903 "Find buffer visiting CLASS definition"
6904 (let* ((pro (concat (downcase class) "__define"))
6905 (file (idlwave-routine-source-file
6906 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6907 (idlwave-routines))))))
6908 (cons file (if file (idlwave-get-buffer-visiting file)))))
6911 (defun idlwave-scan-class-info (class)
6912 "Scan all class and named structure info in the class__define pro"
6913 (let* ((idlwave-auto-routine-info-updates nil)
6914 (filebuf (idlwave-class-file-or-buffer class))
6915 (file (car filebuf))
6917 (class (idlwave-sintern-class class)))
6920 (and ;; neither a regular file nor a visited buffer
6922 (not (file-regular-p file))))
6923 nil ; Cannot find the file/buffer to get any info
6925 (if buf (set-buffer buf)
6926 ;; Read the file in temporarily
6927 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6929 (unless (eq major-mode 'idlwave-mode)
6931 (insert-file-contents file))
6934 (idlwave-find-class-definition class
6935 ;; Scan all of the structures found there
6937 (let* ((this-class (idlwave-sintern-class name))
6940 (cons 'tags (idlwave-struct-tags))
6941 (cons 'inherits (idlwave-struct-inherits)))))
6942 (if (not (eq this-class class))
6943 (setq entry (nconc entry (list (cons 'found-in class)))))
6944 (idlwave-sintern-class-info entry)
6945 (push entry idlwave-class-info)))))))))
6947 (defun idlwave-class-found-in (class)
6948 "Return the FOUND-IN property of the class."
6949 (cdr (assq 'found-in (idlwave-class-info class))))
6950 (defun idlwave-class-tags (class)
6951 "Return the native tags in CLASS."
6952 (cdr (assq 'tags (idlwave-class-info class))))
6953 (defun idlwave-class-inherits (class)
6954 "Return the direct superclasses of CLASS."
6955 (cdr (assq 'inherits (idlwave-class-info class))))
6958 (defun idlwave-all-class-tags (class)
6959 "Return a list of native and inherited tags in CLASS."
6961 (apply 'append (mapcar 'idlwave-class-tags
6962 (cons class (idlwave-all-class-inherits class))))
6964 (idlwave-class-tag-reset)
6965 (error "%s" (error-message-string err)))))
6968 (defun idlwave-all-class-inherits (class)
6969 "Return a list of all superclasses of CLASS (recursively expanded).
6970 The list is cached in `idlwave-class-info' for faster access."
6972 ((not idlwave-support-inheritance) nil)
6973 ((eq class nil) nil)
6976 (let ((info (idlwave-class-info class))
6978 (if (setq entry (assq 'all-inherits info))
6980 ;; Save the depth of inheritance scan to check for circular references
6981 (let ((inherits (mapcar (lambda (x) (cons x 0))
6982 (idlwave-class-inherits class)))
6983 rtn all-inherits cl)
6985 (setq cl (pop inherits)
6986 rtn (cons (car cl) rtn)
6987 inherits (append (mapcar (lambda (x)
6988 (cons x (1+ (cdr cl))))
6989 (idlwave-class-inherits (car cl)))
6991 (if (> (cdr cl) 999)
6993 "Class scan: inheritance depth exceeded. Circular inheritance?")
6995 (setq all-inherits (nreverse rtn))
6996 (nconc info (list (cons 'all-inherits all-inherits)))
6999 (defun idlwave-entry-keywords (entry &optional record-link)
7000 "Return the flat entry keywords alist from routine-info entry.
7001 If RECORD-LINK is non-nil, the keyword text is copied and a text
7002 property indicating the link is added."
7006 (let ((file (car key-list)))
7007 (mapcar (lambda (key-cons)
7008 (let ((key (car key-cons))
7009 (link (cdr key-cons)))
7010 (when (and record-link file)
7011 (setq key (copy-sequence key))
7018 (concat idlwave-html-link-sep
7019 (number-to-string link))))
7021 (push (list key) kwds)))
7026 (defun idlwave-entry-find-keyword (entry keyword)
7027 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7031 (let ((file (car key-list))
7032 (kwd (assoc keyword (cdr key-list))))
7034 (setq kwd (cons (car kwd)
7035 (if (and file (cdr kwd))
7037 idlwave-html-link-sep
7038 (number-to-string (cdr kwd)))
7040 (throw 'exit kwd))))
7043 ;;==========================================================================
7045 ;; Completing class structure tags. This is a completion plugin.
7046 ;; The necessary taglist is constructed dynamically
7048 (defvar idlwave-current-tags-class nil)
7049 (defvar idlwave-current-class-tags nil)
7050 (defvar idlwave-current-native-class-tags nil)
7051 (defvar idlwave-sint-class-tags nil)
7052 (idlwave-new-sintern-type 'class-tag)
7053 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7054 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7056 (defun idlwave-complete-class-structure-tag ()
7057 "Complete a structure tag on a `self' argument in an object method."
7060 (case-fold-search t))
7062 ;; Check if the context is right
7063 (skip-chars-backward "a-zA-Z0-9._$")
7064 (and (< (point) (- pos 4))
7065 (looking-at "self\\.")))
7066 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7067 (super-classes (idlwave-all-class-inherits class-selector)))
7068 ;; Check if we are in a class routine
7069 (unless class-selector
7070 (error "Not in a method procedure or function"))
7071 ;; Check if we need to update the "current" class
7072 (if (not (equal class-selector idlwave-current-tags-class))
7073 (idlwave-prepare-class-tag-completion class-selector))
7074 (setq idlwave-completion-help-info
7075 (list 'idlwave-complete-class-structure-tag-help
7076 (idlwave-sintern-routine
7077 (concat class-selector "__define"))
7079 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7080 (idlwave-complete-in-buffer
7081 'class-tag 'class-tag
7082 idlwave-current-class-tags nil
7083 (format "Select a tag of class %s" class-selector)
7085 'idlwave-attach-class-tag-classes))
7086 t) ; return t to skip other completions
7089 (defun idlwave-class-tag-reset ()
7090 (setq idlwave-current-tags-class nil))
7092 (defun idlwave-prepare-class-tag-completion (class)
7093 "Find and parse the necessary class definitions for class structure tags."
7094 (setq idlwave-sint-class-tags nil)
7095 (setq idlwave-current-tags-class class)
7096 (setq idlwave-current-class-tags
7098 (list (idlwave-sintern-class-tag x 'set)))
7099 (idlwave-all-class-tags class)))
7100 (setq idlwave-current-native-class-tags
7101 (mapcar 'downcase (idlwave-class-tags class))))
7103 ;===========================================================================
7105 ;; Completing system variables and their structure fields
7106 ;; This is also a plugin.
7108 (defvar idlwave-sint-sysvars nil)
7109 (defvar idlwave-sint-sysvartags nil)
7110 (idlwave-new-sintern-type 'sysvar)
7111 (idlwave-new-sintern-type 'sysvartag)
7112 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7113 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7114 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7116 (defvar idlwave-executive-commands-alist nil
7117 "Alist of system variables and their help files.")
7119 (defvar idlwave-system-variables-alist nil
7120 "Alist of system variables and the associated structure tags.
7121 Gets set in `idlw-rinfo.el'.")
7123 (defun idlwave-complete-sysvar-or-tag ()
7124 "Complete a system variable."
7127 (case-fold-search t))
7128 (cond ((save-excursion
7129 ;; Check if the context is right for system variable
7130 (skip-chars-backward "[a-zA-Z0-9_$]")
7131 (equal (char-before) ?!))
7132 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7133 (idlwave-complete-in-buffer 'sysvar 'sysvar
7134 idlwave-system-variables-alist nil
7135 "Select a system variable"
7137 t) ; return t to skip other completions
7139 ;; Check if the context is right for sysvar tag
7140 (skip-chars-backward "a-zA-Z0-9_$.")
7141 (and (equal (char-before) ?!)
7142 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7143 (<= (match-end 0) pos)))
7144 ;; Complete a system variable tag
7145 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7146 (entry (assq var idlwave-system-variables-alist))
7147 (tags (cdr (assq 'tags entry))))
7148 (or entry (error "!%s is not a known system variable" var))
7149 (or tags (error "System variable !%s is not a structure" var))
7150 (setq idlwave-completion-help-info
7151 (list 'idlwave-complete-sysvar-tag-help var))
7152 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7154 "Select a system variable tag"
7155 "system variable tag")
7156 t)) ; return t to skip other completions
7159 (defun idlwave-complete-sysvar-help (mode word)
7160 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7161 (entry (assoc word idlwave-system-variables-alist)))
7164 (and (stringp word) entry (nth 1 (assq 'link entry))))
7166 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7167 (t (error "This should not happen")))))
7169 (defun idlwave-complete-sysvar-tag-help (mode word)
7170 (let* ((var (nth 1 idlwave-completion-help-info))
7171 (entry (assoc var idlwave-system-variables-alist))
7172 (tags (cdr (assq 'tags entry)))
7173 (main (nth 1 (assq 'link entry)))
7176 ((eq mode 'test) ; we can at least link the main
7177 (and (stringp word) entry main))
7181 (if (setq target (cdr (assoc word tags)))
7182 (idlwave-substitute-link-target main target)
7183 main)))) ;; setting dynamic!!!
7184 (t (error "This should not happen")))))
7186 (defun idlwave-substitute-link-target (link target)
7187 "Substitute the target anchor for the given link."
7189 (setq main-base (if (string-match "#" link)
7190 (substring link 0 (match-beginning 0))
7193 (concat main-base idlwave-html-link-sep (number-to-string target))
7196 ;; Fake help in the source buffer for class structure tags.
7197 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7200 (defvar idlwave-help-do-class-struct-tag nil)
7201 (defun idlwave-complete-class-structure-tag-help (mode word)
7203 ((eq mode 'test) ; nothing gets fontified for class tags
7206 (let (class-with found-in)
7207 (when (setq class-with
7208 (idlwave-class-or-superclass-with-tag
7209 idlwave-current-tags-class
7211 (if (assq (idlwave-sintern-class class-with)
7212 idlwave-system-class-info)
7213 (error "No help available for system class tags."))
7214 (if (setq found-in (idlwave-class-found-in class-with))
7215 (setq name (cons (concat found-in "__define") class-with))
7216 (setq name (concat class-with "__define")))))
7218 idlwave-help-do-class-struct-tag t))
7219 (t (error "This should not happen"))))
7221 (defun idlwave-class-or-superclass-with-tag (class tag)
7222 "Find and return the CLASS or one of its superclass with the
7223 associated TAG, if any."
7224 (let ((sclasses (cons class (cdr (assq 'all-inherits
7225 (idlwave-class-info class)))))
7229 (setq cl (pop sclasses))
7230 (let ((tags (idlwave-class-tags cl)))
7232 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7234 (setq tags (cdr tags))))))))
7237 (defun idlwave-sysvars-reset ()
7238 (if (and (fboundp 'idlwave-shell-is-running)
7239 (idlwave-shell-is-running)
7240 idlwave-idlwave_routine_info-compiled)
7241 (idlwave-shell-send-command "idlwave_get_sysvars"
7242 'idlwave-process-sysvars 'hide)))
7244 (defun idlwave-process-sysvars ()
7245 (idlwave-shell-filter-sysvars)
7246 (setq idlwave-sint-sysvars nil
7247 idlwave-sint-sysvartags nil)
7248 (idlwave-sintern-sysvar-alist))
7250 (defun idlwave-sintern-sysvar-alist ()
7251 (let ((list idlwave-system-variables-alist) entry tags)
7252 (while (setq entry (pop list))
7253 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7254 (setq tags (assq 'tags entry))
7258 (cons (idlwave-sintern-sysvartag (car x) 'set)
7262 (defvar idlwave-shell-command-output)
7263 (defun idlwave-shell-filter-sysvars ()
7264 "Get any new system variables and tags."
7265 (let ((text idlwave-shell-command-output)
7267 (old idlwave-system-variables-alist)
7268 var tags type name class link old-entry)
7269 (setq idlwave-system-variables-alist nil)
7270 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7272 (setq start (match-end 0)
7273 var (match-string 1 text)
7274 tags (if (match-end 3)
7275 (idlwave-split-string (match-string 3 text))))
7276 ;; Maintain old links, if present
7277 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7278 (setq link (assq 'link old-entry))
7279 (setq idlwave-system-variables-alist
7286 (idlwave-sintern-sysvartag x)
7287 (cdr (assq 'tags old-entry))))))
7289 idlwave-system-variables-alist)))
7290 ;; Keep the old value if query was not successful
7291 (setq idlwave-system-variables-alist
7292 (or idlwave-system-variables-alist old))))
7294 (defun idlwave-completion-fontify-classes ()
7295 "Goto the *Completions* buffer and fontify the class info."
7296 (when (featurep 'font-lock)
7298 (set-buffer "*Completions*")
7300 (goto-char (point-min))
7301 (let ((buffer-read-only nil))
7302 (while (re-search-forward "\\.*<[^>]+>" nil t)
7303 (put-text-property (match-beginning 0) (match-end 0)
7304 'face 'font-lock-string-face)))))))
7306 (defun idlwave-uniquify (list)
7307 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7310 (unless (gethash x ht)
7315 (defun idlwave-after-successful-completion (type slash &optional verify)
7316 "Add `=' or `(' after successful completion of keyword and function.
7317 Restore the pre-completion window configuration if possible."
7319 ((eq type 'procedure)
7321 ((eq type 'function)
7323 ((equal idlwave-function-completion-adds-paren nil) nil)
7324 ((or (equal idlwave-function-completion-adds-paren t)
7325 (equal idlwave-function-completion-adds-paren 1))
7327 ((equal idlwave-function-completion-adds-paren 2)
7332 (if (and idlwave-keyword-completion-adds-equal
7334 (progn (insert "=") t)
7337 ;; Restore the pre-completion window configuration if this is safe.
7339 (if (or (eq verify 'force) ; force
7341 (get-buffer-window "*Completions*") ; visible
7342 (idlwave-local-value 'idlwave-completion-p
7343 "*Completions*") ; cib-buffer
7344 (eq (marker-buffer idlwave-completion-mark)
7345 (current-buffer)) ; buffer OK
7346 (equal (marker-position idlwave-completion-mark)
7348 (idlwave-restore-wconf-after-completion))
7349 (move-marker idlwave-completion-mark nil)
7350 (setq idlwave-before-completion-wconf nil))
7352 (defun idlwave-mouse-context-help (ev &optional arg)
7353 "Call `idlwave-context-help' on the clicked location."
7355 (mouse-set-point ev)
7356 (idlwave-context-help arg))
7358 (defvar idlwave-last-context-help-pos nil)
7359 (defun idlwave-context-help (&optional arg)
7360 "Display IDL Online Help on context.
7361 If point is on a keyword, help for that keyword will be shown. If
7362 point is on a routine name or in the argument list of a routine, help
7363 for that routine will be displayed. Works for system routines and
7364 keywords, it pulls up text help. For other routies and keywords,
7365 visits the source file, finding help in the header (if
7366 `idlwave-help-source-try-header' is non-nil) or the routine definition
7369 (idlwave-do-context-help arg))
7371 (defun idlwave-mouse-completion-help (ev)
7372 "Display online help about the completion at point."
7374 ;; Restore last-command for next command, to make
7375 ;; scrolling/cancelling of completions work.
7376 (setq this-command last-command)
7377 (idlwave-do-mouse-completion-help ev))
7379 (defun idlwave-routine-info (&optional arg external)
7380 "Display a routines calling sequence and list of keywords. When
7381 point is on the name a function or procedure, or in the argument list
7382 of a function or procedure, this command displays a help buffer with
7383 the information. When called with prefix arg, enforce class query.
7385 When point is on an object operator `->', display the class stored in
7386 this arrow, if any (see `idlwave-store-inquired-class'). With a
7387 prefix arg, the class property is cleared out."
7391 (if (string-match "->" (buffer-substring
7392 (max (point-min) (1- (point)))
7393 (min (+ 2 (point)) (point-max))))
7394 ;; Cursor is on an arrow
7395 (if (get-text-property (point) 'idlwave-class)
7396 ;; arrow has class property
7401 (when (looking-at ".?\\(->\\)")
7402 (remove-text-properties (match-beginning 1) (match-end 1)
7403 '(idlwave-class nil face nil))
7404 (message "Class property removed from arrow")))
7405 ;; Echo class property
7406 (message "Arrow has text property identifying object to be class %s"
7407 (get-text-property (point) 'idlwave-class)))
7408 ;; No property found
7409 (message "Arrow has no class text property"))
7411 ;; Not on an arrow...
7412 (let* ((idlwave-query-class nil)
7413 (idlwave-force-class-query (equal arg '(4)))
7414 (module (idlwave-what-module)))
7416 (apply 'idlwave-display-calling-sequence
7417 (idlwave-fix-module-if-obj_new module))
7418 (error "Don't know which calling sequence to show")))))
7420 (defun idlwave-resolve (&optional arg)
7421 "Call RESOLVE_ROUTINE on the module name at point.
7422 Like `idlwave-routine-info', this looks for a routine call at point.
7423 After confirmation in the minibuffer, it will use the shell to issue
7424 a RESOLVE call for this routine, to attempt to make it defined and its
7425 routine info available for IDLWAVE. If the routine is a method call,
7426 both `class__method' and `class__define' will be tried.
7427 With ARG, enforce query for the class of object methods."
7429 (let* ((idlwave-query-class nil)
7430 (idlwave-force-class-query (equal arg '(4)))
7431 (module (idlwave-what-module))
7432 (name (idlwave-make-full-name (nth 2 module) (car module)))
7433 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7434 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7437 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7439 (setq type (match-string 1 resolve)
7440 class (if (match-beginning 2)
7441 (match-string 3 resolve)
7443 name (match-string 4 resolve)))
7444 (if (string= (downcase type) "function")
7445 (setq kwd ",/is_function"))
7449 (idlwave-shell-send-command
7450 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7451 'idlwave-update-routine-info
7454 (idlwave-shell-send-command
7455 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7456 (list 'idlwave-shell-send-command
7457 (format "resolve_routine,'%s__%s'%s"
7458 (downcase class) (downcase name) kwd)
7459 '(idlwave-update-routine-info)
7462 (defun idlwave-find-module (&optional arg)
7463 "Find the source code of an IDL module.
7464 Works for modules for which IDLWAVE has routine info available. The
7465 function offers as default the module name `idlwave-routine-info'
7466 would use. With ARG limit to this buffer. With two prefix ARG's
7467 force class query for object methods."
7469 (let* ((idlwave-query-class nil)
7470 (idlwave-force-class-query (equal arg '(16)))
7471 (this-buffer (equal arg '(4)))
7472 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7474 (concat (idlwave-make-full-name
7475 (nth 2 module) (car module))
7476 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7482 (if (eq 'system (car-safe (nth 3 x)))
7483 ;; Take out system routines with no source.
7486 (concat (idlwave-make-full-name
7488 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7490 (idlwave-save-buffer-update)
7491 (idlwave-routines))))))
7492 (name (idlwave-completing-read
7493 (if (or (not this-buffer)
7494 (assoc default list))
7495 (format "Module (Default %s): " default)
7496 (format "Module in this file: "))
7499 (if (string-match "\\`\\s-*\\'" name)
7500 ;; Nothing, use the default.
7501 (setq name default))
7502 (if (string-match "<[fp]>" name)
7503 (setq type (substring name -2 -1)
7504 name (substring name 0 -3)))
7505 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7506 (setq class (match-string 1 name)
7507 name (match-string 2 name)))
7508 (setq name (idlwave-sintern-routine-or-method name class)
7509 class (idlwave-sintern-class class)
7510 type (cond ((equal type "f") 'fun)
7511 ((equal type "p") 'pro)
7513 (idlwave-do-find-module name type class nil this-buffer)))
7515 (defun idlwave-do-find-module (name type class
7516 &optional force-source this-buffer)
7517 (let ((name1 (idlwave-make-full-name class name))
7519 (buf (current-buffer))
7522 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7524 source (or force-source (nth 3 entry))
7525 name2 (if (nth 2 entry)
7526 (idlwave-make-full-name (nth 2 entry) name)
7529 (setq file (idlwave-routine-source-file source)))
7530 (unless file ; Try to find it on the path.
7532 (idlwave-expand-lib-file-name
7534 (format "%s__define.pro" (downcase class))
7535 (format "%s.pro" (downcase name))))))
7537 ((or (null name) (equal name ""))
7539 ((eq (car source) 'system)
7540 (error "Source code for system routine %s is not available"
7542 ((or (not file) (not (file-regular-p file)))
7543 (error "Source code for routine %s is not available"
7546 (when (not this-buffer)
7548 (idlwave-find-file-noselect file 'find))
7549 (pop-to-buffer buf1 t))
7550 (goto-char (point-max))
7551 (let ((case-fold-search t))
7552 (if (re-search-backward
7553 (concat "^[ \t]*\\<"
7554 (cond ((eq type 'fun) "function")
7555 ((eq type 'pro) "pro")
7556 (t "\\(pro\\|function\\)"))
7558 (regexp-quote (downcase name2))
7561 (goto-char (match-beginning 0))
7564 (error "Could not find routine %s" name2)))))))
7566 (defun idlwave-what-module ()
7567 "Return a default module for stuff near point.
7568 Used by `idlwave-routine-info' and `idlwave-find-module'."
7570 (if (let ((case-fold-search t))
7572 (idlwave-beginning-of-statement)
7573 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7574 ;; This is a function or procedure definition statement
7575 ;; We return the defined routine as module.
7577 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
7578 (match-string-no-properties 2))
7579 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7580 (idlwave-sintern-class (match-string 3)))
7582 ;; Not a definition statement - analyze precise position.
7583 (let* ((where (idlwave-where))
7585 (pro (car (nth 0 where)))
7586 (func (car (nth 1 where)))
7587 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7588 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7592 ((and (eq cw 'procedure)
7593 (not (equal this-word "")))
7594 (setq this-word (idlwave-sintern-routine-or-method
7595 this-word (nth 2 (nth 3 where))))
7596 (list this-word 'pro
7597 (idlwave-determine-class
7598 (cons this-word (cdr (nth 3 where)))
7600 ((and (eq cw 'function)
7601 (not (equal this-word ""))
7602 (or (eq next-char ?\() ; exclude arrays, vars.
7603 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7604 (setq this-word (idlwave-sintern-routine-or-method
7605 this-word (nth 2 (nth 3 where))))
7606 (list this-word 'fun
7607 (idlwave-determine-class
7608 (cons this-word (cdr (nth 3 where)))
7610 ((and (memq cw '(function-keyword procedure-keyword))
7611 (not (equal this-word ""))
7612 (eq next-char ?\()) ; A function!
7613 (setq this-word (idlwave-sintern-routine this-word))
7614 (list this-word 'fun nil))
7616 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7618 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7621 (defun idlwave-what-module-find-class ()
7622 "Call idlwave-what-module and find the inherited class if necessary."
7623 (let* ((module (idlwave-what-module))
7624 (class (nth 2 module))
7626 (if (and (= (length module) 3)
7630 (apply 'idlwave-find-inherited-class module))
7633 (defun idlwave-find-inherited-class (name type class)
7634 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7635 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7640 (defun idlwave-fix-module-if-obj_new (module)
7641 "Check if MODULE points to obj_new.
7642 If yes, and if the cursor is in the keyword region, change to the
7643 appropriate Init method."
7644 (let* ((name (car module))
7646 (case-fold-search t)
7648 (if (and (stringp name)
7649 (equal (downcase name) "obj_new")
7651 (idlwave-beginning-of-statement)
7652 (setq string (buffer-substring (point) pos))
7653 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7656 (class (match-string 1 string)))
7657 (setq module (list (idlwave-sintern-method "Init")
7659 (idlwave-sintern-class class)))))
7662 (defun idlwave-fix-keywords (name type class keywords &optional super-classes)
7663 "Update a list of keywords.
7664 Translate OBJ_NEW, adding all super-class keywords, or all keywords
7665 from all classes if class equals t."
7666 (let ((case-fold-search t))
7668 ;; If this is the OBJ_NEW function, try to figure out the class and use
7669 ;; the keywords from the corresponding INIT method.
7670 (if (and (equal (upcase name) "OBJ_NEW")
7671 (or (eq major-mode 'idlwave-mode)
7672 (eq major-mode 'idlwave-shell-mode)))
7673 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7674 (string (buffer-substring bos (point)))
7675 (case-fold-search t)
7677 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7679 (setq class (idlwave-sintern-class (match-string 1 string)))
7680 (setq idlwave-current-obj_new-class class)
7683 (idlwave-entry-keywords
7685 (idlwave-sintern-method "INIT")
7688 (idlwave-routines)) 'do-link))))))
7690 ;; If the class is `t', combine all keywords of all methods NAME
7692 (mapc (lambda (entry)
7694 (nth 2 entry) ; non-nil class
7695 (eq (nth 1 entry) type) ; correct type
7698 (idlwave-entry-keywords entry 'do-link)))))
7699 (idlwave-all-assq name (idlwave-routines)))
7700 (setq keywords (idlwave-uniquify keywords)))
7702 ;; If we have inheritance, add all keywords from superclasses, if
7703 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
7706 idlwave-keyword-class-inheritance
7708 (or (assq (idlwave-sintern-keyword "_extra") keywords)
7709 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7710 ;; Check if one of the keyword-class regexps matches the name
7711 (let ((regexps idlwave-keyword-class-inheritance) re)
7713 (while (setq re (pop regexps))
7714 (if (string-match re name) (throw 'exit t))))))
7716 (loop for entry in (idlwave-routines) do
7717 (and (nth 2 entry) ; non-nil class
7718 (memq (nth 2 entry) super-classes) ; an inherited class
7719 (eq (nth 1 entry) type) ; correct type
7720 (eq (car entry) name) ; correct name
7721 (mapcar (lambda (k) (add-to-list 'keywords k))
7722 (idlwave-entry-keywords entry 'do-link))))
7723 (setq keywords (idlwave-uniquify keywords)))
7725 ;; Return the final list
7728 (defun idlwave-expand-keyword (keyword module)
7729 "Expand KEYWORD to one of the legal keyword parameters of MODULE.
7730 KEYWORD may be an exact match or an abbreviation of a keyword.
7731 If the match is exact, KEYWORD itself is returned, even if there may be other
7732 keywords of which KEYWORD is an abbreviation. This is necessary because some
7733 system routines have keywords which are prefixes of other keywords.
7734 If KEYWORD is an abbreviation of several keywords, a list of all possible
7735 completions is returned.
7736 If the abbreviation was unique, the correct keyword is returned.
7737 If it cannot be a keyword, the function return nil.
7738 If we do not know about MODULE, just return KEYWORD literally."
7739 (let* ((name (car module))
7740 (type (nth 1 module))
7741 (class (nth 2 module))
7742 (kwd (idlwave-sintern-keyword keyword))
7743 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7744 (kwd-alist (idlwave-entry-keywords entry))
7745 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7746 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7747 (completion-ignore-case t)
7749 (cond ((assq kwd kwd-alist)
7751 ((setq candidates (all-completions kwd kwd-alist))
7752 (if (= (length candidates) 1)
7756 ;; Inheritance may cause this keyword to be correct
7759 ;; We do know the function, which does not have the keyword.
7762 ;; We do not know the function, so this just might be a correct
7763 ;; keyword - return it as it is.
7766 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7767 (defvar idlwave-rinfo-map (make-sparse-keymap))
7768 (define-key idlwave-rinfo-mouse-map
7769 (if (featurep 'xemacs) [button2] [mouse-2])
7770 'idlwave-mouse-active-rinfo)
7771 (define-key idlwave-rinfo-mouse-map
7772 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7773 'idlwave-mouse-active-rinfo-shift)
7774 (define-key idlwave-rinfo-mouse-map
7775 (if (featurep 'xemacs) [button3] [mouse-3])
7776 'idlwave-mouse-active-rinfo-right)
7777 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7778 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7779 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7780 (defvar idlwave-popup-source nil)
7781 (defvar idlwave-rinfo-marker (make-marker))
7783 (defun idlwave-quit-help ()
7785 (let ((ri-window (get-buffer-window "*Help*"))
7786 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7787 (when (and olh-window
7788 (fboundp 'idlwave-help-quit))
7789 (select-window olh-window)
7790 (idlwave-help-quit))
7791 (when (window-live-p ri-window)
7792 (delete-window ri-window))))
7794 (defun idlwave-display-calling-sequence (name type class
7795 &optional initial-class)
7796 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7797 (let* ((initial-class (or initial-class class))
7798 (entry (or (idlwave-best-rinfo-assq name type class
7800 (idlwave-rinfo-assq name type class
7801 idlwave-unresolved-routines)))
7802 (name (or (car entry) name))
7803 (class (or (nth 2 entry) class))
7804 (superclasses (idlwave-all-class-inherits initial-class))
7805 (twins (idlwave-routine-twins entry))
7806 (dtwins (idlwave-study-twins twins))
7808 (system (eq (car (nth 3 entry)) 'system))
7809 (calling-seq (nth 4 entry))
7810 (keywords (idlwave-entry-keywords entry 'do-link))
7811 (html-file (car (nth 5 entry)))
7813 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
7815 "Button2/3: Online Help")
7817 "Button2: Jump to source and back | Button3: Source in Help window.")
7819 "Button2: Display info about same method in superclass")
7821 (data (list name type class (current-buffer) nil initial-class))
7822 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7823 (face 'idlwave-help-link-face)
7824 beg props win cnt total)
7825 ;; Fix keywords, but don't add chained super-classes, since these
7826 ;; are shown separately for that super-class
7827 (setq keywords (idlwave-fix-keywords name type class keywords))
7830 (error "No %s %s known %s" type name
7831 (if initial-class (concat "in class " initial-class) "")))
7832 ((or (null name) (equal name ""))
7833 (error "No function or procedure call at point"))
7835 (error "Calling sequence of %s %s not available" type name))
7838 (move-marker idlwave-rinfo-marker (point))
7839 (set-buffer (get-buffer-create "*Help*"))
7840 (use-local-map idlwave-rinfo-map)
7841 (setq buffer-read-only nil)
7843 (set (make-local-variable 'idlwave-popup-source) nil)
7844 (set (make-local-variable 'idlwave-current-obj_new-class)
7845 idlwave-current-obj_new-class)
7847 (setq props (list 'mouse-face 'highlight
7848 km-prop idlwave-rinfo-mouse-map
7849 'help-echo help-echo-class
7850 'data (cons 'class data)))
7851 (let ((classes (cons initial-class superclasses)) c)
7852 (insert "Classes: ")
7853 (while (setq c (pop classes))
7857 (if (equal (downcase c) (downcase class))
7858 (add-text-properties beg (point) (list 'face 'bold))
7859 ;; If Method exists in a different class link it
7860 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7861 (add-text-properties beg (point) props))))
7863 (setq props (list 'mouse-face 'highlight
7864 km-prop idlwave-rinfo-mouse-map
7865 'help-echo help-echo-use
7866 'data (cons 'usage data)))
7867 (if html-file (setq props (append (list 'face face 'link html-file)
7872 (format calling-seq class name class name class name)
7873 (format calling-seq name name name name))
7875 (add-text-properties beg (point) props)
7877 (insert "Keywords:")
7879 (insert " No keywords accepted.")
7883 (if (>= (+ col 1 (length (car x)))
7890 ;; Relevant keywords already have link property attached
7891 props (list 'mouse-face 'highlight
7892 km-prop idlwave-rinfo-mouse-map
7893 'data (cons 'keyword data)
7894 'help-echo help-echo-kwd
7896 (if system (setq props (append (list 'face face) props)))
7898 (add-text-properties beg (point) props)
7899 (setq col (+ col 1 (length (car x)))))
7902 (setq cnt 1 total (length all))
7903 ;; Here entry is (key file (list of type-conses))
7904 (while (setq entry (pop all))
7905 (setq props (list 'mouse-face 'highlight
7906 km-prop idlwave-rinfo-mouse-map
7907 'help-echo help-echo-src
7908 'source (list (car (car (nth 2 entry))) ;type
7911 (cdr (car (nth 2 entry))))
7912 'data (cons 'source data)))
7913 (idlwave-insert-source-location
7916 (if (> total 1) "Sources:" "Source:")
7918 (if (> total 1) "- " ""))
7921 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7922 ;; No more source lines, please
7924 "\n Source information truncated to %d entries."
7925 idlwave-rinfo-max-source-lines))
7927 (beginning-of-buffer)
7928 (setq buffer-read-only t))
7929 (display-buffer "*Help*")
7930 (if (and (setq win (get-buffer-window "*Help*"))
7931 idlwave-resize-routine-help-window)
7933 (let ((ww (selected-window)))
7937 (enlarge-window (- (/ (frame-height) 2)
7939 (shrink-window-if-larger-than-buffer))
7940 (select-window ww)))))))))
7942 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7943 "Insert a source location into the routine info buffer.
7944 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
7946 (let* ((key (car entry))
7947 (file (nth 1 entry))
7948 (types (nth 2 entry))
7949 (shell-flag (assq 'compiled types))
7950 (buffer-flag (assq 'buffer types))
7951 (user-flag (assq 'user types))
7952 (lib-flag (assq 'lib types))
7953 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
7954 (and user-flag (idlwave-count-memq 'user types))
7955 (and lib-flag (idlwave-count-memq 'lib types))
7969 (insert "Builtin "))
7971 ((and (not file) shell-flag)
7972 (insert "Unresolved"))
7977 ((idlwave-syslib-p file)
7978 (if (string-match "obsolete" (file-name-directory file))
7979 (insert "Obsolete ")
7980 (insert "SystemLib ")))
7982 ;; New special syntax: taken directly from routine-info for
7983 ;; library catalog routines
7984 ((setq special (or (cdr lib-flag) (cdr user-flag)))
7985 (insert (format "%-10s" special)))
7987 ;; Old special syntax: a matching regexp
7988 ((setq special (idlwave-special-lib-test file))
7989 (insert (format "%-10s" special)))
7991 ;; Catch-all with file
7992 ((idlwave-lib-p file) (insert "Library "))
7995 (t (insert "Other ")))
8000 (if lib-flag "L" "-")
8001 (if user-flag "C" "-")
8002 (if shell-flag "S" "-")
8003 (if buffer-flag "B" "-")
8007 (insert (format "(%dx) " ndupl))
8008 (add-text-properties beg (point) (list 'face 'bold)))
8009 (when (and file (not (equal file "")))
8011 (insert (apply 'abbreviate-file-name
8012 (if (featurep 'xemacs) (list file t) (list file))))
8014 (add-text-properties beg (point) file-props)))))
8016 (defun idlwave-special-lib-test (file)
8017 "Check the path of FILE against the regexps which define special libs.
8018 Return the name of the special lib if there is a match."
8019 (let ((alist idlwave-special-lib-alist)
8023 (while (setq entry (pop alist))
8024 (if (string-match (car entry) file)
8025 (setq rtn (cdr entry)
8030 (defun idlwave-mouse-active-rinfo-right (ev)
8032 (idlwave-mouse-active-rinfo ev 'right))
8034 (defun idlwave-mouse-active-rinfo-shift (ev)
8036 (idlwave-mouse-active-rinfo ev nil 'shift))
8038 (defun idlwave-active-rinfo-space ()
8040 (idlwave-mouse-active-rinfo nil 'right))
8042 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8043 "Does the mouse actions in the routine info buffer.
8044 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8047 (if ev (mouse-set-point ev))
8048 (let (data id name type class buf bufwin source word initial-class)
8049 (setq data (get-text-property (point) 'data)
8050 source (get-text-property (point) 'source)
8051 keyword (get-text-property (point) 'keyword)
8052 link (get-text-property (point) 'link)
8054 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8056 initial-class (nth 6 data)
8057 word (idlwave-this-word)
8058 bufwin (get-buffer-window buf t))
8060 (cond ((eq id 'class) ; Switch class being displayed
8061 (if (window-live-p bufwin) (select-window bufwin))
8062 (idlwave-display-calling-sequence
8063 (idlwave-sintern-method name)
8064 type (idlwave-sintern-class word)
8066 ((eq id 'usage) ; Online help on this routine
8067 (idlwave-online-help link name type class))
8068 ((eq id 'source) ; Source in help or buffer
8070 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8071 (idlwave-help-source-try-header nil)
8072 ;; Fake idlwave-routines so help will find the right entry
8074 (list (list name type class source ""))))
8075 (idlwave-help-get-special-help name type class nil))
8076 ;; Otherwise just pop to the source
8077 (setq idlwave-popup-source (not idlwave-popup-source))
8078 (if idlwave-popup-source
8080 (idlwave-do-find-module name type class source)
8082 (setq idlwave-popup-source nil)
8083 (if (window-live-p bufwin) (select-window bufwin))
8084 (error (nth 1 err))))
8086 (select-window bufwin)
8087 (pop-to-buffer buf))
8088 (goto-char (marker-position idlwave-rinfo-marker)))))
8091 (idlwave-online-help link name type class keyword)
8092 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8094 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8095 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8096 (let ((bwin (get-buffer-window buffer)))
8097 (if idlwave-complete-empty-string-as-lower-case
8098 (setq keyword (downcase keyword)))
8100 (select-window bwin)
8101 (pop-to-buffer buffer)
8102 (setq bwin (get-buffer-window buffer)))
8103 (if (eq (preceding-char) ?/)
8105 (unless (save-excursion
8107 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8108 (min (- (point) 100) (point-min)) t))
8110 (if shift (insert "/"))
8112 (if (and (not shift)
8113 idlwave-keyword-completion-adds-equal)
8116 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8117 "List the load path shadows of all routines defined in current buffer."
8120 (if (eq major-mode 'idlwave-mode)
8121 (idlwave-list-load-path-shadows
8122 nil (idlwave-update-current-buffer-info 'save-buffer)
8123 "in current buffer")
8124 (error "Current buffer is not in idlwave-mode")))
8126 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8127 "List the load path shadows of all routines compiled under the shell.
8128 This is very useful for checking an IDL application. Just compile the
8129 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8130 routines and update IDLWAVE internal info. Then check for shadowing
8134 ((or (not (fboundp 'idlwave-shell-is-running))
8135 (not (idlwave-shell-is-running)))
8136 (error "Shell is not running"))
8137 ((null idlwave-compiled-routines)
8138 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8140 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8143 (defun idlwave-list-all-load-path-shadows (&optional arg)
8144 "List the load path shadows of all routines known to IDLWAVE."
8146 (idlwave-list-load-path-shadows nil nil "globally"))
8148 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8149 "List the routines which are defined multiple times.
8150 Search the information IDLWAVE has about IDL routines for multiple
8152 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8154 When IDL hits a routine call which is not defined, it will search on
8155 the load path in order to find a definition. The output of this
8156 command can be used to detect possible name clashes during this process."
8157 (idlwave-routines) ; Make sure everything is loaded.
8158 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8160 "You don't have any user or library catalogs. Continue anyway? ")
8162 (let* ((routines (append idlwave-system-routines
8163 idlwave-compiled-routines
8164 idlwave-library-catalog-routines
8165 idlwave-user-catalog-routines
8166 idlwave-buffer-routines
8168 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8169 (keymap (make-sparse-keymap))
8170 (props (list 'mouse-face 'highlight
8172 'help-echo "Mouse2: Find source"))
8173 (nroutines (length (or special-routines routines)))
8174 (step (/ nroutines 99))
8178 (idlwave-sort-prefer-buffer-info nil)
8179 routine twins dtwins twin done props1 lroutines)
8181 (if special-routines
8182 ;; Just looking for shadows of a few special routines
8183 (setq lroutines routines
8184 routines special-routines))
8186 (message "Sorting routines...")
8187 (setq routines (sort routines
8189 (string< (downcase (idlwave-make-full-name
8191 (downcase (idlwave-make-full-name
8192 (nth 2 b) (car b)))))))
8193 (message "Sorting routines...done")
8195 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8198 (mouse-set-point ev)
8199 (apply 'idlwave-do-find-module
8200 (get-text-property (point) 'find-args))))
8201 (define-key keymap [(return)]
8204 (apply 'idlwave-do-find-module
8205 (get-text-property (point) 'find-args))))
8206 (message "Compiling list...( 0%%)")
8208 (set-buffer (get-buffer-create "*Shadows*"))
8209 (setq buffer-read-only nil)
8211 (while (setq routine (pop routines))
8213 (if (= (* next-perc step) n)
8215 (message "Compiling list...(%2d%%)" next-perc)
8216 (setq next-perc (1+ next-perc))))
8217 ;; Get a list of all twins
8218 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8219 (if (memq routine done)
8221 (setq dtwins (idlwave-study-twins twins)))
8222 ;; Mark all twins as dealt with
8223 (setq done (append twins done))
8224 (when (or (> (length dtwins) 1)
8225 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8226 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8227 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8229 (insert (format "\n%s%s"
8230 (idlwave-make-full-name (nth 2 routine)
8232 (if (eq (nth 1 routine) 'fun) "()" "")))
8233 (while (setq twin (pop dtwins))
8234 (setq props1 (append (list 'find-args
8235 (list (nth 0 routine)
8239 (idlwave-insert-source-location "\n - " twin props1))))
8240 (goto-char (point-min))
8241 (setq buffer-read-only t))
8242 (setq loc (or loc ""))
8245 (display-buffer (get-buffer "*Shadows*"))
8246 (message "%d case%s of shadowing found %s"
8247 cnt (if (= cnt 1) "" "s") loc))
8248 (message "No shadowing conflicts found %s" loc))))
8250 (defun idlwave-print-source (routine)
8251 (let* ((source (nth 3 routine))
8252 (stype (car source))
8253 (sfile (idlwave-routine-source-file source)))
8254 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8255 (if (and (eq stype 'compiled)
8256 (or (not (stringp sfile))
8257 (not (string-match "\\S-" sfile))))
8258 (setq stype 'unresolved))
8259 (princ (format " %-10s %s\n"
8261 (if sfile sfile "No source code available")))))
8263 (defun idlwave-routine-twins (entry &optional list)
8264 "Return all twin entries of ENTRY in LIST.
8265 LIST defaults to `idlwave-routines'.
8266 Twin entries are those which have the same name, type, and class.
8267 ENTRY will also be returned, as the first item of this list."
8268 (let* ((name (car entry))
8269 (type (nth 1 entry))
8270 (class (nth 2 entry))
8271 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8273 (while (setq candidate (pop candidates))
8274 (if (and (not (eq candidate entry))
8275 (eq type (nth 1 candidate))
8276 (eq class (nth 2 candidate)))
8277 (push candidate twins)))
8278 (if (setq candidate (idlwave-rinfo-assq name type class
8279 idlwave-unresolved-routines))
8280 (push candidate twins))
8281 (cons entry (nreverse twins))))
8283 (defun idlwave-study-twins (entries)
8284 "Return dangerous twins of first entry in ENTRIES.
8285 Dangerous twins are routines with same name, but in different files on
8286 the load path. If a file is in the system library and has an entry in
8287 the `idlwave-system-routines' list, we omit the latter as
8288 non-dangerous because many IDL routines are implemented as library
8289 routines, and may have been scanned."
8290 (let* ((entry (car entries))
8291 (name (car entry)) ;
8292 (type (nth 1 entry)) ; Must be bound for
8293 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8295 source type type-cons file alist syslibp key)
8296 (while (setq entry (pop entries))
8298 (setq source (nth 3 entry)
8300 type-cons (cons type (nth 3 source))
8301 file (idlwave-routine-source-file source))
8303 ;; Make KEY to index entry properly
8304 (setq key (cond ((eq type 'system) type)
8305 (file (file-truename file))
8308 ;; Check for an entry in the system library
8311 (idlwave-syslib-p file))
8314 ;; If there's more than one matching entry for the same file, just
8315 ;; append the type-cons to the type list.
8316 (if (setq entry (assoc key alist))
8317 (push type-cons (nth 2 entry))
8318 (push (list key file (list type-cons)) alist)))
8320 (setq alist (nreverse alist))
8323 ;; File is in system *library* - remove any 'system entry
8324 (setq alist (delq (assq 'system alist) alist)))
8326 ;; If 'system remains and we've scanned the syslib, it's a builtin
8327 ;; (rather than a !DIR/lib/.pro file bundled as source).
8328 (when (and (idlwave-syslib-scanned-p)
8329 (setq entry (assoc 'system alist)))
8330 (setcar entry 'builtin))
8331 (sort alist 'idlwave-routine-twin-compare)))
8336 (defvar idlwave-sort-prefer-buffer-info t
8337 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8339 (defmacro idlwave-xor (a b)
8343 (defun idlwave-routine-entry-compare (a b)
8344 "Compare two routine info entries for sortiung. This is the general case.
8345 It first compates class, names, and type. If it turns out that A and B
8346 are twins (same name, class, and type), calls another routine which
8347 compares twins on the basis of their file names and path locations."
8348 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8350 ((not (equal (idlwave-downcase-safe class)
8351 (idlwave-downcase-safe (nth 2 b))))
8353 (cond ((null (nth 2 b)) nil)
8355 (t (string< (downcase class) (downcase (nth 2 b))))))
8356 ((not (equal (downcase name) (downcase (car b))))
8358 (string< (downcase name) (downcase (car b))))
8359 ((not (eq type (nth 1 b)))
8361 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8363 ;; A and B are twins - so the decision is more complicated.
8364 ;; Call twin-compare with the proper arguments.
8365 (idlwave-routine-entry-compare-twins a b)))))
8367 (defun idlwave-routine-entry-compare-twins (a b)
8368 "Compare two routine entries, under the assumption that they are
8369 twins. This basically calls `idlwave-routine-twin-compare' with the
8371 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8376 (afile (idlwave-routine-source-file asrc))
8377 (bfile (idlwave-routine-source-file bsrc)))
8378 (idlwave-routine-twin-compare
8380 (list (file-truename afile) afile (list atype))
8381 (list atype afile (list atype)))
8383 (list (file-truename bfile) bfile (list btype))
8384 (list btype bfile (list btype))))
8387 (defun idlwave-routine-twin-compare (a b)
8388 "Compare two routine twin entries for sorting.
8389 In here, A and B are not normal routine info entries, but special
8390 lists (KEY FILENAME (TYPES...)).
8391 This expects NAME TYPE CLASS to be bound to the right values."
8392 (let* (;; Dis-assemble entries
8393 (akey (car a)) (bkey (car b))
8394 (afile (nth 1 a)) (bfile (nth 1 b))
8395 (atypes (nth 2 a)) (btypes (nth 2 b))
8397 (asysp (memq akey '(builtin system)))
8398 (bsysp (memq bkey '(builtin system)))
8399 ;; Compiled routines?
8400 (acompp (memq 'compiled atypes))
8401 (bcompp (memq 'compiled btypes))
8403 (aunresp (or (eq akey 'unresolved)
8404 (and acompp (not afile))))
8405 (bunresp (or (eq bkey 'unresolved)
8406 (and bcompp (not bfile))))
8407 ;; Buffer info available?
8408 (abufp (memq 'buffer atypes))
8409 (bbufp (memq 'buffer btypes))
8411 (tpath-alist (idlwave-true-path-alist))
8412 (apathp (and (stringp akey)
8413 (assoc (file-name-directory akey) tpath-alist)))
8414 (bpathp (and (stringp bkey)
8415 (assoc (file-name-directory bkey) tpath-alist)))
8416 ;; How early on search path? High number means early since we
8417 ;; measure the tail of the path list
8418 (anpath (length (memq apathp tpath-alist)))
8419 (bnpath (length (memq bpathp tpath-alist)))
8420 ;; Look at file names
8421 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8422 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8423 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8424 (regexp-quote (downcase class))
8425 (regexp-quote (downcase name)))
8426 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8427 ;; Is file name derived from the routine name?
8428 ;; Method file or class definition file?
8429 (anamep (string-match fname-re aname))
8430 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8431 (bnamep (string-match fname-re bname))
8432 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8434 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8435 ;; doesn't it? The difficult stuff is hidden above...
8437 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8438 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8439 ((and idlwave-sort-prefer-buffer-info
8440 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8441 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8442 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8443 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8444 ((and class anamep bnamep ; both file names match ->
8445 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8446 ((> anpath bnpath) t) ; Who is first on path?
8447 (t nil)))) ; Default
8449 (defun idlwave-routine-source-file (source)
8451 (expand-file-name (nth 1 source) (nth 2 source))
8454 (defun idlwave-downcase-safe (string)
8455 "Donwcase if string, else return unchanged."
8456 (if (stringp string)
8460 (defun idlwave-count-eq (elt list)
8461 "How often is ELT in LIST?"
8462 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8464 (defun idlwave-count-memq (elt alist)
8465 "How often is ELT a key in ALIST?"
8466 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8468 (defun idlwave-syslib-p (file)
8469 "Non-nil if FILE is in the system library."
8470 (let* ((true-syslib (file-name-as-directory
8472 (expand-file-name "lib" (idlwave-sys-dir)))))
8473 (true-file (file-truename file)))
8474 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8476 (defun idlwave-lib-p (file)
8477 "Non-nil if file is in the library"
8478 (let ((true-dir (file-name-directory (file-truename file))))
8479 (assoc true-dir (idlwave-true-path-alist))))
8481 (defun idlwave-path-alist-add-flag (list-entry flag)
8482 "Add a flag to the path list entry, if not set."
8483 (let ((flags (cdr list-entry)))
8484 (add-to-list 'flags flag)
8485 (setcdr list-entry flags)))
8487 (defun idlwave-path-alist-remove-flag (list-entry flag)
8488 "Remove a flag to the path list entry, if set."
8489 (let ((flags (delq flag (cdr list-entry))))
8490 (setcdr list-entry flags)))
8492 (defun idlwave-true-path-alist ()
8493 "Return `idlwave-path-alist' alist with true-names.
8494 Info is cached, but relies on the functions setting `idlwave-path-alist'
8495 to reset the variable `idlwave-true-path-alist' to nil."
8496 (or idlwave-true-path-alist
8497 (setq idlwave-true-path-alist
8498 (mapcar (lambda(x) (cons
8499 (file-name-as-directory
8501 (directory-file-name
8504 idlwave-path-alist))))
8506 (defun idlwave-syslib-scanned-p ()
8507 "Non-nil if the system lib file !DIR/lib has been scanned."
8508 (let* ((true-syslib (file-name-as-directory
8510 (expand-file-name "lib" (idlwave-sys-dir))))))
8511 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8513 ;; ----------------------------------------------------------------------------
8515 ;; Online Help display
8518 ;; ----------------------------------------------------------------------------
8520 ;; Additions for use with imenu.el and func-menu.el
8521 ;; (pop-up a list of IDL units in the current file).
8524 (defun idlwave-prev-index-position ()
8525 "Search for the previous procedure or function.
8526 Return nil if not found. For use with imenu.el."
8529 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
8530 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
8533 (defun idlwave-unit-name ()
8534 "Return the unit name.
8535 Assumes that point is at the beginning of the unit as found by
8536 `idlwave-prev-index-position'."
8539 (let ((begin (point)))
8541 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
8542 (if (fboundp 'buffer-substring-no-properties)
8543 (buffer-substring-no-properties begin (point))
8544 (buffer-substring begin (point)))))
8546 (defalias 'idlwave-function-menu
8549 (require 'func-menu)
8551 (error (condition-case nil
8557 ;; Here we hack func-menu.el in order to support this new mode.
8558 ;; The latest versions of func-menu.el already have this stuff in, so
8559 ;; we hack only if it is not already there.
8560 (when (fboundp 'eval-after-load)
8561 (eval-after-load "func-menu"
8563 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
8564 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
8565 (setq fume-function-name-regexp-alist
8566 (cons '(idlwave-mode . fume-function-name-regexp-idl)
8567 fume-function-name-regexp-alist)))
8568 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
8569 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
8570 (setq fume-find-function-name-method-alist
8571 (cons '(idlwave-mode . fume-find-next-idl-function-name)
8572 fume-find-function-name-method-alist))))))
8574 (defun idlwave-edit-in-idlde ()
8575 "Edit the current file in IDL Development environment."
8577 (start-process "idldeclient" nil
8578 idlwave-shell-explicit-file-name "-c" "-e"
8579 (buffer-file-name) "&"))
8581 (defun idlwave-launch-idlhelp ()
8582 "Start the IDLhelp application."
8584 (start-process "idlhelp" nil idlwave-help-application))
8586 ;; Menus - using easymenu.el
8587 (defvar idlwave-mode-menu-def
8589 ["PRO/FUNC menu" idlwave-function-menu t]
8591 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8592 ["Subprogram End" idlwave-end-of-subprogram t]
8593 ["Block Start" idlwave-beginning-of-block t]
8594 ["Block End" idlwave-end-of-block t]
8595 ["Up Block" idlwave-backward-up-block t]
8596 ["Down Block" idlwave-down-block t]
8597 ["Skip Block Backward" idlwave-backward-block t]
8598 ["Skip Block Forward" idlwave-forward-block t])
8600 ["Subprogram" idlwave-mark-subprogram t]
8601 ["Block" idlwave-mark-block t]
8602 ["Header" idlwave-mark-doclib t])
8604 ["Indent Subprogram" idlwave-indent-subprogram t]
8605 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8606 ["Continue/Split line" idlwave-split-line t]
8608 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8609 :selected (symbol-value idlwave-fill-function)])
8611 ["Procedure" idlwave-procedure t]
8612 ["Function" idlwave-function t]
8613 ["Doc Header" idlwave-doc-header t]
8614 ["Log" idlwave-doc-modification t]
8616 ["Case" idlwave-case t]
8617 ["For" idlwave-for t]
8618 ["Repeat" idlwave-repeat t]
8619 ["While" idlwave-while t]
8621 ["Close Block" idlwave-close-block t])
8623 ["Complete" idlwave-complete t]
8625 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8626 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8628 ["3 Function Name" (idlwave-complete 'function) t]
8629 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8631 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8632 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8634 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8635 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8637 ["9 Class Name" idlwave-complete-class t]))
8639 ["Show Routine Info" idlwave-routine-info t]
8640 ["Online Context Help" idlwave-context-help t]
8642 ["Find Routine Source" idlwave-find-module t]
8643 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8645 ["Update Routine Info" idlwave-update-routine-info t]
8648 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
8649 ["Scan Directories" (idlwave-update-routine-info '(16))
8650 (and idlwave-path-alist (not idlwave-catalog-process))]
8651 ["Scan Directories &" (idlwave-update-routine-info '(64))
8652 (and idlwave-path-alist (not idlwave-catalog-process))]
8655 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8656 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8657 ["Check Everything" idlwave-list-all-load-path-shadows t])
8659 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8661 ["Insert TAB character" idlwave-hard-tab t])
8664 ["Generate IDL tags" idlwave-make-tags t]
8665 ["Start IDL shell" idlwave-shell t]
8666 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8667 ["Launch IDL Help" idlwave-launch-idlhelp t])
8670 ["Browse IDLWAVE Group" idlwave-customize t]
8672 ["Build Full Customize Menu" idlwave-create-customize-menu
8673 (fboundp 'customize-menu-create)])
8675 ["Describe Mode" describe-mode t]
8676 ["Abbreviation List" idlwave-list-abbrevs t]
8678 ["Commentary in idlwave.el" idlwave-show-commentary t]
8679 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8681 ["Info" idlwave-info t]
8683 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8685 (defvar idlwave-mode-debug-menu-def
8687 ["Start IDL shell" idlwave-shell t]
8688 ["Save and .RUN buffer" idlwave-shell-save-and-run
8689 (and (boundp 'idlwave-shell-automatic-start)
8690 idlwave-shell-automatic-start)]))
8692 (if (or (featurep 'easymenu) (load "easymenu" t))
8694 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8695 "IDL and WAVE CL editing menu"
8696 idlwave-mode-menu-def)
8697 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8698 "IDL and WAVE CL editing menu"
8699 idlwave-mode-debug-menu-def)))
8701 (defun idlwave-customize ()
8702 "Call the customize function with idlwave as argument."
8704 ;; Try to load the code for the shell, so that we can customize it
8706 (or (featurep 'idlw-shell)
8707 (load "idlw-shell" t))
8708 (customize-browse 'idlwave))
8710 (defun idlwave-create-customize-menu ()
8711 "Create a full customization menu for IDLWAVE, insert it into the menu."
8713 (if (fboundp 'customize-menu-create)
8715 ;; Try to load the code for the shell, so that we can customize it
8717 (or (featurep 'idlw-shell)
8718 (load "idlw-shell" t))
8720 '("IDLWAVE") "Customize"
8721 `(["Browse IDLWAVE group" idlwave-customize t]
8723 ,(customize-menu-create 'idlwave)
8724 ["Set" Custom-set t]
8725 ["Save" Custom-save t]
8726 ["Reset to Current" Custom-reset-current t]
8727 ["Reset to Saved" Custom-reset-saved t]
8728 ["Reset to Standard Settings" Custom-reset-standard t]))
8729 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8730 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8732 (defun idlwave-show-commentary ()
8733 "Use the finder to view the file documentation from `idlwave.el'."
8736 (finder-commentary "idlwave.el"))
8738 (defun idlwave-shell-show-commentary ()
8739 "Use the finder to view the file documentation from `idlw-shell.el'."
8742 (finder-commentary "idlw-shell.el"))
8744 (defun idlwave-info ()
8745 "Read documentation for IDLWAVE in the info system."
8748 (Info-goto-node "(idlwave)"))
8750 (defun idlwave-list-abbrevs (arg)
8751 "Show the code abbreviations define in IDLWAVE mode.
8752 This lists all abbrevs where the replacement text differs from the input text.
8753 These are the ones the users want to learn to speed up their writing.
8755 The function does *not* list abbrevs which replace a word with itself
8756 to call a hook. These hooks are used to change the case of words or
8757 to blink the matching `begin', and the user does not need to know them.
8759 With arg, list all abbrevs with the corresponding hook.
8761 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8764 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8766 str rpl func fmt (len-str 0) (len-rpl 0))
8769 (if (symbol-value sym)
8771 (setq str (symbol-name sym)
8772 rpl (symbol-value sym)
8773 func (symbol-function sym))
8775 (setq func (prin1-to-string func))
8776 (if (and (listp func) (stringp (nth 2 func)))
8777 (setq rpl (concat "EVAL: " (nth 2 func))
8780 (if (or arg (not (string= rpl str)))
8782 (setq len-str (max len-str (length str)))
8783 (setq len-rpl (max len-rpl (length rpl)))
8784 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8787 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8789 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8790 (with-output-to-temp-buffer "*Help*"
8793 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8794 (princ "=========================================\n\n")
8795 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8796 (princ (format fmt "---" "-------" "----")))
8797 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8798 (princ "================================================\n\n")
8799 (princ (format fmt "KEY" "ACTION" ""))
8800 (princ (format fmt "---" "------" "")))
8803 (setq str (car list)
8806 (princ (format fmt str rpl func)))
8808 ;; Make sure each abbreviation uses only one display line
8810 (set-buffer "*Help*")
8811 (setq truncate-lines t)))
8813 ;; Add .pro files to speedbar for support, if it's loaded
8814 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8816 ;; Set an idle timer to load the routine info.
8817 ;; Will only work on systems which support this.
8818 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8820 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
8823 (run-hooks 'idlwave-load-hook)
8827 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
8828 ;;; idlwave.el ends here