1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009 Free Software Foundation, Inc.
6 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Carsten Dominik <dominik@science.uva.nl>
8 ;; Chris Chase <chase@att.com>
9 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
11 ;; Keywords: languages
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;; IDLWAVE enables feature-rich development and interaction with IDL,
31 ;; the Interactive Data Language. It provides a compelling,
32 ;; full-featured alternative to the IDLDE development environment
35 ;; In the remotely distant past, based on pascal.el, though bears
36 ;; little resemblance to it now.
38 ;; Incorporates many ideas, such as abbrevs, action routines, and
39 ;; continuation line indenting, from wave.el.
40 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
42 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
43 ;; for features, key bindings, and info.
44 ;; Also, Info format documentation is available with `M-x idlwave-info'
46 ;; New versions of IDLWAVE, documentation, and more information
53 ;; Follow the instructions in the INSTALL file of the distribution.
54 ;; In short, put this file on your load path and add the following
55 ;; lines to your .emacs file:
57 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
58 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
59 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
65 ;; The newest version of this file is available from the maintainer's
73 ;; IDLWAVE is documented online in info format. A printable version
74 ;; of the documentation is available from the maintainers webpage (see
81 ;; Thanks to the following people for their contributions and comments:
83 ;; Ulrik Dickow <dickow_at_nbi.dk>
84 ;; Eric E. Dors <edors_at_lanl.gov>
85 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
86 ;; David Huenemoerder <dph_at_space.mit.edu>
87 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
88 ;; Dick Jackson <dick_at_d-jackson.com>
89 ;; Xuyong Liu <liu_at_stsci.edu>
90 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
91 ;; Laurent Mugnier <mugnier_at_onera.fr>
92 ;; Lubos Pochman <lubos_at_rsinc.com>
93 ;; Bob Portmann <portmann_at_al.noaa.gov>
94 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
95 ;; Marty Ryba <ryba_at_ll.mit.edu>
96 ;; Paul Sorenson <aardvark62_at_msn.com>
97 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
98 ;; Phil Williams <williams_at_irc.chmcc.org>
103 ;; IDLWAVE has extensive customize support; to learn about the
104 ;; variables which control the mode's behavior, use `M-x
105 ;; idlwave-customize'.
107 ;; You can set your own preferred values with Customize, or with Lisp
108 ;; code in .emacs. For an example of what to put into .emacs, check
109 ;; the TexInfo documentation or see a complete .emacs available at the
115 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
116 ;; Numerics, Inc. is growing less and less complete as the two
117 ;; languages grow increasingly apart. The mode probably shouldn't
118 ;; even have "WAVE" in its title, but it's catchy, and was required
119 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
121 ;; Moving the point backwards in conjunction with abbrev expansion
122 ;; does not work as I would like it, but this is a problem with
123 ;; emacs abbrev expansion done by the self-insert-command. It ends
124 ;; up inserting the character that expanded the abbrev after moving
125 ;; point backward, e.g., "\cl" expanded with a space becomes
126 ;; "LONG( )" with point before the close paren. This is solved by
127 ;; using a temporary function in `post-command-hook' - not pretty,
130 ;; Tabs and spaces are treated equally as whitespace when filling a
131 ;; comment paragraph. To accomplish this, tabs are permanently
132 ;; replaced by spaces in the text surrounding the paragraph, which
133 ;; may be an undesirable side-effect. Replacing tabs with spaces is
134 ;; limited to comments only and occurs only when a comment
135 ;; paragraph is filled via `idlwave-fill-paragraph'.
137 ;; Muti-statement lines (using "&") on block begin and end lines can
138 ;; ruin the formatting. For example, multiple end statements on a
139 ;; line: endif & endif. Using "&" outside of block begin/end lines
142 ;; Determining the expression at point for printing and other
143 ;; examination commands is somewhat rough: currently only fairly
144 ;; simple entities are found. You can always drag-select or examine
145 ;; a pre-selected region.
147 ;; When forcing completion of method keywords, the initial
148 ;; query for a method has multiple entries for some methods. Would
149 ;; be too difficult to fix this hardly used case.
155 (eval-when-compile (require 'cl
))
159 (unless (fboundp 'line-beginning-position
)
160 (defalias 'line-beginning-position
'point-at-bol
))
161 (unless (fboundp 'line-end-position
)
162 (defalias 'line-end-position
'point-at-eol
))
163 (unless (fboundp 'char-valid-p
)
164 (defalias 'char-valid-p
'characterp
))
165 (unless (fboundp 'match-string-no-properties
)
166 (defalias 'match-string-no-properties
'match-string
))
168 (if (not (fboundp 'cancel-timer
))
173 (declare-function idlwave-shell-get-path-info
"idlw-shell")
174 (declare-function idlwave-shell-temp-file
"idlw-shell")
175 (declare-function idlwave-shell-is-running
"idlw-shell")
176 (declare-function widget-value
"wid-edit" (widget))
177 (declare-function comint-dynamic-complete-filename
"comint" ())
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
2
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
3
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 -
3
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
3
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
40
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 parenthesis.
241 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 `idlwave-max-extra-continuation-indent', which, if zero,
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
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 a long time, in particular if a
359 large number of library catalogs are involved. When Emacs is idle for
360 more than the number of seconds specified by this variable, it starts
361 the initialization. The process is split into five steps, in order to
362 keep work interruption as short as possible. If one of the steps
363 finishes, and no user input has arrived in the mean time, initialization
364 proceeds immediately to the next step. A good value for this variable
365 is about 1/3 of the time initialization take in your setup. So if you
366 have a fast machine and no problems with a slow network connection,
367 don't hesitate to set this to 2 seconds. A value of 0 means, don't
368 initialize automatically, but instead wait until routine information is
369 needed, and initialize then."
370 :group
'idlwave-routine-info
373 (defcustom idlwave-scan-all-buffers-for-routine-info t
374 "*Non-nil means, scan buffers for IDL programs when updating info.
375 The scanning is done by the command `idlwave-update-routine-info'.
376 The following values are allowed:
378 nil Don't scan any buffers.
379 t Scan all `idlwave-mode' buffers in the current editing session.
380 current Scan only the current buffer, but no other buffers."
381 :group
'idlwave-routine-info
383 (const :tag
"No buffer" nil
)
384 (const :tag
"All buffers" t
)
385 (const :tag
"Current buffer only" 'current
)))
387 (defcustom idlwave-query-shell-for-routine-info t
388 "*Non-nil means query the shell for info about compiled routines.
389 Querying the shell is useful to get information about compiled modules,
390 and it is turned on by default. However, when you have a complete library
391 scan, this is not necessary."
392 :group
'idlwave-routine-info
395 (defcustom idlwave-auto-routine-info-updates
396 '(find-file save-buffer kill-buffer compile-buffer
)
397 "*Controls under what circumstances routine info is updated automatically.
401 \(...) A list of circumstances. Allowed members are:
402 find-file Add info for new IDLWAVE buffers.
403 save-buffer Update buffer info when buffer is saved
404 kill-buffer Remove buffer info when buffer gets killed
405 compile-buffer Update shell info after `idlwave-shell-save-and...'"
406 :group
'idlwave-routine-info
408 (const :tag
"Never" nil
)
409 (const :tag
"As often as possible" t
)
410 (set :tag
"Checklist" :greedy t
411 (const :tag
"When visiting a file" find-file
)
412 (const :tag
"When saving a buffer" save-buffer
)
413 (const :tag
"After a buffer was killed" kill-buffer
)
414 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
416 (defcustom idlwave-rinfo-max-source-lines
5
417 "*Maximum number of source files displayed in the Routine Info window.
418 When an integer, it is the maximum number of source files displayed.
419 A value of t means to show all source files."
420 :group
'idlwave-routine-info
423 (defcustom idlwave-library-path nil
424 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
425 When selecting the directories to scan for IDL user catalog routine
426 info, IDLWAVE can, under UNIX, query the shell for the exact search
427 path \(the value of !PATH). However, under Windows and MacOS
428 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
429 variable can be set to specify the paths where IDLWAVE can find PRO
430 files. The shell will only be asked for a list of paths when this
431 variable is nil. The value is a list of directories. A directory
432 preceeded by a `+' will be searched recursively. If you set this
433 variable on a UNIX system, the shell will not be queried. See also
434 `idlwave-system-directory'."
435 :group
'idlwave-routine-info
436 :type
'(repeat (directory)))
438 (defcustom idlwave-system-directory
""
439 "The IDL system directory for Windows and MacOS. Not needed under
440 UNIX. Set this to the value of the `!DIR' system variable in IDL.
441 IDLWAVE uses this to find out which of the library routines belong to
442 the official system library. All files inside the `lib' subdirectory
443 are considered system library files - so don't install private stuff
444 in this directory. On UNIX systems, IDLWAVE queries the shell for the
445 value of `!DIR'. See also `idlwave-library-path'."
446 :group
'idlwave-routine-info
449 ;; Configuration files
450 (defcustom idlwave-config-directory
451 (convert-standard-filename "~/.idlwave")
452 "*Directory for configuration files and user-library catalog."
453 :group
'idlwave-routine-info
456 (defvar idlwave-user-catalog-file
"idlusercat.el")
457 (defvar idlwave-xml-system-rinfo-converted-file
"idl_xml_rinfo.el")
458 (defvar idlwave-path-file
"idlpath.el")
460 (defvar idlwave-libinfo-file nil
461 "*Obsolete variable, no longer used.")
463 (defcustom idlwave-special-lib-alist nil
464 "Alist of regular expressions matching special library directories.
465 When listing routine source locations, IDLWAVE gives a short hint where
466 the file defining the routine is located. By default it lists `SystemLib'
467 for routines in the system library `!DIR/lib' and `Library' for anything
468 else. This variable can define additional types. The car of each entry
469 is a regular expression matching the file name (they normally will match
470 on the path). The cdr is the string to be used as identifier. Max 10
472 :group
'idlwave-routine-info
474 (cons regexp string
)))
476 (defcustom idlwave-auto-write-paths t
477 "Write out path (!PATH) and system directory (!DIR) info automatically.
478 Path info is needed to locate library catalog files. If non-nil,
479 whenever the path-list changes as a result of shell-query, etc., it is
480 written to file. Otherwise, the menu option \"Write Paths\" can be
481 used to force a write."
482 :group
'idlwave-routine-info
485 (defgroup idlwave-completion nil
486 "Completion options for IDLWAVE mode."
491 (defconst idlwave-tmp
492 '(choice :tag
"by applying the function"
497 (symbol :tag
"Other"))))
499 (defcustom idlwave-completion-case
'((routine . upcase
)
503 "Association list setting the case of completed words.
505 This variable determines the case (UPPER/lower/Capitalized...) of
506 words inserted into the buffer by completion. The preferred case can
507 be specified separately for routine names, keywords, classes and
509 This alist should therefore have entries for `routine' (normal
510 functions and procedures, i.e. non-methods), `keyword', `class', and
511 `method'. Plausible values are
513 upcase upcase whole word, like `BOX_CURSOR'
514 downcase downcase whole word, like `read_ppm'
515 capitalize capitalize each part, like `Widget_Control'
516 preserve preserve case as is, like `IDLgrView'
518 The value can also be any Emacs Lisp function which transforms the
519 case of characters in a string.
521 A value of `preserve' means that the case of the completed word is
522 identical to the way it was written in the definition statement of the
523 routine. This was implemented to allow for mixed-case completion, in
524 particular of object classes and methods.
525 If a completable word is defined in multiple locations, the meaning of
526 `preserve' is not unique since the different definitions might be
527 cased differently. Therefore IDLWAVE always takes the case of the
528 *first* definition it encounters during routine info collection and
529 uses the case derived from it consistently.
531 Note that a lowercase-only string in the buffer will always be completed in
532 lower case (but see the variable `idlwave-completion-force-default-case').
534 After changing this variable, you need to either restart Emacs or press
535 `C-u C-c C-i' to update the internal lists."
536 :group
'idlwave-completion
538 (cons (symbol :tag
"Derive completion case for")
541 (defcustom idlwave-completion-force-default-case nil
542 "*Non-nil means, completion will always honor `idlwave-completion-case'.
543 When nil, only the completion of a mixed case or upper case string
544 will honor the default settings in `idlwave-completion-case', while
545 the completion of lower case strings will be completed entirely in
547 :group
'idlwave-completion
550 (defcustom idlwave-complete-empty-string-as-lower-case nil
551 "*Non-nil means, the empty string is considered downcase for completion.
552 The case of what is already in the buffer determines the case of completions.
553 When this variable is non-nil, the empty string is considered to be downcase.
554 Completing on the empty string then offers downcase versions of the possible
556 :group
'idlwave-completion
559 (defvar idlwave-default-completion-case-is-down nil
560 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
561 `idlwave-completion-case'.")
563 (defcustom idlwave-buffer-case-takes-precedence nil
564 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
565 To make this possible, we need to re-case everything each time we update
566 the routine info from the buffers. This is slow.
567 The default is to consider the case given in the system and library files
568 first which makes updating much faster."
569 :group
'idlwave-completion
572 (defcustom idlwave-highlight-help-links-in-completion t
573 "*Non-nil means, highlight completions for which system help is available.
574 Help can then be accessed with mouse-3.
575 This option is only effective when the online help system is installed."
576 :group
'idlwave-completion
579 (defcustom idlwave-support-inheritance t
580 "Non-nil means, treat inheritance with completion, online help etc.
581 When nil, IDLWAVE only knows about the native methods and tags of a class,
582 not about inherited ones."
583 :group
'idlwave-routine-info
586 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
587 "List of regular expressions for class-driven keyword inheritance.
588 Keyword inheritance is often tied to class inheritance by \"chaining\"
589 up the class tree. While it cannot be assumed that the presence of an
590 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
591 certain methods this assumption is almost always true. The methods
592 for which to assume this can be set here."
593 :group
'idlwave-routine-info
594 :type
'(repeat (regexp :tag
"Match method:")))
597 (defcustom idlwave-completion-show-classes
1
598 "*Number of classes to show when completing object methods and keywords.
599 When completing methods or keywords for an object with unknown class,
600 the *Completions* buffer will show the valid classes for each completion
603 MyMethod <Class1,Class2,Class3>
605 The value of this variable may be nil to inhibit display, or an integer to
606 indicate the maximum number of classes to display.
608 On XEmacs, a full list of classes will also be placed into a `help-echo'
609 property on the competion items, so that the list of classes for the current
610 item is displayed in the echo area. If the value of this variable is a
611 negative integer, the `help-echo' property will be suppressed."
612 :group
'idlwave-completion
613 :type
'(choice (const :tag
"Don't show" nil
)
614 (integer :tag
"Number of classes shown" 1)))
616 (defcustom idlwave-completion-fontify-classes t
617 "*Non-nil means, fontify the classes in completions buffer.
618 This makes it easier to distinguish the completion items from the extra
619 class info listed. See `idlwave-completion-show-classes'."
620 :group
'idlwave-completion
623 (defcustom idlwave-query-class
'((method-default . nil
)
624 (keyword-default . nil
))
625 "Association list governing specification of object classes for completion.
627 When IDLWAVE tries to complete object-oriented methods, it usually
628 cannot determine the class of a given object from context. In order
629 to provide the user with a correct list of methods or keywords, it
630 needs to determine the appropriate class. IDLWAVE has two ways of
631 doing this (well, three ways if you count the shell... see
632 `idlwave-shell-query-for-class'):
634 1. Combine the items of all available classes which contain this
635 method for the purpose of completion. So when completing a method,
636 all methods of all known classes are available, and when completing
637 a keyword, all keywords allowed for this method in any class are
638 shown. This behavior is very much like normal completion and is
639 therefore the default. It works much better than one might think -
640 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
641 become uncomfortably long. See also
642 `idlwave-completion-show-classes'.
644 2. The second possibility is to ask the user on each occasion. To
645 make this less interruptive, IDLWAVE can store the class as a text
646 property on the object operator `->'. For a given object in the
647 source code, class selection will then be needed only once
648 - for example to complete the method. Keywords to the method can
649 then be completed directly, because the class is already known.
650 You will have to turn on the storage of the selected class
651 explicitly with the variable `idlwave-store-inquired-class'.
653 This variable allows you to configure IDLWAVE's method and
654 method-keyword completion behavior. Its value is an alist, which
655 should contain at least two elements: (method-default . VALUE) and
656 \(keyword-default . VALUE), where VALUE is either t or nil. These
657 specify if the class should be found during method and keyword
658 completion, respectively.
660 The alist may have additional entries specifying exceptions from the
661 keyword completion rule for specific methods, like INIT or
662 GETPROPERTY. In order to turn on class specification for the INIT
663 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
664 :group
'idlwave-completion
666 (cons (const method-default
)
667 (boolean :tag
"Determine class when completing METHODS "))
668 (cons (const keyword-default
)
669 (boolean :tag
"Determine class when completing KEYWORDS "))
671 :tag
"Exceptions to defaults"
673 (cons (string :tag
"MODULE" :value
"")
674 (boolean :tag
"Determine class for this method")))))
676 (defcustom idlwave-store-inquired-class t
677 "*Non-nil means, store class of a method call as text property on `->'.
678 IDLWAVE sometimes has to ask the user for the class associated with a
679 particular object method call. This happens during the commands
680 `idlwave-routine-info' and `idlwave-complete', depending upon the
681 value of the variable `idlwave-query-class'.
683 When you specify a class, this information can be stored as a text
684 property on the `->' arrow in the source code, so that during the same
685 editing session, IDLWAVE will not have to ask again. When this
686 variable is non-nil, IDLWAVE will store and reuse the class information.
687 The class stored can be checked and removed with `\\[idlwave-routine-info]'
690 The default of this variable is nil, since the result of commands then
691 is more predictable. However, if you know what you are doing, it can
692 be nice to turn this on.
694 An arrow which knows the class will be highlighted with
695 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
696 displays (with prefix arg: deletes) the class stored on the arrow
698 :group
'idlwave-completion
701 (defcustom idlwave-class-arrow-face
'bold
702 "*Face to highlight object operator arrows `->' which carry a class property.
703 When IDLWAVE stores a class name as text property on an object arrow
704 \(see variable `idlwave-store-inquired-class', it highlights the arrow
705 with this font in order to remind the user that this arrow is special."
706 :group
'idlwave-completion
709 (defcustom idlwave-resize-routine-help-window t
710 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
711 :group
'idlwave-completion
714 (defcustom idlwave-keyword-completion-adds-equal t
715 "*Non-nil means, completion automatically adds `=' after completed keywords."
716 :group
'idlwave-completion
719 (defcustom idlwave-function-completion-adds-paren t
720 "*Non-nil means, completion automatically adds `(' after completed function.
721 nil means, don't add anything.
722 A value of `2' means, also add the closing parenthesis and position cursor
724 :group
'idlwave-completion
725 :type
'(choice (const :tag
"Nothing" nil
)
727 (const :tag
"()" 2)))
729 (defcustom idlwave-completion-restore-window-configuration t
730 "*Non-nil means, try to restore the window configuration after completion.
731 When completion is not unique, Emacs displays a list of completions.
732 This messes up your window configuration. With this variable set, IDLWAVE
733 restores the old configuration after successful completion."
734 :group
'idlwave-completion
737 ;;; Variables for abbrev and action behavior -----------------------------
739 (defgroup idlwave-abbrev-and-indent-action nil
740 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
741 The variables in this group govern this."
744 (defcustom idlwave-do-actions nil
745 "*Non-nil means performs actions when indenting.
746 The actions that can be performed are listed in `idlwave-indent-action-table'."
747 :group
'idlwave-abbrev-and-indent-action
750 (defcustom idlwave-abbrev-start-char
"\\"
751 "*A single character string used to start abbreviations in abbrev mode.
752 Possible characters to chose from: ~`\%
753 or even '?'. '.' is not a good choice because it can make structure
754 field names act like abbrevs in certain circumstances.
756 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
757 must set it directly using `setq' in the .emacs file before idlwave.el
759 :group
'idlwave-abbrev-and-indent-action
762 (defcustom idlwave-surround-by-blank nil
763 "*Non-nil means, enable `idlwave-surround'.
764 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
766 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
768 Also see the default key bindings for keys using `idlwave-surround'.
769 Keys are bound and made into actions calling `idlwave-surround' with
770 `idlwave-action-and-binding'.
771 See help for `idlwave-action-and-binding' for examples.
773 Also see help for `idlwave-surround'."
774 :group
'idlwave-abbrev-and-indent-action
777 (defcustom idlwave-pad-keyword t
778 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
779 Whenever `idlwave-surround' is non-nil then this affects how '=' is
780 padded for keywords and for variables. If t, pad the same as for
781 assignments. If nil then spaces are removed. With any other value,
782 spaces are left unchanged."
783 :group
'idlwave-abbrev-and-indent-action
785 (const :tag
"Pad like assignments" t
)
786 (const :tag
"Remove space near `='" nil
)
787 (const :tag
"Keep space near `='" 'keep
)))
789 (defcustom idlwave-show-block t
790 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
791 :group
'idlwave-abbrev-and-indent-action
794 (defcustom idlwave-expand-generic-end nil
795 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
796 :group
'idlwave-abbrev-and-indent-action
799 (defcustom idlwave-reindent-end t
800 "*Non-nil means re-indent line after END was typed."
801 :group
'idlwave-abbrev-and-indent-action
804 (defcustom idlwave-abbrev-move t
805 "*Non-nil means the abbrev hook can move point.
806 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
807 definitions, use the command `list-abbrevs', for abbrevs that move
808 point. Moving point is useful, for example, to place point between
809 parentheses of expanded functions.
811 See `idlwave-check-abbrev'."
812 :group
'idlwave-abbrev-and-indent-action
815 (defcustom idlwave-abbrev-change-case nil
816 "*Non-nil means all abbrevs will be forced to either upper or lower case.
817 If the value t, all expanded abbrevs will be upper case.
818 If the value is 'down then abbrevs will be forced to lower case.
819 If nil, the case will not change.
820 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
821 upper case, regardless of this variable."
822 :group
'idlwave-abbrev-and-indent-action
825 (defcustom idlwave-reserved-word-upcase nil
826 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
827 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
828 Has effect only if in abbrev-mode."
829 :group
'idlwave-abbrev-and-indent-action
832 ;;; Action/Expand Tables.
834 ;; The average user may have difficulty modifying this directly. It
835 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
836 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
837 ;; examples of how to add an action.
839 ;; The action table is used by `idlwave-indent-line' whereas both the
840 ;; action and expand tables are used by `idlwave-indent-and-action'. In
841 ;; general, the expand table is only used when a line is explicitly
842 ;; indented. Whereas, in addition to being used when the expand table
843 ;; is used, the action table is used when a line is indirectly
844 ;; indented via line splitting, auto-filling or a new line creation.
848 ;; Capitalize system vars
849 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
851 ;; Capitalize procedure name
852 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
853 ;; '(capitalize-word 1) t)
855 ;; Capitalize common block name
856 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
857 ;; '(capitalize-word 1) t)
859 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
860 ;; '(capitalize-word -1) t)
862 (defvar idlwave-indent-action-table nil
863 "*Associated array containing action lists of search string (car),
864 and function as a cdr. This table is used by `idlwave-indent-line'.
865 See documentation for `idlwave-do-action' for a complete description of
868 Additions to the table are made with `idlwave-action-and-binding' when a
869 binding is not requested.
870 See help on `idlwave-action-and-binding' for examples.")
872 (defvar idlwave-indent-expand-table nil
873 "*Associated array containing action lists of search string (car),
874 and function as a cdr. The table is used by the
875 `idlwave-indent-and-action' function. See documentation for
876 `idlwave-do-action' for a complete description of the action lists.
878 Additions to the table are made with `idlwave-action-and-binding' when a
879 binding is requested.
880 See help on `idlwave-action-and-binding' for examples.")
882 ;;; Documentation header and history keyword ---------------------------------
884 (defgroup idlwave-documentation nil
885 "Options for documenting IDLWAVE files."
888 ;; FIXME: make defcustom?
889 (defvar idlwave-file-header
916 ; KEYWORD PARAMETERS:
948 ; MODIFICATION HISTORY:
952 "*A list (PATHNAME STRING) specifying the doc-header template to use for
953 summarizing a file. If PATHNAME is non-nil then this file will be included.
954 Otherwise STRING is used. If nil, the file summary will be omitted.
955 For example you might set PATHNAME to the path for the
956 lib_template.pro file included in the IDL distribution.")
958 (defcustom idlwave-header-to-beginning-of-file t
959 "*Non-nil means, the documentation header will always be at start of file.
960 When nil, the header is positioned between the PRO/FUNCTION line of
961 the current routine and the code, allowing several routine headers in
963 :group
'idlwave-documentation
966 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
967 "*The hook function used to update the timestamp of a function."
968 :group
'idlwave-documentation
971 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
972 "*The modifications keyword to use with the log documentation commands.
973 A ':' is added to the keyword end.
974 Inserted by doc-header and used to position logs by doc-modification.
975 If nil it will not be inserted."
976 :group
'idlwave-documentation
979 (defcustom idlwave-doclib-start
"^;+\\+"
980 "*Regexp matching the start of a document library header."
981 :group
'idlwave-documentation
984 (defcustom idlwave-doclib-end
"^;+-"
985 "*Regexp matching the end of a document library header."
986 :group
'idlwave-documentation
989 ;;; External Programs -------------------------------------------------------
991 (defgroup idlwave-external-programs nil
992 "Path locations of external commands used by IDLWAVE."
995 (defcustom idlwave-shell-explicit-file-name
"idl"
996 "*If non-nil, this is the command to run IDL.
997 Should be an absolute file path or path relative to the current environment
998 execution search path. If you want to specify command line switches
999 for the IDL program, use `idlwave-shell-command-line-options'.
1001 I know the name of this variable is badly chosen, but I cannot change
1002 it without compromising backwards-compatibility."
1003 :group
'idlwave-external-programs
1006 (defcustom idlwave-shell-command-line-options nil
1007 "*A list of command line options for calling the IDL program.
1008 Since IDL is executed directly without going through a shell like /bin/sh,
1009 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1010 string for each argument. But you may also give a single string which
1011 contains the options whitespace-separated. Emacs will be kind enough to
1015 (repeat (string :value
"")))
1016 :group
'idlwave-external-programs
)
1018 (defcustom idlwave-help-application
"idlhelp"
1019 "*The external application providing reference help for programming.
1020 Obsolete, if the IDL Assistant is being used for help."
1021 :group
'idlwave-external-programs
1024 ;;; Some Shell variables which must be defined here.-----------------------
1026 (defcustom idlwave-shell-debug-modifiers
'()
1027 "List of modifiers to be used for the debugging commands.
1028 Will be used to bind debugging commands in the shell buffer and in all
1029 source buffers. These are additional convenience bindings, the debugging
1030 commands are always available with the `C-c C-d' prefix.
1031 If you set this to '(control shift), this means setting a breakpoint will
1032 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1033 are `control', `meta', `super', `hyper', `alt', and `shift'."
1034 :group
'idlwave-shell-general-setup
1035 :type
'(set :tag
"Specify modifiers"
1043 (defcustom idlwave-shell-automatic-start nil
1044 "*If non-nil attempt invoke `idlwave-shell' if not already running.
1045 This is checked when an attempt to send a command to an
1046 IDL process is made."
1047 :group
'idlwave-shell-general-setup
1050 ;;; Miscellaneous variables -------------------------------------------------
1052 (defgroup idlwave-misc nil
1053 "Miscellaneous options for IDLWAVE mode."
1054 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
1057 (defcustom idlwave-startup-message t
1058 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1059 :group
'idlwave-misc
1062 (defcustom idlwave-default-font-lock-items
1063 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1064 common-blocks class-arrows
)
1065 "Items which should be fontified on the default fontification level 2.
1066 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1067 is everything and level 2 is specified by this list.
1068 This variable must be set before IDLWAVE gets loaded.
1069 It is a list of symbols; the following symbols are allowed:
1071 pros-and-functions Procedure and Function definitions
1072 batch-files Batch Files
1073 idlwave-idl-keywords IDL Keywords
1074 label Statement Labels
1075 goto Goto Statements
1076 common-blocks Common Blocks
1077 keyword-parameters Keyword Parameters in routine definitions and calls
1078 system-variables System Variables
1079 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1080 class-arrows Object Arrows with class property"
1081 :group
'idlwave-misc
1084 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1085 (const :tag
"Batch Files" batch-files
)
1086 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1087 (const :tag
"Statement Labels" label
)
1088 (const :tag
"Goto Statements" goto
)
1089 (const :tag
"Tags in Structure Definition" structtag
)
1090 (const :tag
"Structure Name" structname
)
1091 (const :tag
"Common Blocks" common-blocks
)
1092 (const :tag
"Keyword Parameters" keyword-parameters
)
1093 (const :tag
"System Variables" system-variables
)
1094 (const :tag
"FIXME: Warning" fixme
)
1095 (const :tag
"Object Arrows with class property " class-arrows
)))
1097 (defcustom idlwave-mode-hook nil
1098 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1099 :group
'idlwave-misc
1102 (defcustom idlwave-load-hook nil
1103 "Normal hook. Executed when idlwave.el is loaded."
1104 :group
'idlwave-misc
1107 (defvar idlwave-experimental nil
1108 "Non-nil means turn on a few experimental features.
1109 This variable is only for the maintainer, to test difficult stuff,
1110 while still distributing stable releases.
1111 As a user, you should not set this to t.")
1114 ;;; End customization variables section
1117 ;;; Non customization variables
1119 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1120 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1121 ;;; and Carsten Dominik...
1123 ;; The following are the reserved words in IDL. Maybe we should
1124 ;; highlight some more stuff as well?
1125 ;; Procedure declarations. Fontify keyword plus procedure name.
1126 (defvar idlwave-idl-keywords
1127 ;; To update this regexp, update the list of keywords and
1128 ;; evaluate the form.
1134 ;; '("||" "&&" "and" "or" "xor" "not"
1135 ;; "eq" "ge" "gt" "le" "lt" "ne"
1136 ;; "for" "do" "endfor"
1137 ;; "if" "then" "endif" "else" "endelse"
1138 ;; "case" "of" "endcase"
1139 ;; "switch" "break" "continue" "endswitch"
1141 ;; "repeat" "until" "endrep"
1142 ;; "while" "endwhile"
1145 ;; "compile_opt" "forward_function"
1146 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1148 "\\<\\(&&\\|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\\|||\\)\\>")
1151 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1152 ;; Function declarations. Fontify keyword plus function name.
1154 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1155 (1 font-lock-keyword-face
)
1156 (2 font-lock-function-name-face nil t
)))
1160 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1161 (1 font-lock-keyword-face
) ; "common"
1162 (2 font-lock-reference-face nil t
) ; block name
1163 ("[ \t]*\\(\\sw+\\)[ ,]*"
1164 ;; Start with point after block name and comma
1165 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1167 (1 font-lock-variable-name-face
) ; variable names
1172 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1176 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1180 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1182 ;; The goto statement and its label
1184 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1185 (1 font-lock-keyword-face
)
1186 (2 font-lock-reference-face
)))
1188 ;; Tags in structure definitions. Note that this definition
1189 ;; actually collides with labels, so we have to use the same
1190 ;; face. It also matches named subscript ranges,
1191 ;; e.g. vec{bottom:top]. No good way around this.
1193 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1197 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1198 (2 font-lock-function-name-face
)))
1200 ;; Keyword parameters, like /xlog or ,xrange=[]
1201 ;; This is anchored to the comma preceeding the keyword.
1202 ;; Treats continuation lines, works only during whole buffer
1203 ;; fontification. Slow, use it only in fancy fontification.
1205 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1206 (6 font-lock-reference-face
)))
1208 ;; System variables start with a bang.
1210 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1211 (1 font-lock-variable-name-face
)))
1213 ;; Special and unusual operators (not used because too noisy)
1215 '("[<>#]" (0 font-lock-keyword-face
)))
1217 ;; All operators (not used because too noisy)
1219 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1221 ;; Arrows with text property `idlwave-class'
1223 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1225 (defconst idlwave-font-lock-keywords-1
1226 (list pros-and-functions batch-files
)
1227 "Subdued level highlighting for IDLWAVE mode.")
1229 (defconst idlwave-font-lock-keywords-2
1230 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1231 "Medium level highlighting for IDLWAVE mode.")
1233 (defconst idlwave-font-lock-keywords-3
1234 (list pros-and-functions
1236 idlwave-idl-keywords
1244 "Gaudy level highlighting for IDLWAVE mode."))
1246 (defun idlwave-match-class-arrows (limit)
1247 ;; Match an object arrow with class property
1248 (and idlwave-store-inquired-class
1249 (re-search-forward "->" limit
'limit
)
1250 (get-text-property (match-beginning 0) 'idlwave-class
)))
1252 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1253 "Default expressions to highlight in IDLWAVE mode.")
1255 (defvar idlwave-font-lock-defaults
1256 '((idlwave-font-lock-keywords
1257 idlwave-font-lock-keywords-1
1258 idlwave-font-lock-keywords-2
1259 idlwave-font-lock-keywords-3
)
1261 ((?$ .
"w") (?_ .
"w") (?. .
"w") (?| .
"w") (?
& .
"w"))
1264 (put 'idlwave-mode
'font-lock-defaults
1265 idlwave-font-lock-defaults
) ; XEmacs
1267 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1268 "Regexp to match the start of a full-line comment.
1269 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1270 only by whitespace.")
1272 (defconst idlwave-begin-block-reg
1273 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1274 "Regular expression to find the beginning of a block.
1275 The case does not matter. The search skips matches in comments.")
1277 (defconst idlwave-begin-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1278 "Regular expression to find the beginning of a unit.
1279 The case does not matter.")
1281 (defconst idlwave-end-unit-reg
"^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1282 "Regular expression to find the line that indicates the end of unit.
1283 This line is the end of buffer or the start of another unit.
1284 The case does not matter. The search skips matches in comments.")
1286 (defconst idlwave-continue-line-reg
"\\<\\$"
1287 "Regular expression to match a continued line.")
1289 (defconst idlwave-end-block-reg
1290 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1291 "Regular expression to find the end of a block.
1292 The case does not matter. The search skips matches in comments.")
1294 (defconst idlwave-block-matches
1296 ("function" .
"end")
1297 ("case" .
"endcase")
1298 ("else" .
"endelse")
1301 ("repeat" .
"endrep")
1302 ("switch" .
"endswitch")
1303 ("while" .
"endwhile"))
1304 "Matches between statements and the corresponding END variant.
1305 The cars are the reserved words starting a block. If the block really
1306 begins with BEGIN, the cars are the reserved words before the begin
1307 which can be used to identify the block type.
1308 This is used to check for the correct END type, to close blocks and
1309 to expand generic end statements to their detailed form.")
1311 (defconst idlwave-block-match-regexp
1312 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1313 "Regular expression matching reserved words which can stand before
1314 blocks starting with a BEGIN statement. The matches must have associations
1315 `idlwave-block-matches'.")
1317 (defconst idlwave-identifier
"[a-zA-Z_][a-zA-Z0-9$_]*"
1318 "Regular expression matching an IDL identifier.")
1320 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1321 "Regular expression matching IDL system variables.")
1323 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1324 "Regular expression matching IDL variable names.")
1326 (defconst idlwave-label
(concat idlwave-identifier
":")
1327 "Regular expression matching IDL labels.")
1329 (defconst idlwave-method-call
(concat idlwave-identifier
"\\s *->"
1330 "\\(\\s *" idlwave-identifier
"::\\)?"
1333 (defconst idlwave-statement-match
1335 ;; "endif else" is the only possible "end" that can be
1336 ;; followed by a statement on the same line.
1337 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1338 ;; all other "end"s can not be followed by a statement.
1339 (cons 'end
(list idlwave-end-block-reg nil
))
1340 '(if .
("if\\>" "then"))
1341 '(for .
("for\\>" "do"))
1342 '(begin .
("begin\\>" nil
))
1343 '(pdef .
("pro\\>\\|function\\>" nil
))
1344 '(while .
("while\\>" "do"))
1345 '(repeat .
("repeat\\>" "repeat"))
1346 '(goto .
("goto\\>" nil
))
1347 '(case .
("case\\>" nil
))
1348 '(switch .
("switch\\>" nil
))
1349 (cons 'call
(list (concat "\\(" idlwave-variable
"\\) *= *"
1350 "\\(" idlwave-method-call
"\\s *\\)?"
1353 (cons 'call
(list (concat
1354 "\\(" idlwave-method-call
"\\s *\\)?"
1356 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil
))
1357 (cons 'assign
(list (concat
1358 "\\(" idlwave-variable
"\\) *=") nil
)))
1360 "Associated list of statement matching regular expressions.
1361 Each regular expression matches the start of an IDL statement.
1362 The first element of each association is a symbol giving the statement
1363 type. The associated value is a list. The first element of this list
1364 is a regular expression matching the start of an IDL statement for
1365 identifying the statement type. The second element of this list is a
1366 regular expression for finding a substatement for the type. The
1367 substatement starts after the end of the found match modulo
1368 whitespace. If it is nil then the statement has no substatement. The
1369 list order matters since matching an assignment statement exactly is
1370 not possible without parsing. Thus assignment statement become just
1371 the leftover unidentified statements containing an equal sign.")
1373 (defvar idlwave-fill-function
'auto-fill-function
1374 "IDL mode auto fill function.")
1376 (defvar idlwave-comment-indent-function
'comment-indent-function
1377 "IDL mode comment indent function.")
1379 ;; Note that this is documented in the v18 manuals as being a string
1380 ;; of length one rather than a single character.
1381 ;; The code in this file accepts either format for compatibility.
1382 (defvar idlwave-comment-indent-char ?\
1383 "Character to be inserted for IDL comment indentation.
1386 (defconst idlwave-continuation-char ?$
1387 "Character which is inserted as a last character on previous line by
1388 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1390 (defconst idlwave-mode-version
"6.1_em22")
1392 (defmacro idlwave-keyword-abbrev
(&rest args
)
1393 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1395 ,(append '(idlwave-check-abbrev) args
))))
1397 ;; If I take the time I can replace idlwave-keyword-abbrev with
1398 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1399 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1400 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1401 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1403 (defmacro idlwave-code-abbrev
(&rest args
)
1404 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1405 Specifically, if the abbrev is in a comment or string it is unexpanded.
1406 Otherwise ARGS forms a list that is evaluated."
1408 ,(prin1-to-string args
) ;; Puts the code in the doc string
1409 (if (idlwave-quoted)
1410 (progn (unexpand-abbrev) nil
)
1413 (defvar idlwave-mode-map
(make-sparse-keymap)
1414 "Keymap used in IDL mode.")
1416 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1417 "Syntax table in use in `idlwave-mode' buffers.")
1419 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
1420 (modify-syntax-entry ?-
"." idlwave-mode-syntax-table
)
1421 (modify-syntax-entry ?
* "." idlwave-mode-syntax-table
)
1422 (modify-syntax-entry ?
/ "." idlwave-mode-syntax-table
)
1423 (modify-syntax-entry ?^
"." idlwave-mode-syntax-table
)
1424 (modify-syntax-entry ?
# "." idlwave-mode-syntax-table
)
1425 (modify-syntax-entry ?
= "." idlwave-mode-syntax-table
)
1426 (modify-syntax-entry ?%
"." idlwave-mode-syntax-table
)
1427 (modify-syntax-entry ?
< "." idlwave-mode-syntax-table
)
1428 (modify-syntax-entry ?
> "." idlwave-mode-syntax-table
)
1429 (modify-syntax-entry ?
\' "\"" idlwave-mode-syntax-table
)
1430 (modify-syntax-entry ?
\" "\"" idlwave-mode-syntax-table
)
1431 (modify-syntax-entry ?
\\ "." idlwave-mode-syntax-table
)
1432 (modify-syntax-entry ?_
"_" idlwave-mode-syntax-table
)
1433 (modify-syntax-entry ?
{ "(}" idlwave-mode-syntax-table
)
1434 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1435 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1436 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1437 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1438 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1439 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1441 (defvar idlwave-find-symbol-syntax-table
1442 (copy-syntax-table idlwave-mode-syntax-table
)
1443 "Syntax table that treats symbol characters as word characters.")
1445 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1446 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1447 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1448 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1450 (defmacro idlwave-with-special-syntax
(&rest body
)
1451 "Execute BODY with a different syntax table."
1452 `(let ((saved-syntax (syntax-table)))
1455 (set-syntax-table idlwave-find-symbol-syntax-table
)
1457 (set-syntax-table saved-syntax
))))
1459 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1460 ; "Execute BODY with a different syntax table."
1461 ; `(let ((saved-syntax (syntax-table)))
1464 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1466 ; (set-syntax-table saved-syntax))))
1468 (defun idlwave-action-and-binding (key cmd
&optional select
)
1469 "KEY and CMD are made into a key binding and an indent action.
1470 KEY is a string - same as for the `define-key' function. CMD is a
1471 function of no arguments or a list to be evaluated. CMD is bound to
1472 KEY in `idlwave-mode-map' by defining an anonymous function calling
1473 `self-insert-command' followed by CMD. If KEY contains more than one
1474 character a binding will only be set if SELECT is 'both.
1476 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1477 replacing any previous value for KEY. If a binding is not set then it
1478 will instead be placed in `idlwave-indent-action-table'.
1480 If the optional argument SELECT is nil then an action and binding are
1481 created. If SELECT is 'noaction, then a binding is always set and no
1482 action is created. If SELECT is 'both then an action and binding
1483 will both be created even if KEY contains more than one character.
1484 Otherwise, if SELECT is non-nil then only an action is created.
1487 No spaces before and 1 after a comma
1488 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1489 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1490 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1491 Capitalize system variables - action only
1492 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1493 (if (not (equal select
'noaction
))
1495 (let* ((table (if select
'idlwave-indent-action-table
1496 'idlwave-indent-expand-table
))
1497 (table-key (regexp-quote key
))
1498 (cell (assoc table-key
(eval table
))))
1500 ;; Replace action command
1503 (set table
(append (eval table
) (list (cons table-key cmd
)))))))
1504 ;; Make key binding for action
1505 (if (or (and (null select
) (= (length key
) 1))
1506 (equal select
'noaction
)
1507 (equal select
'both
))
1508 (define-key idlwave-mode-map key
1511 (self-insert-command 1))
1512 (list (if (listp cmd
)
1516 (fset 'idlwave-debug-map
(make-sparse-keymap))
1518 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1519 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1520 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1521 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1522 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1523 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1524 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1525 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1526 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1527 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1528 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1529 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1530 (define-key idlwave-mode-map
[(meta control h
)] 'idlwave-mark-subprogram
)
1531 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1532 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1533 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1534 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1535 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1536 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1537 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1538 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1539 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1540 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1541 (define-key idlwave-mode-map
[(shift iso-lefttab
)] 'idlwave-indent-statement
)
1542 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1543 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1544 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1545 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1546 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1547 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1548 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1549 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1550 (listp idlwave-shell-debug-modifiers
)
1551 (not (equal idlwave-shell-debug-modifiers
'())))
1552 ;; Bind the debug commands also with the special modifiers.
1553 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1554 (mods-noshift (delq 'shift
1555 (copy-sequence idlwave-shell-debug-modifiers
))))
1556 (define-key idlwave-mode-map
1557 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1558 'idlwave-shell-save-and-run
)
1559 (define-key idlwave-mode-map
1560 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1561 'idlwave-shell-break-here
)
1562 (define-key idlwave-mode-map
1563 (vector (append mods-noshift
(list (if shift ?E ?e
))))
1564 'idlwave-shell-run-region
)))
1565 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1566 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1567 (define-key idlwave-mode-map
"\C-c\C-d\C-e" 'idlwave-shell-run-region
)
1568 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1569 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1570 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1571 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1572 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1573 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1574 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1575 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1576 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1577 (autoload 'idlwave-shell
"idlw-shell"
1578 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1579 (autoload 'idlwave-shell-send-command
"idlw-shell")
1580 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1581 "Run `idlwave-shell' and switch back to current window" t
)
1582 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1583 "Save and run buffer under the shell." t
)
1584 (autoload 'idlwave-shell-break-here
"idlw-shell"
1585 "Set breakpoint in current line." t
)
1586 (autoload 'idlwave-shell-run-region
"idlw-shell"
1587 "Compile and run the region." t
)
1588 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1589 (define-key idlwave-mode-map
"\C-c\C-t" 'idlwave-find-module-this-file
)
1590 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1591 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1592 (define-key idlwave-mode-map
[(control meta ?
\?)]
1593 'idlwave-help-assistant-help-with-topic
)
1594 ;; Pickup both forms of Esc/Meta binding
1595 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1596 (define-key idlwave-mode-map
[?\e?
\t] 'idlwave-complete
)
1597 (define-key idlwave-mode-map
"\M-\C-i" 'idlwave-complete
)
1598 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1599 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1600 (define-key idlwave-mode-map
1601 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1602 'idlwave-mouse-context-help
)
1604 ;; Set action and key bindings.
1605 ;; See description of the function `idlwave-action-and-binding'.
1606 ;; Automatically add spaces for the following characters
1608 ;; Actions for & are complicated by &&
1609 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround
)
1611 ;; Automatically add spaces to equal sign if not keyword. This needs
1612 ;; to go ahead of > and <, so >= and <= will be treated correctly
1613 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1615 ;; Actions for > and < are complicated by >=, <=, and ->...
1616 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil
))
1617 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr
))
1619 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1 1))
1625 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1626 ;;; space is inserted (this is the space typed by the user to expanded
1629 (defvar idlwave-mode-abbrev-table nil
1630 "Abbreviation table used for IDLWAVE mode.")
1631 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1633 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1634 "Define-abbrev with backward compatibility.
1636 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1637 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1638 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1639 (args (list (or table idlwave-mode-abbrev-table
)
1640 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1644 (apply 'define-abbrev
(append args
'(0 t
)))
1645 (error (apply 'define-abbrev args
)))))
1648 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1649 "w" idlwave-mode-syntax-table
)
1655 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1656 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1657 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1658 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1659 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1660 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1661 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1662 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1663 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1665 ;; Keywords, system functions, conversion routines
1667 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1668 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1669 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1670 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1672 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1673 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1678 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1679 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1680 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1681 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1682 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1683 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1684 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1685 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1686 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1687 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1688 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1689 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1690 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1691 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1693 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1704 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1705 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1711 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1712 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1713 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1714 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1715 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1716 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1717 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1718 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1719 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1720 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1721 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1724 ;; This section is reserved words only. (From IDL user manual)
1726 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1727 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1728 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1729 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1730 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1735 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1736 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1737 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1738 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1739 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1740 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1741 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1742 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1743 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1744 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1745 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1746 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1747 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1748 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1749 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1750 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1751 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1752 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1753 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1754 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1755 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1756 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1757 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1758 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1759 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1760 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1761 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1762 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1763 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1764 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1766 (defvar imenu-create-index-function
)
1767 (defvar extract-index-name-function
)
1768 (defvar prev-index-position-function
)
1769 (defvar imenu-extract-index-name-function
)
1770 (defvar imenu-prev-index-position-function
)
1771 ;; defined later - so just make the compiler hush
1772 (defvar idlwave-mode-menu
)
1773 (defvar idlwave-mode-debug-menu
)
1776 (defun idlwave-mode ()
1777 "Major mode for editing IDL source files (version 6.1_em22).
1779 The main features of this mode are
1781 1. Indentation and Formatting
1782 --------------------------
1783 Like other Emacs programming modes, C-j inserts a newline and indents.
1784 TAB is used for explicit indentation of the current line.
1786 To start a continuation line, use \\[idlwave-split-line]. This
1787 function can also be used in the middle of a line to split the line
1788 at that point. When used inside a long constant string, the string
1789 is split at that point with the `+' concatenation operator.
1791 Comments are indented as follows:
1793 `;;;' Indentation remains unchanged.
1794 `;;' Indent like the surrounding code
1795 `;' Indent to a minimum column.
1797 The indentation of comments starting in column 0 is never changed.
1799 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1800 comment. The indentation of the second line of the paragraph
1801 relative to the first will be retained. Use
1802 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1803 comments. When the variable `idlwave-fill-comment-line-only' is
1804 nil, code can also be auto-filled and auto-indented.
1806 To convert pre-existing IDL code to your formatting style, mark the
1807 entire buffer with \\[mark-whole-buffer] and execute
1808 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1809 again followed by \\[indent-region] (`indent-region').
1813 IDLWAVE displays information about the calling sequence and the
1814 accepted keyword parameters of a procedure or function with
1815 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1816 source file of a module. These commands know about system
1817 routines, all routines in idlwave-mode buffers and (when the
1818 idlwave-shell is active) about all modules currently compiled under
1819 this shell. It also makes use of pre-compiled or custom-scanned
1820 user and library catalogs many popular libraries ship with by
1821 default. Use \\[idlwave-update-routine-info] to update this
1822 information, which is also used for completion (see item 4).
1827 \\[idlwave-context-help] displays the IDL documentation relevant
1828 for the system variable, keyword, or routines at point. A single
1829 key stroke gets you directly to the right place in the docs. See
1830 the manual to configure where and how the HTML help is displayed.
1834 \\[idlwave-complete] completes the names of procedures, functions
1835 class names, keyword parameters, system variables and tags, class
1836 tags, structure tags, filenames and much more. It is context
1837 sensitive and figures out what is expected at point. Lower case
1838 strings are completed in lower case, other strings in mixed or
1841 5. Code Templates and Abbreviations
1842 --------------------------------
1843 Many Abbreviations are predefined to expand to code fragments and templates.
1844 The abbreviations start generally with a `\\`. Some examples:
1846 \\pr PROCEDURE template
1847 \\fu FUNCTION template
1848 \\c CASE statement template
1849 \\sw SWITCH statement template
1850 \\f FOR loop template
1851 \\r REPEAT Loop template
1852 \\w WHILE loop template
1853 \\i IF statement template
1854 \\elif IF-ELSE statement template
1857 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1858 have direct keybindings - see the list of keybindings below.
1860 \\[idlwave-doc-header] inserts a documentation header at the
1861 beginning of the current program unit (pro, function or main).
1862 Change log entries can be added to the current program unit with
1863 \\[idlwave-doc-modification].
1865 6. Automatic Case Conversion
1866 -------------------------
1867 The case of reserved words and some abbrevs is controlled by
1868 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1870 7. Automatic END completion
1871 ------------------------
1872 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1873 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1877 Loading idlwave.el runs `idlwave-load-hook'.
1878 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1880 9. Documentation and Customization
1881 -------------------------------
1882 Info documentation for this package is available. Use
1883 \\[idlwave-info] to display (complain to your sysadmin if that does
1884 not work). For Postscript, PDF, and HTML versions of the
1885 documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
1886 IDLWAVE has customize support - see the group `idlwave'.
1890 Here is a list of all keybindings of this mode.
1891 If some of the key bindings below show with ??, use \\[describe-key]
1892 followed by the key sequence to see what the key sequence does.
1894 \\{idlwave-mode-map}"
1897 (kill-all-local-variables)
1899 (if idlwave-startup-message
1900 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1901 (setq idlwave-startup-message nil
)
1903 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1904 (set-syntax-table idlwave-mode-syntax-table
)
1906 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1908 (make-local-variable idlwave-comment-indent-function
)
1909 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1911 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1912 (set (make-local-variable 'comment-start
) ";")
1913 (set (make-local-variable 'comment-add
) 1) ; ";;" for new and regions
1914 (set (make-local-variable 'require-final-newline
) t
)
1915 (set (make-local-variable 'abbrev-all-caps
) t
)
1916 (set (make-local-variable 'indent-tabs-mode
) nil
)
1917 (set (make-local-variable 'completion-ignore-case
) t
)
1919 (use-local-map idlwave-mode-map
)
1921 (when (featurep 'easymenu
)
1922 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1923 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1925 (setq mode-name
"IDLWAVE")
1926 (setq major-mode
'idlwave-mode
)
1927 (setq abbrev-mode t
)
1929 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1930 (setq comment-end
"")
1931 (set (make-local-variable 'comment-multi-line
) nil
)
1932 (set (make-local-variable 'paragraph-separate
)
1933 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1934 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1935 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1936 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1939 (set (make-local-variable 'add-log-current-defun-function
)
1940 'idlwave-current-routine-fullname
)
1942 ;; Set tag table list to use IDLTAGS as file name.
1943 (if (boundp 'tag-table-alist
)
1944 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1946 ;; Font-lock additions
1947 ;; Following line is for Emacs - XEmacs uses the corresponding property
1948 ;; on the `idlwave-mode' symbol.
1949 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1950 (set (make-local-variable 'font-lock-mark-block-function
)
1951 'idlwave-mark-subprogram
)
1952 (set (make-local-variable 'font-lock-fontify-region-function
)
1953 'idlwave-font-lock-fontify-region
)
1956 (set (make-local-variable 'imenu-create-index-function
)
1957 'imenu-default-create-index-function
)
1958 (set (make-local-variable 'imenu-extract-index-name-function
)
1960 (set (make-local-variable 'imenu-prev-index-position-function
)
1961 'idlwave-prev-index-position
)
1964 (add-to-list 'hs-special-modes-alist
1966 idlwave-begin-block-reg
1967 idlwave-end-block-reg
1969 'idlwave-forward-block nil
))
1971 ;; Make a local post-command-hook and add our hook to it
1972 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1973 ;; (make-local-hook 'post-command-hook)
1974 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1976 ;; Make local hooks for buffer updates
1977 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1978 ;; (make-local-hook 'kill-buffer-hook)
1979 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1980 ;; (make-local-hook 'after-save-hook)
1981 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1982 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1984 ;; Setup directories and file, if necessary
1987 ;; Update the routine info with info about current buffer?
1988 (idlwave-new-buffer-update)
1990 ;; Check help location
1991 (idlwave-help-check-locations)
1993 ;; Run the mode hook
1994 (run-mode-hooks 'idlwave-mode-hook
))
1996 (defvar idlwave-setup-done nil
)
1997 (defun idlwave-setup ()
1998 (unless idlwave-setup-done
1999 (if (not (file-directory-p idlwave-config-directory
))
2000 (make-directory idlwave-config-directory
))
2002 idlwave-user-catalog-file
(expand-file-name
2003 idlwave-user-catalog-file
2004 idlwave-config-directory
)
2005 idlwave-xml-system-rinfo-converted-file
2007 idlwave-xml-system-rinfo-converted-file
2008 idlwave-config-directory
)
2009 idlwave-path-file
(expand-file-name
2011 idlwave-config-directory
))
2012 (idlwave-read-paths) ; we may need these early
2013 (setq idlwave-setup-done t
)))
2015 (defun idlwave-font-lock-fontify-region (beg end
&optional verbose
)
2016 "Fontify continuation lines correctly."
2021 (when (setq pos
(idlwave-is-continuation-line))
2023 (idlwave-beginning-of-statement)
2024 (setq beg
(point)))))
2025 (font-lock-default-fontify-region beg end verbose
))
2028 ;; Code Formatting ----------------------------------------------------
2031 (defun idlwave-hard-tab ()
2032 "Insert TAB in buffer in current position."
2036 ;;; This stuff is experimental
2038 (defvar idlwave-command-hook nil
2039 "If non-nil, a list that can be evaluated using `eval'.
2040 It is evaluated in the lisp function `idlwave-command-hook' which is
2041 placed in `post-command-hook'.")
2043 (defun idlwave-command-hook ()
2044 "Command run after every command.
2045 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2046 sets the variable to zero afterwards."
2047 (and idlwave-command-hook
2048 (listp idlwave-command-hook
)
2050 (eval idlwave-command-hook
)
2052 (setq idlwave-command-hook nil
))
2056 ;; It would be better to use expand.el for better abbrev handling and
2059 (defun idlwave-check-abbrev (arg &optional reserved
)
2060 "Reverse abbrev expansion if in comment or string.
2061 Argument ARG is the number of characters to move point
2062 backward if `idlwave-abbrev-move' is non-nil.
2063 If optional argument RESERVED is non-nil then the expansion
2064 consists of reserved words, which will be capitalized if
2065 `idlwave-reserved-word-upcase' is non-nil.
2066 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2067 is non-nil, unless its value is \`down in which case the abbrev will be
2068 made into all lowercase.
2069 Returns non-nil if abbrev is left expanded."
2070 (if (idlwave-quoted)
2071 (progn (unexpand-abbrev)
2073 (if (and reserved idlwave-reserved-word-upcase
)
2074 (upcase-region last-abbrev-location
(point))
2076 ((equal idlwave-abbrev-change-case
'down
)
2077 (downcase-region last-abbrev-location
(point)))
2078 (idlwave-abbrev-change-case
2079 (upcase-region last-abbrev-location
(point)))))
2080 (if (and idlwave-abbrev-move
(> arg
0))
2081 (if (boundp 'post-command-hook
)
2082 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2083 (backward-char arg
)))
2086 (defun idlwave-in-comment ()
2087 "Return t if point is inside a comment, nil otherwise."
2089 (let ((here (point)))
2090 (and (idlwave-goto-comment) (> here
(point))))))
2092 (defun idlwave-goto-comment ()
2093 "Move to start of comment delimiter on current line.
2094 Moves to end of line if there is no comment delimiter.
2095 Ignores comment delimiters in strings.
2096 Returns point if comment found and nil otherwise."
2097 (let ((eos (progn (end-of-line) (point)))
2100 ;; Look for first comment delimiter not in a string
2102 (setq found
(search-forward comment-start eos
'lim
))
2103 (while (and found
(idlwave-in-quote))
2104 (setq found
(search-forward comment-start eos
'lim
)))
2105 (store-match-data data
)
2106 (and found
(not (idlwave-in-quote))
2111 (defun idlwave-region-active-p ()
2112 "Should we operate on an active region?"
2113 (if (fboundp 'use-region-p
)
2117 (defun idlwave-show-matching-quote ()
2118 "Insert quote and show matching quote if this is end of a string."
2120 (let ((bq (idlwave-in-quote))
2121 (inq last-command-event
))
2122 (if (and bq
(not (idlwave-in-comment)))
2123 (let ((delim (char-after bq
)))
2129 ;; Not the end of a string
2132 (defun idlwave-show-begin-check ()
2133 "Ensure that the previous word was a token before `idlwave-show-begin'.
2134 An END token must be preceded by whitespace."
2135 (if (not (idlwave-quoted))
2140 (looking-at "[ \t\n\f]"))
2141 (idlwave-show-begin))))
2143 (defun idlwave-show-begin ()
2144 "Find the start of current block and blinks to it for a second.
2145 Also checks if the correct END statement has been used."
2146 ;; All end statements are reserved words
2147 ;; Re-indent end line
2148 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2150 (let* ((pos (point-marker))
2151 (last-abbrev-marker (copy-marker last-abbrev-location
))
2152 (eol-pos (save-excursion (end-of-line) (point)))
2153 begin-pos end-pos end end1
)
2154 (if idlwave-reindent-end
(idlwave-indent-line))
2155 (setq last-abbrev-location
(marker-position last-abbrev-marker
))
2156 (when (and (idlwave-check-abbrev 0 t
)
2159 ;; Move inside current block
2160 (goto-char last-abbrev-marker
)
2161 (idlwave-block-jump-out -
1 'nomark
)
2162 (setq begin-pos
(point))
2163 (idlwave-block-jump-out 1 'nomark
)
2164 (setq end-pos
(point))
2165 (if (> end-pos eol-pos
)
2168 (setq end
(buffer-substring
2170 (skip-chars-backward "a-zA-Z")
2173 (goto-char begin-pos
)
2174 (when (setq end1
(cdr (idlwave-block-master)))
2176 ((null end1
)) ; no-operation
2177 ((string= (downcase end
) (downcase end1
))
2179 ((string= (downcase end
) "end")
2181 (if idlwave-expand-generic-end
2185 (insert (if (string= end
"END") (upcase end1
) end1
))
2190 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2195 (defun idlwave-block-master ()
2196 (let ((case-fold-search t
))
2199 ((looking-at "pro\\|case\\|switch\\|function\\>")
2200 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2201 ((looking-at "begin\\>")
2202 (let ((limit (save-excursion
2203 (idlwave-beginning-of-statement)
2206 ((re-search-backward ":[ \t]*\\=" limit t
)
2207 ;; seems to be a case thing
2209 ((re-search-backward idlwave-block-match-regexp limit t
)
2210 (assoc (downcase (match-string 1))
2211 idlwave-block-matches
))
2213 ;; Just a normal block
2214 '("begin" .
"end")))))
2217 (defun idlwave-close-block ()
2218 "Terminate the current block with the correct END statement."
2220 ;; Start new line if we are not in a new line
2221 (unless (save-excursion
2222 (skip-chars-backward " \t")
2224 (let ((idlwave-show-block nil
))
2225 (newline-and-indent)))
2226 (let ((last-abbrev-location (point))) ; for upcasing
2228 (idlwave-show-begin)))
2230 (defun idlwave-custom-ampersand-surround (&optional is-action
)
2231 "Surround &, leaving room for && (which surround as well)."
2232 (let* ((prev-char (char-after (- (point) 2)))
2233 (next-char (char-after (point)))
2234 (amp-left (eq prev-char ?
&))
2235 (amp-right (eq next-char ?
&))
2236 (len (if amp-left
2 1)))
2237 (unless amp-right
;no need to do it twice, amp-left will catch it.
2238 (idlwave-surround -
1 (if (or is-action amp-left
) -
1) len
))))
2240 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action
)
2241 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2242 (let* ((prev-char (char-after (- (point) 2)))
2243 (next-char (char-after (point)))
2244 (method-invoke (and gtr
(eq prev-char ?-
)))
2245 (len (if method-invoke
2 1)))
2246 (unless (eq next-char ?
=)
2247 ;; Key binding: pad only on left, to save for possible >=/<=
2248 (idlwave-surround -
1 (if (or is-action method-invoke
) -
1) len
))))
2250 (defun idlwave-surround (&optional before after length is-action
)
2251 "Surround the LENGTH characters before point with blanks.
2252 LENGTH defaults to 1.
2253 Optional arguments BEFORE and AFTER affect the behavior before and
2254 after the characters (see also description of `idlwave-make-space'):
2258 integer > 0 force exactly n spaces
2259 integer < 0 at least |n| spaces
2261 The function does nothing if any of the following conditions is true:
2262 - `idlwave-surround-by-blank' is nil
2263 - the character before point is inside a string or comment"
2264 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2265 (let ((length (or length
1))) ; establish a default for LENGTH
2266 (backward-char length
)
2268 (let ((here (point)))
2269 (skip-chars-backward " \t")
2271 ;; avoid clobbering indent
2273 (move-to-column (idlwave-calculate-indent))
2274 (if (<= (point) here
)
2275 (narrow-to-region (point) here
))
2277 (idlwave-make-space before
))
2278 (skip-chars-forward " \t"))
2279 (forward-char length
)
2280 (idlwave-make-space after
)
2281 ;; Check to see if the line should auto wrap
2282 (if (and (equal (char-after (1- (point))) ?\
)
2283 (> (current-column) fill-column
))
2284 (funcall auto-fill-function
)))))
2286 (defun idlwave-make-space (n)
2287 "Make space at point.
2288 The space affected is all the spaces and tabs around point.
2289 If n is non-nil then point is left abs(n) spaces from the beginning of
2290 the contiguous space.
2291 The amount of space at point is determined by N.
2292 If the value of N is:
2294 > 0 - exactly N spaces.
2295 < 0 - a minimum of -N spaces, i.e., do not change if there are
2297 0 - no spaces (i.e. remove any existing space)."
2300 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2302 (end-col (progn (skip-chars-forward " \t") (current-column))))
2303 (delete-horizontal-space)
2306 (idlwave-indent-to (+ start-col n
))
2307 (goto-char (+ left n
)))
2309 (idlwave-indent-to end-col
(- n
))
2310 (goto-char (- left n
)))
2314 (defun idlwave-newline ()
2315 "Insert a newline and indent the current and previous line."
2318 ;; Handle unterminated single and double quotes
2319 ;; If not in a comment and in a string then insertion of a newline
2320 ;; will mean unbalanced quotes.
2322 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2324 (message "Warning: unbalanced quotes?")))
2327 ;; The current line is being split, the cursor should be at the
2328 ;; beginning of the new line skipping the leading indentation.
2330 ;; The reason we insert the new line before indenting is that the
2331 ;; indenting could be confused by keywords (e.g. END) on the line
2332 ;; after the split point. This prevents us from just using
2333 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2335 (beginning-of-line 0)
2336 (idlwave-indent-line)
2338 (idlwave-indent-line))
2341 ;; Use global variable 'comment-column' to set parallel comment
2343 ;; Modeled on lisp.el
2344 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2345 (defun idlwave-comment-hook ()
2346 "Compute indent for the beginning of the IDL comment delimiter."
2347 (if (or (looking-at idlwave-no-change-comment
)
2348 (if idlwave-begin-line-comment
2349 (looking-at idlwave-begin-line-comment
)
2352 (if (looking-at idlwave-code-comment
)
2353 (if (save-excursion (skip-chars-backward " \t") (bolp))
2354 ;; On line by itself, indent as code
2355 (let ((tem (idlwave-calculate-indent)))
2356 (if (listp tem
) (car tem
) tem
))
2357 ;; after code - do not change
2359 (skip-chars-backward " \t")
2360 (max (if (bolp) 0 (1+ (current-column)))
2363 (defun idlwave-split-line ()
2364 "Continue line by breaking line at point and indent the lines.
2365 For a code line insert continuation marker. If the line is a line comment
2366 then the new line will contain a comment with the same indentation.
2367 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2370 ;; Expand abbreviation, just like normal RET would.
2371 (and abbrev-mode
(expand-abbrev))
2373 (if (not (idlwave-in-comment))
2374 ;; For code line add continuation.
2375 ;; Check if splitting a string.
2377 (if (setq beg
(idlwave-in-quote))
2378 (if idlwave-split-line-string
2379 ;; Split the string.
2380 (progn (insert (setq beg
(char-after beg
)) " + "
2381 idlwave-continuation-char beg
)
2383 (newline-and-indent)
2385 ;; Do not split the string.
2387 (message "Warning: continuation inside string!!")
2388 (insert " " idlwave-continuation-char
))
2389 ;; Not splitting a string.
2390 (if (not (member (char-before) '(?\ ?
\t)))
2392 (insert idlwave-continuation-char
)
2393 (newline-and-indent)))
2394 (indent-new-comment-line))
2395 ;; Indent previous line
2396 (setq beg
(- (point-max) (point)))
2398 (idlwave-indent-line)
2399 (goto-char (- (point-max) beg
))
2400 ;; Reindent new line
2401 (idlwave-indent-line)))
2403 (defun idlwave-beginning-of-subprogram (&optional nomark
)
2404 "Move point to the beginning of the current program unit.
2405 If NOMARK is non-nil, do not push mark."
2407 (idlwave-find-key idlwave-begin-unit-reg -
1 nomark
))
2409 (defun idlwave-end-of-subprogram (&optional nomark
)
2410 "Move point to the start of the next program unit.
2411 If NOMARK is non-nil, do not push mark."
2413 (idlwave-end-of-statement)
2414 (idlwave-find-key idlwave-end-unit-reg
1 nomark
))
2416 (defun idlwave-mark-statement ()
2417 "Mark current IDL statement."
2419 (idlwave-end-of-statement)
2420 (let ((end (point)))
2421 (idlwave-beginning-of-statement)
2422 (push-mark end nil t
)))
2424 (defun idlwave-mark-block ()
2425 "Mark containing block."
2427 (idlwave-end-of-statement)
2428 (idlwave-backward-up-block -
1)
2429 (idlwave-end-of-statement)
2430 (let ((end (point)))
2431 (idlwave-backward-block)
2432 (idlwave-beginning-of-statement)
2433 (push-mark end nil t
)))
2436 (defun idlwave-mark-subprogram ()
2437 "Put mark at beginning of program, point at end.
2438 The marks are pushed."
2440 (idlwave-end-of-statement)
2441 (idlwave-beginning-of-subprogram)
2442 (let ((beg (point)))
2443 (idlwave-forward-block)
2444 (push-mark beg nil t
))
2445 (exchange-point-and-mark))
2447 (defun idlwave-backward-up-block (&optional arg
)
2448 "Move to beginning of enclosing block if prefix ARG >= 0.
2449 If prefix ARG < 0 then move forward to enclosing block end."
2451 (idlwave-block-jump-out (- arg
) 'nomark
))
2453 (defun idlwave-beginning-of-block ()
2454 "Go to the beginning of the current block."
2456 (idlwave-block-jump-out -
1 'nomark
)
2459 (defun idlwave-end-of-block ()
2460 "Go to the beginning of the current block."
2462 (idlwave-block-jump-out 1 'nomark
)
2465 (defun idlwave-forward-block (&optional arg
)
2466 "Move across next nested block."
2468 (let ((arg (or arg
1)))
2469 (if (idlwave-down-block arg
)
2470 (idlwave-block-jump-out arg
'nomark
))))
2472 (defun idlwave-backward-block ()
2473 "Move backward across previous nested block."
2475 (if (idlwave-down-block -
1)
2476 (idlwave-block-jump-out -
1 'nomark
)))
2478 (defun idlwave-down-block (&optional arg
)
2480 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2481 Returns non-nil if successfull."
2486 (let ((eos (save-excursion
2487 (idlwave-block-jump-out -
1 'nomark
)
2489 (if (setq status
(idlwave-find-key
2490 idlwave-end-block-reg -
1 'nomark eos
))
2491 (idlwave-beginning-of-statement)
2492 (message "No nested block before beginning of containing block.")))
2494 (let ((eos (save-excursion
2495 (idlwave-block-jump-out 1 'nomark
)
2497 (if (setq status
(idlwave-find-key
2498 idlwave-begin-block-reg
1 'nomark eos
))
2499 (idlwave-end-of-statement)
2500 (message "No nested block before end of containing block."))))
2503 (defun idlwave-mark-doclib ()
2504 "Put point at beginning of doc library header, mark at end.
2505 The marks are pushed."
2509 (goto-char (point-max))
2510 (if (re-search-backward idlwave-doclib-start nil t
)
2512 (setq beg
(progn (beginning-of-line) (point)))
2513 (if (re-search-forward idlwave-doclib-end nil t
)
2516 (push-mark beg nil t
)
2517 (message "Could not find end of doc library header.")))
2518 (message "Could not find doc library header start.")
2519 (goto-char here
)))))
2521 (defun idlwave-current-routine-fullname ()
2522 (let ((name (idlwave-current-routine)))
2523 (idlwave-make-full-name (nth 2 name
) (car name
))))
2525 (defun idlwave-current-routine ()
2526 "Return (NAME TYPE CLASS) of current routine."
2529 (idlwave-beginning-of-subprogram 'nomark
)
2530 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2531 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2533 (class (idlwave-sintern-class (match-string 3)))
2534 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2535 (list name type class
)))))
2537 (defvar idlwave-shell-prompt-pattern
)
2538 (defun idlwave-beginning-of-statement ()
2539 "Move to beginning of the current statement.
2540 Skips back past statement continuations.
2541 Point is placed at the beginning of the line whether or not this is an
2545 ((eq major-mode
'idlwave-shell-mode
)
2546 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2547 (goto-char (match-end 0))))
2549 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2550 (idlwave-previous-statement)
2551 (beginning-of-line)))))
2553 (defun idlwave-previous-statement ()
2554 "Move point to beginning of the previous statement.
2555 Returns t if the current line before moving is the beginning of
2556 the first non-comment statement in the file, and nil otherwise."
2558 (let (first-statement)
2559 (if (not (= (forward-line -
1) 0))
2560 ;; first line in file
2562 ;; skip blank lines, label lines, include lines and line comments
2564 ;; The current statement is the first statement until we
2565 ;; reach another statement.
2566 (setq first-statement
2568 (looking-at idlwave-comment-line-start-skip
)
2569 (looking-at "[ \t]*$")
2570 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2572 (= (forward-line -
1) 0)))
2573 ;; skip continuation lines
2577 (idlwave-is-continuation-line))
2578 (= (forward-line -
1) 0)))
2581 (defun idlwave-end-of-statement ()
2582 "Move point to the end of the current IDL statement.
2583 If not in a statement just moves to end of line. Returns position."
2585 (while (and (idlwave-is-continuation-line)
2586 (= (forward-line 1) 0))
2587 (while (and (idlwave-is-comment-or-empty-line)
2588 (= (forward-line 1) 0))))
2592 (defun idlwave-end-of-statement0 ()
2593 "Move point to the end of the current IDL statement.
2594 If not in a statement just moves to end of line. Returns position."
2596 (while (and (idlwave-is-continuation-line)
2597 (= (forward-line 1) 0)))
2601 (defun idlwave-next-statement ()
2602 "Move point to beginning of the next IDL statement.
2603 Returns t if that statement is the last non-comment IDL statement
2604 in the file, and nil otherwise."
2606 (let (last-statement)
2607 (idlwave-end-of-statement)
2608 ;; skip blank lines, label lines, include lines and line comments
2609 (while (and (= (forward-line 1) 0)
2610 ;; The current statement is the last statement until
2611 ;; we reach a new statement.
2612 (setq last-statement
2614 (looking-at idlwave-comment-line-start-skip
)
2615 (looking-at "[ \t]*$")
2616 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2617 (looking-at "^@")))))
2620 (defun idlwave-skip-multi-commands (&optional lim
)
2621 "Skip past multiple commands on a line (with `&')."
2622 (let ((save-point (point)))
2623 (when (re-search-forward ".*&" lim t
)
2624 (goto-char (match-end 0))
2625 (if (idlwave-quoted)
2626 (goto-char save-point
)
2627 (if (eq (char-after (- (point) 2)) ?
&) (goto-char save-point
))))
2630 (defun idlwave-skip-label-or-case ()
2631 "Skip label or case statement element.
2632 Returns position after label.
2633 If there is no label point is not moved and nil is returned."
2634 ;; Case expressions and labels are terminated by a colon.
2635 ;; So we find the first colon in the line and make sure
2636 ;; - no `?' is before it (might be a ? b : c)
2637 ;; - it is not in a comment
2638 ;; - not in a string constant
2639 ;; - not in parenthesis (like a[0:3])
2640 ;; - not followed by another ":" in explicit class, ala a->b::c
2641 ;; As many in this mode, this function is heuristic and not an exact
2643 (let* ((start (point))
2644 (eos (save-excursion (idlwave-end-of-statement) (point)))
2645 (end (idlwave-find-key ":" 1 'nomark eos
)))
2647 (= (nth 0 (parse-partial-sexp start end
)) 0)
2648 (not (string-match "\\?" (buffer-substring start end
)))
2649 (not (string-match "^::" (buffer-substring end eos
))))
2656 (defun idlwave-start-of-substatement (&optional pre
)
2657 "Move to start of next IDL substatement after point.
2658 Uses the type of the current IDL statement to determine if the next
2659 statement is on a new line or is a subpart of the current statement.
2660 Returns point at start of substatement modulo whitespace.
2661 If optional argument is non-nil move to beginning of current
2663 (let ((orig (point))
2664 (eos (idlwave-end-of-statement))
2667 (idlwave-beginning-of-statement)
2668 (idlwave-skip-label-or-case)
2669 (if (< (point) orig
)
2670 (idlwave-skip-multi-commands orig
))
2672 ;; Continue looking for substatements until we are past orig
2673 (while (and (<= (point) orig
) (not (eobp)))
2675 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2676 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2678 (idlwave-find-key nst
1 'nomark eos
))
2679 (goto-char (match-end 0)))
2680 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2681 (setq ifnest
(1- ifnest
))
2682 (goto-char (match-end 0)))
2684 (idlwave-next-statement))))
2685 (if pre
(goto-char last
))
2686 ;; If a continuation line starts here, move to next line
2687 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2688 (beginning-of-line 2))
2691 (defun idlwave-statement-type ()
2692 "Return the type of the current IDL statement.
2693 Uses `idlwave-statement-match' to return a cons of (type . point) with
2694 point the ending position where the type was determined. Type is the
2695 association from `idlwave-statement-match', i.e. the cons cell from the
2696 list not just the type symbol. Returns nil if not an identifiable
2699 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2700 ;; and possibly comments
2701 (while (looking-at "[ \t]*\\$")
2703 (skip-chars-forward " \t")
2704 (let ((st idlwave-statement-match
)
2705 (case-fold-search t
))
2706 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2707 (setq st
(cdr st
))))
2709 (append st
(match-end 0))))))
2711 (defun idlwave-expand-equal (&optional before after is-action
)
2712 "Pad '=' with spaces.
2713 Two cases: Assignment statement, and keyword assignment.
2714 Which case is determined using `idlwave-start-of-substatement' and
2715 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2716 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2717 is treated just like assignment statements. When nil, spaces are
2718 removed for keyword assignment. Any other value keeps the current space
2719 around the `='. Limits in for loops are treated as keyword assignment.
2721 Starting with IDL 6.0, a number of op= assignments are available.
2722 Since ambiguities of the form:
2727 can occur, alphanumeric operator assignment will never be pre-padded,
2728 only post-padded. You must use a space before these to disambiguate
2729 \(not just for padding, but for proper parsing by IDL too!). Other
2730 operators, such as ##=, ^=, etc., will be pre-padded.
2732 IS-ACTION is ignored.
2734 See `idlwave-surround'."
2735 (if idlwave-surround-by-blank
2737 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2739 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2743 (let ((case-fold-search t
))
2746 (re-search-backward non-an-ops nil t
)
2747 ;; Why doesn't ##? work for both?
2748 (re-search-backward "\\(#\\)\\=" nil t
))
2749 (setq len
(1+ (length (match-string 1))))
2750 (when (re-search-backward an-ops nil t
)
2751 ;(setq begin nil) ; won't modify begin
2752 (setq len
(1+ (length (match-string 1))))))))
2754 (if (eq t idlwave-pad-keyword
)
2755 ;; Everything gets padded equally
2756 (idlwave-surround before after len
)
2757 ;; Treating keywords/for variables specially...
2758 (let ((st (save-excursion ; To catch "for" variables
2759 (idlwave-start-of-substatement t
)
2760 (idlwave-statement-type)))
2761 (what (save-excursion ; To catch keywords
2762 (skip-chars-backward "= \t")
2763 (nth 2 (idlwave-where)))))
2764 (cond ((or (memq what
'(function-keyword procedure-keyword
))
2765 (memq (caar st
) '(for pdef
)))
2767 ((null idlwave-pad-keyword
)
2768 (idlwave-surround 0 0)
2770 (t))) ; leave any spaces alone
2771 (t (idlwave-surround before after len
))))))))
2774 (defun idlwave-indent-and-action (&optional arg
)
2775 "Call `idlwave-indent-line' and do expand actions.
2776 With prefix ARG non-nil, indent the entire sub-statement."
2779 (if (and idlwave-expand-generic-end
2780 (re-search-backward "\\<\\(end\\)\\s-*\\="
2781 (max 0 (- (point) 10)) t
)
2782 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2783 (progn (goto-char (match-end 1))
2784 ;;Expand the END abbreviation, just as RET or Space would have.
2785 (if abbrev-mode
(expand-abbrev)
2786 (idlwave-show-begin)))))
2787 (when (and (not arg
) current-prefix-arg
)
2788 (setq arg current-prefix-arg
)
2789 (setq current-prefix-arg nil
))
2791 (idlwave-indent-statement)
2792 (idlwave-indent-line t
)))
2794 (defun idlwave-indent-line (&optional expand
)
2795 "Indent current IDL line as code or as a comment.
2796 The actions in `idlwave-indent-action-table' are performed.
2797 If the optional argument EXPAND is non-nil then the actions in
2798 `idlwave-indent-expand-table' are performed."
2800 ;; Move point out of left margin.
2802 (skip-chars-backward " \t")
2804 (skip-chars-forward " \t"))
2805 (let ((mloc (point-marker)))
2808 (if (looking-at idlwave-comment-line-start-skip
)
2809 ;; Indentation for a line comment
2811 (skip-chars-forward " \t")
2812 (idlwave-indent-left-margin (idlwave-comment-hook)))
2816 ;; Before indenting, run action routines.
2818 (if (and expand idlwave-do-actions
)
2819 (mapc 'idlwave-do-action idlwave-indent-expand-table
))
2821 (if idlwave-do-actions
2822 (mapc 'idlwave-do-action idlwave-indent-action-table
))
2824 ;; No longer expand abbrevs on the line. The user can do this
2825 ;; manually using expand-region-abbrevs.
2827 ;; Indent for code line
2832 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2834 (looking-at "^[ \t]*@"))
2838 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2839 ;; Adjust parallel comment
2841 (if (idlwave-in-comment)
2842 ;; Emacs 21 is too smart with fill-column on comment indent
2843 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2846 (indent-for-comment)))))
2848 ;; Get rid of marker
2849 (set-marker mloc nil
)))
2851 (defun idlwave-do-action (action)
2852 "Perform an action repeatedly on a line.
2853 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2854 either a function name to be called with `funcall' or a list to be
2855 evaluated with `eval'. The action performed by FUNC should leave
2856 point after the match for REG - otherwise an infinite loop may be
2857 entered. FUNC is always passed a final argument of 'is-action, so it
2858 can discriminate between being run as an action, or a key binding."
2859 (let ((action-key (car action
))
2860 (action-routine (cdr action
)))
2862 (while (idlwave-look-at action-key
)
2863 (if (listp action-routine
)
2864 (eval (append action-routine
'('is-action
)))
2865 (funcall action-routine
'is-action
)))))
2867 (defun idlwave-indent-to (col &optional min
)
2868 "Indent from point with spaces until column COL.
2869 Inserts space before markers at point."
2870 (if (not min
) (setq min
0))
2871 (insert-before-markers
2872 (make-string (max min
(- col
(current-column))) ?\
)))
2874 (defun idlwave-indent-left-margin (col)
2875 "Indent the current line to column COL.
2876 Indents such that first non-whitespace character is at column COL
2877 Inserts spaces before markers at point."
2880 (delete-horizontal-space)
2881 (idlwave-indent-to col
)))
2883 (defun idlwave-indent-subprogram ()
2884 "Indent program unit which contains point."
2887 (idlwave-end-of-statement)
2888 (idlwave-beginning-of-subprogram)
2889 (let ((beg (point)))
2890 (idlwave-forward-block)
2891 (message "Indenting subprogram...")
2892 (indent-region beg
(point) nil
))
2893 (message "Indenting subprogram...done.")))
2895 (defun idlwave-indent-statement ()
2896 "Indent current statement, including all continuation lines."
2899 (idlwave-beginning-of-statement)
2900 (let ((beg (point)))
2901 (idlwave-end-of-statement)
2902 (indent-region beg
(point) nil
))))
2904 (defun idlwave-calculate-indent ()
2905 "Return appropriate indentation for current line as IDL code."
2909 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2911 ((idlwave-look-at idlwave-begin-unit-reg
)
2913 ;; Check for continuation line
2915 (and (= (forward-line -
1) 0)
2916 (idlwave-is-continuation-line)))
2917 (idlwave-calculate-cont-indent))
2918 ;; calculate indent based on previous and current statements
2919 (t (let* (beg-prev-pos
2921 ;; calculate indent based on previous statement
2924 ;; Beginning of file
2926 (idlwave-previous-statement)
2927 (setq beg-prev-pos
(point)))
2930 ((idlwave-look-at idlwave-begin-unit-reg t
)
2931 (+ (idlwave-current-statement-indent)
2932 idlwave-main-block-indent
))
2934 ((idlwave-look-at idlwave-begin-block-reg t
)
2935 (+ (idlwave-min-current-statement-indent)
2936 idlwave-block-indent
))
2938 ((idlwave-look-at idlwave-end-block-reg t
)
2940 ;; Match to the *beginning* of the block opener
2941 (goto-char beg-prev-pos
)
2942 (idlwave-block-jump-out -
1 'nomark
) ; go to begin block
2943 (idlwave-min-current-statement-indent)))
2944 ;; idlwave-end-offset
2945 ;; idlwave-block-indent))
2947 ;; Default to current indent
2948 ((idlwave-current-statement-indent))))))
2949 ;; adjust the indentation based on the current statement
2952 ((idlwave-look-at idlwave-end-block-reg
)
2953 (+ the-indent idlwave-end-offset
))
2957 ;; Parentheses indent
2960 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2961 "Calculate the continuation indent inside a paren group.
2962 Returns a cons-cell with (open . indent), where open is the
2963 location of the open paren."
2964 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2965 ;; Found an innermost open paren.
2968 ;; Line up with next word unless this is a closing paren.
2971 ;; Plain Kernighan-style nested indent
2972 (idlwave-indent-parens-nested
2973 (+ idlwave-continuation-indent
(idlwave-current-indent)))
2975 ;; This is a closed paren - line up under open paren.
2979 ;; Empty (or just comment) follows -- revert to basic indent
2983 (looking-at "[ \t$]*\\(;.*\\)?$"))
2986 ;; Line up with first word after any blank space
2988 (skip-chars-forward " \t")
2989 (current-column))))))))
2991 (defun idlwave-calculate-cont-indent ()
2992 "Calculates the IDL continuation indent column from the previous statement.
2993 Note that here previous statement usually means the beginning of the
2994 current statement if this statement is a continuation of the previous
2995 line. Various special types of continuations, including assignments,
2996 routine definitions, and parenthetical groupings, are treated separately."
2998 (let* ((case-fold-search t
)
2999 (end-reg (progn (beginning-of-line) (point)))
3000 (beg-last-statement (save-excursion (idlwave-previous-statement)
3002 (beg-reg (progn (idlwave-start-of-substatement 'pre
)
3003 (if (eq (line-beginning-position) end-reg
)
3004 (goto-char beg-last-statement
)
3006 (basic-indent (+ (idlwave-min-current-statement-indent end-reg
)
3007 idlwave-continuation-indent
))
3008 fancy-nonparen-indent fancy-paren-indent
)
3010 ;; Align then with its matching if, etc.
3011 ((let ((matchers '(("\\<if\\>" .
"[ \t]*then")
3012 ("\\<\\(if\\|end\\(if\\)?\\)\\>" .
"[ \t]*else")
3013 ("\\<\\(for\\|while\\)\\>" .
"[ \t]*do")
3014 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3016 ("\\<case\\>" .
"[ \t]*of")))
3022 (while (setq match
(car matchers
))
3023 (if (looking-at (cdr match
))
3024 (throw 'exit
(car match
)))
3025 (setq matchers
(cdr matchers
)))))
3026 (idlwave-find-key cont-re -
1 'nomark beg-last-statement
)))
3027 (if (looking-at "end") ;; that one's special
3028 (- (idlwave-current-indent)
3029 (+ idlwave-block-indent idlwave-end-offset
))
3030 (idlwave-current-indent)))
3032 ;; Indent in from the previous line for continuing statements
3033 ((let ((matchers '("\\<then\\>"
3040 (if (/= (forward-line -
1) 0)
3042 (while (setq match
(car matchers
))
3043 (if (looking-at (concat ".*" match
"[ \t]*\\$[ \t]*"
3046 (setq matchers
(cdr matchers
)))))
3047 (+ idlwave-continuation-indent
(idlwave-current-indent)))
3049 ;; Parenthetical indent, either traditional or Kernighan style
3050 ((setq fancy-paren-indent
3051 (let* ((end-reg end-reg
)
3054 (skip-chars-forward " \t")
3055 (looking-at "\\s)")))
3058 (while (setq indent-cons
(idlwave-calculate-paren-indent
3059 beg-reg end-reg close-exp
))
3060 ;; First permitted containing paren
3062 idlwave-indent-to-open-paren
3063 idlwave-indent-parens-nested
3064 (null (cdr indent-cons
))
3065 (< (- (cdr indent-cons
) basic-indent
)
3066 idlwave-max-extra-continuation-indent
))
3067 (throw 'loop
(cdr indent-cons
)))
3068 (setq end-reg
(car indent-cons
))))))
3071 ;; A continued assignment, or procedure call/definition
3073 (> idlwave-max-extra-continuation-indent
0)
3074 (setq fancy-nonparen-indent
3077 (while (idlwave-look-at "&")) ; skip continued statements
3079 ;; A continued Procedure call or definition
3081 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3082 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3083 (goto-char (match-end 0))
3084 ;; Comment only, or blank line with "$"? Basic indent.
3085 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3089 ;; Continued assignment (with =):
3091 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3092 (goto-char (match-end 0))
3093 (if (null (idlwave-what-function beg-reg
))
3094 (throw 'assign t
))))
3097 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3099 (goto-char beg-last-statement
)
3100 (eq (caar (idlwave-statement-type)) 'for
)))
3101 (current-column))))))
3102 (< (- fancy-nonparen-indent basic-indent
)
3103 idlwave-max-extra-continuation-indent
))
3104 (if fancy-paren-indent
;calculated but disallowed paren indent
3105 (+ fancy-nonparen-indent idlwave-continuation-indent
)
3106 fancy-nonparen-indent
))
3108 ;; Basic indent, by default
3109 (t basic-indent
)))))
3113 (defun idlwave-find-key (key-re &optional dir nomark limit
)
3114 "Move to next match of the regular expression KEY-RE.
3115 Matches inside comments or string constants will be ignored.
3116 If DIR is negative, the search will be backwards.
3117 At a successful match, the mark is pushed unless NOMARK is non-nil.
3118 Searches are limited to LIMIT.
3119 Searches are case-insensitive and use a special syntax table which
3120 treats `$' and `_' as word characters.
3121 Return value is the beginning of the match or (in case of failure) nil."
3122 (setq dir
(or dir
0))
3123 (let ((case-fold-search t
)
3124 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3126 (idlwave-with-special-syntax
3129 (while (funcall search-func key-re limit t
)
3130 (if (not (idlwave-quoted))
3131 (throw 'exit
(setq found
(match-beginning 0)))
3132 (if (or (and (> dir
0) (eobp))
3133 (and (< dir
0) (bobp)))
3134 (throw 'exit nil
)))))))
3137 (if (not nomark
) (push-mark))
3142 (defun idlwave-block-jump-out (&optional dir nomark
)
3143 "When optional argument DIR is non-negative, move forward to end of
3144 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3145 regular expressions. When DIR is negative, move backwards to block beginning.
3146 Recursively calls itself to skip over nested blocks. DIR defaults to
3147 forward. Calls `push-mark' unless the optional argument NOMARK is
3148 non-nil. Movement is limited by the start of program units because of
3149 possibility of unbalanced blocks."
3151 (or dir
(setq dir
0))
3152 (let* ((here (point))
3153 (case-fold-search t
)
3154 (limit (if (>= dir
0) (point-max) (point-min)))
3155 (block-limit (if (>= dir
0)
3156 idlwave-begin-block-reg
3157 idlwave-end-block-reg
))
3159 (block-reg (concat idlwave-begin-block-reg
"\\|"
3160 idlwave-end-block-reg
))
3161 (unit-limit (or (save-excursion
3164 idlwave-begin-unit-reg dir t limit
)
3167 idlwave-end-unit-reg dir t limit
)))
3169 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3170 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3171 (while (and found
(looking-at block-limit
))
3172 (if (>= dir
0) (forward-word 1))
3173 (idlwave-block-jump-out dir t
)
3174 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3175 (if (not nomark
) (push-mark here
))
3176 (if (not found
) (goto-char unit-limit
)
3177 (if (>= dir
0) (forward-word 1)))))
3179 (defun idlwave-min-current-statement-indent (&optional end-reg
)
3180 "The minimum indent in the current statement."
3181 (idlwave-beginning-of-statement)
3182 (if (not (idlwave-is-continuation-line))
3183 (idlwave-current-indent)
3184 (let ((min (idlwave-current-indent)) comm-or-empty
)
3185 (while (and (= (forward-line 1) 0)
3186 (or (setq comm-or-empty
(idlwave-is-comment-or-empty-line))
3187 (idlwave-is-continuation-line))
3188 (or (null end-reg
) (< (point) end-reg
)))
3189 (unless comm-or-empty
(setq min
(min min
(idlwave-current-indent)))))
3190 (if (or comm-or-empty
(and end-reg
(>= (point) end-reg
)))
3192 (min min
(idlwave-current-indent))))))
3194 (defun idlwave-current-statement-indent (&optional last-line
)
3195 "Return indentation of the current statement.
3196 If in a statement, moves to beginning of statement before finding indent."
3198 (idlwave-end-of-statement)
3199 (idlwave-beginning-of-statement))
3200 (idlwave-current-indent))
3202 (defun idlwave-current-indent ()
3203 "Return the column of the indentation of the current line.
3204 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3207 (skip-chars-forward " \t")
3208 ;; if we are at the end of blank line return 0
3210 ((current-column)))))
3212 (defun idlwave-is-continuation-line ()
3213 "Test if current line is continuation line.
3214 Blank or comment-only lines following regular continuation lines (with
3215 `$') count as continuations too."
3219 (idlwave-look-at "\\<\\$")
3221 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3222 (eq (forward-line -
1) 0))
3223 (if (setq p
(idlwave-look-at "\\<\\$")) (throw 'loop p
))))))))
3225 (defun idlwave-is-comment-line ()
3226 "Test if the current line is a comment line."
3228 (beginning-of-line 1)
3229 (looking-at "[ \t]*;")))
3231 (defun idlwave-is-comment-or-empty-line ()
3232 "Test if the current line is a comment line."
3234 (beginning-of-line 1)
3235 (looking-at "[ \t]*[;\n]")))
3237 (defun idlwave-look-at (regexp &optional cont beg
)
3238 "Search current line from current point for REGEXP.
3239 If optional argument CONT is non-nil, searches to the end of
3240 the current statement.
3241 If optional arg BEG is non-nil, search starts from the beginning of the
3243 Ignores matches that end in a comment or inside a string expression.
3244 Returns point if successful, nil otherwise.
3245 This function produces unexpected results if REGEXP contains quotes or
3246 a comment delimiter. The search is case insensitive.
3247 If successful leaves point after the match, otherwise, does not move point."
3248 (let ((here (point))
3249 (case-fold-search t
)
3250 (eos (save-excursion
3251 (if cont
(idlwave-end-of-statement) (end-of-line))
3254 (idlwave-with-special-syntax
3255 (if beg
(idlwave-beginning-of-statement))
3256 (while (and (setq found
(re-search-forward regexp eos t
))
3258 (if (not found
) (goto-char here
))
3261 (defun idlwave-fill-paragraph (&optional nohang
)
3262 "Fill paragraphs in comments.
3263 A paragraph is made up of all contiguous lines having the same comment
3264 leader (the leading whitespace before the comment delimiter and the
3265 comment delimiter). In addition, paragraphs are separated by blank
3266 line comments. The indentation is given by the hanging indent of the
3267 first line, otherwise by the minimum indentation of the lines after
3268 the first line. The indentation of the first line does not change.
3269 Does not effect code lines. Does not fill comments on the same line
3270 with code. The hanging indent is given by the end of the first match
3271 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3272 If the optional argument NOHANG is non-nil then the hanging indent is
3275 ;; check if this is a line comment
3278 (skip-chars-forward " \t")
3279 (looking-at comment-start
))
3282 pre here diff fill-prefix-reg bcl first-indent
3284 ;; Change tabs to spaces in the surrounding paragraph.
3285 ;; The surrounding paragraph will be the largest containing block of
3286 ;; contiguous line comments. Thus, we may be changing tabs in
3287 ;; a much larger area than is needed, but this is the easiest
3288 ;; brute force way to do it.
3290 ;; This has the undesirable side effect of replacing the tabs
3291 ;; permanently without the user's request or knowledge.
3293 (backward-paragraph)
3294 (setq start
(point)))
3298 (untabify start end
)
3304 (concat "^[ \t]*" comment-start
"+")
3305 (save-excursion (end-of-line) (point))
3307 ;; Get the comment leader on the line and its length
3308 (setq pre
(current-column))
3309 ;; the comment leader is the indentation plus exactly the
3310 ;; number of consecutive ";".
3311 (setq fill-prefix-reg
3315 (buffer-substring (save-excursion
3316 (beginning-of-line) (point))
3320 ;; Mark the beginning and end of the paragraph
3322 (while (and (looking-at fill-prefix-reg
)
3323 (not (looking-at paragraph-separate
))
3326 ;; Move to first line of paragraph
3327 (if (/= (point) bcl
)
3329 (setq start
(point))
3331 (while (and (looking-at fill-prefix-reg
)
3332 (not (looking-at paragraph-separate
))
3336 (if (or (not (looking-at fill-prefix-reg
))
3337 (looking-at paragraph-separate
))
3340 ;; if at end of buffer add a newline (need this because
3341 ;; fill-region needs END to be at the beginning of line after
3342 ;; the paragraph or it will add a line).
3344 (progn (insert ?
\n) (backward-char 1)))
3345 ;; Set END to the beginning of line after the paragraph
3346 ;; END is calculated as distance from end of buffer
3347 (setq end
(- (point-max) (point) 1))
3349 ;; Calculate the indentation for the paragraph.
3351 ;; In the following while statements, after one iteration
3352 ;; point will be at the beginning of a line in which case
3353 ;; the while will not be executed for the
3354 ;; the first paragraph line and thus will not affect the
3357 ;; First check to see if indentation is based on hanging indent.
3358 (if (and (not nohang
) idlwave-hanging-indent
3362 (idlwave-calc-hanging-indent))))
3363 ;; Adjust lines of paragraph by inserting spaces so that
3364 ;; each line's indent is at least as great as the hanging
3365 ;; indent. This is needed for fill-paragraph to work with
3370 (while (> (point) start
)
3371 (re-search-forward comment-start-skip
3372 (save-excursion (end-of-line) (point))
3374 (if (> (setq diff
(- indent
(current-column))) 0)
3376 (if (>= here
(point))
3377 ;; adjust the original location for the
3379 (setq here
(+ here diff
)))
3380 (insert (make-string diff ?\
))))
3384 ;; No hang. Instead find minimum indentation of paragraph
3385 ;; after first line.
3386 ;; For the following while statement, since START is at the
3387 ;; beginning of line and END is at the end of line
3388 ;; point is greater than START at least once (which would
3389 ;; be the case for a single line paragraph).
3390 (while (> (point) start
)
3397 (save-excursion (end-of-line) (point))
3402 (setq fill-prefix
(concat fill-prefix
3403 (make-string (- indent pre
)
3405 ;; first-line indent
3411 (save-excursion (end-of-line) (point))
3416 ;; try to keep point at its original place
3419 ;; In place of the more modern fill-region-as-paragraph, a hack
3420 ;; to keep whitespace untouched on the first line within the
3421 ;; indent length and to preserve any indent on the first line
3425 (buffer-substring start
(+ start first-indent -
1)))
3426 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3427 (fill-region-as-paragraph
3430 (current-justification)
3432 (delete-region start
(+ start first-indent -
1))
3435 ;; When we want the point at the beginning of the comment
3436 ;; body fill-region will put it at the beginning of the line.
3437 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3438 (setq fill-prefix nil
))))
3440 (defun idlwave-calc-hanging-indent ()
3441 "Calculate the position of the hanging indent for the comment paragraph.
3442 The hanging indent position is given by the first match with the
3443 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3444 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3446 If not found returns nil."
3447 (if idlwave-use-last-hang-indent
3450 (if (re-search-backward
3451 idlwave-hang-indent-regexp
3452 (save-excursion (beginning-of-line) (point))
3454 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3457 (if (re-search-forward
3458 idlwave-hang-indent-regexp
3459 (save-excursion (end-of-line) (point))
3461 (current-column)))))
3463 (defun idlwave-auto-fill ()
3464 "Called to break lines in auto fill mode.
3465 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3466 non-nil. Places a continuation character at the end of the line if
3467 not in a comment. Splits strings with IDL concatenation operator `+'
3468 if `idlwave-auto-fill-split-string' is non-nil."
3469 (if (<= (current-column) fill-column
)
3470 nil
; do not to fill
3471 (if (or (not idlwave-fill-comment-line-only
)
3473 ;; Check for comment line
3475 (looking-at idlwave-comment-line-start-skip
)))
3477 (idlwave-indent-line)
3478 ;; Prevent actions do-auto-fill which calls indent-line-function.
3479 (let (idlwave-do-actions
3480 (paragraph-separate ".")
3481 (fill-nobreak-predicate
3482 (if (and (idlwave-in-quote)
3483 idlwave-auto-fill-split-string
)
3484 (lambda () ;; We'll need 5 spaces for " ' + $"
3485 (<= (- fill-column
(current-column)) 5)
3490 ;; Indent the split line
3491 (idlwave-indent-line))
3494 (looking-at idlwave-comment-line-start-skip
))
3495 ;; A continued line comment
3496 ;; We treat continued line comments as part of a comment
3497 ;; paragraph. So we check for a hanging indent.
3498 (if idlwave-hanging-indent
3499 (let ((here (- (point-max) (point)))
3503 (idlwave-calc-hanging-indent))))
3506 ;; Remove whitespace between comment delimiter and
3507 ;; text, insert spaces for appropriate indentation.
3511 (save-excursion (end-of-line) (point)) t
)
3512 (delete-horizontal-space)
3513 (idlwave-indent-to indent
)
3514 (goto-char (- (point-max) here
)))
3516 ;; Split code or comment?
3519 (idlwave-in-comment))
3520 ;; Splitting a non-full-line comment.
3521 ;; Insert the comment delimiter from split line
3525 (skip-chars-forward " \t")
3526 ;; Insert blank to keep off beginning of line
3530 (buffer-substring (idlwave-goto-comment)
3532 (skip-chars-forward "; ")
3534 (idlwave-indent-line))
3535 ;; Split code line - add continuation character
3538 ;; Check to see if we split a string
3539 (if (and (setq beg
(idlwave-in-quote))
3540 idlwave-auto-fill-split-string
)
3541 ;; Split the string and concatenate.
3542 ;; The first extra space is for the space
3543 ;; the line was split. That space was removed.
3544 (insert " " (char-after beg
) " +"))
3547 (if idlwave-auto-fill-split-string
3548 ;; Make the second part of continued string
3551 (skip-chars-forward " \t")
3552 (insert (char-after beg
)))
3555 (message "Warning: continuation inside a string.")))
3556 ;; Although do-auto-fill (via indent-new-comment-line) calls
3557 ;; idlwave-indent-line for the new line, re-indent again
3558 ;; because of the addition of the continuation character.
3559 (idlwave-indent-line))
3562 (defun idlwave-auto-fill-mode (arg)
3563 "Toggle auto-fill mode for IDL mode.
3564 With arg, turn auto-fill mode on if arg is positive.
3565 In auto-fill mode, inserting a space at a column beyond `fill-column'
3566 automatically breaks the line at a previous space."
3568 (prog1 (set idlwave-fill-function
3570 (not (symbol-value idlwave-fill-function
))
3571 (> (prefix-numeric-value arg
) 0))
3575 (set-buffer-modified-p (buffer-modified-p))))
3577 ;(defun idlwave-fill-routine-call ()
3578 ; "Fill a routine definition or statement, indenting appropriately."
3579 ; (let ((where (idlwave-where)))))
3582 (defun idlwave-doc-header (&optional nomark
)
3583 "Insert a documentation header at the beginning of the unit.
3584 Inserts the value of the variable `idlwave-file-header'. Sets mark
3585 before moving to do insertion unless the optional prefix argument
3588 (or nomark
(push-mark))
3589 ;; make sure we catch the current line if it begins the unit
3590 (if idlwave-header-to-beginning-of-file
3591 (goto-char (point-min))
3593 (idlwave-beginning-of-subprogram)
3595 ;; skip function or procedure line
3596 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3598 (idlwave-end-of-statement)
3599 (if (> (forward-line 1) 0) (insert "\n")))))
3600 (let ((pos (point)))
3601 (if idlwave-file-header
3602 (cond ((car idlwave-file-header
)
3603 (insert-file-contents (car idlwave-file-header
)))
3604 ((stringp (car (cdr idlwave-file-header
)))
3605 (insert (car (cdr idlwave-file-header
))))))
3608 (defun idlwave-default-insert-timestamp ()
3609 "Default timestamp insertion function."
3610 (insert (current-time-string))
3611 (insert ", " (user-full-name))
3612 (if (boundp 'user-mail-address
)
3613 (insert " <" user-mail-address
">")
3614 (insert " <" (user-login-name) "@" (system-name) ">"))
3615 ;; Remove extra spaces from line
3616 (idlwave-fill-paragraph)
3617 ;; Insert a blank line comment to separate from the date entry -
3618 ;; will keep the entry from flowing onto date line if re-filled.
3619 (insert "\n;\n;\t\t"))
3621 (defun idlwave-doc-modification ()
3622 "Insert a brief modification log at the beginning of the current program.
3623 Looks for an occurrence of the value of user variable
3624 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3625 name and places the point for the user to add a log. Before moving, saves
3626 location on mark ring so that the user can return to previous point."
3630 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3632 (goto-char (point-min))
3633 (re-search-forward idlwave-doclib-start nil t
)))
3634 (setq beg
(match-beginning 0))
3635 (re-search-forward idlwave-doclib-end nil t
)
3636 (setq end
(match-end 0)))
3639 (if (re-search-forward
3640 (concat idlwave-doc-modifications-keyword
":")
3645 (insert "\n" comment-start
"\n")
3646 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3648 (run-hooks 'idlwave-timestamp-hook
))
3649 (error "No valid DOCLIB header"))))
3653 ;;; Interface to expand-region-abbrevs which did not work when the
3654 ;;; abbrev hook associated with an abbrev moves point backwards
3655 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3656 ;;; The original would enter an infinite loop in attempting to expand
3657 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3658 ;;; because the point would keep going back to the beginning of the
3659 ;;; abbrev instead of to the end of the abbrev). We now keep the
3660 ;;; abbrev hook from moving backwards.
3662 (defun idlwave-expand-region-abbrevs (start end
)
3663 "Expand each abbrev occurrence in the region.
3664 Calling from a program, arguments are START END."
3667 (goto-char (min start end
))
3668 (let ((idlwave-show-block nil
) ;Do not blink
3669 (idlwave-abbrev-move nil
)) ;Do not move
3670 (expand-region-abbrevs start end
'noquery
))))
3672 (defun idlwave-quoted ()
3673 "Return t if point is in a comment or quoted string.
3674 Returns nil otherwise."
3675 (or (idlwave-in-comment) (idlwave-in-quote)))
3677 (defun idlwave-in-quote ()
3678 "Return location of the opening quote
3679 if point is in a IDL string constant, nil otherwise.
3680 Ignores comment delimiters on the current line.
3681 Properly handles nested quotation marks and octal
3682 constants - a double quote followed by an octal digit."
3683 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3684 ;;; double quote followed by an octal digit to be an octal constant
3685 ;;; rather than a string. Therefore, there is no terminating double
3688 ;; Because single and double quotes can quote each other we must
3689 ;; search for the string start from the beginning of line.
3690 (let* ((start (point))
3691 (eol (progn (end-of-line) (point)))
3692 (bq (progn (beginning-of-line) (point)))
3697 (while (< endq start
)
3698 ;; Find string start
3699 ;; Don't find an octal constant beginning with a double quote
3700 (if (re-search-forward "[\"']" eol
'lim
)
3701 ;; Find the string end.
3702 ;; In IDL, two consecutive delimiters after the start of a
3704 ;; escape for the delimiter in the string.
3705 ;; Two consecutive delimiters alone (i.e., not after the
3706 ;; start of a string) is the null string.
3708 ;; Move to position after quote
3709 (goto-char (1+ (match-beginning 0)))
3710 (setq bq
(1- (point)))
3711 ;; Get the string delimiter
3712 (setq delim
(char-to-string (preceding-char)))
3713 ;; Check for null string
3714 (if (looking-at delim
)
3715 (progn (setq endq
(point)) (forward-char 1))
3716 ;; Look for next unpaired delimiter
3717 (setq found
(search-forward delim eol
'lim
))
3718 (while (looking-at delim
)
3720 (setq found
(search-forward delim eol
'lim
)))
3722 (setq endq
(- (point) 1))
3723 (setq endq
(point)))
3725 (progn (setq bq
(point)) (setq endq
(point)))))
3726 (store-match-data data
)
3727 ;; return string beginning position or nil
3728 (if (> start bq
) bq
))))
3730 (defun idlwave-is-pointer-dereference (&optional limit
)
3731 "Determine if the character after point is a pointer dereference *."
3732 (let ((pos (point)))
3734 (eq (char-after) ?\
*)
3735 (not (idlwave-in-quote))
3738 (re-search-backward (concat "\\(" idlwave-idl-keywords
3739 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3742 ;; Statement templates
3744 ;; Replace these with a general template function, something like
3745 ;; expand.el (I think there was also something with a name similar to
3748 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3749 "Build a template with optional prompt expression.
3751 Opens a line if point is not followed by a newline modulo intervening
3752 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3753 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3754 adjusted according to `idlwave-abbrev-change-case'. If optional
3755 argument PROMPT is a string then it is displayed as a message in the
3756 minibuffer. The PROMPT serves as a reminder to the user of an
3757 expression to enter.
3759 The lines containing S1 and S2 are reindented using `indent-region'
3760 unless the optional second argument NOINDENT is non-nil."
3761 (if (eq major-mode
'idlwave-shell-mode
)
3762 ;; This is a gross hack to avoit template abbrev expansion
3763 ;; in the shell. FIXME: This is a dirty hack.
3764 (if (and (eq this-command
'self-insert-command
)
3765 (equal last-abbrev-location
(point)))
3766 (insert last-abbrev-text
)
3767 (error "No templates in idlwave-shell"))
3768 (cond ((eq idlwave-abbrev-change-case
'down
)
3769 (setq s1
(downcase s1
) s2
(downcase s2
)))
3770 (idlwave-abbrev-change-case
3771 (setq s1
(upcase s1
) s2
(upcase s2
))))
3772 (let ((beg (save-excursion (beginning-of-line) (point)))
3774 (if (not (looking-at "\\s-*\n"))
3781 (indent-region beg end nil
))
3782 (if (stringp prompt
)
3783 (message "%s" prompt
)))))
3785 (defun idlwave-rw-case (string)
3786 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3787 (if idlwave-reserved-word-upcase
3791 (defun idlwave-elif ()
3792 "Build skeleton IDL if-else block."
3795 (idlwave-rw-case "if")
3796 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3797 "Condition expression"))
3799 (defun idlwave-case ()
3800 "Build skeleton IDL case statement."
3803 (idlwave-rw-case "case")
3804 (idlwave-rw-case " of\n\nendcase")
3805 "Selector expression"))
3807 (defun idlwave-switch ()
3808 "Build skeleton IDL switch statement."
3811 (idlwave-rw-case "switch")
3812 (idlwave-rw-case " of\n\nendswitch")
3813 "Selector expression"))
3815 (defun idlwave-for ()
3816 "Build skeleton IDL loop statement."
3819 (idlwave-rw-case "for")
3820 (idlwave-rw-case " do begin\n\nendfor")
3823 (defun idlwave-if ()
3824 "Build skeleton IDL if statement."
3827 (idlwave-rw-case "if")
3828 (idlwave-rw-case " then begin\n\nendif")
3829 "Scalar logical expression"))
3831 (defun idlwave-procedure ()
3834 (idlwave-rw-case "pro")
3835 (idlwave-rw-case "\n\nreturn\nend")
3838 (defun idlwave-function ()
3841 (idlwave-rw-case "function")
3842 (idlwave-rw-case "\n\nreturn\nend")
3845 (defun idlwave-repeat ()
3848 (idlwave-rw-case "repeat begin\n\nendrep until")
3849 (idlwave-rw-case "")
3852 (defun idlwave-while ()
3855 (idlwave-rw-case "while")
3856 (idlwave-rw-case " do begin\n\nendwhile")
3859 (defun idlwave-split-string (string &optional pattern
)
3860 "Return a list of substrings of STRING which are separated by PATTERN.
3861 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3863 (setq pattern
"[ \f\t\n\r\v]+"))
3864 (let (parts (start 0))
3865 (while (string-match pattern string start
)
3866 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3867 start
(match-end 0)))
3868 (nreverse (cons (substring string start
) parts
))))
3870 (defun idlwave-replace-string (string replace_string replace_with
)
3872 (last (length string
))
3875 (while (setq end
(string-match replace_string string start
))
3877 (concat ret_string
(substring string start end
) replace_with
))
3878 (setq start
(match-end 0)))
3879 (setq ret_string
(concat ret_string
(substring string start last
)))))
3881 (defun idlwave-get-buffer-visiting (file)
3882 ;; Return the buffer currently visiting FILE
3884 ((boundp 'find-file-compare-truenames
) ; XEmacs
3885 (let ((find-file-compare-truenames t
))
3886 (get-file-buffer file
)))
3887 ((fboundp 'find-buffer-visiting
) ; Emacs
3888 (find-buffer-visiting file
))
3889 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3891 (defvar idlwave-outlawed-buffers nil
3892 "List of buffers pulled up by IDLWAVE for special reasons.
3893 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3895 (defun idlwave-find-file-noselect (file &optional why
)
3896 ;; Return a buffer visiting file.
3897 (or (idlwave-get-buffer-visiting file
)
3898 (let ((buf (find-file-noselect file
)))
3899 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3902 (defun idlwave-kill-autoloaded-buffers ()
3903 "Kill buffers created automatically by IDLWAVE.
3904 Function prompts for a letter to identify the buffers to kill.
3905 Possible letters are:
3907 f Buffers created by the command \\[idlwave-find-module] or mouse
3908 clicks in the routine info window.
3909 s Buffers created by the IDLWAVE Shell to display where execution
3910 stopped or an error was found.
3911 a Both of the above.
3913 Buffers containing unsaved changes require confirmation before they are killed."
3915 (if (null idlwave-outlawed-buffers
)
3916 (error "No IDLWAVE-created buffers available")
3917 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3918 (idlwave-count-outlawed-buffers 'find
)
3919 (idlwave-count-outlawed-buffers 'shell
)))
3920 (let ((c (read-char)))
3922 ((member c
'(?f ?\C-f
))
3923 (idlwave-do-kill-autoloaded-buffers 'find
))
3924 ((member c
'(?s ?\C-s
))
3925 (idlwave-do-kill-autoloaded-buffers 'shell
))
3926 ((member c
'(?a ?\C-a
))
3927 (idlwave-do-kill-autoloaded-buffers t
))
3928 (t (error "Abort"))))))
3930 (defun idlwave-count-outlawed-buffers (tag)
3931 "How many outlawed buffers have tag TAG?"
3934 (lambda (x) (eq (cdr x
) tag
))
3935 idlwave-outlawed-buffers
))))
3937 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3938 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3939 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3942 (while (setq entry
(pop list
))
3943 (if (buffer-live-p (car entry
))
3944 (and (or (memq t reasons
)
3945 (memq (cdr entry
) reasons
))
3946 (kill-buffer (car entry
))
3948 (setq idlwave-outlawed-buffers
3949 (delq entry idlwave-outlawed-buffers
)))
3950 (setq idlwave-outlawed-buffers
3951 (delq entry idlwave-outlawed-buffers
))))
3952 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3954 (defun idlwave-revoke-license-to-kill ()
3955 "Remove BUFFER from the buffers which may be killed.
3956 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3957 Intended for `after-save-hook'."
3958 (let* ((buf (current-buffer))
3959 (entry (assq buf idlwave-outlawed-buffers
)))
3962 (setq idlwave-outlawed-buffers
3963 (delq entry idlwave-outlawed-buffers
)))
3964 ;; Remove this function from the hook.
3965 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3967 (defvar idlwave-path-alist
)
3968 (defun idlwave-locate-lib-file (file)
3969 ;; Find FILE on the scanned lib path and return a buffer visiting it
3970 (let* ((dirs idlwave-path-alist
)
3973 (while (setq dir
(car (pop dirs
)))
3975 (setq efile
(expand-file-name file dir
)))
3976 (throw 'exit efile
))))))
3978 (defun idlwave-expand-lib-file-name (file)
3979 ;; Find FILE on the scanned lib path and return a buffer visiting it
3980 ;; This is for, e.g., finding source with no user catalog
3983 ((file-name-absolute-p file
) file
)
3984 (t (idlwave-locate-lib-file file
))))
3986 (defun idlwave-make-tags ()
3987 "Create the IDL tags file IDLTAGS in the current directory from
3988 the list of directories specified in the minibuffer. Directories may be
3989 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3990 specified top directories are searched if the directory name is prefixed
3991 by @. Specify @ directories with care, it may take a long, long time if
3994 (let (directory directories cmd append status numdirs dir getsubdirs
3995 buffer save_buffer files numfiles item errbuf
)
3998 ;; Read list of directories
3999 (setq directory
(read-string "Tag Directories: " "."))
4000 (setq directories
(idlwave-split-string directory
"[ \t]+"))
4002 ;; Set etags command, vars
4003 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
4004 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4005 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4009 ;; For each directory
4011 (setq dir
(nth numdirs directories
))
4014 ;; Find the subdirectories
4015 (if (string-match "^[@]\\(.+\\)$" dir
)
4016 (setq getsubdirs t
) (setq getsubdirs nil
))
4017 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
4018 (setq dir
(expand-file-name dir
))
4019 (if (file-directory-p dir
)
4021 (if (and getsubdirs
)
4023 (setq buffer
(get-buffer-create "*idltags*"))
4024 (call-process "sh" nil buffer nil
"-c"
4025 (concat "find " dir
" -type d -print"))
4026 (setq save_buffer
(current-buffer))
4028 (setq files
(idlwave-split-string
4029 (idlwave-replace-string
4030 (buffer-substring 1 (point-max))
4033 (set-buffer save_buffer
)
4034 (kill-buffer buffer
))
4035 (setq files
(list (concat dir
"/*.pro"))))
4037 ;; For each subdirectory
4039 (setq item
(nth numfiles files
))
4043 (if (not (string-match "^[ \\t]*$" item
))
4045 (message "%s" (concat "Tagging " item
"..."))
4046 (setq errbuf
(get-buffer-create "*idltags-error*"))
4047 (setq status
(+ status
4048 (if (eq 0 (call-process
4049 "sh" nil errbuf nil
"-c"
4050 (concat cmd append item
)))
4054 ;; Append additional tags
4055 (setq append
" --append ")
4056 (setq numfiles
(1+ numfiles
))
4057 (setq item
(nth numfiles files
)))
4059 (setq numfiles
(1+ numfiles
))
4060 (setq item
(nth numfiles files
))
4063 (setq numdirs
(1+ numdirs
))
4064 (setq dir
(nth numdirs directories
)))
4066 (setq numdirs
(1+ numdirs
))
4067 (setq dir
(nth numdirs directories
)))))
4069 (setq errbuf
(get-buffer-create "*idltags-error*"))
4071 (kill-buffer errbuf
))
4075 (defun idlwave-toggle-comment-region (beg end
&optional n
)
4076 "Comment the lines in the region if the first non-blank line is
4077 commented, and conversely, uncomment region. If optional prefix arg
4078 N is non-nil, then for N positive, add N comment delimiters or for N
4079 negative, remove N comment delimiters.
4080 Uses `comment-region' which does not place comment delimiters on
4082 (interactive "r\nP")
4084 (comment-region beg end
(prefix-numeric-value n
))
4089 (skip-chars-forward " \t\n")
4090 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
4091 (if (fboundp 'uncomment-region
)
4092 (uncomment-region beg end
)
4093 (comment-region beg end
4094 (- (length (buffer-substring
4097 (comment-region beg end
)))))
4100 ;; ----------------------------------------------------------------------------
4101 ;; ----------------------------------------------------------------------------
4102 ;; ----------------------------------------------------------------------------
4103 ;; ----------------------------------------------------------------------------
4105 ;; Completion and Routine Info
4108 ;; String "intern" functions
4110 ;; For the completion and routine info function, we want to normalize
4111 ;; the case of procedure names etc. We do this by "interning" these
4112 ;; string is a hand-crafted way. Hashes are used to map the downcase
4113 ;; version of the strings to the cased versions. Most *-sint-*
4114 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4115 ;; system hash. The former is re-scanned, and the latter takes case
4118 ;; Since these cased versions are really lisp objects, we can use `eq'
4119 ;; to search, which is a large performance boost. All new strings
4120 ;; need to be "sinterned". We do this as early as possible after
4121 ;; getting these strings from completion or buffer substrings. So
4122 ;; most of the code can simply assume to deal with "sinterned"
4123 ;; strings. The only exception is that the functions which scan whole
4124 ;; buffers for routine information do not intern the grabbed strings.
4125 ;; This is only done afterwards. Therefore in these functions it is
4126 ;; *not* safe to assume the strings can be compared with `eq' and be
4127 ;; fed into the routine assq functions.
4129 ;; Here we define the hashing functions.
4131 ;; The variables which hold the hashes.
4132 (defvar idlwave-sint-routines
'(nil))
4133 (defvar idlwave-sint-keywords
'(nil))
4134 (defvar idlwave-sint-methods
'(nil))
4135 (defvar idlwave-sint-classes
'(nil))
4136 (defvar idlwave-sint-dirs
'(nil))
4137 (defvar idlwave-sint-libnames
'(nil))
4139 (defun idlwave-reset-sintern (&optional what
)
4140 "Reset all sintern hashes."
4141 ;; Make sure the hash functions are accessible.
4142 (if (or (not (fboundp 'gethash
))
4143 (not (fboundp 'puthash
)))
4146 (or (fboundp 'puthash
)
4147 (defalias 'puthash
'cl-puthash
))))
4148 (let ((entries '((idlwave-sint-routines 1000 10)
4149 (idlwave-sint-keywords 1000 10)
4150 (idlwave-sint-methods 100 10)
4151 (idlwave-sint-classes 10 10))))
4153 ;; Make sure these are lists
4154 (loop for entry in entries
4155 for var
= (car entry
)
4156 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
4158 ;; Reset the system & library hash
4159 (when (or (eq what t
) (eq what
'syslib
)
4160 (null (cdr idlwave-sint-routines
)))
4161 (loop for entry in entries
4162 for var
= (car entry
) for size
= (nth 1 entry
)
4163 do
(setcdr (symbol-value var
)
4164 (make-hash-table ':size size
':test
'equal
)))
4165 (setq idlwave-sint-dirs nil
4166 idlwave-sint-libnames nil
))
4168 ;; Reset the buffer & shell hash
4169 (when (or (eq what t
) (eq what
'bufsh
)
4170 (null (car idlwave-sint-routines
)))
4171 (loop for entry in entries
4172 for var
= (car entry
) for size
= (nth 1 entry
)
4173 do
(setcar (symbol-value var
)
4174 (make-hash-table ':size size
':test
'equal
))))))
4176 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4178 (idlwave-sintern-method name set
)
4179 (idlwave-sintern-routine name set
)))
4181 (defun idlwave-sintern (stype &rest args
)
4182 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4184 ;;(defmacro idlwave-sintern (type var)
4185 ;; `(cond ((not (stringp name)) name)
4186 ;; ((gethash (downcase name) (cdr ,var)))
4187 ;; ((gethash (downcase name) (car ,var)))
4188 ;; (set (idlwave-sintern-set name ,type ,var set))
4191 (defun idlwave-sintern-routine (name &optional set
)
4192 (cond ((not (stringp name
)) name
)
4193 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4194 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4195 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4197 (defun idlwave-sintern-keyword (name &optional set
)
4198 (cond ((not (stringp name
)) name
)
4199 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4200 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4201 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4203 (defun idlwave-sintern-method (name &optional set
)
4204 (cond ((not (stringp name
)) name
)
4205 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4206 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4207 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4209 (defun idlwave-sintern-class (name &optional set
)
4210 (cond ((not (stringp name
)) name
)
4211 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4212 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4213 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4216 (defun idlwave-sintern-dir (dir &optional set
)
4217 (car (or (member dir idlwave-sint-dirs
)
4218 (setq idlwave-sint-dirs
(cons dir idlwave-sint-dirs
)))))
4219 (defun idlwave-sintern-libname (name &optional set
)
4220 (car (or (member name idlwave-sint-libnames
)
4221 (setq idlwave-sint-libnames
(cons name idlwave-sint-libnames
)))))
4223 (defun idlwave-sintern-set (name type tables set
)
4224 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4226 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4227 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4228 (puthash (downcase name
) iname table
)
4231 (defun idlwave-sintern-keyword-list (kwd-list &optional set
)
4232 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4234 (setcar x
(idlwave-sintern-keyword (car x
) set
)))
4238 (defun idlwave-sintern-rinfo-list (list &optional set default-dir
)
4239 "Sintern all strings in the rinfo LIST.
4240 With optional parameter SET: also set new patterns. Probably this
4241 will always have to be t. If DEFAULT-DIR is passed, it is used as
4242 the base of the directory."
4243 (let (entry name type class kwds res source call new
)
4245 (setq entry
(car list
)
4250 source
(nth 3 entry
)
4252 kwds
(nthcdr 5 entry
))
4254 ;; The class and name
4257 (if (symbolp class
) (setq class
(symbol-name class
)))
4258 (setq class
(idlwave-sintern-class class set
))
4259 (setq name
(idlwave-sintern-method name set
)))
4260 (setq name
(idlwave-sintern-routine name set
)))
4263 (let ((source-type (car source
))
4264 (source-file (nth 1 source
))
4265 (source-dir (if default-dir
4266 (file-name-as-directory default-dir
)
4268 (source-lib (nth 3 source
)))
4269 (if (stringp source-dir
)
4270 (setq source-dir
(idlwave-sintern-dir source-dir set
)))
4271 (if (stringp source-lib
)
4272 (setq source-lib
(idlwave-sintern-libname source-lib set
)))
4273 (setq source
(list source-type source-file source-dir source-lib
)))
4276 (setq kwds
(mapcar (lambda (x)
4277 (idlwave-sintern-keyword-list x set
))
4280 ;; Build a canonicalized list
4281 (setq new
(nconc (list name type class source call
) kwds
)
4282 res
(cons new res
)))
4285 ;; Creating new sintern tables
4287 (defun idlwave-new-sintern-type (tag)
4288 "Define a variable and a function to sintern the new type TAG.
4289 This defines the function `idlwave-sintern-TAG' and the variable
4290 `idlwave-sint-TAGs'."
4291 (let* ((name (symbol-name tag
))
4292 (names (concat name
"s"))
4293 (var (intern (concat "idlwave-sint-" names
)))
4294 (func (intern (concat "idlwave-sintern-" name
))))
4295 (set var nil
) ; initial value of the association list
4296 (fset func
; set the function
4297 `(lambda (name &optional set
)
4298 (cond ((not (stringp name
)) name
)
4299 ((cdr (assoc (downcase name
) ,var
)))
4301 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4305 (defun idlwave-reset-sintern-type (tag)
4306 "Reset the sintern variable associated with TAG."
4307 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4309 ;;---------------------------------------------------------------------------
4312 ;; The variables which hold the information
4313 (defvar idlwave-system-routines nil
4314 "Holds the routine-info obtained by scanning buffers.")
4315 (defvar idlwave-buffer-routines nil
4316 "Holds the routine-info obtained by scanning buffers.")
4317 (defvar idlwave-compiled-routines nil
4318 "Holds the routine-info obtained by asking the shell.")
4319 (defvar idlwave-unresolved-routines nil
4320 "Holds the unresolved routine-info obtained by asking the shell.")
4321 (defvar idlwave-user-catalog-routines nil
4322 "Holds the procedure routine-info from the user scan.")
4323 (defvar idlwave-library-catalog-routines nil
4324 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4325 (defvar idlwave-library-catalog-libname nil
4326 "Name of library catalog loaded from .idlwave_catalog files.")
4327 (defvar idlwave-path-alist nil
4328 "Alist with !PATH directories and zero or more flags if the dir has
4329 been scanned in a user catalog ('user) or discovered in a library
4331 (defvar idlwave-true-path-alist nil
4332 "Like `idlwave-path-alist', but with true filenames.")
4333 (defvar idlwave-routines nil
4334 "Holds the combined procedure/function/method routine-info.")
4335 (defvar idlwave-class-alist nil
4336 "Holds the class names known to IDLWAVE.")
4337 (defvar idlwave-class-history nil
4338 "The history of classes selected with the minibuffer.")
4339 (defvar idlwave-force-class-query nil
)
4340 (defvar idlwave-before-completion-wconf nil
4341 "The window configuration just before the completion buffer was displayed.")
4342 (defvar idlwave-last-system-routine-info-cons-cell nil
4343 "The last cons cell in the system routine info.")
4346 ;; The code to get routine info from different sources.
4348 (defvar idlwave-system-routines
)
4349 (defvar idlwave-catalog-process nil
4350 "The background process currently updating the catalog.")
4352 (defun idlwave-routines ()
4353 "Provide a list of IDL routines.
4354 This routine loads the builtin routines on the first call.
4355 Later it only returns the value of the variable."
4356 (if (and idlwave-catalog-process
4357 (processp idlwave-catalog-process
))
4360 ((equal (process-status idlwave-catalog-process
) 'exit
)
4361 (message "updating........")
4362 (setq idlwave-catalog-process nil
)
4363 (idlwave-update-routine-info '(4)))
4364 ((equal (process-status idlwave-catalog-process
) 'run
)
4365 ;; Keep it running...
4368 ;; Something is wrong, get rid of the process
4369 (message "Problem with catalog process") (beep)
4371 (kill-process idlwave-catalog-process
)
4373 (setq idlwave-catalog-process nil
)))))
4374 (or idlwave-routines
4376 (idlwave-update-routine-info)
4377 ;; return the current value
4380 (defvar idlwave-update-rinfo-hook nil
4381 "List of functions which should run after a global rinfo update.
4382 Does not run after automatic updates of buffer or the shell.")
4384 (defun idlwave-rescan-catalog-directories ()
4385 "Rescan the previously selected directories. For batch processing."
4386 (idlwave-update-routine-info '(16)))
4388 (defun idlwave-rescan-asynchronously ()
4389 "Dispatch another Emacs instance to update the idlwave catalog.
4390 After the process finishes normally, the first access to routine info
4391 will re-read the catalog."
4393 (if (processp idlwave-catalog-process
)
4394 (if (eq (process-status idlwave-catalog-process
) 'run
)
4395 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4398 (kill-process idlwave-catalog-process
)
4400 (error "Process killed, no new process started"))
4403 (kill-process idlwave-catalog-process
)
4405 (if (or (not idlwave-user-catalog-file
)
4406 (not (stringp idlwave-user-catalog-file
))
4407 (not (file-regular-p idlwave-user-catalog-file
)))
4408 (error "No catalog has been produced yet"))
4409 (let* ((emacs (concat invocation-directory invocation-name
))
4410 (args (list "-batch"
4411 "-l" (expand-file-name "~/.emacs")
4413 "-f" "idlwave-rescan-catalog-directories"))
4414 (process (apply 'start-process
"idlcat"
4416 (setq idlwave-catalog-process process
)
4417 (set-process-sentinel
4420 (when (string-match "finished" why
)
4421 (setq idlwave-routines nil
4422 idlwave-system-routines nil
4423 idlwave-catalog-process nil
)
4424 (or (idlwave-start-load-rinfo-timer)
4425 (idlwave-update-routine-info '(4))))))
4426 (message "Background job started to update catalog file")))
4429 ;; Format for all routine info user catalog, library catalogs, etc.:
4431 ;; ("ROUTINE" type class
4432 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4433 ;; (buffer pro_file dir) | (compiled pro_file dir)
4434 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4435 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4437 ;; DIR will be supplied dynamically while loading library catalogs,
4438 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4439 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4440 ;; be nil, as can LINK1, etc., if no HTML help is available.
4443 (defvar idlwave-load-rinfo-idle-timer
)
4444 (defvar idlwave-shell-path-query
)
4446 (defun idlwave-update-routine-info (&optional arg no-concatenate
)
4447 "Update the internal routine-info lists.
4448 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4449 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4450 about individual routines.
4452 The information can come from 4 sources:
4453 1. IDL programs in the current editing session
4454 2. Compiled modules in an IDL shell running as Emacs subprocess
4455 3. A list which covers the IDL system routines.
4456 4. A list which covers the prescanned library files.
4458 Scans all IDLWAVE-mode buffers of the current editing session (see
4459 `idlwave-scan-all-buffers-for-routine-info').
4460 When an IDL shell is running, this command also queries the IDL program
4461 for currently compiled routines.
4463 With prefix ARG, also reload the system and library lists.
4464 With two prefix ARG's, also rescans the chosen user catalog tree.
4465 With three prefix args, dispatch asynchronous process to do the update.
4467 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4468 lists, but instead wait for the shell query to complete and
4469 asynchronously finish updating routine info. This is set
4470 automatically when called interactively. When you need routine
4471 information updated immediately, leave NO-CONCATENATE nil."
4472 (interactive "P\np")
4473 ;; Stop any idle processing
4474 (if (or (and (fboundp 'itimerp
)
4475 (itimerp idlwave-load-rinfo-idle-timer
))
4476 (and (fboundp 'timerp
)
4477 (timerp idlwave-load-rinfo-idle-timer
)))
4478 (cancel-timer idlwave-load-rinfo-idle-timer
))
4481 ;; Start a background process which updates the catalog.
4482 (idlwave-rescan-asynchronously))
4484 ;; Update the user catalog now, and wait for them.
4485 (idlwave-create-user-catalog-file t
))
4487 (let* ((load (or arg
4488 idlwave-buffer-case-takes-precedence
4489 (null idlwave-routines
)))
4490 ;; The override-idle means, even if the idle timer has done some
4491 ;; preparing work, load and renormalize everything anyway.
4492 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4494 (setq idlwave-buffer-routines nil
4495 idlwave-compiled-routines nil
4496 idlwave-unresolved-routines nil
)
4497 ;; Reset the appropriate hashes
4498 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4499 ;; reset was already done in idle time, so skip this step now once
4500 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4501 (idlwave-reset-sintern (cond (load t
)
4502 ((null idlwave-system-routines
) t
)
4505 (if idlwave-buffer-case-takes-precedence
4506 ;; We can safely scan the buffer stuff first
4508 (idlwave-update-buffer-routine-info)
4509 (and load
(idlwave-load-all-rinfo override-idle
)))
4510 ;; We first do the system info, and then the buffers
4511 (and load
(idlwave-load-all-rinfo override-idle
))
4512 (idlwave-update-buffer-routine-info))
4514 ;; Let's see if there is a shell
4515 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4516 (idlwave-shell-is-running)))
4517 (ask-shell (and shell-is-running
4518 idlwave-query-shell-for-routine-info
)))
4520 ;; Load the library catalogs again, first re-scanning the path
4522 (if shell-is-running
4523 (idlwave-shell-send-command idlwave-shell-path-query
4525 (idlwave-shell-get-path-info)
4526 (idlwave-scan-library-catalogs))
4528 (idlwave-scan-library-catalogs)))
4530 (if (or (not ask-shell
)
4531 (not no-concatenate
))
4532 ;; 1. If we are not going to ask the shell, we need to do the
4533 ;; concatenation now.
4534 ;; 2. When this function is called non-interactively, it
4535 ;; means that someone needs routine info *now*. The
4536 ;; shell update causes the concatenation to be
4537 ;; *delayed*, so not in time for the current command.
4538 ;; Therefore, we do a concatenation now, even though
4539 ;; the shell might do it again.
4540 (idlwave-concatenate-rinfo-lists nil
'run-hooks
))
4543 ;; Ask the shell about the routines it knows of.
4544 (message "Querying the shell")
4545 (idlwave-shell-update-routine-info nil t
)))))))
4548 (defvar idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4549 (defvar idlwave-load-rinfo-idle-timer nil
)
4550 (defun idlwave-start-load-rinfo-timer ()
4551 (if (or (and (fboundp 'itimerp
)
4552 (itimerp idlwave-load-rinfo-idle-timer
))
4553 (and (fboundp 'timerp
)
4554 (timerp idlwave-load-rinfo-idle-timer
)))
4555 (cancel-timer idlwave-load-rinfo-idle-timer
))
4556 (setq idlwave-load-rinfo-steps-done
(make-vector 6 nil
))
4557 (setq idlwave-load-rinfo-idle-timer nil
)
4558 (if (and idlwave-init-rinfo-when-idle-after
4559 (numberp idlwave-init-rinfo-when-idle-after
)
4560 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4561 (not idlwave-routines
))
4564 (setq idlwave-load-rinfo-idle-timer
4565 (run-with-idle-timer
4566 idlwave-init-rinfo-when-idle-after
4567 nil
'idlwave-load-rinfo-next-step
)))
4570 (defvar idlwave-library-routines nil
"Obsolete variable.")
4572 ;;------ XML Help routine info system
4573 (defun idlwave-load-system-routine-info ()
4574 ;; Load the system routine info from the cached routine info file,
4575 ;; which, if necessary, will be re-created from the XML file on
4576 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4577 ;; file distributed with older IDLWAVE versions (<6.0)
4578 (unless (and (load idlwave-xml-system-rinfo-converted-file
4579 'noerror
'nomessage
)
4580 (idlwave-xml-system-routine-info-up-to-date))
4581 ;; See if we can create it from XML source
4583 (idlwave-convert-xml-system-routine-info)
4585 (unless (load idlwave-xml-system-rinfo-converted-file
4586 'noerror
'nomessage
)
4587 (if idlwave-system-routines
4589 "Failed to load converted routine info, using old conversion.")
4591 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4592 (if (not (load "idlw-rinfo" 'noerror
'nomessage
))
4594 "Could not locate any system routine information."))))))))
4596 (defun idlwave-xml-system-routine-info-up-to-date()
4597 (let* ((dir (file-name-as-directory
4598 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4599 (catalog-file (expand-file-name "idl_catalog.xml" dir
)))
4600 (file-newer-than-file-p ;converted file is newer than catalog
4601 idlwave-xml-system-rinfo-converted-file
4604 (defvar idlwave-system-class-info nil
) ; Gathered from idlw-rinfo
4605 (defvar idlwave-system-variables-alist nil
4606 "Alist of system variables and the associated structure tags.
4607 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4608 (defvar idlwave-executive-commands-alist nil
4609 "Alist of system variables and their help files.")
4610 (defvar idlwave-help-special-topic-words nil
)
4613 (defun idlwave-shorten-syntax (syntax name
&optional class
)
4614 ;; From a list of syntax statments, shorten with %s and group with "or"
4615 (let ((case-fold-search t
))
4618 (while (string-match name x
)
4619 (setq x
(replace-match "%s" t t x
)))
4621 (while (string-match class x
)
4622 (setq x
(replace-match "%s" t t x
))))
4627 (defun idlwave-xml-create-class-method-lists (xml-entry)
4628 ;; Create a class list entry from the xml parsed list., returning a
4629 ;; cons of form (class-entry method-entries).
4630 (let* ((nameblock (nth 1 xml-entry
))
4631 (class (cdr (assq 'name nameblock
)))
4632 (link (cdr (assq 'link nameblock
)))
4633 (params (cddr xml-entry
))
4634 (case-fold-search t
)
4636 method methods-entry extra-kwds
4637 props get-props set-props init-props inherits
4640 (setq pelem
(car params
))
4642 (setq ptype
(car pelem
)
4643 props
(car (cdr pelem
)))
4645 ((eq ptype
'SUPERCLASS
)
4646 (let ((pname (cdr (assq 'name props
)))
4647 (plink (cdr (assq 'link props
))))
4648 (unless (and (string= pname
"None")
4649 (string= plink
"None"))
4650 (push pname inherits
))))
4652 ((eq ptype
'PROPERTY
)
4653 (let ((pname (cdr (assq 'name props
)))
4654 (plink (cdr (assq 'link props
)))
4655 (get (string= (cdr (assq 'get props
)) "Yes"))
4656 (set (string= (cdr (assq 'set props
)) "Yes"))
4657 (init (string= (cdr (assq 'init props
)) "Yes")))
4658 (if get
(push (list pname plink
) get-props
))
4659 (if set
(push (list pname plink
) set-props
))
4660 (if init
(push (list pname plink
) init-props
))))
4663 (setq method
(cdr (assq 'name props
)))
4664 (setq extra-kwds
;;Assume all property keywords are gathered already
4666 ((string-match (concat class
"::Init") method
)
4667 (put 'init-props
'matched t
)
4669 ((string-match (concat class
"::GetProperty") method
)
4670 (put 'get-props
'matched t
)
4672 ((string-match (concat class
"::SetProperty") method
)
4673 (put 'set-props
'matched t
)
4677 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds
)
4680 (setq params
(cdr params
)))
4681 ;(unless (get 'init-props 'matched)
4682 ; (message "Failed to match Init in class %s" class))
4683 ;(unless (get 'get-props 'matched)
4684 ; (message "Failed to match GetProperty in class %s" class))
4685 ;(unless (get 'set-props 'matched)
4686 ; (message "Failed to match SetProperty in class %s" class))
4689 (list class
(append '(inherits) inherits
) (list 'link link
))
4690 (list class
(list 'link link
))))
4691 (cons class-entry methods-entry
)))
4693 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws
)
4694 ;; Create correctly structured list elements from ROUTINE or METHOD
4695 ;; XML list structures. Return a list of list elements, with more
4696 ;; than one sub-list possible if a routine can serve as both
4697 ;; procedure and function (e.g. call_method).
4698 (let* ((nameblock (nth 1 xml-entry
))
4699 (name (cdr (assq 'name nameblock
)))
4700 (link (cdr (assq 'link nameblock
)))
4701 (params (cddr xml-entry
))
4702 (syntax-vec (make-vector 3 nil
)) ; procedure, function, exec command
4703 (case-fold-search t
)
4704 syntax kwd klink pref-list kwds pelem ptype entry props result type
)
4705 (if class
;; strip out class name from class method name string
4706 (if (string-match (concat class
"::") name
)
4707 (setq name
(substring name
(match-end 0)))))
4709 (setq pelem
(car params
))
4711 (setq ptype
(car pelem
)
4712 props
(car (cdr pelem
)))
4715 (setq syntax
(cdr (assq 'name props
)))
4716 (if (string-match "->" syntax
)
4717 (setq syntax
(replace-match "->" t nil syntax
)))
4718 (setq type
(cdr (assq 'type props
)))
4720 (aref syntax-vec
(cond
4721 ((string-match "^pro" type
) 0)
4722 ((string-match "^fun" type
) 1)
4723 ((string-match "^exec" type
) 2)))))
4724 ((eq ptype
'KEYWORD
)
4725 (setq kwd
(cdr (assq 'name props
))
4726 klink
(cdr (assq 'link props
)))
4727 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd
)
4730 (if (match-string 1 kwd
) '("X" "Y" "Z") '("X" "Y"))
4731 kwd
(substring kwd
(match-end 0)))
4732 (loop for x in pref-list do
4733 (push (list (concat x kwd
) klink
) kwds
)))
4734 (push (list kwd klink
) kwds
)))
4736 (t))); Do nothing for the others
4737 (setq params
(cdr params
)))
4740 ; (if (and (null (aref syntax-vec 0))
4741 ; (null (aref syntax-vec 1))
4742 ; (null (aref syntax-vec 2)))
4743 ; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4745 ; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4746 ; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4748 ;; Executive commands are treated specially
4749 (if (aref syntax-vec
2)
4750 (cons (substring name
1) link
)
4751 (if extra-kws
(setq kwds
(nconc kwds extra-kws
)))
4752 (setq kwds
(idlwave-rinfo-group-keywords kwds link
))
4753 (loop for idx from
0 to
1 do
4754 (if (aref syntax-vec idx
)
4755 (push (append (list name
(if (eq idx
0) 'pro
'fun
)
4757 (idlwave-shorten-syntax
4758 (aref syntax-vec idx
) name class
))
4763 (defun idlwave-rinfo-group-keywords (kwds master-link
)
4764 ;; Group keywords by link file, as a list with elements
4765 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4766 (let (kwd link anchor linkfiles block master-elt
)
4768 (setq kwd
(car kwds
)
4769 link
(idlwave-split-link-target (nth 1 kwd
))
4773 (if (setq block
(assoc link linkfiles
))
4774 (push (cons kwd anchor
) (cdr block
))
4775 (push (list link
(cons kwd anchor
)) linkfiles
))
4776 (setq kwds
(cdr kwds
)))
4777 ;; Ensure the master link is there
4778 (if (setq master-elt
(assoc master-link linkfiles
))
4779 (if (eq (car linkfiles
) master-elt
)
4781 (cons master-elt
(delq master-elt linkfiles
)))
4782 (push (list master-link
) linkfiles
))))
4784 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4785 ;; Clean up the syntax of routines which are actually aliases by
4786 ;; removing the "OR" from the statements
4788 (loop for x in aliases do
4789 (setq entry
(assoc x idlwave-system-routines
))
4791 (while (string-match " +or +" (setq syntax
(nth 4 entry
)))
4792 (setf (nth 4 entry
) (replace-match ", " t t syntax
)))))))
4794 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4795 ;; Duplicate and trim original routine aliases from rinfo list
4796 ;; This if for, e.g. OPENR/OPENW/OPENU
4797 (let (alias remove-list new parts all-parts
)
4798 (loop for x in aliases do
4799 (when (setq parts
(split-string (cdr x
) "/"))
4800 (setq new
(assoc (cdr x
) all-parts
))
4802 (setq new
(cons (cdr x
) parts
))
4803 (push new all-parts
))
4804 (setcdr new
(delete (car x
) (cdr new
)))))
4806 ;; Add any missing aliases (separate by slashes)
4807 (loop for x in all-parts do
4809 (push (cons (nth 1 x
) (car x
)) aliases
)))
4811 (loop for x in aliases do
4812 (when (setq alias
(assoc (cdr x
) idlwave-system-routines
))
4813 (unless (memq alias remove-list
) (push alias remove-list
))
4814 (setq alias
(copy-sequence alias
))
4815 (setcar alias
(car x
))
4816 (push alias idlwave-system-routines
)))
4817 (loop for x in remove-list do
4818 (delq x idlwave-system-routines
))))
4820 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4821 ;; Duplicate and trim original routine aliases from rinfo list
4822 ;; This if for, e.g. !X, !Y, !Z.
4823 (let (alias remove-list new parts all-parts
)
4824 (loop for x in aliases do
4825 (when (setq alias
(assoc (cdr x
) idlwave-system-variables-alist
))
4826 (unless (memq alias remove-list
) (push alias remove-list
))
4827 (setq alias
(copy-sequence alias
))
4828 (setcar alias
(car x
))
4829 (push alias idlwave-system-variables-alist
)))
4830 (loop for x in remove-list do
4831 (delq x idlwave-system-variables-alist
))))
4834 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4835 ;; Create a sysvar list entry from the xml parsed list.
4836 (let* ((nameblock (nth 1 xml-entry
))
4837 (name (cdr (assq 'name nameblock
)))
4838 (sysvar (substring name
(progn (string-match "^ *!" name
)
4840 (link (cdr (assq 'link nameblock
)))
4841 (params (cddr xml-entry
))
4842 (case-fold-search t
)
4843 pelem ptype props fields tags
)
4845 (setq pelem
(car params
))
4847 (setq ptype
(car pelem
)
4848 props
(car (cdr pelem
)))
4851 (push (cons (cdr (assq 'name props
))
4853 (idlwave-split-link-target (cdr (assq 'link props
)))))
4855 (setq params
(cdr params
)))
4857 (list sysvar
(if tags
(cons 'tags tags
)) (list 'link link
)))))
4860 (defvar idlwave-xml-routine-info-file nil
)
4862 (defun idlwave-save-routine-info ()
4863 (if idlwave-xml-routine-info-file
4864 (with-temp-file idlwave-xml-system-rinfo-converted-file
4866 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4867 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version
")
4868 ;; Automatically generated from source file:
4869 ;; " idlwave-xml-routine-info-file
"
4870 ;; on " (current-time-string) "
4872 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4873 idlwave-xml-routine-info-file
))
4874 (insert "\n(setq idlwave-system-routines\n '")
4875 (prin1 idlwave-system-routines
(current-buffer))
4877 (insert "\n(setq idlwave-system-variables-alist\n '")
4878 (prin1 idlwave-system-variables-alist
(current-buffer))
4880 (insert "\n(setq idlwave-system-class-info\n '")
4881 (prin1 idlwave-system-class-info
(current-buffer))
4883 (insert "\n(setq idlwave-executive-commands-alist\n '")
4884 (prin1 idlwave-executive-commands-alist
(current-buffer))
4886 (insert "\n(setq idlwave-help-special-topic-words\n '")
4887 (prin1 idlwave-help-special-topic-words
(current-buffer))
4890 (defun idlwave-convert-xml-system-routine-info ()
4891 "Convert XML supplied IDL routine info into internal form.
4892 Cache to disk for quick recovery."
4894 (let* ((dir (file-name-as-directory
4895 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4896 (catalog-file (expand-file-name "idl_catalog.xml" dir
))
4898 props rinfo msg-cnt elem type nelem class-result alias
4899 routines routine-aliases statement-aliases sysvar-aliases
4901 (if (not (file-exists-p catalog-file
))
4902 (error "No such XML routine info file: %s" catalog-file
)
4903 (if (not (file-readable-p catalog-file
))
4904 (error "Cannot read XML routine info file: %s" catalog-file
)))
4905 (message "Reading XML routine info...")
4906 (setq rinfo
(xml-parse-file catalog-file
))
4907 (message "Reading XML routine info...done")
4908 (setq rinfo
(assq 'CATALOG rinfo
))
4909 (unless rinfo
(error "Failed to parse XML routine info"))
4910 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4912 (setq version-string
(cdr (assq 'version
(nth 1 rinfo
)))
4915 (setq nelem
(length rinfo
)
4916 msg-cnt
(/ nelem
20))
4918 (setq idlwave-xml-routine-info-file nil
)
4919 (message "Converting XML routine info...")
4920 (setq idlwave-system-routines nil
4921 idlwave-system-variables-alist nil
4922 idlwave-system-class-info nil
4923 idlwave-executive-commands-alist nil
4924 idlwave-help-special-topic-words nil
)
4927 (setq elem
(car rinfo
)
4931 (setq type
(car elem
)
4932 props
(car (cdr elem
)))
4933 (if (= (mod elem-cnt msg-cnt
) 0)
4934 (message "Converting XML routine info...%2d%%"
4935 (/ (* elem-cnt
100) nelem
)))
4938 (if (setq alias
(assq 'alias_to props
))
4939 (push (cons (cdr (assq 'name props
)) (cdr alias
))
4941 (setq routines
(idlwave-xml-create-rinfo-list elem
))
4942 (if (listp (cdr routines
))
4943 (setq idlwave-system-routines
4944 (nconc idlwave-system-routines routines
))
4945 ;; a cons cell is an executive commands
4946 (push routines idlwave-executive-commands-alist
))))
4949 (setq class-result
(idlwave-xml-create-class-method-lists elem
))
4950 (push (car class-result
) idlwave-system-class-info
)
4951 (setq idlwave-system-routines
4952 (nconc idlwave-system-routines
(cdr class-result
))))
4954 ((eq type
'STATEMENT
)
4955 (push (cons (cdr (assq 'name props
))
4956 (cdr (assq 'link props
)))
4957 idlwave-help-special-topic-words
)
4958 ;; Save the links to those which are statement aliases (not routines)
4959 (if (setq alias
(assq 'alias_to props
))
4960 (unless (member (cdr alias
) statement-aliases
)
4961 (push (cdr alias
) statement-aliases
))))
4964 (if (setq alias
(cdr (assq 'alias_to props
)))
4965 (push (cons (substring (cdr (assq 'name props
)) 1)
4966 (substring alias
1))
4968 (push (idlwave-xml-create-sysvar-alist elem
)
4969 idlwave-system-variables-alist
)))
4971 (idlwave-convert-xml-clean-routine-aliases routine-aliases
)
4972 (idlwave-convert-xml-clean-statement-aliases statement-aliases
)
4973 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases
)
4975 (setq idlwave-xml-routine-info-file catalog-file
)
4976 (idlwave-save-routine-info)
4977 (message "Converting XML routine info...done")))
4980 ;; ("ROUTINE" type class
4981 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4982 ;; (buffer pro_file dir) | (compiled pro_file dir)
4983 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4984 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4987 (defun idlwave-load-rinfo-next-step ()
4988 (let ((inhibit-quit t
)
4989 (arr idlwave-load-rinfo-steps-done
))
4991 (when (not (aref arr
0))
4992 (message "Loading system routine info in idle time...")
4993 (idlwave-load-system-routine-info)
4994 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4995 (message "Loading system routine info in idle time...done")
4999 (when (not (aref arr
1))
5000 (message "Normalizing idlwave-system-routines in idle time...")
5001 (idlwave-reset-sintern t
)
5002 (put 'idlwave-reset-sintern
'done-by-idle t
)
5003 (setq idlwave-system-routines
5004 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5005 (message "Normalizing idlwave-system-routines in idle time...done")
5009 (when (not (aref arr
2))
5010 (when (and (stringp idlwave-user-catalog-file
)
5011 (file-regular-p idlwave-user-catalog-file
))
5012 (message "Loading user catalog in idle time...")
5014 (load-file idlwave-user-catalog-file
)
5015 (error (throw 'exit nil
)))
5016 ;; Check for the old style catalog and warn
5018 (boundp 'idlwave-library-routines
)
5019 idlwave-library-routines
)
5021 (setq idlwave-library-routines nil
)
5023 (message "Outdated user catalog: %s... recreate"
5024 idlwave-user-catalog-file
))
5025 (message "Loading user catalog in idle time...done")))
5029 (when (not (aref arr
3))
5030 (when idlwave-user-catalog-routines
5031 (message "Normalizing user catalog routines in idle time...")
5032 (setq idlwave-user-catalog-routines
5033 (idlwave-sintern-rinfo-list
5034 idlwave-user-catalog-routines
'sys
))
5036 "Normalizing user catalog routines in idle time...done"))
5040 (when (not (aref arr
4))
5041 (idlwave-scan-library-catalogs
5042 "Loading and normalizing library catalogs in idle time...")
5045 (when (not (aref arr
5))
5046 (message "Finishing initialization in idle time...")
5048 (message "Finishing initialization in idle time...done")
5051 ;; restart the timer
5053 (idlwave-load-rinfo-next-step)
5054 (setq idlwave-load-rinfo-idle-timer
5055 (run-with-idle-timer
5056 idlwave-init-rinfo-when-idle-after
5057 nil
'idlwave-load-rinfo-next-step
))))))
5059 (defun idlwave-load-all-rinfo (&optional force
)
5060 ;; Load and case-treat the system, user catalog, and library routine
5064 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
5065 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5066 (idlwave-load-system-routine-info))
5067 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
5068 (message "Normalizing idlwave-system-routines...")
5069 (setq idlwave-system-routines
5070 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
5071 (message "Normalizing idlwave-system-routines...done"))
5072 (when idlwave-system-routines
5073 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
5074 (setq idlwave-last-system-routine-info-cons-cell
5075 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
)))
5078 (when (and (stringp idlwave-user-catalog-file
)
5079 (file-regular-p idlwave-user-catalog-file
))
5081 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
5082 (load-file idlwave-user-catalog-file
))
5085 (boundp 'idlwave-library-routines
)
5086 idlwave-library-routines
)
5087 (setq idlwave-library-routines nil
)
5088 (error "Outdated user catalog: %s... recreate"
5089 idlwave-user-catalog-file
))
5090 (setq idlwave-true-path-alist nil
)
5091 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
5092 (message "Normalizing user catalog routines...")
5093 (setq idlwave-user-catalog-routines
5094 (idlwave-sintern-rinfo-list
5095 idlwave-user-catalog-routines
'sys
))
5096 (message "Normalizing user catalog routines...done")))
5099 (when (or force
(not (aref idlwave-load-rinfo-steps-done
4)))
5100 (idlwave-scan-library-catalogs
5101 "Loading and normalizing library catalogs..."))
5102 (run-hooks 'idlwave-after-load-rinfo-hook
))
5105 (defun idlwave-update-buffer-routine-info ()
5108 ((eq idlwave-scan-all-buffers-for-routine-info t
)
5109 ;; Scan all buffers, current buffer last
5110 (message "Scanning all buffers...")
5111 (setq res
(idlwave-get-routine-info-from-buffers
5112 (reverse (buffer-list)))))
5113 ((null idlwave-scan-all-buffers-for-routine-info
)
5114 ;; Don't scan any buffers
5117 ;; Just scan this buffer
5118 (if (eq major-mode
'idlwave-mode
)
5120 (message "Scanning current buffer...")
5121 (setq res
(idlwave-get-routine-info-from-buffers
5122 (list (current-buffer))))))))
5123 ;; Put the result into the correct variable
5124 (setq idlwave-buffer-routines
5125 (idlwave-sintern-rinfo-list res
'set
))))
5127 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
5128 "Put the different sources for routine information together."
5129 ;; The sequence here is important because earlier definitions shadow
5130 ;; later ones. We assume that if things in the buffers are newer
5131 ;; then in the shell of the system, they are meant to be different.
5132 (setcdr idlwave-last-system-routine-info-cons-cell
5133 (append idlwave-buffer-routines
5134 idlwave-compiled-routines
5135 idlwave-library-catalog-routines
5136 idlwave-user-catalog-routines
))
5137 (setq idlwave-class-alist nil
)
5139 ;; Give a message with information about the number of routines we have.
5142 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5143 (length idlwave-buffer-routines
)
5144 (length idlwave-compiled-routines
)
5145 (length idlwave-library-catalog-routines
)
5146 (length idlwave-user-catalog-routines
)
5147 (length idlwave-system-routines
)))
5149 (run-hooks 'idlwave-update-rinfo-hook
)))
5151 (defun idlwave-class-alist ()
5152 "Return the class alist - make it if necessary."
5153 (or idlwave-class-alist
5155 (loop for x in idlwave-routines do
5156 (when (and (setq class
(nth 2 x
))
5157 (not (assq class idlwave-class-alist
)))
5158 (push (list class
) idlwave-class-alist
)))
5159 idlwave-class-alist
)))
5161 ;; Three functions for the hooks
5162 (defun idlwave-save-buffer-update ()
5163 (idlwave-update-current-buffer-info 'save-buffer
))
5164 (defun idlwave-kill-buffer-update ()
5165 (idlwave-update-current-buffer-info 'kill-buffer
))
5166 (defun idlwave-new-buffer-update ()
5167 (idlwave-update-current-buffer-info 'find-file
))
5169 (defun idlwave-update-current-buffer-info (why)
5170 "Update `idlwave-routines' for current buffer.
5171 Can run from `after-save-hook'."
5172 (when (and (eq major-mode
'idlwave-mode
)
5173 (or (eq t idlwave-auto-routine-info-updates
)
5174 (memq why idlwave-auto-routine-info-updates
))
5175 idlwave-scan-all-buffers-for-routine-info
5179 (idlwave-replace-buffer-routine-info
5181 (if (eq why
'kill-buffer
)
5184 (idlwave-sintern-rinfo-list
5185 (idlwave-get-routine-info-from-buffers
5186 (list (current-buffer))) 'set
))))
5187 (idlwave-concatenate-rinfo-lists 'quiet
)
5191 (defun idlwave-replace-buffer-routine-info (file new
)
5192 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5193 (let ((list idlwave-buffer-routines
)
5196 ;; The following test uses eq to make sure it works correctly
5197 ;; when two buffers visit the same file. Then the file names
5198 ;; will be equal, but not eq.
5199 (if (eq (idlwave-routine-source-file (nth 3 (car list
))) file
)
5204 ;; End of that section reached. Jump.
5206 (setq list
(cdr list
)))
5207 (setq idlwave-buffer-routines
5208 (append new
(delq nil idlwave-buffer-routines
)))))
5210 ;;----- Scanning buffers -------------------
5212 (defun idlwave-get-routine-info-from-buffers (buffers)
5213 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5214 (let (buf routine-lists res
)
5216 (while (setq buf
(pop buffers
))
5218 (if (and (eq major-mode
'idlwave-mode
)
5220 ;; yes, this buffer has the right mode.
5221 (progn (setq res
(condition-case nil
5222 (idlwave-get-buffer-routine-info)
5224 (push res routine-lists
)))))
5225 ;; Concatenate the individual lists and return the result
5226 (apply 'nconc routine-lists
)))
5228 (defun idlwave-get-buffer-routine-info ()
5229 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5230 (let* ((case-fold-search t
)
5231 routine-list string entry
)
5235 (goto-char (point-min))
5236 (while (re-search-forward
5237 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
5238 (setq string
(buffer-substring-no-properties
5241 (idlwave-end-of-statement)
5243 (setq entry
(idlwave-parse-definition string
))
5244 (push entry routine-list
))))
5247 (defvar idlwave-scanning-lib-dir
)
5248 (defun idlwave-parse-definition (string)
5249 "Parse a module definition."
5250 (let ((case-fold-search t
)
5251 start name args type keywords class
)
5253 (while (string-match ";.*" string
)
5254 (setq string
(replace-match "" t t string
)))
5255 ;; Remove the continuation line stuff
5256 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
5257 (setq string
(replace-match "\\1 " t nil string
)))
5258 (while (string-match "\n" string
)
5259 (setq string
(replace-match " " t nil string
)))
5260 ;; Match the name and type.
5262 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
5263 (setq start
(match-end 0))
5264 (setq type
(downcase (match-string 1 string
)))
5265 (if (match-beginning 3)
5266 (setq class
(match-string 3 string
)))
5267 (setq name
(match-string 4 string
)))
5268 ;; Match normal args and keyword args
5269 (while (string-match
5270 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5272 (setq start
(match-end 0))
5273 (if (match-beginning 3)
5274 (push (match-string 1 string
) keywords
)
5275 (push (match-string 1 string
) args
)))
5276 ;; Normalize and sort.
5277 (setq args
(nreverse args
))
5278 (setq keywords
(sort keywords
(lambda (a b
)
5279 (string< (downcase a
) (downcase b
)))))
5280 ;; Make and return the entry
5281 ;; We don't know which argument are optional, so this information
5282 ;; will not be contained in the calling sequence.
5284 (if (equal type
"pro") 'pro
'fun
)
5286 (cond ((not (boundp 'idlwave-scanning-lib
))
5287 (list 'buffer
(buffer-file-name)))
5288 ; ((string= (downcase
5289 ; (file-name-sans-extension
5290 ; (file-name-nondirectory (buffer-file-name))))
5293 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5294 (t (list 'user
(file-name-nondirectory (buffer-file-name))
5295 idlwave-scanning-lib-dir
"UserLib")))
5297 (if (string= type
"function") "Result = " "")
5298 (if class
"Obj ->[%s::]" "")
5302 (if (string= type
"function") "(" ", ")
5303 (mapconcat 'identity args
", ")
5304 (if (string= type
"function") ")" ""))))
5306 (cons nil
(mapcar 'list keywords
)) ;No help file
5310 ;;----- Scanning the user catalog -------------------
5312 (defun idlwave-sys-dir ()
5313 "Return the syslib directory, or a dummy that never matches."
5315 ((and idlwave-system-directory
5316 (not (string= idlwave-system-directory
"")))
5317 idlwave-system-directory
)
5318 ((getenv "IDL_DIR"))
5322 (defun idlwave-create-user-catalog-file (&optional arg
)
5323 "Scan all files on selected dirs of IDL search path for routine information.
5325 A widget checklist will allow you to choose the directories. Write
5326 the result as a file `idlwave-user-catalog-file'. When this file
5327 exists, it will be automatically loaded to give routine information
5328 about library routines. With ARG, just rescan the same directories
5329 as last time - so no widget will pop up."
5331 ;; Make sure the file is loaded if it exists.
5332 (if (and (stringp idlwave-user-catalog-file
)
5333 (file-regular-p idlwave-user-catalog-file
))
5335 (load-file idlwave-user-catalog-file
)
5337 ;; Make sure the file name makes sense
5338 (unless (and (stringp idlwave-user-catalog-file
)
5339 (> (length idlwave-user-catalog-file
) 0)
5340 (file-accessible-directory-p
5341 (file-name-directory idlwave-user-catalog-file
))
5342 (not (string= "" (file-name-nondirectory
5343 idlwave-user-catalog-file
))))
5344 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5347 ;; Rescan the known directories
5348 ((and arg idlwave-path-alist
5349 (consp (car idlwave-path-alist
)))
5350 (idlwave-scan-user-lib-files idlwave-path-alist
))
5352 ;; Expand the directories from library-path and run the widget
5353 (idlwave-library-path
5354 (idlwave-display-user-catalog-widget
5355 (if idlwave-true-path-alist
5356 ;; Propagate any flags on the existing path-alist
5358 (let ((path-entry (assoc (file-truename x
)
5359 idlwave-true-path-alist
)))
5361 (cons x
(cdr path-entry
))
5363 (idlwave-expand-path idlwave-library-path
))
5364 (mapcar 'list
(idlwave-expand-path idlwave-library-path
)))))
5366 ;; Ask the shell for the path and then run the widget
5368 (message "Asking the shell for IDL path...")
5369 (require 'idlw-shell
)
5370 (idlwave-shell-send-command idlwave-shell-path-query
5371 '(idlwave-user-catalog-command-hook nil
)
5375 ;; Parse shell path information and select among it.
5376 (defun idlwave-user-catalog-command-hook (&optional arg
)
5377 ;; Command hook used by `idlwave-create-user-catalog-file'.
5380 (idlwave-scan-user-lib-files idlwave-path-alist
)
5381 ;; Set the path and display the widget
5382 (idlwave-shell-get-path-info 'no-write
) ; set to something path-alist
5383 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load
)
5384 (idlwave-display-user-catalog-widget idlwave-path-alist
)))
5386 (defconst idlwave-user-catalog-widget-help-string
5387 "This is the front-end to the creation of the IDLWAVE user catalog.
5388 Please select the directories on IDL's search path from which you
5389 would like to extract routine information, to be stored in the file:
5393 If this is not the correct file, first set variable
5394 `idlwave-user-catalog-file', and call this command again.
5396 N.B. Many libraries include pre-scanned catalog files
5397 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5398 not be scanned. You can scan your own libraries off-line using the
5399 perl script `idlwave_catalog'.
5401 After selecting the directories, choose [Scan & Save] to scan the library
5402 directories and save the routine info.
5405 (defvar idlwave-widget
)
5406 (defvar widget-keymap
)
5407 (defun idlwave-display-user-catalog-widget (dirs-list)
5408 "Create the widget to select IDL search path directories for scanning."
5413 (error "Don't know IDL's search path"))
5415 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5416 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5417 (kill-all-local-variables)
5418 (make-local-variable 'idlwave-widget
)
5419 (widget-insert (format idlwave-user-catalog-widget-help-string
5420 idlwave-user-catalog-file
))
5422 (widget-create 'push-button
5423 :notify
'idlwave-widget-scan-user-lib-files
5426 (widget-create 'push-button
5427 :notify
'idlwave-delete-user-catalog-file
5430 (widget-create 'push-button
5432 '(lambda (&rest ignore
)
5433 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5435 (unless (memq 'lib
(cdr x
))
5436 (idlwave-path-alist-add-flag x
'user
)))
5438 (idlwave-display-user-catalog-widget path-list
)))
5439 "Select All Non-Lib")
5441 (widget-create 'push-button
5443 '(lambda (&rest ignore
)
5444 (let ((path-list (widget-get idlwave-widget
:path-dirs
)))
5446 (idlwave-path-alist-remove-flag x
'user
))
5448 (idlwave-display-user-catalog-widget path-list
)))
5451 (widget-create 'push-button
5452 :notify
(lambda (&rest ignore
)
5453 (kill-buffer (current-buffer)))
5455 (widget-insert "\n\n")
5457 (widget-insert "Select Directories: \n")
5459 (setq idlwave-widget
5460 (apply 'widget-create
5462 :value
(delq nil
(mapcar (lambda (x)
5463 (if (memq 'user
(cdr x
))
5467 :tag
"List of directories"
5470 (if (memq 'lib
(cdr x
))
5471 (concat "[LIB] " (car x
) )
5472 (car x
)))) dirs-list
)))
5473 (widget-put idlwave-widget
:path-dirs dirs-list
)
5474 (widget-insert "\n")
5475 (use-local-map widget-keymap
)
5477 (goto-char (point-min))
5478 (delete-other-windows))
5480 (defun idlwave-delete-user-catalog-file (&rest ignore
)
5482 (format "Delete file %s " idlwave-user-catalog-file
))
5484 (delete-file idlwave-user-catalog-file
)
5485 (message "%s has been deleted" idlwave-user-catalog-file
))))
5487 (defun idlwave-widget-scan-user-lib-files (&rest ignore
)
5488 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5489 (let* ((widget idlwave-widget
)
5490 (selected-dirs (widget-value widget
))
5491 (path-alist (widget-get widget
:path-dirs
))
5492 (this-path-alist path-alist
)
5494 (while (setq dir-entry
(pop this-path-alist
))
5496 (if (memq 'lib
(cdr dir-entry
))
5497 (concat "[LIB] " (car dir-entry
))
5500 (idlwave-path-alist-add-flag dir-entry
'user
)
5501 (idlwave-path-alist-remove-flag dir-entry
'user
)))
5502 (idlwave-scan-user-lib-files path-alist
)))
5504 (defvar font-lock-mode
)
5505 (defun idlwave-scan-user-lib-files (path-alist)
5506 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5507 (let* ((idlwave-scanning-lib t
)
5508 (idlwave-scanning-lib-dir "")
5509 (idlwave-completion-case nil
)
5510 dirs-alist dir files file
)
5511 (setq idlwave-user-catalog-routines nil
5512 idlwave-path-alist path-alist
; for library-path instead
5513 idlwave-true-path-alist nil
)
5514 (if idlwave-auto-write-paths
(idlwave-write-paths))
5515 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5517 (setq dirs-alist
(reverse path-alist
))
5518 (while (setq dir
(pop dirs-alist
))
5519 (when (memq 'user
(cdr dir
)) ; Has it marked for scan?
5520 (setq dir
(car dir
))
5521 (setq idlwave-scanning-lib-dir dir
)
5522 (when (file-directory-p dir
)
5523 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
5524 (while (setq file
(pop files
))
5525 (when (file-regular-p file
)
5526 (if (not (file-readable-p file
))
5527 (message "Skipping %s (no read permission)" file
)
5528 (message "Scanning %s..." file
)
5530 (insert-file-contents file
'visit
)
5531 (setq idlwave-user-catalog-routines
5532 (append (idlwave-get-routine-info-from-buffers
5533 (list (current-buffer)))
5534 idlwave-user-catalog-routines
)))))))))
5535 (message "Creating user catalog file...")
5536 (kill-buffer "*idlwave-scan.pro*")
5537 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5538 (let ((font-lock-maximum-size 0)
5539 (auto-mode-alist nil
))
5540 (find-file idlwave-user-catalog-file
))
5541 (if (and (boundp 'font-lock-mode
)
5545 (insert ";; IDLWAVE user catalog file\n")
5546 (insert (format ";; Created %s\n\n" (current-time-string)))
5548 ;; Define the routine info list
5549 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5550 (let ((standard-output (current-buffer)))
5554 (goto-char (point-max)))
5555 idlwave-user-catalog-routines
))
5556 (insert (format "))\n\n;;; %s ends here\n"
5557 (file-name-nondirectory idlwave-user-catalog-file
)))
5558 (goto-char (point-min))
5561 (kill-buffer (current-buffer)))
5562 (message "Creating user catalog file...done")
5563 (message "Info for %d routines saved in %s"
5564 (length idlwave-user-catalog-routines
)
5565 idlwave-user-catalog-file
)
5567 (idlwave-update-routine-info t
))
5569 (defun idlwave-read-paths ()
5570 (if (and (stringp idlwave-path-file
)
5571 (file-regular-p idlwave-path-file
))
5573 (load idlwave-path-file t t t
)
5576 (defun idlwave-write-paths ()
5578 (when (and idlwave-path-alist idlwave-system-directory
)
5579 (let ((font-lock-maximum-size 0)
5580 (auto-mode-alist nil
))
5581 (find-file idlwave-path-file
))
5582 (if (and (boundp 'font-lock-mode
)
5586 (insert ";; IDLWAVE paths\n")
5587 (insert (format ";; Created %s\n\n" (current-time-string)))
5588 ;; Define the variable which knows the value of "!DIR"
5589 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5590 idlwave-system-directory
))
5592 ;; Define the variable which contains a list of all scanned directories
5593 (insert "\n(setq idlwave-path-alist\n '(")
5594 (let ((standard-output (current-buffer)))
5598 (goto-char (point-max)))
5599 idlwave-path-alist
))
5602 (kill-buffer (current-buffer))))
5605 (defun idlwave-expand-path (path &optional default-dir
)
5606 ;; Expand parts of path starting with '+' recursively into directory list.
5607 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5608 (message "Expanding path...")
5609 (let (path1 dir recursive
)
5610 (while (setq dir
(pop path
))
5611 (if (setq recursive
(string= (substring dir
0 1) "+"))
5612 (setq dir
(substring dir
1)))
5614 (not (file-name-absolute-p dir
)))
5615 (setq dir
(expand-file-name dir default-dir
)))
5617 ;; Expand recursively
5618 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
5621 (message "Expanding path...done")
5624 (defun idlwave-recursive-directory-list (dir)
5625 ;; Return a list of all directories below DIR, including DIR itself
5626 (let ((path (list dir
)) path1 file files
)
5627 (while (setq dir
(pop path
))
5628 (when (file-directory-p dir
)
5629 (setq files
(nreverse (directory-files dir t
"[^.]")))
5630 (while (setq file
(pop files
))
5631 (if (file-directory-p file
)
5632 (push (file-name-as-directory file
) path
)))
5637 ;;----- Scanning the library catalogs ------------------
5642 (defun idlwave-scan-library-catalogs (&optional message-base no-load
)
5643 "Scan for library catalog files (.idlwave_catalog) and ingest.
5645 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5646 instead, if present) are searched. Print MESSAGE-BASE along with the
5647 libraries being loaded, if passed, and skip loading/normalizing if
5648 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5649 be set to nil to disable library catalog scanning."
5650 (when idlwave-use-library-catalogs
5652 (if idlwave-library-path
5653 (idlwave-expand-path idlwave-library-path
)
5654 (mapcar 'car idlwave-path-alist
)))
5656 dir-entry dir flags catalog all-routines
)
5657 (if message-base
(message message-base
))
5658 (while (setq dir
(pop dirs
))
5660 (when (file-readable-p
5661 (setq catalog
(expand-file-name ".idlwave_catalog" dir
)))
5663 (setq idlwave-library-catalog-routines nil
)
5664 ;; Load the catalog file
5666 (load catalog t t t
)
5667 (error (throw 'continue t
)))
5670 (not (string= idlwave-library-catalog-libname
5672 (message "%s" (concat message-base
5673 idlwave-library-catalog-libname
))
5674 (setq old-libname idlwave-library-catalog-libname
))
5675 (when idlwave-library-catalog-routines
5678 (idlwave-sintern-rinfo-list
5679 idlwave-library-catalog-routines
'sys dir
)
5682 ;; Add a 'lib flag if on path-alist
5683 (when (and idlwave-path-alist
5684 (setq dir-entry
(assoc dir idlwave-path-alist
)))
5685 (idlwave-path-alist-add-flag dir-entry
'lib
)))))
5686 (unless no-load
(setq idlwave-library-catalog-routines all-routines
))
5687 (if message-base
(message (concat message-base
"done"))))))
5689 ;;----- Communicating with the Shell -------------------
5691 ;; First, here is the idl program which can be used to query IDL for
5692 ;; defined routines.
5693 (defconst idlwave-routine-info.pro
5695 ;; START OF IDLWAVE SUPPORT ROUTINES
5696 pro idlwave_print_safe,item,limit
5698 if err ne 0 then begin
5699 print,'Could not print item.'
5702 if n_elements(item) gt limit then $
5703 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5707 pro idlwave_print_info_entry,name,func=func,separator=sep
5708 ;; See if it's an object method
5709 if name eq '' then return
5710 func = keyword_set(func)
5711 methsep = strpos(name,'::')
5712 meth = methsep ne -1
5715 pars = routine_info(name,/parameters,functions=func)
5716 source = routine_info(name,/source,functions=func)
5717 nargs = pars.num_args
5718 nkw = pars.num_kw_args
5719 if nargs gt 0 then args = pars.args
5720 if nkw gt 0 then kwargs = pars.kw_args
5722 ;; Trim the class, and make the name
5724 class = strmid(name,0,methsep)
5725 name = strmid(name,methsep+2,strlen(name)-1)
5726 if nargs gt 0 then begin
5727 ;; remove the self argument
5728 wh = where(args ne 'SELF',nargs)
5729 if nargs gt 0 then args = args[wh]
5732 ;; No class, just a normal routine.
5738 if func then cs = 'Result = '
5739 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5741 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5742 if nargs gt 0 then begin
5743 for j=0,nargs-1 do begin
5745 if j lt nargs-1 then cs = cs + ', '
5748 if func then cs = cs + ')'
5749 ;; Keyword arguments
5751 if nkw gt 0 then begin
5752 for j=0,nkw-1 do begin
5753 kwstring = kwstring + ' ' + kwargs[j]
5757 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5759 print,ret + ': ' + name + sep + class + sep + source[0].path $
5760 + sep + cs + sep + kwstring
5763 pro idlwave_routine_info,file
5766 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5767 all = routine_info()
5768 fileQ=n_elements(file) ne 0
5769 if fileQ then file=strtrim(file,2)
5770 for i=0L,n_elements(all)-1L do begin
5772 if (routine_info(all[i],/SOURCE)).path eq file then $
5773 idlwave_print_info_entry,all[i],separator=sep
5774 endif else idlwave_print_info_entry,all[i],separator=sep
5776 all = routine_info(/functions)
5777 for i=0L,n_elements(all)-1L do begin
5779 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5780 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5781 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5783 print,'>>>END OF IDLWAVE ROUTINE INFO'
5786 pro idlwave_get_sysvars
5789 if error_status ne 0 then begin
5790 print, 'Cannot get info about system variables'
5792 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5793 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5794 v = strsplit(s,' +',/regex,/extract) ; get variables
5795 for i=0L,n_elements(v)-1 do begin
5796 t = [''] ; get tag list
5797 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5798 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5803 pro idlwave_get_class_tags, class
5804 res = execute('tags=tag_names({'+class+'})')
5805 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5807 ;; END OF IDLWAVE SUPPORT ROUTINES
5809 "The IDL programs to get info from the shell.")
5811 (defvar idlwave-idlwave_routine_info-compiled nil
5812 "Remember if the routine info procedure is already compiled.")
5814 (defvar idlwave-shell-temp-pro-file
)
5815 (defvar idlwave-shell-temp-rinfo-save-file
)
5817 (defun idlwave-shell-compile-helper-routines (&optional wait
)
5818 (unless (and idlwave-idlwave_routine_info-compiled
5819 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5820 (with-current-buffer (idlwave-find-file-noselect
5821 (idlwave-shell-temp-file 'pro
))
5823 (insert idlwave-routine-info.pro
)
5825 (idlwave-shell-send-command
5826 (concat ".run \"" idlwave-shell-temp-pro-file
"\"")
5828 (idlwave-shell-send-command
5829 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5830 (idlwave-shell-temp-file 'rinfo
))
5832 (setq idlwave-idlwave_routine_info-compiled t
))
5834 ;; Restore if necessary. Must use execute to hide lame routine_info
5835 ;; errors on undefinded routine
5836 (idlwave-shell-send-command
5837 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5838 idlwave-shell-temp-rinfo-save-file
5839 idlwave-shell-temp-rinfo-save-file
)
5843 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file
)
5844 "Query the shell for routine_info of compiled modules and update the lists."
5845 ;; Save and compile the procedure. The compiled procedure is then
5846 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5847 ;; need to test for and possibly RESTORE the procedure each time we
5848 ;; use it, since the user may have killed or redefined it. In
5849 ;; particular, .RESET_SESSION will kill all user procedures. If
5850 ;; FILE is set, only update routine info for routines in that file.
5852 (idlwave-shell-compile-helper-routines wait
)
5853 ; execute the routine_info procedure, and analyze the output
5854 (idlwave-shell-send-command
5855 (format "idlwave_routine_info%s" (if file
(concat ",'" file
"'") ""))
5857 (idlwave-shell-routine-info-filter)
5858 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5861 ;; ---------------------------------------------------------------------------
5863 ;; Completion and displaying routine calling sequences
5865 (defvar idlwave-completion-help-info nil
)
5866 (defvar idlwave-completion-help-links nil
)
5867 (defvar idlwave-current-obj_new-class nil
)
5868 (defvar idlwave-complete-special nil
)
5870 (defun idlwave-complete (&optional arg module class
)
5871 "Complete a function, procedure or keyword name at point.
5872 This function is smart and figures out what can be completed
5874 - At the beginning of a statement it completes procedure names.
5875 - In the middle of a statement it completes function names.
5876 - After a `(' or `,' in the argument list of a function or procedure,
5877 it completes a keyword of the relevant function or procedure.
5878 - In the first arg of `OBJ_NEW', it completes a class name.
5880 When several completions are possible, a list will be displayed in
5881 the *Completions* buffer. If this list is too long to fit into the
5882 window, scrolling can be achieved by repeatedly pressing
5883 \\[idlwave-complete].
5885 The function also knows about object methods. When it needs a class
5886 name, the action depends upon `idlwave-query-class', which see. You
5887 can force IDLWAVE to ask you for a class name with a
5888 \\[universal-argument] prefix argument to this command.
5890 See also the variables `idlwave-keyword-completion-adds-equal' and
5891 `idlwave-function-completion-adds-paren'.
5893 The optional ARG can be used to specify the completion type in order
5894 to override IDLWAVE's idea of what should be completed at point.
5895 Possible values are:
5897 0 <=> query for the completion type
5899 2 <=> 'procedure-keyword
5901 4 <=> 'function-keyword
5902 5 <=> 'procedure-method
5903 6 <=> 'procedure-method-keyword
5904 7 <=> 'function-method
5905 8 <=> 'function-method-keyword
5908 As a special case, the universal argument C-u forces completion of
5909 function names in places where the default would be a keyword.
5911 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5914 For Lisp programmers only:
5915 When we force a keyword, optional argument MODULE can contain the module name.
5916 When we force a method or a method keyword, CLASS can specify the class."
5921 (or (and (integerp arg
) (not (equal arg
'(16))))
5923 (idlwave-make-force-complete-where-list arg module class
)
5925 (what (nth 2 where-list
))
5926 (idlwave-force-class-query (equal arg
'(4)))
5927 (completion-regexp-list
5928 (if (equal arg
'(16))
5929 (list (read-string (concat "Completion Regexp: "))))))
5931 (if (and module
(string-match "::" module
))
5932 (setq class
(substring module
0 (match-beginning 0))
5933 module
(substring module
(match-end 0))))
5938 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5939 (get-buffer-window "*Completions*"))
5940 (setq this-command last-command
)
5941 (idlwave-scroll-completions))
5943 ;; Complete a filename in quotes
5944 ((and (idlwave-in-quote)
5945 (not (eq what
'class
)))
5946 (idlwave-complete-filename))
5948 ;; Check for any special completion functions
5949 ((and idlwave-complete-special
5950 (idlwave-call-special idlwave-complete-special
)))
5953 (error "Nothing to complete here"))
5957 (setq idlwave-completion-help-info
'(class))
5958 (idlwave-complete-class))
5960 ((eq what
'procedure
)
5961 ;; Complete a procedure name
5962 (let* ((cw-list (nth 3 where-list
))
5963 (class-selector (idlwave-determine-class cw-list
'pro
))
5964 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5965 (idlwave-all-class-inherits class-selector
)))
5966 (isa (concat "procedure" (if class-selector
"-method" "")))
5967 (type-selector 'pro
))
5968 (setq idlwave-completion-help-info
5969 (list 'routine nil type-selector class-selector nil super-classes
))
5970 (idlwave-complete-in-buffer
5971 'procedure
(if class-selector
'method
'routine
)
5972 (idlwave-routines) 'idlwave-selector
5973 (format "Select a %s name%s"
5976 (format " (class is %s)"
5977 (if (eq class-selector t
)
5978 "unknown" class-selector
))
5981 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
5983 ((eq what
'function
)
5984 ;; Complete a function name
5985 (let* ((cw-list (nth 3 where-list
))
5986 (class-selector (idlwave-determine-class cw-list
'fun
))
5987 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5988 (idlwave-all-class-inherits class-selector
)))
5989 (isa (concat "function" (if class-selector
"-method" "")))
5990 (type-selector 'fun
))
5991 (setq idlwave-completion-help-info
5992 (list 'routine nil type-selector class-selector nil super-classes
))
5993 (idlwave-complete-in-buffer
5994 'function
(if class-selector
'method
'routine
)
5995 (idlwave-routines) 'idlwave-selector
5996 (format "Select a %s name%s"
5999 (format " (class is %s)"
6000 (if (eq class-selector t
)
6001 "unknown" class-selector
))
6004 'idlwave-attach-method-classes
'idlwave-add-file-link-selector
)))
6006 ((and (memq what
'(procedure-keyword function-keyword
)) ; Special Case
6008 (idlwave-complete 3))
6010 ((eq what
'procedure-keyword
)
6011 ;; Complete a procedure keyword
6012 (let* ((where (nth 3 where-list
))
6014 (method-selector name
)
6015 (type-selector 'pro
)
6016 (class (idlwave-determine-class where
'pro
))
6017 (class-selector class
)
6018 (super-classes (idlwave-all-class-inherits class-selector
))
6019 (isa (format "procedure%s-keyword" (if class
"-method" "")))
6020 (entry (idlwave-best-rinfo-assq
6021 name
'pro class
(idlwave-routines)))
6022 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6023 (list (idlwave-entry-keywords entry
'do-link
)))
6024 (unless (or entry
(eq class t
))
6025 (error "Nothing known about procedure %s"
6026 (idlwave-make-full-name class name
)))
6027 (setq list
(idlwave-fix-keywords name
'pro class list
6028 super-classes system
))
6029 (unless list
(error "No keywords available for procedure %s"
6030 (idlwave-make-full-name class name
)))
6031 (setq idlwave-completion-help-info
6032 (list 'keyword name type-selector class-selector entry super-classes
))
6033 (idlwave-complete-in-buffer
6034 'keyword
'keyword list nil
6035 (format "Select keyword for procedure %s%s"
6036 (idlwave-make-full-name class name
)
6037 (if (or (member '("_EXTRA") list
)
6038 (member '("_REF_EXTRA") list
))
6039 " (note _EXTRA)" ""))
6041 'idlwave-attach-keyword-classes
)))
6043 ((eq what
'function-keyword
)
6044 ;; Complete a function keyword
6045 (let* ((where (nth 3 where-list
))
6047 (method-selector name
)
6048 (type-selector 'fun
)
6049 (class (idlwave-determine-class where
'fun
))
6050 (class-selector class
)
6051 (super-classes (idlwave-all-class-inherits class-selector
))
6052 (isa (format "function%s-keyword" (if class
"-method" "")))
6053 (entry (idlwave-best-rinfo-assq
6054 name
'fun class
(idlwave-routines)))
6055 (system (if entry
(eq (car (nth 3 entry
)) 'system
)))
6056 (list (idlwave-entry-keywords entry
'do-link
))
6058 (unless (or entry
(eq class t
))
6059 (error "Nothing known about function %s"
6060 (idlwave-make-full-name class name
)))
6061 (setq list
(idlwave-fix-keywords name
'fun class list
6062 super-classes system
))
6063 ;; OBJ_NEW: Messages mention the proper Init method
6064 (setq msg-name
(if (and (null class
)
6065 (string= (upcase name
) "OBJ_NEW"))
6066 (concat idlwave-current-obj_new-class
6067 "::Init (via OBJ_NEW)")
6068 (idlwave-make-full-name class name
)))
6069 (unless list
(error "No keywords available for function %s"
6071 (setq idlwave-completion-help-info
6072 (list 'keyword name type-selector class-selector nil super-classes
))
6073 (idlwave-complete-in-buffer
6074 'keyword
'keyword list nil
6075 (format "Select keyword for function %s%s" msg-name
6076 (if (or (member '("_EXTRA") list
)
6077 (member '("_REF_EXTRA") list
))
6078 " (note _EXTRA)" ""))
6080 'idlwave-attach-keyword-classes
)))
6082 (t (error "This should not happen (idlwave-complete)")))))
6084 (defvar idlwave-complete-special nil
6085 "List of special completion functions.
6086 These functions are called for each completion. Each function must
6087 check if its own special completion context is present. If yes, it
6088 should use `idlwave-complete-in-buffer' to do some completion and
6089 return t. If such a function returns t, *no further* attempts to
6090 complete other contexts will be done. If the function returns nil,
6091 other completions will be tried.")
6093 (defun idlwave-call-special (functions &rest args
)
6094 (let ((funcs functions
)
6097 (while (setq fun
(pop funcs
))
6098 (if (setq ret
(apply fun args
))
6102 (defun idlwave-make-force-complete-where-list (what &optional module class
)
6103 ;; Return an artificial WHERE specification to force the completion
6104 ;; routine to complete a specific item independent of context.
6105 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6106 ;; MODULE and CLASS can be used to specify the routine name and class.
6107 ;; The class name will also be found in MODULE if that is like "class::mod".
6108 (let* ((what-list '(("procedure") ("procedure-keyword")
6109 ("function") ("function-keyword")
6110 ("procedure-method") ("procedure-method-keyword")
6111 ("function-method") ("function-method-keyword")
6113 (module (idlwave-sintern-routine-or-method module class
))
6114 (class (idlwave-sintern-class class
))
6118 (intern (completing-read
6119 "Complete what? " what-list nil t
))))
6121 (setq what
(intern (car (nth (1- what
) what-list
)))))
6124 (assoc (symbol-name what
) what-list
))
6126 (t (error "Invalid WHAT"))))
6127 (nil-list '(nil nil nil nil
))
6128 (class-list (list nil nil
(or class t
) nil
)))
6132 ((eq what
'procedure
)
6133 (list nil-list nil-list
'procedure nil-list nil
))
6135 ((eq what
'procedure-keyword
)
6136 (let* ((class-selector nil
)
6138 (type-selector 'pro
)
6140 (idlwave-completing-read
6141 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
6142 (setq pro
(idlwave-sintern-routine pro
))
6143 (list nil-list nil-list
'procedure-keyword
6144 (list pro nil nil nil
) nil
)))
6146 ((eq what
'function
)
6147 (list nil-list nil-list
'function nil-list nil
))
6149 ((eq what
'function-keyword
)
6150 (let* ((class-selector nil
)
6152 (type-selector 'fun
)
6154 (idlwave-completing-read
6155 "Function: " (idlwave-routines) 'idlwave-selector
))))
6156 (setq func
(idlwave-sintern-routine func
))
6157 (list nil-list nil-list
'function-keyword
6158 (list func nil nil nil
) nil
)))
6160 ((eq what
'procedure-method
)
6161 (list nil-list nil-list
'procedure class-list nil
))
6163 ((eq what
'procedure-method-keyword
)
6164 (let* ((class (idlwave-determine-class class-list
'pro
))
6165 (class-selector class
)
6166 (super-classes (idlwave-all-class-inherits class-selector
))
6167 (type-selector 'pro
)
6169 (idlwave-completing-read
6170 (format "Procedure in %s class: " class-selector
)
6171 (idlwave-routines) 'idlwave-selector
))))
6172 (setq pro
(idlwave-sintern-method pro
))
6173 (list nil-list nil-list
'procedure-keyword
6174 (list pro nil class nil
) nil
)))
6176 ((eq what
'function-method
)
6177 (list nil-list nil-list
'function class-list nil
))
6179 ((eq what
'function-method-keyword
)
6180 (let* ((class (idlwave-determine-class class-list
'fun
))
6181 (class-selector class
)
6182 (super-classes (idlwave-all-class-inherits class-selector
))
6183 (type-selector 'fun
)
6185 (idlwave-completing-read
6186 (format "Function in %s class: " class-selector
)
6187 (idlwave-routines) 'idlwave-selector
))))
6188 (setq func
(idlwave-sintern-method func
))
6189 (list nil-list nil-list
'function-keyword
6190 (list func nil class nil
) nil
)))
6193 (list nil-list nil-list
'class nil-list nil
))
6195 (t (error "Invalid value for WHAT")))))
6197 (defun idlwave-completing-read (&rest args
)
6198 ;; Completing read, case insensitive
6199 (let ((old-value (default-value 'completion-ignore-case
)))
6202 (setq-default completion-ignore-case t
)
6203 (apply 'completing-read args
))
6204 (setq-default completion-ignore-case old-value
))))
6206 (defvar idlwave-shell-default-directory
)
6207 (defun idlwave-complete-filename ()
6208 "Use the comint stuff to complete a file name."
6210 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6211 (comint-completion-addsuffix nil
)
6213 (if (and (boundp 'idlwave-shell-default-directory
)
6214 (stringp idlwave-shell-default-directory
)
6215 (file-directory-p idlwave-shell-default-directory
))
6216 idlwave-shell-default-directory
6217 default-directory
)))
6218 (comint-dynamic-complete-filename)))
6220 (defun idlwave-make-full-name (class name
)
6221 ;; Make a fully qualified module name including the class name
6222 (concat (if class
(format "%s::" class
) "") name
))
6224 (defun idlwave-rinfo-assoc (name type class list
)
6225 "Like `idlwave-rinfo-assq', but sintern strings first."
6227 (idlwave-sintern-routine-or-method name class
)
6228 type
(idlwave-sintern-class class
) list
))
6230 (defun idlwave-rinfo-assq (name type class list
)
6231 ;; Works like assq, but also checks type and class
6234 (while (setq match
(assq name list
))
6235 (and (or (eq type t
)
6236 (eq (nth 1 match
) type
))
6237 (eq (nth 2 match
) class
)
6238 (throw 'exit match
))
6239 (setq list
(cdr (memq match list
)))))))
6241 (defun idlwave-rinfo-assq-any-class (name type class list
)
6242 ;; Return the first matching method on the inheritance list
6243 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
6246 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
6247 (setq classes nil
)))
6250 (defun idlwave-best-rinfo-assq (name type class list
&optional with-file
6252 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6253 If WITH-FILE is passed, find the best rinfo entry with a file
6254 included. If KEEP-SYSTEM is set, don't prune system for compiled
6256 (let ((twins (idlwave-routine-twins
6257 (idlwave-rinfo-assq-any-class name type class list
)
6260 (when (> (length twins
) 1)
6261 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
6262 (if (and (null keep-system
)
6263 (eq 'system
(car (nth 3 (car twins
))))
6264 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
6265 (not (equal 1 syslibp
)))
6266 ;; Its a compiled syslib, so we need to remove the system entry
6267 (setq twins
(cdr twins
)))
6269 (setq twins
(delq nil
6271 (if (nth 1 (nth 3 x
)) x
))
6275 (defun idlwave-best-rinfo-assoc (name type class list
&optional with-file
6277 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6278 (idlwave-best-rinfo-assq
6279 (idlwave-sintern-routine-or-method name class
)
6280 type
(idlwave-sintern-class class
) list with-file keep-system
))
6282 (defun idlwave-any-syslib (entries)
6283 "Does the entry list ENTRIES contain a syslib entry?
6284 If yes, return the index (>=1)."
6289 (setq file
(idlwave-routine-source-file (nth 3 (car entries
))))
6290 (if (and file
(idlwave-syslib-p file
))
6292 (setq entries
(cdr entries
))))
6295 (defun idlwave-all-assq (key list
)
6296 "Return a list of all associations of Key in LIST."
6298 (while (setq elt
(assq key list
))
6300 (setq list
(cdr (memq elt list
))))
6303 (defun idlwave-all-method-classes (method &optional type
)
6304 "Return all classes which have a method METHOD.
6305 TYPE is 'fun or 'pro.
6306 When TYPE is not specified, both procedures and functions will be considered."
6308 (mapcar 'car
(idlwave-class-alist))
6313 (eq type
(nth 1 x
)))
6314 (push (nth 2 x
) rtn
)))
6315 (idlwave-all-assq method
(idlwave-routines)))
6316 (idlwave-uniquify rtn
))))
6318 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
6319 "Return all classes which have a method METHOD with keyword KEYWORD.
6320 TYPE is 'fun or 'pro.
6321 When TYPE is not specified, both procedures and functions will be considered."
6322 (if (or (null method
)
6327 (and (nth 2 x
) ; non-nil class
6328 (or (not type
) ; correct or unspecified type
6329 (eq type
(nth 1 x
)))
6330 (assoc keyword
(idlwave-entry-keywords x
))
6331 (push (nth 2 x
) rtn
)))
6332 (idlwave-all-assq method
(idlwave-routines)))
6333 (idlwave-uniquify rtn
))))
6335 (defun idlwave-members-only (list club
)
6336 "Return list of all elements in LIST which are also in CLUB."
6339 (if (member (car list
) club
)
6340 (setq rtn
(cons (car list
) rtn
)))
6341 (setq list
(cdr list
)))
6344 (defun idlwave-nonmembers-only (list club
)
6345 "Return list of all elements in LIST which are not in CLUB."
6348 (if (member (car list
) club
)
6350 (setq rtn
(cons (car list
) rtn
)))
6351 (setq list
(cdr list
)))
6354 (defun idlwave-explicit-class-listed (info)
6355 "Return whether or not the class is listed explicitly, ala a->b::c.
6356 INFO is as returned by `idlwave-what-function' or `-procedure'."
6357 (let ((apos (nth 3 info
)))
6359 (save-excursion (goto-char apos
)
6360 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6362 (defvar idlwave-determine-class-special nil
6363 "List of special functions for determining class.
6364 Must accept two arguments: `apos' and `info'.")
6366 (defun idlwave-determine-class (info type
)
6367 ;; Determine the class of a routine call.
6368 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6369 ;; The second element in this structure is the class. When nil, we
6370 ;; return nil. When t, try to get the class from text properties at
6371 ;; the arrow. When the object is "self", we use the class of the
6372 ;; current routine. otherwise prompt the user for a class name.
6373 ;; Also stores the selected class as a text property at the arrow.
6374 ;; TYPE is 'fun or 'pro.
6375 (let* ((class (nth 2 info
))
6377 (nassoc (assoc (if (stringp (car info
))
6380 idlwave-query-class
))
6381 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
6382 idlwave-query-class
))
6383 (query (cond (nassoc (cdr nassoc
))
6384 (dassoc (cdr dassoc
))
6386 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
6389 (save-excursion (goto-char apos
)
6391 (let ((case-fold-search t
))
6392 (looking-at "self\\>")))))
6393 (force-query idlwave-force-class-query
)
6394 store special-class class-alist
)
6398 ;; There is an object which would like to know its class
6399 (if (and arrow
(get-text-property apos
'idlwave-class
)
6400 idlwave-store-inquired-class
6402 (setq class
(get-text-property apos
'idlwave-class
)
6403 class
(idlwave-sintern-class class
)))
6404 (if (and (eq t class
) is-self
)
6405 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
6407 ;; Before prompting, try any special class determination routines
6408 (when (and (eq t class
)
6409 idlwave-determine-class-special
6412 (idlwave-call-special idlwave-determine-class-special apos
))
6414 (setq class
(idlwave-sintern-class special-class
)
6415 store idlwave-store-inquired-class
)))
6417 ;; Prompt for a class, if we need to
6418 (when (and (eq class t
)
6419 (or force-query query
))
6421 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
6423 (idlwave-sintern-class
6425 ((and (= (length class-alist
) 0) (not force-query
))
6426 (error "No classes available with method %s" (car info
)))
6427 ((and (= (length class-alist
) 1) (not force-query
))
6428 (car (car class-alist
)))
6430 (setq store idlwave-store-inquired-class
)
6431 (idlwave-completing-read
6432 (format "Class%s: " (if (stringp (car info
))
6433 (format " for %s method %s"
6436 class-alist nil nil nil
'idlwave-class-history
))))))
6438 ;; Store it, if requested
6439 (when (and class
(not (eq t class
)))
6440 ;; We have a real class here
6441 (when (and store arrow
)
6443 (add-text-properties
6445 `(idlwave-class ,class face
,idlwave-class-arrow-face
6448 (setf (nth 2 info
) class
))
6451 ;; Default as fallback
6454 (defvar type-selector
)
6455 (defvar class-selector
)
6456 (defvar method-selector
)
6457 (defvar super-classes
)
6458 (defun idlwave-selector (a)
6459 (and (eq (nth 1 a
) type-selector
)
6460 (or (and (nth 2 a
) (eq class-selector t
))
6461 (eq (nth 2 a
) class-selector
)
6462 (memq (nth 2 a
) super-classes
))))
6464 (defun idlwave-add-file-link-selector (a)
6465 ;; Record a file link, if any, for the tested names during selection.
6466 (let ((sel (idlwave-selector a
)) file
)
6467 (if (and sel
(setq file
(idlwave-entry-has-help a
)))
6468 (push (cons (car a
) file
) idlwave-completion-help-links
))
6472 (defun idlwave-where ()
6473 "Find out where we are.
6474 The return value is a list with the following stuff:
6475 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6477 PRO-LIST (PRO POINT CLASS ARROW)
6478 FUNC-LIST (FUNC POINT CLASS ARROW)
6479 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6480 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6482 LAST-CHAR last relevant character before point (non-white non-comment,
6483 not part of current identifier or leading slash).
6485 In the lists, we have these meanings:
6488 POINT: Where is this
6489 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6490 ARROW: Location of the arrow"
6492 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6493 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
6494 (func-entry (idlwave-what-function bos
))
6495 (func (car func-entry
))
6496 (func-class (nth 1 func-entry
))
6497 (func-arrow (nth 2 func-entry
))
6498 (func-point (or (nth 3 func-entry
) 0))
6499 (func-level (or (nth 4 func-entry
) 0))
6500 (pro-entry (idlwave-what-procedure bos
))
6501 (pro (car pro-entry
))
6502 (pro-class (nth 1 pro-entry
))
6503 (pro-arrow (nth 2 pro-entry
))
6504 (pro-point (or (nth 3 pro-entry
) 0))
6505 (last-char (idlwave-last-valid-char))
6506 (case-fold-search t
)
6507 (match-string (buffer-substring bos
(point)))
6508 cw cw-mod cw-arrow cw-class cw-point
)
6509 (if (< func-point pro-point
) (setq func nil
))
6511 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6515 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6517 (buffer-substring pro-point
(point))
6519 (setq cw
'procedure cw-class pro-class cw-point pro-point
6520 cw-arrow pro-arrow
))
6521 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6524 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6527 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6531 (> func-point pro-point
)
6533 (memq last-char
'(?\
( ?
,)))
6534 (setq cw
'function-keyword cw-mod func cw-point func-point
6535 cw-class func-class cw-arrow func-arrow
))
6536 ((and pro
(eq last-char ?
,))
6537 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
6538 cw-class pro-class cw-arrow pro-arrow
))
6539 ; ((member last-char '(?\' ?\) ?\] ?!))
6540 ; ;; after these chars, a function makes no sense
6541 ; ;; FIXME: I am sure there can be more in this list
6542 ; ;; FIXME: Do we want to do this at all?
6544 ;; Everywhere else we try a function.
6548 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
6549 (setq cw-arrow
(copy-marker (match-beginning 0))
6550 cw-class
(if (match-end 4)
6551 (idlwave-sintern-class (match-string 4))
6553 (list (list pro pro-point pro-class pro-arrow
)
6554 (list func func-point func-class func-arrow
)
6556 (list cw-mod cw-point cw-class cw-arrow
)
6559 (defun idlwave-this-word (&optional class
)
6560 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6561 (setq class
(or class
"a-zA-Z0-9$_."))
6564 (progn (skip-chars-backward class
) (point))
6565 (progn (skip-chars-forward class
) (point)))))
6567 (defun idlwave-what-function (&optional bound
)
6568 ;; Find out if point is within the argument list of a function.
6569 ;; The return value is ("function-name" class arrow-start (point) level).
6570 ;; Level is 1 on the top level parentheses, higher further down.
6572 ;; If the optional BOUND is an integer, bound backwards directed
6573 ;; searches to this point.
6579 func arrow-start class
)
6580 (idlwave-with-special-syntax
6583 (narrow-to-region (max 1 (or bound
0)) (point-max))
6584 ;; move back out of the current parenthesis
6585 (while (condition-case nil
6586 (progn (up-list -
1) t
)
6590 (when (and (= (following-char) ?\
()
6592 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6594 (setq func
(match-string 2)
6595 func-point
(goto-char (match-beginning 2))
6597 (if (re-search-backward
6598 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
6599 (setq arrow-start
(copy-marker (match-beginning 0))
6600 class
(or (match-string 2) t
)))
6604 (idlwave-sintern-routine-or-method func class
)
6605 (idlwave-sintern-class class
)
6606 arrow-start func-point cnt
)))
6608 (throw 'exit nil
)))))))
6610 (defun idlwave-what-procedure (&optional bound
)
6611 ;; Find out if point is within the argument list of a procedure.
6612 ;; The return value is ("procedure-name" class arrow-pos (point)).
6614 ;; If the optional BOUND is an integer, bound backwards directed
6615 ;; searches to this point.
6616 (let ((pos (point)) pro-point
6617 pro class arrow-start string
)
6619 ;;(idlwave-beginning-of-statement)
6620 (idlwave-start-of-substatement 'pre
)
6621 (setq string
(buffer-substring (point) pos
))
6623 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
6624 (setq pro
(match-string 1 string
)
6625 pro-point
(+ (point) (match-beginning 1)))
6626 (if (and (idlwave-skip-object)
6627 (setq string
(buffer-substring (point) pos
))
6629 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6631 (setq pro
(if (match-beginning 4)
6632 (match-string 4 string
))
6633 pro-point
(if (match-beginning 4)
6634 (+ (point) (match-beginning 4))
6636 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
6637 class
(or (match-string 3 string
) t
)))))
6638 (list (idlwave-sintern-routine-or-method pro class
)
6639 (idlwave-sintern-class class
)
6643 (defun idlwave-skip-object ()
6644 ;; If there is an object at point, move over it and return t.
6645 (let ((pos (point)))
6648 (skip-chars-forward " ") ; white space
6649 (skip-chars-forward "*") ; de-reference
6651 ((looking-at idlwave-identifier
)
6652 (goto-char (match-end 0)))
6653 ((eq (following-char) ?\
()
6655 (t (throw 'exit nil
)))
6658 (cond ((eq (following-char) ?.
)
6660 (if (not (looking-at idlwave-identifier
))
6662 (goto-char (match-end 0)))
6663 ((memq (following-char) '(?\
( ?\
[))
6666 (error (throw 'exit nil
))))
6667 (t (throw 'endwhile t
)))))
6668 (if (looking-at "[ \t]*->")
6669 (throw 'exit
(setq pos
(match-beginning 0)))
6670 (throw 'exit nil
))))
6674 (defun idlwave-last-valid-char ()
6675 "Return the last character before point which is not white or a comment
6676 and also not part of the current identifier. Since we do this in
6677 order to identify places where keywords are, we consider the initial
6678 `/' of a keyword as part of the identifier.
6679 This function is not general, can only be used for completion stuff."
6682 ;; skip the current identifier
6683 (skip-chars-backward "a-zA-Z0-9_$")
6684 ;; also skip a leading slash which might be belong to the keyword
6685 (if (eq (preceding-char) ?
/)
6687 ;; FIXME: does not check if this is a valid identifier
6689 (skip-chars-backward " \t")
6691 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
6692 ((eq (preceding-char) ?
\n)
6693 (beginning-of-line 0)
6694 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6695 ;; continuation line
6696 (goto-char (match-end 1))
6698 (t (throw 'exit
(preceding-char))))))))
6700 (defvar idlwave-complete-after-success-form nil
6701 "A form to evaluate after successful completion.")
6702 (defvar idlwave-complete-after-success-form-force nil
6703 "A form to evaluate after completion selection in *Completions* buffer.")
6704 (defconst idlwave-completion-mark
(make-marker)
6705 "A mark pointing to the beginning of the completion string.")
6707 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6708 &optional prepare-display-function
6710 "Perform TYPE completion of word before point against LIST.
6711 SELECTOR is the PREDICATE argument for the completion function. Show
6712 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6713 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
6714 used only once, for `all-completions', and can be used to, e.g.,
6715 accumulate information on matching completions."
6716 (let* ((completion-ignore-case t
)
6717 beg
(end (point)) slash part spart completion all-completions
6721 (error (concat prompt
": No completions available")))
6723 ;; What is already in the buffer?
6725 (skip-chars-backward "a-zA-Z0-9_$")
6726 (setq slash
(eq (preceding-char) ?
/)
6728 idlwave-complete-after-success-form
6729 (list 'idlwave-after-successful-completion
6730 (list 'quote type
) slash beg
)
6731 idlwave-complete-after-success-form-force
6732 (list 'idlwave-after-successful-completion
6733 (list 'quote type
) slash
(list 'quote
'force
))))
6736 (setq part
(buffer-substring beg end
)
6737 dpart
(downcase part
)
6738 spart
(idlwave-sintern stype part
)
6739 completion
(try-completion part list selector
)
6740 dcompletion
(if (stringp completion
) (downcase completion
))
6741 idlwave-completion-help-links nil
)
6744 ;; nothing available.
6745 (error (concat prompt
": no completion for \"%s\"") part
))
6746 ((and (not (equal dpart dcompletion
))
6747 (not (eq t completion
)))
6748 ;; We can add something
6749 (delete-region beg end
)
6750 (if (and (string= part dpart
)
6751 (or (not (string= part
""))
6752 idlwave-complete-empty-string-as-lower-case
)
6753 (not idlwave-completion-force-default-case
))
6754 (insert dcompletion
)
6755 (insert completion
))
6756 (if (eq t
(try-completion completion list selector
))
6757 ;; Now this is a unique match
6758 (idlwave-after-successful-completion type slash beg
))
6760 ((or (eq completion t
)
6761 (and (= 1 (length (setq all-completions
6763 (all-completions part list
6764 (or special-selector
6766 (equal dpart dcompletion
)))
6767 ;; This is already complete
6768 (idlwave-after-successful-completion type slash beg
)
6769 (message "%s is already the complete %s" part isa
)
6772 ;; We cannot add something - offer a list.
6773 (message "Making completion list...")
6775 (unless idlwave-completion-help-links
; already set somewhere?
6776 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6777 (let ((link (get-text-property 0 'link
(car x
))))
6779 (push (cons (car x
) link
)
6780 idlwave-completion-help-links
))))
6782 (let* ((list all-completions
)
6783 ;; "complete" means, this is already a valid completion
6784 (complete (memq spart all-completions
))
6785 (completion-highlight-first-word-only t
)) ; XEmacs
6786 ; (completion-fixup-function ; Emacs
6787 ; (lambda () (and (eq (preceding-char) ?>)
6788 ; (re-search-backward " <" beg t)))))
6790 (setq list
(sort list
(lambda (a b
)
6791 (string< (downcase a
) (downcase b
)))))
6792 (if prepare-display-function
6793 (setq list
(funcall prepare-display-function list
)))
6794 (if (and (string= part dpart
)
6795 (or (not (string= part
""))
6796 idlwave-complete-empty-string-as-lower-case
)
6797 (not idlwave-completion-force-default-case
))
6798 (setq list
(mapcar (lambda (x)
6800 (setcar x
(downcase (car x
)))
6801 (setq x
(downcase x
)))
6804 (idlwave-display-completion-list list prompt beg complete
))
6807 (defun idlwave-complete-class ()
6808 "Complete a class at point."
6810 ;; Call `idlwave-routines' to make sure the class list will be available
6812 ;; Check for the special case of completing empty string after pro/function
6813 (if (let ((case-fold-search t
))
6816 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6818 (goto-char (point-min))
6820 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
6821 ;; Yank the full class specification
6822 (insert (match-string 2))
6823 ;; Do the completion, using list gathered from `idlwave-routines'
6824 (idlwave-complete-in-buffer
6825 'class
'class
(idlwave-class-alist) nil
6826 "Select a class" "class"
6827 '(lambda (list) ;; Push it to help-links if system help available
6829 (let* ((entry (idlwave-class-info x
))
6830 (link (nth 1 (assq 'link entry
))))
6831 (if link
(push (cons x link
)
6832 idlwave-completion-help-links
))
6836 (defun idlwave-attach-classes (list type show-classes
)
6837 ;; Attach the proper class list to a LIST of completion items.
6838 ;; TYPE, when 'kwd, shows classes for method keywords, when
6839 ;; 'class-tag, for class tags, and otherwise for methods.
6840 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6841 (if (or (null show-classes
) ; don't want to see classes
6842 (null class-selector
) ; not a method call
6844 (stringp class-selector
) ; the class is already known
6845 (not super-classes
))) ; no possibilities for inheritance
6846 ;; In these cases, we do not have to do anything
6848 (let* ((do-prop (and (>= show-classes
0)
6849 (>= emacs-major-version
21)))
6850 (do-buf (not (= show-classes
0)))
6851 ;; (do-dots (featurep 'xemacs))
6853 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
6854 (cons class-selector super-classes
)))
6855 (max (abs show-classes
))
6856 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
6857 classes nclasses class-info space
)
6861 (if (eq type
'class-tag
)
6862 ;; Just one class for tags
6865 (idlwave-class-or-superclass-with-tag class-selector x
)))
6866 ;; Multiple classes for method or method-keyword
6869 (idlwave-all-method-keyword-classes
6870 method-selector x type-selector
)
6871 (idlwave-all-method-classes x type-selector
)))
6875 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6877 (setq nclasses
(length classes
))
6878 ;; Make the separator between item and class-info
6880 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6883 ;; We do want info in the buffer
6884 (if (<= nclasses max
)
6885 (setq class-info
(concat
6887 "<" (mapconcat 'identity classes
",") ">"))
6888 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6889 (setq class-info nil
))
6891 ;; We do want properties
6892 (setq x
(copy-sequence x
))
6893 (put-text-property 0 (length x
)
6894 'help-echo
(mapconcat 'identity classes
" ")
6901 (defun idlwave-attach-method-classes (list)
6902 ;; Call idlwave-attach-classes with method parameters
6903 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6904 (defun idlwave-attach-keyword-classes (list)
6905 ;; Call idlwave-attach-classes with keyword parameters
6906 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6907 (defun idlwave-attach-class-tag-classes (list)
6908 ;; Call idlwave-attach-classes with class structure tags
6909 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6912 ;;----------------------------------------------------------------------
6913 ;;----------------------------------------------------------------------
6914 ;;----------------------------------------------------------------------
6915 ;;----------------------------------------------------------------------
6916 ;;----------------------------------------------------------------------
6918 (defun idlwave-pset (item)
6921 (defun idlwave-popup-select (ev list title
&optional sort
)
6922 "Select an item in LIST with a popup menu.
6923 TITLE is the title to put atop the popup. If SORT is non-nil,
6924 sort the list before displaying."
6925 (let ((maxpopup idlwave-max-popup-menu-items
)
6928 ((= 1 (length list
))
6929 (setq rtn
(car list
)))
6931 (if sort
(setq list
(sort list
(lambda (a b
)
6932 (string< (upcase a
) (upcase b
))))))
6934 (append (list title
)
6935 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6938 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6939 (setq resp
(get-popup-menu-response menu
))
6940 (funcall (event-function resp
) (event-object resp
)))
6942 (if sort
(setq list
(sort list
(lambda (a b
)
6943 (string< (upcase a
) (upcase b
))))))
6944 (setq menu
(cons title
6947 (mapcar (lambda(x) (cons x x
)) list
)))))
6948 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6949 (setq rtn
(x-popup-menu ev menu
))))
6952 (defun idlwave-split-menu-xemacs (menu N
)
6953 "Split the MENU into submenus of maximum length N."
6954 (if (<= (length menu
) (1+ N
))
6955 ;; No splitting needed
6957 (let* ((title (car menu
))
6958 (entries (cdr menu
))
6963 (while (and entries
(< cnt N
))
6965 nextmenu
(cons (car entries
) nextmenu
)
6966 entries
(cdr entries
)))
6967 (setq nextmenu
(nreverse nextmenu
))
6968 (setq nextmenu
(cons (format "%s...%s"
6969 (aref (car nextmenu
) 0)
6970 (aref (nth (1- cnt
) nextmenu
) 0))
6972 (setq menu
(cons nextmenu menu
)
6977 (defun idlwave-split-menu-emacs (menu N
)
6978 "Split the MENU into submenus of maximum length N."
6979 (if (<= (length (nth 1 menu
)) (1+ N
))
6980 ;; No splitting needed
6982 (let* ((title (car menu
))
6983 (entries (cdr (nth 1 menu
)))
6988 (while (and entries
(< cnt N
))
6990 nextmenu
(cons (car entries
) nextmenu
)
6991 entries
(cdr entries
)))
6992 (setq nextmenu
(nreverse nextmenu
))
6994 (setq nextmenu
(cons (format "%s...%s"
6995 (car (car nextmenu
))
6996 (car (nth (1- cnt
) nextmenu
)))
6998 (setq menu
(cons nextmenu menu
)
7001 (setq menu
(nreverse menu
))
7002 (setq menu
(cons title menu
))
7005 (defvar idlwave-completion-setup-hook nil
)
7007 (defun idlwave-scroll-completions (&optional message
)
7008 "Scroll the completion window on this frame."
7009 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
7010 (win (selected-window)))
7013 (select-window cwin
)
7016 (error (if (and (listp last-command
)
7017 (nth 2 last-command
))
7020 (eval idlwave-complete-after-success-form
))
7021 (set-window-start cwin
(point-min)))))
7022 (and message
(message "%s" message
)))
7023 (select-window win
))))
7025 (defun idlwave-display-completion-list (list &optional message beg complete
)
7026 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7027 (unless (and (get-buffer-window "*Completions*")
7028 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
7029 (move-marker idlwave-completion-mark beg
)
7030 (setq idlwave-before-completion-wconf
(current-window-configuration)))
7032 (if (featurep 'xemacs
)
7033 (idlwave-display-completion-list-xemacs
7035 (idlwave-display-completion-list-emacs list
))
7037 ;; Store a special value in `this-command'. When `idlwave-complete'
7038 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7039 (setq this-command
(list 'idlwave-display-completion-list message complete
))
7041 ;; Mark the completions buffer as created by cib
7042 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
7044 ;; Fontify the classes
7045 (if (and idlwave-completion-fontify-classes
7047 (idlwave-completion-fontify-classes))
7050 (run-hooks 'idlwave-completion-setup-hook
)
7052 ;; Display the message
7053 (message "%s" (or message
"Making completion list...done")))
7055 (defun idlwave-choose (function &rest args
)
7056 "Call FUNCTION as a completion chooser and pass ARGS to it."
7057 (let ((completion-ignore-case t
)) ; install correct value
7058 (apply function args
))
7059 (if (and (eq major-mode
'idlwave-shell-mode
)
7060 (boundp 'font-lock-mode
)
7061 (not font-lock-mode
))
7062 ;; For the shell, remove the fontification of the word before point
7063 (let ((beg (save-excursion
7064 (skip-chars-backward "a-zA-Z0-9_")
7066 (remove-text-properties beg
(point) '(face nil
))))
7067 (eval idlwave-complete-after-success-form-force
))
7069 (defun idlwave-keyboard-quit ()
7072 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
7073 (idlwave-restore-wconf-after-completion))
7076 (defun idlwave-restore-wconf-after-completion ()
7077 "Restore the old (before completion) window configuration."
7078 (and idlwave-completion-restore-window-configuration
7079 idlwave-before-completion-wconf
7080 (set-window-configuration idlwave-before-completion-wconf
)))
7082 (defun idlwave-one-key-select (sym prompt delay
)
7083 "Make the user select an element from the alist in the variable SYM.
7084 The keys of the alist are expected to be strings. The function returns the
7085 car of the selected association.
7086 To do this, PROMPT is displayed and the user must hit a letter key to
7087 select an entry. If the user does not reply within DELAY seconds, a help
7088 window with the options is displayed automatically.
7089 The key which is associated with each option is generated automatically.
7090 First, the strings are checked for preselected keys, like in \"[P]rint\".
7091 If these don't exist, a letter in the string is automatically selected."
7092 (let* ((alist (symbol-value sym
))
7093 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer
)
7094 '(fit-window-to-buffer)))
7096 ;; First check the cache
7097 (if (and (eq (symbol-value sym
) (get sym
:one-key-alist-last
)))
7098 (setq keys-alist
(get sym
:one-key-alist-cache
))
7099 ;; Need to make new list
7100 (setq keys-alist
(idlwave-make-one-key-alist alist
))
7101 (put sym
:one-key-alist-cache keys-alist
)
7102 (put sym
:one-key-alist-last alist
))
7103 ;; Display prompt and wait for quick reply
7104 (message "%s[%s]" prompt
7105 (mapconcat (lambda(x) (char-to-string (car x
)))
7108 ;; No quick reply: Show help
7109 (save-window-excursion
7110 (with-output-to-temp-buffer "*Completions*"
7115 (setq char
(read-char)))
7116 (setq char
(read-char)))
7118 ;; Return the selected result
7119 (nth 2 (assoc char keys-alist
))))
7121 ;; Used for, e.g., electric debug super-examine.
7122 (defun idlwave-make-one-key-alist (alist)
7123 "Make an alist for single key selection."
7124 (let ((l alist
) keys-alist name start char help
7126 (case-fold-search nil
))
7128 (setq name
(car (car l
))
7131 ;; First check if the configuration predetermined a key
7132 (if (string-match "\\[\\(.\\)\\]" name
)
7134 (setq char
(string-to-char (downcase (match-string 1 name
)))
7135 help
(format "%c: %s" char name
)
7136 keys-alist
(cons (list char help name
) keys-alist
))
7138 ;; Then check for capital letters
7140 (while (string-match "[A-Z]" name start
)
7141 (setq start
(match-end 0)
7142 char
(string-to-char (downcase (match-string 0 name
))))
7143 (if (not (assoc char keys-alist
))
7145 (setq help
(format "%c: %s" char
7147 (concat "[" (match-string 0 name
) "]")
7149 keys-alist
(cons (list char help name
) keys-alist
))
7151 ;; Now check for lowercase letters
7153 (while (string-match "[a-z]" name start
)
7154 (setq start
(match-end 0)
7155 char
(string-to-char (match-string 0 name
)))
7156 (if (not (assoc char keys-alist
))
7158 (setq help
(format "%c: %s" char
7160 (concat "[" (match-string 0 name
) "]")
7162 keys-alist
(cons (list char help name
) keys-alist
))
7164 ;; Bummer, nothing found! Use a stupid number
7165 (setq char
(string-to-char (int-to-string (setq cnt
(1+ cnt
))))
7166 help
(format "%c: %s" char name
)
7167 keys-alist
(cons (list char help name
) keys-alist
))))
7168 (nreverse keys-alist
)))
7170 (defun idlwave-set-local (var value
&optional buffer
)
7171 "Set the buffer-local value of VAR in BUFFER to VALUE."
7172 (with-current-buffer (or buffer
(current-buffer))
7173 (set (make-local-variable var
) value
)))
7175 (defun idlwave-local-value (var &optional buffer
)
7176 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7177 (with-current-buffer (or buffer
(current-buffer))
7178 (and (local-variable-p var
(current-buffer))
7179 (symbol-value var
))))
7181 ;; In XEmacs, we can use :activate-callback directly to advice the
7182 ;; choose functions. We use the private keymap only for the online
7185 (defvar idlwave-completion-map nil
7186 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7188 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
7189 (with-output-to-temp-buffer "*Completions*"
7190 (apply 'display-completion-list list
7191 ':activate-callback
'idlwave-default-choose-completion
7193 (with-current-buffer "*Completions*"
7195 (or idlwave-completion-map
7196 (setq idlwave-completion-map
7197 (idlwave-make-modified-completion-map-xemacs
7198 (current-local-map)))))))
7200 (defun idlwave-default-choose-completion (&rest args
)
7201 "Execute `default-choose-completion' and then restore the win-conf."
7202 (apply 'idlwave-choose
'default-choose-completion args
))
7204 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7205 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7206 (let ((new-map (copy-keymap old-map
)))
7207 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
7208 (define-key new-map [button3] (lambda ()
7210 (setq this-command last-command)))
7213 ;; In Emacs we also replace keybindings in the completion
7214 ;; map in order to install our wrappers.
7216 (defun idlwave-display-completion-list-emacs (list)
7217 "Display completion list and install the choose wrappers."
7218 (with-output-to-temp-buffer "*Completions*"
7219 (display-completion-list list))
7220 (with-current-buffer "*Completions*"
7222 (or idlwave-completion-map
7223 (setq idlwave-completion-map
7224 (idlwave-make-modified-completion-map-emacs
7225 (current-local-map)))))))
7227 (defun idlwave-make-modified-completion-map-emacs (old-map)
7228 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7229 (let ((new-map (copy-keymap old-map)))
7230 (substitute-key-definition
7231 'choose-completion 'idlwave-choose-completion new-map)
7232 (substitute-key-definition
7233 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7234 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7237 (defun idlwave-choose-completion (&rest args)
7238 "Choose the completion that point is in or next to."
7240 (apply 'idlwave-choose 'choose-completion args))
7242 (defun idlwave-mouse-choose-completion (&rest args)
7243 "Click on an alternative in the `*Completions*' buffer to choose it."
7245 (apply 'idlwave-choose 'mouse-choose-completion args))
7247 ;;----------------------------------------------------------------------
7248 ;;----------------------------------------------------------------------
7250 ;;; ------------------------------------------------------------------------
7251 ;;; Stucture parsing code, and code to manage class info
7254 ;; - Go again over the documentation how to write a completion
7255 ;; plugin. It is in self.el, but currently still very bad.
7256 ;; This could be in a separate file in the distribution, or
7257 ;; in an appendix for the manual.
7259 (defvar idlwave-struct-skip
7260 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7261 "Regexp for skipping continued blank or comment-only lines in structures.")
7263 (defvar idlwave-struct-tag-regexp
7264 (concat "[{,]" ;leading comma/brace
7265 idlwave-struct-skip ; 4 groups
7266 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7267 "[ \t]*:") ; the final colon
7268 "Regexp for structure tags.")
7270 (defun idlwave-struct-tags ()
7271 "Return a list of all tags in the structure defined at point.
7272 Point is expected just before the opening `{' of the struct definition."
7274 (let* ((borders (idlwave-struct-borders))
7280 (narrow-to-region beg end)
7281 (while (re-search-forward idlwave-struct-tag-regexp end t)
7282 ;; Check if we are still on the top level of the structure.
7283 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7285 (push (match-string-no-properties 5) tags))
7286 (goto-char (match-end 0))))
7289 (defun idlwave-find-struct-tag (tag)
7290 "Find a given TAG in the structure defined at point."
7291 (let* ((borders (idlwave-struct-borders))
7294 (case-fold-search t))
7295 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7298 (defun idlwave-struct-inherits ()
7299 "Return a list of all `inherits' names in the struct at point.
7300 Point is expected just before the opening `{' of the struct definition."
7302 (let* ((borders (idlwave-struct-borders))
7305 (case-fold-search t)
7309 (narrow-to-region beg end)
7310 (while (re-search-forward
7311 (concat "[{,]" ;leading comma/brace
7312 idlwave-struct-skip ; 4 groups
7313 "inherits" ; The INHERITS tag
7314 idlwave-struct-skip ; 4 more
7315 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7317 ;; Check if we are still on the top level of the structure.
7318 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7320 (push (match-string-no-properties 9) names))
7321 (goto-char (match-end 0))))
7324 (defun idlwave-in-structure ()
7325 "Return t if point is inside an IDL structure definition."
7326 (let ((beg (point)))
7328 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7329 (if (idlwave-find-structure-definition nil nil 'back)
7330 (let ((borders (idlwave-struct-borders)))
7331 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7332 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7334 (defun idlwave-struct-borders ()
7335 "Return the borders of the {...} after point as a cons cell."
7338 (skip-chars-forward "^{")
7340 (condition-case nil (forward-list 1)
7341 (error (goto-char beg)))
7342 (cons beg (point)))))
7344 (defun idlwave-find-structure-definition (&optional var name bound)
7345 "Search forward for a structure definition.
7346 If VAR is non-nil, search for a structure assigned to variable VAR.
7347 If NAME is non-nil, search for a named structure NAME, if a string,
7348 or a generic named structure otherwise. If BOUND is an integer, limit
7349 the search. If BOUND is the symbol `all', we search first back and
7350 then forward through the entire file. If BOUND is the symbol `back'
7351 we search only backward."
7352 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7353 (case-fold-search t)
7354 (lim (if (integerp bound) bound nil))
7357 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7362 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7363 ;; Just a generic name
7364 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7366 (if (or (and (or (eq bound 'all) (eq bound 'back))
7367 (re-search-backward re nil t))
7368 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7370 (goto-char (match-beginning 3))
7371 (match-string-no-properties 5)))))
7373 (defvar idlwave-class-info nil)
7374 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7376 (add-hook 'idlwave-update-rinfo-hook
7377 (lambda () (setq idlwave-class-reset t)))
7378 (add-hook 'idlwave-after-load-rinfo-hook
7379 (lambda () (setq idlwave-class-info nil)))
7381 (defun idlwave-class-info (class)
7383 (if idlwave-class-info
7384 (if idlwave-class-reset
7386 idlwave-class-reset nil
7387 idlwave-class-info ; Remove any visited in a buffer
7391 (idlwave-class-file-or-buffer
7392 (or (cdr (assq 'found-in x)) (car x)))))
7396 idlwave-class-info))))
7397 ;; Info is nil, put in the system stuff to start.
7398 (setq idlwave-class-info idlwave-system-class-info)
7399 (setq list idlwave-class-info)
7400 (while (setq entry (pop list))
7401 (idlwave-sintern-class-info entry)))
7402 (setq class (idlwave-sintern-class class))
7403 (or (assq class idlwave-class-info)
7404 (progn (idlwave-scan-class-info class)
7405 (assq class idlwave-class-info)))))
7407 (defun idlwave-sintern-class-info (entry)
7408 "Sintern the class names in a class-info entry."
7409 (let ((taglist (assq 'tags entry))
7410 (inherits (assq 'inherits entry)))
7411 (setcar entry (idlwave-sintern-class (car entry) 'set))
7413 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7416 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7417 "Find class structure definition(s).
7418 If ALL-HOOK is set, find all named structure definitions in a given
7419 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7420 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7421 class/struct definition."
7422 (let ((case-fold-search t) end-lim list name)
7423 (when (re-search-forward
7424 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7427 ;; For everything there
7428 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7430 (idlwave-find-structure-definition nil t end-lim))
7431 (funcall all-hook name)))
7432 (idlwave-find-structure-definition nil (or alt-class class))))))
7435 (defun idlwave-class-file-or-buffer (class)
7436 "Find buffer visiting CLASS definition."
7437 (let* ((pro (concat (downcase class) "__define"))
7438 (file (idlwave-routine-source-file
7439 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7440 (idlwave-routines))))))
7441 (cons file (if file (idlwave-get-buffer-visiting file)))))
7444 (defun idlwave-scan-class-info (class)
7445 "Scan all class and named structure info in the class__define pro."
7446 (let* ((idlwave-auto-routine-info-updates nil)
7447 (filebuf (idlwave-class-file-or-buffer class))
7448 (file (car filebuf))
7450 (class (idlwave-sintern-class class)))
7453 (and ;; neither a regular file nor a visited buffer
7455 (not (file-regular-p file))))
7456 nil ; Cannot find the file/buffer to get any info
7458 (if buf (set-buffer buf)
7459 ;; Read the file in temporarily
7460 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7462 (unless (eq major-mode 'idlwave-mode)
7464 (insert-file-contents file))
7467 (idlwave-find-class-definition class
7468 ;; Scan all of the structures found there
7470 (let* ((this-class (idlwave-sintern-class name))
7473 (cons 'tags (idlwave-struct-tags))
7474 (cons 'inherits (idlwave-struct-inherits)))))
7475 (if (not (eq this-class class))
7476 (setq entry (nconc entry (list (cons 'found-in class)))))
7477 (idlwave-sintern-class-info entry)
7478 (push entry idlwave-class-info)))))))))
7480 (defun idlwave-class-found-in (class)
7481 "Return the FOUND-IN property of the CLASS."
7482 (cdr (assq 'found-in (idlwave-class-info class))))
7483 (defun idlwave-class-tags (class)
7484 "Return the native tags in CLASS."
7485 (cdr (assq 'tags (idlwave-class-info class))))
7486 (defun idlwave-class-inherits (class)
7487 "Return the direct superclasses of CLASS."
7488 (cdr (assq 'inherits (idlwave-class-info class))))
7491 (defun idlwave-all-class-tags (class)
7492 "Return a list of native and inherited tags in CLASS."
7494 (apply 'append (mapcar 'idlwave-class-tags
7495 (cons class (idlwave-all-class-inherits class))))
7497 (idlwave-class-tag-reset)
7498 (error "%s" (error-message-string err)))))
7501 (defun idlwave-all-class-inherits (class)
7502 "Return a list of all superclasses of CLASS (recursively expanded).
7503 The list is cached in `idlwave-class-info' for faster access."
7505 ((not idlwave-support-inheritance) nil)
7506 ((eq class nil) nil)
7509 (let ((info (idlwave-class-info class))
7511 (if (setq entry (assq 'all-inherits info))
7513 ;; Save the depth of inheritance scan to check for circular references
7514 (let ((inherits (mapcar (lambda (x) (cons x 0))
7515 (idlwave-class-inherits class)))
7516 rtn all-inherits cl)
7518 (setq cl (pop inherits)
7519 rtn (cons (car cl) rtn)
7520 inherits (append (mapcar (lambda (x)
7521 (cons x (1+ (cdr cl))))
7522 (idlwave-class-inherits (car cl)))
7524 (if (> (cdr cl) 999)
7526 "Class scan: inheritance depth exceeded. Circular inheritance?")
7528 (setq all-inherits (nreverse rtn))
7529 (nconc info (list (cons 'all-inherits all-inherits)))
7532 (defun idlwave-entry-keywords (entry &optional record-link)
7533 "Return the flat entry keywords alist from routine-info entry.
7534 If RECORD-LINK is non-nil, the keyword text is copied and a text
7535 property indicating the link is added."
7539 (let ((file (car key-list)))
7540 (mapcar (lambda (key-cons)
7541 (let ((key (car key-cons))
7542 (link (cdr key-cons)))
7543 (when (and record-link file)
7544 (setq key (copy-sequence key))
7551 (concat idlwave-html-link-sep
7552 (number-to-string link))))
7554 (push (list key) kwds)))
7559 (defun idlwave-entry-find-keyword (entry keyword)
7560 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7564 (let ((file (car key-list))
7565 (kwd (assoc keyword (cdr key-list))))
7567 (setq kwd (cons (car kwd)
7568 (if (and file (cdr kwd))
7570 idlwave-html-link-sep
7571 (number-to-string (cdr kwd)))
7573 (throw 'exit kwd))))
7576 ;;==========================================================================
7578 ;; Completing class structure tags. This is a completion plugin.
7579 ;; The necessary taglist is constructed dynamically
7581 (defvar idlwave-current-tags-class nil)
7582 (defvar idlwave-current-class-tags nil)
7583 (defvar idlwave-current-native-class-tags nil)
7584 (defvar idlwave-sint-class-tags nil)
7585 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7586 (idlwave-new-sintern-type 'class-tag)
7587 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7588 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7590 (defun idlwave-complete-class-structure-tag ()
7591 "Complete a structure tag on a `self' argument in an object method."
7594 (case-fold-search t))
7596 ;; Check if the context is right
7597 (skip-chars-backward "a-zA-Z0-9._$")
7598 (and (< (point) (- pos 4))
7599 (looking-at "self\\.")))
7600 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7601 (super-classes (idlwave-all-class-inherits class-selector)))
7602 ;; Check if we are in a class routine
7603 (unless class-selector
7604 (error "Not in a method procedure or function"))
7605 ;; Check if we need to update the "current" class
7606 (if (not (equal class-selector idlwave-current-tags-class))
7607 (idlwave-prepare-class-tag-completion class-selector))
7608 (setq idlwave-completion-help-info
7609 (list 'idlwave-complete-class-structure-tag-help
7610 (idlwave-sintern-routine
7611 (concat class-selector "__define"))
7613 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7614 (idlwave-complete-in-buffer
7615 'class-tag 'class-tag
7616 idlwave-current-class-tags nil
7617 (format "Select a tag of class %s" class-selector)
7619 'idlwave-attach-class-tag-classes))
7620 t) ; return t to skip other completions
7623 (defun idlwave-class-tag-reset ()
7624 (setq idlwave-current-tags-class nil))
7626 (defun idlwave-prepare-class-tag-completion (class)
7627 "Find and parse the necessary class definitions for class structure tags."
7628 (setq idlwave-sint-class-tags nil)
7629 (setq idlwave-current-tags-class class)
7630 (setq idlwave-current-class-tags
7632 (list (idlwave-sintern-class-tag x 'set)))
7633 (idlwave-all-class-tags class)))
7634 (setq idlwave-current-native-class-tags
7635 (mapcar 'downcase (idlwave-class-tags class))))
7637 ;===========================================================================
7639 ;; Completing system variables and their structure fields
7640 ;; This is also a plugin.
7642 (defvar idlwave-sint-sysvars nil)
7643 (defvar idlwave-sint-sysvartags nil)
7644 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7645 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7646 (idlwave-new-sintern-type 'sysvar)
7647 (idlwave-new-sintern-type 'sysvartag)
7648 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7649 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7650 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7653 (defun idlwave-complete-sysvar-or-tag ()
7654 "Complete a system variable."
7657 (case-fold-search t))
7658 (cond ((save-excursion
7659 ;; Check if the context is right for system variable
7660 (skip-chars-backward "[a-zA-Z0-9_$]")
7661 (equal (char-before) ?!))
7662 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7663 (idlwave-complete-in-buffer 'sysvar 'sysvar
7664 idlwave-system-variables-alist nil
7665 "Select a system variable"
7667 t) ; return t to skip other completions
7669 ;; Check if the context is right for sysvar tag
7670 (skip-chars-backward "a-zA-Z0-9_$.")
7671 (and (equal (char-before) ?!)
7672 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7673 (<= (match-end 0) pos)))
7674 ;; Complete a system variable tag
7675 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7676 (entry (assq var idlwave-system-variables-alist))
7677 (tags (cdr (assq 'tags entry))))
7678 (or entry (error "!%s is not a known system variable" var))
7679 (or tags (error "System variable !%s is not a structure" var))
7680 (setq idlwave-completion-help-info
7681 (list 'idlwave-complete-sysvar-tag-help var))
7682 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7684 "Select a system variable tag"
7685 "system variable tag")
7686 t)) ; return t to skip other completions
7689 (defvar link) ;dynamic variables set by help callback
7691 (defun idlwave-complete-sysvar-help (mode word)
7692 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7693 (entry (assoc word idlwave-system-variables-alist)))
7696 (and (stringp word) entry (nth 1 (assq 'link entry))))
7698 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7699 (t (error "This should not happen")))))
7701 (defun idlwave-complete-sysvar-tag-help (mode word)
7702 (let* ((var (nth 1 idlwave-completion-help-info))
7703 (entry (assoc var idlwave-system-variables-alist))
7704 (tags (cdr (assq 'tags entry)))
7705 (main (nth 1 (assq 'link entry)))
7708 ((eq mode 'test) ; we can at least link the main
7709 (and (stringp word) entry main))
7713 (if (setq target (cdr (assoc-string word tags t)))
7714 (idlwave-substitute-link-target main target)
7715 main)))) ;; setting dynamic!!!
7716 (t (error "This should not happen")))))
7718 (defun idlwave-split-link-target (link)
7719 "Split a given LINK into link file and anchor."
7720 (if (string-match idlwave-html-link-sep link)
7721 (cons (substring link 0 (match-beginning 0))
7722 (string-to-number (substring link (match-end 0))))))
7724 (defun idlwave-substitute-link-target (link target)
7725 "Substitute the TARGET anchor for the given LINK."
7727 (setq main-base (if (string-match "#" link)
7728 (substring link 0 (match-beginning 0))
7731 (concat main-base idlwave-html-link-sep (number-to-string target))
7734 ;; Fake help in the source buffer for class structure tags.
7735 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7738 (defvar idlwave-help-do-class-struct-tag nil)
7739 (defun idlwave-complete-class-structure-tag-help (mode word)
7741 ((eq mode 'test) ; nothing gets fontified for class tags
7744 (let (class-with found-in)
7745 (when (setq class-with
7746 (idlwave-class-or-superclass-with-tag
7747 idlwave-current-tags-class
7749 (if (assq (idlwave-sintern-class class-with)
7750 idlwave-system-class-info)
7751 (error "No help available for system class tags"))
7752 (if (setq found-in (idlwave-class-found-in class-with))
7753 (setq name (cons (concat found-in "__define") class-with))
7754 (setq name (concat class-with "__define")))))
7756 idlwave-help-do-class-struct-tag t))
7757 (t (error "This should not happen"))))
7759 (defun idlwave-class-or-superclass-with-tag (class tag)
7760 "Find and return the CLASS or one of its superclass with the
7761 associated TAG, if any."
7762 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7766 (setq cl (pop sclasses))
7767 (let ((tags (idlwave-class-tags cl)))
7769 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7771 (setq tags (cdr tags))))))))
7774 (defun idlwave-sysvars-reset ()
7775 (if (and (fboundp 'idlwave-shell-is-running)
7776 (idlwave-shell-is-running)
7777 idlwave-idlwave_routine_info-compiled)
7778 (idlwave-shell-send-command "idlwave_get_sysvars"
7779 'idlwave-process-sysvars 'hide)))
7781 (defun idlwave-process-sysvars ()
7782 (idlwave-shell-filter-sysvars)
7783 (setq idlwave-sint-sysvars nil
7784 idlwave-sint-sysvartags nil)
7785 (idlwave-sintern-sysvar-alist))
7787 (defun idlwave-sintern-sysvar-alist ()
7788 (let ((list idlwave-system-variables-alist) entry tags)
7789 (while (setq entry (pop list))
7790 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7791 (setq tags (assq 'tags entry))
7795 (cons (idlwave-sintern-sysvartag (car x) 'set)
7799 (defvar idlwave-shell-command-output)
7800 (defun idlwave-shell-filter-sysvars ()
7801 "Get any new system variables and tags."
7802 (let ((text idlwave-shell-command-output)
7804 (old idlwave-system-variables-alist)
7805 var tags type name class link old-entry)
7806 (setq idlwave-system-variables-alist nil)
7807 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7809 (setq start (match-end 0)
7810 var (match-string 1 text)
7811 tags (if (match-end 3)
7812 (idlwave-split-string (match-string 3 text))))
7813 ;; Maintain old links, if present
7814 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7815 (setq link (assq 'link old-entry))
7816 (setq idlwave-system-variables-alist
7823 (idlwave-sintern-sysvartag x)
7824 (cdr (assq 'tags old-entry))))))
7826 idlwave-system-variables-alist)))
7827 ;; Keep the old value if query was not successful
7828 (setq idlwave-system-variables-alist
7829 (or idlwave-system-variables-alist old))))
7831 (defun idlwave-completion-fontify-classes ()
7832 "Goto the *Completions* buffer and fontify the class info."
7833 (when (featurep 'font-lock)
7834 (with-current-buffer "*Completions*"
7836 (goto-char (point-min))
7837 (let ((buffer-read-only nil))
7838 (while (re-search-forward "\\.*<[^>]+>" nil t)
7839 (put-text-property (match-beginning 0) (match-end 0)
7840 'face 'font-lock-string-face)))))))
7842 (defun idlwave-uniquify (list)
7843 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7846 (unless (gethash x ht)
7851 (defun idlwave-after-successful-completion (type slash &optional verify)
7852 "Add `=' or `(' after successful completion of keyword and function.
7853 Restore the pre-completion window configuration if possible."
7855 ((eq type 'procedure)
7857 ((eq type 'function)
7859 ((equal idlwave-function-completion-adds-paren nil) nil)
7860 ((or (equal idlwave-function-completion-adds-paren t)
7861 (equal idlwave-function-completion-adds-paren 1))
7863 ((equal idlwave-function-completion-adds-paren 2)
7868 (if (and idlwave-keyword-completion-adds-equal
7870 (progn (insert "=") t)
7873 ;; Restore the pre-completion window configuration if this is safe.
7875 (if (or (eq verify 'force) ; force
7877 (get-buffer-window "*Completions*") ; visible
7878 (idlwave-local-value 'idlwave-completion-p
7879 "*Completions*") ; cib-buffer
7880 (eq (marker-buffer idlwave-completion-mark)
7881 (current-buffer)) ; buffer OK
7882 (equal (marker-position idlwave-completion-mark)
7884 (idlwave-restore-wconf-after-completion))
7885 (move-marker idlwave-completion-mark nil)
7886 (setq idlwave-before-completion-wconf nil))
7888 (defun idlwave-mouse-context-help (ev &optional arg)
7889 "Call `idlwave-context-help' on the clicked location."
7891 (mouse-set-point ev)
7892 (idlwave-context-help arg))
7894 (defvar idlwave-last-context-help-pos nil)
7895 (defun idlwave-context-help (&optional arg)
7896 "Display IDL Online Help on context.
7897 If point is on a keyword, help for that keyword will be shown. If
7898 point is on a routine name or in the argument list of a routine, help
7899 for that routine will be displayed. Works for system routines and
7900 keywords, it pulls up text help. For other routies and keywords,
7901 visits the source file, finding help in the header (if
7902 `idlwave-help-source-try-header' is non-nil) or the routine definition
7905 (idlwave-do-context-help arg))
7907 (defun idlwave-mouse-completion-help (ev)
7908 "Display online help about the completion at point."
7910 ;; Restore last-command for next command, to make
7911 ;; scrolling/cancelling of completions work.
7912 (setq this-command last-command)
7913 (idlwave-do-mouse-completion-help ev))
7915 (defun idlwave-routine-info (&optional arg external)
7916 "Display a routines calling sequence and list of keywords.
7917 When point is on the name a function or procedure, or in the argument
7918 list of a function or procedure, this command displays a help buffer with
7919 the information. When called with prefix arg, enforce class query.
7921 When point is on an object operator `->', display the class stored in
7922 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7923 arg, the class property is cleared out."
7927 (if (string-match "->" (buffer-substring
7928 (max (point-min) (1- (point)))
7929 (min (+ 2 (point)) (point-max))))
7930 ;; Cursor is on an arrow
7931 (if (get-text-property (point) 'idlwave-class)
7932 ;; arrow has class property
7937 (when (looking-at ".?\\(->\\)")
7938 (remove-text-properties (match-beginning 1) (match-end 1)
7939 '(idlwave-class nil face nil))
7940 (message "Class property removed from arrow")))
7941 ;; Echo class property
7942 (message "Arrow has text property identifying object to be class %s"
7943 (get-text-property (point) 'idlwave-class)))
7944 ;; No property found
7945 (message "Arrow has no class text property"))
7947 ;; Not on an arrow...
7948 (let* ((idlwave-query-class nil)
7949 (idlwave-force-class-query (equal arg '(4)))
7950 (module (idlwave-what-module)))
7952 (apply 'idlwave-display-calling-sequence
7953 (idlwave-fix-module-if-obj_new module))
7954 (error "Don't know which calling sequence to show")))))
7956 (defun idlwave-resolve (&optional arg)
7957 "Call RESOLVE_ROUTINE on the module name at point.
7958 Like `idlwave-routine-info', this looks for a routine call at point.
7959 After confirmation in the minibuffer, it will use the shell to issue
7960 a RESOLVE call for this routine, to attempt to make it defined and its
7961 routine info available for IDLWAVE. If the routine is a method call,
7962 both `class__method' and `class__define' will be tried.
7963 With ARG, enforce query for the class of object methods."
7965 (let* ((idlwave-query-class nil)
7966 (idlwave-force-class-query (equal arg '(4)))
7967 (module (idlwave-what-module))
7968 (name (idlwave-make-full-name (nth 2 module) (car module)))
7969 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7970 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7973 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7975 (setq type (match-string 1 resolve)
7976 class (if (match-beginning 2)
7977 (match-string 3 resolve)
7979 name (match-string 4 resolve)))
7980 (if (string= (downcase type) "function")
7981 (setq kwd ",/is_function"))
7985 (idlwave-shell-send-command
7986 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7987 'idlwave-update-routine-info
7990 (idlwave-shell-send-command
7991 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7992 (list 'idlwave-shell-send-command
7993 (format "resolve_routine,'%s__%s'%s"
7994 (downcase class) (downcase name) kwd)
7995 '(idlwave-update-routine-info)
7998 (defun idlwave-find-module-this-file ()
8000 (idlwave-find-module '(4)))
8002 (defun idlwave-find-module (&optional arg)
8003 "Find the source code of an IDL module.
8004 Works for modules for which IDLWAVE has routine info available.
8005 The function offers as default the module name `idlwave-routine-info'
8006 would use. With ARG limit to this buffer. With two prefix ARG's
8007 force class query for object methods."
8009 (let* ((idlwave-query-class nil)
8010 (idlwave-force-class-query (equal arg '(16)))
8011 (this-buffer (equal arg '(4)))
8012 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
8014 (concat (idlwave-make-full-name
8015 (nth 2 module) (car module))
8016 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8022 (if (eq 'system (car-safe (nth 3 x)))
8023 ;; Take out system routines with no source.
8026 (concat (idlwave-make-full-name
8028 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8030 (idlwave-save-buffer-update)
8031 (idlwave-routines))))))
8032 (name (idlwave-completing-read
8033 (if (or (not this-buffer)
8034 (assoc default list))
8035 (format "Module (Default %s): " default)
8036 (format "Module in this file: "))
8039 (if (string-match "\\`\\s-*\\'" name)
8040 ;; Nothing, use the default.
8041 (setq name default))
8042 (if (string-match "<[fp]>" name)
8043 (setq type (substring name -2 -1)
8044 name (substring name 0 -3)))
8045 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8046 (setq class (match-string 1 name)
8047 name (match-string 2 name)))
8048 (setq name (idlwave-sintern-routine-or-method name class)
8049 class (idlwave-sintern-class class)
8050 type (cond ((equal type "f") 'fun)
8051 ((equal type "p") 'pro)
8053 (idlwave-do-find-module name type class nil this-buffer)))
8055 (defun idlwave-do-find-module (name type class
8056 &optional force-source this-buffer)
8057 (let ((name1 (idlwave-make-full-name class name))
8059 (buf (current-buffer))
8062 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8064 source (or force-source (nth 3 entry))
8065 name2 (if (nth 2 entry)
8066 (idlwave-make-full-name (nth 2 entry) name)
8069 (setq file (idlwave-routine-source-file source)))
8070 (unless file ; Try to find it on the path.
8072 (idlwave-expand-lib-file-name
8074 (format "%s__define.pro" (downcase class))
8075 (format "%s.pro" (downcase name))))))
8077 ((or (null name) (equal name ""))
8079 ((eq (car source) 'system)
8080 (error "Source code for system routine %s is not available"
8082 ((or (not file) (not (file-regular-p file)))
8083 (error "Source code for routine %s is not available"
8086 (when (not this-buffer)
8088 (idlwave-find-file-noselect file 'find))
8089 (pop-to-buffer buf1 t))
8090 (goto-char (point-max))
8091 (let ((case-fold-search t))
8092 (if (re-search-backward
8093 (concat "^[ \t]*\\<"
8094 (cond ((eq type 'fun) "function")
8095 ((eq type 'pro) "pro")
8096 (t "\\(pro\\|function\\)"))
8098 (regexp-quote (downcase name2))
8101 (goto-char (match-beginning 0))
8104 (error "Could not find routine %s" name2)))))))
8106 (defun idlwave-what-module ()
8107 "Return a default module for stuff near point.
8108 Used by `idlwave-routine-info' and `idlwave-find-module'."
8110 (if (let ((case-fold-search t))
8112 (idlwave-beginning-of-statement)
8113 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8114 ;; This is a function or procedure definition statement
8115 ;; We return the defined routine as module.
8117 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8118 (match-string-no-properties 2))
8119 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8120 (idlwave-sintern-class (match-string 3)))
8122 ;; Not a definition statement - analyze precise position.
8123 (let* ((where (idlwave-where))
8125 (pro (car (nth 0 where)))
8126 (func (car (nth 1 where)))
8127 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8128 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8132 ((and (eq cw 'procedure)
8133 (not (equal this-word "")))
8134 (setq this-word (idlwave-sintern-routine-or-method
8135 this-word (nth 2 (nth 3 where))))
8136 (list this-word 'pro
8137 (idlwave-determine-class
8138 (cons this-word (cdr (nth 3 where)))
8140 ((and (eq cw 'function)
8141 (not (equal this-word ""))
8142 (or (eq next-char ?\() ; exclude arrays, vars.
8143 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8144 (setq this-word (idlwave-sintern-routine-or-method
8145 this-word (nth 2 (nth 3 where))))
8146 (list this-word 'fun
8147 (idlwave-determine-class
8148 (cons this-word (cdr (nth 3 where)))
8150 ((and (memq cw '(function-keyword procedure-keyword))
8151 (not (equal this-word ""))
8152 (eq next-char ?\()) ; A function!
8153 (setq this-word (idlwave-sintern-routine this-word))
8154 (list this-word 'fun nil))
8156 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8158 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8161 (defun idlwave-what-module-find-class ()
8162 "Call `idlwave-what-module' and find the inherited class if necessary."
8163 (let* ((module (idlwave-what-module))
8164 (class (nth 2 module))
8166 (if (and (= (length module) 3)
8170 (apply 'idlwave-find-inherited-class module))
8173 (defun idlwave-find-inherited-class (name type class)
8174 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8175 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8180 (defun idlwave-fix-module-if-obj_new (module)
8181 "Check if MODULE points to obj_new.
8182 If yes, and if the cursor is in the keyword region, change to the
8183 appropriate Init method."
8184 (let* ((name (car module))
8186 (case-fold-search t)
8188 (if (and (stringp name)
8189 (equal (downcase name) "obj_new")
8191 (idlwave-beginning-of-statement)
8192 (setq string (buffer-substring (point) pos))
8193 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8196 (class (match-string 1 string)))
8197 (setq module (list (idlwave-sintern-method "Init")
8199 (idlwave-sintern-class class)))))
8202 (defun idlwave-fix-keywords (name type class keywords
8203 &optional super-classes system)
8204 "Update a list of keywords.
8205 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8206 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8207 demand _EXTRA in the keyword list."
8208 (let ((case-fold-search t))
8210 ;; If this is the OBJ_NEW function, try to figure out the class and use
8211 ;; the keywords from the corresponding INIT method.
8212 (if (and (equal (upcase name) "OBJ_NEW")
8213 (or (eq major-mode 'idlwave-mode)
8214 (eq major-mode 'idlwave-shell-mode)))
8215 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8216 (string (buffer-substring bos (point)))
8217 (case-fold-search t)
8219 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8221 (setq class (idlwave-sintern-class (match-string 1 string)))
8222 (setq idlwave-current-obj_new-class class)
8225 (idlwave-entry-keywords
8227 (idlwave-sintern-method "INIT")
8230 (idlwave-routines)) 'do-link))))))
8232 ;; If the class is `t', combine all keywords of all methods NAME
8234 (mapc (lambda (entry)
8236 (nth 2 entry) ; non-nil class
8237 (eq (nth 1 entry) type) ; correct type
8240 (idlwave-entry-keywords entry 'do-link)))))
8241 (idlwave-all-assq name (idlwave-routines)))
8242 (setq keywords (idlwave-uniquify keywords)))
8244 ;; If we have inheritance, add all keywords from superclasses, if
8245 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8248 idlwave-keyword-class-inheritance
8252 (assq (idlwave-sintern-keyword "_extra") keywords)
8253 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8254 ;; Check if one of the keyword-class regexps matches the name
8255 (let ((regexps idlwave-keyword-class-inheritance) re)
8257 (while (setq re (pop regexps))
8258 (if (string-match re name) (throw 'exit t))))))
8260 (loop for entry in (idlwave-routines) do
8261 (and (nth 2 entry) ; non-nil class
8262 (memq (nth 2 entry) super-classes) ; an inherited class
8263 (eq (nth 1 entry) type) ; correct type
8264 (eq (car entry) name) ; correct name
8265 (mapc (lambda (k) (add-to-list 'keywords k))
8266 (idlwave-entry-keywords entry 'do-link))))
8267 (setq keywords (idlwave-uniquify keywords)))
8269 ;; Return the final list
8272 (defun idlwave-expand-keyword (keyword module)
8273 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8274 KEYWORD may be an exact match or an abbreviation of a keyword.
8275 If the match is exact, KEYWORD itself is returned, even if there may be other
8276 keywords of which KEYWORD is an abbreviation. This is necessary because some
8277 system routines have keywords which are prefixes of other keywords.
8278 If KEYWORD is an abbreviation of several keywords, a list of all possible
8279 completions is returned.
8280 If the abbreviation was unique, the correct keyword is returned.
8281 If it cannot be a keyword, the function return nil.
8282 If we do not know about MODULE, just return KEYWORD literally."
8283 (let* ((name (car module))
8284 (type (nth 1 module))
8285 (class (nth 2 module))
8286 (kwd (idlwave-sintern-keyword keyword))
8287 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8288 (kwd-alist (idlwave-entry-keywords entry))
8289 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8290 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8291 (completion-ignore-case t)
8293 (cond ((assq kwd kwd-alist)
8295 ((setq candidates (all-completions kwd kwd-alist))
8296 (if (= (length candidates) 1)
8300 ;; Inheritance may cause this keyword to be correct
8303 ;; We do know the function, which does not have the keyword.
8306 ;; We do not know the function, so this just might be a correct
8307 ;; keyword - return it as it is.
8310 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8311 (defvar idlwave-rinfo-map (make-sparse-keymap))
8312 (define-key idlwave-rinfo-mouse-map
8313 (if (featurep 'xemacs) [button2] [mouse-2])
8314 'idlwave-mouse-active-rinfo)
8315 (define-key idlwave-rinfo-mouse-map
8316 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8317 'idlwave-mouse-active-rinfo-shift)
8318 (define-key idlwave-rinfo-mouse-map
8319 (if (featurep 'xemacs) [button3] [mouse-3])
8320 'idlwave-mouse-active-rinfo-right)
8321 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8322 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8323 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8324 (defvar idlwave-popup-source nil)
8325 (defvar idlwave-rinfo-marker (make-marker))
8327 (defun idlwave-quit-help ()
8329 (let ((ri-window (get-buffer-window "*Help*"))
8330 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8331 (when (and olh-window
8332 (fboundp 'idlwave-help-quit))
8333 (select-window olh-window)
8334 (idlwave-help-quit))
8335 (when (window-live-p ri-window)
8336 (delete-window ri-window))))
8338 (defun idlwave-display-calling-sequence (name type class
8339 &optional initial-class)
8340 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8341 (let* ((initial-class (or initial-class class))
8342 (entry (or (idlwave-best-rinfo-assq name type class
8344 (idlwave-rinfo-assq name type class
8345 idlwave-unresolved-routines)))
8346 (name (or (car entry) name))
8347 (class (or (nth 2 entry) class))
8348 (superclasses (idlwave-all-class-inherits initial-class))
8349 (twins (idlwave-routine-twins entry))
8350 (dtwins (idlwave-study-twins twins))
8352 (system (eq (car (nth 3 entry)) 'system))
8353 (calling-seq (nth 4 entry))
8354 (keywords (idlwave-entry-keywords entry 'do-link))
8355 (html-file (car (nth 5 entry)))
8357 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8359 "Button2/3: Online Help")
8361 "Button2: Jump to source and back | Button3: Source in Help window.")
8363 "Button2: Display info about same method in superclass")
8365 (data (list name type class (current-buffer) nil initial-class))
8366 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8367 (face 'idlwave-help-link)
8368 beg props win cnt total)
8369 ;; Fix keywords, but don't add chained super-classes, since these
8370 ;; are shown separately for that super-class
8371 (setq keywords (idlwave-fix-keywords name type class keywords))
8374 (error "No %s %s known %s" type name
8375 (if initial-class (concat "in class " initial-class) "")))
8376 ((or (null name) (equal name ""))
8377 (error "No function or procedure call at point"))
8379 (error "Calling sequence of %s %s not available" type name))
8381 (move-marker idlwave-rinfo-marker (point))
8382 (with-current-buffer (get-buffer-create "*Help*")
8383 (use-local-map idlwave-rinfo-map)
8384 (setq buffer-read-only nil)
8386 (set (make-local-variable 'idlwave-popup-source) nil)
8387 (set (make-local-variable 'idlwave-current-obj_new-class)
8388 idlwave-current-obj_new-class)
8390 (setq props (list 'mouse-face 'highlight
8391 km-prop idlwave-rinfo-mouse-map
8392 'help-echo help-echo-class
8393 'data (cons 'class data)))
8394 (let ((classes (cons initial-class superclasses)) c)
8395 (insert "Classes: ")
8396 (while (setq c (pop classes))
8400 (if (equal (downcase c) (downcase class))
8401 (add-text-properties beg (point) (list 'face 'bold))
8402 ;; If Method exists in a different class link it
8403 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8404 (add-text-properties beg (point) props))))
8406 (setq props (list 'mouse-face 'highlight
8407 km-prop idlwave-rinfo-mouse-map
8408 'help-echo help-echo-use
8409 'data (cons 'usage data)))
8410 (if html-file (setq props (append (list 'face face 'link html-file)
8415 (format calling-seq class name class name class name)
8416 (format calling-seq name name name name))
8418 (add-text-properties beg (point) props)
8420 (insert "Keywords:")
8422 (insert " No keywords accepted.")
8426 (if (>= (+ col 1 (length (car x)))
8433 ;; Relevant keywords already have link property attached
8434 props (list 'mouse-face 'highlight
8435 km-prop idlwave-rinfo-mouse-map
8436 'data (cons 'keyword data)
8437 'help-echo help-echo-kwd
8439 (if system (setq props (append (list 'face face) props)))
8441 (add-text-properties beg (point) props)
8442 (setq col (+ col 1 (length (car x)))))
8445 (setq cnt 1 total (length all))
8446 ;; Here entry is (key file (list of type-conses))
8447 (while (setq entry (pop all))
8448 (setq props (list 'mouse-face 'highlight
8449 km-prop idlwave-rinfo-mouse-map
8450 'help-echo help-echo-src
8451 'source (list (car (car (nth 2 entry))) ;type
8454 (cdr (car (nth 2 entry))))
8455 'data (cons 'source data)))
8456 (idlwave-insert-source-location
8459 (if (> total 1) "Sources:" "Source:")
8461 (if (> total 1) "- " ""))
8464 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8465 ;; No more source lines, please
8467 "\n Source information truncated to %d entries."
8468 idlwave-rinfo-max-source-lines))
8470 (goto-char (point-min))
8471 (setq buffer-read-only t))
8472 (display-buffer "*Help*")
8473 (if (and (setq win (get-buffer-window "*Help*"))
8474 idlwave-resize-routine-help-window)
8476 (let ((ww (selected-window)))
8480 (enlarge-window (- (/ (frame-height) 2)
8482 (shrink-window-if-larger-than-buffer))
8483 (select-window ww)))))))))
8485 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8486 "Insert a source location into the routine info buffer.
8487 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8489 (let* ((key (car entry))
8490 (file (nth 1 entry))
8491 (types (nth 2 entry))
8492 (shell-flag (assq 'compiled types))
8493 (buffer-flag (assq 'buffer types))
8494 (user-flag (assq 'user types))
8495 (lib-flag (assq 'lib types))
8496 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8497 (and user-flag (idlwave-count-memq 'user types))
8498 (and lib-flag (idlwave-count-memq 'lib types))
8512 (insert "Builtin "))
8514 ((and (not file) shell-flag)
8515 (insert "Unresolved"))
8520 ((idlwave-syslib-p file)
8521 (if (string-match "obsolete" (file-name-directory file))
8522 (insert "Obsolete ")
8523 (insert "SystemLib ")))
8525 ;; New special syntax: taken directly from routine-info for
8526 ;; library catalog routines
8527 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8528 (insert (format "%-10s" special)))
8530 ;; Old special syntax: a matching regexp
8531 ((setq special (idlwave-special-lib-test file))
8532 (insert (format "%-10s" special)))
8534 ;; Catch-all with file
8535 ((idlwave-lib-p file) (insert "Library "))
8538 (t (insert "Other ")))
8543 (if lib-flag "L" "-")
8544 (if user-flag "C" "-")
8545 (if shell-flag "S" "-")
8546 (if buffer-flag "B" "-")
8550 (insert (format "(%dx) " ndupl))
8551 (add-text-properties beg (point) (list 'face 'bold)))
8552 (when (and file (not (equal file "")))
8554 (insert (apply 'abbreviate-file-name
8555 (if (featurep 'xemacs) (list file t) (list file))))
8557 (add-text-properties beg (point) file-props)))))
8559 (defun idlwave-special-lib-test (file)
8560 "Check the path of FILE against the regexps which define special libs.
8561 Return the name of the special lib if there is a match."
8562 (let ((alist idlwave-special-lib-alist)
8566 (while (setq entry (pop alist))
8567 (if (string-match (car entry) file)
8568 (setq rtn (cdr entry)
8573 (defun idlwave-mouse-active-rinfo-right (ev)
8575 (idlwave-mouse-active-rinfo ev 'right))
8577 (defun idlwave-mouse-active-rinfo-shift (ev)
8579 (idlwave-mouse-active-rinfo ev nil 'shift))
8581 (defun idlwave-active-rinfo-space ()
8583 (idlwave-mouse-active-rinfo nil 'right))
8585 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8586 "Do the mouse actions in the routine info buffer.
8587 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8590 (if ev (mouse-set-point ev))
8591 (let (data id name type class buf bufwin source link keyword
8593 (setq data (get-text-property (point) 'data)
8594 source (get-text-property (point) 'source)
8595 keyword (get-text-property (point) 'keyword)
8596 link (get-text-property (point) 'link)
8598 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8600 initial-class (nth 6 data)
8601 word (idlwave-this-word)
8602 bufwin (get-buffer-window buf t))
8604 (cond ((eq id 'class) ; Switch class being displayed
8605 (if (window-live-p bufwin) (select-window bufwin))
8606 (idlwave-display-calling-sequence
8607 (idlwave-sintern-method name)
8608 type (idlwave-sintern-class word)
8610 ((eq id 'usage) ; Online help on this routine
8611 (idlwave-online-help link name type class))
8612 ((eq id 'source) ; Source in help or buffer
8614 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8615 (idlwave-help-source-try-header nil)
8616 ;; Fake idlwave-routines so help will find the right entry
8618 (list (list name type class source ""))))
8619 (idlwave-help-get-special-help name type class nil))
8620 ;; Otherwise just pop to the source
8621 (setq idlwave-popup-source (not idlwave-popup-source))
8622 (if idlwave-popup-source
8624 (idlwave-do-find-module name type class source)
8626 (setq idlwave-popup-source nil)
8627 (if (window-live-p bufwin) (select-window bufwin))
8628 (error (nth 1 err))))
8630 (select-window bufwin)
8631 (pop-to-buffer buf))
8632 (goto-char (marker-position idlwave-rinfo-marker)))))
8635 (idlwave-online-help link name type class keyword)
8636 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8638 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8639 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8640 (let ((bwin (get-buffer-window buffer)))
8641 (if idlwave-complete-empty-string-as-lower-case
8642 (setq keyword (downcase keyword)))
8644 (select-window bwin)
8645 (pop-to-buffer buffer)
8646 (setq bwin (get-buffer-window buffer)))
8647 (if (eq (preceding-char) ?/)
8649 (unless (save-excursion
8651 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8652 (min (- (point) 100) (point-min)) t))
8654 (if shift (insert "/"))
8656 (if (and (not shift)
8657 idlwave-keyword-completion-adds-equal)
8660 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8661 "List the load path shadows of all routines defined in current buffer."
8664 (if (eq major-mode 'idlwave-mode)
8665 (idlwave-list-load-path-shadows
8666 nil (idlwave-update-current-buffer-info 'save-buffer)
8667 "in current buffer")
8668 (error "Current buffer is not in idlwave-mode")))
8670 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8671 "List the load path shadows of all routines compiled under the shell.
8672 This is very useful for checking an IDL application. Just compile the
8673 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8674 routines and update IDLWAVE internal info. Then check for shadowing
8678 ((or (not (fboundp 'idlwave-shell-is-running))
8679 (not (idlwave-shell-is-running)))
8680 (error "Shell is not running"))
8681 ((null idlwave-compiled-routines)
8682 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8684 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8687 (defun idlwave-list-all-load-path-shadows (&optional arg)
8688 "List the load path shadows of all routines known to IDLWAVE."
8690 (idlwave-list-load-path-shadows nil nil "globally"))
8692 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8693 "List the routines which are defined multiple times.
8694 Search the information IDLWAVE has about IDL routines for multiple
8696 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8698 When IDL hits a routine call which is not defined, it will search on
8699 the load path in order to find a definition. The output of this command
8700 can be used to detect possible name clashes during this process."
8701 (idlwave-routines) ; Make sure everything is loaded.
8702 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8704 "You don't have any user or library catalogs. Continue anyway? ")
8706 (let* ((routines (append idlwave-system-routines
8707 idlwave-compiled-routines
8708 idlwave-library-catalog-routines
8709 idlwave-user-catalog-routines
8710 idlwave-buffer-routines
8712 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8713 (keymap (make-sparse-keymap))
8714 (props (list 'mouse-face 'highlight
8716 'help-echo "Mouse2: Find source"))
8717 (nroutines (length (or special-routines routines)))
8718 (step (/ nroutines 100))
8721 (idlwave-sort-prefer-buffer-info nil)
8722 routine twins dtwins twin done props1 lroutines)
8724 (if special-routines
8725 ;; Just looking for shadows of a few special routines
8726 (setq lroutines routines
8727 routines special-routines))
8729 (message "Sorting routines...")
8730 (setq routines (sort routines
8732 (string< (downcase (idlwave-make-full-name
8734 (downcase (idlwave-make-full-name
8735 (nth 2 b) (car b)))))))
8736 (message "Sorting routines...done")
8738 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8741 (mouse-set-point ev)
8742 (apply 'idlwave-do-find-module
8743 (get-text-property (point) 'find-args))))
8744 (define-key keymap [(return)]
8747 (apply 'idlwave-do-find-module
8748 (get-text-property (point) 'find-args))))
8749 (message "Compiling list...( 0%%)")
8750 (with-current-buffer (get-buffer-create "*Shadows*")
8751 (setq buffer-read-only nil)
8753 (while (setq routine (pop routines))
8754 (if (= (mod (setq n (1+ n)) step) 0)
8755 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8757 ;; Get a list of all twins
8758 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8759 (if (memq routine done)
8761 (setq dtwins (idlwave-study-twins twins)))
8762 ;; Mark all twins as dealt with
8763 (setq done (append twins done))
8764 (when (or (> (length dtwins) 1)
8765 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8766 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8767 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8769 (insert (format "\n%s%s"
8770 (idlwave-make-full-name (nth 2 routine)
8772 (if (eq (nth 1 routine) 'fun) "()" "")))
8773 (while (setq twin (pop dtwins))
8774 (setq props1 (append (list 'find-args
8775 (list (nth 0 routine)
8779 (idlwave-insert-source-location "\n - " twin props1))))
8780 (goto-char (point-min))
8781 (setq buffer-read-only t))
8782 (setq loc (or loc ""))
8785 (display-buffer (get-buffer "*Shadows*"))
8786 (message "%d case%s of shadowing found %s"
8787 cnt (if (= cnt 1) "" "s") loc))
8788 (message "No shadowing conflicts found %s" loc))))
8790 (defun idlwave-print-source (routine)
8791 (let* ((source (nth 3 routine))
8792 (stype (car source))
8793 (sfile (idlwave-routine-source-file source)))
8794 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8795 (if (and (eq stype 'compiled)
8796 (or (not (stringp sfile))
8797 (not (string-match "\\S-" sfile))))
8798 (setq stype 'unresolved))
8799 (princ (format " %-10s %s\n"
8801 (if sfile sfile "No source code available")))))
8803 (defun idlwave-routine-twins (entry &optional list)
8804 "Return all twin entries of ENTRY in LIST.
8805 LIST defaults to `idlwave-routines'.
8806 Twin entries are those which have the same name, type, and class.
8807 ENTRY will also be returned, as the first item of this list."
8808 (let* ((name (car entry))
8809 (type (nth 1 entry))
8810 (class (nth 2 entry))
8811 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8813 (while (setq candidate (pop candidates))
8814 (if (and (not (eq candidate entry))
8815 (eq type (nth 1 candidate))
8816 (eq class (nth 2 candidate)))
8817 (push candidate twins)))
8818 (if (setq candidate (idlwave-rinfo-assq name type class
8819 idlwave-unresolved-routines))
8820 (push candidate twins))
8821 (cons entry (nreverse twins))))
8823 (defun idlwave-study-twins (entries)
8824 "Return dangerous twins of first entry in ENTRIES.
8825 Dangerous twins are routines with same name, but in different files on
8826 the load path. If a file is in the system library and has an entry in
8827 the `idlwave-system-routines' list, we omit the latter as
8828 non-dangerous because many IDL routines are implemented as library
8829 routines, and may have been scanned."
8830 (let* ((entry (car entries))
8831 (name (car entry)) ;
8832 (type (nth 1 entry)) ; Must be bound for
8833 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8835 source type type-cons file alist syslibp key)
8836 (while (setq entry (pop entries))
8838 (setq source (nth 3 entry)
8840 type-cons (cons type (nth 3 source))
8841 file (idlwave-routine-source-file source))
8843 ;; Make KEY to index entry properly
8844 (setq key (cond ((eq type 'system) type)
8845 (file (file-truename file))
8848 ;; Check for an entry in the system library
8851 (idlwave-syslib-p file))
8854 ;; If there's more than one matching entry for the same file, just
8855 ;; append the type-cons to the type list.
8856 (if (setq entry (assoc key alist))
8857 (push type-cons (nth 2 entry))
8858 (push (list key file (list type-cons)) alist)))
8860 (setq alist (nreverse alist))
8863 ;; File is in system *library* - remove any 'system entry
8864 (setq alist (delq (assq 'system alist) alist)))
8866 ;; If 'system remains and we've scanned the syslib, it's a builtin
8867 ;; (rather than a !DIR/lib/.pro file bundled as source).
8868 (when (and (idlwave-syslib-scanned-p)
8869 (setq entry (assoc 'system alist)))
8870 (setcar entry 'builtin))
8871 (sort alist 'idlwave-routine-twin-compare)))
8875 (defvar idlwave-sort-prefer-buffer-info t
8876 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8878 (defmacro idlwave-xor (a b)
8882 (defun idlwave-routine-entry-compare (a b)
8883 "Compare two routine info entries for sorting.
8884 This is the general case. It first compares class, names, and type.
8885 If it turns out that A and B are twins (same name, class, and type),
8886 calls another routine which compares twins on the basis of their file
8887 names and path locations."
8888 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8890 ((not (equal (idlwave-downcase-safe class)
8891 (idlwave-downcase-safe (nth 2 b))))
8893 (cond ((null (nth 2 b)) nil)
8895 (t (string< (downcase class) (downcase (nth 2 b))))))
8896 ((not (equal (downcase name) (downcase (car b))))
8898 (string< (downcase name) (downcase (car b))))
8899 ((not (eq type (nth 1 b)))
8901 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8903 ;; A and B are twins - so the decision is more complicated.
8904 ;; Call twin-compare with the proper arguments.
8905 (idlwave-routine-entry-compare-twins a b)))))
8907 (defun idlwave-routine-entry-compare-twins (a b)
8908 "Compare two routine entries, under the assumption that they are twins.
8909 This basically calls `idlwave-routine-twin-compare' with the correct args."
8910 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8915 (afile (idlwave-routine-source-file asrc))
8916 (bfile (idlwave-routine-source-file bsrc)))
8917 (idlwave-routine-twin-compare
8919 (list (file-truename afile) afile (list atype))
8920 (list atype afile (list atype)))
8922 (list (file-truename bfile) bfile (list btype))
8923 (list btype bfile (list btype))))
8926 (defun idlwave-routine-twin-compare (a b)
8927 "Compare two routine twin entries for sorting.
8928 In here, A and B are not normal routine info entries, but special
8929 lists (KEY FILENAME (TYPES...)).
8930 This expects NAME TYPE CLASS to be bound to the right values."
8931 (let* (;; Dis-assemble entries
8932 (akey (car a)) (bkey (car b))
8933 (afile (nth 1 a)) (bfile (nth 1 b))
8934 (atypes (nth 2 a)) (btypes (nth 2 b))
8936 (asysp (memq akey '(builtin system)))
8937 (bsysp (memq bkey '(builtin system)))
8938 ;; Compiled routines?
8939 (acompp (memq 'compiled atypes))
8940 (bcompp (memq 'compiled btypes))
8942 (aunresp (or (eq akey 'unresolved)
8943 (and acompp (not afile))))
8944 (bunresp (or (eq bkey 'unresolved)
8945 (and bcompp (not bfile))))
8946 ;; Buffer info available?
8947 (abufp (memq 'buffer atypes))
8948 (bbufp (memq 'buffer btypes))
8950 (tpath-alist (idlwave-true-path-alist))
8951 (apathp (and (stringp akey)
8952 (assoc (file-name-directory akey) tpath-alist)))
8953 (bpathp (and (stringp bkey)
8954 (assoc (file-name-directory bkey) tpath-alist)))
8955 ;; How early on search path? High number means early since we
8956 ;; measure the tail of the path list
8957 (anpath (length (memq apathp tpath-alist)))
8958 (bnpath (length (memq bpathp tpath-alist)))
8959 ;; Look at file names
8960 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8961 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8962 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8963 (regexp-quote (downcase class))
8964 (regexp-quote (downcase name)))
8965 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8966 ;; Is file name derived from the routine name?
8967 ;; Method file or class definition file?
8968 (anamep (string-match fname-re aname))
8969 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8970 (bnamep (string-match fname-re bname))
8971 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8973 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8974 ;; doesn't it? The difficult stuff is hidden above...
8976 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8977 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8978 ((and idlwave-sort-prefer-buffer-info
8979 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8980 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8981 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8982 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8983 ((and class anamep bnamep ; both file names match ->
8984 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8985 ((> anpath bnpath) t) ; Who is first on path?
8986 (t nil)))) ; Default
8988 (defun idlwave-routine-source-file (source)
8990 (expand-file-name (nth 1 source) (nth 2 source))
8993 (defun idlwave-downcase-safe (string)
8994 "Donwcase if string, else return unchanged."
8995 (if (stringp string)
8999 (defun idlwave-count-eq (elt list)
9000 "How often is ELT in LIST?"
9001 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9003 (defun idlwave-count-memq (elt alist)
9004 "How often is ELT a key in ALIST?"
9005 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9007 (defun idlwave-syslib-p (file)
9008 "Non-nil if FILE is in the system library."
9009 (let* ((true-syslib (file-name-as-directory
9011 (expand-file-name "lib" (idlwave-sys-dir)))))
9012 (true-file (file-truename file)))
9013 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9015 (defun idlwave-lib-p (file)
9016 "Non-nil if FILE is in the library."
9017 (let ((true-dir (file-name-directory (file-truename file))))
9018 (assoc true-dir (idlwave-true-path-alist))))
9020 (defun idlwave-path-alist-add-flag (list-entry flag)
9021 "Add a flag to the path list entry, if not set."
9022 (let ((flags (cdr list-entry)))
9023 (add-to-list 'flags flag)
9024 (setcdr list-entry flags)))
9026 (defun idlwave-path-alist-remove-flag (list-entry flag)
9027 "Remove a flag to the path list entry, if set."
9028 (let ((flags (delq flag (cdr list-entry))))
9029 (setcdr list-entry flags)))
9031 (defun idlwave-true-path-alist ()
9032 "Return `idlwave-path-alist' alist with true-names.
9033 Info is cached, but relies on the functions setting `idlwave-path-alist'
9034 to reset the variable `idlwave-true-path-alist' to nil."
9035 (or idlwave-true-path-alist
9036 (setq idlwave-true-path-alist
9037 (mapcar (lambda(x) (cons
9038 (file-name-as-directory
9040 (directory-file-name
9043 idlwave-path-alist))))
9045 (defun idlwave-syslib-scanned-p ()
9046 "Non-nil if the system lib file !DIR/lib has been scanned."
9047 (let* ((true-syslib (file-name-as-directory
9049 (expand-file-name "lib" (idlwave-sys-dir))))))
9050 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9052 ;; ----------------------------------------------------------------------------
9054 ;; Online Help display
9057 ;; ----------------------------------------------------------------------------
9059 ;; Additions for use with imenu.el and func-menu.el
9060 ;; (pop-up a list of IDL units in the current file).
9063 (defun idlwave-prev-index-position ()
9064 "Search for the previous procedure or function.
9065 Return nil if not found. For use with imenu.el."
9068 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9069 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9072 (defun idlwave-unit-name ()
9073 "Return the unit name.
9074 Assumes that point is at the beginning of the unit as found by
9075 `idlwave-prev-index-position'."
9078 (let ((begin (point)))
9080 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9081 (if (fboundp 'buffer-substring-no-properties)
9082 (buffer-substring-no-properties begin (point))
9083 (buffer-substring begin (point)))))
9085 (defalias 'idlwave-function-menu
9088 (require 'func-menu)
9090 (error (condition-case nil
9096 ;; Here we hack func-menu.el in order to support this new mode.
9097 ;; The latest versions of func-menu.el already have this stuff in, so
9098 ;; we hack only if it is not already there.
9099 (when (fboundp 'eval-after-load)
9100 (eval-after-load "func-menu"
9102 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9103 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9104 (setq fume-function-name-regexp-alist
9105 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9106 fume-function-name-regexp-alist)))
9107 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9108 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9109 (setq fume-find-function-name-method-alist
9110 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9111 fume-find-function-name-method-alist))))))
9113 (defun idlwave-edit-in-idlde ()
9114 "Edit the current file in IDL Development environment."
9116 (start-process "idldeclient" nil
9117 idlwave-shell-explicit-file-name "-c" "-e"
9118 (buffer-file-name)))
9120 (defvar idlwave-help-use-assistant)
9121 (defun idlwave-launch-idlhelp ()
9122 "Start the IDLhelp application."
9124 (if idlwave-help-use-assistant
9125 (idlwave-help-assistant-raise)
9126 (start-process "idlhelp" nil idlwave-help-application)))
9128 ;; Menus - using easymenu.el
9129 (defvar idlwave-mode-menu-def
9131 ["PRO/FUNC menu" idlwave-function-menu t]
9133 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9134 ["Subprogram End" idlwave-end-of-subprogram t]
9135 ["Block Start" idlwave-beginning-of-block t]
9136 ["Block End" idlwave-end-of-block t]
9137 ["Up Block" idlwave-backward-up-block t]
9138 ["Down Block" idlwave-down-block t]
9139 ["Skip Block Backward" idlwave-backward-block t]
9140 ["Skip Block Forward" idlwave-forward-block t])
9142 ["Subprogram" idlwave-mark-subprogram t]
9143 ["Block" idlwave-mark-block t]
9144 ["Header" idlwave-mark-doclib t])
9146 ["Indent Entire Statement" idlwave-indent-statement
9147 :active t :keys "C-u \\[indent-for-tab-command]" ]
9148 ["Indent Subprogram" idlwave-indent-subprogram t]
9149 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9150 ["Continue/Split line" idlwave-split-line t]
9152 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9153 :selected (symbol-value idlwave-fill-function)])
9155 ["Procedure" idlwave-procedure t]
9156 ["Function" idlwave-function t]
9157 ["Doc Header" idlwave-doc-header t]
9158 ["Log" idlwave-doc-modification t]
9160 ["Case" idlwave-case t]
9161 ["For" idlwave-for t]
9162 ["Repeat" idlwave-repeat t]
9163 ["While" idlwave-while t]
9165 ["Close Block" idlwave-close-block t])
9167 ["Complete" idlwave-complete t]
9168 ("Complete Specific"
9169 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9170 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9172 ["3 Function Name" (idlwave-complete 'function) t]
9173 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9175 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9176 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9178 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9179 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9181 ["9 Class Name" idlwave-complete-class t]))
9183 ["Show Routine Info" idlwave-routine-info t]
9184 ["Online Context Help" idlwave-context-help t]
9186 ["Find Routine Source" idlwave-find-module t]
9187 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9189 ["Update Routine Info" idlwave-update-routine-info t]
9190 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9193 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9194 ["Scan Directories" (idlwave-update-routine-info '(16))
9195 (and idlwave-path-alist (not idlwave-catalog-process))]
9196 ["Scan Directories &" (idlwave-update-routine-info '(64))
9197 (and idlwave-path-alist (not idlwave-catalog-process))]
9200 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9201 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9202 ["Check Everything" idlwave-list-all-load-path-shadows t])
9204 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9206 ["Insert TAB character" idlwave-hard-tab t])
9209 ["Start IDL shell" idlwave-shell t]
9210 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9211 ["Launch IDL Help" idlwave-launch-idlhelp t])
9214 ["Browse IDLWAVE Group" idlwave-customize t]
9216 ["Build Full Customize Menu" idlwave-create-customize-menu
9217 (fboundp 'customize-menu-create)])
9219 ["Describe Mode" describe-mode t]
9220 ["Abbreviation List" idlwave-list-abbrevs t]
9222 ["Commentary in idlwave.el" idlwave-show-commentary t]
9223 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9225 ["Info" idlwave-info t]
9227 ["Help with Topic" idlwave-help-assistant-help-with-topic
9228 idlwave-help-use-assistant]
9229 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9231 (defvar idlwave-mode-debug-menu-def
9233 ["Start IDL shell" idlwave-shell t]
9234 ["Save and .RUN buffer" idlwave-shell-save-and-run
9235 (and (boundp 'idlwave-shell-automatic-start)
9236 idlwave-shell-automatic-start)]))
9238 (if (or (featurep 'easymenu) (load "easymenu" t))
9240 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9241 "IDL and WAVE CL editing menu"
9242 idlwave-mode-menu-def)
9243 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9244 "IDL and WAVE CL editing menu"
9245 idlwave-mode-debug-menu-def)))
9247 (defun idlwave-customize ()
9248 "Call the customize function with `idlwave' as argument."
9250 ;; Try to load the code for the shell, so that we can customize it
9252 (or (featurep 'idlw-shell)
9253 (load "idlw-shell" t))
9254 (customize-browse 'idlwave))
9256 (defun idlwave-create-customize-menu ()
9257 "Create a full customization menu for IDLWAVE, insert it into the menu."
9259 (if (fboundp 'customize-menu-create)
9261 ;; Try to load the code for the shell, so that we can customize it
9263 (or (featurep 'idlw-shell)
9264 (load "idlw-shell" t))
9266 '("IDLWAVE") "Customize"
9267 `(["Browse IDLWAVE group" idlwave-customize t]
9269 ,(customize-menu-create 'idlwave)
9270 ["Set" Custom-set t]
9271 ["Save" Custom-save t]
9272 ["Reset to Current" Custom-reset-current t]
9273 ["Reset to Saved" Custom-reset-saved t]
9274 ["Reset to Standard Settings" Custom-reset-standard t]))
9275 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9276 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9278 (defun idlwave-show-commentary ()
9279 "Use the finder to view the file documentation from `idlwave.el'."
9281 (finder-commentary "idlwave.el"))
9283 (defun idlwave-shell-show-commentary ()
9284 "Use the finder to view the file documentation from `idlw-shell.el'."
9286 (finder-commentary "idlw-shell.el"))
9288 (defun idlwave-info ()
9289 "Read documentation for IDLWAVE in the info system."
9293 (defun idlwave-list-abbrevs (arg)
9294 "Show the code abbreviations define in IDLWAVE mode.
9295 This lists all abbrevs where the replacement text differs from the input text.
9296 These are the ones the users want to learn to speed up their writing.
9298 The function does *not* list abbrevs which replace a word with itself
9299 to call a hook. These hooks are used to change the case of words or
9300 to blink the matching `begin', and the user does not need to know them.
9302 With arg, list all abbrevs with the corresponding hook.
9304 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9307 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9309 str rpl func fmt (len-str 0) (len-rpl 0))
9312 (if (symbol-value sym)
9314 (setq str (symbol-name sym)
9315 rpl (symbol-value sym)
9316 func (symbol-function sym))
9318 (setq func (prin1-to-string func))
9319 (if (and (listp func) (stringp (nth 2 func)))
9320 (setq rpl (concat "EVAL: " (nth 2 func))
9323 (if (or arg (not (string= rpl str)))
9325 (setq len-str (max len-str (length str)))
9326 (setq len-rpl (max len-rpl (length rpl)))
9327 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9330 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9332 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9333 (with-output-to-temp-buffer "*Help*"
9336 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9337 (princ "=========================================\n\n")
9338 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9339 (princ (format fmt "---" "-------" "----")))
9340 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9341 (princ "================================================\n\n")
9342 (princ (format fmt "KEY" "ACTION" ""))
9343 (princ (format fmt "---" "------" "")))
9346 (setq str (car list)
9349 (princ (format fmt str rpl func)))
9351 ;; Make sure each abbreviation uses only one display line
9352 (with-current-buffer "*Help*"
9353 (setq truncate-lines t)))
9355 ;; Add .pro files to speedbar for support, if it's loaded
9356 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9358 ;; Set an idle timer to load the routine info.
9359 ;; Will only work on systems which support this.
9360 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9363 (run-hooks 'idlwave-load-hook)
9367 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
9368 ;;; idlwave.el ends here