1 ;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; Keywords: languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; IDLWAVE enables feature-rich development and interaction with IDL.
33 ;; In the remotely distant past, based on pascal.el, though bears
34 ;; little resemblance to it now.
36 ;; Incorporates many ideas, such as abbrevs, action routines, and
37 ;; continuation line indenting, from wave.el.
38 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
40 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
41 ;; for features, key bindings, and info.
42 ;; Also, Info format documentation is available with `M-x idlwave-info'
44 ;; New versions of IDLWAVE, documentation, and more information
51 ;; Follow the instructions in the INSTALL file of the distribution.
52 ;; In short, put this file on your load path and add the following
53 ;; lines to your .emacs file:
55 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
56 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
57 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
63 ;; The newest version of this file is available from the maintainer's
71 ;; IDLWAVE is documented online in info format. A printable version
72 ;; of the documentation is available from the maintainers webpage (see
79 ;; Thanks to the following people for their contributions and comments:
81 ;; Ulrik Dickow <dickow_at_nbi.dk>
82 ;; Eric E. Dors <edors_at_lanl.gov>
83 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
84 ;; David Huenemoerder <dph_at_space.mit.edu>
85 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
86 ;; Dick Jackson <dick_at_d-jackson.com>
87 ;; Xuyong Liu <liu_at_stsci.edu>
88 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
89 ;; Laurent Mugnier <mugnier_at_onera.fr>
90 ;; Lubos Pochman <lubos_at_rsinc.com>
91 ;; Bob Portmann <portmann_at_al.noaa.gov>
92 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
93 ;; Marty Ryba <ryba_at_ll.mit.edu>
94 ;; Paul Sorenson <aardvark62_at_msn.com>
95 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
96 ;; Phil Williams <williams_at_irc.chmcc.org>
101 ;; IDLWAVE has extensive customize support; to learn about the
102 ;; variables which control the mode's behavior, use `M-x
103 ;; idlwave-customize'.
105 ;; You can set your own preferred values with Customize, or with Lisp
106 ;; code in .emacs. For an example of what to put into .emacs, check
107 ;; the TexInfo documentation or see a complete .emacs available at the
113 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
114 ;; Numerics, Inc. is growing less and less complete as the two
115 ;; languages grow increasingly apart. The mode probably shouldn't
116 ;; even have "WAVE" in its title, but it's catchy, and was required
117 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
119 ;; Moving the point backwards in conjunction with abbrev expansion
120 ;; does not work as I would like it, but this is a problem with
121 ;; emacs abbrev expansion done by the self-insert-command. It ends
122 ;; up inserting the character that expanded the abbrev after moving
123 ;; point backward, e.g., "\cl" expanded with a space becomes
124 ;; "LONG( )" with point before the close paren. This is solved by
125 ;; using a temporary function in `post-command-hook' - not pretty,
128 ;; Tabs and spaces are treated equally as whitespace when filling a
129 ;; comment paragraph. To accomplish this, tabs are permanently
130 ;; replaced by spaces in the text surrounding the paragraph, which
131 ;; may be an undesirable side-effect. Replacing tabs with spaces is
132 ;; limited to comments only and occurs only when a comment
133 ;; paragraph is filled via `idlwave-fill-paragraph'.
135 ;; Muti-statement lines (using "&") on block begin and end lines can
136 ;; ruin the formatting. For example, multiple end statements on a
137 ;; line: endif & endif. Using "&" outside of block begin/end lines
140 ;; Determining the expression at point for printing and other
141 ;; examination commands is somewhat rough: currently only fairly
142 ;; simple entities are found. You can always drag-select or examine
143 ;; a pre-selected region.
145 ;; When forcing completion of method keywords, the initial
146 ;; query for a method has multiple entries for some methods. Would
147 ;; be too difficult to fix this hardly used case.
153 (eval-when-compile (require 'cl
))
157 (unless (fboundp 'line-beginning-position
)
158 (defalias 'line-beginning-position
'point-at-bol
))
159 (unless (fboundp 'line-end-position
)
160 (defalias 'line-end-position
'point-at-eol
))
161 (unless (fboundp 'char-valid-p
)
162 (defalias 'char-valid-p
'characterp
))
164 (if (not (fboundp 'cancel-timer
))
170 ;; Kludge to allow `defcustom' for Emacs 19.
171 (condition-case () (require 'custom
) (error nil
))
172 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
173 nil
;; We've got what we needed
174 ;; We have the old or no custom-library, hack around it!
175 (defmacro defgroup
(&rest args
) nil
)
176 (defmacro defcustom
(var value doc
&rest args
)
177 `(defvar ,var
,value
,doc
))))
179 (defgroup idlwave nil
180 "Major mode for editing IDL .pro files"
182 :link
'(url-link :tag
"Home Page"
183 "http://idlwave.org")
184 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
186 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
187 :link
'(custom-manual "(idlwave)Top")
192 ;;; Variables for indentation behavior ---------------------------------------
194 (defgroup idlwave-code-formatting nil
195 "Indentation and formatting options for IDLWAVE mode."
198 (defcustom idlwave-main-block-indent
0
199 "*Extra indentation for the main block of code.
200 That is the block between the FUNCTION/PRO statement and the END
201 statement for that program unit."
202 :group
'idlwave-code-formatting
205 (defcustom idlwave-block-indent
4
206 "*Extra indentation applied to block lines.
207 If you change this, you probably also want to change `idlwave-end-offset'."
208 :group
'idlwave-code-formatting
211 (defcustom idlwave-end-offset -
4
212 "*Extra indentation applied to block END lines.
213 A value equal to negative `idlwave-block-indent' will make END lines
214 line up with the block BEGIN lines."
215 :group
'idlwave-code-formatting
218 (defcustom idlwave-continuation-indent
2
219 "*Extra indentation applied to continuation lines.
220 This extra offset applies to the first of a set of continuation lines.
221 The following lines receive the same indentation as the first."
222 :group
'idlwave-code-formatting
225 (defcustom idlwave-max-extra-continuation-indent
20
226 "*Maximum additional indentation for special continuation indent.
227 Several special indentations are tried to help line up continuation
228 lines in routine calls or definitions, other statements with
229 parentheses, or assignment statements. This variable specifies a
230 maximum amount by which this special indentation can exceed the
231 standard continuation indentation, otherwise defaulting to a fixed
232 offset. Set to 0 to effectively disable all special continuation
233 indentation, or to a large number (like 100) to enable it in all
234 cases. See also `idlwave-indent-to-open-paren', which can override
236 :group
'idlwave-code-formatting
239 (defcustom idlwave-indent-to-open-paren t
240 "*Non-nil means, indent continuation lines to innermost open
241 parenthesis. This indentation occurs even if otherwise disallowed by
242 `idlwave-max-extra-continuation-indent'. Matching parens and the
243 interleaving args are lined up. Example:
245 x = function_a(function_b(function_c( a, b, [1,2,3, $
251 When this variable is nil, paren alignment may still occur, based on
252 the value of `max-extra-continuation-indent', which, if zero, would
255 x = function_a(function_b(function_c( a, b, [1,2,3, $
260 :group
'idlwave-code-formatting
263 (defcustom idlwave-indent-parens-nested nil
264 "*Non-nil means, indent continuation lines with parens by nesting
265 lines at consecutively deeper levels."
266 :group
'idlwave-code-formatting
270 (defcustom idlwave-hanging-indent t
271 "*If set non-nil then comment paragraphs are indented under the
272 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
274 :group
'idlwave-code-formatting
277 (defcustom idlwave-hang-indent-regexp
"- "
278 "*Regular expression matching the position of the hanging indent
279 in the first line of a comment paragraph. The size of the indent
280 extends to the end of the match for the regular expression."
281 :group
'idlwave-code-formatting
284 (defcustom idlwave-use-last-hang-indent nil
285 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
286 :group
'idlwave-code-formatting
289 (defcustom idlwave-fill-comment-line-only t
290 "*If non-nil then auto fill will only operate on comment lines."
291 :group
'idlwave-code-formatting
294 (defcustom idlwave-auto-fill-split-string t
295 "*If non-nil then auto fill will split strings with the IDL `+' operator.
296 When the line end falls within a string, string concatenation with the
297 '+' operator will be used to distribute a long string over lines.
298 If nil and a string is split then a terminal beep and warning are issued.
300 This variable is ignored when `idlwave-fill-comment-line-only' is
301 non-nil, since in this case code is not auto-filled."
302 :group
'idlwave-code-formatting
305 (defcustom idlwave-split-line-string t
306 "*If non-nil then `idlwave-split-line' will split strings with `+'.
307 When the splitting point of a line falls inside a string, split the string
308 using the `+' string concatenation operator. If nil and a string is
309 split then a terminal beep and warning are issued."
310 :group
'idlwave-code-formatting
313 (defcustom idlwave-no-change-comment
";;;"
314 "*The indentation of a comment that starts with this regular
315 expression will not be changed. Note that the indentation of a comment
316 at the beginning of a line is never changed."
317 :group
'idlwave-code-formatting
320 (defcustom idlwave-begin-line-comment nil
321 "*A comment anchored at the beginning of line.
322 A comment matching this regular expression will not have its
323 indentation changed. If nil the default is \"^;\", i.e., any line
324 beginning with a \";\". Expressions for comments at the beginning of
325 the line should begin with \"^\"."
326 :group
'idlwave-code-formatting
327 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
330 (defcustom idlwave-code-comment
";;[^;]"
331 "*A comment that starts with this regular expression on a line by
332 itself is indented as if it is a part of IDL code. As a result if
333 the comment is not preceded by whitespace it is unchanged."
334 :group
'idlwave-code-formatting
337 ;; Comments not matching any of the above will be indented as a
338 ;; right-margin comment, i.e., to a minimum of `comment-column'.
340 ;;; Routine Info and Completion ---------------------------------------
342 (defgroup idlwave-routine-info nil
343 "Routine Info options for IDLWAVE mode."
346 (defcustom idlwave-use-library-catalogs t
347 "*Non-nil means search the IDL path for library catalog files.
349 These files, named .idlwave_catalog, document routine information for
350 individual directories and libraries of IDL .pro files. Many popular
351 libraries come with catalog files by default, so leaving this on is a
352 usually a good idea.."
353 :group
'idlwave-routine-info
356 (defcustom idlwave-init-rinfo-when-idle-after
10
357 "*Seconds of idle time before routine info is automatically initialized.
358 Initializing the routine info can take long, in particular if a large
359 library catalog is involved. When Emacs is idle for more than the number
360 of seconds specified by this variable, it starts the initialization.
361 The process is split into five steps, in order to keep possible work
362 interruption as short as possible. If one of the steps finishes, and no
363 user input has arrived in the mean time, initialization proceeds immediately
365 A good value for this variable is about 1/3 of the time initialization
366 take in you setup. So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
367 A Value of 0 means, don't initialize automatically."
368 :group
'idlwave-routine-info
371 (defcustom idlwave-scan-all-buffers-for-routine-info t
372 "*Non-nil means, scan buffers for IDL programs when updating info.
373 The scanning is done by the command `idlwave-update-routine-info'.
374 The following values are allowed:
376 nil Don't scan any buffers.
377 t Scan all idlwave-mode buffers in the current editing session.
378 current Scan only the current buffer, but no other buffers."
379 :group
'idlwave-routine-info
381 (const :tag
"No buffer" nil
)
382 (const :tag
"All buffers" t
)
383 (const :tag
"Current buffer only" 'current
)))
385 (defcustom idlwave-query-shell-for-routine-info t
386 "*Non-nil means query the shell for info about compiled routines.
387 Querying the shell is useful to get information about compiled modules,
388 and it is turned on by default. However, when you have a complete library
389 scan, this is not necessary."
390 :group
'idlwave-routine-info
393 (defcustom idlwave-auto-routine-info-updates
394 '(find-file save-buffer kill-buffer compile-buffer
)
395 "*Controls under what circumstances routine info is updated automatically.
399 \(...) A list of circumstances. Allowed members are:
400 find-file Add info for new IDLWAVE buffers.
401 save-buffer Update buffer info when buffer is saved
402 kill-buffer Remove buffer info when buffer gets killed
403 compile-buffer Update shell info after `idlwave-shell-save-and...'"
404 :group
'idlwave-routine-info
406 (const :tag
"Never" nil
)
407 (const :tag
"As often as possible" t
)
408 (set :tag
"Checklist" :greedy t
409 (const :tag
"When visiting a file" find-file
)
410 (const :tag
"When saving a buffer" save-buffer
)
411 (const :tag
"After a buffer was killed" kill-buffer
)
412 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
414 (defcustom idlwave-rinfo-max-source-lines
5
415 "*Maximum number of source files displayed in the Routine Info window.
416 When an integer, it is the maximum number of source files displayed.
417 t means to show all source files."
418 :group
'idlwave-routine-info
421 (defcustom idlwave-library-path nil
422 "Library path for Windows and MacOS. Not needed under Unix. When
423 selecting the directories to scan for IDL user catalog routine info,
424 IDLWAVE can, under UNIX, query the shell for the exact search path
425 \(the value of !PATH). However, under Windows and MacOS (pre-OSX),
426 the IDLWAVE shell does not work. In this case, this variable can be
427 set to specify the paths where IDLWAVE can find PRO files. The shell
428 will only be asked for a list of paths when this variable is nil. The
429 value is a list of directories. A directory preceeded by a `+' will
430 be searched recursively. If you set this variable on a UNIX system,
431 the shell will not be queried. See also `idlwave-system-directory'."
432 :group
'idlwave-routine-info
433 :type
'(repeat (directory)))
435 (defcustom idlwave-system-directory
""
436 "The IDL system directory for Windows and MacOS. Not needed under
437 UNIX. Set this to the value of the `!DIR' system variable in IDL.
438 IDLWAVE uses this to find out which of the library routines belong to
439 the official system library. All files inside the `lib' subdirectory
440 are considered system library files - so don't install private stuff
441 in this directory. On UNIX systems, IDLWAVE queries the shell for the
442 value of `!DIR'. See also `idlwave-library-path'."
443 :group
'idlwave-routine-info
446 (defcustom idlwave-config-directory
447 (convert-standard-filename "~/.idlwave")
448 "*Directory for configuration files and user-library catalog."
449 :group
'idlwave-routine-info
452 (defvar idlwave-user-catalog-file
"idlusercat.el")
453 (defvar idlwave-path-file
"idlpath.el")
455 (defvar idlwave-libinfo-file nil
456 "*Obsolete variable, no longer used.")
458 (defcustom idlwave-special-lib-alist nil
459 "Alist of regular expressions matching special library directories.
460 When listing routine source locations, IDLWAVE gives a short hint where
461 the file defining the routine is located. By default it lists `SystemLib'
462 for routines in the system library `!DIR/lib' and `Library' for anything
463 else. This variable can define additional types. The car of each entry
464 is a regular expression matching the file name (they normally will match
465 on the path). The cdr is the string to be used as identifier. Max 10
467 :group
'idlwave-routine-info
469 (cons regexp string
)))
471 (defcustom idlwave-auto-write-paths t
472 "Write out path (!PATH) and system directory (!DIR) info automatically.
473 Path info is needed to locate library catalog files. If non-nil,
474 whenever the path-list changes as a result of shell-query, etc., it is
475 written to file. Otherwise, the menu option \"Write Paths\" can be
476 used to force a write."
477 :group
'idlwave-routine-info
480 (defgroup idlwave-completion nil
481 "Completion options for IDLWAVE mode."
486 (defconst idlwave-tmp
487 '(choice :tag
"by applying the function"
492 (symbol :tag
"Other"))))
494 (defcustom idlwave-completion-case
'((routine . upcase
)
498 "Association list setting the case of completed words.
500 This variable determines the case (UPPER/lower/Capitalized...) of
501 words inserted into the buffer by completion. The preferred case can
502 be specified separately for routine names, keywords, classes and
504 This alist should therefore have entries for `routine' (normal
505 functions and procedures, i.e. non-methods), `keyword', `class', and
506 `method'. Plausible values are
508 upcase upcase whole word, like `BOX_CURSOR'
509 downcase downcase whole word, like `read_ppm'
510 capitalize capitalize each part, like `Widget_Control'
511 preserve preserve case as is, like `IDLgrView'
513 The value can also be any Emacs Lisp function which transforms the
514 case of characters in a string.
516 A value of `preserve' means that the case of the completed word is
517 identical to the way it was written in the definition statement of the
518 routine. This was implemented to allow for mixed-case completion, in
519 particular of object classes and methods.
520 If a completable word is defined in multiple locations, the meaning of
521 `preserve' is not unique since the different definitions might be
522 cased differently. Therefore IDLWAVE always takes the case of the
523 *first* definition it encounters during routine info collection and
524 uses the case derived from it consistently.
526 Note that a lowercase-only string in the buffer will always be completed in
527 lower case (but see the variable `idlwave-completion-force-default-case').
529 After changing this variable, you need to either restart Emacs or press
530 `C-u C-c C-i' to update the internal lists."
531 :group
'idlwave-completion
533 (cons (symbol :tag
"Derive completion case for")
536 (defcustom idlwave-completion-force-default-case nil
537 "*Non-nil means, completion will always honor `idlwave-completion-case'.
538 When nil, only the completion of a mixed case or upper case string
539 will honor the default settings in `idlwave-completion-case', while
540 the completion of lower case strings will be completed entirely in
542 :group
'idlwave-completion
545 (defcustom idlwave-complete-empty-string-as-lower-case nil
546 "*Non-nil means, the empty string is considered downcase for completion.
547 The case of what is already in the buffer determines the case of completions.
548 When this variable is non-nil, the empty string is considered to be downcase.
549 Completing on the empty string then offers downcase versions of the possible
551 :group
'idlwave-completion
554 (defvar idlwave-default-completion-case-is-down nil
555 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
556 `idlwave-completion-case'.")
558 (defcustom idlwave-buffer-case-takes-precedence nil
559 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
560 To make this possible, we need to re-case everything each time we update
561 the routine info from the buffers. This is slow.
562 The default is to consider the case given in the system and library files
563 first which makes updating much faster."
564 :group
'idlwave-completion
567 (defcustom idlwave-highlight-help-links-in-completion t
568 "*Non-nil means, highlight completions for which system help is available.
569 Help can then be accessed with mouse-3.
570 This option is only effective when the online help system is installed."
571 :group
'idlwave-completion
574 (defcustom idlwave-support-inheritance t
575 "Non-nil means, treat inheritance with completion, online help etc.
576 When nil, IDLWAVE only knows about the native methods and tags of a class,
577 not about inherited ones."
578 :group
'idlwave-routine-info
581 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
582 "List of regular expressions for class-driven keyword inheritance.
583 Keyword inheritance is often tied to class inheritance by \"chaining\"
584 up the class tree. While it cannot be assumed that the presence of an
585 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
586 certain methods this assumption is almost always true. The methods
587 for which to assume this can be set here."
588 :group
'idlwave-routine-info
589 :type
'(repeat (regexp :tag
"Match method:")))
592 (defcustom idlwave-completion-show-classes
1
593 "*Number of classes to show when completing object methods and keywords.
594 When completing methods or keywords for an object with unknown class,
595 the *Completions* buffer will show the valid classes for each completion
598 MyMethod <Class1,Class2,Class3>
600 The value of this variable may be nil to inhibit display, or an integer to
601 indicate the maximum number of classes to display.
603 On XEmacs, a full list of classes will also be placed into a `help-echo'
604 property on the competion items, so that the list of classes for the current
605 item is displayed in the echo area. If the value of this variable is a
606 negative integer, the `help-echo' property will be suppressed."
607 :group
'idlwave-completion
608 :type
'(choice (const :tag
"Don't show" nil
)
609 (integer :tag
"Number of classes shown" 1)))
611 (defcustom idlwave-completion-fontify-classes t
612 "*Non-nil means, fontify the classes in completions buffer.
613 This makes it easier to distinguish the completion items from the extra
614 class info listed. See `idlwave-completion-show-classes'."
615 :group
'idlwave-completion
618 (defcustom idlwave-query-class
'((method-default . nil
)
619 (keyword-default . nil
))
620 "Association list governing specification of object classes for completion.
622 When IDLWAVE tries to complete object-oriented methods, it usually
623 cannot determine the class of a given object from context. In order
624 to provide the user with a correct list of methods or keywords, it
625 needs to determine the appropriate class. IDLWAVE has two ways of
626 doing this (well, three ways if you count the shell... see
627 `idlwave-shell-query-for-class'):
629 1. Combine the items of all available classes which contain this
630 method for the purpose of completion. So when completing a method,
631 all methods of all known classes are available, and when completing
632 a keyword, all keywords allowed for this method in any class are
633 shown. This behavior is very much like normal completion and is
634 therefore the default. It works much better than one might think -
635 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
636 become uncomfortably long. See also
637 `idlwave-completion-show-classes'.
639 2. The second possibility is to ask the user on each occasion. To
640 make this less interruptive, IDLWAVE can store the class as a text
641 property on the object operator `->'. For a given object in the
642 source code, class selection will then be needed only once
643 - for example to complete the method. Keywords to the method can
644 then be completed directly, because the class is already known.
645 You will have to turn on the storage of the selected class
646 explicitly with the variable `idlwave-store-inquired-class'.
648 This variable allows you to configure IDLWAVE's method and
649 method-keyword completion behavior. Its value is an alist, which
650 should contain at least two elements: (method-default . VALUE) and
651 \(keyword-default . VALUE), where VALUE is either t or nil. These
652 specify if the class should be found during method and keyword
653 completion, respectively.
655 The alist may have additional entries specifying exceptions from the
656 keyword completion rule for specific methods, like INIT or
657 GETPROPERTY. In order to turn on class specification for the INIT
658 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
659 :group
'idlwave-completion
661 (cons (const method-default
)
662 (boolean :tag
"Determine class when completing METHODS "))
663 (cons (const keyword-default
)
664 (boolean :tag
"Determine class when completing KEYWORDS "))
666 :tag
"Exceptions to defaults"
668 (cons (string :tag
"MODULE" :value
"")
669 (boolean :tag
"Determine class for this method")))))
671 (defcustom idlwave-store-inquired-class nil
672 "*Non-nil means, store class of a method call as text property on `->'.
673 IDLWAVE sometimes has to ask the user for the class associated with a
674 particular object method call. This happens during the commands
675 `idlwave-routine-info' and `idlwave-complete', depending upon the
676 value of the variable `idlwave-query-class'.
678 When you specify a class, this information can be stored as a text
679 property on the `->' arrow in the source code, so that during the same
680 editing session, IDLWAVE will not have to ask again. When this
681 variable is non-nil, IDLWAVE will store and reuse the class information.
682 The class stored can be checked and removed with `\\[idlwave-routine-info]'
685 The default of this variable is nil, since the result of commands then
686 is more predictable. However, if you know what you are doing, it can
687 be nice to turn this on.
689 An arrow which knows the class will be highlighted with
690 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
691 displays (with prefix arg: deletes) the class stored on the arrow
693 :group
'idlwave-completion
696 (defcustom idlwave-class-arrow-face
'bold
697 "*Face to highlight object operator arrows `->' which carry a class property.
698 When IDLWAVE stores a class name as text property on an object arrow
699 \(see variable `idlwave-store-inquired-class', it highlights the arrow
700 with this font in order to remind the user that this arrow is special."
701 :group
'idlwave-completion
704 (defcustom idlwave-resize-routine-help-window t
705 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
706 :group
'idlwave-completion
709 (defcustom idlwave-keyword-completion-adds-equal t
710 "*Non-nil means, completion automatically adds `=' after completed keywords."
711 :group
'idlwave-completion
714 (defcustom idlwave-function-completion-adds-paren t
715 "*Non-nil means, completion automatically adds `(' after completed function.
716 nil means, don't add anything.
717 A value of `2' means, also add the closing parenthesis and position cursor
719 :group
'idlwave-completion
720 :type
'(choice (const :tag
"Nothing" nil
)
722 (const :tag
"()" 2)))
724 (defcustom idlwave-completion-restore-window-configuration t
725 "*Non-nil means, try to restore the window configuration after completion.
726 When completion is not unique, Emacs displays a list of completions.
727 This messes up your window configuration. With this variable set, IDLWAVE
728 restores the old configuration after successful completion."
729 :group
'idlwave-completion
732 ;;; Variables for abbrev and action behavior -----------------------------
734 (defgroup idlwave-abbrev-and-indent-action nil
735 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
736 The variables in this group govern this."
739 (defcustom idlwave-do-actions nil
740 "*Non-nil means performs actions when indenting.
741 The actions that can be performed are listed in `idlwave-indent-action-table'."
742 :group
'idlwave-abbrev-and-indent-action
745 (defcustom idlwave-abbrev-start-char
"\\"
746 "*A single character string used to start abbreviations in abbrev mode.
747 Possible characters to chose from: ~`\%
748 or even '?'. '.' is not a good choice because it can make structure
749 field names act like abbrevs in certain circumstances.
751 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
752 must set it directly using `setq' in the .emacs file before idlwave.el
754 :group
'idlwave-abbrev-and-indent-action
757 (defcustom idlwave-surround-by-blank nil
758 "*Non-nil means, enable `idlwave-surround'.
759 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
761 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
763 Also see the default key bindings for keys using `idlwave-surround'.
764 Keys are bound and made into actions calling `idlwave-surround' with
765 `idlwave-action-and-binding'.
766 See help for `idlwave-action-and-binding' for examples.
768 Also see help for `idlwave-surround'."
769 :group
'idlwave-abbrev-and-indent-action
772 (defcustom idlwave-pad-keyword t
773 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
774 Whenever `idlwave-surround' is non-nil then this affects how '=' is
775 padded for keywords and for variables. If t, pad the same as for
776 assignments. If nil then spaces are removed. With any other value,
777 spaces are left unchanged."
778 :group
'idlwave-abbrev-and-indent-action
780 (const :tag
"Pad like assignments" t
)
781 (const :tag
"Remove space near `='" nil
)
782 (const :tag
"Keep space near `='" 'keep
)))
784 (defcustom idlwave-show-block t
785 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
786 :group
'idlwave-abbrev-and-indent-action
789 (defcustom idlwave-expand-generic-end nil
790 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
791 :group
'idlwave-abbrev-and-indent-action
794 (defcustom idlwave-reindent-end t
795 "*Non-nil means re-indent line after END was typed."
796 :group
'idlwave-abbrev-and-indent-action
799 (defcustom idlwave-abbrev-move t
800 "*Non-nil means the abbrev hook can move point.
801 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
802 definitions, use the command `list-abbrevs', for abbrevs that move
803 point. Moving point is useful, for example, to place point between
804 parentheses of expanded functions.
806 See `idlwave-check-abbrev'."
807 :group
'idlwave-abbrev-and-indent-action
810 (defcustom idlwave-abbrev-change-case nil
811 "*Non-nil means all abbrevs will be forced to either upper or lower case.
812 If the value t, all expanded abbrevs will be upper case.
813 If the value is 'down then abbrevs will be forced to lower case.
814 If nil, the case will not change.
815 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
816 upper case, regardless of this variable."
817 :group
'idlwave-abbrev-and-indent-action
820 (defcustom idlwave-reserved-word-upcase nil
821 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
822 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
823 Has effect only if in abbrev-mode."
824 :group
'idlwave-abbrev-and-indent-action
827 ;;; Action/Expand Tables.
829 ;; The average user may have difficulty modifying this directly. It
830 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
831 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
832 ;; examples of how to add an action.
834 ;; The action table is used by `idlwave-indent-line' whereas both the
835 ;; action and expand tables are used by `idlwave-indent-and-action'. In
836 ;; general, the expand table is only used when a line is explicitly
837 ;; indented. Whereas, in addition to being used when the expand table
838 ;; is used, the action table is used when a line is indirectly
839 ;; indented via line splitting, auto-filling or a new line creation.
843 ;; Capitalize system vars
844 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
846 ;; Capitalize procedure name
847 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
848 ;; '(capitalize-word 1) t)
850 ;; Capitalize common block name
851 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
852 ;; '(capitalize-word 1) t)
854 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
855 ;; '(capitalize-word -1) t)
857 (defvar idlwave-indent-action-table nil
858 "*Associated array containing action lists of search string (car),
859 and function as a cdr. This table is used by `idlwave-indent-line'.
860 See documentation for `idlwave-do-action' for a complete description of
863 Additions to the table are made with `idlwave-action-and-binding' when a
864 binding is not requested.
865 See help on `idlwave-action-and-binding' for examples.")
867 (defvar idlwave-indent-expand-table nil
868 "*Associated array containing action lists of search string (car),
869 and function as a cdr. The table is used by the
870 `idlwave-indent-and-action' function. See documentation for
871 `idlwave-do-action' for a complete description of the action lists.
873 Additions to the table are made with `idlwave-action-and-binding' when a
874 binding is requested.
875 See help on `idlwave-action-and-binding' for examples.")
877 ;;; Documentation header and history keyword ---------------------------------
879 (defgroup idlwave-documentation nil
880 "Options for documenting IDLWAVE files."
883 ;; FIXME: make defcustom?
884 (defvar idlwave-file-header
911 ; KEYWORD PARAMETERS:
943 ; MODIFICATION HISTORY:
947 "*A list (PATHNAME STRING) specifying the doc-header template to use for
948 summarizing a file. If PATHNAME is non-nil then this file will be included.
949 Otherwise STRING is used. If nil, the file summary will be omitted.
950 For example you might set PATHNAME to the path for the
951 lib_template.pro file included in the IDL distribution.")
953 (defcustom idlwave-header-to-beginning-of-file nil
954 "*Non-nil means, the documentation header will always be at start of file.
955 When nil, the header is positioned between the PRO/FUNCTION line of
956 the current routine and the code, allowing several routine headers in
958 :group
'idlwave-documentation
961 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
962 "*The hook function used to update the timestamp of a function."
963 :group
'idlwave-documentation
966 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
967 "*The modifications keyword to use with the log documentation commands.
968 A ':' is added to the keyword end.
969 Inserted by doc-header and used to position logs by doc-modification.
970 If nil it will not be inserted."
971 :group
'idlwave-documentation
974 (defcustom idlwave-doclib-start
"^;+\\+"
975 "*Regexp matching the start of a document library header."
976 :group
'idlwave-documentation
979 (defcustom idlwave-doclib-end
"^;+-"
980 "*Regexp matching the end of a document library header."
981 :group
'idlwave-documentation
984 ;;; External Programs -------------------------------------------------------
986 (defgroup idlwave-external-programs nil
987 "Path locations of external commands used by IDLWAVE."
990 ;; WARNING: The following variable has recently been moved from
991 ;; idlw-shell.el to this file. I hope this does not break
994 (defcustom idlwave-shell-explicit-file-name
"idl"
995 "*If non-nil, this is the command to run IDL.
996 Should be an absolute file path or path relative to the current environment
997 execution search path. If you want to specify command line switches
998 for the idl program, use `idlwave-shell-command-line-options'.
1000 I know the name of this variable is badly chosen, but I cannot change
1001 it without compromizing backwards-compatibility."
1002 :group
'idlwave-external-programs
1005 (defcustom idlwave-shell-command-line-options nil
1006 "*A list of command line options for calling the IDL program.
1007 Since IDL is executed directly without going through a shell like /bin/sh,
1008 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1009 string for each argument. But you may also give a single string which
1010 contains the options whitespace-separated. Emacs will be kind enough to
1014 (repeat (string :value
"")))
1015 :group
'idlwave-external-programs
)
1017 (defcustom idlwave-help-application
"idlhelp"
1018 "*The external application providing reference help for programming."
1019 :group
'idlwave-external-programs
1022 ;;; Some Shell variables which must be defined here.-----------------------
1024 (defcustom idlwave-shell-debug-modifiers
'()
1025 "List of modifiers to be used for the debugging commands.
1026 Will be used to bind debugging commands in the shell buffer and in all
1027 source buffers. These are additional convenience bindings, the debugging
1028 commands are always available with the `C-c C-d' prefix.
1029 If you set this to '(control shift), this means setting a breakpoint will
1030 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1031 are `control', `meta', `super', `hyper', `alt', and `shift'."
1032 :group
'idlwave-shell-general-setup
1033 :type
'(set :tag
"Specify modifiers"
1041 (defcustom idlwave-shell-automatic-start nil
1042 "*If non-nil attempt invoke idlwave-shell if not already running.
1043 This is checked when an attempt to send a command to an
1044 IDL process is made."
1045 :group
'idlwave-shell-general-setup
1048 ;;; Miscellaneous variables -------------------------------------------------
1050 (defgroup idlwave-misc nil
1051 "Miscellaneous options for IDLWAVE mode."
1054 (defcustom idlwave-startup-message t
1055 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1056 :group
'idlwave-misc
1059 (defcustom idlwave-default-font-lock-items
1060 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1061 common-blocks class-arrows
)
1062 "Items which should be fontified on the default fontification level 2.
1063 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1064 is everything and level 2 is specified by this list.
1065 This variable must be set before IDLWAVE gets loaded. It is
1066 a list of symbols, the following symbols are allowed.
1068 pros-and-functions Procedure and Function definitions
1069 batch-files Batch Files
1070 idlwave-idl-keywords IDL Keywords
1071 label Statement Labels
1072 goto Goto Statements
1073 common-blocks Common Blocks
1074 keyword-parameters Keyword Parameters in routine definitions and calls
1075 system-variables System Variables
1076 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1077 class-arrows Object Arrows with class property"
1078 :group
'idlwave-misc
1081 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1082 (const :tag
"Batch Files" batch-files
)
1083 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1084 (const :tag
"Statement Labels" label
)
1085 (const :tag
"Goto Statements" goto
)
1086 (const :tag
"Tags in Structure Definition" structtag
)
1087 (const :tag
"Structure Name" structname
)
1088 (const :tag
"Common Blocks" common-blocks
)
1089 (const :tag
"Keyword Parameters" keyword-parameters
)
1090 (const :tag
"System Variables" system-variables
)
1091 (const :tag
"FIXME: Warning" fixme
)
1092 (const :tag
"Object Arrows with class property " class-arrows
)))
1094 (defcustom idlwave-mode-hook nil
1095 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1096 :group
'idlwave-misc
1099 (defcustom idlwave-load-hook nil
1100 "Normal hook. Executed when idlwave.el is loaded."
1101 :group
'idlwave-misc
1104 (defvar idlwave-experimental nil
1105 "Non-nil means turn on a few experimental features.
1106 This variable is only for the maintainer, to test difficult stuff,
1107 while still distributing stable releases.
1108 As a user, you should not set this to t.")
1111 ;;; End customization variables section
1114 ;;; Non customization variables
1116 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1117 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1118 ;;; and Carsten Dominik...
1120 ;; The following are the reserved words in IDL. Maybe we should
1121 ;; highlight some more stuff as well?
1122 ;; Procedure declarations. Fontify keyword plus procedure name.
1123 (defvar idlwave-idl-keywords
1124 ;; To update this regexp, update the list of keywords and
1125 ;; evaluate the form.
1131 ;; '("||" "&&" "and" "or" "xor" "not"
1132 ;; "eq" "ge" "gt" "le" "lt" "ne"
1133 ;; "for" "do" "endfor"
1134 ;; "if" "then" "endif" "else" "endelse"
1135 ;; "case" "of" "endcase"
1136 ;; "switch" "break" "continue" "endswitch"
1138 ;; "repeat" "until" "endrep"
1139 ;; "while" "endwhile"
1142 ;; "compile_opt" "forward_function"
1143 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1145 "\\<\\(&&\\|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\\|||\\)\\>")
1148 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1149 ;; Function declarations. Fontify keyword plus function name.
1151 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1152 (1 font-lock-keyword-face
)
1153 (2 font-lock-function-name-face nil t
)))
1157 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1158 (1 font-lock-keyword-face
) ; "common"
1159 (2 font-lock-reference-face nil t
) ; block name
1160 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1161 ;; Start with point after block name and comma
1162 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1164 (1 font-lock-variable-name-face
) ; variable names
1169 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1173 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1177 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1179 ;; The goto statement and its label
1181 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1182 (1 font-lock-keyword-face
)
1183 (2 font-lock-reference-face
)))
1185 ;; Tags in structure definitions. Note that this definition
1186 ;; actually collides with labels, so we have to use the same
1187 ;; face. It also matches named subscript ranges,
1188 ;; e.g. vec{bottom:top]. No good way around this.
1190 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1194 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1195 (2 font-lock-function-name-face
)))
1197 ;; Keyword parameters, like /xlog or ,xrange=[]
1198 ;; This is anchored to the comma preceeding the keyword.
1199 ;; Treats continuation lines, works only during whole buffer
1200 ;; fontification. Slow, use it only in fancy fontification.
1202 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1203 (5 font-lock-reference-face
)))
1205 ;; System variables start with a bang.
1207 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1208 (1 font-lock-variable-name-face
)))
1210 ;; Special and unusual operators (not used because too noisy)
1212 '("[<>#]" (0 font-lock-keyword-face
)))
1214 ;; All operators (not used because too noisy)
1216 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1218 ;; Arrows with text property `idlwave-class'
1220 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1222 (defconst idlwave-font-lock-keywords-1
1223 (list pros-and-functions batch-files
)
1224 "Subdued level highlighting for IDLWAVE mode.")
1226 (defconst idlwave-font-lock-keywords-2
1227 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1228 "Medium level highlighting for IDLWAVE mode.")
1230 (defconst idlwave-font-lock-keywords-3
1231 (list pros-and-functions
1233 idlwave-idl-keywords
1241 "Gaudy level highlighting for IDLWAVE mode."))
1243 (defun idlwave-match-class-arrows (limit)
1244 ;; Match an object arrow with class property
1245 (and idlwave-store-inquired-class
1246 (re-search-forward "->" limit
'limit
)
1247 (get-text-property (match-beginning 0) 'idlwave-class
)))
1249 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1250 "Default expressions to highlight in IDLWAVE mode.")
1252 (defvar idlwave-font-lock-defaults
1253 '((idlwave-font-lock-keywords
1254 idlwave-font-lock-keywords-1
1255 idlwave-font-lock-keywords-2
1256 idlwave-font-lock-keywords-3
)
1258 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1261 (put 'idlwave-mode
'font-lock-defaults
1262 idlwave-font-lock-defaults
) ; XEmacs
1264 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1265 "Regexp to match the start of a full-line comment.
1266 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1267 only by whitespace.")
1269 (defconst idlwave-begin-block-reg
1270 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1271 "Regular expression to find the beginning of a block. The case does
1272 not matter. The search skips matches in comments.")
1274 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1275 "Regular expression to find the beginning of a unit. The case does
1278 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1279 "Regular expression to find the line that indicates the end of unit.
1280 This line is the end of buffer or the start of another unit. The case does
1281 not matter. The search skips matches in comments.")
1283 (defconst idlwave-continue-line-reg
"\\<\\$"
1284 "Regular expression to match a continued line.")
1286 (defconst idlwave-end-block-reg
1287 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1288 "Regular expression to find the end of a block. The case does
1289 not matter. The search skips matches found in comments.")
1291 (defconst idlwave-block-matches
1293 ("function" .
"end")
1294 ("case" .
"endcase")
1295 ("else" .
"endelse")
1298 ("repeat" .
"endrep")
1299 ("switch" .
"endswitch")
1300 ("while" .
"endwhile"))
1301 "Matches between statements and the corresponding END variant.
1302 The cars are the reserved words starting a block. If the block really
1303 begins with BEGIN, the cars are the reserved words before the begin
1304 which can be used to identify the block type.
1305 This is used to check for the correct END type, to close blocks and
1306 to expand generic end statements to their detailed form.")
1308 (defconst idlwave-block-match-regexp
1309 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1310 "Regular expression matching reserved words which can stand before
1311 blocks starting with a BEGIN statement. The matches must have associations
1312 `idlwave-block-matches'")
1314 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1315 "Regular expression matching an IDL identifier.")
1317 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1318 "Regular expression matching IDL system variables.")
1320 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1321 "Regular expression matching IDL variable names.")
1323 (defconst idlwave-label
(concat idlwave-identifier
":")
1324 "Regular expression matching IDL labels.")
1326 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1327 "\\(\\s *" idlwave-identifier
"::\\)?"
1330 (defconst idlwave-statement-match
1332 ;; "endif else" is the only possible "end" that can be
1333 ;; followed by a statement on the same line.
1334 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1335 ;; all other "end"s can not be followed by a statement.
1336 (cons 'end
(list idlwave-end-block-reg nil
))
1337 '(if .
("if\\>" "then"))
1338 '(for .
("for\\>" "do"))
1339 '(begin .
("begin\\>" nil
))
1340 '(pdef .
("pro\\>\\|function\\>" nil
))
1341 '(while .
("while\\>" "do"))
1342 '(repeat .
("repeat\\>" "repeat"))
1343 '(goto .
("goto\\>" nil
))
1344 '(case .
("case\\>" nil
))
1345 '(switch .
("switch\\>" nil
))
1346 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1347 "\\(" idlwave-method-call
"\\s *\\)?"
1350 (cons 'call
(list (concat
1351 "\\(" idlwave-method-call
"\\s *\\)?"
1353 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1354 (cons 'assign
(list (concat
1355 "\\(" idlwave-variable
"\\) *=") nil
)))
1357 "Associated list of statement matching regular expressions.
1358 Each regular expression matches the start of an IDL statement. The
1359 first element of each association is a symbol giving the statement
1360 type. The associated value is a list. The first element of this list
1361 is a regular expression matching the start of an IDL statement for
1362 identifying the statement type. The second element of this list is a
1363 regular expression for finding a substatement for the type. The
1364 substatement starts after the end of the found match modulo
1365 whitespace. If it is nil then the statement has no substatement. The
1366 list order matters since matching an assignment statement exactly is
1367 not possible without parsing. Thus assignment statement become just
1368 the leftover unidentified statements containing an equal sign." )
1370 (defvar idlwave-fill-function
'auto-fill-function
1371 "IDL mode auto fill function.")
1373 (defvar idlwave-comment-indent-function
'comment-indent-function
1374 "IDL mode comment indent function.")
1376 ;; Note that this is documented in the v18 manuals as being a string
1377 ;; of length one rather than a single character.
1378 ;; The code in this file accepts either format for compatibility.
1379 (defvar idlwave-comment-indent-char ?\
1380 "Character to be inserted for IDL comment indentation.
1383 (defconst idlwave-continuation-char ?$
1384 "Character which is inserted as a last character on previous line by
1385 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1387 (defconst idlwave-mode-version
"5.7_22")
1389 (defmacro idlwave-keyword-abbrev
(&rest args
)
1390 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1392 ,(append '(idlwave-check-abbrev) args
))))
1394 ;; If I take the time I can replace idlwave-keyword-abbrev with
1395 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1396 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1397 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1398 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1400 (defmacro idlwave-code-abbrev
(&rest args
)
1401 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1402 Specifically, if the abbrev is in a comment or string it is unexpanded.
1403 Otherwise ARGS forms a list that is evaluated."
1405 ,(prin1-to-string args
) ;; Puts the code in the doc string
1406 (if (idlwave-quoted)
1407 (progn (unexpand-abbrev) nil
)
1410 (defvar idlwave-mode-map
(make-sparse-keymap)
1411 "Keymap used in IDL mode.")
1413 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1414 "Syntax table in use in `idlwave-mode' buffers.")
1416 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
1417 (modify-syntax-entry ?-
"." idlwave-mode-syntax-table
)
1418 (modify-syntax-entry ?
* "." idlwave-mode-syntax-table
)
1419 (modify-syntax-entry ?
/ "." idlwave-mode-syntax-table
)
1420 (modify-syntax-entry ?^
"." idlwave-mode-syntax-table
)
1421 (modify-syntax-entry ?
# "." idlwave-mode-syntax-table
)
1422 (modify-syntax-entry ?
= "." idlwave-mode-syntax-table
)
1423 (modify-syntax-entry ?%
"." idlwave-mode-syntax-table
)
1424 (modify-syntax-entry ?
< "." idlwave-mode-syntax-table
)
1425 (modify-syntax-entry ?
> "." idlwave-mode-syntax-table
)
1426 (modify-syntax-entry ?
\' "\"" idlwave-mode-syntax-table
)
1427 (modify-syntax-entry ?
\" "\"" idlwave-mode-syntax-table
)
1428 (modify-syntax-entry ?
\\ "." idlwave-mode-syntax-table
)
1429 (modify-syntax-entry ?_
"_" idlwave-mode-syntax-table
)
1430 (modify-syntax-entry ?
{ "(}" idlwave-mode-syntax-table
)
1431 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1432 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1433 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1434 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1435 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1436 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1438 (defvar idlwave-find-symbol-syntax-table
1439 (copy-syntax-table idlwave-mode-syntax-table
)
1440 "Syntax table that treats symbol characters as word characters.")
1442 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1443 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1444 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1445 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1447 (defmacro idlwave-with-special-syntax
(&rest body
)
1448 "Execute BODY with a different syntax table."
1449 `(let ((saved-syntax (syntax-table)))
1452 (set-syntax-table idlwave-find-symbol-syntax-table
)
1454 (set-syntax-table saved-syntax
))))
1456 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1457 ; "Execute BODY with a different syntax table."
1458 ; `(let ((saved-syntax (syntax-table)))
1461 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1463 ; (set-syntax-table saved-syntax))))
1465 (defun idlwave-action-and-binding (key cmd
&optional select
)
1466 "KEY and CMD are made into a key binding and an indent action.
1467 KEY is a string - same as for the `define-key' function. CMD is a
1468 function of no arguments or a list to be evaluated. CMD is bound to
1469 KEY in `idlwave-mode-map' by defining an anonymous function calling
1470 `self-insert-command' followed by CMD. If KEY contains more than one
1471 character a binding will only be set if SELECT is 'both.
1473 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1474 replacing any previous value for KEY. If a binding is not set then it
1475 will instead be placed in `idlwave-indent-action-table'.
1477 If the optional argument SELECT is nil then an action and binding are
1478 created. If SELECT is 'noaction, then a binding is always set and no
1479 action is created. If SELECT is 'both then an action and binding
1480 will both be created even if KEY contains more than one character.
1481 Otherwise, if SELECT is non-nil then only an action is created.
1484 No spaces before and 1 after a comma
1485 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1486 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1487 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1488 Capitalize system variables - action only
1489 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1490 (if (not (equal select
'noaction
))
1492 (let* ((table (if select
'idlwave-indent-action-table
1493 'idlwave-indent-expand-table
))
1494 (table-key (regexp-quote key
))
1495 (cell (assoc table-key
(eval table
))))
1497 ;; Replace action command
1500 (set table
(append (eval table
) (list (cons table-key cmd
)))))))
1501 ;; Make key binding for action
1502 (if (or (and (null select
) (= (length key
) 1))
1503 (equal select
'noaction
)
1504 (equal select
'both
))
1505 (define-key idlwave-mode-map key
1508 (self-insert-command 1))
1509 (list (if (listp cmd
)
1513 (fset 'idlwave-debug-map
(make-sparse-keymap))
1515 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1516 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1517 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1518 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1519 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1520 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1521 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1522 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1523 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1524 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1525 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1526 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1527 (define-key idlwave-mode-map
[(meta control h
)] 'idlwave-mark-subprogram
)
1528 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1529 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1530 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1531 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1532 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1533 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1534 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1535 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1536 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1537 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1538 (define-key idlwave-mode-map
[(shift tab
)] 'idlwave-indent-statement
)
1539 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1540 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1541 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1542 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1543 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1544 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1545 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1546 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1547 (listp idlwave-shell-debug-modifiers
)
1548 (not (equal idlwave-shell-debug-modifiers
'())))
1549 ;; Bind the debug commands also with the special modifiers.
1550 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1551 (mods-noshift (delq 'shift
1552 (copy-sequence idlwave-shell-debug-modifiers
))))
1553 (define-key idlwave-mode-map
1554 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1555 'idlwave-shell-save-and-run
)
1556 (define-key idlwave-mode-map
1557 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1558 'idlwave-shell-break-here
)
1559 (define-key idlwave-mode-map
1560 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1561 'idlwave-shell-run-region
)))
1562 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1563 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1564 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1565 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1566 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1567 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1568 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1569 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1570 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1571 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1572 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1573 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1574 (autoload 'idlwave-shell
"idlw-shell"
1575 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1576 (autoload 'idlwave-shell-send-command
"idlw-shell")
1577 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1578 "Run `idlwave-shell' and switch back to current window" t
)
1579 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1580 "Save and run buffer under the shell." t
)
1581 (autoload 'idlwave-shell-break-here
"idlw-shell"
1582 "Set breakpoint in current line." t
)
1583 (autoload 'idlwave-shell-run-region
"idlw-shell"
1584 "Compile and run the region." t
)
1585 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1586 (define-key idlwave-mode-map
"\C-c\C-t" 'idlwave-find-module-this-file
)
1587 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1588 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1589 (define-key idlwave-mode-map
[(control meta ?
\?)] 'idlwave-online-help
)
1590 ;; Pickup both forms of Esc/Meta binding
1591 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1592 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1593 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1594 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1595 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1596 (define-key idlwave-mode-map
1597 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1598 'idlwave-mouse-context-help
)
1600 ;; Set action and key bindings.
1601 ;; See description of the function `idlwave-action-and-binding'.
1602 ;; Automatically add spaces for the following characters
1603 ;(idlwave-action-and-binding "&" '(idlwave-surround -1 -1 '(?&) 1
1604 ; (lambda (char) 0)))
1605 (idlwave-action-and-binding "<" '(idlwave-surround -
1 -
1))
1606 ;; Binding works for both > and ->, by changing the length of the token.
1607 (idlwave-action-and-binding ">" '(idlwave-surround -
1 -
1 '(?-
) 1
1608 'idlwave-gtr-pad-hook
))
1609 (idlwave-action-and-binding "->" '(idlwave-surround -
1 -
1 nil
2) t
)
1610 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1))
1612 ;; Automatically add spaces to equal sign if not keyword
1613 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1618 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1619 ;;; space is inserted (this is the space typed by the user to expanded
1622 (defvar idlwave-mode-abbrev-table nil
1623 "Abbreviation table used for IDLWAVE mode")
1624 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1626 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1627 "Define-abbrev with backward compatibility.
1629 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1630 idlwave-mode-abbrev-table unless TABLE is non-nil."
1631 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1632 (args (list (or table idlwave-mode-abbrev-table
)
1633 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1637 (apply 'define-abbrev
(append args
'(0 t
)))
1638 (error (apply 'define-abbrev args
)))))
1641 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1642 "w" idlwave-mode-syntax-table
)
1648 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1649 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1650 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1651 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1652 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1653 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1654 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1655 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1656 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1658 ;; Keywords, system functions, conversion routines
1660 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1661 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1662 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1663 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1664 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1665 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1666 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1667 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1668 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1669 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1671 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1672 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1673 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1674 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1675 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1676 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1677 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1678 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1679 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1680 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1681 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1682 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1683 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1684 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1685 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1686 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1687 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1688 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1689 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1690 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1693 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1696 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1697 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1698 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1699 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1700 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1701 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1702 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1704 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1705 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1706 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1707 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1708 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1709 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1710 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1711 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1714 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1715 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1717 ;; This section is reserved words only. (From IDL user manual)
1719 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1720 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1721 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1722 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1723 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1724 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1725 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1726 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1727 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1728 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1729 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1730 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1731 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1732 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1733 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1734 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1735 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1736 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1737 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1738 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1739 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1740 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1741 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1742 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1743 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1744 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1745 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1746 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1747 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1748 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1749 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1750 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1751 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1752 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1753 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1754 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1755 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1756 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1757 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1759 (defvar imenu-create-index-function
)
1760 (defvar extract-index-name-function
)
1761 (defvar prev-index-position-function
)
1762 (defvar imenu-extract-index-name-function
)
1763 (defvar imenu-prev-index-position-function
)
1764 ;; defined later - so just make the compiler hush
1765 (defvar idlwave-mode-menu
)
1766 (defvar idlwave-mode-debug-menu
)
1769 (defun idlwave-mode ()
1770 "Major mode for editing IDL source files (version 5.7_22).
1772 The main features of this mode are
1774 1. Indentation and Formatting
1775 --------------------------
1776 Like other Emacs programming modes, C-j inserts a newline and indents.
1777 TAB is used for explicit indentation of the current line.
1779 To start a continuation line, use \\[idlwave-split-line]. This
1780 function can also be used in the middle of a line to split the line
1781 at that point. When used inside a long constant string, the string
1782 is split at that point with the `+' concatenation operator.
1784 Comments are indented as follows:
1786 `;;;' Indentation remains unchanged.
1787 `;;' Indent like the surrounding code
1788 `;' Indent to a minimum column.
1790 The indentation of comments starting in column 0 is never changed.
1792 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1793 comment. The indentation of the second line of the paragraph
1794 relative to the first will be retained. Use
1795 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1796 comments. When the variable `idlwave-fill-comment-line-only' is
1797 nil, code can also be auto-filled and auto-indented.
1799 To convert pre-existing IDL code to your formatting style, mark the
1800 entire buffer with \\[mark-whole-buffer] and execute
1801 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1802 again followed by \\[indent-region] (`indent-region').
1806 IDLWAVE displays information about the calling sequence and the
1807 accepted keyword parameters of a procedure or function with
1808 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1809 source file of a module. These commands know about system
1810 routines, all routines in idlwave-mode buffers and (when the
1811 idlwave-shell is active) about all modules currently compiled under
1812 this shell. It also makes use of pre-compiled or custom-scanned
1813 user and library catalogs many popular libraries ship with by
1814 default. Use \\[idlwave-update-routine-info] to update this
1815 information, which is also used for completion (see item 4).
1819 \\[idlwave-context-help] displays the IDL documentation relevant
1820 for the system variable, keyword, or routine at point. A single
1821 key stroke gets you directly to the right place in the docs. The
1822 HTML help files package must be installed for this to work -- check
1823 the IDLWAVE webpage for the correct package for your version. See
1824 the manual to configure where and how the HTML help is displayed.
1828 \\[idlwave-complete] completes the names of procedures, functions
1829 class names, keyword parameters, system variables and tags, class
1830 tags, structure tags, filenames and much more. It is context
1831 sensitive and figures out what is expected at point. Lower case
1832 strings are completed in lower case, other strings in mixed or
1835 5. Code Templates and Abbreviations
1836 --------------------------------
1837 Many Abbreviations are predefined to expand to code fragments and templates.
1838 The abbreviations start generally with a `\\`. Some examples
1840 \\pr PROCEDURE template
1841 \\fu FUNCTION template
1842 \\c CASE statement template
1843 \\sw SWITCH statement template
1844 \\f FOR loop template
1845 \\r REPEAT Loop template
1846 \\w WHILE loop template
1847 \\i IF statement template
1848 \\elif IF-ELSE statement template
1851 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1852 have direct keybindings - see the list of keybindings below.
1854 \\[idlwave-doc-header] inserts a documentation header at the
1855 beginning of the current program unit (pro, function or main).
1856 Change log entries can be added to the current program unit with
1857 \\[idlwave-doc-modification].
1859 6. Automatic Case Conversion
1860 -------------------------
1861 The case of reserved words and some abbrevs is controlled by
1862 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1864 7. Automatic END completion
1865 ------------------------
1866 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1867 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1871 Loading idlwave.el runs `idlwave-load-hook'.
1872 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1874 9. Documentation and Customization
1875 -------------------------------
1876 Info documentation for this package is available. Use
1877 \\[idlwave-info] to display (complain to your sysadmin if that does
1878 not work). For Postscript, PDF, and HTML versions of the
1879 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1880 IDLWAVE has customize support - see the group `idlwave'.
1884 Here is a list of all keybindings of this mode.
1885 If some of the key bindings below show with ??, use \\[describe-key]
1886 followed by the key sequence to see what the key sequence does.
1888 \\{idlwave-mode-map}"
1891 (kill-all-local-variables)
1893 (if idlwave-startup-message
1894 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1895 (setq idlwave-startup-message nil
)
1897 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1898 (set-syntax-table idlwave-mode-syntax-table
)
1900 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1902 (make-local-variable idlwave-comment-indent-function
)
1903 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1905 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1906 (set (make-local-variable 'comment-start
) ";")
1907 (set (make-local-variable 'require-final-newline
) mode-require-final-newline
)
1908 (set (make-local-variable 'abbrev-all-caps
) t
)
1909 (set (make-local-variable 'indent-tabs-mode
) nil
)
1910 (set (make-local-variable 'completion-ignore-case
) t
)
1912 (use-local-map idlwave-mode-map
)
1914 (when (featurep 'easymenu
)
1915 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1916 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1918 (setq mode-name
"IDLWAVE")
1919 (setq major-mode
'idlwave-mode
)
1920 (setq abbrev-mode t
)
1922 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1923 (setq comment-end
"")
1924 (set (make-local-variable 'comment-multi-line
) nil
)
1925 (set (make-local-variable 'paragraph-separate
)
1926 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1927 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1928 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1929 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1931 ;; Set tag table list to use IDLTAGS as file name.
1932 (if (boundp 'tag-table-alist
)
1933 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1935 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1936 ;; Following line is for Emacs - XEmacs uses the corresponding property
1937 ;; on the `idlwave-mode' symbol.
1938 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1941 (set (make-local-variable 'imenu-create-index-function
)
1942 'imenu-default-create-index-function
)
1943 (set (make-local-variable 'imenu-extract-index-name-function
)
1945 (set (make-local-variable 'imenu-prev-index-position-function
)
1946 'idlwave-prev-index-position
)
1948 ;; Make a local post-command-hook and add our hook to it
1949 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1951 ;; Make local hooks for buffer updates
1952 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1953 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1954 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1956 ;; Setup directories and file, if necessary
1959 ;; Update the routine info with info about current buffer?
1960 (idlwave-new-buffer-update)
1962 ;; Run the mode hook
1963 (run-mode-hooks 'idlwave-mode-hook
))
1965 (defvar idlwave-setup-done nil
)
1966 (defun idlwave-setup ()
1967 (unless idlwave-setup-done
1968 (if (not (file-directory-p idlwave-config-directory
))
1969 (make-directory idlwave-config-directory
))
1970 (setq idlwave-user-catalog-file
(expand-file-name
1971 idlwave-user-catalog-file
1972 idlwave-config-directory
)
1973 idlwave-path-file
(expand-file-name
1975 idlwave-config-directory
))
1976 (idlwave-read-paths) ; we may need these early
1977 (setq idlwave-setup-done t
)))
1980 ;; Code Formatting ----------------------------------------------------
1983 (defun idlwave-push-mark (&rest rest
)
1984 "Push mark for compatibility with Emacs 18/19."
1985 (if (fboundp 'iconify-frame
)
1986 (apply 'push-mark rest
)
1989 (defun idlwave-hard-tab ()
1990 "Inserts TAB in buffer in current position."
1994 ;;; This stuff is experimental
1996 (defvar idlwave-command-hook nil
1997 "If non-nil, a list that can be evaluated using `eval'.
1998 It is evaluated in the lisp function `idlwave-command-hook' which is
1999 placed in `post-command-hook'.")
2001 (defun idlwave-command-hook ()
2002 "Command run after every command.
2003 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2004 sets the variable to zero afterwards."
2005 (and idlwave-command-hook
2006 (listp idlwave-command-hook
)
2008 (eval idlwave-command-hook
)
2010 (setq idlwave-command-hook nil
))
2014 ;; It would be better to use expand.el for better abbrev handling and
2017 (defun idlwave-check-abbrev (arg &optional reserved
)
2018 "Reverses abbrev expansion if in comment or string.
2019 Argument ARG is the number of characters to move point
2020 backward if `idlwave-abbrev-move' is non-nil.
2021 If optional argument RESERVED is non-nil then the expansion
2022 consists of reserved words, which will be capitalized if
2023 `idlwave-reserved-word-upcase' is non-nil.
2024 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2025 is non-nil, unless its value is \`down in which case the abbrev will be
2026 made into all lowercase.
2027 Returns non-nil if abbrev is left expanded."
2028 (if (idlwave-quoted)
2029 (progn (unexpand-abbrev)
2031 (if (and reserved idlwave-reserved-word-upcase
)
2032 (upcase-region last-abbrev-location
(point))
2034 ((equal idlwave-abbrev-change-case
'down
)
2035 (downcase-region last-abbrev-location
(point)))
2036 (idlwave-abbrev-change-case
2037 (upcase-region last-abbrev-location
(point)))))
2038 (if (and idlwave-abbrev-move
(> arg
0))
2039 (if (boundp 'post-command-hook
)
2040 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2041 (backward-char arg
)))
2044 (defun idlwave-in-comment ()
2045 "Returns t if point is inside a comment, nil otherwise."
2047 (let ((here (point)))
2048 (and (idlwave-goto-comment) (> here
(point))))))
2050 (defun idlwave-goto-comment ()
2051 "Move to start of comment delimiter on current line.
2052 Moves to end of line if there is no comment delimiter.
2053 Ignores comment delimiters in strings.
2054 Returns point if comment found and nil otherwise."
2055 (let ((eos (progn (end-of-line) (point)))
2058 ;; Look for first comment delimiter not in a string
2060 (setq found
(search-forward comment-start eos
'lim
))
2061 (while (and found
(idlwave-in-quote))
2062 (setq found
(search-forward comment-start eos
'lim
)))
2063 (store-match-data data
)
2064 (and found
(not (idlwave-in-quote))
2069 (defvar transient-mark-mode
)
2070 (defvar zmacs-regions
)
2071 (defvar mark-active
)
2072 (defun idlwave-region-active-p ()
2073 "Is transient-mark-mode on and the region active?
2074 Works on both Emacs and XEmacs."
2075 (if (featurep 'xemacs
)
2076 (and zmacs-regions
(region-active-p))
2077 (and transient-mark-mode mark-active
)))
2079 (defun idlwave-show-matching-quote ()
2080 "Insert quote and show matching quote if this is end of a string."
2082 (let ((bq (idlwave-in-quote))
2083 (inq last-command-char
))
2084 (if (and bq
(not (idlwave-in-comment)))
2085 (let ((delim (char-after bq
)))
2091 ;; Not the end of a string
2094 (defun idlwave-show-begin-check ()
2095 "Ensure that the previous word was a token before `idlwave-show-begin'.
2096 An END token must be preceded by whitespace."
2097 (if (not (idlwave-quoted))
2102 (looking-at "[ \t\n\f]"))
2103 (idlwave-show-begin))))
2105 (defun idlwave-show-begin ()
2106 "Finds the start of current block and blinks to it for a second.
2107 Also checks if the correct end statement has been used."
2108 ;; All end statements are reserved words
2109 ;; Re-indent end line
2110 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2112 (let* ((pos (point-marker))
2113 (last-abbrev-marker (copy-marker last-abbrev-location
))
2114 (eol-pos (save-excursion (end-of-line) (point)))
2115 begin-pos end-pos end end1
)
2116 (if idlwave-reindent-end
(idlwave-indent-line))
2117 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2118 (when (and (idlwave-check-abbrev 0 t
)
2121 ;; Move inside current block
2122 (goto-char last-abbrev-marker
)
2123 (idlwave-block-jump-out -
1 'nomark
)
2124 (setq begin-pos
(point))
2125 (idlwave-block-jump-out 1 'nomark
)
2126 (setq end-pos
(point))
2127 (if (> end-pos eol-pos
)
2130 (setq end
(buffer-substring
2132 (skip-chars-backward "a-zA-Z")
2135 (goto-char begin-pos
)
2136 (when (setq end1
(cdr (idlwave-block-master)))
2138 ((null end1
)) ; no-operation
2139 ((string= (downcase end
) (downcase end1
))
2141 ((string= (downcase end
) "end")
2143 (if idlwave-expand-generic-end
2147 (insert (if (string= end
"END") (upcase end1
) end1
))
2152 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2157 (defun idlwave-block-master ()
2158 (let ((case-fold-search t
))
2161 ((looking-at "pro\\|case\\|switch\\|function\\>")
2162 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2163 ((looking-at "begin\\>")
2164 (let ((limit (save-excursion
2165 (idlwave-beginning-of-statement)
2168 ((re-search-backward ":[ \t]*\\=" limit t
)
2169 ;; seems to be a case thing
2171 ((re-search-backward idlwave-block-match-regexp limit t
)
2172 (assoc (downcase (match-string 1))
2173 idlwave-block-matches
))
2175 ;; Just a normal block
2176 '("begin" .
"end")))))
2179 (defun idlwave-close-block ()
2180 "Terminate the current block with the correct END statement."
2183 ;; Start new line if we are not in a new line
2184 (unless (save-excursion
2185 (skip-chars-backward " \t")
2187 (let ((idlwave-show-block nil
))
2188 (newline-and-indent)))
2189 (let ((last-abbrev-location (point))) ; for upcasing
2191 (idlwave-show-begin)))
2193 (defun idlwave-gtr-pad-hook (char)
2194 "Let the > symbol expand around -> if present. The new token length
2198 (defun idlwave-surround (&optional before after escape-chars length ec-hook
)
2199 "Surround the LENGTH characters before point with blanks.
2200 LENGTH defaults to 1.
2201 Optional arguments BEFORE and AFTER affect the behavior before and
2202 after the characters (see also description of `idlwave-make-space'):
2206 integer > 0 force exactly n spaces
2207 integer < 0 at least |n| spaces
2209 The function does nothing if any of the following conditions is true:
2210 - `idlwave-surround-by-blank' is nil
2211 - the character before point is inside a string or comment
2212 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2213 This hack is used to avoid padding of `>' when it is part of
2214 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2216 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2217 the named function will be called with a single argument of the
2218 preceeding character. Then idlwave-surround will run as usual if
2219 EC-HOOK returns non-nil, and a new length will be taken from the
2221 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2222 (let* ((length (or length
1)) ; establish a default for LENGTH
2223 (prev-char (char-after (- (point) (1+ length
)))))
2224 (when (or (not (memq prev-char escape-chars
))
2225 (and (fboundp ec-hook
)
2227 (save-excursion (funcall ec-hook prev-char
)))))
2228 (backward-char length
)
2230 (let ((here (point)))
2231 (skip-chars-backward " \t")
2233 ;; avoid clobbering indent
2235 (move-to-column (idlwave-calculate-indent))
2236 (if (<= (point) here
)
2237 (narrow-to-region (point) here
))
2239 (idlwave-make-space before
))
2240 (skip-chars-forward " \t"))
2241 (forward-char length
)
2242 (idlwave-make-space after
)
2243 ;; Check to see if the line should auto wrap
2244 (if (and (equal (char-after (1- (point))) ?\
)
2245 (> (current-column) fill-column
))
2246 (funcall auto-fill-function
))))))
2248 (defun idlwave-make-space (n)
2249 "Make space at point.
2250 The space affected is all the spaces and tabs around point.
2251 If n is non-nil then point is left abs(n) spaces from the beginning of
2252 the contiguous space.
2253 The amount of space at point is determined by N.
2254 If the value of N is:
2256 > 0 - exactly N spaces.
2257 < 0 - a minimum of -N spaces, i.e., do not change if there are
2259 0 - no spaces (i.e. remove any existing space)."
2262 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2264 (end-col (progn (skip-chars-forward " \t") (current-column))))
2265 (delete-horizontal-space)
2268 (idlwave-indent-to (+ start-col n
))
2269 (goto-char (+ left n
)))
2271 (idlwave-indent-to end-col
(- n
))
2272 (goto-char (- left n
)))
2276 (defun idlwave-newline ()
2277 "Inserts a newline and indents the current and previous line."
2280 ;; Handle unterminated single and double quotes
2281 ;; If not in a comment and in a string then insertion of a newline
2282 ;; will mean unbalanced quotes.
2284 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2286 (message "Warning: unbalanced quotes?")))
2289 ;; The current line is being split, the cursor should be at the
2290 ;; beginning of the new line skipping the leading indentation.
2292 ;; The reason we insert the new line before indenting is that the
2293 ;; indenting could be confused by keywords (e.g. END) on the line
2294 ;; after the split point. This prevents us from just using
2295 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2297 (beginning-of-line 0)
2298 (idlwave-indent-line)
2300 (idlwave-indent-line))
2303 ;; Use global variable 'comment-column' to set parallel comment
2305 ;; Modeled on lisp.el
2306 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2307 (defun idlwave-comment-hook ()
2308 "Compute indent for the beginning of the IDL comment delimiter."
2309 (if (or (looking-at idlwave-no-change-comment
)
2310 (if idlwave-begin-line-comment
2311 (looking-at idlwave-begin-line-comment
)
2314 (if (looking-at idlwave-code-comment
)
2315 (if (save-excursion (skip-chars-backward " \t") (bolp))
2316 ;; On line by itself, indent as code
2317 (let ((tem (idlwave-calculate-indent)))
2318 (if (listp tem
) (car tem
) tem
))
2319 ;; after code - do not change
2321 (skip-chars-backward " \t")
2322 (max (if (bolp) 0 (1+ (current-column)))
2325 (defun idlwave-split-line ()
2326 "Continue line by breaking line at point and indent the lines.
2327 For a code line insert continuation marker. If the line is a line comment
2328 then the new line will contain a comment with the same indentation.
2329 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2332 ;; Expand abbreviation, just like normal RET would.
2333 (and abbrev-mode
(expand-abbrev))
2335 (if (not (idlwave-in-comment))
2336 ;; For code line add continuation.
2337 ;; Check if splitting a string.
2339 (if (setq beg
(idlwave-in-quote))
2340 (if idlwave-split-line-string
2341 ;; Split the string.
2342 (progn (insert (setq beg
(char-after beg
)) " + "
2343 idlwave-continuation-char beg
)
2345 (newline-and-indent)
2347 ;; Do not split the string.
2349 (message "Warning: continuation inside string!!")
2350 (insert " " idlwave-continuation-char
))
2351 ;; Not splitting a string.
2352 (if (not (member (char-before) '(?\ ?
\t)))
2354 (insert idlwave-continuation-char
)
2355 (newline-and-indent)))
2356 (indent-new-comment-line))
2357 ;; Indent previous line
2358 (setq beg
(- (point-max) (point)))
2360 (idlwave-indent-line)
2361 (goto-char (- (point-max) beg
))
2362 ;; Reindent new line
2363 (idlwave-indent-line)))
2365 (defun idlwave-beginning-of-subprogram ()
2366 "Moves point to the beginning of the current program unit."
2368 (idlwave-find-key idlwave-begin-unit-reg -
1))
2370 (defun idlwave-end-of-subprogram ()
2371 "Moves point to the start of the next program unit."
2373 (idlwave-end-of-statement)
2374 (idlwave-find-key idlwave-end-unit-reg
1))
2376 (defun idlwave-mark-statement ()
2377 "Mark current IDL statement."
2379 (idlwave-end-of-statement)
2380 (let ((end (point)))
2381 (idlwave-beginning-of-statement)
2382 (idlwave-push-mark end nil t
)))
2384 (defun idlwave-mark-block ()
2385 "Mark containing block."
2387 (idlwave-end-of-statement)
2388 (idlwave-backward-up-block -
1)
2389 (idlwave-end-of-statement)
2390 (let ((end (point)))
2391 (idlwave-backward-block)
2392 (idlwave-beginning-of-statement)
2393 (idlwave-push-mark end nil t
)))
2396 (defun idlwave-mark-subprogram ()
2397 "Put mark at beginning of program, point at end.
2398 The marks are pushed."
2400 (idlwave-end-of-statement)
2401 (idlwave-beginning-of-subprogram)
2402 (let ((beg (point)))
2403 (idlwave-forward-block)
2404 (idlwave-push-mark beg nil t
))
2405 (exchange-point-and-mark))
2407 (defun idlwave-backward-up-block (&optional arg
)
2408 "Move to beginning of enclosing block if prefix ARG >= 0.
2409 If prefix ARG < 0 then move forward to enclosing block end."
2411 (idlwave-block-jump-out (- arg
) 'nomark
))
2413 (defun idlwave-beginning-of-block ()
2414 "Go to the beginning of the current block."
2416 (idlwave-block-jump-out -
1 'nomark
)
2419 (defun idlwave-end-of-block ()
2420 "Go to the beginning of the current block."
2422 (idlwave-block-jump-out 1 'nomark
)
2425 (defun idlwave-forward-block ()
2426 "Move across next nested block."
2428 (if (idlwave-down-block 1)
2429 (idlwave-block-jump-out 1 'nomark
)))
2431 (defun idlwave-backward-block ()
2432 "Move backward across previous nested block."
2434 (if (idlwave-down-block -
1)
2435 (idlwave-block-jump-out -
1 'nomark
)))
2437 (defun idlwave-down-block (&optional arg
)
2439 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2440 Returns non-nil if successfull."
2445 (let ((eos (save-excursion
2446 (idlwave-block-jump-out -
1 'nomark
)
2448 (if (setq status
(idlwave-find-key
2449 idlwave-end-block-reg -
1 'nomark eos
))
2450 (idlwave-beginning-of-statement)
2451 (message "No nested block before beginning of containing block.")))
2453 (let ((eos (save-excursion
2454 (idlwave-block-jump-out 1 'nomark
)
2456 (if (setq status
(idlwave-find-key
2457 idlwave-begin-block-reg
1 'nomark eos
))
2458 (idlwave-end-of-statement)
2459 (message "No nested block before end of containing block."))))
2462 (defun idlwave-mark-doclib ()
2463 "Put point at beginning of doc library header, mark at end.
2464 The marks are pushed."
2468 (goto-char (point-max))
2469 (if (re-search-backward idlwave-doclib-start nil t
)
2471 (setq beg
(progn (beginning-of-line) (point)))
2472 (if (re-search-forward idlwave-doclib-end nil t
)
2475 (idlwave-push-mark beg nil t
)
2476 (message "Could not find end of doc library header.")))
2477 (message "Could not find doc library header start.")
2478 (goto-char here
)))))
2481 (defun idlwave-current-routine ()
2482 "Return (NAME TYPE CLASS) of current routine."
2485 (idlwave-beginning-of-subprogram)
2486 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2487 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2489 (class (idlwave-sintern-class (match-string 3)))
2490 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2491 (list name type class
)))))
2493 (defvar idlwave-shell-prompt-pattern
)
2494 (defun idlwave-beginning-of-statement ()
2495 "Move to beginning of the current statement.
2496 Skips back past statement continuations.
2497 Point is placed at the beginning of the line whether or not this is an
2501 ((eq major-mode
'idlwave-shell-mode
)
2502 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2503 (goto-char (match-end 0))))
2505 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2506 (idlwave-previous-statement)
2507 (beginning-of-line)))))
2509 (defun idlwave-previous-statement ()
2510 "Moves point to beginning of the previous statement.
2511 Returns t if the current line before moving is the beginning of
2512 the first non-comment statement in the file, and nil otherwise."
2514 (let (first-statement)
2515 (if (not (= (forward-line -
1) 0))
2516 ;; first line in file
2518 ;; skip blank lines, label lines, include lines and line comments
2520 ;; The current statement is the first statement until we
2521 ;; reach another statement.
2522 (setq first-statement
2524 (looking-at idlwave-comment-line-start-skip
)
2525 (looking-at "[ \t]*$")
2526 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2528 (= (forward-line -
1) 0)))
2529 ;; skip continuation lines
2533 (idlwave-is-continuation-line))
2534 (= (forward-line -
1) 0)))
2537 (defun idlwave-end-of-statement ()
2538 "Moves point to the end of the current IDL statement.
2539 If not in a statement just moves to end of line. Returns position."
2541 (while (and (idlwave-is-continuation-line)
2542 (= (forward-line 1) 0))
2543 (while (and (idlwave-is-comment-or-empty-line)
2544 (= (forward-line 1) 0))))
2548 (defun idlwave-end-of-statement0 ()
2549 "Moves point to the end of the current IDL statement.
2550 If not in a statement just moves to end of line. Returns position."
2552 (while (and (idlwave-is-continuation-line)
2553 (= (forward-line 1) 0)))
2557 (defun idlwave-next-statement ()
2558 "Moves point to beginning of the next IDL statement.
2559 Returns t if that statement is the last
2560 non-comment IDL statement in the file, and nil otherwise."
2562 (let (last-statement)
2563 (idlwave-end-of-statement)
2564 ;; skip blank lines, label lines, include lines and line comments
2565 (while (and (= (forward-line 1) 0)
2566 ;; The current statement is the last statement until
2567 ;; we reach a new statement.
2568 (setq last-statement
2570 (looking-at idlwave-comment-line-start-skip
)
2571 (looking-at "[ \t]*$")
2572 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2573 (looking-at "^@")))))
2576 (defun idlwave-skip-multi-commands (&optional lim
)
2577 "Skip past multiple commands on a line (with `&')."
2578 (let ((save-point (point)))
2579 (when (re-search-forward ".*&" lim t
)
2580 (goto-char (match-end 0))
2581 (if (idlwave-quoted)
2582 (goto-char save-point
)
2583 (if (eq (char-after (- (point) 2)) ?
&) (goto-char save-point
))))
2586 (defun idlwave-skip-label-or-case ()
2587 "Skip label or case statement element.
2588 Returns position after label.
2589 If there is no label point is not moved and nil is returned."
2590 ;; Case expressions and labels are terminated by a colon.
2591 ;; So we find the first colon in the line and make sure
2592 ;; - no `?' is before it (might be a ? b : c)
2593 ;; - it is not in a comment
2594 ;; - not in a string constant
2595 ;; - not in parenthesis (like a[0:3])
2596 ;; - not followed by another ":" in explicit class, ala a->b::c
2597 ;; As many in this mode, this function is heuristic and not an exact
2599 (let* ((start (point))
2600 (eos (save-excursion (idlwave-end-of-statement) (point)))
2601 (end (idlwave-find-key ":" 1 'nomark eos
)))
2603 (= (nth 0 (parse-partial-sexp start end
)) 0)
2604 (not (string-match "\\?" (buffer-substring start end
)))
2605 (not (string-match "^::" (buffer-substring end eos
))))
2612 (defun idlwave-start-of-substatement (&optional pre
)
2613 "Move to start of next IDL substatement after point.
2614 Uses the type of the current IDL statement to determine if the next
2615 statement is on a new line or is a subpart of the current statement.
2616 Returns point at start of substatement modulo whitespace.
2617 If optional argument is non-nil move to beginning of current
2619 (let ((orig (point))
2620 (eos (idlwave-end-of-statement))
2623 (idlwave-beginning-of-statement)
2624 (idlwave-skip-label-or-case)
2625 (if (< (point) orig
)
2626 (idlwave-skip-multi-commands orig
))
2628 ;; Continue looking for substatements until we are past orig
2629 (while (and (<= (point) orig
) (not (eobp)))
2631 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2632 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2634 (idlwave-find-key nst
1 'nomark eos
))
2635 (goto-char (match-end 0)))
2636 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2637 (setq ifnest
(1- ifnest
))
2638 (goto-char (match-end 0)))
2640 (idlwave-next-statement))))
2641 (if pre
(goto-char last
))
2642 ;; If a continuation line starts here, move to next line
2643 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2644 (beginning-of-line 2))
2647 (defun idlwave-statement-type ()
2648 "Return the type of the current IDL statement.
2649 Uses `idlwave-statement-match' to return a cons of (type . point) with
2650 point the ending position where the type was determined. Type is the
2651 association from `idlwave-statement-match', i.e. the cons cell from the
2652 list not just the type symbol. Returns nil if not an identifiable
2655 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2656 ;; and possibly comments
2657 (while (looking-at "[ \t]*\\$")
2659 (skip-chars-forward " \t")
2660 (let ((st idlwave-statement-match
)
2661 (case-fold-search t
))
2662 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2663 (setq st
(cdr st
))))
2665 (append st
(match-end 0))))))
2667 (defun idlwave-expand-equal (&optional before after
)
2668 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2669 assignment. Which case is determined using
2670 `idlwave-start-of-substatement' and `idlwave-statement-type'. The
2671 equal sign will be surrounded by BEFORE and AFTER blanks. If
2672 `idlwave-pad-keyword' is t then keyword assignment is treated just
2673 like assignment statements. When nil, spaces are removed for keyword
2674 assignment. Any other value keeps the current space around the `='.
2675 Limits in for loops are treated as keyword assignment.
2677 Starting with IDL 6.0, a number of op= assignments are available.
2678 Since ambiguities of the form:
2683 can occur, alphanumeric operator assignment will never be pre-padded,
2684 only post-padded. You must use a space before these to disambiguate
2685 \(not just for padding, but for proper parsing by IDL too!). Other
2686 operators, such as ##=, ^=, etc., will be pre-padded.
2688 See `idlwave-surround'."
2689 (if idlwave-surround-by-blank
2691 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2693 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2697 (let ((case-fold-search t
))
2700 (re-search-backward non-an-ops nil t
)
2701 ;; Why doesn't ##? work for both?
2702 (re-search-backward "\\(#\\)\\=" nil t
))
2703 (setq len
(1+ (length (match-string 1))))
2704 (when (re-search-backward an-ops nil t
)
2705 ;(setq begin nil) ; won't modify begin
2706 (setq len
(1+ (length (match-string 1))))))))
2708 (if (eq t idlwave-pad-keyword
)
2709 ;; Everything gets padded equally
2710 (idlwave-surround before after nil len
)
2711 ;; Treating keywords/for variables specially...
2712 (let ((st (save-excursion ; To catch "for" variables
2713 (idlwave-start-of-substatement t
)
2714 (idlwave-statement-type)))
2715 (what (save-excursion ; To catch keywords
2716 (skip-chars-backward "= \t")
2717 (nth 2 (idlwave-where)))))
2718 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2719 (memq (caar st
) '(for pdef
)))
2721 ((null idlwave-pad-keyword
)
2722 (idlwave-surround 0 0)
2724 (t))) ; leave any spaces alone
2725 (t (idlwave-surround before after nil len
))))))))
2728 (defun idlwave-indent-and-action (&optional arg
)
2729 "Call `idlwave-indent-line' and do expand actions.
2730 With prefix ARG non-nil, indent the entire sub-statement."
2733 (if (and idlwave-expand-generic-end
2734 (re-search-backward "\\<\\(end\\)\\s-*\\="
2735 (max 0 (- (point) 10)) t
)
2736 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2737 (progn (goto-char (match-end 1))
2738 ;;Expand the END abbreviation, just as RET or Space would have.
2739 (if abbrev-mode
(expand-abbrev)
2740 (idlwave-show-begin)))))
2741 (when (and (not arg
) current-prefix-arg
)
2742 (setq arg current-prefix-arg
)
2743 (setq current-prefix-arg nil
))
2745 (idlwave-indent-statement)
2746 (idlwave-indent-line t
)))
2748 (defun idlwave-indent-line (&optional expand
)
2749 "Indents current IDL line as code or as a comment.
2750 The actions in `idlwave-indent-action-table' are performed.
2751 If the optional argument EXPAND is non-nil then the actions in
2752 `idlwave-indent-expand-table' are performed."
2754 ;; Move point out of left margin.
2756 (skip-chars-backward " \t")
2758 (skip-chars-forward " \t"))
2759 (let ((mloc (point-marker)))
2762 (if (looking-at idlwave-comment-line-start-skip
)
2763 ;; Indentation for a line comment
2765 (skip-chars-forward " \t")
2766 (idlwave-indent-left-margin (idlwave-comment-hook)))
2770 ;; Before indenting, run action routines.
2772 (if (and expand idlwave-do-actions
)
2773 (mapcar 'idlwave-do-action idlwave-indent-expand-table
))
2775 (if idlwave-do-actions
2776 (mapcar 'idlwave-do-action idlwave-indent-action-table
))
2778 ;; No longer expand abbrevs on the line. The user can do this
2779 ;; manually using expand-region-abbrevs.
2781 ;; Indent for code line
2786 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2788 (looking-at "^[ \t]*@"))
2792 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2793 ;; Adjust parallel comment
2795 (if (idlwave-in-comment)
2796 ;; Emacs 21 is too smart with fill-column on comment indent
2797 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2800 (indent-for-comment)))))
2802 ;; Get rid of marker
2803 (set-marker mloc nil
)))
2805 (defun idlwave-do-action (action)
2806 "Perform an action repeatedly on a line.
2807 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2808 either a function name to be called with `funcall' or a list to be
2809 evaluated with `eval'. The action performed by FUNC should leave point
2810 after the match for REG - otherwise an infinite loop may be entered."
2811 (let ((action-key (car action
))
2812 (action-routine (cdr action
)))
2814 (while (idlwave-look-at action-key
)
2815 (if (listp action-routine
)
2816 (eval action-routine
)
2817 (funcall action-routine
)))))
2819 (defun idlwave-indent-to (col &optional min
)
2820 "Indent from point with spaces until column COL.
2821 Inserts space before markers at point."
2822 (if (not min
) (setq min
0))
2823 (insert-before-markers
2824 (make-string (max min
(- col
(current-column))) ?\
)))
2826 (defun idlwave-indent-left-margin (col)
2827 "Indent the current line to column COL.
2828 Indents such that first non-whitespace character is at column COL
2829 Inserts spaces before markers at point."
2832 (delete-horizontal-space)
2833 (idlwave-indent-to col
)))
2835 (defun idlwave-indent-subprogram ()
2836 "Indents program unit which contains point."
2839 (idlwave-end-of-statement)
2840 (idlwave-beginning-of-subprogram)
2841 (let ((beg (point)))
2842 (idlwave-forward-block)
2843 (message "Indenting subprogram...")
2844 (indent-region beg
(point) nil
))
2845 (message "Indenting subprogram...done.")))
2847 (defun idlwave-indent-statement ()
2848 "Indent current statement, including all continuation lines."
2851 (idlwave-beginning-of-statement)
2852 (let ((beg (point)))
2853 (idlwave-end-of-statement)
2854 (indent-region beg
(point) nil
))))
2856 (defun idlwave-calculate-indent ()
2857 "Return appropriate indentation for current line as IDL code."
2861 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2863 ((idlwave-look-at idlwave-begin-unit-reg
)
2865 ;; Check for continuation line
2867 (and (= (forward-line -
1) 0)
2868 (idlwave-is-continuation-line)))
2869 (idlwave-calculate-cont-indent))
2870 ;; calculate indent based on previous and current statements
2871 (t (let* (beg-prev-pos
2873 ;; calculate indent based on previous statement
2876 ;; Beginning of file
2878 (idlwave-previous-statement)
2879 (setq beg-prev-pos
(point)))
2882 ((idlwave-look-at idlwave-begin-unit-reg t
)
2883 (+ (idlwave-current-statement-indent)
2884 idlwave-main-block-indent
))
2886 ((idlwave-look-at idlwave-begin-block-reg t
)
2887 (+ (idlwave-min-current-statement-indent)
2888 idlwave-block-indent
))
2890 ((idlwave-look-at idlwave-end-block-reg t
)
2892 ;; Match to the *beginning* of the block opener
2893 (goto-char beg-prev-pos
)
2894 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2895 (idlwave-min-current-statement-indent)))
2896 ;; idlwave-end-offset
2897 ;; idlwave-block-indent))
2899 ;; Default to current indent
2900 ((idlwave-current-statement-indent))))))
2901 ;; adjust the indentation based on the current statement
2904 ((idlwave-look-at idlwave-end-block-reg
)
2905 (+ the-indent idlwave-end-offset
))
2909 ;; Parentheses indent
2912 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2913 "Calculate the continuation indent inside a paren group.
2914 Returns a cons-cell with (open . indent), where open is the
2915 location of the open paren"
2916 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2917 ;; Found an innermost open paren.
2920 ;; Line up with next word unless this is a closing paren.
2923 ;; Plain Kernighan-style nested indent
2924 (idlwave-indent-parens-nested
2925 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2927 ;; This is a closed paren - line up under open paren.
2931 ;; Empty (or just comment) follows -- revert to basic indent
2935 (looking-at "[ \t$]*\\(;.*\\)?$"))
2938 ;; Line up with first word after any blank space
2940 (skip-chars-forward " \t")
2941 (current-column))))))))
2943 (defun idlwave-calculate-cont-indent ()
2944 "Calculates the IDL continuation indent column from the previous
2945 statement. Note that here previous statement usually means the
2946 beginning of the current statement if this statement is a continuation
2947 of the previous line. Various special types of continuations,
2948 including assignments, routine definitions, and parenthetical
2949 groupings, are treated separately."
2951 (let* ((case-fold-search t
)
2952 (end-reg (progn (beginning-of-line) (point)))
2953 (beg-last-statement (save-excursion (idlwave-previous-statement)
2955 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
2956 (if (eq (line-beginning-position) end-reg
)
2957 (goto-char beg-last-statement
)
2959 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
2960 idlwave-continuation-indent
))
2961 fancy-nonparen-indent fancy-paren-indent
)
2963 ;; Align then with its matching if, etc.
2964 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
2965 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
2966 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
2967 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2969 ("\\<case\\>" .
"[ \t]*of")))
2975 (while (setq match
(car matchers
))
2976 (if (looking-at (cdr match
))
2977 (throw 'exit
(car match
)))
2978 (setq matchers
(cdr matchers
)))))
2979 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
2980 (if (looking-at "end") ;; that one's special
2981 (- (idlwave-current-indent)
2982 (+ idlwave-block-indent idlwave-end-offset
))
2983 (idlwave-current-indent)))
2985 ;; Indent in from the previous line for continuing statements
2986 ((let ((matchers '("\\<then\\>"
2993 (if (/= (forward-line -
1) 0)
2995 (while (setq match
(car matchers
))
2996 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
2999 (setq matchers
(cdr matchers
)))))
3000 (+ idlwave-continuation-indent
(idlwave-current-indent)))
3002 ;; Parenthetical indent, either traditional or Kernighan style
3003 ((setq fancy-paren-indent
3004 (let* ((end-reg end-reg
)
3007 (skip-chars-forward " \t")
3008 (looking-at "\\s)")))
3011 (while (setq indent-cons
(idlwave-calculate-paren-indent
3012 beg-reg end-reg close-exp
))
3013 ;; First permitted containing paren
3015 idlwave-indent-to-open-paren
3016 idlwave-indent-parens-nested
3017 (null (cdr indent-cons
))
3018 (< (- (cdr indent-cons
) basic-indent
)
3019 idlwave-max-extra-continuation-indent
))
3020 (throw 'loop
(cdr indent-cons
)))
3021 (setq end-reg
(car indent-cons
))))))
3024 ;; A continued assignment, or procedure call/definition
3026 (> idlwave-max-extra-continuation-indent
0)
3027 (setq fancy-nonparen-indent
3030 (while (idlwave-look-at "&")) ; skip continued statements
3032 ;; A continued Procedure call or definition
3034 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3035 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3036 (goto-char (match-end 0))
3037 ;; Comment only, or blank line with "$"? Basic indent.
3038 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3042 ;; Continued assignment (with =):
3044 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3045 (goto-char (match-end 0))
3046 (if (null (idlwave-what-function beg-reg
))
3047 (throw 'assign t
))))
3050 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3052 (goto-char beg-last-statement
)
3053 (eq (caar (idlwave-statement-type)) 'for
)))
3054 (current-column))))))
3055 (< (- fancy-nonparen-indent basic-indent
)
3056 idlwave-max-extra-continuation-indent
))
3057 (if fancy-paren-indent
;calculated but disallowed paren indent
3058 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3059 fancy-nonparen-indent
))
3061 ;; Basic indent, by default
3062 (t basic-indent
)))))
3066 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3067 "Move to next match of the regular expression KEY-RE.
3068 Matches inside comments or string constants will be ignored.
3069 If DIR is negative, the search will be backwards.
3070 At a successful match, the mark is pushed unless NOMARK is non-nil.
3071 Searches are limited to LIMIT.
3072 Searches are case-insensitive and use a special syntax table which
3073 treats `$' and `_' as word characters.
3074 Return value is the beginning of the match or (in case of failure) nil."
3075 (setq dir
(or dir
0))
3076 (let ((case-fold-search t
)
3077 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3079 (idlwave-with-special-syntax
3082 (while (funcall search-func key-re limit t
)
3083 (if (not (idlwave-quoted))
3084 (throw 'exit
(setq found
(match-beginning 0)))
3085 (if (or (and (> dir
0) (eobp))
3086 (and (< dir
0) (bobp)))
3087 (throw 'exit nil
)))))))
3090 (if (not nomark
) (push-mark))
3095 (defun idlwave-block-jump-out (&optional dir nomark
)
3096 "When optional argument DIR is non-negative, move forward to end of
3097 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3098 regular expressions. When DIR is negative, move backwards to block beginning.
3099 Recursively calls itself to skip over nested blocks. DIR defaults to
3100 forward. Calls `push-mark' unless the optional argument NOMARK is
3101 non-nil. Movement is limited by the start of program units because of
3102 possibility of unbalanced blocks."
3104 (or dir
(setq dir
0))
3105 (let* ((here (point))
3106 (case-fold-search t
)
3107 (limit (if (>= dir
0) (point-max) (point-min)))
3108 (block-limit (if (>= dir
0)
3109 idlwave-begin-block-reg
3110 idlwave-end-block-reg
))
3112 (block-reg (concat idlwave-begin-block-reg
"\\|"
3113 idlwave-end-block-reg
))
3114 (unit-limit (or (save-excursion
3117 idlwave-begin-unit-reg dir t limit
)
3120 idlwave-end-unit-reg dir t limit
)))
3122 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3123 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3124 (while (and found
(looking-at block-limit
))
3125 (if (>= dir
0) (forward-word 1))
3126 (idlwave-block-jump-out dir t
)
3127 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3128 (if (not nomark
) (push-mark here
))
3129 (if (not found
) (goto-char unit-limit
)
3130 (if (>= dir
0) (forward-word 1)))))
3132 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3133 "The minimum indent in the current statement."
3134 (idlwave-beginning-of-statement)
3135 (if (not (idlwave-is-continuation-line))
3136 (idlwave-current-indent)
3137 (let ((min (idlwave-current-indent)) comm-or-empty
)
3138 (while (and (= (forward-line 1) 0)
3139 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3140 (idlwave-is-continuation-line))
3141 (or (null end-reg
) (< (point) end-reg
)))
3142 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3143 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3145 (min min
(idlwave-current-indent))))))
3147 (defun idlwave-current-statement-indent (&optional last-line
)
3148 "Return indentation of the current statement.
3149 If in a statement, moves to beginning of statement before finding indent."
3151 (idlwave-end-of-statement)
3152 (idlwave-beginning-of-statement))
3153 (idlwave-current-indent))
3155 (defun idlwave-current-indent ()
3156 "Return the column of the indentation of the current line.
3157 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3160 (skip-chars-forward " \t")
3161 ;; if we are at the end of blank line return 0
3163 ((current-column)))))
3165 (defun idlwave-is-continuation-line ()
3166 "Tests if current line is continuation line.
3167 Blank or comment-only lines following regular continuation lines (with
3168 `$') count as continuations too."
3171 (idlwave-look-at "\\<\\$")
3173 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3174 (eq (forward-line -
1) 0))
3175 (if (idlwave-look-at "\\<\\$") (throw 'loop t
)))))))
3177 (defun idlwave-is-comment-line ()
3178 "Tests if the current line is a comment line."
3180 (beginning-of-line 1)
3181 (looking-at "[ \t]*;")))
3183 (defun idlwave-is-comment-or-empty-line ()
3184 "Tests if the current line is a comment line."
3186 (beginning-of-line 1)
3187 (looking-at "[ \t]*[;\n]")))
3189 (defun idlwave-look-at (regexp &optional cont beg
)
3190 "Searches current line from current point for REGEXP.
3191 If optional argument CONT is non-nil, searches to the end of
3192 the current statement.
3193 If optional arg BEG is non-nil, search starts from the beginning of the
3195 Ignores matches that end in a comment or inside a string expression.
3196 Returns point if successful, nil otherwise.
3197 This function produces unexpected results if REGEXP contains quotes or
3198 a comment delimiter. The search is case insensitive.
3199 If successful leaves point after the match, otherwise, does not move point."
3200 (let ((here (point))
3201 (case-fold-search t
)
3202 (eos (save-excursion
3203 (if cont
(idlwave-end-of-statement) (end-of-line))
3206 (idlwave-with-special-syntax
3207 (if beg
(idlwave-beginning-of-statement))
3208 (while (and (setq found
(re-search-forward regexp eos t
))
3210 (if (not found
) (goto-char here
))
3213 (defun idlwave-fill-paragraph (&optional nohang
)
3214 "Fills paragraphs in comments.
3215 A paragraph is made up of all contiguous lines having the same comment
3216 leader (the leading whitespace before the comment delimiter and the
3217 comment delimiter). In addition, paragraphs are separated by blank
3218 line comments. The indentation is given by the hanging indent of the
3219 first line, otherwise by the minimum indentation of the lines after
3220 the first line. The indentation of the first line does not change.
3221 Does not effect code lines. Does not fill comments on the same line
3222 with code. The hanging indent is given by the end of the first match
3223 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3224 optional argument NOHANG is non-nil then the hanging indent is
3227 ;; check if this is a line comment
3230 (skip-chars-forward " \t")
3231 (looking-at comment-start
))
3234 pre here diff fill-prefix-reg bcl first-indent
3236 ;; Change tabs to spaces in the surrounding paragraph.
3237 ;; The surrounding paragraph will be the largest containing block of
3238 ;; contiguous line comments. Thus, we may be changing tabs in
3239 ;; a much larger area than is needed, but this is the easiest
3240 ;; brute force way to do it.
3242 ;; This has the undesirable side effect of replacing the tabs
3243 ;; permanently without the user's request or knowledge.
3245 (backward-paragraph)
3246 (setq start
(point)))
3250 (untabify start end
)
3256 (concat "^[ \t]*" comment-start
"+")
3257 (save-excursion (end-of-line) (point))
3259 ;; Get the comment leader on the line and its length
3260 (setq pre
(current-column))
3261 ;; the comment leader is the indentation plus exactly the
3262 ;; number of consecutive ";".
3263 (setq fill-prefix-reg
3267 (buffer-substring (save-excursion
3268 (beginning-of-line) (point))
3272 ;; Mark the beginning and end of the paragraph
3274 (while (and (looking-at fill-prefix-reg
)
3275 (not (looking-at paragraph-separate
))
3278 ;; Move to first line of paragraph
3279 (if (/= (point) bcl
)
3281 (setq start
(point))
3283 (while (and (looking-at fill-prefix-reg
)
3284 (not (looking-at paragraph-separate
))
3288 (if (or (not (looking-at fill-prefix-reg
))
3289 (looking-at paragraph-separate
))
3292 ;; if at end of buffer add a newline (need this because
3293 ;; fill-region needs END to be at the beginning of line after
3294 ;; the paragraph or it will add a line).
3296 (progn (insert ?
\n) (backward-char 1)))
3297 ;; Set END to the beginning of line after the paragraph
3298 ;; END is calculated as distance from end of buffer
3299 (setq end
(- (point-max) (point) 1))
3301 ;; Calculate the indentation for the paragraph.
3303 ;; In the following while statements, after one iteration
3304 ;; point will be at the beginning of a line in which case
3305 ;; the while will not be executed for the
3306 ;; the first paragraph line and thus will not affect the
3309 ;; First check to see if indentation is based on hanging indent.
3310 (if (and (not nohang
) idlwave-hanging-indent
3314 (idlwave-calc-hanging-indent))))
3315 ;; Adjust lines of paragraph by inserting spaces so that
3316 ;; each line's indent is at least as great as the hanging
3317 ;; indent. This is needed for fill-paragraph to work with
3322 (while (> (point) start
)
3323 (re-search-forward comment-start-skip
3324 (save-excursion (end-of-line) (point))
3326 (if (> (setq diff
(- indent
(current-column))) 0)
3328 (if (>= here
(point))
3329 ;; adjust the original location for the
3331 (setq here
(+ here diff
)))
3332 (insert (make-string diff ?\
))))
3336 ;; No hang. Instead find minimum indentation of paragraph
3337 ;; after first line.
3338 ;; For the following while statement, since START is at the
3339 ;; beginning of line and END is at the end of line
3340 ;; point is greater than START at least once (which would
3341 ;; be the case for a single line paragraph).
3342 (while (> (point) start
)
3349 (save-excursion (end-of-line) (point))
3354 (setq fill-prefix
(concat fill-prefix
3355 (make-string (- indent pre
)
3357 ;; first-line indent
3363 (save-excursion (end-of-line) (point))
3368 ;; try to keep point at its original place
3371 ;; In place of the more modern fill-region-as-paragraph, a hack
3372 ;; to keep whitespace untouched on the first line within the
3373 ;; indent length and to preserve any indent on the first line
3377 (buffer-substring start
(+ start first-indent -
1)))
3378 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3379 (fill-region-as-paragraph
3382 (current-justification)
3384 (delete-region start
(+ start first-indent -
1))
3387 ;; When we want the point at the beginning of the comment
3388 ;; body fill-region will put it at the beginning of the line.
3389 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3390 (setq fill-prefix nil
))))
3392 (defun idlwave-calc-hanging-indent ()
3393 "Calculate the position of the hanging indent for the comment
3394 paragraph. The hanging indent position is given by the first match
3395 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3396 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3398 If not found returns nil."
3399 (if idlwave-use-last-hang-indent
3402 (if (re-search-backward
3403 idlwave-hang-indent-regexp
3404 (save-excursion (beginning-of-line) (point))
3406 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3409 (if (re-search-forward
3410 idlwave-hang-indent-regexp
3411 (save-excursion (end-of-line) (point))
3413 (current-column)))))
3415 (defun idlwave-auto-fill ()
3416 "Called to break lines in auto fill mode.
3417 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3418 non-nil. Places a continuation character at the end of the line if
3419 not in a comment. Splits strings with IDL concatenation operator `+'
3420 if `idlwave-auto-fill-split-string' is non-nil."
3421 (if (<= (current-column) fill-column
)
3422 nil
; do not to fill
3423 (if (or (not idlwave-fill-comment-line-only
)
3425 ;; Check for comment line
3427 (looking-at idlwave-comment-line-start-skip
)))
3429 (idlwave-indent-line)
3430 ;; Prevent actions do-auto-fill which calls indent-line-function.
3431 (let (idlwave-do-actions
3432 (paragraph-start ".")
3433 (paragraph-separate ".")
3434 (fill-nobreak-predicate
3435 (if (and (idlwave-in-quote)
3436 idlwave-auto-fill-split-string
)
3437 (lambda () ;; We'll need 5 spaces for " ' + $"
3438 (<= (- fill-column
(current-column)) 5)
3443 ;; Indent the split line
3444 (idlwave-indent-line)
3448 (looking-at idlwave-comment-line-start-skip
))
3449 ;; A continued line comment
3450 ;; We treat continued line comments as part of a comment
3451 ;; paragraph. So we check for a hanging indent.
3452 (if idlwave-hanging-indent
3453 (let ((here (- (point-max) (point)))
3457 (idlwave-calc-hanging-indent))))
3460 ;; Remove whitespace between comment delimiter and
3461 ;; text, insert spaces for appropriate indentation.
3465 (save-excursion (end-of-line) (point)) t
)
3466 (delete-horizontal-space)
3467 (idlwave-indent-to indent
)
3468 (goto-char (- (point-max) here
)))
3470 ;; Split code or comment?
3473 (idlwave-in-comment))
3474 ;; Splitting a non-full-line comment.
3475 ;; Insert the comment delimiter from split line
3479 (skip-chars-forward " \t")
3480 ;; Insert blank to keep off beginning of line
3484 (buffer-substring (idlwave-goto-comment)
3486 (skip-chars-forward "; ")
3488 (idlwave-indent-line))
3489 ;; Split code line - add continuation character
3492 ;; Check to see if we split a string
3493 (if (and (setq beg
(idlwave-in-quote))
3494 idlwave-auto-fill-split-string
)
3495 ;; Split the string and concatenate.
3496 ;; The first extra space is for the space
3497 ;; the line was split. That space was removed.
3498 (insert " " (char-after beg
) " +"))
3501 (if idlwave-auto-fill-split-string
3502 ;; Make the second part of continued string
3505 (skip-chars-forward " \t")
3506 (insert (char-after beg
)))
3509 (message "Warning: continuation inside a string.")))
3510 ;; Although do-auto-fill (via indent-new-comment-line) calls
3511 ;; idlwave-indent-line for the new line, re-indent again
3512 ;; because of the addition of the continuation character.
3513 (idlwave-indent-line))
3516 (defun idlwave-auto-fill-mode (arg)
3517 "Toggle auto-fill mode for IDL mode.
3518 With arg, turn auto-fill mode on if arg is positive.
3519 In auto-fill mode, inserting a space at a column beyond `fill-column'
3520 automatically breaks the line at a previous space."
3522 (prog1 (set idlwave-fill-function
3524 (not (symbol-value idlwave-fill-function
))
3525 (> (prefix-numeric-value arg
) 0))
3529 (set-buffer-modified-p (buffer-modified-p))))
3531 ;(defun idlwave-fill-routine-call ()
3532 ; "Fill a routine definition or statement, indenting appropriately."
3533 ; (let ((where (idlwave-where)))))
3536 (defun idlwave-doc-header (&optional nomark
)
3537 "Insert a documentation header at the beginning of the unit.
3538 Inserts the value of the variable idlwave-file-header. Sets mark before
3539 moving to do insertion unless the optional prefix argument NOMARK
3542 (or nomark
(push-mark))
3543 ;; make sure we catch the current line if it begins the unit
3544 (if idlwave-header-to-beginning-of-file
3545 (goto-char (point-min))
3547 (idlwave-beginning-of-subprogram)
3549 ;; skip function or procedure line
3550 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3552 (idlwave-end-of-statement)
3553 (if (> (forward-line 1) 0) (insert "\n")))))
3554 (let ((pos (point)))
3555 (if idlwave-file-header
3556 (cond ((car idlwave-file-header
)
3557 (insert-file-contents (car idlwave-file-header
)))
3558 ((stringp (car (cdr idlwave-file-header
)))
3559 (insert (car (cdr idlwave-file-header
))))))
3562 (defun idlwave-default-insert-timestamp ()
3563 "Default timestamp insertion function"
3564 (insert (current-time-string))
3565 (insert ", " (user-full-name))
3566 (if (boundp 'user-mail-address
)
3567 (insert " <" user-mail-address
">")
3568 (insert " <" (user-login-name) "@" (system-name) ">"))
3569 ;; Remove extra spaces from line
3570 (idlwave-fill-paragraph)
3571 ;; Insert a blank line comment to separate from the date entry -
3572 ;; will keep the entry from flowing onto date line if re-filled.
3573 (insert "\n;\n;\t\t"))
3575 (defun idlwave-doc-modification ()
3576 "Insert a brief modification log at the beginning of the current program.
3577 Looks for an occurrence of the value of user variable
3578 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3579 and places the point for the user to add a log. Before moving, saves
3580 location on mark ring so that the user can return to previous point."
3584 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3586 (goto-char (point-min))
3587 (re-search-forward idlwave-doclib-start nil t
)))
3588 (setq beg
(match-beginning 0))
3589 (re-search-forward idlwave-doclib-end nil t
)
3590 (setq end
(match-end 0)))
3593 (if (re-search-forward
3594 (concat idlwave-doc-modifications-keyword
":")
3599 (insert "\n" comment-start
"\n")
3600 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3602 (run-hooks 'idlwave-timestamp-hook
))
3603 (error "No valid DOCLIB header"))))
3606 ;;; Interface to expand-region-abbrevs which did not work when the
3607 ;;; abbrev hook associated with an abbrev moves point backwards
3608 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3609 ;;; The original would enter an infinite loop in attempting to expand
3610 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3611 ;;; because the point would keep going back to the beginning of the
3612 ;;; abbrev instead of to the end of the abbrev). We now keep the
3613 ;;; abbrev hook from moving backwards.
3615 (defun idlwave-expand-region-abbrevs (start end
)
3616 "Expand each abbrev occurrence in the region.
3617 Calling from a program, arguments are START END."
3620 (goto-char (min start end
))
3621 (let ((idlwave-show-block nil
) ;Do not blink
3622 (idlwave-abbrev-move nil
)) ;Do not move
3623 (expand-region-abbrevs start end
'noquery
))))
3625 (defun idlwave-quoted ()
3626 "Returns t if point is in a comment or quoted string.
3628 (or (idlwave-in-comment) (idlwave-in-quote)))
3630 (defun idlwave-in-quote ()
3631 "Returns location of the opening quote
3632 if point is in a IDL string constant, nil otherwise.
3633 Ignores comment delimiters on the current line.
3634 Properly handles nested quotation marks and octal
3635 constants - a double quote followed by an octal digit."
3636 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3637 ;;; double quote followed by an octal digit to be an octal constant
3638 ;;; rather than a string. Therefore, there is no terminating double
3641 ;; Because single and double quotes can quote each other we must
3642 ;; search for the string start from the beginning of line.
3643 (let* ((start (point))
3644 (eol (progn (end-of-line) (point)))
3645 (bq (progn (beginning-of-line) (point)))
3650 (while (< endq start
)
3651 ;; Find string start
3652 ;; Don't find an octal constant beginning with a double quote
3653 (if (re-search-forward "[\"']" eol
'lim
)
3654 ;; Find the string end.
3655 ;; In IDL, two consecutive delimiters after the start of a
3657 ;; escape for the delimiter in the string.
3658 ;; Two consecutive delimiters alone (i.e., not after the
3659 ;; start of a string) is the null string.
3661 ;; Move to position after quote
3662 (goto-char (1+ (match-beginning 0)))
3663 (setq bq
(1- (point)))
3664 ;; Get the string delimiter
3665 (setq delim
(char-to-string (preceding-char)))
3666 ;; Check for null string
3667 (if (looking-at delim
)
3668 (progn (setq endq
(point)) (forward-char 1))
3669 ;; Look for next unpaired delimiter
3670 (setq found
(search-forward delim eol
'lim
))
3671 (while (looking-at delim
)
3673 (setq found
(search-forward delim eol
'lim
)))
3675 (setq endq
(- (point) 1))
3676 (setq endq
(point)))
3678 (progn (setq bq
(point)) (setq endq
(point)))))
3679 (store-match-data data
)
3680 ;; return string beginning position or nil
3681 (if (> start bq
) bq
))))
3683 (defun idlwave-is-pointer-dereference (&optional limit
)
3684 "Determines if the character after point is a pointer dereference *."
3685 (let ((pos (point)))
3687 (eq (char-after) ?\
*)
3688 (not (idlwave-in-quote))
3691 (re-search-backward (concat "\\(" idlwave-idl-keywords
3692 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3695 ;; Statement templates
3697 ;; Replace these with a general template function, something like
3698 ;; expand.el (I think there was also something with a name similar to
3701 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3702 "Build a template with optional prompt expression.
3704 Opens a line if point is not followed by a newline modulo intervening
3705 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3706 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3707 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3708 PROMPT is a string then it is displayed as a message in the
3709 minibuffer. The PROMPT serves as a reminder to the user of an
3710 expression to enter.
3712 The lines containing S1 and S2 are reindented using `indent-region'
3713 unless the optional second argument NOINDENT is non-nil."
3714 (if (eq major-mode
'idlwave-shell-mode
)
3715 ;; This is a gross hack to avoit template abbrev expansion
3716 ;; in the shell. FIXME: This is a dirty hack.
3717 (if (and (eq this-command
'self-insert-command
)
3718 (equal last-abbrev-location
(point)))
3719 (insert last-abbrev-text
)
3720 (error "No templates in idlwave-shell"))
3721 (cond ((eq idlwave-abbrev-change-case
'down
)
3722 (setq s1
(downcase s1
) s2
(downcase s2
)))
3723 (idlwave-abbrev-change-case
3724 (setq s1
(upcase s1
) s2
(upcase s2
))))
3725 (let ((beg (save-excursion (beginning-of-line) (point)))
3727 (if (not (looking-at "\\s-*\n"))
3734 (indent-region beg end nil
))
3735 (if (stringp prompt
)
3736 (message prompt
)))))
3738 (defun idlwave-rw-case (string)
3739 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3740 (if idlwave-reserved-word-upcase
3744 (defun idlwave-elif ()
3745 "Build skeleton IDL if-else block."
3748 (idlwave-rw-case "if")
3749 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3750 "Condition expression"))
3752 (defun idlwave-case ()
3753 "Build skeleton IDL case statement."
3756 (idlwave-rw-case "case")
3757 (idlwave-rw-case " of\n\nendcase")
3758 "Selector expression"))
3760 (defun idlwave-switch ()
3761 "Build skeleton IDL switch statement."
3764 (idlwave-rw-case "switch")
3765 (idlwave-rw-case " of\n\nendswitch")
3766 "Selector expression"))
3768 (defun idlwave-for ()
3769 "Build skeleton for loop statment."
3772 (idlwave-rw-case "for")
3773 (idlwave-rw-case " do begin\n\nendfor")
3776 (defun idlwave-if ()
3777 "Build skeleton for loop statment."
3780 (idlwave-rw-case "if")
3781 (idlwave-rw-case " then begin\n\nendif")
3782 "Scalar logical expression"))
3784 (defun idlwave-procedure ()
3787 (idlwave-rw-case "pro")
3788 (idlwave-rw-case "\n\nreturn\nend")
3791 (defun idlwave-function ()
3794 (idlwave-rw-case "function")
3795 (idlwave-rw-case "\n\nreturn\nend")
3798 (defun idlwave-repeat ()
3801 (idlwave-rw-case "repeat begin\n\nendrep until")
3802 (idlwave-rw-case "")
3805 (defun idlwave-while ()
3808 (idlwave-rw-case "while")
3809 (idlwave-rw-case " do begin\n\nendwhile")
3812 (defun idlwave-split-string (string &optional pattern
)
3813 "Return a list of substrings of STRING which are separated by PATTERN.
3814 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3816 (setq pattern
"[ \f\t\n\r\v]+"))
3817 (let (parts (start 0))
3818 (while (string-match pattern string start
)
3819 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3820 start
(match-end 0)))
3821 (nreverse (cons (substring string start
) parts
))))
3823 (defun idlwave-replace-string (string replace_string replace_with
)
3825 (last (length string
))
3828 (while (setq end
(string-match replace_string string start
))
3830 (concat ret_string
(substring string start end
) replace_with
))
3831 (setq start
(match-end 0)))
3832 (setq ret_string
(concat ret_string
(substring string start last
)))))
3834 (defun idlwave-get-buffer-visiting (file)
3835 ;; Return the buffer currently visiting FILE
3837 ((boundp 'find-file-compare-truenames
) ; XEmacs
3838 (let ((find-file-compare-truenames t
))
3839 (get-file-buffer file
)))
3840 ((fboundp 'find-buffer-visiting
) ; Emacs
3841 (find-buffer-visiting file
))
3842 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3844 (defvar idlwave-outlawed-buffers nil
3845 "List of buffer pulled up by idlwave for special reasons.
3846 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3848 (defun idlwave-find-file-noselect (file &optional why
)
3849 ;; Return a buffer visiting file.
3850 (or (idlwave-get-buffer-visiting file
)
3851 (let ((buf (find-file-noselect file
)))
3852 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3855 (defun idlwave-kill-autoloaded-buffers ()
3856 "Kill buffers created automatically by IDLWAVE.
3857 Function prompts for a letter to identify the buffers to kill.
3858 Possible letters are:
3860 f Buffers created by the command \\[idlwave-find-module] or mouse
3861 clicks in the routine info window.
3862 s Buffers created by the IDLWAVE Shell to display where execution
3863 stopped or an error was found.
3864 a Both of the above.
3866 Buffer containing unsaved changes require confirmation before they are killed."
3868 (if (null idlwave-outlawed-buffers
)
3869 (error "No IDLWAVE-created buffers available")
3870 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3871 (idlwave-count-outlawed-buffers 'find
)
3872 (idlwave-count-outlawed-buffers 'shell
)))
3873 (let ((c (read-char)))
3875 ((member c
'(?f ?\C-f
))
3876 (idlwave-do-kill-autoloaded-buffers 'find
))
3877 ((member c
'(?s ?\C-s
))
3878 (idlwave-do-kill-autoloaded-buffers 'shell
))
3879 ((member c
'(?a ?\C-a
))
3880 (idlwave-do-kill-autoloaded-buffers t
))
3881 (t (error "Abort"))))))
3883 (defun idlwave-count-outlawed-buffers (tag)
3884 "How many outlawed buffers have tag TAG?"
3887 (lambda (x) (eq (cdr x
) tag
))
3888 idlwave-outlawed-buffers
))))
3890 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3891 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3892 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3895 (while (setq entry
(pop list
))
3896 (if (buffer-live-p (car entry
))
3897 (and (or (memq t reasons
)
3898 (memq (cdr entry
) reasons
))
3899 (kill-buffer (car entry
))
3901 (setq idlwave-outlawed-buffers
3902 (delq entry idlwave-outlawed-buffers
)))
3903 (setq idlwave-outlawed-buffers
3904 (delq entry idlwave-outlawed-buffers
))))
3905 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3907 (defun idlwave-revoke-license-to-kill ()
3908 "Remove BUFFER from the buffers which may be killed.
3909 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3910 Intended for `after-save-hook'."
3911 (let* ((buf (current-buffer))
3912 (entry (assq buf idlwave-outlawed-buffers
)))
3915 (setq idlwave-outlawed-buffers
3916 (delq entry idlwave-outlawed-buffers
)))
3917 ;; Remove this function from the hook.
3918 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3920 (defvar idlwave-path-alist
)
3921 (defun idlwave-locate-lib-file (file)
3922 ;; Find FILE on the scanned lib path and return a buffer visiting it
3923 (let* ((dirs idlwave-path-alist
)
3926 (while (setq dir
(car (pop dirs
)))
3928 (setq efile
(expand-file-name file dir
)))
3929 (throw 'exit efile
))))))
3931 (defun idlwave-expand-lib-file-name (file)
3932 ;; Find FILE on the scanned lib path and return a buffer visiting it
3933 ;; This is for, e.g., finding source with no user catalog
3936 ((file-name-absolute-p file
) file
)
3937 (t (idlwave-locate-lib-file file
))))
3939 (defun idlwave-make-tags ()
3940 "Creates the IDL tags file IDLTAGS in the current directory from
3941 the list of directories specified in the minibuffer. Directories may be
3942 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3943 specified top directories are searched if the directory name is prefixed
3944 by @. Specify @ directories with care, it may take a long, long time if
3947 (let (directory directories cmd append status numdirs dir getsubdirs
3948 buffer save_buffer files numfiles item errbuf
)
3951 ;; Read list of directories
3952 (setq directory
(read-string "Tag Directories: " "."))
3953 (setq directories
(idlwave-split-string directory
"[ \t]+"))
3955 ;; Set etags command, vars
3956 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
3957 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3958 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3962 ;; For each directory
3964 (setq dir
(nth numdirs directories
))
3967 ;; Find the subdirectories
3968 (if (string-match "^[@]\\(.+\\)$" dir
)
3969 (setq getsubdirs t
) (setq getsubdirs nil
))
3970 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
3971 (setq dir
(expand-file-name dir
))
3972 (if (file-directory-p dir
)
3974 (if (and getsubdirs
)
3976 (setq buffer
(get-buffer-create "*idltags*"))
3977 (call-process "sh" nil buffer nil
"-c"
3978 (concat "find " dir
" -type d -print"))
3979 (setq save_buffer
(current-buffer))
3981 (setq files
(idlwave-split-string
3982 (idlwave-replace-string
3983 (buffer-substring 1 (point-max))
3986 (set-buffer save_buffer
)
3987 (kill-buffer buffer
))
3988 (setq files
(list (concat dir
"/*.pro"))))
3990 ;; For each subdirectory
3992 (setq item
(nth numfiles files
))
3996 (if (not (string-match "^[ \\t]*$" item
))
3998 (message (concat "Tagging " item
"..."))
3999 (setq errbuf
(get-buffer-create "*idltags-error*"))
4000 (setq status
(+ status
4001 (if (eq 0 (call-process
4002 "sh" nil errbuf nil
"-c"
4003 (concat cmd append item
)))
4007 ;; Append additional tags
4008 (setq append
" --append ")
4009 (setq numfiles
(1+ numfiles
))
4010 (setq item
(nth numfiles files
)))
4012 (setq numfiles
(1+ numfiles
))
4013 (setq item
(nth numfiles files
))
4016 (setq numdirs
(1+ numdirs
))
4017 (setq dir
(nth numdirs directories
)))
4019 (setq numdirs
(1+ numdirs
))
4020 (setq dir
(nth numdirs directories
)))))
4022 (setq errbuf
(get-buffer-create "*idltags-error*"))
4024 (kill-buffer errbuf
))
4028 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4029 "Comment the lines in the region if the first non-blank line is
4030 commented, and conversely, uncomment region. If optional prefix arg
4031 N is non-nil, then for N positive, add N comment delimiters or for N
4032 negative, remove N comment delimiters.
4033 Uses `comment-region' which does not place comment delimiters on
4035 (interactive "r\nP")
4037 (comment-region beg end
(prefix-numeric-value n
))
4042 (skip-chars-forward " \t\n")
4043 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4044 (if (fboundp 'uncomment-region
)
4045 (uncomment-region beg end
)
4046 (comment-region beg end
4047 (- (length (buffer-substring
4050 (comment-region beg end
)))))
4053 ;; ----------------------------------------------------------------------------
4054 ;; ----------------------------------------------------------------------------
4055 ;; ----------------------------------------------------------------------------
4056 ;; ----------------------------------------------------------------------------
4058 ;; Completion and Routine Info
4061 ;; String "intern" functions
4063 ;; For the completion and routine info function, we want to normalize
4064 ;; the case of procedure names etc. We do this by "interning" these
4065 ;; string is a hand-crafted way. Hashes are used to map the downcase
4066 ;; version of the strings to the cased versions. Most *-sint-*
4067 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4068 ;; system hash. The former is re-scanned, and the latter takes case
4071 ;; Since these cased versions are really lisp objects, we can use `eq'
4072 ;; to search, which is a large performance boost. All new strings
4073 ;; need to be "sinterned". We do this as early as possible after
4074 ;; getting these strings from completion or buffer substrings. So
4075 ;; most of the code can simply assume to deal with "sinterned"
4076 ;; strings. The only exception is that the functions which scan whole
4077 ;; buffers for routine information do not intern the grabbed strings.
4078 ;; This is only done afterwards. Therefore in these functions it is
4079 ;; *not* safe to assume the strings can be compared with `eq' and be
4080 ;; fed into the routine assq functions.
4082 ;; Here we define the hashing functions.
4084 ;; The variables which hold the hashes.
4085 (defvar idlwave-sint-routines
'(nil))
4086 (defvar idlwave-sint-keywords
'(nil))
4087 (defvar idlwave-sint-methods
'(nil))
4088 (defvar idlwave-sint-classes
'(nil))
4089 (defvar idlwave-sint-dirs
'(nil))
4090 (defvar idlwave-sint-libnames
'(nil))
4092 (defun idlwave-reset-sintern (&optional what
)
4093 "Reset all sintern hashes."
4094 ;; Make sure the hash functions are accessible.
4095 (if (or (not (fboundp 'gethash
))
4096 (not (fboundp 'puthash
)))
4099 (or (fboundp 'puthash
)
4100 (defalias 'puthash
'cl-puthash
))))
4101 (let ((entries '((idlwave-sint-routines 1000 10)
4102 (idlwave-sint-keywords 1000 10)
4103 (idlwave-sint-methods 100 10)
4104 (idlwave-sint-classes 10 10))))
4106 ;; Make sure these are lists
4107 (loop for entry in entries
4108 for var
= (car entry
)
4109 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4111 (when (or (eq what t
) (eq what
'syslib
)
4112 (null (cdr idlwave-sint-routines
)))
4113 ;; Reset the system & library hash
4114 (loop for entry in entries
4115 for var
= (car entry
) for size
= (nth 1 entry
)
4116 do
(setcdr (symbol-value var
)
4117 (make-hash-table ':size size
':test
'equal
)))
4118 (setq idlwave-sint-dirs nil
4119 idlwave-sint-libnames nil
))
4121 (when (or (eq what t
) (eq what
'bufsh
)
4122 (null (car idlwave-sint-routines
)))
4123 ;; Reset the buffer & shell hash
4124 (loop for entry in entries
4125 for var
= (car entry
) for size
= (nth 1 entry
)
4126 do
(setcar (symbol-value var
)
4127 (make-hash-table ':size size
':test
'equal
))))))
4129 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4131 (idlwave-sintern-method name set
)
4132 (idlwave-sintern-routine name set
)))
4134 (defun idlwave-sintern (stype &rest args
)
4135 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4137 ;;(defmacro idlwave-sintern (type var)
4138 ;; `(cond ((not (stringp name)) name)
4139 ;; ((gethash (downcase name) (cdr ,var)))
4140 ;; ((gethash (downcase name) (car ,var)))
4141 ;; (set (idlwave-sintern-set name ,type ,var set))
4144 (defun idlwave-sintern-routine (name &optional set
)
4145 (cond ((not (stringp name
)) name
)
4146 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4147 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4148 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4150 (defun idlwave-sintern-keyword (name &optional set
)
4151 (cond ((not (stringp name
)) name
)
4152 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4153 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4154 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4156 (defun idlwave-sintern-method (name &optional set
)
4157 (cond ((not (stringp name
)) name
)
4158 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4159 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4160 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4162 (defun idlwave-sintern-class (name &optional set
)
4163 (cond ((not (stringp name
)) name
)
4164 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4165 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4166 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4169 (defun idlwave-sintern-dir (dir &optional set
)
4170 (car (or (member dir idlwave-sint-dirs
)
4171 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4172 (defun idlwave-sintern-libname (name &optional set
)
4173 (car (or (member name idlwave-sint-libnames
)
4174 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4176 (defun idlwave-sintern-set (name type tables set
)
4177 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4179 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4180 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4181 (puthash (downcase name
) iname table
)
4184 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4185 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4187 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4191 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4192 "Sintern all strings in the rinfo LIST. With optional parameter
4193 SET: also set new patterns. Probably this will always have to be t.
4194 If DEFAULT-DIR is passed, it is used as the base of the directory"
4195 (let (entry name type class kwds res source call new
)
4197 (setq entry
(car list
)
4202 source
(nth 3 entry
)
4204 kwds
(nthcdr 5 entry
))
4206 ;; The class and name
4209 (if (symbolp class
) (setq class
(symbol-name class
)))
4210 (setq class
(idlwave-sintern-class class set
))
4211 (setq name
(idlwave-sintern-method name set
)))
4212 (setq name
(idlwave-sintern-routine name set
)))
4215 (let ((source-type (car source
))
4216 (source-file (nth 1 source
))
4217 (source-dir (if default-dir
4218 (file-name-as-directory default-dir
)
4220 (source-lib (nth 3 source
)))
4221 (if (stringp source-dir
)
4222 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4223 (if (stringp source-lib
)
4224 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4225 (setq source
(list source-type source-file source-dir source-lib
)))
4228 (setq kwds
(mapcar (lambda (x)
4229 (idlwave-sintern-keyword-list x set
))
4232 ;; Build a canonicalized list
4233 (setq new
(nconc (list name type class source call
) kwds
)
4234 res
(cons new res
)))
4237 ;; Creating new sintern tables
4239 (defun idlwave-new-sintern-type (tag)
4240 "Define a variable and a function to sintern the new type TAG.
4241 This defines the function `idlwave-sintern-TAG' and the variable
4242 `idlwave-sint-TAGs'."
4243 (let* ((name (symbol-name tag
))
4244 (names (concat name
"s"))
4245 (var (intern (concat "idlwave-sint-" names
)))
4246 (func (intern (concat "idlwave-sintern-" name
))))
4247 (set var nil
) ; initial value of the association list
4248 (fset func
; set the function
4249 `(lambda (name &optional set
)
4250 (cond ((not (stringp name
)) name
)
4251 ((cdr (assoc (downcase name
) ,var
)))
4253 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4257 (defun idlwave-reset-sintern-type (tag)
4258 "Reset the sintern variable associated with TAG."
4259 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4261 ;;---------------------------------------------------------------------------
4264 ;; The variables which hold the information
4265 (defvar idlwave-system-routines nil
4266 "Holds the routine-info obtained by scanning buffers.")
4267 (defvar idlwave-buffer-routines nil
4268 "Holds the routine-info obtained by scanning buffers.")
4269 (defvar idlwave-compiled-routines nil
4270 "Holds the routine-info obtained by asking the shell.")
4271 (defvar idlwave-unresolved-routines nil
4272 "Holds the unresolved routine-info obtained by asking the shell.")
4273 (defvar idlwave-user-catalog-routines nil
4274 "Holds the procedure routine-info from the user scan.")
4275 (defvar idlwave-library-catalog-routines nil
4276 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4277 (defvar idlwave-library-catalog-libname nil
4278 "Name of library catalog loaded from .idlwave_catalog files.")
4279 (defvar idlwave-path-alist nil
4280 "Alist with !PATH directories and zero or more flags if the dir has
4281 been scanned in a user catalog ('user) or discovered in a library
4283 (defvar idlwave-true-path-alist nil
4284 "Like `idlwave-path-alist', but with true filenames.")
4285 (defvar idlwave-routines nil
4286 "Holds the combinded procedure/function/method routine-info.")
4287 (defvar idlwave-class-alist nil
4288 "Holds the class names known to IDLWAVE.")
4289 (defvar idlwave-class-history nil
4290 "The history of classes selected with the minibuffer.")
4291 (defvar idlwave-force-class-query nil
)
4292 (defvar idlwave-before-completion-wconf nil
4293 "The window configuration just before the completion buffer was displayed.")
4294 (defvar idlwave-last-system-routine-info-cons-cell nil
4295 "The last cons cell in the system routine info.")
4298 ;; The code to get routine info from different sources.
4300 (defvar idlwave-system-routines
)
4301 (defvar idlwave-catalog-process nil
4302 "The background process currently updating the catalog.")
4304 (defun idlwave-routines ()
4305 "Provide a list of IDL routines.
4306 This routine loads the builtin routines on the first call. Later it
4307 only returns the value of the variable."
4308 (if (and idlwave-catalog-process
4309 (processp idlwave-catalog-process
))
4312 ((equal (process-status idlwave-catalog-process
) 'exit
)
4313 (message "updating........")
4314 (setq idlwave-catalog-process nil
)
4315 (idlwave-update-routine-info '(4)))
4316 ((equal (process-status idlwave-catalog-process
) 'run
)
4317 ;; Keep it running...
4320 ;; Something is wrong, get rid of the process
4321 (message "Problem with catalog process") (beep)
4323 (kill-process idlwave-catalog-process
)
4325 (setq idlwave-catalog-process nil
)))))
4326 (or idlwave-routines
4328 (idlwave-update-routine-info)
4329 ;; return the current value
4332 (defvar idlwave-update-rinfo-hook nil
4333 "List of functions which should run after a global rinfo update.
4334 Does not run after automatic updates of buffer or the shell.")
4336 (defun idlwave-rescan-catalog-directories ()
4337 "Rescan the previously selected directories. For batch processing."
4338 (idlwave-update-routine-info '(16)))
4340 (defun idlwave-rescan-asynchronously ()
4341 "Dispatch another emacs instance to update the idlwave catalog.
4342 After the process finishes normally, the first access to routine info
4343 will re-read the catalog."
4345 (if (processp idlwave-catalog-process
)
4346 (if (eq (process-status idlwave-catalog-process
) 'run
)
4347 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4350 (kill-process idlwave-catalog-process
)
4352 (error "Process killed, no new process started"))
4355 (kill-process idlwave-catalog-process
)
4357 (if (or (not idlwave-user-catalog-file
)
4358 (not (stringp idlwave-user-catalog-file
))
4359 (not (file-regular-p idlwave-user-catalog-file
)))
4360 (error "No catalog has been produced yet"))
4361 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4362 (args (list "-batch"
4363 "-l" (expand-file-name "~/.emacs")
4365 "-f" "idlwave-rescan-catalog-directories"))
4366 (process (apply 'start-process
"idlcat"
4368 (setq idlwave-catalog-process process
)
4369 (set-process-sentinel
4372 (when (string-match "finished" why
)
4373 (setq idlwave-routines nil
4374 idlwave-system-routines nil
4375 idlwave-catalog-process nil
)
4376 (or (idlwave-start-load-rinfo-timer)
4377 (idlwave-update-routine-info '(4))))))
4378 (message "Background job started to update catalog file")))
4381 ;; Format for all routine info user catalog, library catalogs, etc.:
4383 ;; ("ROUTINE" type class
4384 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4385 ;; (buffer pro_file dir) | (compiled pro_file dir)
4386 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
4388 ;; DIR will be supplied dynamically while loading library catalogs,
4389 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4390 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4391 ;; be nil, as can LINK1, etc., if no HTML help is available.
4394 (defvar idlwave-load-rinfo-idle-timer
)
4395 (defvar idlwave-shell-path-query
)
4397 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4398 "Update the internal routine-info lists.
4399 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4400 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4401 about individual routines.
4403 The information can come from 4 sources:
4404 1. IDL programs in the current editing session
4405 2. Compiled modules in an IDL shell running as Emacs subprocess
4406 3. A list which covers the IDL system routines.
4407 4. A list which covers the prescanned library files.
4409 Scans all IDLWAVE-mode buffers of the current editing session (see
4410 `idlwave-scan-all-buffers-for-routine-info').
4411 When an IDL shell is running, this command also queries the IDL program
4412 for currently compiled routines.
4414 With prefix ARG, also reload the system and library lists.
4415 With two prefix ARG's, also rescans the chosen user catalog tree.
4416 With three prefix args, dispatch asynchronous process to do the update.
4418 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4419 lists, but instead wait for the shell query to complete and
4420 asynchronously finish updating routine info. This is set
4421 automatically when called interactively. When you need routine
4422 information updated immediately, leave NO-CONCATENATE nil."
4423 (interactive "P\np")
4424 ;; Stop any idle processing
4425 (if (or (and (fboundp 'itimerp
)
4426 (itimerp idlwave-load-rinfo-idle-timer
))
4427 (and (fboundp 'timerp
)
4428 (timerp idlwave-load-rinfo-idle-timer
)))
4429 (cancel-timer idlwave-load-rinfo-idle-timer
))
4432 ;; Start a background process which updates the catalog.
4433 (idlwave-rescan-asynchronously))
4435 ;; Update the user catalog now, and wait for them.
4436 (idlwave-create-user-catalog-file t
))
4438 (let* ((load (or arg
4439 idlwave-buffer-case-takes-precedence
4440 (null idlwave-routines
)))
4441 ;; The override-idle means, even if the idle timer has done some
4442 ;; preparing work, load and renormalize everything anyway.
4443 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4445 (setq idlwave-buffer-routines nil
4446 idlwave-compiled-routines nil
4447 idlwave-unresolved-routines nil
)
4448 ;; Reset the appropriate hashes
4449 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4450 ;; reset was already done in idle time, so skip this step now once
4451 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4452 (idlwave-reset-sintern (cond (load t
)
4453 ((null idlwave-system-routines
) t
)
4456 (if idlwave-buffer-case-takes-precedence
4457 ;; We can safely scan the buffer stuff first
4459 (idlwave-update-buffer-routine-info)
4460 (and load
(idlwave-load-system-rinfo override-idle
)))
4461 ;; We first do the system info, and then the buffers
4462 (and load
(idlwave-load-system-rinfo override-idle
))
4463 (idlwave-update-buffer-routine-info))
4465 ;; Let's see if there is a shell
4466 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4467 (idlwave-shell-is-running)))
4468 (ask-shell (and shell-is-running
4469 idlwave-query-shell-for-routine-info
)))
4471 ;; Load the library catalogs again, first re-scanning the path
4473 (if shell-is-running
4474 (idlwave-shell-send-command idlwave-shell-path-query
4476 (idlwave-shell-get-path-info)
4477 (idlwave-scan-library-catalogs))
4479 (idlwave-scan-library-catalogs)))
4481 (if (or (not ask-shell
)
4482 (not no-concatenate
))
4483 ;; 1. If we are not going to ask the shell, we need to do the
4484 ;; concatenation now.
4485 ;; 2. When this function is called non-interactively, it
4486 ;; means that someone needs routine info *now*. The
4487 ;; shell update causes the concatenation to be
4488 ;; *delayed*, so not in time for the current command.
4489 ;; Therefore, we do a concatenation now, even though
4490 ;; the shell might do it again.
4491 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4494 ;; Ask the shell about the routines it knows of.
4495 (message "Querying the shell")
4496 (idlwave-shell-update-routine-info nil t
)))))))
4499 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4500 (defvar idlwave-load-rinfo-idle-timer nil
)
4501 (defun idlwave-start-load-rinfo-timer ()
4502 (if (or (and (fboundp 'itimerp
)
4503 (itimerp idlwave-load-rinfo-idle-timer
))
4504 (and (fboundp 'timerp
)
4505 (timerp idlwave-load-rinfo-idle-timer
)))
4506 (cancel-timer idlwave-load-rinfo-idle-timer
))
4507 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4508 (setq idlwave-load-rinfo-idle-timer nil
)
4509 (if (and idlwave-init-rinfo-when-idle-after
4510 (numberp idlwave-init-rinfo-when-idle-after
)
4511 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4512 (not idlwave-routines
))
4515 (setq idlwave-load-rinfo-idle-timer
4516 (run-with-idle-timer
4517 idlwave-init-rinfo-when-idle-after
4518 nil
'idlwave-load-rinfo-next-step
)))
4521 (defvar idlwave-library-routines nil
"Obsolete variable.")
4523 (defun idlwave-load-rinfo-next-step ()
4524 (let ((inhibit-quit t
)
4525 (arr idlwave-load-rinfo-steps-done
))
4527 (when (not (aref arr
0))
4528 (message "Loading idlw-rinfo.el in idle time...")
4529 (load "idlw-rinfo" 'noerror
'nomessage
)
4530 (message "Loading idlw-rinfo.el in idle time...done")
4533 (when (not (aref arr
1))
4534 (message "Normalizing idlwave-system-routines in idle time...")
4535 (idlwave-reset-sintern t
)
4536 (put 'idlwave-reset-sintern
'done-by-idle t
)
4537 (setq idlwave-system-routines
4538 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4539 (message "Normalizing idlwave-system-routines in idle time...done")
4542 (when (not (aref arr
2))
4543 (when (and (stringp idlwave-user-catalog-file
)
4544 (file-regular-p idlwave-user-catalog-file
))
4545 (message "Loading user catalog in idle time...")
4547 (load-file idlwave-user-catalog-file
)
4548 (error (throw 'exit nil
)))
4549 ;; Check for the old style catalog and warn
4551 (boundp 'idlwave-library-routines
)
4552 idlwave-library-routines
)
4554 (setq idlwave-library-routines nil
)
4556 (message "Outdated user catalog: %s... recreate"
4557 idlwave-user-catalog-file
))
4558 (message "Loading user catalog in idle time...done"))
4561 (when (not (aref arr
3))
4562 (when idlwave-user-catalog-routines
4563 (message "Normalizing user catalog routines in idle time...")
4564 (setq idlwave-user-catalog-routines
4565 (idlwave-sintern-rinfo-list
4566 idlwave-user-catalog-routines
'sys
))
4568 "Normalizing user catalog routines in idle time...done"))
4571 (when (not (aref arr
4))
4572 (idlwave-scan-library-catalogs
4573 "Loading and normalizing library catalogs in idle time...")
4576 (when (not (aref arr
5))
4577 (message "Finishing initialization in idle time...")
4579 (message "Finishing initialization in idle time...done")
4581 ;; restart the timer
4583 (idlwave-load-rinfo-next-step)
4584 (setq idlwave-load-rinfo-idle-timer
4585 (run-with-idle-timer
4586 idlwave-init-rinfo-when-idle-after
4587 nil
'idlwave-load-rinfo-next-step
))))))
4589 (defun idlwave-load-system-rinfo (&optional force
)
4590 ;; Load and case-treat the system and catalog files.
4591 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
4592 (load "idlw-rinfo" 'noerror
'nomessage
))
4593 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
4594 (message "Normalizing idlwave-system-routines...")
4595 (setq idlwave-system-routines
4596 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4597 (message "Normalizing idlwave-system-routines...done"))
4598 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
4599 (setq idlwave-last-system-routine-info-cons-cell
4600 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
))
4601 (when (and (stringp idlwave-user-catalog-file
)
4602 (file-regular-p idlwave-user-catalog-file
))
4604 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
4605 (load-file idlwave-user-catalog-file
))
4607 (when (boundp 'idlwave-library-routines
)
4608 (setq idlwave-library-routines nil
)
4609 (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file
))
4610 (setq idlwave-true-path-alist nil
)
4611 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
4612 (message "Normalizing user catalog routines...")
4613 (setq idlwave-user-catalog-routines
4614 (idlwave-sintern-rinfo-list
4615 idlwave-user-catalog-routines
'sys
))
4616 (message "Normalizing user catalog routines...done")))
4617 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
4618 (idlwave-scan-library-catalogs
4619 "Loading and normalizing library catalogs..."))
4620 (run-hooks 'idlwave-after-load-rinfo-hook
))
4623 (defun idlwave-update-buffer-routine-info ()
4626 ((eq idlwave-scan-all-buffers-for-routine-info t
)
4627 ;; Scan all buffers, current buffer last
4628 (message "Scanning all buffers...")
4629 (setq res
(idlwave-get-routine-info-from-buffers
4630 (reverse (buffer-list)))))
4631 ((null idlwave-scan-all-buffers-for-routine-info
)
4632 ;; Don't scan any buffers
4635 ;; Just scan this buffer
4636 (if (eq major-mode
'idlwave-mode
)
4638 (message "Scanning current buffer...")
4639 (setq res
(idlwave-get-routine-info-from-buffers
4640 (list (current-buffer))))))))
4641 ;; Put the result into the correct variable
4642 (setq idlwave-buffer-routines
4643 (idlwave-sintern-rinfo-list res
'set
))))
4645 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
4646 "Put the different sources for routine information together."
4647 ;; The sequence here is important because earlier definitions shadow
4648 ;; later ones. We assume that if things in the buffers are newer
4649 ;; then in the shell of the system, they are meant to be different.
4650 (setcdr idlwave-last-system-routine-info-cons-cell
4651 (append idlwave-buffer-routines
4652 idlwave-compiled-routines
4653 idlwave-library-catalog-routines
4654 idlwave-user-catalog-routines
))
4655 (setq idlwave-class-alist nil
)
4657 ;; Give a message with information about the number of routines we have.
4660 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
4661 (length idlwave-buffer-routines
)
4662 (length idlwave-compiled-routines
)
4663 (length idlwave-library-catalog-routines
)
4664 (length idlwave-user-catalog-routines
)
4665 (length idlwave-system-routines
)))
4667 (run-hooks 'idlwave-update-rinfo-hook
)))
4669 (defun idlwave-class-alist ()
4670 "Return the class alist - make it if necessary."
4671 (or idlwave-class-alist
4673 (loop for x in idlwave-routines do
4674 (when (and (setq class
(nth 2 x
))
4675 (not (assq class idlwave-class-alist
)))
4676 (push (list class
) idlwave-class-alist
)))
4677 idlwave-class-alist
)))
4679 ;; Three functions for the hooks
4680 (defun idlwave-save-buffer-update ()
4681 (idlwave-update-current-buffer-info 'save-buffer
))
4682 (defun idlwave-kill-buffer-update ()
4683 (idlwave-update-current-buffer-info 'kill-buffer
))
4684 (defun idlwave-new-buffer-update ()
4685 (idlwave-update-current-buffer-info 'find-file
))
4687 (defun idlwave-update-current-buffer-info (why)
4688 "Update idlwave-routines for current buffer. Can run from after-save-hook."
4689 (when (and (eq major-mode
'idlwave-mode
)
4690 (or (eq t idlwave-auto-routine-info-updates
)
4691 (memq why idlwave-auto-routine-info-updates
))
4692 idlwave-scan-all-buffers-for-routine-info
4696 (idlwave-replace-buffer-routine-info
4698 (if (eq why
'kill-buffer
)
4701 (idlwave-sintern-rinfo-list
4702 (idlwave-get-routine-info-from-buffers
4703 (list (current-buffer))) 'set
))))
4704 (idlwave-concatenate-rinfo-lists 'quiet
)
4708 (defun idlwave-replace-buffer-routine-info (file new
)
4709 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4710 (let ((list idlwave-buffer-routines
)
4713 ;; The following test uses eq to make sure it works correctly
4714 ;; when two buffers visit the same file. Then the file names
4715 ;; will be equal, but not eq.
4716 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
4721 ;; End of that section reached. Jump.
4723 (setq list
(cdr list
)))
4724 (setq idlwave-buffer-routines
4725 (append new
(delq nil idlwave-buffer-routines
)))))
4727 ;;----- Scanning buffers -------------------
4729 (defun idlwave-get-routine-info-from-buffers (buffers)
4730 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4731 (let (buf routine-lists res
)
4733 (while (setq buf
(pop buffers
))
4735 (if (and (eq major-mode
'idlwave-mode
)
4737 ;; yes, this buffer has the right mode.
4738 (progn (setq res
(condition-case nil
4739 (idlwave-get-buffer-routine-info)
4741 (push res routine-lists
)))))
4742 ;; Concatenate the individual lists and return the result
4743 (apply 'nconc routine-lists
)))
4745 (defun idlwave-get-buffer-routine-info ()
4746 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4747 (let* ((case-fold-search t
)
4748 routine-list string entry
)
4752 (goto-char (point-min))
4753 (while (re-search-forward
4754 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
4755 (setq string
(buffer-substring-no-properties
4758 (idlwave-end-of-statement)
4760 (setq entry
(idlwave-parse-definition string
))
4761 (push entry routine-list
))))
4764 (defvar idlwave-scanning-lib-dir
)
4765 (defun idlwave-parse-definition (string)
4766 "Parse a module definition."
4767 (let ((case-fold-search t
)
4768 start name args type keywords class
)
4770 (while (string-match ";.*" string
)
4771 (setq string
(replace-match "" t t string
)))
4772 ;; Remove the continuation line stuff
4773 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
4774 (setq string
(replace-match "\\1 " t nil string
)))
4775 (while (string-match "\n" string
)
4776 (setq string
(replace-match " " t nil string
)))
4777 ;; Match the name and type.
4779 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
4780 (setq start
(match-end 0))
4781 (setq type
(downcase (match-string 1 string
)))
4782 (if (match-beginning 3)
4783 (setq class
(match-string 3 string
)))
4784 (setq name
(match-string 4 string
)))
4785 ;; Match normal args and keyword args
4786 (while (string-match
4787 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4789 (setq start
(match-end 0))
4790 (if (match-beginning 3)
4791 (push (match-string 1 string
) keywords
)
4792 (push (match-string 1 string
) args
)))
4793 ;; Normalize and sort.
4794 (setq args
(nreverse args
))
4795 (setq keywords
(sort keywords
(lambda (a b
)
4796 (string< (downcase a
) (downcase b
)))))
4797 ;; Make and return the entry
4798 ;; We don't know which argument are optional, so this information
4799 ;; will not be contained in the calling sequence.
4801 (if (equal type
"pro") 'pro
'fun
)
4803 (cond ((not (boundp 'idlwave-scanning-lib
))
4804 (list 'buffer
(buffer-file-name)))
4805 ; ((string= (downcase
4806 ; (file-name-sans-extension
4807 ; (file-name-nondirectory (buffer-file-name))))
4810 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4811 (t (list 'user
(file-name-nondirectory (buffer-file-name))
4812 idlwave-scanning-lib-dir
"UserLib")))
4814 (if (string= type
"function") "Result = " "")
4815 (if class
"Obj ->[%s::]" "")
4819 (if (string= type
"function") "(" ", ")
4820 (mapconcat 'identity args
", ")
4821 (if (string= type
"function") ")" ""))))
4823 (cons nil
(mapcar 'list keywords
)) ;No help file
4827 ;;----- Scanning the user catalog -------------------
4829 (defun idlwave-sys-dir ()
4830 "Return the syslib directory, or a dummy that never matches."
4832 ((and idlwave-system-directory
4833 (not (string= idlwave-system-directory
"")))
4834 idlwave-system-directory
)
4835 ((getenv "IDL_DIR"))
4840 (defun idlwave-create-user-catalog-file (&optional arg
)
4841 "Scan all files on selected dirs of IDL search path for routine information.
4843 A widget checklist will allow you to choose the directories. Write
4844 the result as a file `idlwave-user-catalog-file'. When this file
4845 exists, will be automatically loaded to give routine information about
4846 library routines. With ARG, just rescan the same directories as last
4847 time - so no widget will pop up."
4849 ;; Make sure the file is loaded if it exists.
4850 (if (and (stringp idlwave-user-catalog-file
)
4851 (file-regular-p idlwave-user-catalog-file
))
4853 (load-file idlwave-user-catalog-file
)
4855 ;; Make sure the file name makes sense
4856 (unless (and (stringp idlwave-user-catalog-file
)
4857 (> (length idlwave-user-catalog-file
) 0)
4858 (file-accessible-directory-p
4859 (file-name-directory idlwave-user-catalog-file
))
4860 (not (string= "" (file-name-nondirectory
4861 idlwave-user-catalog-file
))))
4862 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
4865 ;; Rescan the known directories
4866 ((and arg idlwave-path-alist
4867 (consp (car idlwave-path-alist
)))
4868 (idlwave-scan-user-lib-files idlwave-path-alist
))
4870 ;; Expand the directories from library-path and run the widget
4871 (idlwave-library-path
4872 (idlwave-display-user-catalog-widget
4873 (if idlwave-true-path-alist
4874 ;; Propagate any flags on the existing path-alist
4876 (let ((path-entry (assoc (file-truename x
)
4877 idlwave-true-path-alist
)))
4879 (cons x
(cdr path-entry
))
4881 (idlwave-expand-path idlwave-library-path
))
4882 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
4884 ;; Ask the shell for the path and then run the widget
4886 (message "Asking the shell for IDL path...")
4887 (require 'idlw-shell
)
4888 (idlwave-shell-send-command idlwave-shell-path-query
4889 '(idlwave-user-catalog-command-hook nil
)
4893 ;; Parse shell path information and select among it.
4894 (defun idlwave-user-catalog-command-hook (&optional arg
)
4895 ;; Command hook used by `idlwave-create-user-catalog-file'.
4898 (idlwave-scan-user-lib-files idlwave-path-alist
)
4899 ;; Set the path and display the widget
4900 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
4901 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
4902 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
4904 (defconst idlwave-user-catalog-widget-help-string
4905 "This is the front-end to the creation of the IDLWAVE user catalog.
4906 Please select the directories on IDL's search path from which you
4907 would like to extract routine information, to be stored in the file:
4911 If this is not the correct file, first set variable
4912 `idlwave-user-catalog-file', and call this command again.
4914 N.B. Many libraries include pre-scanned catalog files
4915 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
4916 not be scanned. You can scan your own libraries off-line using the
4917 perl script `idlwave_catalog'.
4919 After selecting the directories, choose [Scan & Save] to scan the library
4920 directories and save the routine info.
4923 (defvar idlwave-widget
)
4924 (defvar widget-keymap
)
4925 (defun idlwave-display-user-catalog-widget (dirs-list)
4926 "Create the widget to select IDL search path directories for scanning."
4931 (error "Don't know IDL's search path"))
4933 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4934 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4935 (kill-all-local-variables)
4936 (make-local-variable 'idlwave-widget
)
4937 (widget-insert (format idlwave-user-catalog-widget-help-string
4938 idlwave-user-catalog-file
))
4940 (widget-create 'push-button
4941 :notify
'idlwave-widget-scan-user-lib-files
4944 (widget-create 'push-button
4945 :notify
'idlwave-delete-user-catalog-file
4948 (widget-create 'push-button
4950 '(lambda (&rest ignore
)
4951 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4953 (unless (memq 'lib
(cdr x
))
4954 (idlwave-path-alist-add-flag x
'user
)))
4956 (idlwave-display-user-catalog-widget path-list
)))
4957 "Select All Non-Lib")
4959 (widget-create 'push-button
4961 '(lambda (&rest ignore
)
4962 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
4964 (idlwave-path-alist-remove-flag x
'user
))
4966 (idlwave-display-user-catalog-widget path-list
)))
4969 (widget-create 'push-button
4970 :notify
(lambda (&rest ignore
)
4971 (kill-buffer (current-buffer)))
4973 (widget-insert "\n\n")
4975 (widget-insert "Select Directories: \n")
4977 (setq idlwave-widget
4978 (apply 'widget-create
4980 :value
(delq nil
(mapcar (lambda (x)
4981 (if (memq 'user
(cdr x
))
4985 :tag
"List of directories"
4988 (if (memq 'lib
(cdr x
))
4989 (concat "[LIB] " (car x
) )
4990 (car x
)))) dirs-list
)))
4991 (widget-put idlwave-widget
:path-dirs dirs-list
)
4992 (widget-insert "\n")
4993 (use-local-map widget-keymap
)
4995 (goto-char (point-min))
4996 (delete-other-windows))
4998 (defun idlwave-delete-user-catalog-file (&rest ignore
)
5000 (format "Delete file %s " idlwave-user-catalog-file
))
5002 (delete-file idlwave-user-catalog-file
)
5003 (message "%s has been deleted" idlwave-user-catalog-file
))))
5005 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
5006 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5007 (let* ((widget idlwave-widget
)
5008 (selected-dirs (widget-value widget
))
5009 (path-alist (widget-get widget
:path-dirs
))
5010 (this-path-alist path-alist
)
5012 (while (setq dir-entry
(pop this-path-alist
))
5014 (if (memq 'lib
(cdr dir-entry
))
5015 (concat "[LIB] " (car dir-entry
))
5018 (idlwave-path-alist-add-flag dir-entry
'user
)
5019 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5020 (idlwave-scan-user-lib-files path-alist
)))
5022 (defvar font-lock-mode
)
5023 (defun idlwave-scan-user-lib-files (path-alist)
5024 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5025 (let* ((idlwave-scanning-lib t
)
5026 (idlwave-scanning-lib-dir "")
5027 (idlwave-completion-case nil
)
5028 dirs-alist dir files file
)
5029 (setq idlwave-user-catalog-routines nil
5030 idlwave-path-alist path-alist
; for library-path instead
5031 idlwave-true-path-alist nil
)
5032 (if idlwave-auto-write-paths
(idlwave-write-paths))
5034 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5036 (setq dirs-alist
(reverse path-alist
))
5037 (while (setq dir
(pop dirs-alist
))
5038 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5039 (setq dir
(car dir
))
5040 (setq idlwave-scanning-lib-dir dir
)
5041 (when (file-directory-p dir
)
5042 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5043 (while (setq file
(pop files
))
5044 (when (file-regular-p file
)
5045 (if (not (file-readable-p file
))
5046 (message "Skipping %s (no read permission)" file
)
5047 (message "Scanning %s..." file
)
5049 (insert-file-contents file
'visit
)
5050 (setq idlwave-user-catalog-routines
5051 (append (idlwave-get-routine-info-from-buffers
5052 (list (current-buffer)))
5053 idlwave-user-catalog-routines
)))))))))
5054 (message "Creating user catalog file...")
5055 (kill-buffer "*idlwave-scan.pro*")
5056 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5057 (let ((font-lock-maximum-size 0)
5058 (auto-mode-alist nil
))
5059 (find-file idlwave-user-catalog-file
))
5060 (if (and (boundp 'font-lock-mode
)
5064 (insert ";; IDLWAVE user catalog file\n")
5065 (insert (format ";; Created %s\n\n" (current-time-string)))
5067 ;; Define the routine info list
5068 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5069 (let ((standard-output (current-buffer)))
5073 (goto-char (point-max)))
5074 idlwave-user-catalog-routines
))
5075 (insert (format "))\n\n;;; %s ends here\n"
5076 (file-name-nondirectory idlwave-user-catalog-file
)))
5077 (goto-char (point-min))
5080 (kill-buffer (current-buffer)))
5081 (message "Creating user catalog file...done")
5082 (message "Info for %d routines saved in %s"
5083 (length idlwave-user-catalog-routines
)
5084 idlwave-user-catalog-file
)
5086 (idlwave-update-routine-info t
))
5088 (defun idlwave-read-paths ()
5089 (if (and (stringp idlwave-path-file
)
5090 (file-regular-p idlwave-path-file
))
5092 (load idlwave-path-file t t t
)
5095 (defun idlwave-write-paths ()
5097 (when (and idlwave-path-alist idlwave-system-directory
)
5098 (let ((font-lock-maximum-size 0)
5099 (auto-mode-alist nil
))
5100 (find-file idlwave-path-file
))
5101 (if (and (boundp 'font-lock-mode
)
5105 (insert ";; IDLWAVE paths\n")
5106 (insert (format ";; Created %s\n\n" (current-time-string)))
5107 ;; Define the variable which knows the value of "!DIR"
5108 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5109 idlwave-system-directory
))
5111 ;; Define the variable which contains a list of all scanned directories
5112 (insert "\n(setq idlwave-path-alist\n '(")
5113 (let ((standard-output (current-buffer)))
5117 (goto-char (point-max)))
5118 idlwave-path-alist
))
5121 (kill-buffer (current-buffer))))
5124 (defun idlwave-expand-path (path &optional default-dir
)
5125 ;; Expand parts of path starting with '+' recursively into directory list.
5126 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5127 (message "Expanding path...")
5128 (let (path1 dir recursive
)
5129 (while (setq dir
(pop path
))
5130 (if (setq recursive
(string= (substring dir
0 1) "+"))
5131 (setq dir
(substring dir
1)))
5133 (not (file-name-absolute-p dir
)))
5134 (setq dir
(expand-file-name dir default-dir
)))
5136 ;; Expand recursively
5137 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5140 (message "Expanding path...done")
5143 (defun idlwave-recursive-directory-list (dir)
5144 ;; Return a list of all directories below DIR, including DIR itself
5145 (let ((path (list dir
)) path1 file files
)
5146 (while (setq dir
(pop path
))
5147 (when (file-directory-p dir
)
5148 (setq files
(nreverse (directory-files dir t
"[^.]")))
5149 (while (setq file
(pop files
))
5150 (if (file-directory-p file
)
5151 (push (file-name-as-directory file
) path
)))
5156 ;;----- Scanning the library catalogs ------------------
5161 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5162 "Scan for library catalog files (.idlwave_catalog) and ingest.
5164 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5165 instead, if present) are searched. Print MESSAGE-BASE along with the
5166 libraries being loaded, if passed, and skip loading/normalizing if
5167 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5168 be set to nil to disable library catalog scanning."
5169 (when idlwave-use-library-catalogs
5171 (if idlwave-library-path
5172 (idlwave-expand-path idlwave-library-path
)
5173 (mapcar 'car idlwave-path-alist
)))
5175 dir-entry dir flags catalog all-routines
)
5176 (if message-base
(message message-base
))
5177 (while (setq dir
(pop dirs
))
5179 (when (file-readable-p
5180 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5182 (setq idlwave-library-catalog-routines nil
)
5183 ;; Load the catalog file
5185 (load catalog t t t
)
5186 (error (throw 'continue t
)))
5189 (not (string= idlwave-library-catalog-libname
5191 (message (concat message-base
5192 idlwave-library-catalog-libname
))
5193 (setq old-libname idlwave-library-catalog-libname
))
5194 (when idlwave-library-catalog-routines
5197 (idlwave-sintern-rinfo-list
5198 idlwave-library-catalog-routines
'sys dir
)
5201 ;; Add a 'lib flag if on path-alist
5202 (when (and idlwave-path-alist
5203 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5204 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5205 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5206 (if message-base
(message (concat message-base
"done"))))))
5208 ;;----- Communicating with the Shell -------------------
5210 ;; First, here is the idl program which can be used to query IDL for
5211 ;; defined routines.
5212 (defconst idlwave-routine-info.pro
5214 ;; START OF IDLWAVE SUPPORT ROUTINES
5215 pro idlwave_print_info_entry,name,func=func,separator=sep
5216 ;; See if it's an object method
5217 if name eq '' then return
5218 func = keyword_set(func)
5219 methsep = strpos(name,'::')
5220 meth = methsep ne -1
5223 pars = routine_info(name,/parameters,functions=func)
5224 source = routine_info(name,/source,functions=func)
5225 nargs = pars.num_args
5226 nkw = pars.num_kw_args
5227 if nargs gt 0 then args = pars.args
5228 if nkw gt 0 then kwargs = pars.kw_args
5230 ;; Trim the class, and make the name
5232 class = strmid(name,0,methsep)
5233 name = strmid(name,methsep+2,strlen(name)-1)
5234 if nargs gt 0 then begin
5235 ;; remove the self argument
5236 wh = where(args ne 'SELF',nargs)
5237 if nargs gt 0 then args = args[wh]
5240 ;; No class, just a normal routine.
5246 if func then cs = 'Result = '
5247 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5249 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5250 if nargs gt 0 then begin
5251 for j=0,nargs-1 do begin
5253 if j lt nargs-1 then cs = cs + ', '
5256 if func then cs = cs + ')'
5257 ;; Keyword arguments
5259 if nkw gt 0 then begin
5260 for j=0,nkw-1 do begin
5261 kwstring = kwstring + ' ' + kwargs[j]
5265 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5267 print,ret + ': ' + name + sep + class + sep + source[0].path $
5268 + sep + cs + sep + kwstring
5271 pro idlwave_routine_info
5274 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5275 all = routine_info()
5276 for i=0,n_elements(all)-1 do $
5277 idlwave_print_info_entry,all[i],separator=sep
5278 all = routine_info(/functions)
5279 for i=0,n_elements(all)-1 do $
5280 idlwave_print_info_entry,all[i],/func,separator=sep
5281 print,'>>>END OF IDLWAVE ROUTINE INFO'
5284 pro idlwave_get_sysvars
5287 if error_status ne 0 then begin
5288 print, 'Cannot get info about system variables'
5290 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5291 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5292 v = strsplit(s,' +',/regex,/extract) ; get variables
5293 for i=0,n_elements(v)-1 do begin
5294 t = [''] ; get tag list
5295 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5296 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5301 pro idlwave_get_class_tags, class
5302 res = execute('tags=tag_names({'+class+'})')
5303 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5305 ;; END OF IDLWAVE SUPPORT ROUTINES
5307 "The idl programs to get info from the shell.")
5309 (defvar idlwave-idlwave_routine_info-compiled nil
5310 "Remembers if the routine info procedure is already compiled.")
5312 (defvar idlwave-shell-temp-pro-file
)
5313 (defvar idlwave-shell-temp-rinfo-save-file
)
5314 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait
)
5315 "Query the shell for routine_info of compiled modules and update the lists."
5316 ;; Save and compile the procedure. The compiled procedure is then
5317 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5318 ;; We need to RESTORE the procedure each time we use it, since
5319 ;; the user may have killed or redefined it. In particular,
5320 ;; .RESET_SESSION will kill all user procedures.
5321 (unless (and idlwave-idlwave_routine_info-compiled
5322 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5324 (set-buffer (idlwave-find-file-noselect
5325 (idlwave-shell-temp-file 'pro
)))
5327 (insert idlwave-routine-info.pro
)
5329 (idlwave-shell-send-command
5330 (concat ".run " idlwave-shell-temp-pro-file
)
5332 ; (message "SENDING SAVE") ; ????????????????????????
5333 (idlwave-shell-send-command
5334 (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5335 (idlwave-shell-temp-file 'rinfo
))
5338 ;; Restore and execute the procedure, analyze the output
5339 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5340 (idlwave-shell-send-command
5341 (format "RESTORE, '%s' & idlwave_routine_info"
5342 idlwave-shell-temp-rinfo-save-file
)
5344 (idlwave-shell-routine-info-filter)
5345 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5348 ;; ---------------------------------------------------------------------------
5350 ;; Completion and displaying routine calling sequences
5352 (defvar idlwave-completion-help-info nil
)
5353 (defvar idlwave-completion-help-links nil
)
5354 (defvar idlwave-current-obj_new-class nil
)
5355 (defvar idlwave-complete-special nil
)
5357 (defun idlwave-complete (&optional arg module class
)
5358 "Complete a function, procedure or keyword name at point.
5359 This function is smart and figures out what can be completed
5361 - At the beginning of a statement it completes procedure names.
5362 - In the middle of a statement it completes function names.
5363 - after a `(' or `,' in the argument list of a function or procedure,
5364 it completes a keyword of the relevant function or procedure.
5365 - In the first arg of `OBJ_NEW', it completes a class name.
5367 When several completions are possible, a list will be displayed in the
5368 *Completions* buffer. If this list is too long to fit into the
5369 window, scrolling can be achieved by repeatedly pressing
5370 \\[idlwave-complete].
5372 The function also knows about object methods. When it needs a class
5373 name, the action depends upon `idlwave-query-class', which see. You
5374 can force IDLWAVE to ask you for a class name with a
5375 \\[universal-argument] prefix argument to this command.
5377 See also the variables `idlwave-keyword-completion-adds-equal' and
5378 `idlwave-function-completion-adds-paren'.
5380 The optional ARG can be used to specify the completion type in order
5381 to override IDLWAVE's idea of what should be completed at point.
5382 Possible values are:
5384 0 <=> query for the completion type
5386 2 <=> 'procedure-keyword
5388 4 <=> 'function-keyword
5389 5 <=> 'procedure-method
5390 6 <=> 'procedure-method-keyword
5391 7 <=> 'function-method
5392 8 <=> 'function-method-keyword
5395 As a special case, the universal argument C-u forces completion of
5396 function names in places where the default would be a keyword.
5398 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5401 For Lisp programmers only:
5402 When we force a keyword, optional argument MODULE can contain the module name.
5403 When we force a method or a method keyword, CLASS can specify the class."
5408 (or (and (integerp arg
) (not (equal arg
'(16))))
5410 (idlwave-make-force-complete-where-list arg module class
)
5412 (what (nth 2 where-list
))
5413 (idlwave-force-class-query (equal arg
'(4)))
5414 (completion-regexp-list
5415 (if (equal arg
'(16))
5416 (list (read-string (concat "Completion Regexp: "))))))
5418 (if (and module
(string-match "::" module
))
5419 (setq class
(substring module
0 (match-beginning 0))
5420 module
(substring module
(match-end 0))))
5425 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5426 (get-buffer-window "*Completions*"))
5427 (setq this-command last-command
)
5428 (idlwave-scroll-completions))
5430 ;; Complete a filename in quotes
5431 ((and (idlwave-in-quote)
5432 (not (eq what
'class
)))
5433 (idlwave-complete-filename))
5435 ;; Check for any special completion functions
5436 ((and idlwave-complete-special
5437 (idlwave-call-special idlwave-complete-special
)))
5440 (error "Nothing to complete here"))
5444 (setq idlwave-completion-help-info
'(class))
5445 (idlwave-complete-class))
5447 ((eq what
'procedure
)
5448 ;; Complete a procedure name
5449 (let* ((cw-list (nth 3 where-list
))
5450 (class-selector (idlwave-determine-class cw-list
'pro
))
5451 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5452 (idlwave-all-class-inherits class-selector
)))
5453 (isa (concat "procedure" (if class-selector
"-method" "")))
5454 (type-selector 'pro
))
5455 (setq idlwave-completion-help-info
5456 (list 'routine nil type-selector class-selector nil super-classes
))
5457 (idlwave-complete-in-buffer
5458 'procedure
(if class-selector
'method
'routine
)
5459 (idlwave-routines) 'idlwave-selector
5460 (format "Select a %s name%s"
5463 (format " (class is %s)"
5464 (if (eq class-selector t
)
5465 "unknown" class-selector
))
5468 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5470 ((eq what
'function
)
5471 ;; Complete a function name
5472 (let* ((cw-list (nth 3 where-list
))
5473 (class-selector (idlwave-determine-class cw-list
'fun
))
5474 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5475 (idlwave-all-class-inherits class-selector
)))
5476 (isa (concat "function" (if class-selector
"-method" "")))
5477 (type-selector 'fun
))
5478 (setq idlwave-completion-help-info
5479 (list 'routine nil type-selector class-selector nil super-classes
))
5480 (idlwave-complete-in-buffer
5481 'function
(if class-selector
'method
'routine
)
5482 (idlwave-routines) 'idlwave-selector
5483 (format "Select a %s name%s"
5486 (format " (class is %s)"
5487 (if (eq class-selector t
)
5488 "unknown" class-selector
))
5491 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5493 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
5495 (idlwave-complete 3))
5497 ((eq what
'procedure-keyword
)
5498 ;; Complete a procedure keyword
5499 (let* ((where (nth 3 where-list
))
5501 (method-selector name
)
5502 (type-selector 'pro
)
5503 (class (idlwave-determine-class where
'pro
))
5504 (class-selector class
)
5505 (super-classes (idlwave-all-class-inherits class-selector
))
5506 (isa (format "procedure%s-keyword" (if class
"-method" "")))
5507 (entry (idlwave-best-rinfo-assq
5508 name
'pro class
(idlwave-routines)))
5509 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
5510 (list (idlwave-entry-keywords entry
'do-link
)))
5511 (unless (or entry
(eq class t
))
5512 (error "Nothing known about procedure %s"
5513 (idlwave-make-full-name class name
)))
5514 (setq list
(idlwave-fix-keywords name
'pro class list
5515 super-classes system
))
5516 (unless list
(error "No keywords available for procedure %s"
5517 (idlwave-make-full-name class name
)))
5518 (setq idlwave-completion-help-info
5519 (list 'keyword name type-selector class-selector entry super-classes
))
5520 (idlwave-complete-in-buffer
5521 'keyword
'keyword list nil
5522 (format "Select keyword for procedure %s%s"
5523 (idlwave-make-full-name class name
)
5524 (if (or (member '("_EXTRA") list
)
5525 (member '("_REF_EXTRA") list
))
5526 " (note _EXTRA)" ""))
5528 'idlwave-attach-keyword-classes
)))
5530 ((eq what
'function-keyword
)
5531 ;; Complete a function keyword
5532 (let* ((where (nth 3 where-list
))
5534 (method-selector name
)
5535 (type-selector 'fun
)
5536 (class (idlwave-determine-class where
'fun
))
5537 (class-selector class
)
5538 (super-classes (idlwave-all-class-inherits class-selector
))
5539 (isa (format "function%s-keyword" (if class
"-method" "")))
5540 (entry (idlwave-best-rinfo-assq
5541 name
'fun class
(idlwave-routines)))
5542 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
5543 (list (idlwave-entry-keywords entry
'do-link
))
5545 (unless (or entry
(eq class t
))
5546 (error "Nothing known about function %s"
5547 (idlwave-make-full-name class name
)))
5548 (setq list
(idlwave-fix-keywords name
'fun class list
5549 super-classes system
))
5550 ;; OBJ_NEW: Messages mention the proper Init method
5551 (setq msg-name
(if (and (null class
)
5552 (string= (upcase name
) "OBJ_NEW"))
5553 (concat idlwave-current-obj_new-class
5554 "::Init (via OBJ_NEW)")
5555 (idlwave-make-full-name class name
)))
5556 (unless list
(error "No keywords available for function %s"
5558 (setq idlwave-completion-help-info
5559 (list 'keyword name type-selector class-selector nil super-classes
))
5560 (idlwave-complete-in-buffer
5561 'keyword
'keyword list nil
5562 (format "Select keyword for function %s%s" msg-name
5563 (if (or (member '("_EXTRA") list
)
5564 (member '("_REF_EXTRA") list
))
5565 " (note _EXTRA)" ""))
5567 'idlwave-attach-keyword-classes
)))
5569 (t (error "This should not happen (idlwave-complete)")))))
5571 (defvar idlwave-complete-special nil
5572 "List of special completion functions.
5573 These functions are called for each completion. Each function must
5574 check if its own special completion context is present. If yes, it
5575 should use `idlwave-complete-in-buffer' to do some completion and
5576 return t. If such a function returns t, *no further* attempts to
5577 complete other contexts will be done. If the function returns nil,
5578 other completions will be tried.")
5580 (defun idlwave-call-special (functions &rest args
)
5581 (let ((funcs functions
)
5584 (while (setq fun
(pop funcs
))
5585 (if (setq ret
(apply fun args
))
5589 (defun idlwave-make-force-complete-where-list (what &optional module class
)
5590 ;; Return an artificial WHERE specification to force the completion
5591 ;; routine to complete a specific item independent of context.
5592 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5593 ;; MODULE and CLASS can be used to specify the routine name and class.
5594 ;; The class name will also be found in MODULE if that is like "class::mod".
5595 (let* ((what-list '(("procedure") ("procedure-keyword")
5596 ("function") ("function-keyword")
5597 ("procedure-method") ("procedure-method-keyword")
5598 ("function-method") ("function-method-keyword")
5600 (module (idlwave-sintern-routine-or-method module class
))
5601 (class (idlwave-sintern-class class
))
5605 (intern (completing-read
5606 "Complete what? " what-list nil t
))))
5608 (setq what
(intern (car (nth (1- what
) what-list
)))))
5611 (assoc (symbol-name what
) what-list
))
5613 (t (error "Invalid WHAT"))))
5614 (nil-list '(nil nil nil nil
))
5615 (class-list (list nil nil
(or class t
) nil
)))
5619 ((eq what
'procedure
)
5620 (list nil-list nil-list
'procedure nil-list nil
))
5622 ((eq what
'procedure-keyword
)
5623 (let* ((class-selector nil
)
5625 (type-selector 'pro
)
5627 (idlwave-completing-read
5628 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
5629 (setq pro
(idlwave-sintern-routine pro
))
5630 (list nil-list nil-list
'procedure-keyword
5631 (list pro nil nil nil
) nil
)))
5633 ((eq what
'function
)
5634 (list nil-list nil-list
'function nil-list nil
))
5636 ((eq what
'function-keyword
)
5637 (let* ((class-selector nil
)
5639 (type-selector 'fun
)
5641 (idlwave-completing-read
5642 "Function: " (idlwave-routines) 'idlwave-selector
))))
5643 (setq func
(idlwave-sintern-routine func
))
5644 (list nil-list nil-list
'function-keyword
5645 (list func nil nil nil
) nil
)))
5647 ((eq what
'procedure-method
)
5648 (list nil-list nil-list
'procedure class-list nil
))
5650 ((eq what
'procedure-method-keyword
)
5651 (let* ((class (idlwave-determine-class class-list
'pro
))
5652 (class-selector class
)
5653 (super-classes (idlwave-all-class-inherits class-selector
))
5654 (type-selector 'pro
)
5656 (idlwave-completing-read
5657 (format "Procedure in %s class: " class-selector
)
5658 (idlwave-routines) 'idlwave-selector
))))
5659 (setq pro
(idlwave-sintern-method pro
))
5660 (list nil-list nil-list
'procedure-keyword
5661 (list pro nil class nil
) nil
)))
5663 ((eq what
'function-method
)
5664 (list nil-list nil-list
'function class-list nil
))
5666 ((eq what
'function-method-keyword
)
5667 (let* ((class (idlwave-determine-class class-list
'fun
))
5668 (class-selector class
)
5669 (super-classes (idlwave-all-class-inherits class-selector
))
5670 (type-selector 'fun
)
5672 (idlwave-completing-read
5673 (format "Function in %s class: " class-selector
)
5674 (idlwave-routines) 'idlwave-selector
))))
5675 (setq func
(idlwave-sintern-method func
))
5676 (list nil-list nil-list
'function-keyword
5677 (list func nil class nil
) nil
)))
5680 (list nil-list nil-list
'class nil-list nil
))
5682 (t (error "Invalid value for WHAT")))))
5684 (defun idlwave-completing-read (&rest args
)
5685 ;; Completing read, case insensitive
5686 (let ((old-value (default-value 'completion-ignore-case
)))
5689 (setq-default completion-ignore-case t
)
5690 (apply 'completing-read args
))
5691 (setq-default completion-ignore-case old-value
))))
5693 (defvar idlwave-shell-default-directory
)
5694 (defun idlwave-complete-filename ()
5695 "Use the comint stuff to complete a file name."
5697 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5698 (comint-completion-addsuffix nil
)
5700 (if (and (boundp 'idlwave-shell-default-directory
)
5701 (stringp idlwave-shell-default-directory
)
5702 (file-directory-p idlwave-shell-default-directory
))
5703 idlwave-shell-default-directory
5704 default-directory
)))
5705 (comint-dynamic-complete-filename)))
5707 (defun idlwave-make-full-name (class name
)
5708 ;; Make a fully qualified module name including the class name
5709 (concat (if class
(format "%s::" class
) "") name
))
5711 (defun idlwave-rinfo-assoc (name type class list
)
5712 "Like `idlwave-rinfo-assq', but sintern strings first."
5714 (idlwave-sintern-routine-or-method name class
)
5715 type
(idlwave-sintern-class class
) list
))
5717 (defun idlwave-rinfo-assq (name type class list
)
5718 ;; Works like assq, but also checks type and class
5721 (while (setq match
(assq name list
))
5722 (and (or (eq type t
)
5723 (eq (nth 1 match
) type
))
5724 (eq (nth 2 match
) class
)
5725 (throw 'exit match
))
5726 (setq list
(cdr (memq match list
)))))))
5728 (defun idlwave-rinfo-assq-any-class (name type class list
)
5729 ;; Return the first matching method on the inheritance list
5730 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
5733 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
5734 (setq classes nil
)))
5737 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
5739 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
5740 If WITH-FILE is passed, find the best rinfo entry with a file
5741 included. If KEEP-SYSTEM is set, don't prune system for compiled
5743 (let ((twins (idlwave-routine-twins
5744 (idlwave-rinfo-assq-any-class name type class list
)
5747 (when (> (length twins
) 1)
5748 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
5749 (if (and (null keep-system
)
5750 (eq 'system
(car (nth 3 (car twins
))))
5751 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
5752 (not (equal 1 syslibp
)))
5753 ;; Its a compiled syslib, so we need to remove the system entry
5754 (setq twins
(cdr twins
)))
5756 (setq twins
(delq nil
5758 (if (nth 1 (nth 3 x
)) x
))
5762 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
5764 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5765 (idlwave-best-rinfo-assq
5766 (idlwave-sintern-routine-or-method name class
)
5767 type
(idlwave-sintern-class class
) list with-file keep-system
))
5769 (defun idlwave-any-syslib (entries)
5770 "Does the entry list ENTRIES contain a syslib entry?
5771 If yes, return the index (>=1)."
5776 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
5777 (if (and file
(idlwave-syslib-p file
))
5779 (setq entries
(cdr entries
))))
5782 (defun idlwave-all-assq (key list
)
5783 "Return a list of all associations of Key in LIST."
5785 (while (setq elt
(assq key list
))
5787 (setq list
(cdr (memq elt list
))))
5790 (defun idlwave-all-method-classes (method &optional type
)
5791 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5792 When TYPE is not specified, both procedures and functions will be considered."
5794 (mapcar 'car
(idlwave-class-alist))
5799 (eq type
(nth 1 x
)))
5800 (push (nth 2 x
) rtn
)))
5801 (idlwave-all-assq method
(idlwave-routines)))
5802 (idlwave-uniquify rtn
))))
5804 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
5805 "Return all classes which have a method METHOD with keyword KEYWORD.
5806 TYPE is 'fun or 'pro.
5807 When TYPE is not specified, both procedures and functions will be considered."
5808 (if (or (null method
)
5813 (and (nth 2 x
) ; non-nil class
5814 (or (not type
) ; correct or unspecified type
5815 (eq type
(nth 1 x
)))
5816 (assoc keyword
(idlwave-entry-keywords x
))
5817 (push (nth 2 x
) rtn
)))
5818 (idlwave-all-assq method
(idlwave-routines)))
5819 (idlwave-uniquify rtn
))))
5821 (defun idlwave-members-only (list club
)
5822 "Return list of all elements in LIST which are also in CLUB."
5825 (if (member (car list
) club
)
5826 (setq rtn
(cons (car list
) rtn
)))
5827 (setq list
(cdr list
)))
5830 (defun idlwave-nonmembers-only (list club
)
5831 "Return list of all elements in LIST which are not in CLUB."
5834 (if (member (car list
) club
)
5836 (setq rtn
(cons (car list
) rtn
)))
5837 (setq list
(cdr list
)))
5840 (defun idlwave-explicit-class-listed (info)
5841 "Return whether or not the class is listed explicitly, ala a->b::c.
5842 INFO is as returned by idlwave-what-function or -procedure."
5843 (let ((apos (nth 3 info
)))
5845 (save-excursion (goto-char apos
)
5846 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5848 (defvar idlwave-determine-class-special nil
5849 "List of special functions for determining class.
5850 Must accept two arguments: `apos' and `info'")
5852 (defun idlwave-determine-class (info type
)
5853 ;; Determine the class of a routine call.
5854 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5855 ;; The second element in this structure is the class. When nil, we
5856 ;; return nil. When t, try to get the class from text properties at
5857 ;; the arrow. When the object is "self", we use the class of the
5858 ;; current routine. otherwise prompt the user for a class name.
5859 ;; Also stores the selected class as a text property at the arrow.
5860 ;; TYPE is 'fun or 'pro.
5861 (let* ((class (nth 2 info
))
5863 (nassoc (assoc (if (stringp (car info
))
5866 idlwave-query-class
))
5867 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
5868 idlwave-query-class
))
5869 (query (cond (nassoc (cdr nassoc
))
5870 (dassoc (cdr dassoc
))
5872 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
5875 (save-excursion (goto-char apos
)
5877 (let ((case-fold-search t
))
5878 (looking-at "self\\>")))))
5879 (force-query idlwave-force-class-query
)
5880 store special-class class-alist
)
5884 ;; There is an object which would like to know its class
5885 (if (and arrow
(get-text-property apos
'idlwave-class
)
5886 idlwave-store-inquired-class
5888 (setq class
(get-text-property apos
'idlwave-class
)
5889 class
(idlwave-sintern-class class
)))
5890 (if (and (eq t class
) is-self
)
5891 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
5893 ;; Before prompting, try any special class determination routines
5894 (when (and (eq t class
)
5895 idlwave-determine-class-special
5898 (idlwave-call-special idlwave-determine-class-special apos
))
5900 (setq class
(idlwave-sintern-class special-class
)
5901 store idlwave-store-inquired-class
)))
5903 ;; Prompt for a class, if we need to
5904 (when (and (eq class t
)
5905 (or force-query query
))
5907 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
5909 (idlwave-sintern-class
5911 ((and (= (length class-alist
) 0) (not force-query
))
5912 (error "No classes available with method %s" (car info
)))
5913 ((and (= (length class-alist
) 1) (not force-query
))
5914 (car (car class-alist
)))
5916 (setq store idlwave-store-inquired-class
)
5917 (idlwave-completing-read
5918 (format "Class%s: " (if (stringp (car info
))
5919 (format " for %s method %s"
5922 class-alist nil nil nil
'idlwave-class-history
))))))
5924 ;; Store it, if requested
5925 (when (and class
(not (eq t class
)))
5926 ;; We have a real class here
5927 (when (and store arrow
)
5929 (add-text-properties
5931 `(idlwave-class ,class face
,idlwave-class-arrow-face
5934 (setf (nth 2 info
) class
))
5937 ;; Default as fallback
5940 (defvar type-selector
)
5941 (defvar class-selector
)
5942 (defvar method-selector
)
5943 (defvar super-classes
)
5944 (defun idlwave-selector (a)
5945 (and (eq (nth 1 a
) type-selector
)
5946 (or (and (nth 2 a
) (eq class-selector t
))
5947 (eq (nth 2 a
) class-selector
)
5948 (memq (nth 2 a
) super-classes
))))
5950 (defun idlwave-add-file-link-selector (a)
5951 ;; Record a file link, if any, for the tested names during selection.
5952 (let ((sel (idlwave-selector a
)) file
)
5953 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
5954 (push (cons (car a
) file
) idlwave-completion-help-links
))
5958 (defun idlwave-where ()
5959 "Find out where we are.
5960 The return value is a list with the following stuff:
5961 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5963 PRO-LIST (PRO POINT CLASS ARROW)
5964 FUNC-LIST (FUNC POINT CLASS ARROW)
5965 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5966 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5968 LAST-CHAR last relevant character before point (non-white non-comment,
5969 not part of current identifier or leading slash).
5971 In the lists, we have these meanings:
5974 POINT: Where is this
5975 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5976 ARROW: Location of the arrow"
5978 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5979 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
5980 (func-entry (idlwave-what-function bos
))
5981 (func (car func-entry
))
5982 (func-class (nth 1 func-entry
))
5983 (func-arrow (nth 2 func-entry
))
5984 (func-point (or (nth 3 func-entry
) 0))
5985 (func-level (or (nth 4 func-entry
) 0))
5986 (pro-entry (idlwave-what-procedure bos
))
5987 (pro (car pro-entry
))
5988 (pro-class (nth 1 pro-entry
))
5989 (pro-arrow (nth 2 pro-entry
))
5990 (pro-point (or (nth 3 pro-entry
) 0))
5991 (last-char (idlwave-last-valid-char))
5992 (case-fold-search t
)
5993 (match-string (buffer-substring bos
(point)))
5994 cw cw-mod cw-arrow cw-class cw-point
)
5995 (if (< func-point pro-point
) (setq func nil
))
5997 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6001 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6003 (buffer-substring pro-point
(point))
6005 (setq cw
'procedure cw-class pro-class cw-point pro-point
6006 cw-arrow pro-arrow
))
6007 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6010 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6013 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6017 (> func-point pro-point
)
6019 (memq last-char
'(?\
( ?
,)))
6020 (setq cw
'function-keyword cw-mod func cw-point func-point
6021 cw-class func-class cw-arrow func-arrow
))
6022 ((and pro
(eq last-char ?
,))
6023 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
6024 cw-class pro-class cw-arrow pro-arrow
))
6025 ; ((member last-char '(?\' ?\) ?\] ?!))
6026 ; ;; after these chars, a function makes no sense
6027 ; ;; FIXME: I am sure there can be more in this list
6028 ; ;; FIXME: Do we want to do this at all?
6030 ;; Everywhere else we try a function.
6034 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6035 (setq cw-arrow
(copy-marker (match-beginning 0))
6036 cw-class
(if (match-end 4)
6037 (idlwave-sintern-class (match-string 4))
6039 (list (list pro pro-point pro-class pro-arrow
)
6040 (list func func-point func-class func-arrow
)
6042 (list cw-mod cw-point cw-class cw-arrow
)
6045 (defun idlwave-this-word (&optional class
)
6046 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6047 (setq class
(or class
"a-zA-Z0-9$_."))
6050 (progn (skip-chars-backward class
) (point))
6051 (progn (skip-chars-forward class
) (point)))))
6053 (defun idlwave-what-function (&optional bound
)
6054 ;; Find out if point is within the argument list of a function.
6055 ;; The return value is ("function-name" class arrow-start (point) level).
6056 ;; Level is 1 on the top level parentheses, higher further down.
6058 ;; If the optional BOUND is an integer, bound backwards directed
6059 ;; searches to this point.
6065 func arrow-start class
)
6066 (idlwave-with-special-syntax
6069 (narrow-to-region (max 1 (or bound
0)) (point-max))
6070 ;; move back out of the current parenthesis
6071 (while (condition-case nil
6072 (progn (up-list -
1) t
)
6076 (when (and (= (following-char) ?\
()
6078 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6080 (setq func
(match-string 2)
6081 func-point
(goto-char (match-beginning 2))
6083 (if (re-search-backward
6084 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6085 (setq arrow-start
(copy-marker (match-beginning 0))
6086 class
(or (match-string 2) t
)))
6090 (idlwave-sintern-routine-or-method func class
)
6091 (idlwave-sintern-class class
)
6092 arrow-start func-point cnt
)))
6094 (throw 'exit nil
)))))))
6096 (defun idlwave-what-procedure (&optional bound
)
6097 ;; Find out if point is within the argument list of a procedure.
6098 ;; The return value is ("procedure-name" class arrow-pos (point)).
6100 ;; If the optional BOUND is an integer, bound backwards directed
6101 ;; searches to this point.
6102 (let ((pos (point)) pro-point
6103 pro class arrow-start string
)
6105 ;;(idlwave-beginning-of-statement)
6106 (idlwave-start-of-substatement 'pre
)
6107 (setq string
(buffer-substring (point) pos
))
6109 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6110 (setq pro
(match-string 1 string
)
6111 pro-point
(+ (point) (match-beginning 1)))
6112 (if (and (idlwave-skip-object)
6113 (setq string
(buffer-substring (point) pos
))
6115 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6117 (setq pro
(if (match-beginning 4)
6118 (match-string 4 string
))
6119 pro-point
(if (match-beginning 4)
6120 (+ (point) (match-beginning 4))
6122 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6123 class
(or (match-string 3 string
) t
)))))
6124 (list (idlwave-sintern-routine-or-method pro class
)
6125 (idlwave-sintern-class class
)
6129 (defun idlwave-skip-object ()
6130 ;; If there is an object at point, move over it and return t.
6131 (let ((pos (point)))
6134 (skip-chars-forward " ") ; white space
6135 (skip-chars-forward "*") ; de-reference
6137 ((looking-at idlwave-identifier
)
6138 (goto-char (match-end 0)))
6139 ((eq (following-char) ?\
()
6141 (t (throw 'exit nil
)))
6144 (cond ((eq (following-char) ?.
)
6146 (if (not (looking-at idlwave-identifier
))
6148 (goto-char (match-end 0)))
6149 ((memq (following-char) '(?\
( ?\
[))
6152 (error (throw 'exit nil
))))
6153 (t (throw 'endwhile t
)))))
6154 (if (looking-at "[ \t]*->")
6155 (throw 'exit
(setq pos
(match-beginning 0)))
6156 (throw 'exit nil
))))
6160 (defun idlwave-last-valid-char ()
6161 "Return the last character before point which is not white or a comment
6162 and also not part of the current identifier. Since we do this in
6163 order to identify places where keywords are, we consider the initial
6164 `/' of a keyword as part of the identifier.
6165 This function is not general, can only be used for completion stuff."
6168 ;; skip the current identifier
6169 (skip-chars-backward "a-zA-Z0-9_$")
6170 ;; also skip a leading slash which might be belong to the keyword
6171 (if (eq (preceding-char) ?
/)
6173 ;; FIXME: does not check if this is a valid identifier
6175 (skip-chars-backward " \t")
6177 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6178 ((eq (preceding-char) ?
\n)
6179 (beginning-of-line 0)
6180 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6181 ;; continuation line
6182 (goto-char (match-end 1))
6184 (t (throw 'exit
(preceding-char))))))))
6186 (defvar idlwave-complete-after-success-form nil
6187 "A form to evaluate after successful completion.")
6188 (defvar idlwave-complete-after-success-form-force nil
6189 "A form to evaluate after completion selection in *Completions* buffer.")
6190 (defconst idlwave-completion-mark
(make-marker)
6191 "A mark pointing to the beginning of the completion string.")
6193 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6194 &optional prepare-display-function
6196 "Perform TYPE completion of word before point against LIST.
6197 SELECTOR is the PREDICATE argument for the completion function. Show
6198 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6199 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6200 used only once, for `all-completions', and can be used to, e.g.,
6201 accumulate information on matching completions."
6202 (let* ((completion-ignore-case t
)
6203 beg
(end (point)) slash part spart completion all-completions
6207 (error (concat prompt
": No completions available")))
6209 ;; What is already in the buffer?
6211 (skip-chars-backward "a-zA-Z0-9_$")
6212 (setq slash
(eq (preceding-char) ?
/)
6214 idlwave-complete-after-success-form
6215 (list 'idlwave-after-successful-completion
6216 (list 'quote type
) slash beg
)
6217 idlwave-complete-after-success-form-force
6218 (list 'idlwave-after-successful-completion
6219 (list 'quote type
) slash
(list 'quote
'force
))))
6222 (setq part
(buffer-substring beg end
)
6223 dpart
(downcase part
)
6224 spart
(idlwave-sintern stype part
)
6225 completion
(try-completion part list selector
)
6226 dcompletion
(if (stringp completion
) (downcase completion
))
6227 idlwave-completion-help-links nil
)
6230 ;; nothing available.
6231 (error (concat prompt
": no completion for \"%s\"") part
))
6232 ((and (not (equal dpart dcompletion
))
6233 (not (eq t completion
)))
6234 ;; We can add something
6235 (delete-region beg end
)
6236 (if (and (string= part dpart
)
6237 (or (not (string= part
""))
6238 idlwave-complete-empty-string-as-lower-case
)
6239 (not idlwave-completion-force-default-case
))
6240 (insert dcompletion
)
6241 (insert completion
))
6242 (if (eq t
(try-completion completion list selector
))
6243 ;; Now this is a unique match
6244 (idlwave-after-successful-completion type slash beg
))
6246 ((or (eq completion t
)
6247 (and (= 1 (length (setq all-completions
6249 (all-completions part list
6250 (or special-selector
6252 (equal dpart dcompletion
)))
6253 ;; This is already complete
6254 (idlwave-after-successful-completion type slash beg
)
6255 (message "%s is already the complete %s" part isa
)
6258 ;; We cannot add something - offer a list.
6259 (message "Making completion list...")
6261 (unless idlwave-completion-help-links
; already set somewhere?
6262 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6263 (let ((link (get-text-property 0 'link
(car x
))))
6265 (push (cons (car x
) link
)
6266 idlwave-completion-help-links
))))
6268 (let* ((list all-completions
)
6269 ;; "complete" means, this is already a valid completion
6270 (complete (memq spart all-completions
))
6271 (completion-highlight-first-word-only t
)) ; XEmacs
6272 ; (completion-fixup-function ; Emacs
6273 ; (lambda () (and (eq (preceding-char) ?>)
6274 ; (re-search-backward " <" beg t)))))
6276 (setq list
(sort list
(lambda (a b
)
6277 (string< (downcase a
) (downcase b
)))))
6278 (if prepare-display-function
6279 (setq list
(funcall prepare-display-function list
)))
6280 (if (and (string= part dpart
)
6281 (or (not (string= part
""))
6282 idlwave-complete-empty-string-as-lower-case
)
6283 (not idlwave-completion-force-default-case
))
6284 (setq list
(mapcar (lambda (x)
6286 (setcar x
(downcase (car x
)))
6287 (setq x
(downcase x
)))
6290 (idlwave-display-completion-list list prompt beg complete
))
6293 (defun idlwave-complete-class ()
6294 "Complete a class at point."
6296 ;; Call `idlwave-routines' to make sure the class list will be available
6298 ;; Check for the special case of completing empty string after pro/function
6299 (if (let ((case-fold-search t
))
6302 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6304 (goto-char (point-min))
6306 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6307 ;; Yank the full class specification
6308 (insert (match-string 2))
6309 ;; Do the completion, using list gathered from `idlwave-routines'
6310 (idlwave-complete-in-buffer
6311 'class
'class
(idlwave-class-alist) nil
6312 "Select a class" "class"
6313 '(lambda (list) ;; Push it to help-links if system help available
6315 (let* ((entry (idlwave-class-info x
))
6316 (link (nth 1 (assq 'link entry
))))
6317 (if link
(push (cons x link
)
6318 idlwave-completion-help-links
))
6322 (defun idlwave-attach-classes (list type show-classes
)
6323 ;; Attach the proper class list to a LIST of completion items.
6324 ;; TYPE, when 'kwd, shows classes for method keywords, when
6325 ;; 'class-tag, for class tags, and otherwise for methods.
6326 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6327 (if (or (null show-classes
) ; don't want to see classes
6328 (null class-selector
) ; not a method call
6330 (stringp class-selector
) ; the class is already known
6331 (not super-classes
))) ; no possibilities for inheritance
6332 ;; In these cases, we do not have to do anything
6334 (let* ((do-prop (and (>= show-classes
0)
6335 (>= emacs-major-version
21)))
6336 (do-buf (not (= show-classes
0)))
6337 ;; (do-dots (featurep 'xemacs))
6339 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6340 (cons class-selector super-classes
)))
6341 (max (abs show-classes
))
6342 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6343 classes nclasses class-info space
)
6347 (if (eq type
'class-tag
)
6348 ;; Just one class for tags
6351 (idlwave-class-or-superclass-with-tag class-selector x
)))
6352 ;; Multiple classes for method or method-keyword
6355 (idlwave-all-method-keyword-classes
6356 method-selector x type-selector
)
6357 (idlwave-all-method-classes x type-selector
)))
6361 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6363 (setq nclasses
(length classes
))
6364 ;; Make the separator between item and class-info
6366 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6369 ;; We do want info in the buffer
6370 (if (<= nclasses max
)
6371 (setq class-info
(concat
6373 "<" (mapconcat 'identity classes
",") ">"))
6374 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6375 (setq class-info nil
))
6377 ;; We do want properties
6378 (setq x
(copy-sequence x
))
6379 (put-text-property 0 (length x
)
6380 'help-echo
(mapconcat 'identity classes
" ")
6387 (defun idlwave-attach-method-classes (list)
6388 ;; Call idlwave-attach-classes with method parameters
6389 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6390 (defun idlwave-attach-keyword-classes (list)
6391 ;; Call idlwave-attach-classes with keyword parameters
6392 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6393 (defun idlwave-attach-class-tag-classes (list)
6394 ;; Call idlwave-attach-classes with class structure tags
6395 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6398 ;;----------------------------------------------------------------------
6399 ;;----------------------------------------------------------------------
6400 ;;----------------------------------------------------------------------
6401 ;;----------------------------------------------------------------------
6402 ;;----------------------------------------------------------------------
6404 (defun idlwave-pset (item)
6407 (defun idlwave-popup-select (ev list title
&optional sort
)
6408 "Select an item in LIST with a popup menu.
6409 TITLE is the title to put atop the popup. If SORT is non-nil,
6410 sort the list before displaying"
6411 (let ((maxpopup idlwave-max-popup-menu-items
)
6414 ((= 1 (length list
))
6415 (setq rtn
(car list
)))
6417 (if sort
(setq list
(sort list
(lambda (a b
)
6418 (string< (upcase a
) (upcase b
))))))
6420 (append (list title
)
6421 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6424 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6425 (setq resp
(get-popup-menu-response menu
))
6426 (funcall (event-function resp
) (event-object resp
)))
6428 (if sort
(setq list
(sort list
(lambda (a b
)
6429 (string< (upcase a
) (upcase b
))))))
6430 (setq menu
(cons title
6433 (mapcar (lambda(x) (cons x x
)) list
)))))
6434 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6435 (setq rtn
(x-popup-menu ev menu
))))
6438 (defun idlwave-split-menu-xemacs (menu N
)
6439 "Split the MENU into submenus of maximum length N."
6440 (if (<= (length menu
) (1+ N
))
6441 ;; No splitting needed
6443 (let* ((title (car menu
))
6444 (entries (cdr menu
))
6449 (while (and entries
(< cnt N
))
6451 nextmenu
(cons (car entries
) nextmenu
)
6452 entries
(cdr entries
)))
6453 (setq nextmenu
(nreverse nextmenu
))
6454 (setq nextmenu
(cons (format "%s...%s"
6455 (aref (car nextmenu
) 0)
6456 (aref (nth (1- cnt
) nextmenu
) 0))
6458 (setq menu
(cons nextmenu menu
)
6463 (defun idlwave-split-menu-emacs (menu N
)
6464 "Split the MENU into submenus of maximum length N."
6465 (if (<= (length (nth 1 menu
)) (1+ N
))
6466 ;; No splitting needed
6468 (let* ((title (car menu
))
6469 (entries (cdr (nth 1 menu
)))
6474 (while (and entries
(< cnt N
))
6476 nextmenu
(cons (car entries
) nextmenu
)
6477 entries
(cdr entries
)))
6478 (setq nextmenu
(nreverse nextmenu
))
6480 (setq nextmenu
(cons (format "%s...%s"
6481 (car (car nextmenu
))
6482 (car (nth (1- cnt
) nextmenu
)))
6484 (setq menu
(cons nextmenu menu
)
6487 (setq menu
(nreverse menu
))
6488 (setq menu
(cons title menu
))
6491 (defvar idlwave-completion-setup-hook nil
)
6493 (defun idlwave-scroll-completions (&optional message
)
6494 "Scroll the completion window on this frame."
6495 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
6496 (win (selected-window)))
6499 (select-window cwin
)
6502 (error (if (and (listp last-command
)
6503 (nth 2 last-command
))
6506 (eval idlwave-complete-after-success-form
))
6507 (set-window-start cwin
(point-min)))))
6508 (and message
(message message
)))
6509 (select-window win
))))
6511 (defun idlwave-display-completion-list (list &optional message beg complete
)
6512 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6513 (unless (and (get-buffer-window "*Completions*")
6514 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
6515 (move-marker idlwave-completion-mark beg
)
6516 (setq idlwave-before-completion-wconf
(current-window-configuration)))
6518 (if (featurep 'xemacs
)
6519 (idlwave-display-completion-list-xemacs
6521 (idlwave-display-completion-list-emacs list
))
6523 ;; Store a special value in `this-command'. When `idlwave-complete'
6524 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6525 (setq this-command
(list 'idlwave-display-completion-list message complete
))
6527 ;; Mark the completions buffer as created by cib
6528 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
6530 ;; Fontify the classes
6531 (if (and idlwave-completion-fontify-classes
6533 (idlwave-completion-fontify-classes))
6536 (run-hooks 'idlwave-completion-setup-hook
)
6538 ;; Display the message
6539 (message (or message
"Making completion list...done")))
6541 (defun idlwave-choose (function &rest args
)
6542 "Call FUNCTION as a completion chooser and pass ARGS to it."
6543 (let ((completion-ignore-case t
)) ; install correct value
6544 (apply function args
))
6545 (if (and (eq major-mode
'idlwave-shell-mode
)
6546 (boundp 'font-lock-mode
)
6547 (not font-lock-mode
))
6548 ;; For the shell, remove the fontification of the word before point
6549 (let ((beg (save-excursion
6550 (skip-chars-backward "a-zA-Z0-9_")
6552 (remove-text-properties beg
(point) '(face nil
))))
6553 (eval idlwave-complete-after-success-form-force
))
6555 (defun idlwave-keyboard-quit ()
6558 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
6559 (idlwave-restore-wconf-after-completion))
6562 (defun idlwave-restore-wconf-after-completion ()
6563 "Restore the old (before completion) window configuration."
6564 (and idlwave-completion-restore-window-configuration
6565 idlwave-before-completion-wconf
6566 (set-window-configuration idlwave-before-completion-wconf
)))
6568 (defun idlwave-one-key-select (sym prompt delay
)
6569 "Make the user select an element from the alist in the variable SYM.
6570 The keys of the alist are expected to be strings. The function returns the
6571 car of the selected association.
6572 To do this, PROMPT is displayed and and the user must hit a letter key to
6573 select an entry. If the user does not reply within DELAY seconds, a help
6574 window with the options is displayed automatically.
6575 The key which is associated with each option is generated automatically.
6576 First, the strings are checked for preselected keys, like in \"[P]rint\".
6577 If these don't exist, a letter in the string is automatically selected."
6578 (let* ((alist (symbol-value sym
))
6579 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
6580 '(fit-window-to-buffer)))
6582 ;; First check the cache
6583 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
6584 (setq keys-alist
(get sym
:one-key-alist-cache
))
6585 ;; Need to make new list
6586 (setq keys-alist
(idlwave-make-one-key-alist alist
))
6587 (put sym
:one-key-alist-cache keys-alist
)
6588 (put sym
:one-key-alist-last alist
))
6589 ;; Display prompt and wait for quick reply
6590 (message "%s[%s]" prompt
6591 (mapconcat (lambda(x) (char-to-string (car x
)))
6594 ;; No quick reply: Show help
6595 (save-window-excursion
6596 (with-output-to-temp-buffer "*Completions*"
6601 (setq char
(read-char)))
6602 (setq char
(read-char)))
6604 ;; Return the selected result
6605 (nth 2 (assoc char keys-alist
))))
6607 ;; Used for, e.g., electric debug super-examine.
6608 (defun idlwave-make-one-key-alist (alist)
6609 "Make an alist for single key selection."
6610 (let ((l alist
) keys-alist name start char help
6612 (case-fold-search nil
))
6614 (setq name
(car (car l
))
6617 ;; First check if the configuration predetermined a key
6618 (if (string-match "\\[\\(.\\)\\]" name
)
6620 (setq char
(string-to-char (downcase (match-string 1 name
)))
6621 help
(format "%c: %s" char name
)
6622 keys-alist
(cons (list char help name
) keys-alist
))
6624 ;; Then check for capital letters
6626 (while (string-match "[A-Z]" name start
)
6627 (setq start
(match-end 0)
6628 char
(string-to-char (downcase (match-string 0 name
))))
6629 (if (not (assoc char keys-alist
))
6631 (setq help
(format "%c: %s" char
6633 (concat "[" (match-string 0 name
) "]")
6635 keys-alist
(cons (list char help name
) keys-alist
))
6637 ;; Now check for lowercase letters
6639 (while (string-match "[a-z]" name start
)
6640 (setq start
(match-end 0)
6641 char
(string-to-char (match-string 0 name
)))
6642 (if (not (assoc char keys-alist
))
6644 (setq help
(format "%c: %s" char
6646 (concat "[" (match-string 0 name
) "]")
6648 keys-alist
(cons (list char help name
) keys-alist
))
6650 ;; Bummer, nothing found! Use a stupid number
6651 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
6652 help
(format "%c: %s" char name
)
6653 keys-alist
(cons (list char help name
) keys-alist
))))
6654 (nreverse keys-alist
)))
6656 (defun idlwave-set-local (var value
&optional buffer
)
6657 "Set the buffer-local value of VAR in BUFFER to VALUE."
6659 (set-buffer (or buffer
(current-buffer)))
6660 (set (make-local-variable var
) value
)))
6662 (defun idlwave-local-value (var &optional buffer
)
6663 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6665 (set-buffer (or buffer
(current-buffer)))
6666 (and (local-variable-p var
(current-buffer))
6667 (symbol-value var
))))
6669 ;; In XEmacs, we can use :activate-callback directly to advice the
6670 ;; choose functions. We use the private keymap only for the online
6673 (defvar idlwave-completion-map nil
6674 "Keymap for completion-list-mode with idlwave-complete.")
6676 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
6677 (with-output-to-temp-buffer "*Completions*"
6678 (apply 'display-completion-list list
6679 ':activate-callback
'idlwave-default-choose-completion
6682 (set-buffer "*Completions*")
6684 (or idlwave-completion-map
6685 (setq idlwave-completion-map
6686 (idlwave-make-modified-completion-map-xemacs
6687 (current-local-map)))))))
6689 (defun idlwave-default-choose-completion (&rest args
)
6690 "Execute `default-choose-completion' and then restore the win-conf."
6691 (apply 'idlwave-choose
'default-choose-completion args
))
6693 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6694 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6695 (let ((new-map (copy-keymap old-map
)))
6696 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
6697 (define-key new-map [button3] (lambda ()
6699 (setq this-command last-command)))
6702 ;; In Emacs we also replace keybindings in the completion
6703 ;; map in order to install our wrappers.
6705 (defun idlwave-display-completion-list-emacs (list)
6706 "Display completion list and install the choose wrappers."
6707 (with-output-to-temp-buffer "*Completions*"
6708 (display-completion-list list))
6710 (set-buffer "*Completions*")
6712 (or idlwave-completion-map
6713 (setq idlwave-completion-map
6714 (idlwave-make-modified-completion-map-emacs
6715 (current-local-map)))))))
6717 (defun idlwave-make-modified-completion-map-emacs (old-map)
6718 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6719 (let ((new-map (copy-keymap old-map)))
6720 (substitute-key-definition
6721 'choose-completion 'idlwave-choose-completion new-map)
6722 (substitute-key-definition
6723 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6724 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6727 (defun idlwave-choose-completion (&rest args)
6728 "Choose the completion that point is in or next to."
6730 (apply 'idlwave-choose 'choose-completion args))
6732 (defun idlwave-mouse-choose-completion (&rest args)
6733 "Click on an alternative in the `*Completions*' buffer to choose it."
6735 (apply 'idlwave-choose 'mouse-choose-completion args))
6737 ;;----------------------------------------------------------------------
6738 ;;----------------------------------------------------------------------
6740 ;;; ------------------------------------------------------------------------
6741 ;;; Stucture parsing code, and code to manage class info
6744 ;; - Go again over the documentation how to write a completion
6745 ;; plugin. It is in self.el, but currently still very bad.
6746 ;; This could be in a separate file in the distribution, or
6747 ;; in an appendix for the manual.
6749 (defvar idlwave-struct-skip
6750 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
6751 "Regexp for skipping continued blank or comment-only lines in
6754 (defvar idlwave-struct-tag-regexp
6755 (concat "[{,]" ;leading comma/brace
6756 idlwave-struct-skip ; 4 groups
6757 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
6758 "[ \t]*:") ; the final colon
6759 "Regexp for structure tags.")
6761 (defun idlwave-struct-tags ()
6762 "Return a list of all tags in the structure defined at point.
6763 Point is expected just before the opening `{' of the struct definition."
6765 (let* ((borders (idlwave-struct-borders))
6771 (narrow-to-region beg end)
6772 (while (re-search-forward idlwave-struct-tag-regexp end t)
6773 ;; Check if we are still on the top level of the structure.
6774 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6776 (push (match-string-no-properties 5) tags))
6777 (goto-char (match-end 0))))
6780 (defun idlwave-find-struct-tag (tag)
6781 "Find a given TAG in the structure defined at point."
6782 (let* ((borders (idlwave-struct-borders))
6785 (case-fold-search t))
6786 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6789 (defun idlwave-struct-inherits ()
6790 "Return a list of all `inherits' names in the struct at point.
6791 Point is expected just before the opening `{' of the struct definition."
6793 (let* ((borders (idlwave-struct-borders))
6796 (case-fold-search t)
6800 (narrow-to-region beg end)
6801 (while (re-search-forward
6802 (concat "[{,]" ;leading comma/brace
6803 idlwave-struct-skip ; 4 groups
6804 "inherits" ; The INHERITS tag
6805 idlwave-struct-skip ; 4 more
6806 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
6808 ;; Check if we are still on the top level of the structure.
6809 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6811 (push (match-string-no-properties 9) names))
6812 (goto-char (match-end 0))))
6815 (defun idlwave-in-structure ()
6816 "Return t if point is inside an IDL structure definition."
6817 (let ((beg (point)))
6819 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6820 (if (idlwave-find-structure-definition nil nil 'back)
6821 (let ((borders (idlwave-struct-borders)))
6822 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6823 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6825 (defun idlwave-struct-borders ()
6826 "Return the borders of the {...} after point as a cons cell."
6829 (skip-chars-forward "^{")
6831 (condition-case nil (forward-list 1)
6832 (error (goto-char beg)))
6833 (cons beg (point)))))
6835 (defun idlwave-find-structure-definition (&optional var name bound)
6836 "Search forward for a structure definition. If VAR is non-nil,
6837 search for a structure assigned to variable VAR. If NAME is non-nil,
6838 search for a named structure NAME, if a string, or a generic named
6839 structure otherwise. If BOUND is an integer, limit the search. If
6840 BOUND is the symbol `all', we search first back and then forward
6841 through the entire file. If BOUND is the symbol `back' we search only
6843 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6844 (case-fold-search t)
6845 (lim (if (integerp bound) bound nil))
6848 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6853 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
6854 ;; Just a generic name
6855 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
6857 (if (or (and (or (eq bound 'all) (eq bound 'back))
6858 (re-search-backward re nil t))
6859 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6861 (goto-char (match-beginning 3))
6862 (match-string-no-properties 5)))))
6864 (defvar idlwave-class-info nil)
6865 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
6866 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
6868 (add-hook 'idlwave-update-rinfo-hook
6869 (lambda () (setq idlwave-class-reset t)))
6870 (add-hook 'idlwave-after-load-rinfo-hook
6871 (lambda () (setq idlwave-class-info nil)))
6873 (defun idlwave-class-info (class)
6875 (if idlwave-class-info
6876 (if idlwave-class-reset
6878 idlwave-class-reset nil
6879 idlwave-class-info ; Remove any visited in a buffer
6883 (idlwave-class-file-or-buffer
6884 (or (cdr (assq 'found-in x)) (car x)))))
6888 idlwave-class-info))))
6889 ;; Info is nil, put in the system stuff to start.
6890 (setq idlwave-class-info idlwave-system-class-info)
6891 (setq list idlwave-class-info)
6892 (while (setq entry (pop list))
6893 (idlwave-sintern-class-info entry)))
6894 (setq class (idlwave-sintern-class class))
6895 (or (assq class idlwave-class-info)
6896 (progn (idlwave-scan-class-info class)
6897 (assq class idlwave-class-info)))))
6899 (defun idlwave-sintern-class-info (entry)
6900 "Sintern the class names in a class-info entry."
6901 (let ((taglist (assq 'tags entry))
6902 (inherits (assq 'inherits entry)))
6903 (setcar entry (idlwave-sintern-class (car entry) 'set))
6905 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6908 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
6909 "Find class structure definition(s)
6910 If ALL-HOOK is set, find all named structure definitions in a given
6911 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
6912 set, look for the name__define pro, and inside of it, for the ALT-CLASS
6913 class/struct definition"
6914 (let ((case-fold-search t) end-lim list name)
6915 (when (re-search-forward
6916 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6919 ;; For everything there
6920 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
6922 (idlwave-find-structure-definition nil t end-lim))
6923 (funcall all-hook name)))
6924 (idlwave-find-structure-definition nil (or alt-class class))))))
6927 (defun idlwave-class-file-or-buffer (class)
6928 "Find buffer visiting CLASS definition"
6929 (let* ((pro (concat (downcase class) "__define"))
6930 (file (idlwave-routine-source-file
6931 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6932 (idlwave-routines))))))
6933 (cons file (if file (idlwave-get-buffer-visiting file)))))
6936 (defun idlwave-scan-class-info (class)
6937 "Scan all class and named structure info in the class__define pro"
6938 (let* ((idlwave-auto-routine-info-updates nil)
6939 (filebuf (idlwave-class-file-or-buffer class))
6940 (file (car filebuf))
6942 (class (idlwave-sintern-class class)))
6945 (and ;; neither a regular file nor a visited buffer
6947 (not (file-regular-p file))))
6948 nil ; Cannot find the file/buffer to get any info
6950 (if buf (set-buffer buf)
6951 ;; Read the file in temporarily
6952 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6954 (unless (eq major-mode 'idlwave-mode)
6956 (insert-file-contents file))
6959 (idlwave-find-class-definition class
6960 ;; Scan all of the structures found there
6962 (let* ((this-class (idlwave-sintern-class name))
6965 (cons 'tags (idlwave-struct-tags))
6966 (cons 'inherits (idlwave-struct-inherits)))))
6967 (if (not (eq this-class class))
6968 (setq entry (nconc entry (list (cons 'found-in class)))))
6969 (idlwave-sintern-class-info entry)
6970 (push entry idlwave-class-info)))))))))
6972 (defun idlwave-class-found-in (class)
6973 "Return the FOUND-IN property of the class."
6974 (cdr (assq 'found-in (idlwave-class-info class))))
6975 (defun idlwave-class-tags (class)
6976 "Return the native tags in CLASS."
6977 (cdr (assq 'tags (idlwave-class-info class))))
6978 (defun idlwave-class-inherits (class)
6979 "Return the direct superclasses of CLASS."
6980 (cdr (assq 'inherits (idlwave-class-info class))))
6983 (defun idlwave-all-class-tags (class)
6984 "Return a list of native and inherited tags in CLASS."
6986 (apply 'append (mapcar 'idlwave-class-tags
6987 (cons class (idlwave-all-class-inherits class))))
6989 (idlwave-class-tag-reset)
6990 (error "%s" (error-message-string err)))))
6993 (defun idlwave-all-class-inherits (class)
6994 "Return a list of all superclasses of CLASS (recursively expanded).
6995 The list is cached in `idlwave-class-info' for faster access."
6997 ((not idlwave-support-inheritance) nil)
6998 ((eq class nil) nil)
7001 (let ((info (idlwave-class-info class))
7003 (if (setq entry (assq 'all-inherits info))
7005 ;; Save the depth of inheritance scan to check for circular references
7006 (let ((inherits (mapcar (lambda (x) (cons x 0))
7007 (idlwave-class-inherits class)))
7008 rtn all-inherits cl)
7010 (setq cl (pop inherits)
7011 rtn (cons (car cl) rtn)
7012 inherits (append (mapcar (lambda (x)
7013 (cons x (1+ (cdr cl))))
7014 (idlwave-class-inherits (car cl)))
7016 (if (> (cdr cl) 999)
7018 "Class scan: inheritance depth exceeded. Circular inheritance?")
7020 (setq all-inherits (nreverse rtn))
7021 (nconc info (list (cons 'all-inherits all-inherits)))
7024 (defun idlwave-entry-keywords (entry &optional record-link)
7025 "Return the flat entry keywords alist from routine-info entry.
7026 If RECORD-LINK is non-nil, the keyword text is copied and a text
7027 property indicating the link is added."
7031 (let ((file (car key-list)))
7032 (mapcar (lambda (key-cons)
7033 (let ((key (car key-cons))
7034 (link (cdr key-cons)))
7035 (when (and record-link file)
7036 (setq key (copy-sequence key))
7043 (concat idlwave-html-link-sep
7044 (number-to-string link))))
7046 (push (list key) kwds)))
7051 (defun idlwave-entry-find-keyword (entry keyword)
7052 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7056 (let ((file (car key-list))
7057 (kwd (assoc keyword (cdr key-list))))
7059 (setq kwd (cons (car kwd)
7060 (if (and file (cdr kwd))
7062 idlwave-html-link-sep
7063 (number-to-string (cdr kwd)))
7065 (throw 'exit kwd))))
7068 ;;==========================================================================
7070 ;; Completing class structure tags. This is a completion plugin.
7071 ;; The necessary taglist is constructed dynamically
7073 (defvar idlwave-current-tags-class nil)
7074 (defvar idlwave-current-class-tags nil)
7075 (defvar idlwave-current-native-class-tags nil)
7076 (defvar idlwave-sint-class-tags nil)
7077 (idlwave-new-sintern-type 'class-tag)
7078 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7079 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7081 (defun idlwave-complete-class-structure-tag ()
7082 "Complete a structure tag on a `self' argument in an object method."
7085 (case-fold-search t))
7087 ;; Check if the context is right
7088 (skip-chars-backward "a-zA-Z0-9._$")
7089 (and (< (point) (- pos 4))
7090 (looking-at "self\\.")))
7091 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7092 (super-classes (idlwave-all-class-inherits class-selector)))
7093 ;; Check if we are in a class routine
7094 (unless class-selector
7095 (error "Not in a method procedure or function"))
7096 ;; Check if we need to update the "current" class
7097 (if (not (equal class-selector idlwave-current-tags-class))
7098 (idlwave-prepare-class-tag-completion class-selector))
7099 (setq idlwave-completion-help-info
7100 (list 'idlwave-complete-class-structure-tag-help
7101 (idlwave-sintern-routine
7102 (concat class-selector "__define"))
7104 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7105 (idlwave-complete-in-buffer
7106 'class-tag 'class-tag
7107 idlwave-current-class-tags nil
7108 (format "Select a tag of class %s" class-selector)
7110 'idlwave-attach-class-tag-classes))
7111 t) ; return t to skip other completions
7114 (defun idlwave-class-tag-reset ()
7115 (setq idlwave-current-tags-class nil))
7117 (defun idlwave-prepare-class-tag-completion (class)
7118 "Find and parse the necessary class definitions for class structure tags."
7119 (setq idlwave-sint-class-tags nil)
7120 (setq idlwave-current-tags-class class)
7121 (setq idlwave-current-class-tags
7123 (list (idlwave-sintern-class-tag x 'set)))
7124 (idlwave-all-class-tags class)))
7125 (setq idlwave-current-native-class-tags
7126 (mapcar 'downcase (idlwave-class-tags class))))
7128 ;===========================================================================
7130 ;; Completing system variables and their structure fields
7131 ;; This is also a plugin.
7133 (defvar idlwave-sint-sysvars nil)
7134 (defvar idlwave-sint-sysvartags nil)
7135 (idlwave-new-sintern-type 'sysvar)
7136 (idlwave-new-sintern-type 'sysvartag)
7137 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7138 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7139 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7141 (defvar idlwave-executive-commands-alist nil
7142 "Alist of system variables and their help files.")
7144 (defvar idlwave-system-variables-alist nil
7145 "Alist of system variables and the associated structure tags.
7146 Gets set in `idlw-rinfo.el'.")
7148 (defun idlwave-complete-sysvar-or-tag ()
7149 "Complete a system variable."
7152 (case-fold-search t))
7153 (cond ((save-excursion
7154 ;; Check if the context is right for system variable
7155 (skip-chars-backward "[a-zA-Z0-9_$]")
7156 (equal (char-before) ?!))
7157 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7158 (idlwave-complete-in-buffer 'sysvar 'sysvar
7159 idlwave-system-variables-alist nil
7160 "Select a system variable"
7162 t) ; return t to skip other completions
7164 ;; Check if the context is right for sysvar tag
7165 (skip-chars-backward "a-zA-Z0-9_$.")
7166 (and (equal (char-before) ?!)
7167 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7168 (<= (match-end 0) pos)))
7169 ;; Complete a system variable tag
7170 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7171 (entry (assq var idlwave-system-variables-alist))
7172 (tags (cdr (assq 'tags entry))))
7173 (or entry (error "!%s is not a known system variable" var))
7174 (or tags (error "System variable !%s is not a structure" var))
7175 (setq idlwave-completion-help-info
7176 (list 'idlwave-complete-sysvar-tag-help var))
7177 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7179 "Select a system variable tag"
7180 "system variable tag")
7181 t)) ; return t to skip other completions
7184 (defvar link) ;dynamic
7185 (defun idlwave-complete-sysvar-help (mode word)
7186 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7187 (entry (assoc word idlwave-system-variables-alist)))
7190 (and (stringp word) entry (nth 1 (assq 'link entry))))
7192 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7193 (t (error "This should not happen")))))
7195 (defun idlwave-complete-sysvar-tag-help (mode word)
7196 (let* ((var (nth 1 idlwave-completion-help-info))
7197 (entry (assoc var idlwave-system-variables-alist))
7198 (tags (cdr (assq 'tags entry)))
7199 (main (nth 1 (assq 'link entry)))
7202 ((eq mode 'test) ; we can at least link the main
7203 (and (stringp word) entry main))
7207 (if (setq target (cdr (assoc word tags)))
7208 (idlwave-substitute-link-target main target)
7209 main)))) ;; setting dynamic!!!
7210 (t (error "This should not happen")))))
7212 (defun idlwave-substitute-link-target (link target)
7213 "Substitute the target anchor for the given link."
7215 (setq main-base (if (string-match "#" link)
7216 (substring link 0 (match-beginning 0))
7219 (concat main-base idlwave-html-link-sep (number-to-string target))
7222 ;; Fake help in the source buffer for class structure tags.
7223 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7226 (defvar idlwave-help-do-class-struct-tag nil)
7227 (defun idlwave-complete-class-structure-tag-help (mode word)
7229 ((eq mode 'test) ; nothing gets fontified for class tags
7232 (let (class-with found-in)
7233 (when (setq class-with
7234 (idlwave-class-or-superclass-with-tag
7235 idlwave-current-tags-class
7237 (if (assq (idlwave-sintern-class class-with)
7238 idlwave-system-class-info)
7239 (error "No help available for system class tags"))
7240 (if (setq found-in (idlwave-class-found-in class-with))
7241 (setq name (cons (concat found-in "__define") class-with))
7242 (setq name (concat class-with "__define")))))
7244 idlwave-help-do-class-struct-tag t))
7245 (t (error "This should not happen"))))
7247 (defun idlwave-class-or-superclass-with-tag (class tag)
7248 "Find and return the CLASS or one of its superclass with the
7249 associated TAG, if any."
7250 (let ((sclasses (cons class (cdr (assq 'all-inherits
7251 (idlwave-class-info class)))))
7255 (setq cl (pop sclasses))
7256 (let ((tags (idlwave-class-tags cl)))
7258 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7260 (setq tags (cdr tags))))))))
7263 (defun idlwave-sysvars-reset ()
7264 (if (and (fboundp 'idlwave-shell-is-running)
7265 (idlwave-shell-is-running)
7266 idlwave-idlwave_routine_info-compiled)
7267 (idlwave-shell-send-command "idlwave_get_sysvars"
7268 'idlwave-process-sysvars 'hide)))
7270 (defun idlwave-process-sysvars ()
7271 (idlwave-shell-filter-sysvars)
7272 (setq idlwave-sint-sysvars nil
7273 idlwave-sint-sysvartags nil)
7274 (idlwave-sintern-sysvar-alist))
7276 (defun idlwave-sintern-sysvar-alist ()
7277 (let ((list idlwave-system-variables-alist) entry tags)
7278 (while (setq entry (pop list))
7279 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7280 (setq tags (assq 'tags entry))
7284 (cons (idlwave-sintern-sysvartag (car x) 'set)
7288 (defvar idlwave-shell-command-output)
7289 (defun idlwave-shell-filter-sysvars ()
7290 "Get any new system variables and tags."
7291 (let ((text idlwave-shell-command-output)
7293 (old idlwave-system-variables-alist)
7294 var tags type name class link old-entry)
7295 (setq idlwave-system-variables-alist nil)
7296 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7298 (setq start (match-end 0)
7299 var (match-string 1 text)
7300 tags (if (match-end 3)
7301 (idlwave-split-string (match-string 3 text))))
7302 ;; Maintain old links, if present
7303 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7304 (setq link (assq 'link old-entry))
7305 (setq idlwave-system-variables-alist
7312 (idlwave-sintern-sysvartag x)
7313 (cdr (assq 'tags old-entry))))))
7315 idlwave-system-variables-alist)))
7316 ;; Keep the old value if query was not successful
7317 (setq idlwave-system-variables-alist
7318 (or idlwave-system-variables-alist old))))
7320 (defun idlwave-completion-fontify-classes ()
7321 "Goto the *Completions* buffer and fontify the class info."
7322 (when (featurep 'font-lock)
7324 (set-buffer "*Completions*")
7326 (goto-char (point-min))
7327 (let ((buffer-read-only nil))
7328 (while (re-search-forward "\\.*<[^>]+>" nil t)
7329 (put-text-property (match-beginning 0) (match-end 0)
7330 'face 'font-lock-string-face)))))))
7332 (defun idlwave-uniquify (list)
7333 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7336 (unless (gethash x ht)
7341 (defun idlwave-after-successful-completion (type slash &optional verify)
7342 "Add `=' or `(' after successful completion of keyword and function.
7343 Restore the pre-completion window configuration if possible."
7345 ((eq type 'procedure)
7347 ((eq type 'function)
7349 ((equal idlwave-function-completion-adds-paren nil) nil)
7350 ((or (equal idlwave-function-completion-adds-paren t)
7351 (equal idlwave-function-completion-adds-paren 1))
7353 ((equal idlwave-function-completion-adds-paren 2)
7358 (if (and idlwave-keyword-completion-adds-equal
7360 (progn (insert "=") t)
7363 ;; Restore the pre-completion window configuration if this is safe.
7365 (if (or (eq verify 'force) ; force
7367 (get-buffer-window "*Completions*") ; visible
7368 (idlwave-local-value 'idlwave-completion-p
7369 "*Completions*") ; cib-buffer
7370 (eq (marker-buffer idlwave-completion-mark)
7371 (current-buffer)) ; buffer OK
7372 (equal (marker-position idlwave-completion-mark)
7374 (idlwave-restore-wconf-after-completion))
7375 (move-marker idlwave-completion-mark nil)
7376 (setq idlwave-before-completion-wconf nil))
7378 (defun idlwave-mouse-context-help (ev &optional arg)
7379 "Call `idlwave-context-help' on the clicked location."
7381 (mouse-set-point ev)
7382 (idlwave-context-help arg))
7384 (defvar idlwave-last-context-help-pos nil)
7385 (defun idlwave-context-help (&optional arg)
7386 "Display IDL Online Help on context.
7387 If point is on a keyword, help for that keyword will be shown. If
7388 point is on a routine name or in the argument list of a routine, help
7389 for that routine will be displayed. Works for system routines and
7390 keywords, it pulls up text help. For other routies and keywords,
7391 visits the source file, finding help in the header (if
7392 `idlwave-help-source-try-header' is non-nil) or the routine definition
7395 (idlwave-do-context-help arg))
7397 (defun idlwave-mouse-completion-help (ev)
7398 "Display online help about the completion at point."
7400 ;; Restore last-command for next command, to make
7401 ;; scrolling/cancelling of completions work.
7402 (setq this-command last-command)
7403 (idlwave-do-mouse-completion-help ev))
7405 (defun idlwave-routine-info (&optional arg external)
7406 "Display a routines calling sequence and list of keywords. When
7407 point is on the name a function or procedure, or in the argument list
7408 of a function or procedure, this command displays a help buffer with
7409 the information. When called with prefix arg, enforce class query.
7411 When point is on an object operator `->', display the class stored in
7412 this arrow, if any (see `idlwave-store-inquired-class'). With a
7413 prefix arg, the class property is cleared out."
7417 (if (string-match "->" (buffer-substring
7418 (max (point-min) (1- (point)))
7419 (min (+ 2 (point)) (point-max))))
7420 ;; Cursor is on an arrow
7421 (if (get-text-property (point) 'idlwave-class)
7422 ;; arrow has class property
7427 (when (looking-at ".?\\(->\\)")
7428 (remove-text-properties (match-beginning 1) (match-end 1)
7429 '(idlwave-class nil face nil))
7430 (message "Class property removed from arrow")))
7431 ;; Echo class property
7432 (message "Arrow has text property identifying object to be class %s"
7433 (get-text-property (point) 'idlwave-class)))
7434 ;; No property found
7435 (message "Arrow has no class text property"))
7437 ;; Not on an arrow...
7438 (let* ((idlwave-query-class nil)
7439 (idlwave-force-class-query (equal arg '(4)))
7440 (module (idlwave-what-module)))
7442 (apply 'idlwave-display-calling-sequence
7443 (idlwave-fix-module-if-obj_new module))
7444 (error "Don't know which calling sequence to show")))))
7446 (defun idlwave-resolve (&optional arg)
7447 "Call RESOLVE_ROUTINE on the module name at point.
7448 Like `idlwave-routine-info', this looks for a routine call at point.
7449 After confirmation in the minibuffer, it will use the shell to issue
7450 a RESOLVE call for this routine, to attempt to make it defined and its
7451 routine info available for IDLWAVE. If the routine is a method call,
7452 both `class__method' and `class__define' will be tried.
7453 With ARG, enforce query for the class of object methods."
7455 (let* ((idlwave-query-class nil)
7456 (idlwave-force-class-query (equal arg '(4)))
7457 (module (idlwave-what-module))
7458 (name (idlwave-make-full-name (nth 2 module) (car module)))
7459 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7460 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7463 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7465 (setq type (match-string 1 resolve)
7466 class (if (match-beginning 2)
7467 (match-string 3 resolve)
7469 name (match-string 4 resolve)))
7470 (if (string= (downcase type) "function")
7471 (setq kwd ",/is_function"))
7475 (idlwave-shell-send-command
7476 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7477 'idlwave-update-routine-info
7480 (idlwave-shell-send-command
7481 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7482 (list 'idlwave-shell-send-command
7483 (format "resolve_routine,'%s__%s'%s"
7484 (downcase class) (downcase name) kwd)
7485 '(idlwave-update-routine-info)
7488 (defun idlwave-find-module-this-file ()
7490 (idlwave-find-module '(4)))
7492 (defun idlwave-find-module (&optional arg)
7493 "Find the source code of an IDL module.
7494 Works for modules for which IDLWAVE has routine info available. The
7495 function offers as default the module name `idlwave-routine-info'
7496 would use. With ARG limit to this buffer. With two prefix ARG's
7497 force class query for object methods."
7499 (let* ((idlwave-query-class nil)
7500 (idlwave-force-class-query (equal arg '(16)))
7501 (this-buffer (equal arg '(4)))
7502 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7504 (concat (idlwave-make-full-name
7505 (nth 2 module) (car module))
7506 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7512 (if (eq 'system (car-safe (nth 3 x)))
7513 ;; Take out system routines with no source.
7516 (concat (idlwave-make-full-name
7518 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7520 (idlwave-save-buffer-update)
7521 (idlwave-routines))))))
7522 (name (idlwave-completing-read
7523 (if (or (not this-buffer)
7524 (assoc default list))
7525 (format "Module (Default %s): " default)
7526 (format "Module in this file: "))
7529 (if (string-match "\\`\\s-*\\'" name)
7530 ;; Nothing, use the default.
7531 (setq name default))
7532 (if (string-match "<[fp]>" name)
7533 (setq type (substring name -2 -1)
7534 name (substring name 0 -3)))
7535 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7536 (setq class (match-string 1 name)
7537 name (match-string 2 name)))
7538 (setq name (idlwave-sintern-routine-or-method name class)
7539 class (idlwave-sintern-class class)
7540 type (cond ((equal type "f") 'fun)
7541 ((equal type "p") 'pro)
7543 (idlwave-do-find-module name type class nil this-buffer)))
7545 (defun idlwave-do-find-module (name type class
7546 &optional force-source this-buffer)
7547 (let ((name1 (idlwave-make-full-name class name))
7549 (buf (current-buffer))
7552 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7554 source (or force-source (nth 3 entry))
7555 name2 (if (nth 2 entry)
7556 (idlwave-make-full-name (nth 2 entry) name)
7559 (setq file (idlwave-routine-source-file source)))
7560 (unless file ; Try to find it on the path.
7562 (idlwave-expand-lib-file-name
7564 (format "%s__define.pro" (downcase class))
7565 (format "%s.pro" (downcase name))))))
7567 ((or (null name) (equal name ""))
7569 ((eq (car source) 'system)
7570 (error "Source code for system routine %s is not available"
7572 ((or (not file) (not (file-regular-p file)))
7573 (error "Source code for routine %s is not available"
7576 (when (not this-buffer)
7578 (idlwave-find-file-noselect file 'find))
7579 (pop-to-buffer buf1 t))
7580 (goto-char (point-max))
7581 (let ((case-fold-search t))
7582 (if (re-search-backward
7583 (concat "^[ \t]*\\<"
7584 (cond ((eq type 'fun) "function")
7585 ((eq type 'pro) "pro")
7586 (t "\\(pro\\|function\\)"))
7588 (regexp-quote (downcase name2))
7591 (goto-char (match-beginning 0))
7594 (error "Could not find routine %s" name2)))))))
7596 (defun idlwave-what-module ()
7597 "Return a default module for stuff near point.
7598 Used by `idlwave-routine-info' and `idlwave-find-module'."
7600 (if (let ((case-fold-search t))
7602 (idlwave-beginning-of-statement)
7603 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7604 ;; This is a function or procedure definition statement
7605 ;; We return the defined routine as module.
7607 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
7608 (match-string-no-properties 2))
7609 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7610 (idlwave-sintern-class (match-string 3)))
7612 ;; Not a definition statement - analyze precise position.
7613 (let* ((where (idlwave-where))
7615 (pro (car (nth 0 where)))
7616 (func (car (nth 1 where)))
7617 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7618 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7622 ((and (eq cw 'procedure)
7623 (not (equal this-word "")))
7624 (setq this-word (idlwave-sintern-routine-or-method
7625 this-word (nth 2 (nth 3 where))))
7626 (list this-word 'pro
7627 (idlwave-determine-class
7628 (cons this-word (cdr (nth 3 where)))
7630 ((and (eq cw 'function)
7631 (not (equal this-word ""))
7632 (or (eq next-char ?\() ; exclude arrays, vars.
7633 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7634 (setq this-word (idlwave-sintern-routine-or-method
7635 this-word (nth 2 (nth 3 where))))
7636 (list this-word 'fun
7637 (idlwave-determine-class
7638 (cons this-word (cdr (nth 3 where)))
7640 ((and (memq cw '(function-keyword procedure-keyword))
7641 (not (equal this-word ""))
7642 (eq next-char ?\()) ; A function!
7643 (setq this-word (idlwave-sintern-routine this-word))
7644 (list this-word 'fun nil))
7646 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7648 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7651 (defun idlwave-what-module-find-class ()
7652 "Call idlwave-what-module and find the inherited class if necessary."
7653 (let* ((module (idlwave-what-module))
7654 (class (nth 2 module))
7656 (if (and (= (length module) 3)
7660 (apply 'idlwave-find-inherited-class module))
7663 (defun idlwave-find-inherited-class (name type class)
7664 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7665 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7670 (defun idlwave-fix-module-if-obj_new (module)
7671 "Check if MODULE points to obj_new.
7672 If yes, and if the cursor is in the keyword region, change to the
7673 appropriate Init method."
7674 (let* ((name (car module))
7676 (case-fold-search t)
7678 (if (and (stringp name)
7679 (equal (downcase name) "obj_new")
7681 (idlwave-beginning-of-statement)
7682 (setq string (buffer-substring (point) pos))
7683 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7686 (class (match-string 1 string)))
7687 (setq module (list (idlwave-sintern-method "Init")
7689 (idlwave-sintern-class class)))))
7692 (defun idlwave-fix-keywords (name type class keywords
7693 &optional super-classes system)
7694 "Update a list of keywords.
7695 Translate OBJ_NEW, adding all super-class keywords, or all keywords
7696 from all classes if class equals t. If SYSTEM is non-nil, don't
7697 demand _EXTRA in the keyword list."
7698 (let ((case-fold-search t))
7700 ;; If this is the OBJ_NEW function, try to figure out the class and use
7701 ;; the keywords from the corresponding INIT method.
7702 (if (and (equal (upcase name) "OBJ_NEW")
7703 (or (eq major-mode 'idlwave-mode)
7704 (eq major-mode 'idlwave-shell-mode)))
7705 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7706 (string (buffer-substring bos (point)))
7707 (case-fold-search t)
7709 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7711 (setq class (idlwave-sintern-class (match-string 1 string)))
7712 (setq idlwave-current-obj_new-class class)
7715 (idlwave-entry-keywords
7717 (idlwave-sintern-method "INIT")
7720 (idlwave-routines)) 'do-link))))))
7722 ;; If the class is `t', combine all keywords of all methods NAME
7724 (mapc (lambda (entry)
7726 (nth 2 entry) ; non-nil class
7727 (eq (nth 1 entry) type) ; correct type
7730 (idlwave-entry-keywords entry 'do-link)))))
7731 (idlwave-all-assq name (idlwave-routines)))
7732 (setq keywords (idlwave-uniquify keywords)))
7734 ;; If we have inheritance, add all keywords from superclasses, if
7735 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
7738 idlwave-keyword-class-inheritance
7742 (assq (idlwave-sintern-keyword "_extra") keywords)
7743 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7744 ;; Check if one of the keyword-class regexps matches the name
7745 (let ((regexps idlwave-keyword-class-inheritance) re)
7747 (while (setq re (pop regexps))
7748 (if (string-match re name) (throw 'exit t))))))
7750 (loop for entry in (idlwave-routines) do
7751 (and (nth 2 entry) ; non-nil class
7752 (memq (nth 2 entry) super-classes) ; an inherited class
7753 (eq (nth 1 entry) type) ; correct type
7754 (eq (car entry) name) ; correct name
7755 (mapcar (lambda (k) (add-to-list 'keywords k))
7756 (idlwave-entry-keywords entry 'do-link))))
7757 (setq keywords (idlwave-uniquify keywords)))
7759 ;; Return the final list
7762 (defun idlwave-expand-keyword (keyword module)
7763 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
7764 KEYWORD may be an exact match or an abbreviation of a keyword.
7765 If the match is exact, KEYWORD itself is returned, even if there may be other
7766 keywords of which KEYWORD is an abbreviation. This is necessary because some
7767 system routines have keywords which are prefixes of other keywords.
7768 If KEYWORD is an abbreviation of several keywords, a list of all possible
7769 completions is returned.
7770 If the abbreviation was unique, the correct keyword is returned.
7771 If it cannot be a keyword, the function return nil.
7772 If we do not know about MODULE, just return KEYWORD literally."
7773 (let* ((name (car module))
7774 (type (nth 1 module))
7775 (class (nth 2 module))
7776 (kwd (idlwave-sintern-keyword keyword))
7777 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7778 (kwd-alist (idlwave-entry-keywords entry))
7779 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7780 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7781 (completion-ignore-case t)
7783 (cond ((assq kwd kwd-alist)
7785 ((setq candidates (all-completions kwd kwd-alist))
7786 (if (= (length candidates) 1)
7790 ;; Inheritance may cause this keyword to be correct
7793 ;; We do know the function, which does not have the keyword.
7796 ;; We do not know the function, so this just might be a correct
7797 ;; keyword - return it as it is.
7800 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7801 (defvar idlwave-rinfo-map (make-sparse-keymap))
7802 (define-key idlwave-rinfo-mouse-map
7803 (if (featurep 'xemacs) [button2] [mouse-2])
7804 'idlwave-mouse-active-rinfo)
7805 (define-key idlwave-rinfo-mouse-map
7806 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7807 'idlwave-mouse-active-rinfo-shift)
7808 (define-key idlwave-rinfo-mouse-map
7809 (if (featurep 'xemacs) [button3] [mouse-3])
7810 'idlwave-mouse-active-rinfo-right)
7811 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7812 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7813 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7814 (defvar idlwave-popup-source nil)
7815 (defvar idlwave-rinfo-marker (make-marker))
7817 (defun idlwave-quit-help ()
7819 (let ((ri-window (get-buffer-window "*Help*"))
7820 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7821 (when (and olh-window
7822 (fboundp 'idlwave-help-quit))
7823 (select-window olh-window)
7824 (idlwave-help-quit))
7825 (when (window-live-p ri-window)
7826 (delete-window ri-window))))
7828 (defun idlwave-display-calling-sequence (name type class
7829 &optional initial-class)
7830 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7831 (let* ((initial-class (or initial-class class))
7832 (entry (or (idlwave-best-rinfo-assq name type class
7834 (idlwave-rinfo-assq name type class
7835 idlwave-unresolved-routines)))
7836 (name (or (car entry) name))
7837 (class (or (nth 2 entry) class))
7838 (superclasses (idlwave-all-class-inherits initial-class))
7839 (twins (idlwave-routine-twins entry))
7840 (dtwins (idlwave-study-twins twins))
7842 (system (eq (car (nth 3 entry)) 'system))
7843 (calling-seq (nth 4 entry))
7844 (keywords (idlwave-entry-keywords entry 'do-link))
7845 (html-file (car (nth 5 entry)))
7847 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
7849 "Button2/3: Online Help")
7851 "Button2: Jump to source and back | Button3: Source in Help window.")
7853 "Button2: Display info about same method in superclass")
7855 (data (list name type class (current-buffer) nil initial-class))
7856 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7857 (face 'idlwave-help-link-face)
7858 beg props win cnt total)
7859 ;; Fix keywords, but don't add chained super-classes, since these
7860 ;; are shown separately for that super-class
7861 (setq keywords (idlwave-fix-keywords name type class keywords))
7864 (error "No %s %s known %s" type name
7865 (if initial-class (concat "in class " initial-class) "")))
7866 ((or (null name) (equal name ""))
7867 (error "No function or procedure call at point"))
7869 (error "Calling sequence of %s %s not available" type name))
7872 (move-marker idlwave-rinfo-marker (point))
7873 (set-buffer (get-buffer-create "*Help*"))
7874 (use-local-map idlwave-rinfo-map)
7875 (setq buffer-read-only nil)
7877 (set (make-local-variable 'idlwave-popup-source) nil)
7878 (set (make-local-variable 'idlwave-current-obj_new-class)
7879 idlwave-current-obj_new-class)
7881 (setq props (list 'mouse-face 'highlight
7882 km-prop idlwave-rinfo-mouse-map
7883 'help-echo help-echo-class
7884 'data (cons 'class data)))
7885 (let ((classes (cons initial-class superclasses)) c)
7886 (insert "Classes: ")
7887 (while (setq c (pop classes))
7891 (if (equal (downcase c) (downcase class))
7892 (add-text-properties beg (point) (list 'face 'bold))
7893 ;; If Method exists in a different class link it
7894 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7895 (add-text-properties beg (point) props))))
7897 (setq props (list 'mouse-face 'highlight
7898 km-prop idlwave-rinfo-mouse-map
7899 'help-echo help-echo-use
7900 'data (cons 'usage data)))
7901 (if html-file (setq props (append (list 'face face 'link html-file)
7906 (format calling-seq class name class name class name)
7907 (format calling-seq name name name name))
7909 (add-text-properties beg (point) props)
7911 (insert "Keywords:")
7913 (insert " No keywords accepted.")
7917 (if (>= (+ col 1 (length (car x)))
7924 ;; Relevant keywords already have link property attached
7925 props (list 'mouse-face 'highlight
7926 km-prop idlwave-rinfo-mouse-map
7927 'data (cons 'keyword data)
7928 'help-echo help-echo-kwd
7930 (if system (setq props (append (list 'face face) props)))
7932 (add-text-properties beg (point) props)
7933 (setq col (+ col 1 (length (car x)))))
7936 (setq cnt 1 total (length all))
7937 ;; Here entry is (key file (list of type-conses))
7938 (while (setq entry (pop all))
7939 (setq props (list 'mouse-face 'highlight
7940 km-prop idlwave-rinfo-mouse-map
7941 'help-echo help-echo-src
7942 'source (list (car (car (nth 2 entry))) ;type
7945 (cdr (car (nth 2 entry))))
7946 'data (cons 'source data)))
7947 (idlwave-insert-source-location
7950 (if (> total 1) "Sources:" "Source:")
7952 (if (> total 1) "- " ""))
7955 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7956 ;; No more source lines, please
7958 "\n Source information truncated to %d entries."
7959 idlwave-rinfo-max-source-lines))
7961 (goto-char (point-min))
7962 (setq buffer-read-only t))
7963 (display-buffer "*Help*")
7964 (if (and (setq win (get-buffer-window "*Help*"))
7965 idlwave-resize-routine-help-window)
7967 (let ((ww (selected-window)))
7971 (enlarge-window (- (/ (frame-height) 2)
7973 (shrink-window-if-larger-than-buffer))
7974 (select-window ww)))))))))
7976 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7977 "Insert a source location into the routine info buffer.
7978 Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
7980 (let* ((key (car entry))
7981 (file (nth 1 entry))
7982 (types (nth 2 entry))
7983 (shell-flag (assq 'compiled types))
7984 (buffer-flag (assq 'buffer types))
7985 (user-flag (assq 'user types))
7986 (lib-flag (assq 'lib types))
7987 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
7988 (and user-flag (idlwave-count-memq 'user types))
7989 (and lib-flag (idlwave-count-memq 'lib types))
8003 (insert "Builtin "))
8005 ((and (not file) shell-flag)
8006 (insert "Unresolved"))
8011 ((idlwave-syslib-p file)
8012 (if (string-match "obsolete" (file-name-directory file))
8013 (insert "Obsolete ")
8014 (insert "SystemLib ")))
8016 ;; New special syntax: taken directly from routine-info for
8017 ;; library catalog routines
8018 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8019 (insert (format "%-10s" special)))
8021 ;; Old special syntax: a matching regexp
8022 ((setq special (idlwave-special-lib-test file))
8023 (insert (format "%-10s" special)))
8025 ;; Catch-all with file
8026 ((idlwave-lib-p file) (insert "Library "))
8029 (t (insert "Other ")))
8034 (if lib-flag "L" "-")
8035 (if user-flag "C" "-")
8036 (if shell-flag "S" "-")
8037 (if buffer-flag "B" "-")
8041 (insert (format "(%dx) " ndupl))
8042 (add-text-properties beg (point) (list 'face 'bold)))
8043 (when (and file (not (equal file "")))
8045 (insert (apply 'abbreviate-file-name
8046 (if (featurep 'xemacs) (list file t) (list file))))
8048 (add-text-properties beg (point) file-props)))))
8050 (defun idlwave-special-lib-test (file)
8051 "Check the path of FILE against the regexps which define special libs.
8052 Return the name of the special lib if there is a match."
8053 (let ((alist idlwave-special-lib-alist)
8057 (while (setq entry (pop alist))
8058 (if (string-match (car entry) file)
8059 (setq rtn (cdr entry)
8064 (defun idlwave-mouse-active-rinfo-right (ev)
8066 (idlwave-mouse-active-rinfo ev 'right))
8068 (defun idlwave-mouse-active-rinfo-shift (ev)
8070 (idlwave-mouse-active-rinfo ev nil 'shift))
8072 (defun idlwave-active-rinfo-space ()
8074 (idlwave-mouse-active-rinfo nil 'right))
8076 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8077 "Does the mouse actions in the routine info buffer.
8078 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8081 (if ev (mouse-set-point ev))
8082 (let (data id name type class buf bufwin source link keyword
8084 (setq data (get-text-property (point) 'data)
8085 source (get-text-property (point) 'source)
8086 keyword (get-text-property (point) 'keyword)
8087 link (get-text-property (point) 'link)
8089 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8091 initial-class (nth 6 data)
8092 word (idlwave-this-word)
8093 bufwin (get-buffer-window buf t))
8095 (cond ((eq id 'class) ; Switch class being displayed
8096 (if (window-live-p bufwin) (select-window bufwin))
8097 (idlwave-display-calling-sequence
8098 (idlwave-sintern-method name)
8099 type (idlwave-sintern-class word)
8101 ((eq id 'usage) ; Online help on this routine
8102 (idlwave-online-help link name type class))
8103 ((eq id 'source) ; Source in help or buffer
8105 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8106 (idlwave-help-source-try-header nil)
8107 ;; Fake idlwave-routines so help will find the right entry
8109 (list (list name type class source ""))))
8110 (idlwave-help-get-special-help name type class nil))
8111 ;; Otherwise just pop to the source
8112 (setq idlwave-popup-source (not idlwave-popup-source))
8113 (if idlwave-popup-source
8115 (idlwave-do-find-module name type class source)
8117 (setq idlwave-popup-source nil)
8118 (if (window-live-p bufwin) (select-window bufwin))
8119 (error (nth 1 err))))
8121 (select-window bufwin)
8122 (pop-to-buffer buf))
8123 (goto-char (marker-position idlwave-rinfo-marker)))))
8126 (idlwave-online-help link name type class keyword)
8127 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8129 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8130 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8131 (let ((bwin (get-buffer-window buffer)))
8132 (if idlwave-complete-empty-string-as-lower-case
8133 (setq keyword (downcase keyword)))
8135 (select-window bwin)
8136 (pop-to-buffer buffer)
8137 (setq bwin (get-buffer-window buffer)))
8138 (if (eq (preceding-char) ?/)
8140 (unless (save-excursion
8142 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8143 (min (- (point) 100) (point-min)) t))
8145 (if shift (insert "/"))
8147 (if (and (not shift)
8148 idlwave-keyword-completion-adds-equal)
8151 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8152 "List the load path shadows of all routines defined in current buffer."
8155 (if (eq major-mode 'idlwave-mode)
8156 (idlwave-list-load-path-shadows
8157 nil (idlwave-update-current-buffer-info 'save-buffer)
8158 "in current buffer")
8159 (error "Current buffer is not in idlwave-mode")))
8161 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8162 "List the load path shadows of all routines compiled under the shell.
8163 This is very useful for checking an IDL application. Just compile the
8164 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8165 routines and update IDLWAVE internal info. Then check for shadowing
8169 ((or (not (fboundp 'idlwave-shell-is-running))
8170 (not (idlwave-shell-is-running)))
8171 (error "Shell is not running"))
8172 ((null idlwave-compiled-routines)
8173 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8175 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8178 (defun idlwave-list-all-load-path-shadows (&optional arg)
8179 "List the load path shadows of all routines known to IDLWAVE."
8181 (idlwave-list-load-path-shadows nil nil "globally"))
8183 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8184 "List the routines which are defined multiple times.
8185 Search the information IDLWAVE has about IDL routines for multiple
8187 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8189 When IDL hits a routine call which is not defined, it will search on
8190 the load path in order to find a definition. The output of this
8191 command can be used to detect possible name clashes during this process."
8192 (idlwave-routines) ; Make sure everything is loaded.
8193 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8195 "You don't have any user or library catalogs. Continue anyway? ")
8197 (let* ((routines (append idlwave-system-routines
8198 idlwave-compiled-routines
8199 idlwave-library-catalog-routines
8200 idlwave-user-catalog-routines
8201 idlwave-buffer-routines
8203 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8204 (keymap (make-sparse-keymap))
8205 (props (list 'mouse-face 'highlight
8207 'help-echo "Mouse2: Find source"))
8208 (nroutines (length (or special-routines routines)))
8209 (step (/ nroutines 99))
8213 (idlwave-sort-prefer-buffer-info nil)
8214 routine twins dtwins twin done props1 lroutines)
8216 (if special-routines
8217 ;; Just looking for shadows of a few special routines
8218 (setq lroutines routines
8219 routines special-routines))
8221 (message "Sorting routines...")
8222 (setq routines (sort routines
8224 (string< (downcase (idlwave-make-full-name
8226 (downcase (idlwave-make-full-name
8227 (nth 2 b) (car b)))))))
8228 (message "Sorting routines...done")
8230 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8233 (mouse-set-point ev)
8234 (apply 'idlwave-do-find-module
8235 (get-text-property (point) 'find-args))))
8236 (define-key keymap [(return)]
8239 (apply 'idlwave-do-find-module
8240 (get-text-property (point) 'find-args))))
8241 (message "Compiling list...( 0%%)")
8243 (set-buffer (get-buffer-create "*Shadows*"))
8244 (setq buffer-read-only nil)
8246 (while (setq routine (pop routines))
8248 (if (= (* next-perc step) n)
8250 (message "Compiling list...(%2d%%)" next-perc)
8251 (setq next-perc (1+ next-perc))))
8252 ;; Get a list of all twins
8253 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8254 (if (memq routine done)
8256 (setq dtwins (idlwave-study-twins twins)))
8257 ;; Mark all twins as dealt with
8258 (setq done (append twins done))
8259 (when (or (> (length dtwins) 1)
8260 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8261 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8262 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8264 (insert (format "\n%s%s"
8265 (idlwave-make-full-name (nth 2 routine)
8267 (if (eq (nth 1 routine) 'fun) "()" "")))
8268 (while (setq twin (pop dtwins))
8269 (setq props1 (append (list 'find-args
8270 (list (nth 0 routine)
8274 (idlwave-insert-source-location "\n - " twin props1))))
8275 (goto-char (point-min))
8276 (setq buffer-read-only t))
8277 (setq loc (or loc ""))
8280 (display-buffer (get-buffer "*Shadows*"))
8281 (message "%d case%s of shadowing found %s"
8282 cnt (if (= cnt 1) "" "s") loc))
8283 (message "No shadowing conflicts found %s" loc))))
8285 (defun idlwave-print-source (routine)
8286 (let* ((source (nth 3 routine))
8287 (stype (car source))
8288 (sfile (idlwave-routine-source-file source)))
8289 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8290 (if (and (eq stype 'compiled)
8291 (or (not (stringp sfile))
8292 (not (string-match "\\S-" sfile))))
8293 (setq stype 'unresolved))
8294 (princ (format " %-10s %s\n"
8296 (if sfile sfile "No source code available")))))
8298 (defun idlwave-routine-twins (entry &optional list)
8299 "Return all twin entries of ENTRY in LIST.
8300 LIST defaults to `idlwave-routines'.
8301 Twin entries are those which have the same name, type, and class.
8302 ENTRY will also be returned, as the first item of this list."
8303 (let* ((name (car entry))
8304 (type (nth 1 entry))
8305 (class (nth 2 entry))
8306 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8308 (while (setq candidate (pop candidates))
8309 (if (and (not (eq candidate entry))
8310 (eq type (nth 1 candidate))
8311 (eq class (nth 2 candidate)))
8312 (push candidate twins)))
8313 (if (setq candidate (idlwave-rinfo-assq name type class
8314 idlwave-unresolved-routines))
8315 (push candidate twins))
8316 (cons entry (nreverse twins))))
8318 (defun idlwave-study-twins (entries)
8319 "Return dangerous twins of first entry in ENTRIES.
8320 Dangerous twins are routines with same name, but in different files on
8321 the load path. If a file is in the system library and has an entry in
8322 the `idlwave-system-routines' list, we omit the latter as
8323 non-dangerous because many IDL routines are implemented as library
8324 routines, and may have been scanned."
8325 (let* ((entry (car entries))
8326 (name (car entry)) ;
8327 (type (nth 1 entry)) ; Must be bound for
8328 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8330 source type type-cons file alist syslibp key)
8331 (while (setq entry (pop entries))
8333 (setq source (nth 3 entry)
8335 type-cons (cons type (nth 3 source))
8336 file (idlwave-routine-source-file source))
8338 ;; Make KEY to index entry properly
8339 (setq key (cond ((eq type 'system) type)
8340 (file (file-truename file))
8343 ;; Check for an entry in the system library
8346 (idlwave-syslib-p file))
8349 ;; If there's more than one matching entry for the same file, just
8350 ;; append the type-cons to the type list.
8351 (if (setq entry (assoc key alist))
8352 (push type-cons (nth 2 entry))
8353 (push (list key file (list type-cons)) alist)))
8355 (setq alist (nreverse alist))
8358 ;; File is in system *library* - remove any 'system entry
8359 (setq alist (delq (assq 'system alist) alist)))
8361 ;; If 'system remains and we've scanned the syslib, it's a builtin
8362 ;; (rather than a !DIR/lib/.pro file bundled as source).
8363 (when (and (idlwave-syslib-scanned-p)
8364 (setq entry (assoc 'system alist)))
8365 (setcar entry 'builtin))
8366 (sort alist 'idlwave-routine-twin-compare)))
8370 (defvar idlwave-sort-prefer-buffer-info t
8371 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8373 (defmacro idlwave-xor (a b)
8377 (defun idlwave-routine-entry-compare (a b)
8378 "Compare two routine info entries for sortiung. This is the general case.
8379 It first compates class, names, and type. If it turns out that A and B
8380 are twins (same name, class, and type), calls another routine which
8381 compares twins on the basis of their file names and path locations."
8382 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8384 ((not (equal (idlwave-downcase-safe class)
8385 (idlwave-downcase-safe (nth 2 b))))
8387 (cond ((null (nth 2 b)) nil)
8389 (t (string< (downcase class) (downcase (nth 2 b))))))
8390 ((not (equal (downcase name) (downcase (car b))))
8392 (string< (downcase name) (downcase (car b))))
8393 ((not (eq type (nth 1 b)))
8395 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8397 ;; A and B are twins - so the decision is more complicated.
8398 ;; Call twin-compare with the proper arguments.
8399 (idlwave-routine-entry-compare-twins a b)))))
8401 (defun idlwave-routine-entry-compare-twins (a b)
8402 "Compare two routine entries, under the assumption that they are
8403 twins. This basically calls `idlwave-routine-twin-compare' with the
8405 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8410 (afile (idlwave-routine-source-file asrc))
8411 (bfile (idlwave-routine-source-file bsrc)))
8412 (idlwave-routine-twin-compare
8414 (list (file-truename afile) afile (list atype))
8415 (list atype afile (list atype)))
8417 (list (file-truename bfile) bfile (list btype))
8418 (list btype bfile (list btype))))
8421 (defun idlwave-routine-twin-compare (a b)
8422 "Compare two routine twin entries for sorting.
8423 In here, A and B are not normal routine info entries, but special
8424 lists (KEY FILENAME (TYPES...)).
8425 This expects NAME TYPE CLASS to be bound to the right values."
8426 (let* (;; Dis-assemble entries
8427 (akey (car a)) (bkey (car b))
8428 (afile (nth 1 a)) (bfile (nth 1 b))
8429 (atypes (nth 2 a)) (btypes (nth 2 b))
8431 (asysp (memq akey '(builtin system)))
8432 (bsysp (memq bkey '(builtin system)))
8433 ;; Compiled routines?
8434 (acompp (memq 'compiled atypes))
8435 (bcompp (memq 'compiled btypes))
8437 (aunresp (or (eq akey 'unresolved)
8438 (and acompp (not afile))))
8439 (bunresp (or (eq bkey 'unresolved)
8440 (and bcompp (not bfile))))
8441 ;; Buffer info available?
8442 (abufp (memq 'buffer atypes))
8443 (bbufp (memq 'buffer btypes))
8445 (tpath-alist (idlwave-true-path-alist))
8446 (apathp (and (stringp akey)
8447 (assoc (file-name-directory akey) tpath-alist)))
8448 (bpathp (and (stringp bkey)
8449 (assoc (file-name-directory bkey) tpath-alist)))
8450 ;; How early on search path? High number means early since we
8451 ;; measure the tail of the path list
8452 (anpath (length (memq apathp tpath-alist)))
8453 (bnpath (length (memq bpathp tpath-alist)))
8454 ;; Look at file names
8455 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8456 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8457 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8458 (regexp-quote (downcase class))
8459 (regexp-quote (downcase name)))
8460 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8461 ;; Is file name derived from the routine name?
8462 ;; Method file or class definition file?
8463 (anamep (string-match fname-re aname))
8464 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8465 (bnamep (string-match fname-re bname))
8466 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8468 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8469 ;; doesn't it? The difficult stuff is hidden above...
8471 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8472 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8473 ((and idlwave-sort-prefer-buffer-info
8474 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8475 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8476 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8477 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8478 ((and class anamep bnamep ; both file names match ->
8479 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8480 ((> anpath bnpath) t) ; Who is first on path?
8481 (t nil)))) ; Default
8483 (defun idlwave-routine-source-file (source)
8485 (expand-file-name (nth 1 source) (nth 2 source))
8488 (defun idlwave-downcase-safe (string)
8489 "Donwcase if string, else return unchanged."
8490 (if (stringp string)
8494 (defun idlwave-count-eq (elt list)
8495 "How often is ELT in LIST?"
8496 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8498 (defun idlwave-count-memq (elt alist)
8499 "How often is ELT a key in ALIST?"
8500 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8502 (defun idlwave-syslib-p (file)
8503 "Non-nil if FILE is in the system library."
8504 (let* ((true-syslib (file-name-as-directory
8506 (expand-file-name "lib" (idlwave-sys-dir)))))
8507 (true-file (file-truename file)))
8508 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8510 (defun idlwave-lib-p (file)
8511 "Non-nil if file is in the library"
8512 (let ((true-dir (file-name-directory (file-truename file))))
8513 (assoc true-dir (idlwave-true-path-alist))))
8515 (defun idlwave-path-alist-add-flag (list-entry flag)
8516 "Add a flag to the path list entry, if not set."
8517 (let ((flags (cdr list-entry)))
8518 (add-to-list 'flags flag)
8519 (setcdr list-entry flags)))
8521 (defun idlwave-path-alist-remove-flag (list-entry flag)
8522 "Remove a flag to the path list entry, if set."
8523 (let ((flags (delq flag (cdr list-entry))))
8524 (setcdr list-entry flags)))
8526 (defun idlwave-true-path-alist ()
8527 "Return `idlwave-path-alist' alist with true-names.
8528 Info is cached, but relies on the functions setting `idlwave-path-alist'
8529 to reset the variable `idlwave-true-path-alist' to nil."
8530 (or idlwave-true-path-alist
8531 (setq idlwave-true-path-alist
8532 (mapcar (lambda(x) (cons
8533 (file-name-as-directory
8535 (directory-file-name
8538 idlwave-path-alist))))
8540 (defun idlwave-syslib-scanned-p ()
8541 "Non-nil if the system lib file !DIR/lib has been scanned."
8542 (let* ((true-syslib (file-name-as-directory
8544 (expand-file-name "lib" (idlwave-sys-dir))))))
8545 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8547 ;; ----------------------------------------------------------------------------
8549 ;; Online Help display
8552 ;; ----------------------------------------------------------------------------
8554 ;; Additions for use with imenu.el and func-menu.el
8555 ;; (pop-up a list of IDL units in the current file).
8558 (defun idlwave-prev-index-position ()
8559 "Search for the previous procedure or function.
8560 Return nil if not found. For use with imenu.el."
8563 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
8564 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
8567 (defun idlwave-unit-name ()
8568 "Return the unit name.
8569 Assumes that point is at the beginning of the unit as found by
8570 `idlwave-prev-index-position'."
8573 (let ((begin (point)))
8575 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
8576 (if (fboundp 'buffer-substring-no-properties)
8577 (buffer-substring-no-properties begin (point))
8578 (buffer-substring begin (point)))))
8580 (defalias 'idlwave-function-menu
8583 (require 'func-menu)
8585 (error (condition-case nil
8591 ;; Here we hack func-menu.el in order to support this new mode.
8592 ;; The latest versions of func-menu.el already have this stuff in, so
8593 ;; we hack only if it is not already there.
8594 (when (fboundp 'eval-after-load)
8595 (eval-after-load "func-menu"
8597 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
8598 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
8599 (setq fume-function-name-regexp-alist
8600 (cons '(idlwave-mode . fume-function-name-regexp-idl)
8601 fume-function-name-regexp-alist)))
8602 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
8603 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
8604 (setq fume-find-function-name-method-alist
8605 (cons '(idlwave-mode . fume-find-next-idl-function-name)
8606 fume-find-function-name-method-alist))))))
8608 (defun idlwave-edit-in-idlde ()
8609 "Edit the current file in IDL Development environment."
8611 (start-process "idldeclient" nil
8612 idlwave-shell-explicit-file-name "-c" "-e"
8613 (buffer-file-name) "&"))
8615 (defun idlwave-launch-idlhelp ()
8616 "Start the IDLhelp application."
8618 (start-process "idlhelp" nil idlwave-help-application))
8620 ;; Menus - using easymenu.el
8621 (defvar idlwave-mode-menu-def
8623 ["PRO/FUNC menu" idlwave-function-menu t]
8625 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8626 ["Subprogram End" idlwave-end-of-subprogram t]
8627 ["Block Start" idlwave-beginning-of-block t]
8628 ["Block End" idlwave-end-of-block t]
8629 ["Up Block" idlwave-backward-up-block t]
8630 ["Down Block" idlwave-down-block t]
8631 ["Skip Block Backward" idlwave-backward-block t]
8632 ["Skip Block Forward" idlwave-forward-block t])
8634 ["Subprogram" idlwave-mark-subprogram t]
8635 ["Block" idlwave-mark-block t]
8636 ["Header" idlwave-mark-doclib t])
8638 ["Indent Subprogram" idlwave-indent-subprogram t]
8639 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8640 ["Continue/Split line" idlwave-split-line t]
8642 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8643 :selected (symbol-value idlwave-fill-function)])
8645 ["Procedure" idlwave-procedure t]
8646 ["Function" idlwave-function t]
8647 ["Doc Header" idlwave-doc-header t]
8648 ["Log" idlwave-doc-modification t]
8650 ["Case" idlwave-case t]
8651 ["For" idlwave-for t]
8652 ["Repeat" idlwave-repeat t]
8653 ["While" idlwave-while t]
8655 ["Close Block" idlwave-close-block t])
8657 ["Complete" idlwave-complete t]
8659 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8660 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8662 ["3 Function Name" (idlwave-complete 'function) t]
8663 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8665 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8666 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8668 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8669 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8671 ["9 Class Name" idlwave-complete-class t]))
8673 ["Show Routine Info" idlwave-routine-info t]
8674 ["Online Context Help" idlwave-context-help t]
8676 ["Find Routine Source" idlwave-find-module t]
8677 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8679 ["Update Routine Info" idlwave-update-routine-info t]
8682 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
8683 ["Scan Directories" (idlwave-update-routine-info '(16))
8684 (and idlwave-path-alist (not idlwave-catalog-process))]
8685 ["Scan Directories &" (idlwave-update-routine-info '(64))
8686 (and idlwave-path-alist (not idlwave-catalog-process))]
8689 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8690 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8691 ["Check Everything" idlwave-list-all-load-path-shadows t])
8693 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8695 ["Insert TAB character" idlwave-hard-tab t])
8698 ["Generate IDL tags" idlwave-make-tags t]
8699 ["Start IDL shell" idlwave-shell t]
8700 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8701 ["Launch IDL Help" idlwave-launch-idlhelp t])
8704 ["Browse IDLWAVE Group" idlwave-customize t]
8706 ["Build Full Customize Menu" idlwave-create-customize-menu
8707 (fboundp 'customize-menu-create)])
8709 ["Describe Mode" describe-mode t]
8710 ["Abbreviation List" idlwave-list-abbrevs t]
8712 ["Commentary in idlwave.el" idlwave-show-commentary t]
8713 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8715 ["Info" idlwave-info t]
8717 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8719 (defvar idlwave-mode-debug-menu-def
8721 ["Start IDL shell" idlwave-shell t]
8722 ["Save and .RUN buffer" idlwave-shell-save-and-run
8723 (and (boundp 'idlwave-shell-automatic-start)
8724 idlwave-shell-automatic-start)]))
8726 (if (or (featurep 'easymenu) (load "easymenu" t))
8728 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8729 "IDL and WAVE CL editing menu"
8730 idlwave-mode-menu-def)
8731 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8732 "IDL and WAVE CL editing menu"
8733 idlwave-mode-debug-menu-def)))
8735 (defun idlwave-customize ()
8736 "Call the customize function with idlwave as argument."
8738 ;; Try to load the code for the shell, so that we can customize it
8740 (or (featurep 'idlw-shell)
8741 (load "idlw-shell" t))
8742 (customize-browse 'idlwave))
8744 (defun idlwave-create-customize-menu ()
8745 "Create a full customization menu for IDLWAVE, insert it into the menu."
8747 (if (fboundp 'customize-menu-create)
8749 ;; Try to load the code for the shell, so that we can customize it
8751 (or (featurep 'idlw-shell)
8752 (load "idlw-shell" t))
8754 '("IDLWAVE") "Customize"
8755 `(["Browse IDLWAVE group" idlwave-customize t]
8757 ,(customize-menu-create 'idlwave)
8758 ["Set" Custom-set t]
8759 ["Save" Custom-save t]
8760 ["Reset to Current" Custom-reset-current t]
8761 ["Reset to Saved" Custom-reset-saved t]
8762 ["Reset to Standard Settings" Custom-reset-standard t]))
8763 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8764 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8766 (defun idlwave-show-commentary ()
8767 "Use the finder to view the file documentation from `idlwave.el'."
8770 (finder-commentary "idlwave.el"))
8772 (defun idlwave-shell-show-commentary ()
8773 "Use the finder to view the file documentation from `idlw-shell.el'."
8776 (finder-commentary "idlw-shell.el"))
8778 (defun idlwave-info ()
8779 "Read documentation for IDLWAVE in the info system."
8782 (Info-goto-node "(idlwave)"))
8784 (defun idlwave-list-abbrevs (arg)
8785 "Show the code abbreviations define in IDLWAVE mode.
8786 This lists all abbrevs where the replacement text differs from the input text.
8787 These are the ones the users want to learn to speed up their writing.
8789 The function does *not* list abbrevs which replace a word with itself
8790 to call a hook. These hooks are used to change the case of words or
8791 to blink the matching `begin', and the user does not need to know them.
8793 With arg, list all abbrevs with the corresponding hook.
8795 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8798 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8800 str rpl func fmt (len-str 0) (len-rpl 0))
8803 (if (symbol-value sym)
8805 (setq str (symbol-name sym)
8806 rpl (symbol-value sym)
8807 func (symbol-function sym))
8809 (setq func (prin1-to-string func))
8810 (if (and (listp func) (stringp (nth 2 func)))
8811 (setq rpl (concat "EVAL: " (nth 2 func))
8814 (if (or arg (not (string= rpl str)))
8816 (setq len-str (max len-str (length str)))
8817 (setq len-rpl (max len-rpl (length rpl)))
8818 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8821 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8823 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8824 (with-output-to-temp-buffer "*Help*"
8827 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8828 (princ "=========================================\n\n")
8829 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8830 (princ (format fmt "---" "-------" "----")))
8831 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8832 (princ "================================================\n\n")
8833 (princ (format fmt "KEY" "ACTION" ""))
8834 (princ (format fmt "---" "------" "")))
8837 (setq str (car list)
8840 (princ (format fmt str rpl func)))
8842 ;; Make sure each abbreviation uses only one display line
8844 (set-buffer "*Help*")
8845 (setq truncate-lines t)))
8847 ;; Add .pro files to speedbar for support, if it's loaded
8848 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8850 ;; Set an idle timer to load the routine info.
8851 ;; Will only work on systems which support this.
8852 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8854 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
8857 (run-hooks 'idlwave-load-hook)
8861 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
8862 ;;; idlwave.el ends here