* lisp/emacs-lisp/ert.el (ert--expand-should-1): Adapt to cl-lib.
[emacs.git] / lisp / progmodes / idlwave.el
blobe58fb2b3eab7bff6ebe90ce68f20b37f185c2296
1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
9 ;; Version: 6.1.22
10 ;; Keywords: languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; IDLWAVE enables feature-rich development and interaction with IDL,
30 ;; the Interactive Data Language. It provides a compelling,
31 ;; full-featured alternative to the IDLDE development environment
32 ;; bundled with IDL.
34 ;; In the remotely distant past, based on pascal.el, though bears
35 ;; little resemblance to it now.
37 ;; Incorporates many ideas, such as abbrevs, action routines, and
38 ;; continuation line indenting, from wave.el.
39 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
41 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
42 ;; for features, key bindings, and info.
43 ;; Also, Info format documentation is available with `M-x idlwave-info'
45 ;; New versions of IDLWAVE, documentation, and more information
46 ;; available from:
47 ;; http://idlwave.org
49 ;; INSTALLATION
50 ;; ============
52 ;; Follow the instructions in the INSTALL file of the distribution.
53 ;; In short, put this file on your load path and add the following
54 ;; lines to your init file:
56 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
57 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
58 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
61 ;; SOURCE
62 ;; ======
64 ;; The newest version of this file is available from the maintainer's
65 ;; Webpage:
67 ;; http://idlwave.org
69 ;; DOCUMENTATION
70 ;; =============
72 ;; IDLWAVE is documented online in info format. A printable version
73 ;; of the documentation is available from the maintainers webpage (see
74 ;; SOURCE).
77 ;; ACKNOWLEDGMENTS
78 ;; ===============
80 ;; Thanks to the following people for their contributions and comments:
82 ;; Ulrik Dickow <dickow_at_nbi.dk>
83 ;; Eric E. Dors <edors_at_lanl.gov>
84 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
85 ;; David Huenemoerder <dph_at_space.mit.edu>
86 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
87 ;; Dick Jackson <dick_at_d-jackson.com>
88 ;; Xuyong Liu <liu_at_stsci.edu>
89 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
90 ;; Laurent Mugnier <mugnier_at_onera.fr>
91 ;; Lubos Pochman <lubos_at_rsinc.com>
92 ;; Bob Portmann <portmann_at_al.noaa.gov>
93 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
94 ;; Marty Ryba <ryba_at_ll.mit.edu>
95 ;; Paul Sorenson <aardvark62_at_msn.com>
96 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
97 ;; Phil Williams <williams_at_irc.chmcc.org>
99 ;; CUSTOMIZATION:
100 ;; =============
102 ;; IDLWAVE has extensive customize support; to learn about the
103 ;; variables which control the mode's behavior, use `M-x
104 ;; idlwave-customize'.
106 ;; You can set your own preferred values with Customize, or with Lisp
107 ;; code in .emacs. For an example of what to put into .emacs, check
108 ;; the TexInfo documentation or see a complete .emacs available at the
109 ;; website.
111 ;; KNOWN PROBLEMS:
112 ;; ==============
114 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
115 ;; Numerics, Inc. is growing less and less complete as the two
116 ;; languages grow increasingly apart. The mode probably shouldn't
117 ;; even have "WAVE" in its title, but it's catchy, and was required
118 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
120 ;; Moving the point backwards in conjunction with abbrev expansion
121 ;; does not work as I would like it, but this is a problem with
122 ;; emacs abbrev expansion done by the self-insert-command. It ends
123 ;; up inserting the character that expanded the abbrev after moving
124 ;; point backward, e.g., "\cl" expanded with a space becomes
125 ;; "LONG( )" with point before the close paren. This is solved by
126 ;; using a temporary function in `post-command-hook' - not pretty,
127 ;; but it works.
129 ;; Tabs and spaces are treated equally as whitespace when filling a
130 ;; comment paragraph. To accomplish this, tabs are permanently
131 ;; replaced by spaces in the text surrounding the paragraph, which
132 ;; may be an undesirable side-effect. Replacing tabs with spaces is
133 ;; limited to comments only and occurs only when a comment
134 ;; paragraph is filled via `idlwave-fill-paragraph'.
136 ;; Muti-statement lines (using "&") on block begin and end lines can
137 ;; ruin the formatting. For example, multiple end statements on a
138 ;; line: endif & endif. Using "&" outside of block begin/end lines
139 ;; should be okay.
141 ;; Determining the expression at point for printing and other
142 ;; examination commands is somewhat rough: currently only fairly
143 ;; simple entities are found. You can always drag-select or examine
144 ;; a pre-selected region.
146 ;; When forcing completion of method keywords, the initial
147 ;; query for a method has multiple entries for some methods. Would
148 ;; be too difficult to fix this hardly used case.
151 ;;; Code:
154 (eval-when-compile (require 'cl))
155 (require 'idlw-help)
157 ;; For XEmacs
158 (unless (fboundp 'line-beginning-position)
159 (defalias 'line-beginning-position 'point-at-bol))
160 (unless (fboundp 'line-end-position)
161 (defalias 'line-end-position 'point-at-eol))
162 (unless (fboundp 'char-valid-p)
163 (defalias 'char-valid-p 'characterp))
164 (unless (fboundp 'match-string-no-properties)
165 (defalias 'match-string-no-properties 'match-string))
167 (if (not (fboundp 'cancel-timer))
168 (condition-case nil
169 (require 'timer)
170 (error nil)))
172 (declare-function idlwave-shell-get-path-info "idlw-shell")
173 (declare-function idlwave-shell-temp-file "idlw-shell")
174 (declare-function idlwave-shell-is-running "idlw-shell")
175 (declare-function widget-value "wid-edit" (widget))
176 (declare-function comint-dynamic-complete-filename "comint" ())
178 (defgroup idlwave nil
179 "Major mode for editing IDL .pro files."
180 :tag "IDLWAVE"
181 :link '(url-link :tag "Home Page"
182 "http://idlwave.org")
183 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
184 "idlw-shell.el")
185 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
186 :link '(custom-manual "(idlwave)Top")
187 :prefix "idlwave"
188 :group 'languages)
191 ;;; Variables for indentation behavior ---------------------------------------
193 (defgroup idlwave-code-formatting nil
194 "Indentation and formatting options for IDLWAVE mode."
195 :group 'idlwave)
197 (defcustom idlwave-main-block-indent 2
198 "Extra indentation for the main block of code.
199 That is the block between the FUNCTION/PRO statement and the END
200 statement for that program unit."
201 :group 'idlwave-code-formatting
202 :type 'integer)
204 (defcustom idlwave-block-indent 3
205 "Extra indentation applied to block lines.
206 If you change this, you probably also want to change `idlwave-end-offset'."
207 :group 'idlwave-code-formatting
208 :type 'integer)
210 (defcustom idlwave-end-offset -3
211 "Extra indentation applied to block END lines.
212 A value equal to negative `idlwave-block-indent' will make END lines
213 line up with the block BEGIN lines."
214 :group 'idlwave-code-formatting
215 :type 'integer)
217 (defcustom idlwave-continuation-indent 3
218 "Extra indentation applied to continuation lines.
219 This extra offset applies to the first of a set of continuation lines.
220 The following lines receive the same indentation as the first."
221 :group 'idlwave-code-formatting
222 :type 'integer)
224 (defcustom idlwave-max-extra-continuation-indent 40
225 "Maximum additional indentation for special continuation indent.
226 Several special indentations are tried to help line up continuation
227 lines in routine calls or definitions, other statements with
228 parentheses, or assignment statements. This variable specifies a
229 maximum amount by which this special indentation can exceed the
230 standard continuation indentation, otherwise defaulting to a fixed
231 offset. Set to 0 to effectively disable all special continuation
232 indentation, or to a large number (like 100) to enable it in all
233 cases. See also `idlwave-indent-to-open-paren', which can override
234 this variable."
235 :group 'idlwave-code-formatting
236 :type 'integer)
238 (defcustom idlwave-indent-to-open-paren t
239 "Non-nil means, indent continuation lines to innermost open parenthesis.
240 This indentation occurs even if otherwise disallowed by
241 `idlwave-max-extra-continuation-indent'. Matching parens and the
242 interleaving args are lined up. Example:
244 x = function_a(function_b(function_c( a, b, [1,2,3, $
245 4,5,6 $
246 ], $
247 c, d $
250 When this variable is nil, paren alignment may still occur, based on
251 the value of `idlwave-max-extra-continuation-indent', which, if zero,
252 would yield:
254 x = function_a(function_b(function_c( a, b, [1,2,3, $
255 4,5,6 $
256 ], $
257 c, d $
258 )))"
259 :group 'idlwave-code-formatting
260 :type 'boolean)
262 (defcustom idlwave-indent-parens-nested nil
263 "Non-nil means, indent continuation lines with parens by nesting
264 lines at consecutively deeper levels."
265 :group 'idlwave-code-formatting
266 :type 'boolean)
269 (defcustom idlwave-hanging-indent t
270 "If set non-nil then comment paragraphs are indented under the
271 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
272 of the paragraph."
273 :group 'idlwave-code-formatting
274 :type 'boolean)
276 (defcustom idlwave-hang-indent-regexp "- "
277 "Regular expression matching the position of the hanging indent
278 in the first line of a comment paragraph. The size of the indent
279 extends to the end of the match for the regular expression."
280 :group 'idlwave-code-formatting
281 :type 'regexp)
283 (defcustom idlwave-use-last-hang-indent nil
284 "If non-nil then use last match on line for `idlwave-indent-regexp'."
285 :group 'idlwave-code-formatting
286 :type 'boolean)
288 (defcustom idlwave-fill-comment-line-only t
289 "If non-nil then auto fill will only operate on comment lines."
290 :group 'idlwave-code-formatting
291 :type 'boolean)
293 (defcustom idlwave-auto-fill-split-string t
294 "If non-nil then auto fill will split strings with the IDL `+' operator.
295 When the line end falls within a string, string concatenation with the
296 '+' operator will be used to distribute a long string over lines.
297 If nil and a string is split then a terminal beep and warning are issued.
299 This variable is ignored when `idlwave-fill-comment-line-only' is
300 non-nil, since in this case code is not auto-filled."
301 :group 'idlwave-code-formatting
302 :type 'boolean)
304 (defcustom idlwave-split-line-string t
305 "If non-nil then `idlwave-split-line' will split strings with `+'.
306 When the splitting point of a line falls inside a string, split the string
307 using the `+' string concatenation operator. If nil and a string is
308 split then a terminal beep and warning are issued."
309 :group 'idlwave-code-formatting
310 :type 'boolean)
312 (defcustom idlwave-no-change-comment ";;;"
313 "The indentation of a comment that starts with this regular
314 expression will not be changed. Note that the indentation of a comment
315 at the beginning of a line is never changed."
316 :group 'idlwave-code-formatting
317 :type 'string)
319 (defcustom idlwave-begin-line-comment nil
320 "A comment anchored at the beginning of line.
321 A comment matching this regular expression will not have its
322 indentation changed. If nil the default is \"^;\", i.e., any line
323 beginning with a \";\". Expressions for comments at the beginning of
324 the line should begin with \"^\"."
325 :group 'idlwave-code-formatting
326 :type '(choice (const :tag "Any line beginning with `;'" nil)
327 'regexp))
329 (defcustom idlwave-code-comment ";;[^;]"
330 "A comment that starts with this regular expression on a line by
331 itself is indented as if it is a part of IDL code. As a result if
332 the comment is not preceded by whitespace it is unchanged."
333 :group 'idlwave-code-formatting
334 :type 'regexp)
336 ;; Comments not matching any of the above will be indented as a
337 ;; right-margin comment, i.e., to a minimum of `comment-column'.
339 ;;; Routine Info and Completion ---------------------------------------
341 (defgroup idlwave-routine-info nil
342 "Routine Info options for IDLWAVE mode."
343 :group 'idlwave)
345 (defcustom idlwave-use-library-catalogs t
346 "Non-nil means search the IDL path for library catalog files.
348 These files, named .idlwave_catalog, document routine information for
349 individual directories and libraries of IDL .pro files. Many popular
350 libraries come with catalog files by default, so leaving this on is
351 usually a good idea."
352 :group 'idlwave-routine-info
353 :type 'boolean)
355 (defcustom idlwave-init-rinfo-when-idle-after 10
356 "Seconds of idle time before routine info is automatically initialized.
357 Initializing the routine info can take a long time, in particular if a
358 large number of library catalogs are involved. When Emacs is idle for
359 more than the number of seconds specified by this variable, it starts
360 the initialization. The process is split into five steps, in order to
361 keep work interruption as short as possible. If one of the steps
362 finishes, and no user input has arrived in the mean time, initialization
363 proceeds immediately to the next step. A good value for this variable
364 is about 1/3 of the time initialization take in your setup. So if you
365 have a fast machine and no problems with a slow network connection,
366 don't hesitate to set this to 2 seconds. A value of 0 means, don't
367 initialize automatically, but instead wait until routine information is
368 needed, and initialize then."
369 :group 'idlwave-routine-info
370 :type 'number)
372 (defcustom idlwave-scan-all-buffers-for-routine-info t
373 "Non-nil means, scan buffers for IDL programs when updating info.
374 The scanning is done by the command `idlwave-update-routine-info'.
375 The following values are allowed:
377 nil Don't scan any buffers.
378 t Scan all `idlwave-mode' buffers in the current editing session.
379 current Scan only the current buffer, but no other buffers."
380 :group 'idlwave-routine-info
381 :type '(choice
382 (const :tag "No buffer" nil)
383 (const :tag "All buffers" t)
384 (const :tag "Current buffer only" 'current)))
386 (defcustom idlwave-query-shell-for-routine-info t
387 "Non-nil means query the shell for info about compiled routines.
388 Querying the shell is useful to get information about compiled modules,
389 and it is turned on by default. However, when you have a complete library
390 scan, this is not necessary."
391 :group 'idlwave-routine-info
392 :type 'boolean)
394 (defcustom idlwave-auto-routine-info-updates
395 '(find-file save-buffer kill-buffer compile-buffer)
396 "Controls under what circumstances routine info is updated automatically.
397 Possible values:
398 nil Never
399 t All available
400 \(...) A list of circumstances. Allowed members are:
401 find-file Add info for new IDLWAVE buffers.
402 save-buffer Update buffer info when buffer is saved
403 kill-buffer Remove buffer info when buffer gets killed
404 compile-buffer Update shell info after `idlwave-shell-save-and...'"
405 :group 'idlwave-routine-info
406 :type '(choice
407 (const :tag "Never" nil)
408 (const :tag "As often as possible" t)
409 (set :tag "Checklist" :greedy t
410 (const :tag "When visiting a file" find-file)
411 (const :tag "When saving a buffer" save-buffer)
412 (const :tag "After a buffer was killed" kill-buffer)
413 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
415 (defcustom idlwave-rinfo-max-source-lines 5
416 "Maximum number of source files displayed in the Routine Info window.
417 When an integer, it is the maximum number of source files displayed.
418 A value of t means to show all source files."
419 :group 'idlwave-routine-info
420 :type 'integer)
422 (defcustom idlwave-library-path nil
423 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
424 When selecting the directories to scan for IDL user catalog routine
425 info, IDLWAVE can, under UNIX, query the shell for the exact search
426 path \(the value of !PATH). However, under Windows and MacOS
427 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
428 variable can be set to specify the paths where IDLWAVE can find PRO
429 files. The shell will only be asked for a list of paths when this
430 variable is nil. The value is a list of directories. A directory
431 preceded by a `+' will be searched recursively. If you set this
432 variable on a UNIX system, the shell will not be queried. See also
433 `idlwave-system-directory'."
434 :group 'idlwave-routine-info
435 :type '(repeat (directory)))
437 (defcustom idlwave-system-directory ""
438 "The IDL system directory for Windows and MacOS. Not needed under
439 UNIX. Set this to the value of the `!DIR' system variable in IDL.
440 IDLWAVE uses this to find out which of the library routines belong to
441 the official system library. All files inside the `lib' subdirectory
442 are considered system library files - so don't install private stuff
443 in this directory. On UNIX systems, IDLWAVE queries the shell for the
444 value of `!DIR'. See also `idlwave-library-path'."
445 :group 'idlwave-routine-info
446 :type 'directory)
448 ;; Configuration files
449 (defcustom idlwave-config-directory
450 (convert-standard-filename "~/.idlwave")
451 "Directory for configuration files and user-library catalog."
452 :group 'idlwave-routine-info
453 :type 'file)
455 (defvar idlwave-user-catalog-file "idlusercat.el")
456 (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
457 (defvar idlwave-path-file "idlpath.el")
459 (defcustom idlwave-special-lib-alist nil
460 "Alist of regular expressions matching special library directories.
461 When listing routine source locations, IDLWAVE gives a short hint where
462 the file defining the routine is located. By default it lists `SystemLib'
463 for routines in the system library `!DIR/lib' and `Library' for anything
464 else. This variable can define additional types. The car of each entry
465 is a regular expression matching the file name (they normally will match
466 on the path). The cdr is the string to be used as identifier. Max 10
467 chars are allowed."
468 :group 'idlwave-routine-info
469 :type '(repeat
470 (cons regexp string)))
472 (defcustom idlwave-auto-write-paths t
473 "Write out path (!PATH) and system directory (!DIR) info automatically.
474 Path info is needed to locate library catalog files. If non-nil,
475 whenever the path-list changes as a result of shell-query, etc., it is
476 written to file. Otherwise, the menu option \"Write Paths\" can be
477 used to force a write."
478 :group 'idlwave-routine-info
479 :type 'boolean)
481 (defgroup idlwave-completion nil
482 "Completion options for IDLWAVE mode."
483 :prefix "idlwave"
484 :group 'idlwave)
486 (eval-and-compile
487 (defconst idlwave-tmp
488 '(choice :tag "by applying the function"
489 (const upcase)
490 (const downcase)
491 (const capitalize)
492 (const preserve)
493 (symbol :tag "Other"))))
495 (defcustom idlwave-completion-case '((routine . upcase)
496 (keyword . upcase)
497 (class . preserve)
498 (method . preserve))
499 "Association list setting the case of completed words.
501 This variable determines the case (UPPER/lower/Capitalized...) of
502 words inserted into the buffer by completion. The preferred case can
503 be specified separately for routine names, keywords, classes and
504 methods.
505 This alist should therefore have entries for `routine' (normal
506 functions and procedures, i.e. non-methods), `keyword', `class', and
507 `method'. Plausible values are
509 upcase upcase whole word, like `BOX_CURSOR'
510 downcase downcase whole word, like `read_ppm'
511 capitalize capitalize each part, like `Widget_Control'
512 preserve preserve case as is, like `IDLgrView'
514 The value can also be any Emacs Lisp function which transforms the
515 case of characters in a string.
517 A value of `preserve' means that the case of the completed word is
518 identical to the way it was written in the definition statement of the
519 routine. This was implemented to allow for mixed-case completion, in
520 particular of object classes and methods.
521 If a completable word is defined in multiple locations, the meaning of
522 `preserve' is not unique since the different definitions might be
523 cased differently. Therefore IDLWAVE always takes the case of the
524 *first* definition it encounters during routine info collection and
525 uses the case derived from it consistently.
527 Note that a lowercase-only string in the buffer will always be completed in
528 lower case (but see the variable `idlwave-completion-force-default-case').
530 After changing this variable, you need to either restart Emacs or press
531 `C-u C-c C-i' to update the internal lists."
532 :group 'idlwave-completion
533 :type `(repeat
534 (cons (symbol :tag "Derive completion case for")
535 ,idlwave-tmp)))
537 (defcustom idlwave-completion-force-default-case nil
538 "Non-nil means, completion will always honor `idlwave-completion-case'.
539 When nil, only the completion of a mixed case or upper case string
540 will honor the default settings in `idlwave-completion-case', while
541 the completion of lower case strings will be completed entirely in
542 lower case."
543 :group 'idlwave-completion
544 :type 'boolean)
546 (defcustom idlwave-complete-empty-string-as-lower-case nil
547 "Non-nil means, the empty string is considered downcase for completion.
548 The case of what is already in the buffer determines the case of completions.
549 When this variable is non-nil, the empty string is considered to be downcase.
550 Completing on the empty string then offers downcase versions of the possible
551 completions."
552 :group 'idlwave-completion
553 :type 'boolean)
555 (defcustom idlwave-buffer-case-takes-precedence nil
556 "Non-nil means, the case of tokens in buffers dominates over system stuff.
557 To make this possible, we need to re-case everything each time we update
558 the routine info from the buffers. This is slow.
559 The default is to consider the case given in the system and library files
560 first which makes updating much faster."
561 :group 'idlwave-completion
562 :type 'boolean)
564 (defcustom idlwave-highlight-help-links-in-completion t
565 "Non-nil means, highlight completions for which system help is available.
566 Help can then be accessed with mouse-3.
567 This option is only effective when the online help system is installed."
568 :group 'idlwave-completion
569 :type 'boolean)
571 (defcustom idlwave-support-inheritance t
572 "Non-nil means, treat inheritance with completion, online help etc.
573 When nil, IDLWAVE only knows about the native methods and tags of a class,
574 not about inherited ones."
575 :group 'idlwave-routine-info
576 :type 'boolean)
578 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
579 "List of regular expressions for class-driven keyword inheritance.
580 Keyword inheritance is often tied to class inheritance by \"chaining\"
581 up the class tree. While it cannot be assumed that the presence of an
582 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
583 certain methods this assumption is almost always true. The methods
584 for which to assume this can be set here."
585 :group 'idlwave-routine-info
586 :type '(repeat (regexp :tag "Match method:")))
589 (defcustom idlwave-completion-show-classes 1
590 "Number of classes to show when completing object methods and keywords.
591 When completing methods or keywords for an object with unknown class,
592 the *Completions* buffer will show the valid classes for each completion
593 like this:
595 MyMethod <Class1,Class2,Class3>
597 The value of this variable may be nil to inhibit display, or an integer to
598 indicate the maximum number of classes to display.
600 On XEmacs, a full list of classes will also be placed into a `help-echo'
601 property on the completion items, so that the list of classes for the current
602 item is displayed in the echo area. If the value of this variable is a
603 negative integer, the `help-echo' property will be suppressed."
604 :group 'idlwave-completion
605 :type '(choice (const :tag "Don't show" nil)
606 (integer :tag "Number of classes shown" 1)))
608 (defcustom idlwave-completion-fontify-classes t
609 "Non-nil means, fontify the classes in completions buffer.
610 This makes it easier to distinguish the completion items from the extra
611 class info listed. See `idlwave-completion-show-classes'."
612 :group 'idlwave-completion
613 :type 'boolean)
615 (defcustom idlwave-query-class '((method-default . nil)
616 (keyword-default . nil))
617 "Association list governing specification of object classes for completion.
619 When IDLWAVE tries to complete object-oriented methods, it usually
620 cannot determine the class of a given object from context. In order
621 to provide the user with a correct list of methods or keywords, it
622 needs to determine the appropriate class. IDLWAVE has two ways of
623 doing this (well, three ways if you count the shell... see
624 `idlwave-shell-query-for-class'):
626 1. Combine the items of all available classes which contain this
627 method for the purpose of completion. So when completing a method,
628 all methods of all known classes are available, and when completing
629 a keyword, all keywords allowed for this method in any class are
630 shown. This behavior is very much like normal completion and is
631 therefore the default. It works much better than one might think -
632 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
633 become uncomfortably long. See also
634 `idlwave-completion-show-classes'.
636 2. The second possibility is to ask the user on each occasion. To
637 make this less interruptive, IDLWAVE can store the class as a text
638 property on the object operator `->'. For a given object in the
639 source code, class selection will then be needed only once
640 - for example to complete the method. Keywords to the method can
641 then be completed directly, because the class is already known.
642 You will have to turn on the storage of the selected class
643 explicitly with the variable `idlwave-store-inquired-class'.
645 This variable allows you to configure IDLWAVE's method and
646 method-keyword completion behavior. Its value is an alist, which
647 should contain at least two elements: (method-default . VALUE) and
648 \(keyword-default . VALUE), where VALUE is either t or nil. These
649 specify if the class should be found during method and keyword
650 completion, respectively.
652 The alist may have additional entries specifying exceptions from the
653 keyword completion rule for specific methods, like INIT or
654 GETPROPERTY. In order to turn on class specification for the INIT
655 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
656 :group 'idlwave-completion
657 :type '(list
658 (cons (const method-default)
659 (boolean :tag "Determine class when completing METHODS "))
660 (cons (const keyword-default)
661 (boolean :tag "Determine class when completing KEYWORDS "))
662 (repeat
663 :tag "Exceptions to defaults"
664 :inline t
665 (cons (string :tag "MODULE" :value "")
666 (boolean :tag "Determine class for this method")))))
668 (defcustom idlwave-store-inquired-class t
669 "Non-nil means, store class of a method call as text property on `->'.
670 IDLWAVE sometimes has to ask the user for the class associated with a
671 particular object method call. This happens during the commands
672 `idlwave-routine-info' and `idlwave-complete', depending upon the
673 value of the variable `idlwave-query-class'.
675 When you specify a class, this information can be stored as a text
676 property on the `->' arrow in the source code, so that during the same
677 editing session, IDLWAVE will not have to ask again. When this
678 variable is non-nil, IDLWAVE will store and reuse the class information.
679 The class stored can be checked and removed with `\\[idlwave-routine-info]'
680 on the arrow.
682 The default of this variable is nil, since the result of commands then
683 is more predictable. However, if you know what you are doing, it can
684 be nice to turn this on.
686 An arrow which knows the class will be highlighted with
687 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
688 displays (with prefix arg: deletes) the class stored on the arrow
689 at point."
690 :group 'idlwave-completion
691 :type 'boolean)
693 (defcustom idlwave-class-arrow-face 'bold
694 "Face to highlight object operator arrows `->' which carry a class property.
695 When IDLWAVE stores a class name as text property on an object arrow
696 \(see variable `idlwave-store-inquired-class', it highlights the arrow
697 with this font in order to remind the user that this arrow is special."
698 :group 'idlwave-completion
699 :type 'symbol)
701 (defcustom idlwave-resize-routine-help-window t
702 "Non-nil means, resize the Routine-info *Help* window to fit the content."
703 :group 'idlwave-completion
704 :type 'boolean)
706 (defcustom idlwave-keyword-completion-adds-equal t
707 "Non-nil means, completion automatically adds `=' after completed keywords."
708 :group 'idlwave-completion
709 :type 'boolean)
711 (defcustom idlwave-function-completion-adds-paren t
712 "Non-nil means, completion automatically adds `(' after completed function.
713 nil means, don't add anything.
714 A value of `2' means, also add the closing parenthesis and position cursor
715 between the two."
716 :group 'idlwave-completion
717 :type '(choice (const :tag "Nothing" nil)
718 (const :tag "(" t)
719 (const :tag "()" 2)))
721 (defcustom idlwave-completion-restore-window-configuration t
722 "Non-nil means, try to restore the window configuration after completion.
723 When completion is not unique, Emacs displays a list of completions.
724 This messes up your window configuration. With this variable set, IDLWAVE
725 restores the old configuration after successful completion."
726 :group 'idlwave-completion
727 :type 'boolean)
729 ;;; Variables for abbrev and action behavior -----------------------------
731 (defgroup idlwave-abbrev-and-indent-action nil
732 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
733 The variables in this group govern this."
734 :group 'idlwave)
736 (defcustom idlwave-do-actions nil
737 "Non-nil means performs actions when indenting.
738 The actions that can be performed are listed in `idlwave-indent-action-table'."
739 :group 'idlwave-abbrev-and-indent-action
740 :type 'boolean)
742 (defcustom idlwave-abbrev-start-char "\\"
743 "A single character string used to start abbreviations in abbrev mode.
744 Possible characters to chose from: ~`\%
745 or even '?'. '.' is not a good choice because it can make structure
746 field names act like abbrevs in certain circumstances.
748 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
749 must set it directly using `setq' in the init file before idlwave.el
750 is loaded."
751 :group 'idlwave-abbrev-and-indent-action
752 :type 'string)
754 (defcustom idlwave-surround-by-blank nil
755 "Non-nil means, enable `idlwave-surround'.
756 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
757 `idlwave-surround'.
758 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
760 Also see the default key bindings for keys using `idlwave-surround'.
761 Keys are bound and made into actions calling `idlwave-surround' with
762 `idlwave-action-and-binding'.
763 See help for `idlwave-action-and-binding' for examples.
765 Also see help for `idlwave-surround'."
766 :group 'idlwave-abbrev-and-indent-action
767 :type 'boolean)
769 (defcustom idlwave-pad-keyword t
770 "Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
771 Whenever `idlwave-surround' is non-nil then this affects how '=' is
772 padded for keywords and for variables. If t, pad the same as for
773 assignments. If nil then spaces are removed. With any other value,
774 spaces are left unchanged."
775 :group 'idlwave-abbrev-and-indent-action
776 :type '(choice
777 (const :tag "Pad like assignments" t)
778 (const :tag "Remove space near `='" nil)
779 (const :tag "Keep space near `='" 'keep)))
781 (defcustom idlwave-show-block t
782 "Non-nil means point blinks to block beginning for `idlwave-show-begin'."
783 :group 'idlwave-abbrev-and-indent-action
784 :type 'boolean)
786 (defcustom idlwave-expand-generic-end nil
787 "Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
788 :group 'idlwave-abbrev-and-indent-action
789 :type 'boolean)
791 (defcustom idlwave-reindent-end t
792 "Non-nil means re-indent line after END was typed."
793 :group 'idlwave-abbrev-and-indent-action
794 :type 'boolean)
796 (defcustom idlwave-abbrev-move t
797 "Non-nil means the abbrev hook can move point.
798 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
799 definitions, use the command `list-abbrevs', for abbrevs that move
800 point. Moving point is useful, for example, to place point between
801 parentheses of expanded functions.
803 See `idlwave-check-abbrev'."
804 :group 'idlwave-abbrev-and-indent-action
805 :type 'boolean)
807 (defcustom idlwave-abbrev-change-case nil
808 "Non-nil means all abbrevs will be forced to either upper or lower case.
809 If the value t, all expanded abbrevs will be upper case.
810 If the value is 'down then abbrevs will be forced to lower case.
811 If nil, the case will not change.
812 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
813 upper case, regardless of this variable."
814 :group 'idlwave-abbrev-and-indent-action
815 :type 'boolean)
817 (defcustom idlwave-reserved-word-upcase nil
818 "Non-nil means, reserved words will be made upper case via abbrev expansion.
819 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
820 Has effect only if in abbrev-mode."
821 :group 'idlwave-abbrev-and-indent-action
822 :type 'boolean)
824 ;;; Action/Expand Tables.
826 ;; The average user may have difficulty modifying this directly. It
827 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
828 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
829 ;; examples of how to add an action.
831 ;; The action table is used by `idlwave-indent-line' whereas both the
832 ;; action and expand tables are used by `idlwave-indent-and-action'. In
833 ;; general, the expand table is only used when a line is explicitly
834 ;; indented. Whereas, in addition to being used when the expand table
835 ;; is used, the action table is used when a line is indirectly
836 ;; indented via line splitting, auto-filling or a new line creation.
838 ;; Example actions:
840 ;; Capitalize system vars
841 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
843 ;; Capitalize procedure name
844 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
845 ;; '(capitalize-word 1) t)
847 ;; Capitalize common block name
848 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
849 ;; '(capitalize-word 1) t)
850 ;; Capitalize label
851 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
852 ;; '(capitalize-word -1) t)
854 (defvar idlwave-indent-action-table nil
855 "Associated array containing action lists of search string (car),
856 and function as a cdr. This table is used by `idlwave-indent-line'.
857 See documentation for `idlwave-do-action' for a complete description of
858 the action lists.
860 Additions to the table are made with `idlwave-action-and-binding' when a
861 binding is not requested.
862 See help on `idlwave-action-and-binding' for examples.")
864 (defvar idlwave-indent-expand-table nil
865 "Associated array containing action lists of search string (car),
866 and function as a cdr. The table is used by the
867 `idlwave-indent-and-action' function. See documentation for
868 `idlwave-do-action' for a complete description of the action lists.
870 Additions to the table are made with `idlwave-action-and-binding' when a
871 binding is requested.
872 See help on `idlwave-action-and-binding' for examples.")
874 ;;; Documentation header and history keyword ---------------------------------
876 (defgroup idlwave-documentation nil
877 "Options for documenting IDLWAVE files."
878 :group 'idlwave)
880 ;; FIXME: make defcustom?
881 (defvar idlwave-file-header
882 (list nil
884 ; NAME:
888 ; PURPOSE:
892 ; CATEGORY:
896 ; CALLING SEQUENCE:
900 ; INPUTS:
904 ; OPTIONAL INPUTS:
908 ; KEYWORD PARAMETERS:
912 ; OUTPUTS:
916 ; OPTIONAL OUTPUTS:
920 ; COMMON BLOCKS:
924 ; SIDE EFFECTS:
928 ; RESTRICTIONS:
932 ; PROCEDURE:
936 ; EXAMPLE:
940 ; MODIFICATION HISTORY:
944 "A list (PATHNAME STRING) specifying the doc-header template to use for
945 summarizing a file. If PATHNAME is non-nil then this file will be included.
946 Otherwise STRING is used. If nil, the file summary will be omitted.
947 For example you might set PATHNAME to the path for the
948 lib_template.pro file included in the IDL distribution.")
950 (defcustom idlwave-header-to-beginning-of-file t
951 "Non-nil means, the documentation header will always be at start of file.
952 When nil, the header is positioned between the PRO/FUNCTION line of
953 the current routine and the code, allowing several routine headers in
954 a file."
955 :group 'idlwave-documentation
956 :type 'boolean)
958 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
959 "The hook function used to update the timestamp of a function."
960 :group 'idlwave-documentation
961 :type 'function)
963 (defcustom idlwave-doc-modifications-keyword "HISTORY"
964 "The modifications keyword to use with the log documentation commands.
965 A ':' is added to the keyword end.
966 Inserted by doc-header and used to position logs by doc-modification.
967 If nil it will not be inserted."
968 :group 'idlwave-documentation
969 :type 'string)
971 (defcustom idlwave-doclib-start "^;+\\+"
972 "Regexp matching the start of a document library header."
973 :group 'idlwave-documentation
974 :type 'regexp)
976 (defcustom idlwave-doclib-end "^;+-"
977 "Regexp matching the end of a document library header."
978 :group 'idlwave-documentation
979 :type 'regexp)
981 ;;; External Programs -------------------------------------------------------
983 (defgroup idlwave-external-programs nil
984 "Path locations of external commands used by IDLWAVE."
985 :group 'idlwave)
987 (defcustom idlwave-shell-explicit-file-name "idl"
988 "If non-nil, this is the command to run IDL.
989 Should be an absolute file path or path relative to the current environment
990 execution search path. If you want to specify command line switches
991 for the IDL program, use `idlwave-shell-command-line-options'.
993 I know the name of this variable is badly chosen, but I cannot change
994 it without compromising backwards-compatibility."
995 :group 'idlwave-external-programs
996 :type 'string)
998 (defcustom idlwave-shell-command-line-options nil
999 "A list of command line options for calling the IDL program.
1000 Since IDL is executed directly without going through a shell like /bin/sh,
1001 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1002 string for each argument. But you may also give a single string which
1003 contains the options whitespace-separated. Emacs will be kind enough to
1004 split it for you."
1005 :type '(choice
1006 string
1007 (repeat (string :value "")))
1008 :group 'idlwave-external-programs)
1010 (defcustom idlwave-help-application "idlhelp"
1011 "The external application providing reference help for programming.
1012 Obsolete, if the IDL Assistant is being used for help."
1013 :group 'idlwave-external-programs
1014 :type 'string)
1016 ;;; Some Shell variables which must be defined here.-----------------------
1018 (defcustom idlwave-shell-debug-modifiers '()
1019 "List of modifiers to be used for the debugging commands.
1020 Will be used to bind debugging commands in the shell buffer and in all
1021 source buffers. These are additional convenience bindings, the debugging
1022 commands are always available with the `C-c C-d' prefix.
1023 If you set this to '(control shift), this means setting a breakpoint will
1024 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1025 are `control', `meta', `super', `hyper', `alt', and `shift'."
1026 :group 'idlwave-shell-general-setup
1027 :type '(set :tag "Specify modifiers"
1028 (const control)
1029 (const meta)
1030 (const super)
1031 (const hyper)
1032 (const alt)
1033 (const shift)))
1035 (defcustom idlwave-shell-automatic-start nil
1036 "If non-nil attempt invoke `idlwave-shell' if not already running.
1037 This is checked when an attempt to send a command to an
1038 IDL process is made."
1039 :group 'idlwave-shell-general-setup
1040 :type 'boolean)
1042 ;;; Miscellaneous variables -------------------------------------------------
1044 (defgroup idlwave-misc nil
1045 "Miscellaneous options for IDLWAVE mode."
1046 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
1047 :group 'idlwave)
1049 (defcustom idlwave-startup-message t
1050 "Non-nil displays a startup message when `idlwave-mode' is first called."
1051 :group 'idlwave-misc
1052 :type 'boolean)
1054 (defcustom idlwave-default-font-lock-items
1055 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1056 common-blocks class-arrows)
1057 "Items which should be fontified on the default fontification level 2.
1058 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1059 is everything and level 2 is specified by this list.
1060 This variable must be set before IDLWAVE gets loaded.
1061 It is a list of symbols; the following symbols are allowed:
1063 pros-and-functions Procedure and Function definitions
1064 batch-files Batch Files
1065 idlwave-idl-keywords IDL Keywords
1066 label Statement Labels
1067 goto Goto Statements
1068 common-blocks Common Blocks
1069 keyword-parameters Keyword Parameters in routine definitions and calls
1070 system-variables System Variables
1071 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1072 class-arrows Object Arrows with class property"
1073 :group 'idlwave-misc
1074 :type '(set
1075 :inline t :greedy t
1076 (const :tag "Procedure and Function definitions" pros-and-functions)
1077 (const :tag "Batch Files" batch-files)
1078 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1079 (const :tag "Statement Labels" label)
1080 (const :tag "Goto Statements" goto)
1081 (const :tag "Tags in Structure Definition" structtag)
1082 (const :tag "Structure Name" structname)
1083 (const :tag "Common Blocks" common-blocks)
1084 (const :tag "Keyword Parameters" keyword-parameters)
1085 (const :tag "System Variables" system-variables)
1086 (const :tag "FIXME: Warning" fixme)
1087 (const :tag "Object Arrows with class property " class-arrows)))
1089 (defcustom idlwave-mode-hook nil
1090 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1091 :group 'idlwave-misc
1092 :type 'hook)
1094 (defcustom idlwave-load-hook nil
1095 "Normal hook. Executed when idlwave.el is loaded."
1096 :group 'idlwave-misc
1097 :type 'hook)
1099 (defvar idlwave-experimental nil
1100 "Non-nil means turn on a few experimental features.
1101 This variable is only for the maintainer, to test difficult stuff,
1102 while still distributing stable releases.
1103 As a user, you should not set this to t.")
1106 ;;; End customization variables section
1109 ;;; Non customization variables
1111 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1112 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1113 ;;; and Carsten Dominik...
1115 ;; The following are the reserved words in IDL. Maybe we should
1116 ;; highlight some more stuff as well?
1117 ;; Procedure declarations. Fontify keyword plus procedure name.
1118 (defvar idlwave-idl-keywords
1119 ;; To update this regexp, update the list of keywords and
1120 ;; evaluate the form.
1121 ;; (insert
1122 ;; (prin1-to-string
1123 ;; (concat
1124 ;; "\\<\\("
1125 ;; (regexp-opt
1126 ;; '("||" "&&" "and" "or" "xor" "not"
1127 ;; "eq" "ge" "gt" "le" "lt" "ne"
1128 ;; "for" "do" "endfor"
1129 ;; "if" "then" "endif" "else" "endelse"
1130 ;; "case" "of" "endcase"
1131 ;; "switch" "break" "continue" "endswitch"
1132 ;; "begin" "end"
1133 ;; "repeat" "until" "endrep"
1134 ;; "while" "endwhile"
1135 ;; "goto" "return"
1136 ;; "inherits" "mod"
1137 ;; "compile_opt" "forward_function"
1138 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1139 ;; "\\)\\>")))
1140 "\\<\\(&&\\|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\\|||\\)\\>")
1143 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1144 ;; Function declarations. Fontify keyword plus function name.
1145 (pros-and-functions
1146 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1147 (1 font-lock-keyword-face)
1148 (2 font-lock-function-name-face nil t)))
1150 ;; Common blocks
1151 (common-blocks
1152 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1153 (1 font-lock-keyword-face) ; "common"
1154 (2 font-lock-constant-face nil t) ; block name
1155 ("[ \t]*\\(\\sw+\\)[ ,]*"
1156 ;; Start with point after block name and comma
1157 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1159 (1 font-lock-variable-name-face) ; variable names
1162 ;; Batch files
1163 (batch-files
1164 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1166 ;; FIXME warning.
1167 (fixme
1168 '("\\<FIXME:" (0 font-lock-warning-face t)))
1170 ;; Labels
1171 (label
1172 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-constant-face)))
1174 ;; The goto statement and its label
1175 (goto
1176 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1177 (1 font-lock-keyword-face)
1178 (2 font-lock-constant-face)))
1180 ;; Tags in structure definitions. Note that this definition
1181 ;; actually collides with labels, so we have to use the same
1182 ;; face. It also matches named subscript ranges,
1183 ;; e.g. vec{bottom:top]. No good way around this.
1184 (structtag
1185 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-constant-face)))
1187 ;; Structure names
1188 (structname
1189 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1190 (2 font-lock-function-name-face)))
1192 ;; Keyword parameters, like /xlog or ,xrange=[]
1193 ;; This is anchored to the comma preceding the keyword.
1194 ;; Treats continuation lines, works only during whole buffer
1195 ;; fontification. Slow, use it only in fancy fontification.
1196 (keyword-parameters
1197 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1198 (6 font-lock-constant-face)))
1200 ;; System variables start with a bang.
1201 (system-variables
1202 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1203 (1 font-lock-variable-name-face)))
1205 ;; Special and unusual operators (not used because too noisy)
1206 ;; (special-operators
1207 ;; '("[<>#]" (0 font-lock-keyword-face)))
1209 ;; All operators (not used because too noisy)
1210 ;; (all-operators
1211 ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1213 ;; Arrows with text property `idlwave-class'
1214 (class-arrows
1215 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1217 (defconst idlwave-font-lock-keywords-1
1218 (list pros-and-functions batch-files)
1219 "Subdued level highlighting for IDLWAVE mode.")
1221 (defconst idlwave-font-lock-keywords-2
1222 (mapcar 'symbol-value idlwave-default-font-lock-items)
1223 "Medium level highlighting for IDLWAVE mode.")
1225 (defconst idlwave-font-lock-keywords-3
1226 (list pros-and-functions
1227 batch-files
1228 idlwave-idl-keywords
1229 label goto
1230 structtag
1231 structname
1232 common-blocks
1233 keyword-parameters
1234 system-variables
1235 class-arrows)
1236 "Gaudy level highlighting for IDLWAVE mode."))
1238 (defun idlwave-match-class-arrows (limit)
1239 ;; Match an object arrow with class property
1240 (and idlwave-store-inquired-class
1241 (re-search-forward "->" limit 'limit)
1242 (get-text-property (match-beginning 0) 'idlwave-class)))
1244 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1245 "Default expressions to highlight in IDLWAVE mode.")
1247 (defvar idlwave-font-lock-defaults
1248 '((idlwave-font-lock-keywords
1249 idlwave-font-lock-keywords-1
1250 idlwave-font-lock-keywords-2
1251 idlwave-font-lock-keywords-3)
1252 nil t
1253 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
1254 beginning-of-line))
1256 (put 'idlwave-mode 'font-lock-defaults
1257 idlwave-font-lock-defaults) ; XEmacs
1259 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1260 "Regexp to match the start of a full-line comment.
1261 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1262 only by whitespace.")
1264 (defconst idlwave-begin-block-reg
1265 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1266 "Regular expression to find the beginning of a block.
1267 The case does not matter. The search skips matches in comments.")
1269 (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1270 "Regular expression to find the beginning of a unit.
1271 The case does not matter.")
1273 (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1274 "Regular expression to find the line that indicates the end of unit.
1275 This line is the end of buffer or the start of another unit.
1276 The case does not matter. The search skips matches in comments.")
1278 (defconst idlwave-continue-line-reg "\\<\\$"
1279 "Regular expression to match a continued line.")
1281 (defconst idlwave-end-block-reg
1282 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1283 "Regular expression to find the end of a block.
1284 The case does not matter. The search skips matches in comments.")
1286 (defconst idlwave-block-matches
1287 '(("pro" . "end")
1288 ("function" . "end")
1289 ("case" . "endcase")
1290 ("else" . "endelse")
1291 ("for" . "endfor")
1292 ("then" . "endif")
1293 ("repeat" . "endrep")
1294 ("switch" . "endswitch")
1295 ("while" . "endwhile"))
1296 "Matches between statements and the corresponding END variant.
1297 The cars are the reserved words starting a block. If the block really
1298 begins with BEGIN, the cars are the reserved words before the begin
1299 which can be used to identify the block type.
1300 This is used to check for the correct END type, to close blocks and
1301 to expand generic end statements to their detailed form.")
1303 (defconst idlwave-block-match-regexp
1304 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1305 "Regular expression matching reserved words which can stand before
1306 blocks starting with a BEGIN statement. The matches must have associations
1307 `idlwave-block-matches'.")
1309 (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
1310 "Regular expression matching an IDL identifier.")
1312 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1313 "Regular expression matching IDL system variables.")
1315 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1316 "Regular expression matching IDL variable names.")
1318 (defconst idlwave-label (concat idlwave-identifier ":")
1319 "Regular expression matching IDL labels.")
1321 (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1322 "\\(\\s *" idlwave-identifier "::\\)?"
1325 (defconst idlwave-statement-match
1326 (list
1327 ;; "endif else" is the only possible "end" that can be
1328 ;; followed by a statement on the same line.
1329 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1330 ;; all other "end"s can not be followed by a statement.
1331 (cons 'end (list idlwave-end-block-reg nil))
1332 '(if . ("if\\>" "then"))
1333 '(for . ("for\\>" "do"))
1334 '(begin . ("begin\\>" nil))
1335 '(pdef . ("pro\\>\\|function\\>" nil))
1336 '(while . ("while\\>" "do"))
1337 '(repeat . ("repeat\\>" "repeat"))
1338 '(goto . ("goto\\>" nil))
1339 '(case . ("case\\>" nil))
1340 '(switch . ("switch\\>" nil))
1341 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
1342 "\\(" idlwave-method-call "\\s *\\)?"
1343 idlwave-identifier
1344 "\\s *(") nil))
1345 (cons 'call (list (concat
1346 "\\(" idlwave-method-call "\\s *\\)?"
1347 idlwave-identifier
1348 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
1349 (cons 'assign (list (concat
1350 "\\(" idlwave-variable "\\) *=") nil)))
1352 "Associated list of statement matching regular expressions.
1353 Each regular expression matches the start of an IDL statement.
1354 The first element of each association is a symbol giving the statement
1355 type. The associated value is a list. The first element of this list
1356 is a regular expression matching the start of an IDL statement for
1357 identifying the statement type. The second element of this list is a
1358 regular expression for finding a substatement for the type. The
1359 substatement starts after the end of the found match modulo
1360 whitespace. If it is nil then the statement has no substatement. The
1361 list order matters since matching an assignment statement exactly is
1362 not possible without parsing. Thus assignment statement become just
1363 the leftover unidentified statements containing an equal sign.")
1365 ;; FIXME: This var seems to only ever be set, but never actually used!
1366 (defvar idlwave-fill-function 'auto-fill-function
1367 "IDL mode auto fill function.")
1369 (defvar idlwave-comment-indent-function 'comment-indent-function
1370 "IDL mode comment indent function.")
1372 ;; Note that this is documented in the v18 manuals as being a string
1373 ;; of length one rather than a single character.
1374 ;; The code in this file accepts either format for compatibility.
1375 (defvar idlwave-comment-indent-char ?\
1376 "Character to be inserted for IDL comment indentation.
1377 Normally a space.")
1379 (defconst idlwave-continuation-char ?$
1380 "Character which is inserted as a last character on previous line by
1381 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1383 (defconst idlwave-mode-version "6.1_em22")
1385 (defmacro idlwave-keyword-abbrev (&rest args)
1386 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1387 `(quote (lambda ()
1388 ,(append '(idlwave-check-abbrev) args))))
1390 ;; If I take the time I can replace idlwave-keyword-abbrev with
1391 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1392 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1393 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1394 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1396 (defmacro idlwave-code-abbrev (&rest args)
1397 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1398 Specifically, if the abbrev is in a comment or string it is unexpanded.
1399 Otherwise ARGS forms a list that is evaluated."
1400 ;; FIXME: it would probably be better to rely on the new :enable-function
1401 ;; to enforce the "don't expand in comments or strings".
1402 `(lambda ()
1403 ,(prin1-to-string args) ;; Puts the code in the doc string
1404 (if (idlwave-quoted)
1405 (progn (unexpand-abbrev) nil)
1406 ,(append args))))
1408 (autoload 'idlwave-shell "idlw-shell"
1409 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1410 (autoload 'idlwave-shell-send-command "idlw-shell")
1411 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1412 "Run `idlwave-shell' and switch back to current window" t)
1413 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1414 "Save and run buffer under the shell." t)
1415 (autoload 'idlwave-shell-break-here "idlw-shell"
1416 "Set breakpoint in current line." t)
1417 (autoload 'idlwave-shell-run-region "idlw-shell"
1418 "Compile and run the region." t)
1420 (fset 'idlwave-debug-map (make-sparse-keymap))
1422 (defvar idlwave-mode-map
1423 (let ((map (make-sparse-keymap)))
1424 (define-key map "\C-c " 'idlwave-hard-tab)
1425 (define-key map [(control tab)] 'idlwave-hard-tab)
1426 ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
1427 (define-key map "'" 'idlwave-show-matching-quote)
1428 (define-key map "\"" 'idlwave-show-matching-quote)
1429 (define-key map "\C-g" 'idlwave-keyboard-quit)
1430 (define-key map "\C-c;" 'idlwave-toggle-comment-region)
1431 (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1432 (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
1433 (define-key map "\C-c{" 'idlwave-beginning-of-block)
1434 (define-key map "\C-c}" 'idlwave-end-of-block)
1435 (define-key map "\C-c]" 'idlwave-close-block)
1436 (define-key map [(meta control h)] 'idlwave-mark-subprogram)
1437 (define-key map "\M-\C-n" 'idlwave-forward-block)
1438 (define-key map "\M-\C-p" 'idlwave-backward-block)
1439 (define-key map "\M-\C-d" 'idlwave-down-block)
1440 (define-key map "\M-\C-u" 'idlwave-backward-up-block)
1441 (define-key map "\M-\r" 'idlwave-split-line)
1442 (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
1443 (define-key map "\C-c\C-p" 'idlwave-previous-statement)
1444 (define-key map "\C-c\C-n" 'idlwave-next-statement)
1445 ;; (define-key map "\r" 'idlwave-newline)
1446 ;; (define-key map "\t" 'idlwave-indent-line)
1447 (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
1448 (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
1449 (define-key map "\M-q" 'idlwave-fill-paragraph)
1450 (define-key map "\M-s" 'idlwave-edit-in-idlde)
1451 (define-key map "\C-c\C-h" 'idlwave-doc-header)
1452 (define-key map "\C-c\C-m" 'idlwave-doc-modification)
1453 (define-key map "\C-c\C-c" 'idlwave-case)
1454 (define-key map "\C-c\C-d" 'idlwave-debug-map)
1455 (when (and (listp idlwave-shell-debug-modifiers)
1456 (not (equal idlwave-shell-debug-modifiers '())))
1457 ;; Bind the debug commands also with the special modifiers.
1458 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1459 (mods-noshift
1460 (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
1461 (define-key map
1462 (vector (append mods-noshift (list (if shift ?C ?c))))
1463 'idlwave-shell-save-and-run)
1464 (define-key map
1465 (vector (append mods-noshift (list (if shift ?B ?b))))
1466 'idlwave-shell-break-here)
1467 (define-key map
1468 (vector (append mods-noshift (list (if shift ?E ?e))))
1469 'idlwave-shell-run-region)))
1470 (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1471 (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1472 (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1473 (define-key map "\C-c\C-f" 'idlwave-for)
1474 ;; (define-key map "\C-c\C-f" 'idlwave-function)
1475 ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
1476 (define-key map "\C-c\C-r" 'idlwave-repeat)
1477 (define-key map "\C-c\C-w" 'idlwave-while)
1478 (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1479 (define-key map "\C-c\C-s" 'idlwave-shell)
1480 (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1481 (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1482 (define-key map "\C-c\C-v" 'idlwave-find-module)
1483 (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
1484 (define-key map "\C-c?" 'idlwave-routine-info)
1485 (define-key map "\M-?" 'idlwave-context-help)
1486 (define-key map [(control meta ?\?)]
1487 'idlwave-help-assistant-help-with-topic)
1488 ;; Pickup both forms of Esc/Meta binding
1489 (define-key map [(meta tab)] 'idlwave-complete)
1490 (define-key map [?\e?\t] 'idlwave-complete)
1491 (define-key map "\M-\C-i" 'idlwave-complete)
1492 (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
1493 (define-key map "\C-c=" 'idlwave-resolve)
1494 (define-key map
1495 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1496 'idlwave-mouse-context-help)
1497 map)
1498 "Keymap used in IDL mode.")
1500 (defvar idlwave-mode-syntax-table
1501 (let ((st (make-syntax-table)))
1502 (modify-syntax-entry ?+ "." st)
1503 (modify-syntax-entry ?- "." st)
1504 (modify-syntax-entry ?* "." st)
1505 (modify-syntax-entry ?/ "." st)
1506 (modify-syntax-entry ?^ "." st)
1507 (modify-syntax-entry ?# "." st)
1508 (modify-syntax-entry ?= "." st)
1509 (modify-syntax-entry ?% "." st)
1510 (modify-syntax-entry ?< "." st)
1511 (modify-syntax-entry ?> "." st)
1512 (modify-syntax-entry ?\' "\"" st)
1513 (modify-syntax-entry ?\" "\"" st)
1514 (modify-syntax-entry ?\\ "." st)
1515 (modify-syntax-entry ?_ "_" st)
1516 (modify-syntax-entry ?{ "(}" st)
1517 (modify-syntax-entry ?} "){" st)
1518 (modify-syntax-entry ?$ "_" st)
1519 (modify-syntax-entry ?. "." st)
1520 (modify-syntax-entry ?\; "<" st)
1521 (modify-syntax-entry ?\n ">" st)
1522 (modify-syntax-entry ?\f ">" st)
1524 "Syntax table in use in `idlwave-mode' buffers.")
1526 (defvar idlwave-find-symbol-syntax-table
1527 (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
1528 (modify-syntax-entry ?$ "w" st)
1529 (modify-syntax-entry ?_ "w" st)
1530 (modify-syntax-entry ?! "w" st)
1531 (modify-syntax-entry ?. "w" st)
1533 "Syntax table that treats symbol characters as word characters.")
1535 (defmacro idlwave-with-special-syntax (&rest body)
1536 "Execute BODY with a different syntax table."
1537 `(let ((saved-syntax (syntax-table)))
1538 (unwind-protect
1539 (progn
1540 (set-syntax-table idlwave-find-symbol-syntax-table)
1541 ,@body)
1542 (set-syntax-table saved-syntax))))
1544 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1545 ; "Execute BODY with a different syntax table."
1546 ; `(let ((saved-syntax (syntax-table)))
1547 ; (unwind-protect
1548 ; (progn
1549 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1550 ; ,@body)
1551 ; (set-syntax-table saved-syntax))))
1553 (defun idlwave-action-and-binding (key cmd &optional select)
1554 "KEY and CMD are made into a key binding and an indent action.
1555 KEY is a string - same as for the `define-key' function. CMD is a
1556 function of no arguments or a list to be evaluated. CMD is bound to
1557 KEY in `idlwave-mode-map' by defining an anonymous function calling
1558 `self-insert-command' followed by CMD. If KEY contains more than one
1559 character a binding will only be set if SELECT is 'both.
1561 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1562 replacing any previous value for KEY. If a binding is not set then it
1563 will instead be placed in `idlwave-indent-action-table'.
1565 If the optional argument SELECT is nil then an action and binding are
1566 created. If SELECT is 'noaction, then a binding is always set and no
1567 action is created. If SELECT is 'both then an action and binding
1568 will both be created even if KEY contains more than one character.
1569 Otherwise, if SELECT is non-nil then only an action is created.
1571 Some examples:
1572 No spaces before and 1 after a comma
1573 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1574 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1575 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1576 Capitalize system variables - action only
1577 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1578 (if (not (equal select 'noaction))
1579 ;; Add action
1580 (let* ((table (if select 'idlwave-indent-action-table
1581 'idlwave-indent-expand-table))
1582 (table-key (regexp-quote key))
1583 (cell (assoc table-key (eval table))))
1584 (if cell
1585 ;; Replace action command
1586 (setcdr cell cmd)
1587 ;; New action
1588 (set table (append (eval table) (list (cons table-key cmd)))))))
1589 ;; Make key binding for action
1590 (if (or (and (null select) (= (length key) 1))
1591 (equal select 'noaction)
1592 (equal select 'both))
1593 (define-key idlwave-mode-map key
1594 `(lambda ()
1595 (interactive)
1596 (self-insert-command 1)
1597 ,(if (listp cmd) cmd (list cmd))))))
1599 ;; Set action and key bindings.
1600 ;; See description of the function `idlwave-action-and-binding'.
1601 ;; Automatically add spaces for the following characters
1603 ;; Actions for & are complicated by &&
1604 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1606 ;; Automatically add spaces to equal sign if not keyword. This needs
1607 ;; to go ahead of > and <, so >= and <= will be treated correctly
1608 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1610 ;; Actions for > and < are complicated by >=, <=, and ->...
1611 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1612 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1614 (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1618 ;;; Abbrev Section
1620 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1621 ;;; space is inserted (this is the space typed by the user to expanded
1622 ;;; the abbrev).
1624 (defvar idlwave-mode-abbrev-table nil
1625 "Abbreviation table used for IDLWAVE mode.")
1626 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1628 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1629 "Define-abbrev with backward compatibility.
1631 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1632 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1633 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1634 (args (list (or table idlwave-mode-abbrev-table)
1635 (if noprefix name (concat idlwave-abbrev-start-char name))
1636 expansion
1637 hook)))
1638 (condition-case nil
1639 (apply 'define-abbrev (append args '(0 t)))
1640 (error (apply 'define-abbrev args)))))
1642 (condition-case nil
1643 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1644 "w" idlwave-mode-syntax-table)
1645 (error nil))
1648 ;; Templates
1650 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1651 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1652 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1653 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1654 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1655 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1656 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1657 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1658 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1660 ;; Keywords, system functions, conversion routines
1662 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1663 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1664 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1665 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1666 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1667 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1668 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1669 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1672 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1673 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1674 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1675 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1676 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1677 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1678 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1679 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1680 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1681 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1683 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1684 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1685 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1686 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1687 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1688 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1689 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1690 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1693 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1698 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1699 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1700 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1701 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1702 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1704 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1705 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1706 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1707 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1708 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1709 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1710 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1711 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1712 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1713 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1714 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1715 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1716 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1717 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1719 ;; This section is reserved words only. (From IDL user manual)
1721 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1722 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1723 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1724 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1725 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1726 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1727 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1728 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1729 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1730 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1731 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1732 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1733 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1734 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1735 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1736 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1737 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1739 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1740 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1741 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1742 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1743 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1744 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1745 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1746 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1761 (defvar imenu-create-index-function)
1762 (defvar extract-index-name-function)
1763 (defvar prev-index-position-function)
1764 (defvar imenu-extract-index-name-function)
1765 (defvar imenu-prev-index-position-function)
1766 ;; defined later - so just make the compiler hush
1767 (defvar idlwave-mode-menu)
1768 (defvar idlwave-mode-debug-menu)
1770 ;;;###autoload
1771 (define-derived-mode idlwave-mode prog-mode "IDLWAVE"
1772 "Major mode for editing IDL source files (version 6.1_em22).
1774 The main features of this mode are
1776 1. Indentation and Formatting
1777 --------------------------
1778 Like other Emacs programming modes, C-j inserts a newline and indents.
1779 TAB is used for explicit indentation of the current line.
1781 To start a continuation line, use \\[idlwave-split-line]. This
1782 function can also be used in the middle of a line to split the line
1783 at that point. When used inside a long constant string, the string
1784 is split at that point with the `+' concatenation operator.
1786 Comments are indented as follows:
1788 `;;;' Indentation remains unchanged.
1789 `;;' Indent like the surrounding code
1790 `;' Indent to a minimum column.
1792 The indentation of comments starting in column 0 is never changed.
1794 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1795 comment. The indentation of the second line of the paragraph
1796 relative to the first will be retained. Use
1797 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1798 comments. When the variable `idlwave-fill-comment-line-only' is
1799 nil, code can also be auto-filled and auto-indented.
1801 To convert pre-existing IDL code to your formatting style, mark the
1802 entire buffer with \\[mark-whole-buffer] and execute
1803 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1804 again followed by \\[indent-region] (`indent-region').
1806 2. Routine Info
1807 ------------
1808 IDLWAVE displays information about the calling sequence and the
1809 accepted keyword parameters of a procedure or function with
1810 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1811 source file of a module. These commands know about system
1812 routines, all routines in idlwave-mode buffers and (when the
1813 idlwave-shell is active) about all modules currently compiled under
1814 this shell. It also makes use of pre-compiled or custom-scanned
1815 user and library catalogs many popular libraries ship with by
1816 default. Use \\[idlwave-update-routine-info] to update this
1817 information, which is also used for completion (see item 4).
1819 3. Online IDL Help
1820 ---------------
1822 \\[idlwave-context-help] displays the IDL documentation relevant
1823 for the system variable, keyword, or routines at point. A single
1824 key stroke gets you directly to the right place in the docs. See
1825 the manual to configure where and how the HTML help is displayed.
1827 4. Completion
1828 ----------
1829 \\[idlwave-complete] completes the names of procedures, functions
1830 class names, keyword parameters, system variables and tags, class
1831 tags, structure tags, filenames and much more. It is context
1832 sensitive and figures out what is expected at point. Lower case
1833 strings are completed in lower case, other strings in mixed or
1834 upper case.
1836 5. Code Templates and Abbreviations
1837 --------------------------------
1838 Many Abbreviations are predefined to expand to code fragments and templates.
1839 The abbreviations start generally with a `\\`. Some examples:
1841 \\pr PROCEDURE template
1842 \\fu FUNCTION template
1843 \\c CASE statement template
1844 \\sw SWITCH statement template
1845 \\f FOR loop template
1846 \\r REPEAT Loop template
1847 \\w WHILE loop template
1848 \\i IF statement template
1849 \\elif IF-ELSE statement template
1850 \\b BEGIN
1852 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1853 have direct keybindings - see the list of keybindings below.
1855 \\[idlwave-doc-header] inserts a documentation header at the
1856 beginning of the current program unit (pro, function or main).
1857 Change log entries can be added to the current program unit with
1858 \\[idlwave-doc-modification].
1860 6. Automatic Case Conversion
1861 -------------------------
1862 The case of reserved words and some abbrevs is controlled by
1863 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1865 7. Automatic END completion
1866 ------------------------
1867 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1868 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1870 8. Hooks
1871 -----
1872 Loading idlwave.el runs `idlwave-load-hook'.
1873 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1875 9. Documentation and Customization
1876 -------------------------------
1877 Info documentation for this package is available. Use
1878 \\[idlwave-info] to display (complain to your sysadmin if that does
1879 not work). For Postscript, PDF, and HTML versions of the
1880 documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
1881 IDLWAVE has customize support - see the group `idlwave'.
1883 10.Keybindings
1884 -----------
1885 Here is a list of all keybindings of this mode.
1886 If some of the key bindings below show with ??, use \\[describe-key]
1887 followed by the key sequence to see what the key sequence does.
1889 \\{idlwave-mode-map}"
1890 :abbrev-table idlwave-mode-abbrev-table
1891 (if idlwave-startup-message
1892 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1893 (setq idlwave-startup-message nil)
1895 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1897 (set (make-local-variable idlwave-comment-indent-function)
1898 #'idlwave-comment-hook)
1900 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1901 (set (make-local-variable 'comment-start) ";")
1902 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
1903 (set (make-local-variable 'abbrev-all-caps) t)
1904 (set (make-local-variable 'indent-tabs-mode) nil)
1905 (set (make-local-variable 'completion-ignore-case) t)
1907 (when (featurep 'easymenu)
1908 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1909 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1911 (setq abbrev-mode t)
1913 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1914 (setq comment-end "")
1915 (set (make-local-variable 'comment-multi-line) nil)
1916 (set (make-local-variable 'paragraph-separate)
1917 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1918 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1919 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1920 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1922 ;; ChangeLog
1923 (set (make-local-variable 'add-log-current-defun-function)
1924 'idlwave-current-routine-fullname)
1926 ;; Set tag table list to use IDLTAGS as file name.
1927 (if (boundp 'tag-table-alist)
1928 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1930 ;; Font-lock additions
1931 ;; Following line is for Emacs - XEmacs uses the corresponding property
1932 ;; on the `idlwave-mode' symbol.
1933 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1934 (set (make-local-variable 'font-lock-mark-block-function)
1935 'idlwave-mark-subprogram)
1936 (set (make-local-variable 'font-lock-fontify-region-function)
1937 'idlwave-font-lock-fontify-region)
1939 ;; Imenu setup
1940 (set (make-local-variable 'imenu-create-index-function)
1941 'imenu-default-create-index-function)
1942 (set (make-local-variable 'imenu-extract-index-name-function)
1943 'idlwave-unit-name)
1944 (set (make-local-variable 'imenu-prev-index-position-function)
1945 'idlwave-prev-index-position)
1947 ;; HideShow setup
1948 (add-to-list 'hs-special-modes-alist
1949 (list 'idlwave-mode
1950 idlwave-begin-block-reg
1951 idlwave-end-block-reg
1953 'idlwave-forward-block nil))
1955 ;; Make a local post-command-hook and add our hook to it
1956 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1957 ;; (make-local-hook 'post-command-hook)
1958 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1960 ;; Make local hooks for buffer updates
1961 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1962 ;; (make-local-hook 'kill-buffer-hook)
1963 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1964 ;; (make-local-hook 'after-save-hook)
1965 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1966 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1968 ;; Setup directories and file, if necessary
1969 (idlwave-setup)
1971 ;; Update the routine info with info about current buffer?
1972 (idlwave-new-buffer-update)
1974 ;; Check help location
1975 (idlwave-help-check-locations))
1977 (defvar idlwave-setup-done nil)
1978 (defun idlwave-setup ()
1979 (unless idlwave-setup-done
1980 (if (not (file-directory-p idlwave-config-directory))
1981 (make-directory idlwave-config-directory))
1982 (setq
1983 idlwave-user-catalog-file (expand-file-name
1984 idlwave-user-catalog-file
1985 idlwave-config-directory)
1986 idlwave-xml-system-rinfo-converted-file
1987 (expand-file-name
1988 idlwave-xml-system-rinfo-converted-file
1989 idlwave-config-directory)
1990 idlwave-path-file (expand-file-name
1991 idlwave-path-file
1992 idlwave-config-directory))
1993 (idlwave-read-paths) ; we may need these early
1994 (setq idlwave-setup-done t)))
1996 (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
1997 "Fontify continuation lines correctly."
1998 (let (pos)
1999 (save-excursion
2000 (goto-char beg)
2001 (forward-line -1)
2002 (when (setq pos (idlwave-is-continuation-line))
2003 (goto-char pos)
2004 (idlwave-beginning-of-statement)
2005 (setq beg (point)))))
2006 (font-lock-default-fontify-region beg end verbose))
2009 ;; Code Formatting ----------------------------------------------------
2012 (defun idlwave-hard-tab ()
2013 "Insert TAB in buffer in current position."
2014 (interactive)
2015 (insert "\t"))
2017 ;;; This stuff is experimental
2019 (defvar idlwave-command-hook nil
2020 "If non-nil, a list that can be evaluated using `eval'.
2021 It is evaluated in the lisp function `idlwave-command-hook' which is
2022 placed in `post-command-hook'.")
2024 (defun idlwave-command-hook ()
2025 "Command run after every command.
2026 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2027 sets the variable to zero afterwards."
2028 (and idlwave-command-hook
2029 (listp idlwave-command-hook)
2030 (condition-case nil
2031 (eval idlwave-command-hook)
2032 (error nil)))
2033 (setq idlwave-command-hook nil))
2035 ;;; End experiment
2037 ;; It would be better to use expand.el for better abbrev handling and
2038 ;; versatility.
2040 (defun idlwave-check-abbrev (arg &optional reserved)
2041 "Reverse abbrev expansion if in comment or string.
2042 Argument ARG is the number of characters to move point
2043 backward if `idlwave-abbrev-move' is non-nil.
2044 If optional argument RESERVED is non-nil then the expansion
2045 consists of reserved words, which will be capitalized if
2046 `idlwave-reserved-word-upcase' is non-nil.
2047 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2048 is non-nil, unless its value is \`down in which case the abbrev will be
2049 made into all lowercase.
2050 Returns non-nil if abbrev is left expanded."
2051 (if (idlwave-quoted)
2052 (progn (unexpand-abbrev)
2053 nil)
2054 (if (and reserved idlwave-reserved-word-upcase)
2055 (upcase-region last-abbrev-location (point))
2056 (cond
2057 ((equal idlwave-abbrev-change-case 'down)
2058 (downcase-region last-abbrev-location (point)))
2059 (idlwave-abbrev-change-case
2060 (upcase-region last-abbrev-location (point)))))
2061 (if (and idlwave-abbrev-move (> arg 0))
2062 (if (boundp 'post-command-hook)
2063 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2064 (backward-char arg)))
2067 (defun idlwave-in-comment ()
2068 "Return t if point is inside a comment, nil otherwise."
2069 (save-excursion
2070 (let ((here (point)))
2071 (and (idlwave-goto-comment) (> here (point))))))
2073 (defun idlwave-goto-comment ()
2074 "Move to start of comment delimiter on current line.
2075 Moves to end of line if there is no comment delimiter.
2076 Ignores comment delimiters in strings.
2077 Returns point if comment found and nil otherwise."
2078 (let ((eos (point-at-eol))
2079 (data (match-data))
2080 found)
2081 ;; Look for first comment delimiter not in a string
2082 (beginning-of-line)
2083 (setq found (search-forward comment-start eos 'lim))
2084 (while (and found (idlwave-in-quote))
2085 (setq found (search-forward comment-start eos 'lim)))
2086 (store-match-data data)
2087 (and found (not (idlwave-in-quote))
2088 (progn
2089 (backward-char 1)
2090 (point)))))
2092 (defun idlwave-region-active-p ()
2093 "Should we operate on an active region?"
2094 (if (fboundp 'use-region-p)
2095 (use-region-p)
2096 (region-active-p)))
2098 (defun idlwave-show-matching-quote ()
2099 "Insert quote and show matching quote if this is end of a string."
2100 (interactive)
2101 (let ((bq (idlwave-in-quote))
2102 (inq last-command-event))
2103 (if (and bq (not (idlwave-in-comment)))
2104 (let ((delim (char-after bq)))
2105 (insert inq)
2106 (if (eq inq delim)
2107 (save-excursion
2108 (goto-char bq)
2109 (sit-for 1))))
2110 ;; Not the end of a string
2111 (insert inq))))
2113 (defun idlwave-show-begin-check ()
2114 "Ensure that the previous word was a token before `idlwave-show-begin'.
2115 An END token must be preceded by whitespace."
2116 (if (not (idlwave-quoted))
2118 (save-excursion
2119 (backward-word 1)
2120 (backward-char 1)
2121 (looking-at "[ \t\n\f]"))
2122 (idlwave-show-begin))))
2124 (defun idlwave-show-begin ()
2125 "Find the start of current block and blinks to it for a second.
2126 Also checks if the correct END statement has been used."
2127 ;; All end statements are reserved words
2128 ;; Re-indent end line
2129 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2130 ;;(backward-char 1)
2131 (let* ((pos (point-marker))
2132 (last-abbrev-marker (copy-marker last-abbrev-location))
2133 (eol-pos (point-at-eol))
2134 begin-pos end-pos end end1 )
2135 (if idlwave-reindent-end (idlwave-indent-line))
2136 (setq last-abbrev-location (marker-position last-abbrev-marker))
2137 (when (and (idlwave-check-abbrev 0 t)
2138 idlwave-show-block)
2139 (save-excursion
2140 ;; Move inside current block
2141 (goto-char last-abbrev-marker)
2142 (idlwave-block-jump-out -1 'nomark)
2143 (setq begin-pos (point))
2144 (idlwave-block-jump-out 1 'nomark)
2145 (setq end-pos (point))
2146 (if (> end-pos eol-pos)
2147 (setq end-pos pos))
2148 (goto-char end-pos)
2149 (setq end (buffer-substring
2150 (progn
2151 (skip-chars-backward "a-zA-Z")
2152 (point))
2153 end-pos))
2154 (goto-char begin-pos)
2155 (when (setq end1 (cdr (idlwave-block-master)))
2156 (cond
2157 ((null end1)) ; no-operation
2158 ((string= (downcase end) (downcase end1))
2159 (sit-for 1))
2160 ((string= (downcase end) "end")
2161 ;; A generic end
2162 (if idlwave-expand-generic-end
2163 (save-excursion
2164 (goto-char pos)
2165 (backward-char 3)
2166 (insert (if (string= end "END") (upcase end1) end1))
2167 (delete-char 3)))
2168 (sit-for 1))
2170 (beep)
2171 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2172 end1 end)
2173 (sit-for 1))))))))
2174 ;;(delete-char 1))
2176 (defun idlwave-block-master ()
2177 (let ((case-fold-search t))
2178 (save-excursion
2179 (cond
2180 ((looking-at "pro\\|case\\|switch\\|function\\>")
2181 (assoc (downcase (match-string 0)) idlwave-block-matches))
2182 ((looking-at "begin\\>")
2183 (let ((limit (save-excursion
2184 (idlwave-beginning-of-statement)
2185 (point))))
2186 (cond
2187 ((re-search-backward ":[ \t]*\\=" limit t)
2188 ;; seems to be a case thing
2189 '("begin" . "end"))
2190 ((re-search-backward idlwave-block-match-regexp limit t)
2191 (assoc (downcase (match-string 1))
2192 idlwave-block-matches))
2194 ;; Just a normal block
2195 '("begin" . "end")))))
2196 (t nil)))))
2198 (defun idlwave-close-block ()
2199 "Terminate the current block with the correct END statement."
2200 (interactive)
2201 ;; Start new line if we are not in a new line
2202 (unless (save-excursion
2203 (skip-chars-backward " \t")
2204 (bolp))
2205 (let ((idlwave-show-block nil))
2206 (newline-and-indent)))
2207 (let ((last-abbrev-location (point))) ; for upcasing
2208 (insert "end")
2209 (idlwave-show-begin)))
2211 (defun idlwave-custom-ampersand-surround (&optional is-action)
2212 "Surround &, leaving room for && (which surround as well)."
2213 (let* ((prev-char (char-after (- (point) 2)))
2214 (next-char (char-after (point)))
2215 (amp-left (eq prev-char ?&))
2216 (amp-right (eq next-char ?&))
2217 (len (if amp-left 2 1)))
2218 (unless amp-right ;no need to do it twice, amp-left will catch it.
2219 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2221 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2222 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2223 (let* ((prev-char (char-after (- (point) 2)))
2224 (next-char (char-after (point)))
2225 (method-invoke (and gtr (eq prev-char ?-)))
2226 (len (if method-invoke 2 1)))
2227 (unless (eq next-char ?=)
2228 ;; Key binding: pad only on left, to save for possible >=/<=
2229 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2231 (defun idlwave-surround (&optional before after length is-action)
2232 "Surround the LENGTH characters before point with blanks.
2233 LENGTH defaults to 1.
2234 Optional arguments BEFORE and AFTER affect the behavior before and
2235 after the characters (see also description of `idlwave-make-space'):
2237 nil do nothing
2238 0 force no spaces
2239 integer > 0 force exactly n spaces
2240 integer < 0 at least |n| spaces
2242 The function does nothing if any of the following conditions is true:
2243 - `idlwave-surround-by-blank' is nil
2244 - the character before point is inside a string or comment"
2245 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2246 (let ((length (or length 1))) ; establish a default for LENGTH
2247 (backward-char length)
2248 (save-restriction
2249 (let ((here (point)))
2250 (skip-chars-backward " \t")
2251 (if (bolp)
2252 ;; avoid clobbering indent
2253 (progn
2254 (move-to-column (idlwave-calculate-indent))
2255 (if (<= (point) here)
2256 (narrow-to-region (point) here))
2257 (goto-char here)))
2258 (idlwave-make-space before))
2259 (skip-chars-forward " \t"))
2260 (forward-char length)
2261 (idlwave-make-space after)
2262 ;; Check to see if the line should auto wrap
2263 (if (and (equal (char-after (1- (point))) ?\ )
2264 (> (current-column) fill-column))
2265 (funcall auto-fill-function)))))
2267 (defun idlwave-make-space (n)
2268 "Make space at point.
2269 The space affected is all the spaces and tabs around point.
2270 If n is non-nil then point is left abs(n) spaces from the beginning of
2271 the contiguous space.
2272 The amount of space at point is determined by N.
2273 If the value of N is:
2274 nil - do nothing.
2275 > 0 - exactly N spaces.
2276 < 0 - a minimum of -N spaces, i.e., do not change if there are
2277 already -N spaces.
2278 0 - no spaces (i.e. remove any existing space)."
2279 (if (integerp n)
2280 (let
2281 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2282 (left (point))
2283 (end-col (progn (skip-chars-forward " \t") (current-column))))
2284 (delete-horizontal-space)
2285 (cond
2286 ((> n 0)
2287 (idlwave-indent-to (+ start-col n))
2288 (goto-char (+ left n)))
2289 ((< n 0)
2290 (idlwave-indent-to end-col (- n))
2291 (goto-char (- left n)))
2292 ;; n = 0, done
2293 ))))
2295 (defun idlwave-newline ()
2296 "Insert a newline and indent the current and previous line."
2297 (interactive)
2299 ;; Handle unterminated single and double quotes
2300 ;; If not in a comment and in a string then insertion of a newline
2301 ;; will mean unbalanced quotes.
2303 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2304 (progn (beep)
2305 (message "Warning: unbalanced quotes?")))
2306 (newline)
2308 ;; The current line is being split, the cursor should be at the
2309 ;; beginning of the new line skipping the leading indentation.
2311 ;; The reason we insert the new line before indenting is that the
2312 ;; indenting could be confused by keywords (e.g. END) on the line
2313 ;; after the split point. This prevents us from just using
2314 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2316 (beginning-of-line 0)
2317 (idlwave-indent-line)
2318 (forward-line)
2319 (idlwave-indent-line))
2322 ;; Use global variable 'comment-column' to set parallel comment
2324 ;; Modeled on lisp.el
2325 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2326 (defun idlwave-comment-hook ()
2327 "Compute indent for the beginning of the IDL comment delimiter."
2328 (if (or (looking-at idlwave-no-change-comment)
2329 (looking-at (or idlwave-begin-line-comment "^;")))
2330 (current-column)
2331 (if (looking-at idlwave-code-comment)
2332 (if (save-excursion (skip-chars-backward " \t") (bolp))
2333 ;; On line by itself, indent as code
2334 (let ((tem (idlwave-calculate-indent)))
2335 (if (listp tem) (car tem) tem))
2336 ;; after code - do not change
2337 (current-column))
2338 (skip-chars-backward " \t")
2339 (max (if (bolp) 0 (1+ (current-column)))
2340 comment-column))))
2342 (defun idlwave-split-line ()
2343 "Continue line by breaking line at point and indent the lines.
2344 For a code line insert continuation marker. If the line is a line comment
2345 then the new line will contain a comment with the same indentation.
2346 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2347 non-nil."
2348 (interactive)
2349 ;; Expand abbreviation, just like normal RET would.
2350 (and abbrev-mode (expand-abbrev))
2351 (let (beg)
2352 (if (not (idlwave-in-comment))
2353 ;; For code line add continuation.
2354 ;; Check if splitting a string.
2355 (progn
2356 (if (setq beg (idlwave-in-quote))
2357 (if idlwave-split-line-string
2358 ;; Split the string.
2359 (progn (insert (setq beg (char-after beg)) " + "
2360 idlwave-continuation-char beg)
2361 (backward-char 1)
2362 (newline-and-indent)
2363 (forward-char 1))
2364 ;; Do not split the string.
2365 (beep)
2366 (message "Warning: continuation inside string!!")
2367 (insert " " idlwave-continuation-char))
2368 ;; Not splitting a string.
2369 (if (not (member (char-before) '(?\ ?\t)))
2370 (insert " "))
2371 (insert idlwave-continuation-char)
2372 (newline-and-indent)))
2373 (indent-new-comment-line))
2374 ;; Indent previous line
2375 (setq beg (- (point-max) (point)))
2376 (forward-line -1)
2377 (idlwave-indent-line)
2378 (goto-char (- (point-max) beg))
2379 ;; Reindent new line
2380 (idlwave-indent-line)))
2382 (defun idlwave-beginning-of-subprogram (&optional nomark)
2383 "Move point to the beginning of the current program unit.
2384 If NOMARK is non-nil, do not push mark."
2385 (interactive)
2386 (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
2388 (defun idlwave-end-of-subprogram (&optional nomark)
2389 "Move point to the start of the next program unit.
2390 If NOMARK is non-nil, do not push mark."
2391 (interactive)
2392 (idlwave-end-of-statement)
2393 (idlwave-find-key idlwave-end-unit-reg 1 nomark))
2395 (defun idlwave-mark-statement ()
2396 "Mark current IDL statement."
2397 (interactive)
2398 (idlwave-end-of-statement)
2399 (let ((end (point)))
2400 (idlwave-beginning-of-statement)
2401 (push-mark end nil t)))
2403 (defun idlwave-mark-block ()
2404 "Mark containing block."
2405 (interactive)
2406 (idlwave-end-of-statement)
2407 (idlwave-backward-up-block -1)
2408 (idlwave-end-of-statement)
2409 (let ((end (point)))
2410 (idlwave-backward-block)
2411 (idlwave-beginning-of-statement)
2412 (push-mark end nil t)))
2415 (defun idlwave-mark-subprogram ()
2416 "Put mark at beginning of program, point at end.
2417 The marks are pushed."
2418 (interactive)
2419 (idlwave-end-of-statement)
2420 (idlwave-beginning-of-subprogram)
2421 (let ((beg (point)))
2422 (idlwave-forward-block)
2423 (push-mark beg nil t))
2424 (exchange-point-and-mark))
2426 (defun idlwave-backward-up-block (&optional arg)
2427 "Move to beginning of enclosing block if prefix ARG >= 0.
2428 If prefix ARG < 0 then move forward to enclosing block end."
2429 (interactive "p")
2430 (idlwave-block-jump-out (- arg) 'nomark))
2432 (defun idlwave-beginning-of-block ()
2433 "Go to the beginning of the current block."
2434 (interactive)
2435 (idlwave-block-jump-out -1 'nomark)
2436 (forward-word 1))
2438 (defun idlwave-end-of-block ()
2439 "Go to the beginning of the current block."
2440 (interactive)
2441 (idlwave-block-jump-out 1 'nomark)
2442 (backward-word 1))
2444 (defun idlwave-forward-block (&optional arg)
2445 "Move across next nested block."
2446 (interactive)
2447 (let ((arg (or arg 1)))
2448 (if (idlwave-down-block arg)
2449 (idlwave-block-jump-out arg 'nomark))))
2451 (defun idlwave-backward-block ()
2452 "Move backward across previous nested block."
2453 (interactive)
2454 (if (idlwave-down-block -1)
2455 (idlwave-block-jump-out -1 'nomark)))
2457 (defun idlwave-down-block (&optional arg)
2458 "Go down a block.
2459 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2460 Returns non-nil if successful."
2461 (interactive "p")
2462 (let (status)
2463 (if (< arg 0)
2464 ;; Backward
2465 (let ((eos (save-excursion
2466 (idlwave-block-jump-out -1 'nomark)
2467 (point))))
2468 (if (setq status (idlwave-find-key
2469 idlwave-end-block-reg -1 'nomark eos))
2470 (idlwave-beginning-of-statement)
2471 (message "No nested block before beginning of containing block.")))
2472 ;; Forward
2473 (let ((eos (save-excursion
2474 (idlwave-block-jump-out 1 'nomark)
2475 (point))))
2476 (if (setq status (idlwave-find-key
2477 idlwave-begin-block-reg 1 'nomark eos))
2478 (idlwave-end-of-statement)
2479 (message "No nested block before end of containing block."))))
2480 status))
2482 (defun idlwave-mark-doclib ()
2483 "Put point at beginning of doc library header, mark at end.
2484 The marks are pushed."
2485 (interactive)
2486 (let (beg
2487 (here (point)))
2488 (goto-char (point-max))
2489 (if (re-search-backward idlwave-doclib-start nil t)
2490 (progn
2491 (setq beg (progn (beginning-of-line) (point)))
2492 (if (re-search-forward idlwave-doclib-end nil t)
2493 (progn
2494 (forward-line 1)
2495 (push-mark beg nil t)
2496 (message "Could not find end of doc library header.")))
2497 (message "Could not find doc library header start.")
2498 (goto-char here)))))
2500 (defun idlwave-current-routine-fullname ()
2501 (let ((name (idlwave-current-routine)))
2502 (idlwave-make-full-name (nth 2 name) (car name))))
2504 (defun idlwave-current-routine ()
2505 "Return (NAME TYPE CLASS) of current routine."
2506 (idlwave-routines)
2507 (save-excursion
2508 (idlwave-beginning-of-subprogram 'nomark)
2509 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2510 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2511 'pro 'function))
2512 (class (idlwave-sintern-class (match-string 3)))
2513 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2514 (list name type class)))))
2516 (defvar idlwave-shell-prompt-pattern)
2517 (defun idlwave-beginning-of-statement ()
2518 "Move to beginning of the current statement.
2519 Skips back past statement continuations.
2520 Point is placed at the beginning of the line whether or not this is an
2521 actual statement."
2522 (interactive)
2523 (cond
2524 ((derived-mode-p 'idlwave-shell-mode)
2525 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2526 (goto-char (match-end 0))))
2528 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2529 (idlwave-previous-statement)
2530 (beginning-of-line)))))
2532 (defun idlwave-previous-statement ()
2533 "Move point to beginning of the previous statement.
2534 Returns t if the current line before moving is the beginning of
2535 the first non-comment statement in the file, and nil otherwise."
2536 (interactive)
2537 (let (first-statement)
2538 (if (not (= (forward-line -1) 0))
2539 ;; first line in file
2541 ;; skip blank lines, label lines, include lines and line comments
2542 (while (and
2543 ;; The current statement is the first statement until we
2544 ;; reach another statement.
2545 (setq first-statement
2547 (looking-at idlwave-comment-line-start-skip)
2548 (looking-at "[ \t]*$")
2549 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2550 (looking-at "^@")))
2551 (= (forward-line -1) 0)))
2552 ;; skip continuation lines
2553 (while (and
2554 (save-excursion
2555 (forward-line -1)
2556 (idlwave-is-continuation-line))
2557 (= (forward-line -1) 0)))
2558 first-statement)))
2560 (defun idlwave-end-of-statement ()
2561 "Move point to the end of the current IDL statement.
2562 If not in a statement just moves to end of line. Returns position."
2563 (interactive)
2564 (while (and (idlwave-is-continuation-line)
2565 (= (forward-line 1) 0))
2566 (while (and (idlwave-is-comment-or-empty-line)
2567 (= (forward-line 1) 0))))
2568 (end-of-line)
2569 (point))
2571 (defun idlwave-end-of-statement0 ()
2572 "Move point to the end of the current IDL statement.
2573 If not in a statement just moves to end of line. Returns position."
2574 (interactive)
2575 (while (and (idlwave-is-continuation-line)
2576 (= (forward-line 1) 0)))
2577 (end-of-line)
2578 (point))
2580 (defun idlwave-next-statement ()
2581 "Move point to beginning of the next IDL statement.
2582 Returns t if that statement is the last non-comment IDL statement
2583 in the file, and nil otherwise."
2584 (interactive)
2585 (let (last-statement)
2586 (idlwave-end-of-statement)
2587 ;; skip blank lines, label lines, include lines and line comments
2588 (while (and (= (forward-line 1) 0)
2589 ;; The current statement is the last statement until
2590 ;; we reach a new statement.
2591 (setq last-statement
2593 (looking-at idlwave-comment-line-start-skip)
2594 (looking-at "[ \t]*$")
2595 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2596 (looking-at "^@")))))
2597 last-statement))
2599 (defun idlwave-skip-multi-commands (&optional lim)
2600 "Skip past multiple commands on a line (with `&')."
2601 (let ((save-point (point)))
2602 (when (re-search-forward ".*&" lim t)
2603 (goto-char (match-end 0))
2604 (if (idlwave-quoted)
2605 (goto-char save-point)
2606 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2607 (point)))
2609 (defun idlwave-skip-label-or-case ()
2610 "Skip label or case statement element.
2611 Returns position after label.
2612 If there is no label point is not moved and nil is returned."
2613 ;; Case expressions and labels are terminated by a colon.
2614 ;; So we find the first colon in the line and make sure
2615 ;; - no `?' is before it (might be a ? b : c)
2616 ;; - it is not in a comment
2617 ;; - not in a string constant
2618 ;; - not in parenthesis (like a[0:3])
2619 ;; - not followed by another ":" in explicit class, ala a->b::c
2620 ;; As many in this mode, this function is heuristic and not an exact
2621 ;; parser.
2622 (let* ((start (point))
2623 (eos (save-excursion (idlwave-end-of-statement) (point)))
2624 (end (idlwave-find-key ":" 1 'nomark eos)))
2625 (if (and end
2626 (= (nth 0 (parse-partial-sexp start end)) 0)
2627 (not (string-match "\\?" (buffer-substring start end)))
2628 (not (string-match "^::" (buffer-substring end eos))))
2629 (progn
2630 (forward-char)
2631 (point))
2632 (goto-char start)
2633 nil)))
2635 (defun idlwave-start-of-substatement (&optional pre)
2636 "Move to start of next IDL substatement after point.
2637 Uses the type of the current IDL statement to determine if the next
2638 statement is on a new line or is a subpart of the current statement.
2639 Returns point at start of substatement modulo whitespace.
2640 If optional argument is non-nil move to beginning of current
2641 substatement."
2642 (let ((orig (point))
2643 (eos (idlwave-end-of-statement))
2644 (ifnest 0)
2645 st nst last)
2646 (idlwave-beginning-of-statement)
2647 (idlwave-skip-label-or-case)
2648 (if (< (point) orig)
2649 (idlwave-skip-multi-commands orig))
2650 (setq last (point))
2651 ;; Continue looking for substatements until we are past orig
2652 (while (and (<= (point) orig) (not (eobp)))
2653 (setq last (point))
2654 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2655 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2656 (cond ((and nst
2657 (idlwave-find-key nst 1 'nomark eos))
2658 (goto-char (match-end 0)))
2659 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2660 (setq ifnest (1- ifnest))
2661 (goto-char (match-end 0)))
2662 (t (setq ifnest 0)
2663 (idlwave-next-statement))))
2664 (if pre (goto-char last))
2665 ;; If a continuation line starts here, move to next line
2666 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2667 (beginning-of-line 2))
2668 (point)))
2670 (defun idlwave-statement-type ()
2671 "Return the type of the current IDL statement.
2672 Uses `idlwave-statement-match' to return a cons of (type . point) with
2673 point the ending position where the type was determined. Type is the
2674 association from `idlwave-statement-match', i.e. the cons cell from the
2675 list not just the type symbol. Returns nil if not an identifiable
2676 statement."
2677 (save-excursion
2678 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2679 ;; and possibly comments
2680 (while (looking-at "[ \t]*\\$")
2681 (forward-line 1))
2682 (skip-chars-forward " \t")
2683 (let ((st idlwave-statement-match)
2684 (case-fold-search t))
2685 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2686 (setq st (cdr st))))
2687 (if st
2688 (append st (match-end 0))))))
2690 (defun idlwave-expand-equal (&optional before after is-action)
2691 "Pad '=' with spaces.
2692 Two cases: Assignment statement, and keyword assignment.
2693 Which case is determined using `idlwave-start-of-substatement' and
2694 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2695 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2696 is treated just like assignment statements. When nil, spaces are
2697 removed for keyword assignment. Any other value keeps the current space
2698 around the `='. Limits in for loops are treated as keyword assignment.
2700 Starting with IDL 6.0, a number of op= assignments are available.
2701 Since ambiguities of the form:
2703 r and= b
2704 rand= b
2706 can occur, alphanumeric operator assignment will never be pre-padded,
2707 only post-padded. You must use a space before these to disambiguate
2708 \(not just for padding, but for proper parsing by IDL too!). Other
2709 operators, such as ##=, ^=, etc., will be pre-padded.
2711 IS-ACTION is ignored.
2713 See `idlwave-surround'."
2714 (if idlwave-surround-by-blank
2715 (let
2716 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2717 (an-ops
2718 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2719 (len 1))
2721 (save-excursion
2722 (let ((case-fold-search t))
2723 (backward-char)
2724 (if (or
2725 (re-search-backward non-an-ops nil t)
2726 ;; Why doesn't ##? work for both?
2727 (re-search-backward "\\(#\\)\\=" nil t))
2728 (setq len (1+ (length (match-string 1))))
2729 (when (re-search-backward an-ops nil t)
2730 ;(setq begin nil) ; won't modify begin
2731 (setq len (1+ (length (match-string 1))))))))
2733 (if (eq t idlwave-pad-keyword)
2734 ;; Everything gets padded equally
2735 (idlwave-surround before after len)
2736 ;; Treating keywords/for variables specially...
2737 (let ((st (save-excursion ; To catch "for" variables
2738 (idlwave-start-of-substatement t)
2739 (idlwave-statement-type)))
2740 (what (save-excursion ; To catch keywords
2741 (skip-chars-backward "= \t")
2742 (nth 2 (idlwave-where)))))
2743 (cond ((or (memq what '(function-keyword procedure-keyword))
2744 (memq (caar st) '(for pdef)))
2745 (cond
2746 ((null idlwave-pad-keyword)
2747 (idlwave-surround 0 0)
2748 ) ; remove space
2749 (t))) ; leave any spaces alone
2750 (t (idlwave-surround before after len))))))))
2753 (defun idlwave-indent-and-action (&optional arg)
2754 "Call `idlwave-indent-line' and do expand actions.
2755 With prefix ARG non-nil, indent the entire sub-statement."
2756 (interactive "p")
2757 (save-excursion
2758 (if (and idlwave-expand-generic-end
2759 (re-search-backward "\\<\\(end\\)\\s-*\\="
2760 (max 0 (- (point) 10)) t)
2761 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2762 (progn (goto-char (match-end 1))
2763 ;;Expand the END abbreviation, just as RET or Space would have.
2764 (if abbrev-mode (expand-abbrev)
2765 (idlwave-show-begin)))))
2766 (when (and (not arg) current-prefix-arg)
2767 (setq arg current-prefix-arg)
2768 (setq current-prefix-arg nil))
2769 (if arg
2770 (idlwave-indent-statement)
2771 (idlwave-indent-line t)))
2773 (defun idlwave-indent-line (&optional expand)
2774 "Indent current IDL line as code or as a comment.
2775 The actions in `idlwave-indent-action-table' are performed.
2776 If the optional argument EXPAND is non-nil then the actions in
2777 `idlwave-indent-expand-table' are performed."
2778 (interactive)
2779 ;; Move point out of left margin.
2780 (if (save-excursion
2781 (skip-chars-backward " \t")
2782 (bolp))
2783 (skip-chars-forward " \t"))
2784 (let ((mloc (point-marker)))
2785 (save-excursion
2786 (beginning-of-line)
2787 (if (looking-at idlwave-comment-line-start-skip)
2788 ;; Indentation for a line comment
2789 (progn
2790 (skip-chars-forward " \t")
2791 (idlwave-indent-left-margin (idlwave-comment-hook)))
2793 ;; Code Line
2795 ;; Before indenting, run action routines.
2797 (if (and expand idlwave-do-actions)
2798 (mapc 'idlwave-do-action idlwave-indent-expand-table))
2800 (if idlwave-do-actions
2801 (mapc 'idlwave-do-action idlwave-indent-action-table))
2803 ;; No longer expand abbrevs on the line. The user can do this
2804 ;; manually using expand-region-abbrevs.
2806 ;; Indent for code line
2808 (beginning-of-line)
2809 (if (or
2810 ;; a label line
2811 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2812 ;; a batch command
2813 (looking-at "^[ \t]*@"))
2814 ;; leave flush left
2816 ;; indent the line
2817 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2818 ;; Adjust parallel comment
2819 (end-of-line)
2820 (if (idlwave-in-comment)
2821 ;; Emacs 21 is too smart with fill-column on comment indent
2822 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2823 (1- (frame-width))
2824 fill-column)))
2825 (indent-for-comment)))))
2826 (goto-char mloc)
2827 ;; Get rid of marker
2828 (set-marker mloc nil)))
2830 (defun idlwave-do-action (action)
2831 "Perform an action repeatedly on a line.
2832 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2833 either a function name to be called with `funcall' or a list to be
2834 evaluated with `eval'. The action performed by FUNC should leave
2835 point after the match for REG - otherwise an infinite loop may be
2836 entered. FUNC is always passed a final argument of 'is-action, so it
2837 can discriminate between being run as an action, or a key binding."
2838 (let ((action-key (car action))
2839 (action-routine (cdr action)))
2840 (beginning-of-line)
2841 (while (idlwave-look-at action-key)
2842 (if (listp action-routine)
2843 (eval (append action-routine '('is-action)))
2844 (funcall action-routine 'is-action)))))
2846 (defun idlwave-indent-to (col &optional min)
2847 "Indent from point with spaces until column COL.
2848 Inserts space before markers at point."
2849 (if (not min) (setq min 0))
2850 (insert-before-markers
2851 (make-string (max min (- col (current-column))) ?\ )))
2853 (defun idlwave-indent-left-margin (col)
2854 "Indent the current line to column COL.
2855 Indents such that first non-whitespace character is at column COL
2856 Inserts spaces before markers at point."
2857 (save-excursion
2858 (beginning-of-line)
2859 (delete-horizontal-space)
2860 (idlwave-indent-to col)))
2862 (defun idlwave-indent-subprogram ()
2863 "Indent program unit which contains point."
2864 (interactive)
2865 (save-excursion
2866 (idlwave-end-of-statement)
2867 (idlwave-beginning-of-subprogram)
2868 (let ((beg (point)))
2869 (idlwave-forward-block)
2870 (message "Indenting subprogram...")
2871 (indent-region beg (point) nil))
2872 (message "Indenting subprogram...done.")))
2874 (defun idlwave-indent-statement ()
2875 "Indent current statement, including all continuation lines."
2876 (interactive)
2877 (save-excursion
2878 (idlwave-beginning-of-statement)
2879 (let ((beg (point)))
2880 (idlwave-end-of-statement)
2881 (indent-region beg (point) nil))))
2883 (defun idlwave-calculate-indent ()
2884 "Return appropriate indentation for current line as IDL code."
2885 (save-excursion
2886 (beginning-of-line)
2887 (cond
2888 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2889 ;; function
2890 ((idlwave-look-at idlwave-begin-unit-reg)
2892 ;; Check for continuation line
2893 ((save-excursion
2894 (and (= (forward-line -1) 0)
2895 (idlwave-is-continuation-line)))
2896 (idlwave-calculate-cont-indent))
2897 ;; calculate indent based on previous and current statements
2898 (t (let* (beg-prev-pos
2899 (the-indent
2900 ;; calculate indent based on previous statement
2901 (save-excursion
2902 (cond
2903 ;; Beginning of file
2904 ((prog1
2905 (idlwave-previous-statement)
2906 (setq beg-prev-pos (point)))
2908 ;; Main block
2909 ((idlwave-look-at idlwave-begin-unit-reg t)
2910 (+ (idlwave-current-statement-indent)
2911 idlwave-main-block-indent))
2912 ;; Begin block
2913 ((idlwave-look-at idlwave-begin-block-reg t)
2914 (+ (idlwave-min-current-statement-indent)
2915 idlwave-block-indent))
2916 ;; End Block
2917 ((idlwave-look-at idlwave-end-block-reg t)
2918 (progn
2919 ;; Match to the *beginning* of the block opener
2920 (goto-char beg-prev-pos)
2921 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2922 (idlwave-min-current-statement-indent)))
2923 ;; idlwave-end-offset
2924 ;; idlwave-block-indent))
2926 ;; Default to current indent
2927 ((idlwave-current-statement-indent))))))
2928 ;; adjust the indentation based on the current statement
2929 (cond
2930 ;; End block
2931 ((idlwave-look-at idlwave-end-block-reg)
2932 (+ the-indent idlwave-end-offset))
2933 (the-indent)))))))
2936 ;; Parentheses indent
2939 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2940 "Calculate the continuation indent inside a paren group.
2941 Returns a cons-cell with (open . indent), where open is the
2942 location of the open paren."
2943 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2944 ;; Found an innermost open paren.
2945 (when open
2946 (goto-char open)
2947 ;; Line up with next word unless this is a closing paren.
2948 (cons open
2949 (cond
2950 ;; Plain Kernighan-style nested indent
2951 (idlwave-indent-parens-nested
2952 (+ idlwave-continuation-indent (idlwave-current-indent)))
2954 ;; This is a closed paren - line up under open paren.
2955 (close-exp
2956 (current-column))
2958 ;; Empty (or just comment) follows -- revert to basic indent
2959 ((progn
2960 ;; Skip paren
2961 (forward-char 1)
2962 (looking-at "[ \t$]*\\(;.*\\)?$"))
2963 nil)
2965 ;; Line up with first word after any blank space
2966 ((progn
2967 (skip-chars-forward " \t")
2968 (current-column))))))))
2970 (defun idlwave-calculate-cont-indent ()
2971 "Calculates the IDL continuation indent column from the previous statement.
2972 Note that here previous statement usually means the beginning of the
2973 current statement if this statement is a continuation of the previous
2974 line. Various special types of continuations, including assignments,
2975 routine definitions, and parenthetical groupings, are treated separately."
2976 (save-excursion
2977 (let* ((case-fold-search t)
2978 (end-reg (progn (beginning-of-line) (point)))
2979 (beg-last-statement (save-excursion (idlwave-previous-statement)
2980 (point)))
2981 (beg-reg (progn (idlwave-start-of-substatement 'pre)
2982 (if (eq (line-beginning-position) end-reg)
2983 (goto-char beg-last-statement)
2984 (point))))
2985 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
2986 idlwave-continuation-indent))
2987 fancy-nonparen-indent fancy-paren-indent)
2988 (cond
2989 ;; Align then with its matching if, etc.
2990 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
2991 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
2992 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
2993 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2994 "[ \t]*until")
2995 ("\\<case\\>" . "[ \t]*of")))
2996 match cont-re)
2997 (goto-char end-reg)
2998 (and
2999 (setq cont-re
3000 (catch 'exit
3001 (while (setq match (car matchers))
3002 (if (looking-at (cdr match))
3003 (throw 'exit (car match)))
3004 (setq matchers (cdr matchers)))))
3005 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3006 (if (looking-at "end") ;; that one's special
3007 (- (idlwave-current-indent)
3008 (+ idlwave-block-indent idlwave-end-offset))
3009 (idlwave-current-indent)))
3011 ;; Indent in from the previous line for continuing statements
3012 ((let ((matchers '("\\<then\\>"
3013 "\\<do\\>"
3014 "\\<repeat\\>"
3015 "\\<else\\>"))
3016 match)
3017 (catch 'exit
3018 (goto-char end-reg)
3019 (if (/= (forward-line -1) 0)
3020 (throw 'exit nil))
3021 (while (setq match (car matchers))
3022 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3023 "\\(;.*\\)?$"))
3024 (throw 'exit t))
3025 (setq matchers (cdr matchers)))))
3026 (+ idlwave-continuation-indent (idlwave-current-indent)))
3028 ;; Parenthetical indent, either traditional or Kernighan style
3029 ((setq fancy-paren-indent
3030 (let* ((end-reg end-reg)
3031 (close-exp (progn
3032 (goto-char end-reg)
3033 (skip-chars-forward " \t")
3034 (looking-at "\\s)")))
3035 indent-cons)
3036 (catch 'loop
3037 (while (setq indent-cons (idlwave-calculate-paren-indent
3038 beg-reg end-reg close-exp))
3039 ;; First permitted containing paren
3040 (if (or
3041 idlwave-indent-to-open-paren
3042 idlwave-indent-parens-nested
3043 (null (cdr indent-cons))
3044 (< (- (cdr indent-cons) basic-indent)
3045 idlwave-max-extra-continuation-indent))
3046 (throw 'loop (cdr indent-cons)))
3047 (setq end-reg (car indent-cons))))))
3048 fancy-paren-indent)
3050 ;; A continued assignment, or procedure call/definition
3051 ((and
3052 (> idlwave-max-extra-continuation-indent 0)
3053 (setq fancy-nonparen-indent
3054 (progn
3055 (goto-char beg-reg)
3056 (while (idlwave-look-at "&")) ; skip continued statements
3057 (cond
3058 ;; A continued Procedure call or definition
3059 ((progn
3060 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3061 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3062 (goto-char (match-end 0))
3063 ;; Comment only, or blank line with "$"? Basic indent.
3064 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3066 (current-column)))
3068 ;; Continued assignment (with =):
3069 ((catch 'assign ;
3070 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3071 (goto-char (match-end 0))
3072 (if (null (idlwave-what-function beg-reg))
3073 (throw 'assign t))))
3074 (unless (or
3075 (idlwave-in-quote)
3076 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3077 (save-excursion
3078 (goto-char beg-last-statement)
3079 (eq (caar (idlwave-statement-type)) 'for)))
3080 (current-column))))))
3081 (< (- fancy-nonparen-indent basic-indent)
3082 idlwave-max-extra-continuation-indent))
3083 (if fancy-paren-indent ;calculated but disallowed paren indent
3084 (+ fancy-nonparen-indent idlwave-continuation-indent)
3085 fancy-nonparen-indent))
3087 ;; Basic indent, by default
3088 (t basic-indent)))))
3092 (defun idlwave-find-key (key-re &optional dir nomark limit)
3093 "Move to next match of the regular expression KEY-RE.
3094 Matches inside comments or string constants will be ignored.
3095 If DIR is negative, the search will be backwards.
3096 At a successful match, the mark is pushed unless NOMARK is non-nil.
3097 Searches are limited to LIMIT.
3098 Searches are case-insensitive and use a special syntax table which
3099 treats `$' and `_' as word characters.
3100 Return value is the beginning of the match or (in case of failure) nil."
3101 (setq dir (or dir 0))
3102 (let ((case-fold-search t)
3103 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3104 found)
3105 (idlwave-with-special-syntax
3106 (save-excursion
3107 (catch 'exit
3108 (while (funcall search-func key-re limit t)
3109 (if (not (idlwave-quoted))
3110 (throw 'exit (setq found (match-beginning 0)))
3111 (if (or (and (> dir 0) (eobp))
3112 (and (< dir 0) (bobp)))
3113 (throw 'exit nil)))))))
3114 (if found
3115 (progn
3116 (if (not nomark) (push-mark))
3117 (goto-char found)
3118 found)
3119 nil)))
3121 (defun idlwave-block-jump-out (&optional dir nomark)
3122 "When optional argument DIR is non-negative, move forward to end of
3123 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3124 regular expressions. When DIR is negative, move backwards to block beginning.
3125 Recursively calls itself to skip over nested blocks. DIR defaults to
3126 forward. Calls `push-mark' unless the optional argument NOMARK is
3127 non-nil. Movement is limited by the start of program units because of
3128 possibility of unbalanced blocks."
3129 (interactive "P")
3130 (or dir (setq dir 0))
3131 (let* ((here (point))
3132 (case-fold-search t)
3133 (limit (if (>= dir 0) (point-max) (point-min)))
3134 (block-limit (if (>= dir 0)
3135 idlwave-begin-block-reg
3136 idlwave-end-block-reg))
3137 found
3138 (block-reg (concat idlwave-begin-block-reg "\\|"
3139 idlwave-end-block-reg))
3140 (unit-limit (or (save-excursion
3141 (if (< dir 0)
3142 (idlwave-find-key
3143 idlwave-begin-unit-reg dir t limit)
3144 (end-of-line)
3145 (idlwave-find-key
3146 idlwave-end-unit-reg dir t limit)))
3147 limit)))
3148 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3149 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3150 (while (and found (looking-at block-limit))
3151 (if (>= dir 0) (forward-word 1))
3152 (idlwave-block-jump-out dir t)
3153 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3154 (if (not nomark) (push-mark here))
3155 (if (not found) (goto-char unit-limit)
3156 (if (>= dir 0) (forward-word 1)))))
3158 (defun idlwave-min-current-statement-indent (&optional end-reg)
3159 "The minimum indent in the current statement."
3160 (idlwave-beginning-of-statement)
3161 (if (not (idlwave-is-continuation-line))
3162 (idlwave-current-indent)
3163 (let ((min (idlwave-current-indent)) comm-or-empty)
3164 (while (and (= (forward-line 1) 0)
3165 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3166 (idlwave-is-continuation-line))
3167 (or (null end-reg) (< (point) end-reg)))
3168 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3169 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3171 (min min (idlwave-current-indent))))))
3173 (defun idlwave-current-statement-indent (&optional last-line)
3174 "Return indentation of the current statement.
3175 If in a statement, moves to beginning of statement before finding indent."
3176 (if last-line
3177 (idlwave-end-of-statement)
3178 (idlwave-beginning-of-statement))
3179 (idlwave-current-indent))
3181 (defun idlwave-current-indent ()
3182 "Return the column of the indentation of the current line.
3183 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3184 (save-excursion
3185 (beginning-of-line)
3186 (skip-chars-forward " \t")
3187 ;; if we are at the end of blank line return 0
3188 (cond ((eolp) 0)
3189 ((current-column)))))
3191 (defun idlwave-is-continuation-line ()
3192 "Test if current line is continuation line.
3193 Blank or comment-only lines following regular continuation lines (with
3194 `$') count as continuations too."
3195 (let (p)
3196 (save-excursion
3198 (idlwave-look-at "\\<\\$")
3199 (catch 'loop
3200 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3201 (eq (forward-line -1) 0))
3202 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
3204 (defun idlwave-is-comment-line ()
3205 "Test if the current line is a comment line."
3206 (save-excursion
3207 (beginning-of-line 1)
3208 (looking-at "[ \t]*;")))
3210 (defun idlwave-is-comment-or-empty-line ()
3211 "Test if the current line is a comment line."
3212 (save-excursion
3213 (beginning-of-line 1)
3214 (looking-at "[ \t]*[;\n]")))
3216 (defun idlwave-look-at (regexp &optional cont beg)
3217 "Search current line from current point for REGEXP.
3218 If optional argument CONT is non-nil, searches to the end of
3219 the current statement.
3220 If optional arg BEG is non-nil, search starts from the beginning of the
3221 current statement.
3222 Ignores matches that end in a comment or inside a string expression.
3223 Returns point if successful, nil otherwise.
3224 This function produces unexpected results if REGEXP contains quotes or
3225 a comment delimiter. The search is case insensitive.
3226 If successful leaves point after the match, otherwise, does not move point."
3227 (let ((here (point))
3228 (case-fold-search t)
3229 (eos (save-excursion
3230 (if cont (idlwave-end-of-statement) (end-of-line))
3231 (point)))
3232 found)
3233 (idlwave-with-special-syntax
3234 (if beg (idlwave-beginning-of-statement))
3235 (while (and (setq found (re-search-forward regexp eos t))
3236 (idlwave-quoted))))
3237 (if (not found) (goto-char here))
3238 found))
3240 (defun idlwave-fill-paragraph (&optional nohang)
3241 "Fill paragraphs in comments.
3242 A paragraph is made up of all contiguous lines having the same comment
3243 leader (the leading whitespace before the comment delimiter and the
3244 comment delimiter). In addition, paragraphs are separated by blank
3245 line comments. The indentation is given by the hanging indent of the
3246 first line, otherwise by the minimum indentation of the lines after
3247 the first line. The indentation of the first line does not change.
3248 Does not effect code lines. Does not fill comments on the same line
3249 with code. The hanging indent is given by the end of the first match
3250 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3251 If the optional argument NOHANG is non-nil then the hanging indent is
3252 ignored."
3253 (interactive "P")
3254 ;; check if this is a line comment
3255 (if (save-excursion
3256 (beginning-of-line)
3257 (skip-chars-forward " \t")
3258 (looking-at comment-start))
3259 (let
3260 ((indent 999)
3261 pre here diff fill-prefix-reg bcl first-indent
3262 hang start end)
3263 ;; Change tabs to spaces in the surrounding paragraph.
3264 ;; The surrounding paragraph will be the largest containing block of
3265 ;; contiguous line comments. Thus, we may be changing tabs in
3266 ;; a much larger area than is needed, but this is the easiest
3267 ;; brute force way to do it.
3269 ;; This has the undesirable side effect of replacing the tabs
3270 ;; permanently without the user's request or knowledge.
3271 (save-excursion
3272 (backward-paragraph)
3273 (setq start (point)))
3274 (save-excursion
3275 (forward-paragraph)
3276 (setq end (point)))
3277 (untabify start end)
3279 (setq here (point))
3280 (beginning-of-line)
3281 (setq bcl (point))
3282 (re-search-forward (concat "^[ \t]*" comment-start "+")
3283 (point-at-eol) t)
3284 ;; Get the comment leader on the line and its length
3285 (setq pre (current-column))
3286 ;; the comment leader is the indentation plus exactly the
3287 ;; number of consecutive ";".
3288 (setq fill-prefix-reg
3289 (concat
3290 (setq fill-prefix
3291 (regexp-quote (buffer-substring (point-at-bol) (point))))
3292 "[^;]"))
3294 ;; Mark the beginning and end of the paragraph
3295 (goto-char bcl)
3296 (while (and (looking-at fill-prefix-reg)
3297 (not (looking-at paragraph-separate))
3298 (not (bobp)))
3299 (forward-line -1))
3300 ;; Move to first line of paragraph
3301 (if (/= (point) bcl)
3302 (forward-line 1))
3303 (setq start (point))
3304 (goto-char bcl)
3305 (while (and (looking-at fill-prefix-reg)
3306 (not (looking-at paragraph-separate))
3307 (not (eobp)))
3308 (forward-line 1))
3309 (beginning-of-line)
3310 (if (or (not (looking-at fill-prefix-reg))
3311 (looking-at paragraph-separate))
3312 (forward-line -1))
3313 (end-of-line)
3314 ;; if at end of buffer add a newline (need this because
3315 ;; fill-region needs END to be at the beginning of line after
3316 ;; the paragraph or it will add a line).
3317 (if (eobp)
3318 (progn (insert ?\n) (backward-char 1)))
3319 ;; Set END to the beginning of line after the paragraph
3320 ;; END is calculated as distance from end of buffer
3321 (setq end (- (point-max) (point) 1))
3323 ;; Calculate the indentation for the paragraph.
3325 ;; In the following while statements, after one iteration
3326 ;; point will be at the beginning of a line in which case
3327 ;; the while will not be executed for the
3328 ;; the first paragraph line and thus will not affect the
3329 ;; indentation.
3331 ;; First check to see if indentation is based on hanging indent.
3332 (if (and (not nohang) idlwave-hanging-indent
3333 (setq hang
3334 (save-excursion
3335 (goto-char start)
3336 (idlwave-calc-hanging-indent))))
3337 ;; Adjust lines of paragraph by inserting spaces so that
3338 ;; each line's indent is at least as great as the hanging
3339 ;; indent. This is needed for fill-paragraph to work with
3340 ;; a fill-prefix.
3341 (progn
3342 (setq indent hang)
3343 (beginning-of-line)
3344 (while (> (point) start)
3345 (re-search-forward comment-start-skip (point-at-eol) t)
3346 (if (> (setq diff (- indent (current-column))) 0)
3347 (progn
3348 (if (>= here (point))
3349 ;; adjust the original location for the
3350 ;; inserted text.
3351 (setq here (+ here diff)))
3352 (insert (make-string diff ?\ ))))
3353 (forward-line -1))
3356 ;; No hang. Instead find minimum indentation of paragraph
3357 ;; after first line.
3358 ;; For the following while statement, since START is at the
3359 ;; beginning of line and END is at the end of line
3360 ;; point is greater than START at least once (which would
3361 ;; be the case for a single line paragraph).
3362 (while (> (point) start)
3363 (beginning-of-line)
3364 (setq indent
3365 (min indent
3366 (progn
3367 (re-search-forward comment-start-skip (point-at-eol) t)
3368 (current-column))))
3369 (forward-line -1)))
3370 (setq fill-prefix (concat fill-prefix
3371 (make-string (- indent pre)
3372 ?\ )))
3373 ;; first-line indent
3374 (setq first-indent
3375 (max
3376 (progn
3377 (re-search-forward comment-start-skip (point-at-eol) t)
3378 (current-column))
3379 indent))
3381 ;; try to keep point at its original place
3382 (goto-char here)
3384 ;; In place of the more modern fill-region-as-paragraph, a hack
3385 ;; to keep whitespace untouched on the first line within the
3386 ;; indent length and to preserve any indent on the first line
3387 ;; (first indent).
3388 (save-excursion
3389 (setq diff
3390 (buffer-substring start (+ start first-indent -1)))
3391 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3392 (fill-region-as-paragraph
3393 start
3394 (- (point-max) end)
3395 (current-justification)
3396 nil)
3397 (delete-region start (+ start first-indent -1))
3398 (goto-char start)
3399 (insert diff))
3400 ;; When we want the point at the beginning of the comment
3401 ;; body fill-region will put it at the beginning of the line.
3402 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3403 (setq fill-prefix nil))))
3405 (defun idlwave-calc-hanging-indent ()
3406 "Calculate the position of the hanging indent for the comment paragraph.
3407 The hanging indent position is given by the first match with the
3408 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3409 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3410 on the line.
3411 If not found returns nil."
3412 (if idlwave-use-last-hang-indent
3413 (save-excursion
3414 (end-of-line)
3415 (if (re-search-backward idlwave-hang-indent-regexp (point-at-bol) t)
3416 (+ (current-column) (length idlwave-hang-indent-regexp))))
3417 (save-excursion
3418 (beginning-of-line)
3419 (if (re-search-forward idlwave-hang-indent-regexp (point-at-eol) t)
3420 (current-column)))))
3422 (defun idlwave-auto-fill ()
3423 "Called to break lines in auto fill mode.
3424 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3425 non-nil. Places a continuation character at the end of the line if
3426 not in a comment. Splits strings with IDL concatenation operator `+'
3427 if `idlwave-auto-fill-split-string' is non-nil."
3428 (if (<= (current-column) fill-column)
3429 nil ; do not to fill
3430 (if (or (not idlwave-fill-comment-line-only)
3431 (save-excursion
3432 ;; Check for comment line
3433 (beginning-of-line)
3434 (looking-at idlwave-comment-line-start-skip)))
3435 (let (beg)
3436 (idlwave-indent-line)
3437 ;; Prevent actions do-auto-fill which calls indent-line-function.
3438 (let (idlwave-do-actions
3439 (paragraph-separate ".")
3440 (fill-nobreak-predicate
3441 (if (and (idlwave-in-quote)
3442 idlwave-auto-fill-split-string)
3443 (lambda () ;; We'll need 5 spaces for " ' + $"
3444 (<= (- fill-column (current-column)) 5)
3445 ))))
3446 (do-auto-fill))
3447 (save-excursion
3448 (end-of-line 0)
3449 ;; Indent the split line
3450 (idlwave-indent-line))
3451 (if (save-excursion
3452 (beginning-of-line)
3453 (looking-at idlwave-comment-line-start-skip))
3454 ;; A continued line comment
3455 ;; We treat continued line comments as part of a comment
3456 ;; paragraph. So we check for a hanging indent.
3457 (if idlwave-hanging-indent
3458 (let ((here (- (point-max) (point)))
3459 (indent
3460 (save-excursion
3461 (forward-line -1)
3462 (idlwave-calc-hanging-indent))))
3463 (when indent
3464 ;; Remove whitespace between comment delimiter and
3465 ;; text, insert spaces for appropriate indentation.
3466 (beginning-of-line)
3467 (re-search-forward comment-start-skip (point-at-eol) t)
3468 (delete-horizontal-space)
3469 (idlwave-indent-to indent)
3470 (goto-char (- (point-max) here)))))
3471 ;; Split code or comment?
3472 (if (save-excursion
3473 (end-of-line 0)
3474 (idlwave-in-comment))
3475 ;; Splitting a non-full-line comment.
3476 ;; Insert the comment delimiter from split line
3477 (progn
3478 (save-excursion
3479 (beginning-of-line)
3480 (skip-chars-forward " \t")
3481 ;; Insert blank to keep off beginning of line
3482 (insert " "
3483 (save-excursion
3484 (forward-line -1)
3485 (buffer-substring (idlwave-goto-comment)
3486 (progn
3487 (skip-chars-forward "; ")
3488 (point))))))
3489 (idlwave-indent-line))
3490 ;; Split code line - add continuation character
3491 (save-excursion
3492 (end-of-line 0)
3493 ;; Check to see if we split a string
3494 (if (and (setq beg (idlwave-in-quote))
3495 idlwave-auto-fill-split-string)
3496 ;; Split the string and concatenate.
3497 ;; The first extra space is for the space
3498 ;; the line was split. That space was removed.
3499 (insert " " (char-after beg) " +"))
3500 (insert " $"))
3501 (if beg
3502 (if idlwave-auto-fill-split-string
3503 ;; Make the second part of continued string
3504 (save-excursion
3505 (beginning-of-line)
3506 (skip-chars-forward " \t")
3507 (insert (char-after beg)))
3508 ;; Warning
3509 (beep)
3510 (message "Warning: continuation inside a string.")))
3511 ;; Although do-auto-fill (via indent-new-comment-line) calls
3512 ;; idlwave-indent-line for the new line, re-indent again
3513 ;; because of the addition of the continuation character.
3514 (idlwave-indent-line))
3515 )))))
3517 (defun idlwave-auto-fill-mode (arg)
3518 "Toggle auto-fill mode for IDL mode.
3519 With arg, turn auto-fill mode on if arg is positive.
3520 In auto-fill mode, inserting a space at a column beyond `fill-column'
3521 automatically breaks the line at a previous space."
3522 (interactive "P")
3523 (prog1 (set idlwave-fill-function
3524 (if (if (null arg)
3525 (not (symbol-value idlwave-fill-function))
3526 (> (prefix-numeric-value arg) 0))
3527 'idlwave-auto-fill
3528 nil))
3529 ;; update mode-line
3530 (set-buffer-modified-p (buffer-modified-p))))
3532 ;(defun idlwave-fill-routine-call ()
3533 ; "Fill a routine definition or statement, indenting appropriately."
3534 ; (let ((where (idlwave-where)))))
3537 (defun idlwave-doc-header (&optional nomark)
3538 "Insert a documentation header at the beginning of the unit.
3539 Inserts the value of the variable `idlwave-file-header'. Sets mark
3540 before moving to do insertion unless the optional prefix argument
3541 NOMARK is non-nil."
3542 (interactive "P")
3543 (or nomark (push-mark))
3544 ;; make sure we catch the current line if it begins the unit
3545 (if idlwave-header-to-beginning-of-file
3546 (goto-char (point-min))
3547 (end-of-line)
3548 (idlwave-beginning-of-subprogram)
3549 (beginning-of-line)
3550 ;; skip function or procedure line
3551 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3552 (progn
3553 (idlwave-end-of-statement)
3554 (if (> (forward-line 1) 0) (insert "\n")))))
3555 (let ((pos (point)))
3556 (if idlwave-file-header
3557 (cond ((car idlwave-file-header)
3558 (insert-file-contents (car idlwave-file-header)))
3559 ((stringp (car (cdr idlwave-file-header)))
3560 (insert (car (cdr idlwave-file-header))))))
3561 (goto-char pos)))
3563 (defun idlwave-default-insert-timestamp ()
3564 "Default timestamp insertion function."
3565 (insert (current-time-string))
3566 (insert ", " (user-full-name))
3567 (if (boundp 'user-mail-address)
3568 (insert " <" user-mail-address ">")
3569 (insert " <" (user-login-name) "@" (system-name) ">"))
3570 ;; Remove extra spaces from line
3571 (idlwave-fill-paragraph)
3572 ;; Insert a blank line comment to separate from the date entry -
3573 ;; will keep the entry from flowing onto date line if re-filled.
3574 (insert "\n;\n;\t\t"))
3576 (defun idlwave-doc-modification ()
3577 "Insert a brief modification log at the beginning of the current program.
3578 Looks for an occurrence of the value of user variable
3579 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3580 name and places the point for the user to add a log. Before moving, saves
3581 location on mark ring so that the user can return to previous point."
3582 (interactive)
3583 (push-mark)
3584 (let* (beg end)
3585 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3586 (progn
3587 (goto-char (point-min))
3588 (re-search-forward idlwave-doclib-start nil t)))
3589 (setq beg (match-beginning 0))
3590 (re-search-forward idlwave-doclib-end nil t)
3591 (setq end (match-end 0)))
3592 (progn
3593 (goto-char beg)
3594 (if (re-search-forward
3595 (concat idlwave-doc-modifications-keyword ":")
3596 end t)
3597 (end-of-line)
3598 (goto-char end)
3599 (end-of-line -1)
3600 (insert "\n" comment-start "\n")
3601 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3602 (insert "\n;\n;\t")
3603 (run-hooks 'idlwave-timestamp-hook))
3604 (error "No valid DOCLIB header"))))
3607 ;; CJC 3/16/93
3608 ;; Interface to expand-region-abbrevs which did not work when the
3609 ;; abbrev hook associated with an abbrev moves point backwards
3610 ;; after abbrev expansion, e.g., as with the abbrev '.n'.
3611 ;; The original would enter an infinite loop in attempting to expand
3612 ;; .n (it would continually expand and unexpand the abbrev without expanding
3613 ;; because the point would keep going back to the beginning of the
3614 ;; abbrev instead of to the end of the abbrev). We now keep the
3615 ;; abbrev hook from moving backwards.
3617 (defun idlwave-expand-region-abbrevs (start end)
3618 "Expand each abbrev occurrence in the region.
3619 Calling from a program, arguments are START END."
3620 (interactive "r")
3621 (save-excursion
3622 (goto-char (min start end))
3623 (let ((idlwave-show-block nil) ;Do not blink
3624 (idlwave-abbrev-move nil)) ;Do not move
3625 (expand-region-abbrevs start end 'noquery))))
3627 (defun idlwave-quoted ()
3628 "Return t if point is in a comment or quoted string.
3629 Returns nil otherwise."
3630 (or (idlwave-in-comment) (idlwave-in-quote)))
3632 (defun idlwave-in-quote ()
3633 "Return location of the opening quote
3634 if point is in a IDL string constant, nil otherwise.
3635 Ignores comment delimiters on the current line.
3636 Properly handles nested quotation marks and octal
3637 constants - a double quote followed by an octal digit."
3638 ;; Treat an octal inside an apostrophe to be a normal string. Treat a
3639 ;; double quote followed by an octal digit to be an octal constant
3640 ;; rather than a string. Therefore, there is no terminating double
3641 ;; quote.
3642 (save-excursion
3643 ;; Because single and double quotes can quote each other we must
3644 ;; search for the string start from the beginning of line.
3645 (let* ((start (point))
3646 (eol (point-at-eol))
3647 (bq (progn (beginning-of-line) (point)))
3648 (endq (point))
3649 (data (match-data))
3650 delim
3651 found)
3652 (while (< endq start)
3653 ;; Find string start
3654 ;; Don't find an octal constant beginning with a double quote
3655 (if (re-search-forward "[\"']" eol 'lim)
3656 ;; Find the string end.
3657 ;; In IDL, two consecutive delimiters after the start of a
3658 ;; string act as an
3659 ;; escape for the delimiter in the string.
3660 ;; Two consecutive delimiters alone (i.e., not after the
3661 ;; start of a string) is the null string.
3662 (progn
3663 ;; Move to position after quote
3664 (goto-char (1+ (match-beginning 0)))
3665 (setq bq (1- (point)))
3666 ;; Get the string delimiter
3667 (setq delim (char-to-string (preceding-char)))
3668 ;; Check for null string
3669 (if (looking-at delim)
3670 (progn (setq endq (point)) (forward-char 1))
3671 ;; Look for next unpaired delimiter
3672 (setq found (search-forward delim eol 'lim))
3673 (while (looking-at delim)
3674 (forward-char 1)
3675 (setq found (search-forward delim eol 'lim)))
3676 (setq endq (if found (1- (point)) (point)))
3678 (progn (setq bq (point)) (setq endq (point)))))
3679 (store-match-data data)
3680 ;; return string beginning position or nil
3681 (if (> start bq) bq))))
3683 (defun idlwave-is-pointer-dereference (&optional limit)
3684 "Determine if the character after point is a pointer dereference *."
3685 (and
3686 (eq (char-after) ?\*)
3687 (not (idlwave-in-quote))
3688 (save-excursion
3689 (forward-char)
3690 (re-search-backward (concat "\\(" idlwave-idl-keywords
3691 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
3694 ;; Statement templates
3696 ;; Replace these with a general template function, something like
3697 ;; expand.el (I think there was also something with a name similar to
3698 ;; dmacro.el)
3700 (defun idlwave-template (s1 s2 &optional prompt noindent)
3701 "Build a template with optional prompt expression.
3703 Opens a line if point is not followed by a newline modulo intervening
3704 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3705 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3706 adjusted according to `idlwave-abbrev-change-case'. If optional
3707 argument PROMPT is a string then it is displayed as a message in the
3708 minibuffer. The PROMPT serves as a reminder to the user of an
3709 expression to enter.
3711 The lines containing S1 and S2 are reindented using `indent-region'
3712 unless the optional second argument NOINDENT is non-nil."
3713 (if (derived-mode-p 'idlwave-shell-mode)
3714 ;; This is a gross hack to avoit template abbrev expansion
3715 ;; in the shell. FIXME: This is a dirty hack.
3716 (if (and (eq this-command 'self-insert-command)
3717 (equal last-abbrev-location (point)))
3718 (insert last-abbrev-text)
3719 (error "No templates in idlwave-shell"))
3720 (cond ((eq idlwave-abbrev-change-case 'down)
3721 (setq s1 (downcase s1) s2 (downcase s2)))
3722 (idlwave-abbrev-change-case
3723 (setq s1 (upcase s1) s2 (upcase s2))))
3724 (let ((beg (point-at-bol))
3725 end)
3726 (if (not (looking-at "\\s-*\n"))
3727 (open-line 1))
3728 (insert s1)
3729 (save-excursion
3730 (insert s2)
3731 (setq end (point)))
3732 (if (not noindent)
3733 (indent-region beg end nil))
3734 (if (stringp prompt)
3735 (message "%s" prompt)))))
3737 (defun idlwave-rw-case (string)
3738 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3739 (if idlwave-reserved-word-upcase
3740 (upcase string)
3741 string))
3743 (defun idlwave-elif ()
3744 "Build skeleton IDL if-else block."
3745 (interactive)
3746 (idlwave-template
3747 (idlwave-rw-case "if")
3748 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3749 "Condition expression"))
3751 (defun idlwave-case ()
3752 "Build skeleton IDL case statement."
3753 (interactive)
3754 (idlwave-template
3755 (idlwave-rw-case "case")
3756 (idlwave-rw-case " of\n\nendcase")
3757 "Selector expression"))
3759 (defun idlwave-switch ()
3760 "Build skeleton IDL switch statement."
3761 (interactive)
3762 (idlwave-template
3763 (idlwave-rw-case "switch")
3764 (idlwave-rw-case " of\n\nendswitch")
3765 "Selector expression"))
3767 (defun idlwave-for ()
3768 "Build skeleton IDL loop statement."
3769 (interactive)
3770 (idlwave-template
3771 (idlwave-rw-case "for")
3772 (idlwave-rw-case " do begin\n\nendfor")
3773 "Loop expression"))
3775 (defun idlwave-if ()
3776 "Build skeleton IDL if statement."
3777 (interactive)
3778 (idlwave-template
3779 (idlwave-rw-case "if")
3780 (idlwave-rw-case " then begin\n\nendif")
3781 "Scalar logical expression"))
3783 (defun idlwave-procedure ()
3784 (interactive)
3785 (idlwave-template
3786 (idlwave-rw-case "pro")
3787 (idlwave-rw-case "\n\nreturn\nend")
3788 "Procedure name"))
3790 (defun idlwave-function ()
3791 (interactive)
3792 (idlwave-template
3793 (idlwave-rw-case "function")
3794 (idlwave-rw-case "\n\nreturn\nend")
3795 "Function name"))
3797 (defun idlwave-repeat ()
3798 (interactive)
3799 (idlwave-template
3800 (idlwave-rw-case "repeat begin\n\nendrep until")
3801 (idlwave-rw-case "")
3802 "Exit condition"))
3804 (defun idlwave-while ()
3805 (interactive)
3806 (idlwave-template
3807 (idlwave-rw-case "while")
3808 (idlwave-rw-case " do begin\n\nendwhile")
3809 "Entry condition"))
3811 (defun idlwave-split-string (string &optional pattern)
3812 "Return a list of substrings of STRING which are separated by PATTERN.
3813 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3814 (or pattern
3815 (setq pattern "[ \f\t\n\r\v]+"))
3816 (let (parts (start 0))
3817 (while (string-match pattern string start)
3818 (setq parts (cons (substring string start (match-beginning 0)) parts)
3819 start (match-end 0)))
3820 (nreverse (cons (substring string start) parts))))
3822 (defun idlwave-replace-string (string replace_string replace_with)
3823 (let* ((start 0)
3824 (last (length string))
3825 (ret_string "")
3826 end)
3827 (while (setq end (string-match replace_string string start))
3828 (setq ret_string
3829 (concat ret_string (substring string start end) replace_with))
3830 (setq start (match-end 0)))
3831 (setq ret_string (concat ret_string (substring string start last)))))
3833 (defun idlwave-get-buffer-visiting (file)
3834 ;; Return the buffer currently visiting FILE
3835 (cond
3836 ((boundp 'find-file-compare-truenames) ; XEmacs
3837 (let ((find-file-compare-truenames t))
3838 (get-file-buffer file)))
3839 ((fboundp 'find-buffer-visiting) ; Emacs
3840 (find-buffer-visiting file))
3841 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3843 (defvar idlwave-outlawed-buffers nil
3844 "List of buffers pulled up by IDLWAVE for special reasons.
3845 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3847 (defun idlwave-find-file-noselect (file &optional why)
3848 ;; Return a buffer visiting file.
3849 (or (idlwave-get-buffer-visiting file)
3850 (let ((buf (find-file-noselect file)))
3851 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3852 buf)))
3854 (defun idlwave-kill-autoloaded-buffers ()
3855 "Kill buffers created automatically by IDLWAVE.
3856 Function prompts for a letter to identify the buffers to kill.
3857 Possible letters are:
3859 f Buffers created by the command \\[idlwave-find-module] or mouse
3860 clicks in the routine info window.
3861 s Buffers created by the IDLWAVE Shell to display where execution
3862 stopped or an error was found.
3863 a Both of the above.
3865 Buffers containing unsaved changes require confirmation before they are killed."
3866 (interactive)
3867 (if (null idlwave-outlawed-buffers)
3868 (error "No IDLWAVE-created buffers available")
3869 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3870 (idlwave-count-outlawed-buffers 'find)
3871 (idlwave-count-outlawed-buffers 'shell)))
3872 (let ((c (read-char)))
3873 (cond
3874 ((member c '(?f ?\C-f))
3875 (idlwave-do-kill-autoloaded-buffers 'find))
3876 ((member c '(?s ?\C-s))
3877 (idlwave-do-kill-autoloaded-buffers 'shell))
3878 ((member c '(?a ?\C-a))
3879 (idlwave-do-kill-autoloaded-buffers t))
3880 (t (error "Abort"))))))
3882 (defun idlwave-count-outlawed-buffers (tag)
3883 "How many outlawed buffers have tag TAG?"
3884 (length (delq nil
3885 (mapcar
3886 (lambda (x) (eq (cdr x) tag))
3887 idlwave-outlawed-buffers))))
3889 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3890 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3891 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3892 (cnt 0)
3893 entry)
3894 (while (setq entry (pop list))
3895 (if (buffer-live-p (car entry))
3896 (and (or (memq t reasons)
3897 (memq (cdr entry) reasons))
3898 (kill-buffer (car entry))
3899 (incf cnt)
3900 (setq idlwave-outlawed-buffers
3901 (delq entry idlwave-outlawed-buffers)))
3902 (setq idlwave-outlawed-buffers
3903 (delq entry idlwave-outlawed-buffers))))
3904 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3906 (defun idlwave-revoke-license-to-kill ()
3907 "Remove BUFFER from the buffers which may be killed.
3908 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3909 Intended for `after-save-hook'."
3910 (let* ((buf (current-buffer))
3911 (entry (assq buf idlwave-outlawed-buffers)))
3912 ;; Revoke license
3913 (if entry
3914 (setq idlwave-outlawed-buffers
3915 (delq entry idlwave-outlawed-buffers)))
3916 ;; Remove this function from the hook.
3917 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3919 (defvar idlwave-path-alist)
3920 (defun idlwave-locate-lib-file (file)
3921 ;; Find FILE on the scanned lib path and return a buffer visiting it
3922 (let* ((dirs idlwave-path-alist)
3923 dir efile)
3924 (catch 'exit
3925 (while (setq dir (car (pop dirs)))
3926 (if (file-regular-p
3927 (setq efile (expand-file-name file dir)))
3928 (throw 'exit efile))))))
3930 (defun idlwave-expand-lib-file-name (file)
3931 ;; Find FILE on the scanned lib path and return a buffer visiting it
3932 ;; This is for, e.g., finding source with no user catalog
3933 (cond
3934 ((null file) nil)
3935 ((file-name-absolute-p file) file)
3936 (t (idlwave-locate-lib-file file))))
3938 (defun idlwave-make-tags ()
3939 "Create the IDL tags file IDLTAGS in the current directory from
3940 the list of directories specified in the minibuffer. Directories may be
3941 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3942 specified top directories are searched if the directory name is prefixed
3943 by @. Specify @ directories with care, it may take a long, long time if
3944 you specify /."
3945 (interactive)
3946 (let (directory directories cmd append status numdirs dir getsubdirs
3947 buffer save_buffer files numfiles item errbuf)
3950 ;; Read list of directories
3951 (setq directory (read-string "Tag Directories: " "."))
3952 (setq directories (idlwave-split-string directory "[ \t]+"))
3954 ;; Set etags command, vars
3955 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3956 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3957 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3958 (setq append " ")
3959 (setq status 0)
3961 ;; For each directory
3962 (setq numdirs 0)
3963 (setq dir (nth numdirs directories))
3964 (while (and dir)
3966 ;; Find the subdirectories
3967 (if (string-match "^[@]\\(.+\\)$" dir)
3968 (setq getsubdirs t) (setq getsubdirs nil))
3969 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3970 (setq dir (expand-file-name dir))
3971 (if (file-directory-p dir)
3972 (progn
3973 (if (and getsubdirs)
3974 (progn
3975 (setq buffer (get-buffer-create "*idltags*"))
3976 (call-process "sh" nil buffer nil "-c"
3977 (concat "find " dir " -type d -print"))
3978 (setq save_buffer (current-buffer))
3979 (set-buffer buffer)
3980 (setq files (idlwave-split-string
3981 (idlwave-replace-string
3982 (buffer-substring 1 (point-max))
3983 "\n" "/*.pro ")
3984 "[ \t]+"))
3985 (set-buffer save_buffer)
3986 (kill-buffer buffer))
3987 (setq files (list (concat dir "/*.pro"))))
3989 ;; For each subdirectory
3990 (setq numfiles 0)
3991 (setq item (nth numfiles files))
3992 (while (and item)
3994 ;; Call etags
3995 (if (not (string-match "^[ \\t]*$" item))
3996 (progn
3997 (message "%s" (concat "Tagging " item "..."))
3998 (setq errbuf (get-buffer-create "*idltags-error*"))
3999 (setq status (+ status
4000 (if (eq 0 (call-process
4001 "sh" nil errbuf nil "-c"
4002 (concat cmd append item)))
4004 1)))
4006 ;; Append additional tags
4007 (setq append " --append ")
4008 (setq numfiles (1+ numfiles))
4009 (setq item (nth numfiles files)))
4010 (progn
4011 (setq numfiles (1+ numfiles))
4012 (setq item (nth numfiles files))
4015 (setq numdirs (1+ numdirs))
4016 (setq dir (nth numdirs directories)))
4017 (progn
4018 (setq numdirs (1+ numdirs))
4019 (setq dir (nth numdirs directories)))))
4021 (setq errbuf (get-buffer-create "*idltags-error*"))
4022 (if (= status 0)
4023 (kill-buffer errbuf))
4024 (message "")
4027 (defun idlwave-toggle-comment-region (beg end &optional n)
4028 "Comment the lines in the region if the first non-blank line is
4029 commented, and conversely, uncomment region. If optional prefix arg
4030 N is non-nil, then for N positive, add N comment delimiters or for N
4031 negative, remove N comment delimiters.
4032 Uses `comment-region' which does not place comment delimiters on
4033 blank lines."
4034 (interactive "r\nP")
4035 (if n
4036 (comment-region beg end (prefix-numeric-value n))
4037 (save-excursion
4038 (goto-char beg)
4039 (beginning-of-line)
4040 ;; skip blank lines
4041 (skip-chars-forward " \t\n")
4042 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4043 (if (fboundp 'uncomment-region)
4044 (uncomment-region beg end)
4045 (comment-region beg end
4046 (- (length (buffer-substring
4047 (match-beginning 1)
4048 (match-end 1))))))
4049 (comment-region beg end)))))
4052 ;; ----------------------------------------------------------------------------
4053 ;; ----------------------------------------------------------------------------
4054 ;; ----------------------------------------------------------------------------
4055 ;; ----------------------------------------------------------------------------
4057 ;; Completion and Routine Info
4060 ;; String "intern" functions
4062 ;; For the completion and routine info function, we want to normalize
4063 ;; the case of procedure names etc. We do this by "interning" these
4064 ;; string is a hand-crafted way. Hashes are used to map the downcase
4065 ;; version of the strings to the cased versions. Most *-sint-*
4066 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4067 ;; system hash. The former is re-scanned, and the latter takes case
4068 ;; precedence.
4070 ;; Since these cased versions are really lisp objects, we can use `eq'
4071 ;; to search, which is a large performance boost. All new strings
4072 ;; need to be "sinterned". We do this as early as possible after
4073 ;; getting these strings from completion or buffer substrings. So
4074 ;; most of the code can simply assume to deal with "sinterned"
4075 ;; strings. The only exception is that the functions which scan whole
4076 ;; buffers for routine information do not intern the grabbed strings.
4077 ;; This is only done afterwards. Therefore in these functions it is
4078 ;; *not* safe to assume the strings can be compared with `eq' and be
4079 ;; fed into the routine assq functions.
4081 ;; Here we define the hashing functions.
4083 ;; The variables which hold the hashes.
4084 (defvar idlwave-sint-routines '(nil))
4085 (defvar idlwave-sint-keywords '(nil))
4086 (defvar idlwave-sint-methods '(nil))
4087 (defvar idlwave-sint-classes '(nil))
4088 (defvar idlwave-sint-dirs '(nil))
4089 (defvar idlwave-sint-libnames '(nil))
4091 (defun idlwave-reset-sintern (&optional what)
4092 "Reset all sintern hashes."
4093 ;; Make sure the hash functions are accessible.
4094 (unless (and (fboundp 'gethash)
4095 (fboundp 'puthash))
4096 (require 'cl)
4097 (or (fboundp 'puthash)
4098 (defalias 'puthash 'cl-puthash)))
4099 (let ((entries '((idlwave-sint-routines 1000 10)
4100 (idlwave-sint-keywords 1000 10)
4101 (idlwave-sint-methods 100 10)
4102 (idlwave-sint-classes 10 10))))
4104 ;; Make sure these are lists
4105 (loop for entry in entries
4106 for var = (car entry)
4107 do (if (not (consp (symbol-value var))) (set var (list nil))))
4109 ;; Reset the system & library hash
4110 (when (or (eq what t) (eq what 'syslib)
4111 (null (cdr idlwave-sint-routines)))
4112 (loop for entry in entries
4113 for var = (car entry) for size = (nth 1 entry)
4114 do (setcdr (symbol-value var)
4115 (make-hash-table ':size size ':test 'equal)))
4116 (setq idlwave-sint-dirs nil
4117 idlwave-sint-libnames nil))
4119 ;; Reset the buffer & shell hash
4120 (when (or (eq what t) (eq what 'bufsh)
4121 (null (car idlwave-sint-routines)))
4122 (loop for entry in entries
4123 for var = (car entry) for size = (nth 1 entry)
4124 do (setcar (symbol-value var)
4125 (make-hash-table ':size size ':test 'equal))))))
4127 (defun idlwave-sintern-routine-or-method (name &optional class set)
4128 (if class
4129 (idlwave-sintern-method name set)
4130 (idlwave-sintern-routine name set)))
4132 (defun idlwave-sintern (stype &rest args)
4133 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4135 ;;(defmacro idlwave-sintern (type var)
4136 ;; `(cond ((not (stringp name)) name)
4137 ;; ((gethash (downcase name) (cdr ,var)))
4138 ;; ((gethash (downcase name) (car ,var)))
4139 ;; (set (idlwave-sintern-set name ,type ,var set))
4140 ;; (name)))
4142 (defun idlwave-sintern-routine (name &optional set)
4143 (cond ((not (stringp name)) name)
4144 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4145 ((gethash (downcase name) (car idlwave-sint-routines)))
4146 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4147 (name)))
4148 (defun idlwave-sintern-keyword (name &optional set)
4149 (cond ((not (stringp name)) name)
4150 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4151 ((gethash (downcase name) (car idlwave-sint-keywords)))
4152 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4153 (name)))
4154 (defun idlwave-sintern-method (name &optional set)
4155 (cond ((not (stringp name)) name)
4156 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4157 ((gethash (downcase name) (car idlwave-sint-methods)))
4158 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4159 (name)))
4160 (defun idlwave-sintern-class (name &optional set)
4161 (cond ((not (stringp name)) name)
4162 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4163 ((gethash (downcase name) (car idlwave-sint-classes)))
4164 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4165 (name)))
4167 (defun idlwave-sintern-dir (dir &optional set)
4168 (car (or (member dir idlwave-sint-dirs)
4169 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4170 (defun idlwave-sintern-libname (name &optional set)
4171 (car (or (member name idlwave-sint-libnames)
4172 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4174 (defun idlwave-sintern-set (name type tables set)
4175 (let* ((func (or (cdr (assq type idlwave-completion-case))
4176 'identity))
4177 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4178 (table (if (eq set 'sys) (cdr tables) (car tables))))
4179 (puthash (downcase name) iname table)
4180 iname))
4182 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4183 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4184 (mapc (lambda(x)
4185 (setcar x (idlwave-sintern-keyword (car x) set)))
4186 (cdr kwd-list))
4187 kwd-list)
4189 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4190 "Sintern all strings in the rinfo LIST.
4191 With optional parameter SET: also set new patterns. Probably this
4192 will always have to be t. If DEFAULT-DIR is passed, it is used as
4193 the base of the directory."
4194 (let (entry name type class kwds res source call new)
4195 (while list
4196 (setq entry (car list)
4197 list (cdr list)
4198 name (car entry)
4199 type (nth 1 entry)
4200 class (nth 2 entry)
4201 source (nth 3 entry)
4202 call (nth 4 entry)
4203 kwds (nthcdr 5 entry))
4205 ;; The class and name
4206 (if class
4207 (progn
4208 (if (symbolp class) (setq class (symbol-name class)))
4209 (setq class (idlwave-sintern-class class set))
4210 (setq name (idlwave-sintern-method name set)))
4211 (setq name (idlwave-sintern-routine name set)))
4213 ;; The source
4214 (let ((source-type (car source))
4215 (source-file (nth 1 source))
4216 (source-dir (if default-dir
4217 (file-name-as-directory default-dir)
4218 (nth 2 source)))
4219 (source-lib (nth 3 source)))
4220 (if (stringp source-dir)
4221 (setq source-dir (idlwave-sintern-dir source-dir set)))
4222 (if (stringp source-lib)
4223 (setq source-lib (idlwave-sintern-libname source-lib set)))
4224 (setq source (list source-type source-file source-dir source-lib)))
4226 ;; The keywords
4227 (setq kwds (mapcar (lambda (x)
4228 (idlwave-sintern-keyword-list x set))
4229 kwds))
4231 ;; Build a canonicalized list
4232 (setq new (nconc (list name type class source call) kwds)
4233 res (cons new res)))
4234 (nreverse res)))
4236 ;; Creating new sintern tables
4238 (defun idlwave-new-sintern-type (tag)
4239 "Define a variable and a function to sintern the new type TAG.
4240 This defines the function `idlwave-sintern-TAG' and the variable
4241 `idlwave-sint-TAGs'."
4242 (let* ((name (symbol-name tag))
4243 (names (concat name "s"))
4244 (var (intern (concat "idlwave-sint-" names)))
4245 (func (intern (concat "idlwave-sintern-" name))))
4246 (set var nil) ; initial value of the association list
4247 (fset func ; set the function
4248 `(lambda (name &optional set)
4249 (cond ((not (stringp name)) name)
4250 ((cdr (assoc (downcase name) ,var)))
4251 (set
4252 (setq ,var (cons (cons (downcase name) name) ,var))
4253 name)
4254 (name))))))
4256 (defun idlwave-reset-sintern-type (tag)
4257 "Reset the sintern variable associated with TAG."
4258 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4260 ;;---------------------------------------------------------------------------
4263 ;; The variables which hold the information
4264 (defvar idlwave-system-routines nil
4265 "Holds the routine-info obtained by scanning buffers.")
4266 (defvar idlwave-buffer-routines nil
4267 "Holds the routine-info obtained by scanning buffers.")
4268 (defvar idlwave-compiled-routines nil
4269 "Holds the routine-info obtained by asking the shell.")
4270 (defvar idlwave-unresolved-routines nil
4271 "Holds the unresolved routine-info obtained by asking the shell.")
4272 (defvar idlwave-user-catalog-routines nil
4273 "Holds the procedure routine-info from the user scan.")
4274 (defvar idlwave-library-catalog-routines nil
4275 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4276 (defvar idlwave-library-catalog-libname nil
4277 "Name of library catalog loaded from .idlwave_catalog files.")
4278 (defvar idlwave-path-alist nil
4279 "Alist with !PATH directories and zero or more flags if the dir has
4280 been scanned in a user catalog ('user) or discovered in a library
4281 catalog \('lib).")
4282 (defvar idlwave-true-path-alist nil
4283 "Like `idlwave-path-alist', but with true filenames.")
4284 (defvar idlwave-routines nil
4285 "Holds the combined procedure/function/method routine-info.")
4286 (defvar idlwave-class-alist nil
4287 "Holds the class names known to IDLWAVE.")
4288 (defvar idlwave-class-history nil
4289 "The history of classes selected with the minibuffer.")
4290 (defvar idlwave-force-class-query nil)
4291 (defvar idlwave-before-completion-wconf nil
4292 "The window configuration just before the completion buffer was displayed.")
4293 (defvar idlwave-last-system-routine-info-cons-cell nil
4294 "The last cons cell in the system routine info.")
4297 ;; The code to get routine info from different sources.
4299 (defvar idlwave-system-routines)
4300 (defvar idlwave-catalog-process nil
4301 "The background process currently updating the catalog.")
4303 (defun idlwave-routines ()
4304 "Provide a list of IDL routines.
4305 This routine loads the builtin routines on the first call.
4306 Later it only returns the value of the variable."
4307 (if (and idlwave-catalog-process
4308 (processp idlwave-catalog-process))
4309 (progn
4310 (cond
4311 ((equal (process-status idlwave-catalog-process) 'exit)
4312 (message "updating........")
4313 (setq idlwave-catalog-process nil)
4314 (idlwave-update-routine-info '(4)))
4315 ((equal (process-status idlwave-catalog-process) 'run)
4316 ;; Keep it running...
4319 ;; Something is wrong, get rid of the process
4320 (message "Problem with catalog process") (beep)
4321 (condition-case nil
4322 (kill-process idlwave-catalog-process)
4323 (error nil))
4324 (setq idlwave-catalog-process nil)))))
4325 (or idlwave-routines
4326 (progn
4327 (idlwave-update-routine-info)
4328 ;; return the current value
4329 idlwave-routines)))
4331 (defvar idlwave-update-rinfo-hook nil
4332 "List of functions which should run after a global rinfo update.
4333 Does not run after automatic updates of buffer or the shell.")
4335 (defun idlwave-rescan-catalog-directories ()
4336 "Rescan the previously selected directories. For batch processing."
4337 (idlwave-update-routine-info '(16)))
4339 (defun idlwave-rescan-asynchronously ()
4340 "Dispatch another Emacs instance to update the idlwave catalog.
4341 After the process finishes normally, the first access to routine info
4342 will re-read the catalog."
4343 (interactive)
4344 (if (processp idlwave-catalog-process)
4345 (if (eq (process-status idlwave-catalog-process) 'run)
4346 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4347 (progn
4348 (condition-case nil
4349 (kill-process idlwave-catalog-process)
4350 (error nil))
4351 (error "Process killed, no new process started"))
4352 (error "Quit"))
4353 (condition-case nil
4354 (kill-process idlwave-catalog-process)
4355 (error nil))))
4356 (if (or (not idlwave-user-catalog-file)
4357 (not (stringp idlwave-user-catalog-file))
4358 (not (file-regular-p idlwave-user-catalog-file)))
4359 (error "No catalog has been produced yet"))
4360 (let* ((emacs (concat invocation-directory invocation-name))
4361 (args (list "-batch"
4362 "-l" (expand-file-name "~/.emacs")
4363 "-l" "idlwave"
4364 "-f" "idlwave-rescan-catalog-directories"))
4365 (process (apply 'start-process "idlcat"
4366 nil emacs args)))
4367 (setq idlwave-catalog-process process)
4368 (set-process-sentinel
4369 process
4370 (lambda (pro why)
4371 (when (string-match "finished" why)
4372 (setq idlwave-routines nil
4373 idlwave-system-routines nil
4374 idlwave-catalog-process nil)
4375 (or (idlwave-start-load-rinfo-timer)
4376 (idlwave-update-routine-info '(4))))))
4377 (message "Background job started to update catalog file")))
4380 ;; Format for all routine info user catalog, library catalogs, etc.:
4382 ;; ("ROUTINE" type class
4383 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4384 ;; (buffer pro_file dir) | (compiled pro_file dir)
4385 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4386 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4388 ;; DIR will be supplied dynamically while loading library catalogs,
4389 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4390 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4391 ;; be nil, as can LINK1, etc., if no HTML help is available.
4394 (defvar idlwave-load-rinfo-idle-timer)
4395 (defvar idlwave-shell-path-query)
4397 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4398 "Update the internal routine-info lists.
4399 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4400 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4401 about individual routines.
4403 The information can come from 4 sources:
4404 1. IDL programs in the current editing session
4405 2. Compiled modules in an IDL shell running as Emacs subprocess
4406 3. A list which covers the IDL system routines.
4407 4. A list which covers the prescanned library files.
4409 Scans all IDLWAVE-mode buffers of the current editing session (see
4410 `idlwave-scan-all-buffers-for-routine-info').
4411 When an IDL shell is running, this command also queries the IDL program
4412 for currently compiled routines.
4414 With prefix ARG, also reload the system and library lists.
4415 With two prefix ARG's, also rescans the chosen user catalog tree.
4416 With three prefix args, dispatch asynchronous process to do the update.
4418 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4419 lists, but instead wait for the shell query to complete and
4420 asynchronously finish updating routine info. This is set
4421 automatically when called interactively. When you need routine
4422 information updated immediately, leave NO-CONCATENATE nil."
4423 (interactive "P\np")
4424 ;; Stop any idle processing
4425 (if (or (and (fboundp 'itimerp)
4426 (itimerp idlwave-load-rinfo-idle-timer))
4427 (and (fboundp 'timerp)
4428 (timerp idlwave-load-rinfo-idle-timer)))
4429 (cancel-timer idlwave-load-rinfo-idle-timer))
4430 (cond
4431 ((equal arg '(64))
4432 ;; Start a background process which updates the catalog.
4433 (idlwave-rescan-asynchronously))
4434 ((equal arg '(16))
4435 ;; Update the user catalog now, and wait for them.
4436 (idlwave-create-user-catalog-file t))
4438 (let* ((load (or arg
4439 idlwave-buffer-case-takes-precedence
4440 (null idlwave-routines)))
4441 ;; The override-idle means, even if the idle timer has done some
4442 ;; preparing work, load and renormalize everything anyway.
4443 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4445 (setq idlwave-buffer-routines nil
4446 idlwave-compiled-routines nil
4447 idlwave-unresolved-routines nil)
4448 ;; Reset the appropriate hashes
4449 (if (get 'idlwave-reset-sintern 'done-by-idle)
4450 ;; reset was already done in idle time, so skip this step now once
4451 (put 'idlwave-reset-sintern 'done-by-idle nil)
4452 (idlwave-reset-sintern (cond (load t)
4453 ((null idlwave-system-routines) t)
4454 (t 'bufsh))))
4456 (if idlwave-buffer-case-takes-precedence
4457 ;; We can safely scan the buffer stuff first
4458 (progn
4459 (idlwave-update-buffer-routine-info)
4460 (and load (idlwave-load-all-rinfo override-idle)))
4461 ;; We first do the system info, and then the buffers
4462 (and load (idlwave-load-all-rinfo override-idle))
4463 (idlwave-update-buffer-routine-info))
4465 ;; Let's see if there is a shell
4466 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4467 (idlwave-shell-is-running)))
4468 (ask-shell (and shell-is-running
4469 idlwave-query-shell-for-routine-info)))
4471 ;; Load the library catalogs again, first re-scanning the path
4472 (when arg
4473 (if shell-is-running
4474 (idlwave-shell-send-command idlwave-shell-path-query
4475 '(progn
4476 (idlwave-shell-get-path-info)
4477 (idlwave-scan-library-catalogs))
4478 'hide)
4479 (idlwave-scan-library-catalogs)))
4481 (if (or (not ask-shell)
4482 (not no-concatenate))
4483 ;; 1. If we are not going to ask the shell, we need to do the
4484 ;; concatenation now.
4485 ;; 2. When this function is called non-interactively, it
4486 ;; means that someone needs routine info *now*. The
4487 ;; shell update causes the concatenation to be
4488 ;; *delayed*, so not in time for the current command.
4489 ;; Therefore, we do a concatenation now, even though
4490 ;; the shell might do it again.
4491 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4493 (when ask-shell
4494 ;; Ask the shell about the routines it knows of.
4495 (message "Querying the shell")
4496 (idlwave-shell-update-routine-info nil t)))))))
4499 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4500 (defvar idlwave-load-rinfo-idle-timer nil)
4501 (defun idlwave-start-load-rinfo-timer ()
4502 (if (or (and (fboundp 'itimerp)
4503 (itimerp idlwave-load-rinfo-idle-timer))
4504 (and (fboundp 'timerp)
4505 (timerp idlwave-load-rinfo-idle-timer)))
4506 (cancel-timer idlwave-load-rinfo-idle-timer))
4507 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4508 (setq idlwave-load-rinfo-idle-timer nil)
4509 (if (and idlwave-init-rinfo-when-idle-after
4510 (numberp idlwave-init-rinfo-when-idle-after)
4511 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4512 (not idlwave-routines))
4513 (condition-case nil
4514 (progn
4515 (setq idlwave-load-rinfo-idle-timer
4516 (run-with-idle-timer
4517 idlwave-init-rinfo-when-idle-after
4518 nil 'idlwave-load-rinfo-next-step)))
4519 (error nil))))
4521 ;;------ XML Help routine info system
4522 (defun idlwave-load-system-routine-info ()
4523 ;; Load the system routine info from the cached routine info file,
4524 ;; which, if necessary, will be re-created from the XML file on
4525 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4526 ;; file distributed with older IDLWAVE versions (<6.0)
4527 (unless (and (load idlwave-xml-system-rinfo-converted-file
4528 'noerror 'nomessage)
4529 (idlwave-xml-system-routine-info-up-to-date))
4530 ;; See if we can create it from XML source
4531 (condition-case nil
4532 (idlwave-convert-xml-system-routine-info)
4533 (error
4534 (unless (load idlwave-xml-system-rinfo-converted-file
4535 'noerror 'nomessage)
4536 (if idlwave-system-routines
4537 (message
4538 "Failed to load converted routine info, using old conversion.")
4539 (message
4540 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4541 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4542 (message
4543 "Could not locate any system routine information."))))))))
4545 (defun idlwave-xml-system-routine-info-up-to-date()
4546 (let* ((dir (file-name-as-directory
4547 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4548 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4549 (file-newer-than-file-p ;converted file is newer than catalog
4550 idlwave-xml-system-rinfo-converted-file
4551 catalog-file)))
4553 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4554 (defvar idlwave-system-variables-alist nil
4555 "Alist of system variables and the associated structure tags.
4556 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4557 (defvar idlwave-executive-commands-alist nil
4558 "Alist of system variables and their help files.")
4559 (defvar idlwave-help-special-topic-words nil)
4562 (defun idlwave-shorten-syntax (syntax name &optional class)
4563 ;; From a list of syntax statements, shorten with %s and group with "or"
4564 (let ((case-fold-search t))
4565 (mapconcat
4566 (lambda (x)
4567 (while (string-match name x)
4568 (setq x (replace-match "%s" t t x)))
4569 (if class
4570 (while (string-match class x)
4571 (setq x (replace-match "%s" t t x))))
4573 (nreverse syntax)
4574 " or ")))
4576 (defun idlwave-xml-create-class-method-lists (xml-entry)
4577 ;; Create a class list entry from the xml parsed list., returning a
4578 ;; cons of form (class-entry method-entries).
4579 (let* ((nameblock (nth 1 xml-entry))
4580 (class (cdr (assq 'name nameblock)))
4581 (link (cdr (assq 'link nameblock)))
4582 (params (cddr xml-entry))
4583 (case-fold-search t)
4584 class-entry
4585 method methods-entry extra-kwds
4586 props get-props set-props init-props inherits
4587 pelem ptype)
4588 (while params
4589 (setq pelem (car params))
4590 (when (listp pelem)
4591 (setq ptype (car pelem)
4592 props (car (cdr pelem)))
4593 (cond
4594 ((eq ptype 'SUPERCLASS)
4595 (let ((pname (cdr (assq 'name props)))
4596 (plink (cdr (assq 'link props))))
4597 (unless (and (string= pname "None")
4598 (string= plink "None"))
4599 (push pname inherits))))
4601 ((eq ptype 'PROPERTY)
4602 (let ((pname (cdr (assq 'name props)))
4603 (plink (cdr (assq 'link props)))
4604 (get (string= (cdr (assq 'get props)) "Yes"))
4605 (set (string= (cdr (assq 'set props)) "Yes"))
4606 (init (string= (cdr (assq 'init props)) "Yes")))
4607 (if get (push (list pname plink) get-props))
4608 (if set (push (list pname plink) set-props))
4609 (if init (push (list pname plink) init-props))))
4611 ((eq ptype 'METHOD)
4612 (setq method (cdr (assq 'name props)))
4613 (setq extra-kwds ;;Assume all property keywords are gathered already
4614 (cond
4615 ((string-match (concat class "::Init") method)
4616 (put 'init-props 'matched t)
4617 init-props)
4618 ((string-match (concat class "::GetProperty") method)
4619 (put 'get-props 'matched t)
4620 get-props)
4621 ((string-match (concat class "::SetProperty") method)
4622 (put 'set-props 'matched t)
4623 set-props)
4624 (t nil)))
4625 (setq methods-entry
4626 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4627 methods-entry)))
4628 (t)))
4629 (setq params (cdr params)))
4630 ;;(unless (get 'init-props 'matched)
4631 ;; (message "Failed to match Init in class %s" class))
4632 ;;(unless (get 'get-props 'matched)
4633 ;; (message "Failed to match GetProperty in class %s" class))
4634 ;;(unless (get 'set-props 'matched)
4635 ;; (message "Failed to match SetProperty in class %s" class))
4636 (setq class-entry
4637 (if inherits
4638 (list class (append '(inherits) inherits) (list 'link link))
4639 (list class (list 'link link))))
4640 (cons class-entry methods-entry)))
4642 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4643 ;; Create correctly structured list elements from ROUTINE or METHOD
4644 ;; XML list structures. Return a list of list elements, with more
4645 ;; than one sub-list possible if a routine can serve as both
4646 ;; procedure and function (e.g. call_method).
4647 (let* ((nameblock (nth 1 xml-entry))
4648 (name (cdr (assq 'name nameblock)))
4649 (link (cdr (assq 'link nameblock)))
4650 (params (cddr xml-entry))
4651 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4652 (case-fold-search t)
4653 syntax kwd klink pref-list kwds pelem ptype props result type)
4654 (if class ;; strip out class name from class method name string
4655 (if (string-match (concat class "::") name)
4656 (setq name (substring name (match-end 0)))))
4657 (while params
4658 (setq pelem (car params))
4659 (when (listp pelem)
4660 (setq ptype (car pelem)
4661 props (car (cdr pelem)))
4662 (cond
4663 ((eq ptype 'SYNTAX)
4664 (setq syntax (cdr (assq 'name props)))
4665 (if (string-match "-&gt;" syntax)
4666 (setq syntax (replace-match "->" t nil syntax)))
4667 (setq type (cdr (assq 'type props)))
4668 (push syntax
4669 (aref syntax-vec (cond
4670 ((string-match "^pro" type) 0)
4671 ((string-match "^fun" type) 1)
4672 ((string-match "^exec" type) 2)))))
4673 ((eq ptype 'KEYWORD)
4674 (setq kwd (cdr (assq 'name props))
4675 klink (cdr (assq 'link props)))
4676 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4677 (progn
4678 (setq pref-list
4679 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4680 kwd (substring kwd (match-end 0)))
4681 (loop for x in pref-list do
4682 (push (list (concat x kwd) klink) kwds)))
4683 (push (list kwd klink) kwds)))
4685 (t))); Do nothing for the others
4686 (setq params (cdr params)))
4688 ;; Debug
4689 ;; (if (and (null (aref syntax-vec 0))
4690 ;; (null (aref syntax-vec 1))
4691 ;; (null (aref syntax-vec 2)))
4692 ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4693 ;; (if class
4694 ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4695 ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4697 ;; Executive commands are treated specially
4698 (if (aref syntax-vec 2)
4699 (cons (substring name 1) link)
4700 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4701 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4702 (loop for idx from 0 to 1 do
4703 (if (aref syntax-vec idx)
4704 (push (append (list name (if (eq idx 0) 'pro 'fun)
4705 class '(system)
4706 (idlwave-shorten-syntax
4707 (aref syntax-vec idx) name class))
4708 kwds) result)))
4709 result)))
4712 (defun idlwave-rinfo-group-keywords (kwds master-link)
4713 ;; Group keywords by link file, as a list with elements
4714 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4715 (let (kwd link anchor linkfiles block master-elt)
4716 (while kwds
4717 (setq kwd (car kwds)
4718 link (idlwave-split-link-target (nth 1 kwd))
4719 anchor (cdr link)
4720 link (car link)
4721 kwd (car kwd))
4722 (if (setq block (assoc link linkfiles))
4723 (push (cons kwd anchor) (cdr block))
4724 (push (list link (cons kwd anchor)) linkfiles))
4725 (setq kwds (cdr kwds)))
4726 ;; Ensure the master link is there
4727 (if (setq master-elt (assoc master-link linkfiles))
4728 (if (eq (car linkfiles) master-elt)
4729 linkfiles
4730 (cons master-elt (delq master-elt linkfiles)))
4731 (push (list master-link) linkfiles))))
4733 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4734 ;; Clean up the syntax of routines which are actually aliases by
4735 ;; removing the "OR" from the statements
4736 (let (syntax entry)
4737 (loop for x in aliases do
4738 (setq entry (assoc x idlwave-system-routines))
4739 (when entry
4740 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4741 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4743 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4744 ;; Duplicate and trim original routine aliases from rinfo list
4745 ;; This if for, e.g. OPENR/OPENW/OPENU
4746 (let (alias remove-list new parts all-parts)
4747 (loop for x in aliases do
4748 (when (setq parts (split-string (cdr x) "/"))
4749 (setq new (assoc (cdr x) all-parts))
4750 (unless new
4751 (setq new (cons (cdr x) parts))
4752 (push new all-parts))
4753 (setcdr new (delete (car x) (cdr new)))))
4755 ;; Add any missing aliases (separate by slashes)
4756 (loop for x in all-parts do
4757 (if (cdr x)
4758 (push (cons (nth 1 x) (car x)) aliases)))
4760 (loop for x in aliases do
4761 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4762 (unless (memq alias remove-list) (push alias remove-list))
4763 (setq alias (copy-sequence alias))
4764 (setcar alias (car x))
4765 (push alias idlwave-system-routines)))
4766 (loop for x in remove-list do
4767 (delq x idlwave-system-routines))))
4769 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4770 ;; Duplicate and trim original routine aliases from rinfo list
4771 ;; This if for, e.g. !X, !Y, !Z.
4772 (let (alias remove-list)
4773 (loop for x in aliases do
4774 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4775 (unless (memq alias remove-list) (push alias remove-list))
4776 (setq alias (copy-sequence alias))
4777 (setcar alias (car x))
4778 (push alias idlwave-system-variables-alist)))
4779 (loop for x in remove-list do
4780 (delq x idlwave-system-variables-alist))))
4783 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4784 ;; Create a sysvar list entry from the xml parsed list.
4785 (let* ((nameblock (nth 1 xml-entry))
4786 (name (cdr (assq 'name nameblock)))
4787 (sysvar (substring name (progn (string-match "^ *!" name)
4788 (match-end 0))))
4789 (link (cdr (assq 'link nameblock)))
4790 (params (cddr xml-entry))
4791 (case-fold-search t)
4792 pelem ptype props tags)
4793 (while params
4794 (setq pelem (car params))
4795 (when (listp pelem)
4796 (setq ptype (car pelem)
4797 props (car (cdr pelem)))
4798 (cond
4799 ((eq ptype 'FIELD)
4800 (push (cons (cdr (assq 'name props))
4801 (cdr
4802 (idlwave-split-link-target (cdr (assq 'link props)))))
4803 tags))))
4804 (setq params (cdr params)))
4805 (delq nil
4806 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4809 (defvar idlwave-xml-routine-info-file nil)
4811 (defun idlwave-save-routine-info ()
4812 (if idlwave-xml-routine-info-file
4813 (with-temp-file idlwave-xml-system-rinfo-converted-file
4814 (insert
4815 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4816 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4817 ;; Automatically generated from source file:
4818 ;; " idlwave-xml-routine-info-file "
4819 ;; on " (current-time-string) "
4820 ;; Do not edit."))
4821 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4822 idlwave-xml-routine-info-file))
4823 (insert "\n(setq idlwave-system-routines\n '")
4824 (prin1 idlwave-system-routines (current-buffer))
4825 (insert ")")
4826 (insert "\n(setq idlwave-system-variables-alist\n '")
4827 (prin1 idlwave-system-variables-alist (current-buffer))
4828 (insert ")")
4829 (insert "\n(setq idlwave-system-class-info\n '")
4830 (prin1 idlwave-system-class-info (current-buffer))
4831 (insert ")")
4832 (insert "\n(setq idlwave-executive-commands-alist\n '")
4833 (prin1 idlwave-executive-commands-alist (current-buffer))
4834 (insert ")")
4835 (insert "\n(setq idlwave-help-special-topic-words\n '")
4836 (prin1 idlwave-help-special-topic-words (current-buffer))
4837 (insert ")"))))
4839 (defun idlwave-convert-xml-system-routine-info ()
4840 "Convert XML supplied IDL routine info into internal form.
4841 Cache to disk for quick recovery."
4842 (interactive)
4843 (let* ((dir (file-name-as-directory
4844 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4845 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4846 (elem-cnt 0)
4847 props rinfo msg-cnt elem type nelem class-result alias
4848 routines routine-aliases statement-aliases sysvar-aliases)
4849 (if (not (file-exists-p catalog-file))
4850 (error "No such XML routine info file: %s" catalog-file)
4851 (if (not (file-readable-p catalog-file))
4852 (error "Cannot read XML routine info file: %s" catalog-file)))
4853 (message "Reading XML routine info...")
4854 (setq rinfo (xml-parse-file catalog-file))
4855 (message "Reading XML routine info...done")
4856 (setq rinfo (assq 'CATALOG rinfo))
4857 (unless rinfo (error "Failed to parse XML routine info"))
4858 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4860 (setq rinfo (cddr rinfo))
4862 (setq nelem (length rinfo)
4863 msg-cnt (/ nelem 20))
4865 (setq idlwave-xml-routine-info-file nil)
4866 (message "Converting XML routine info...")
4867 (setq idlwave-system-routines nil
4868 idlwave-system-variables-alist nil
4869 idlwave-system-class-info nil
4870 idlwave-executive-commands-alist nil
4871 idlwave-help-special-topic-words nil)
4873 (while rinfo
4874 (setq elem (car rinfo)
4875 rinfo (cdr rinfo))
4876 (incf elem-cnt)
4877 (when (listp elem)
4878 (setq type (car elem)
4879 props (car (cdr elem)))
4880 (if (= (mod elem-cnt msg-cnt) 0)
4881 (message "Converting XML routine info...%2d%%"
4882 (/ (* elem-cnt 100) nelem)))
4883 (cond
4884 ((eq type 'ROUTINE)
4885 (if (setq alias (assq 'alias_to props))
4886 (push (cons (cdr (assq 'name props)) (cdr alias))
4887 routine-aliases)
4888 (setq routines (idlwave-xml-create-rinfo-list elem))
4889 (if (listp (cdr routines))
4890 (setq idlwave-system-routines
4891 (nconc idlwave-system-routines routines))
4892 ;; a cons cell is an executive commands
4893 (push routines idlwave-executive-commands-alist))))
4895 ((eq type 'CLASS)
4896 (setq class-result (idlwave-xml-create-class-method-lists elem))
4897 (push (car class-result) idlwave-system-class-info)
4898 (setq idlwave-system-routines
4899 (nconc idlwave-system-routines (cdr class-result))))
4901 ((eq type 'STATEMENT)
4902 (push (cons (cdr (assq 'name props))
4903 (cdr (assq 'link props)))
4904 idlwave-help-special-topic-words)
4905 ;; Save the links to those which are statement aliases (not routines)
4906 (if (setq alias (assq 'alias_to props))
4907 (unless (member (cdr alias) statement-aliases)
4908 (push (cdr alias) statement-aliases))))
4910 ((eq type 'SYSVAR)
4911 (if (setq alias (cdr (assq 'alias_to props)))
4912 (push (cons (substring (cdr (assq 'name props)) 1)
4913 (substring alias 1))
4914 sysvar-aliases)
4915 (push (idlwave-xml-create-sysvar-alist elem)
4916 idlwave-system-variables-alist)))
4917 (t))))
4918 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4919 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4920 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4922 (setq idlwave-xml-routine-info-file catalog-file)
4923 (idlwave-save-routine-info)
4924 (message "Converting XML routine info...done")))
4927 ;; ("ROUTINE" type class
4928 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4929 ;; (buffer pro_file dir) | (compiled pro_file dir)
4930 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4931 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4934 (defun idlwave-load-rinfo-next-step ()
4935 (let ((inhibit-quit t)
4936 (arr idlwave-load-rinfo-steps-done))
4937 (if (catch 'exit
4938 (when (not (aref arr 0))
4939 (message "Loading system routine info in idle time...")
4940 (idlwave-load-system-routine-info)
4941 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4942 (message "Loading system routine info in idle time...done")
4943 (aset arr 0 t)
4944 (throw 'exit t))
4946 (when (not (aref arr 1))
4947 (message "Normalizing idlwave-system-routines in idle time...")
4948 (idlwave-reset-sintern t)
4949 (put 'idlwave-reset-sintern 'done-by-idle t)
4950 (setq idlwave-system-routines
4951 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4952 (message "Normalizing idlwave-system-routines in idle time...done")
4953 (aset arr 1 t)
4954 (throw 'exit t))
4956 (when (not (aref arr 2))
4957 (when (and (stringp idlwave-user-catalog-file)
4958 (file-regular-p idlwave-user-catalog-file))
4959 (message "Loading user catalog in idle time...")
4960 (condition-case nil
4961 (load-file idlwave-user-catalog-file)
4962 (error (throw 'exit nil)))
4963 ;; Check for the old style catalog and warn
4964 (if (and
4965 (boundp 'idlwave-library-routines)
4966 idlwave-library-routines)
4967 (progn
4968 (setq idlwave-library-routines nil)
4969 (ding)
4970 (message "Outdated user catalog: %s... recreate"
4971 idlwave-user-catalog-file))
4972 (message "Loading user catalog in idle time...done")))
4973 (aset arr 2 t)
4974 (throw 'exit t))
4976 (when (not (aref arr 3))
4977 (when idlwave-user-catalog-routines
4978 (message "Normalizing user catalog routines in idle time...")
4979 (setq idlwave-user-catalog-routines
4980 (idlwave-sintern-rinfo-list
4981 idlwave-user-catalog-routines 'sys))
4982 (message
4983 "Normalizing user catalog routines in idle time...done"))
4984 (aset arr 3 t)
4985 (throw 'exit t))
4987 (when (not (aref arr 4))
4988 (idlwave-scan-library-catalogs
4989 "Loading and normalizing library catalogs in idle time...")
4990 (aset arr 4 t)
4991 (throw 'exit t))
4992 (when (not (aref arr 5))
4993 (message "Finishing initialization in idle time...")
4994 (idlwave-routines)
4995 (message "Finishing initialization in idle time...done")
4996 (aset arr 5 t)
4997 (throw 'exit nil)))
4998 ;; restart the timer
4999 (if (sit-for 1)
5000 (idlwave-load-rinfo-next-step)
5001 (setq idlwave-load-rinfo-idle-timer
5002 (run-with-idle-timer
5003 idlwave-init-rinfo-when-idle-after
5004 nil 'idlwave-load-rinfo-next-step))))))
5006 (defvar idlwave-after-load-rinfo-hook nil)
5008 (defun idlwave-load-all-rinfo (&optional force)
5009 ;; Load and case-treat the system, user catalog, and library routine
5010 ;; info files.
5012 ;; System
5013 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
5014 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5015 (idlwave-load-system-routine-info))
5016 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5017 (message "Normalizing idlwave-system-routines...")
5018 (setq idlwave-system-routines
5019 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5020 (message "Normalizing idlwave-system-routines...done"))
5021 (when idlwave-system-routines
5022 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5023 (setq idlwave-last-system-routine-info-cons-cell
5024 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5026 ;; User catalog
5027 (when (and (stringp idlwave-user-catalog-file)
5028 (file-regular-p idlwave-user-catalog-file))
5029 (condition-case nil
5030 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5031 (load-file idlwave-user-catalog-file))
5032 (error nil))
5033 (when (and
5034 (boundp 'idlwave-library-routines)
5035 idlwave-library-routines)
5036 (setq idlwave-library-routines nil)
5037 (error "Outdated user catalog: %s... recreate"
5038 idlwave-user-catalog-file))
5039 (setq idlwave-true-path-alist nil)
5040 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5041 (message "Normalizing user catalog routines...")
5042 (setq idlwave-user-catalog-routines
5043 (idlwave-sintern-rinfo-list
5044 idlwave-user-catalog-routines 'sys))
5045 (message "Normalizing user catalog routines...done")))
5047 ;; Library catalog
5048 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5049 (idlwave-scan-library-catalogs
5050 "Loading and normalizing library catalogs..."))
5051 (run-hooks 'idlwave-after-load-rinfo-hook))
5054 (defun idlwave-update-buffer-routine-info ()
5055 (let (res)
5056 (cond
5057 ((eq idlwave-scan-all-buffers-for-routine-info t)
5058 ;; Scan all buffers, current buffer last
5059 (message "Scanning all buffers...")
5060 (setq res (idlwave-get-routine-info-from-buffers
5061 (reverse (buffer-list)))))
5062 ((null idlwave-scan-all-buffers-for-routine-info)
5063 ;; Don't scan any buffers
5064 (setq res nil))
5066 ;; Just scan this buffer
5067 (if (derived-mode-p 'idlwave-mode)
5068 (progn
5069 (message "Scanning current buffer...")
5070 (setq res (idlwave-get-routine-info-from-buffers
5071 (list (current-buffer))))))))
5072 ;; Put the result into the correct variable
5073 (setq idlwave-buffer-routines
5074 (idlwave-sintern-rinfo-list res 'set))))
5076 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
5077 "Put the different sources for routine information together."
5078 ;; The sequence here is important because earlier definitions shadow
5079 ;; later ones. We assume that if things in the buffers are newer
5080 ;; then in the shell of the system, they are meant to be different.
5081 (setcdr idlwave-last-system-routine-info-cons-cell
5082 (append idlwave-buffer-routines
5083 idlwave-compiled-routines
5084 idlwave-library-catalog-routines
5085 idlwave-user-catalog-routines))
5086 (setq idlwave-class-alist nil)
5088 ;; Give a message with information about the number of routines we have.
5089 (unless quiet
5090 (message
5091 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5092 (length idlwave-buffer-routines)
5093 (length idlwave-compiled-routines)
5094 (length idlwave-library-catalog-routines)
5095 (length idlwave-user-catalog-routines)
5096 (length idlwave-system-routines)))
5097 (if run-hook
5098 (run-hooks 'idlwave-update-rinfo-hook)))
5100 (defun idlwave-class-alist ()
5101 "Return the class alist - make it if necessary."
5102 (or idlwave-class-alist
5103 (let (class)
5104 (loop for x in idlwave-routines do
5105 (when (and (setq class (nth 2 x))
5106 (not (assq class idlwave-class-alist)))
5107 (push (list class) idlwave-class-alist)))
5108 idlwave-class-alist)))
5110 ;; Three functions for the hooks
5111 (defun idlwave-save-buffer-update ()
5112 (idlwave-update-current-buffer-info 'save-buffer))
5113 (defun idlwave-kill-buffer-update ()
5114 (idlwave-update-current-buffer-info 'kill-buffer))
5115 (defun idlwave-new-buffer-update ()
5116 (idlwave-update-current-buffer-info 'find-file))
5118 (defun idlwave-update-current-buffer-info (why)
5119 "Update `idlwave-routines' for current buffer.
5120 Can run from `after-save-hook'."
5121 (when (and (derived-mode-p 'idlwave-mode)
5122 (or (eq t idlwave-auto-routine-info-updates)
5123 (memq why idlwave-auto-routine-info-updates))
5124 idlwave-scan-all-buffers-for-routine-info
5125 idlwave-routines)
5126 (condition-case nil
5127 (let (routines)
5128 (idlwave-replace-buffer-routine-info
5129 (buffer-file-name)
5130 (if (eq why 'kill-buffer)
5132 (setq routines
5133 (idlwave-sintern-rinfo-list
5134 (idlwave-get-routine-info-from-buffers
5135 (list (current-buffer))) 'set))))
5136 (idlwave-concatenate-rinfo-lists 'quiet)
5137 routines)
5138 (error nil))))
5140 (defun idlwave-replace-buffer-routine-info (file new)
5141 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5142 (let ((list idlwave-buffer-routines)
5143 found)
5144 (while list
5145 ;; The following test uses eq to make sure it works correctly
5146 ;; when two buffers visit the same file. Then the file names
5147 ;; will be equal, but not eq.
5148 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
5149 (progn
5150 (setcar list nil)
5151 (setq found t))
5152 (if found
5153 ;; End of that section reached. Jump.
5154 (setq list nil)))
5155 (setq list (cdr list)))
5156 (setq idlwave-buffer-routines
5157 (append new (delq nil idlwave-buffer-routines)))))
5159 ;;----- Scanning buffers -------------------
5161 (defun idlwave-get-routine-info-from-buffers (buffers)
5162 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5163 (let (buf routine-lists res)
5164 (save-excursion
5165 (while (setq buf (pop buffers))
5166 (set-buffer buf)
5167 (if (and (derived-mode-p 'idlwave-mode)
5168 buffer-file-name)
5169 ;; yes, this buffer has the right mode.
5170 (progn (setq res (condition-case nil
5171 (idlwave-get-buffer-routine-info)
5172 (error nil)))
5173 (push res routine-lists)))))
5174 ;; Concatenate the individual lists and return the result
5175 (apply 'nconc routine-lists)))
5177 (defun idlwave-get-buffer-routine-info ()
5178 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5179 (let* ((case-fold-search t)
5180 routine-list string entry)
5181 (save-excursion
5182 (save-restriction
5183 (widen)
5184 (goto-char (point-min))
5185 (while (re-search-forward
5186 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
5187 (setq string (buffer-substring-no-properties
5188 (match-beginning 0)
5189 (progn
5190 (idlwave-end-of-statement)
5191 (point))))
5192 (setq entry (idlwave-parse-definition string))
5193 (push entry routine-list))))
5194 routine-list))
5196 (defvar idlwave-scanning-lib-dir)
5197 (defvar idlwave-scanning-lib)
5198 (defun idlwave-parse-definition (string)
5199 "Parse a module definition."
5200 (let ((case-fold-search t)
5201 start name args type keywords class)
5202 ;; Remove comments
5203 (while (string-match ";.*" string)
5204 (setq string (replace-match "" t t string)))
5205 ;; Remove the continuation line stuff
5206 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5207 (setq string (replace-match "\\1 " t nil string)))
5208 (while (string-match "\n" string)
5209 (setq string (replace-match " " t nil string)))
5210 ;; Match the name and type.
5211 (when (string-match
5212 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5213 (setq start (match-end 0))
5214 (setq type (downcase (match-string 1 string)))
5215 (if (match-beginning 3)
5216 (setq class (match-string 3 string)))
5217 (setq name (match-string 4 string)))
5218 ;; Match normal args and keyword args
5219 (while (string-match
5220 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5221 string start)
5222 (setq start (match-end 0))
5223 (if (match-beginning 3)
5224 (push (match-string 1 string) keywords)
5225 (push (match-string 1 string) args)))
5226 ;; Normalize and sort.
5227 (setq args (nreverse args))
5228 (setq keywords (sort keywords (lambda (a b)
5229 (string< (downcase a) (downcase b)))))
5230 ;; Make and return the entry
5231 ;; We don't know which argument are optional, so this information
5232 ;; will not be contained in the calling sequence.
5233 (list name
5234 (if (equal type "pro") 'pro 'fun)
5235 class
5236 (cond ((not (boundp 'idlwave-scanning-lib))
5237 (list 'buffer (buffer-file-name)))
5238 ; ((string= (downcase (file-name-base))
5239 ; (downcase name))
5240 ; (list 'lib))
5241 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5242 (t (list 'user (file-name-nondirectory (buffer-file-name))
5243 idlwave-scanning-lib-dir "UserLib")))
5244 (concat
5245 (if (string= type "function") "Result = " "")
5246 (if class "Obj ->[%s::]" "")
5247 "%s"
5248 (if args
5249 (concat
5250 (if (string= type "function") "(" ", ")
5251 (mapconcat 'identity args ", ")
5252 (if (string= type "function") ")" ""))))
5253 (if keywords
5254 (cons nil (mapcar 'list keywords)) ;No help file
5255 nil))))
5258 ;;----- Scanning the user catalog -------------------
5260 (defun idlwave-sys-dir ()
5261 "Return the syslib directory, or a dummy that never matches."
5262 (cond
5263 ((and idlwave-system-directory
5264 (not (string= idlwave-system-directory "")))
5265 idlwave-system-directory)
5266 ((getenv "IDL_DIR"))
5267 (t "@@@@@@@@")))
5270 (defun idlwave-create-user-catalog-file (&optional arg)
5271 "Scan all files on selected dirs of IDL search path for routine information.
5273 A widget checklist will allow you to choose the directories. Write
5274 the result as a file `idlwave-user-catalog-file'. When this file
5275 exists, it will be automatically loaded to give routine information
5276 about library routines. With ARG, just rescan the same directories
5277 as last time - so no widget will pop up."
5278 (interactive "P")
5279 ;; Make sure the file is loaded if it exists.
5280 (if (and (stringp idlwave-user-catalog-file)
5281 (file-regular-p idlwave-user-catalog-file))
5282 (condition-case nil
5283 (load-file idlwave-user-catalog-file)
5284 (error nil)))
5285 ;; Make sure the file name makes sense
5286 (unless (and (stringp idlwave-user-catalog-file)
5287 (> (length idlwave-user-catalog-file) 0)
5288 (file-accessible-directory-p
5289 (file-name-directory idlwave-user-catalog-file))
5290 (not (string= "" (file-name-nondirectory
5291 idlwave-user-catalog-file))))
5292 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5294 (cond
5295 ;; Rescan the known directories
5296 ((and arg idlwave-path-alist
5297 (consp (car idlwave-path-alist)))
5298 (idlwave-scan-user-lib-files idlwave-path-alist))
5300 ;; Expand the directories from library-path and run the widget
5301 (idlwave-library-path
5302 (idlwave-display-user-catalog-widget
5303 (if idlwave-true-path-alist
5304 ;; Propagate any flags on the existing path-alist
5305 (mapcar (lambda (x)
5306 (let ((path-entry (assoc (file-truename x)
5307 idlwave-true-path-alist)))
5308 (if path-entry
5309 (cons x (cdr path-entry))
5310 (list x))))
5311 (idlwave-expand-path idlwave-library-path))
5312 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5314 ;; Ask the shell for the path and then run the widget
5316 (message "Asking the shell for IDL path...")
5317 (require 'idlw-shell)
5318 (idlwave-shell-send-command idlwave-shell-path-query
5319 '(idlwave-user-catalog-command-hook nil)
5320 'hide))))
5323 ;; Parse shell path information and select among it.
5324 (defun idlwave-user-catalog-command-hook (&optional arg)
5325 ;; Command hook used by `idlwave-create-user-catalog-file'.
5326 (if arg
5327 ;; Scan immediately
5328 (idlwave-scan-user-lib-files idlwave-path-alist)
5329 ;; Set the path and display the widget
5330 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5331 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5332 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5334 (defconst idlwave-user-catalog-widget-help-string
5335 "This is the front-end to the creation of the IDLWAVE user catalog.
5336 Please select the directories on IDL's search path from which you
5337 would like to extract routine information, to be stored in the file:
5341 If this is not the correct file, first set variable
5342 `idlwave-user-catalog-file', and call this command again.
5344 N.B. Many libraries include pre-scanned catalog files
5345 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5346 not be scanned. You can scan your own libraries off-line using the
5347 perl script `idlwave_catalog'.
5349 After selecting the directories, choose [Scan & Save] to scan the library
5350 directories and save the routine info.
5351 \n")
5353 (defvar idlwave-widget)
5354 (defvar widget-keymap)
5355 (defun idlwave-display-user-catalog-widget (dirs-list)
5356 "Create the widget to select IDL search path directories for scanning."
5357 (interactive)
5358 (require 'widget)
5359 (require 'wid-edit)
5360 (unless dirs-list
5361 (error "Don't know IDL's search path"))
5363 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5364 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5365 (kill-all-local-variables)
5366 (make-local-variable 'idlwave-widget)
5367 (widget-insert (format idlwave-user-catalog-widget-help-string
5368 idlwave-user-catalog-file))
5370 (widget-create 'push-button
5371 :notify 'idlwave-widget-scan-user-lib-files
5372 "Scan & Save")
5373 (widget-insert " ")
5374 (widget-create 'push-button
5375 :notify 'idlwave-delete-user-catalog-file
5376 "Delete File")
5377 (widget-insert " ")
5378 (widget-create 'push-button
5379 :notify
5380 (lambda (&rest ignore)
5381 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5382 (dolist (x path-list)
5383 (unless (memq 'lib (cdr x))
5384 (idlwave-path-alist-add-flag x 'user)))
5385 (idlwave-display-user-catalog-widget path-list)))
5386 "Select All Non-Lib")
5387 (widget-insert " ")
5388 (widget-create 'push-button
5389 :notify
5390 (lambda (&rest ignore)
5391 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5392 (dolist (x path-list)
5393 (idlwave-path-alist-remove-flag x 'user))
5394 (idlwave-display-user-catalog-widget path-list)))
5395 "Deselect All")
5396 (widget-insert " ")
5397 (widget-create 'push-button
5398 :notify (lambda (&rest ignore)
5399 (kill-buffer (current-buffer)))
5400 "Quit")
5401 (widget-insert "\n\n")
5403 (widget-insert "Select Directories: \n")
5405 (setq idlwave-widget
5406 (apply 'widget-create
5407 'checklist
5408 :value (delq nil (mapcar (lambda (x)
5409 (if (memq 'user (cdr x))
5410 (car x)))
5411 dirs-list))
5412 :greedy t
5413 :tag "List of directories"
5414 (mapcar (lambda (x)
5415 (list 'item
5416 (if (memq 'lib (cdr x))
5417 (concat "[LIB] " (car x) )
5418 (car x)))) dirs-list)))
5419 (widget-put idlwave-widget :path-dirs dirs-list)
5420 (widget-insert "\n")
5421 (use-local-map widget-keymap)
5422 (widget-setup)
5423 (goto-char (point-min))
5424 (delete-other-windows))
5426 (defun idlwave-delete-user-catalog-file (&rest ignore)
5427 (if (yes-or-no-p
5428 (format "Delete file %s " idlwave-user-catalog-file))
5429 (progn
5430 (delete-file idlwave-user-catalog-file)
5431 (message "%s has been deleted" idlwave-user-catalog-file))))
5433 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5434 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5435 (let* ((widget idlwave-widget)
5436 (selected-dirs (widget-value widget))
5437 (path-alist (widget-get widget :path-dirs))
5438 (this-path-alist path-alist)
5439 dir-entry)
5440 (while (setq dir-entry (pop this-path-alist))
5441 (if (member
5442 (if (memq 'lib (cdr dir-entry))
5443 (concat "[LIB] " (car dir-entry))
5444 (car dir-entry))
5445 selected-dirs)
5446 (idlwave-path-alist-add-flag dir-entry 'user)
5447 (idlwave-path-alist-remove-flag dir-entry 'user)))
5448 (idlwave-scan-user-lib-files path-alist)))
5450 (defvar font-lock-mode)
5451 (defun idlwave-scan-user-lib-files (path-alist)
5452 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5453 (let* ((idlwave-scanning-lib t)
5454 (idlwave-scanning-lib-dir "")
5455 (idlwave-completion-case nil)
5456 dirs-alist dir files file)
5457 (setq idlwave-user-catalog-routines nil
5458 idlwave-path-alist path-alist ; for library-path instead
5459 idlwave-true-path-alist nil)
5460 (if idlwave-auto-write-paths (idlwave-write-paths))
5461 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5462 (idlwave-mode)
5463 (setq dirs-alist (reverse path-alist))
5464 (while (setq dir (pop dirs-alist))
5465 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5466 (setq dir (car dir))
5467 (setq idlwave-scanning-lib-dir dir)
5468 (when (file-directory-p dir)
5469 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5470 (while (setq file (pop files))
5471 (when (file-regular-p file)
5472 (if (not (file-readable-p file))
5473 (message "Skipping %s (no read permission)" file)
5474 (message "Scanning %s..." file)
5475 (erase-buffer)
5476 (insert-file-contents file 'visit)
5477 (setq idlwave-user-catalog-routines
5478 (append (idlwave-get-routine-info-from-buffers
5479 (list (current-buffer)))
5480 idlwave-user-catalog-routines)))))))))
5481 (message "Creating user catalog file...")
5482 (kill-buffer "*idlwave-scan.pro*")
5483 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5484 (let ((font-lock-maximum-size 0)
5485 (auto-mode-alist nil))
5486 (find-file idlwave-user-catalog-file))
5487 (if (and (boundp 'font-lock-mode)
5488 font-lock-mode)
5489 (font-lock-mode 0))
5490 (erase-buffer)
5491 (insert ";; IDLWAVE user catalog file\n")
5492 (insert (format ";; Created %s\n\n" (current-time-string)))
5494 ;; Define the routine info list
5495 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5496 (let ((standard-output (current-buffer)))
5497 (mapc (lambda (x)
5498 (insert "\n ")
5499 (prin1 x)
5500 (goto-char (point-max)))
5501 idlwave-user-catalog-routines))
5502 (insert (format "))\n\n;;; %s ends here\n"
5503 (file-name-nondirectory idlwave-user-catalog-file)))
5504 (goto-char (point-min))
5505 ;; Save the buffer
5506 (save-buffer 0)
5507 (kill-buffer (current-buffer)))
5508 (message "Creating user catalog file...done")
5509 (message "Info for %d routines saved in %s"
5510 (length idlwave-user-catalog-routines)
5511 idlwave-user-catalog-file)
5512 (sit-for 2)
5513 (idlwave-update-routine-info t))
5515 (defun idlwave-read-paths ()
5516 (if (and (stringp idlwave-path-file)
5517 (file-regular-p idlwave-path-file))
5518 (condition-case nil
5519 (load idlwave-path-file t t t)
5520 (error nil))))
5522 (defun idlwave-write-paths ()
5523 (interactive)
5524 (when (and idlwave-path-alist idlwave-system-directory)
5525 (let ((font-lock-maximum-size 0)
5526 (auto-mode-alist nil))
5527 (find-file idlwave-path-file))
5528 (if (and (boundp 'font-lock-mode)
5529 font-lock-mode)
5530 (font-lock-mode 0))
5531 (erase-buffer)
5532 (insert ";; IDLWAVE paths\n")
5533 (insert (format ";; Created %s\n\n" (current-time-string)))
5534 ;; Define the variable which knows the value of "!DIR"
5535 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5536 idlwave-system-directory))
5538 ;; Define the variable which contains a list of all scanned directories
5539 (insert "\n(setq idlwave-path-alist\n '(")
5540 (let ((standard-output (current-buffer)))
5541 (mapc (lambda (x)
5542 (insert "\n ")
5543 (prin1 x)
5544 (goto-char (point-max)))
5545 idlwave-path-alist))
5546 (insert "))\n")
5547 (save-buffer 0)
5548 (kill-buffer (current-buffer))))
5551 (defun idlwave-expand-path (path &optional default-dir)
5552 ;; Expand parts of path starting with '+' recursively into directory list.
5553 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5554 (message "Expanding path...")
5555 (let (path1 dir recursive)
5556 (while (setq dir (pop path))
5557 (if (setq recursive (string= (substring dir 0 1) "+"))
5558 (setq dir (substring dir 1)))
5559 (if (and recursive
5560 (not (file-name-absolute-p dir)))
5561 (setq dir (expand-file-name dir default-dir)))
5562 (if recursive
5563 ;; Expand recursively
5564 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5565 ;; Keep unchanged
5566 (push dir path1)))
5567 (message "Expanding path...done")
5568 (nreverse path1)))
5570 (defun idlwave-recursive-directory-list (dir)
5571 ;; Return a list of all directories below DIR, including DIR itself
5572 (let ((path (list dir)) path1 file files)
5573 (while (setq dir (pop path))
5574 (when (file-directory-p dir)
5575 (setq files (nreverse (directory-files dir t "[^.]")))
5576 (while (setq file (pop files))
5577 (if (file-directory-p file)
5578 (push (file-name-as-directory file) path)))
5579 (push dir path1)))
5580 path1))
5583 ;;----- Scanning the library catalogs ------------------
5588 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5589 "Scan for library catalog files (.idlwave_catalog) and ingest.
5591 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5592 instead, if present) are searched. Print MESSAGE-BASE along with the
5593 libraries being loaded, if passed, and skip loading/normalizing if
5594 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5595 be set to nil to disable library catalog scanning."
5596 (when idlwave-use-library-catalogs
5597 (let ((dirs
5598 (if idlwave-library-path
5599 (idlwave-expand-path idlwave-library-path)
5600 (mapcar 'car idlwave-path-alist)))
5601 (old-libname "")
5602 dir-entry dir catalog all-routines)
5603 (if message-base (message message-base))
5604 (while (setq dir (pop dirs))
5605 (catch 'continue
5606 (when (file-readable-p
5607 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5608 (unless no-load
5609 (setq idlwave-library-catalog-routines nil)
5610 ;; Load the catalog file
5611 (condition-case nil
5612 (load catalog t t t)
5613 (error (throw 'continue t)))
5614 (when (and
5615 message-base
5616 (not (string= idlwave-library-catalog-libname
5617 old-libname)))
5618 (message "%s" (concat message-base
5619 idlwave-library-catalog-libname))
5620 (setq old-libname idlwave-library-catalog-libname))
5621 (when idlwave-library-catalog-routines
5622 (setq all-routines
5623 (append
5624 (idlwave-sintern-rinfo-list
5625 idlwave-library-catalog-routines 'sys dir)
5626 all-routines))))
5628 ;; Add a 'lib flag if on path-alist
5629 (when (and idlwave-path-alist
5630 (setq dir-entry (assoc dir idlwave-path-alist)))
5631 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5632 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5633 (if message-base (message (concat message-base "done"))))))
5635 ;;----- Communicating with the Shell -------------------
5637 ;; First, here is the idl program which can be used to query IDL for
5638 ;; defined routines.
5639 (defconst idlwave-routine-info.pro
5641 ;; START OF IDLWAVE SUPPORT ROUTINES
5642 pro idlwave_print_safe,item,limit
5643 catch,err
5644 if err ne 0 then begin
5645 print,'Could not print item.'
5646 return
5647 endif
5648 if n_elements(item) gt limit then $
5649 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5650 else print,item
5653 pro idlwave_print_info_entry,name,func=func,separator=sep
5654 ;; See if it's an object method
5655 if name eq '' then return
5656 func = keyword_set(func)
5657 methsep = strpos(name,'::')
5658 meth = methsep ne -1
5660 ;; Get routine info
5661 pars = routine_info(name,/parameters,functions=func)
5662 source = routine_info(name,/source,functions=func)
5663 nargs = pars.num_args
5664 nkw = pars.num_kw_args
5665 if nargs gt 0 then args = pars.args
5666 if nkw gt 0 then kwargs = pars.kw_args
5668 ;; Trim the class, and make the name
5669 if meth then begin
5670 class = strmid(name,0,methsep)
5671 name = strmid(name,methsep+2,strlen(name)-1)
5672 if nargs gt 0 then begin
5673 ;; remove the self argument
5674 wh = where(args ne 'SELF',nargs)
5675 if nargs gt 0 then args = args[wh]
5676 endif
5677 endif else begin
5678 ;; No class, just a normal routine.
5679 class = \"\"
5680 endelse
5682 ;; Calling sequence
5683 cs = \"\"
5684 if func then cs = 'Result = '
5685 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5686 cs = cs + '%s'
5687 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5688 if nargs gt 0 then begin
5689 for j=0,nargs-1 do begin
5690 cs = cs + args[j]
5691 if j lt nargs-1 then cs = cs + ', '
5692 endfor
5694 if func then cs = cs + ')'
5695 ;; Keyword arguments
5696 kwstring = ''
5697 if nkw gt 0 then begin
5698 for j=0,nkw-1 do begin
5699 kwstring = kwstring + ' ' + kwargs[j]
5700 endfor
5701 endif
5703 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5705 print,ret + ': ' + name + sep + class + sep + source[0].path $
5706 + sep + cs + sep + kwstring
5709 pro idlwave_routine_info,file
5710 on_error,1
5711 sep = '<@>'
5712 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5713 all = routine_info()
5714 fileQ=n_elements(file) ne 0
5715 if fileQ then file=strtrim(file,2)
5716 for i=0L,n_elements(all)-1L do begin
5717 if fileQ then begin
5718 if (routine_info(all[i],/SOURCE)).path eq file then $
5719 idlwave_print_info_entry,all[i],separator=sep
5720 endif else idlwave_print_info_entry,all[i],separator=sep
5721 endfor
5722 all = routine_info(/functions)
5723 for i=0L,n_elements(all)-1L do begin
5724 if fileQ then begin
5725 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5726 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5727 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5728 endfor
5729 print,'>>>END OF IDLWAVE ROUTINE INFO'
5732 pro idlwave_get_sysvars
5733 on_error,1
5734 catch,error_status
5735 if error_status ne 0 then begin
5736 print, 'Cannot get info about system variables'
5737 endif else begin
5738 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5739 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5740 v = strsplit(s,' +',/regex,/extract) ; get variables
5741 for i=0L,n_elements(v)-1 do begin
5742 t = [''] ; get tag list
5743 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5744 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5745 endfor
5746 endelse
5749 pro idlwave_get_class_tags, class
5750 res = execute('tags=tag_names({'+class+'})')
5751 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5753 ;; END OF IDLWAVE SUPPORT ROUTINES
5755 "The IDL programs to get info from the shell.")
5757 (defvar idlwave-idlwave_routine_info-compiled nil
5758 "Remember if the routine info procedure is already compiled.")
5760 (defvar idlwave-shell-temp-pro-file)
5761 (defvar idlwave-shell-temp-rinfo-save-file)
5763 (defun idlwave-shell-compile-helper-routines (&optional wait)
5764 (unless (and idlwave-idlwave_routine_info-compiled
5765 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5766 (with-current-buffer (idlwave-find-file-noselect
5767 (idlwave-shell-temp-file 'pro))
5768 (erase-buffer)
5769 (insert idlwave-routine-info.pro)
5770 (save-buffer 0))
5771 (idlwave-shell-send-command
5772 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
5773 nil 'hide wait)
5774 (idlwave-shell-send-command
5775 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5776 (idlwave-shell-temp-file 'rinfo))
5777 nil 'hide)
5778 (setq idlwave-idlwave_routine_info-compiled t))
5780 ;; Restore if necessary. Must use execute to hide lame routine_info
5781 ;; errors on undefined routine
5782 (idlwave-shell-send-command
5783 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5784 idlwave-shell-temp-rinfo-save-file
5785 idlwave-shell-temp-rinfo-save-file)
5786 nil 'hide))
5789 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5790 "Query the shell for routine_info of compiled modules and update the lists."
5791 ;; Save and compile the procedure. The compiled procedure is then
5792 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5793 ;; need to test for and possibly RESTORE the procedure each time we
5794 ;; use it, since the user may have killed or redefined it. In
5795 ;; particular, .RESET_SESSION will kill all user procedures. If
5796 ;; FILE is set, only update routine info for routines in that file.
5798 (idlwave-shell-compile-helper-routines wait)
5799 ; execute the routine_info procedure, and analyze the output
5800 (idlwave-shell-send-command
5801 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
5802 `(progn
5803 (idlwave-shell-routine-info-filter)
5804 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5805 'hide wait))
5807 ;; ---------------------------------------------------------------------------
5809 ;; Completion and displaying routine calling sequences
5811 (defvar idlwave-completion-help-info nil)
5812 (defvar idlwave-completion-help-links nil)
5813 (defvar idlwave-current-obj_new-class nil)
5814 (defvar idlwave-complete-special nil)
5815 (defvar method-selector)
5816 (defvar class-selector)
5817 (defvar type-selector)
5818 (defvar super-classes)
5820 (defun idlwave-complete (&optional arg module class)
5821 "Complete a function, procedure or keyword name at point.
5822 This function is smart and figures out what can be completed
5823 at this point.
5824 - At the beginning of a statement it completes procedure names.
5825 - In the middle of a statement it completes function names.
5826 - After a `(' or `,' in the argument list of a function or procedure,
5827 it completes a keyword of the relevant function or procedure.
5828 - In the first arg of `OBJ_NEW', it completes a class name.
5830 When several completions are possible, a list will be displayed in
5831 the *Completions* buffer. If this list is too long to fit into the
5832 window, scrolling can be achieved by repeatedly pressing
5833 \\[idlwave-complete].
5835 The function also knows about object methods. When it needs a class
5836 name, the action depends upon `idlwave-query-class', which see. You
5837 can force IDLWAVE to ask you for a class name with a
5838 \\[universal-argument] prefix argument to this command.
5840 See also the variables `idlwave-keyword-completion-adds-equal' and
5841 `idlwave-function-completion-adds-paren'.
5843 The optional ARG can be used to specify the completion type in order
5844 to override IDLWAVE's idea of what should be completed at point.
5845 Possible values are:
5847 0 <=> query for the completion type
5848 1 <=> 'procedure
5849 2 <=> 'procedure-keyword
5850 3 <=> 'function
5851 4 <=> 'function-keyword
5852 5 <=> 'procedure-method
5853 6 <=> 'procedure-method-keyword
5854 7 <=> 'function-method
5855 8 <=> 'function-method-keyword
5856 9 <=> 'class
5858 As a special case, the universal argument C-u forces completion of
5859 function names in places where the default would be a keyword.
5861 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5862 completion.
5864 For Lisp programmers only:
5865 When we force a keyword, optional argument MODULE can contain the module name.
5866 When we force a method or a method keyword, CLASS can specify the class."
5867 (interactive "P")
5868 (idlwave-routines)
5869 (let* ((where-list
5870 (if (and arg
5871 (or (and (integerp arg) (not (equal arg '(16))))
5872 (symbolp arg)))
5873 (idlwave-make-force-complete-where-list arg module class)
5874 (idlwave-where)))
5875 (what (nth 2 where-list))
5876 (idlwave-force-class-query (equal arg '(4)))
5877 (completion-regexp-list
5878 (if (equal arg '(16))
5879 (list (read-string (concat "Completion Regexp: "))))))
5881 (if (and module (string-match "::" module))
5882 (setq class (substring module 0 (match-beginning 0))
5883 module (substring module (match-end 0))))
5885 (cond
5887 ((and (null arg)
5888 (eq (car-safe last-command) 'idlwave-display-completion-list)
5889 (get-buffer-window "*Completions*"))
5890 (setq this-command last-command)
5891 (idlwave-scroll-completions))
5893 ;; Complete a filename in quotes
5894 ((and (idlwave-in-quote)
5895 (not (eq what 'class)))
5896 (idlwave-complete-filename))
5898 ;; Check for any special completion functions
5899 ((and idlwave-complete-special
5900 (idlwave-call-special idlwave-complete-special)))
5902 ((null what)
5903 (error "Nothing to complete here"))
5905 ;; Complete a class
5906 ((eq what 'class)
5907 (setq idlwave-completion-help-info '(class))
5908 (idlwave-complete-class))
5910 ((eq what 'procedure)
5911 ;; Complete a procedure name
5912 (let* ((cw-list (nth 3 where-list))
5913 (class-selector (idlwave-determine-class cw-list 'pro))
5914 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5915 (idlwave-all-class-inherits class-selector)))
5916 (isa (concat "procedure" (if class-selector "-method" "")))
5917 (type-selector 'pro))
5918 (setq idlwave-completion-help-info
5919 (list 'routine nil type-selector class-selector nil super-classes))
5920 (idlwave-complete-in-buffer
5921 'procedure (if class-selector 'method 'routine)
5922 (idlwave-routines) 'idlwave-selector
5923 (format "Select a %s name%s"
5925 (if class-selector
5926 (format " (class is %s)"
5927 (if (eq class-selector t)
5928 "unknown" class-selector))
5929 ""))
5931 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5933 ((eq what 'function)
5934 ;; Complete a function name
5935 (let* ((cw-list (nth 3 where-list))
5936 (class-selector (idlwave-determine-class cw-list 'fun))
5937 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5938 (idlwave-all-class-inherits class-selector)))
5939 (isa (concat "function" (if class-selector "-method" "")))
5940 (type-selector 'fun))
5941 (setq idlwave-completion-help-info
5942 (list 'routine nil type-selector class-selector nil super-classes))
5943 (idlwave-complete-in-buffer
5944 'function (if class-selector 'method 'routine)
5945 (idlwave-routines) 'idlwave-selector
5946 (format "Select a %s name%s"
5948 (if class-selector
5949 (format " (class is %s)"
5950 (if (eq class-selector t)
5951 "unknown" class-selector))
5952 ""))
5954 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5956 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5957 (equal arg '(4)))
5958 (idlwave-complete 3))
5960 ((eq what 'procedure-keyword)
5961 ;; Complete a procedure keyword
5962 (let* ((where (nth 3 where-list))
5963 (name (car where))
5964 (method-selector name)
5965 (type-selector 'pro)
5966 (class (idlwave-determine-class where 'pro))
5967 (class-selector class)
5968 (super-classes (idlwave-all-class-inherits class-selector))
5969 (isa (format "procedure%s-keyword" (if class "-method" "")))
5970 (entry (idlwave-best-rinfo-assq
5971 name 'pro class (idlwave-routines)))
5972 (system (if entry (eq (car (nth 3 entry)) 'system)))
5973 (list (idlwave-entry-keywords entry 'do-link)))
5974 (unless (or entry (eq class t))
5975 (error "Nothing known about procedure %s"
5976 (idlwave-make-full-name class name)))
5977 (setq list (idlwave-fix-keywords name 'pro class list
5978 super-classes system))
5979 (unless list (error "No keywords available for procedure %s"
5980 (idlwave-make-full-name class name)))
5981 (setq idlwave-completion-help-info
5982 (list 'keyword name type-selector class-selector entry super-classes))
5983 (idlwave-complete-in-buffer
5984 'keyword 'keyword list nil
5985 (format "Select keyword for procedure %s%s"
5986 (idlwave-make-full-name class name)
5987 (if (or (member '("_EXTRA") list)
5988 (member '("_REF_EXTRA") list))
5989 " (note _EXTRA)" ""))
5991 'idlwave-attach-keyword-classes)))
5993 ((eq what 'function-keyword)
5994 ;; Complete a function keyword
5995 (let* ((where (nth 3 where-list))
5996 (name (car where))
5997 (method-selector name)
5998 (type-selector 'fun)
5999 (class (idlwave-determine-class where 'fun))
6000 (class-selector class)
6001 (super-classes (idlwave-all-class-inherits class-selector))
6002 (isa (format "function%s-keyword" (if class "-method" "")))
6003 (entry (idlwave-best-rinfo-assq
6004 name 'fun class (idlwave-routines)))
6005 (system (if entry (eq (car (nth 3 entry)) 'system)))
6006 (list (idlwave-entry-keywords entry 'do-link))
6007 msg-name)
6008 (unless (or entry (eq class t))
6009 (error "Nothing known about function %s"
6010 (idlwave-make-full-name class name)))
6011 (setq list (idlwave-fix-keywords name 'fun class list
6012 super-classes system))
6013 ;; OBJ_NEW: Messages mention the proper Init method
6014 (setq msg-name (if (and (null class)
6015 (string= (upcase name) "OBJ_NEW"))
6016 (concat idlwave-current-obj_new-class
6017 "::Init (via OBJ_NEW)")
6018 (idlwave-make-full-name class name)))
6019 (unless list (error "No keywords available for function %s"
6020 msg-name))
6021 (setq idlwave-completion-help-info
6022 (list 'keyword name type-selector class-selector nil super-classes))
6023 (idlwave-complete-in-buffer
6024 'keyword 'keyword list nil
6025 (format "Select keyword for function %s%s" msg-name
6026 (if (or (member '("_EXTRA") list)
6027 (member '("_REF_EXTRA") list))
6028 " (note _EXTRA)" ""))
6030 'idlwave-attach-keyword-classes)))
6032 (t (error "This should not happen (idlwave-complete)")))))
6034 (defvar idlwave-complete-special nil
6035 "List of special completion functions.
6036 These functions are called for each completion. Each function must
6037 check if its own special completion context is present. If yes, it
6038 should use `idlwave-complete-in-buffer' to do some completion and
6039 return t. If such a function returns t, *no further* attempts to
6040 complete other contexts will be done. If the function returns nil,
6041 other completions will be tried.")
6043 (defun idlwave-call-special (functions &rest args)
6044 (let ((funcs functions)
6045 fun ret)
6046 (catch 'exit
6047 (while (setq fun (pop funcs))
6048 (if (setq ret (apply fun args))
6049 (throw 'exit ret)))
6050 nil)))
6052 (defun idlwave-make-force-complete-where-list (what &optional module class)
6053 ;; Return an artificial WHERE specification to force the completion
6054 ;; routine to complete a specific item independent of context.
6055 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6056 ;; MODULE and CLASS can be used to specify the routine name and class.
6057 ;; The class name will also be found in MODULE if that is like "class::mod".
6058 (let* ((what-list '(("procedure") ("procedure-keyword")
6059 ("function") ("function-keyword")
6060 ("procedure-method") ("procedure-method-keyword")
6061 ("function-method") ("function-method-keyword")
6062 ("class")))
6063 (module (idlwave-sintern-routine-or-method module class))
6064 (class (idlwave-sintern-class class))
6065 (what (cond
6066 ((equal what 0)
6067 (setq what
6068 (intern (completing-read
6069 "Complete what? " what-list nil t))))
6070 ((integerp what)
6071 (setq what (intern (car (nth (1- what) what-list)))))
6072 ((and what
6073 (symbolp what)
6074 (assoc (symbol-name what) what-list))
6075 what)
6076 (t (error "Invalid WHAT"))))
6077 (nil-list '(nil nil nil nil))
6078 (class-list (list nil nil (or class t) nil)))
6080 (cond
6082 ((eq what 'procedure)
6083 (list nil-list nil-list 'procedure nil-list nil))
6085 ((eq what 'procedure-keyword)
6086 (let* ((class-selector nil)
6087 (super-classes nil)
6088 (type-selector 'pro)
6089 (pro (or module
6090 (idlwave-completing-read
6091 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6092 (setq pro (idlwave-sintern-routine pro))
6093 (list nil-list nil-list 'procedure-keyword
6094 (list pro nil nil nil) nil)))
6096 ((eq what 'function)
6097 (list nil-list nil-list 'function nil-list nil))
6099 ((eq what 'function-keyword)
6100 (let* ((class-selector nil)
6101 (super-classes nil)
6102 (type-selector 'fun)
6103 (func (or module
6104 (idlwave-completing-read
6105 "Function: " (idlwave-routines) 'idlwave-selector))))
6106 (setq func (idlwave-sintern-routine func))
6107 (list nil-list nil-list 'function-keyword
6108 (list func nil nil nil) nil)))
6110 ((eq what 'procedure-method)
6111 (list nil-list nil-list 'procedure class-list nil))
6113 ((eq what 'procedure-method-keyword)
6114 (let* ((class (idlwave-determine-class class-list 'pro))
6115 (class-selector class)
6116 (super-classes (idlwave-all-class-inherits class-selector))
6117 (type-selector 'pro)
6118 (pro (or module
6119 (idlwave-completing-read
6120 (format "Procedure in %s class: " class-selector)
6121 (idlwave-routines) 'idlwave-selector))))
6122 (setq pro (idlwave-sintern-method pro))
6123 (list nil-list nil-list 'procedure-keyword
6124 (list pro nil class nil) nil)))
6126 ((eq what 'function-method)
6127 (list nil-list nil-list 'function class-list nil))
6129 ((eq what 'function-method-keyword)
6130 (let* ((class (idlwave-determine-class class-list 'fun))
6131 (class-selector class)
6132 (super-classes (idlwave-all-class-inherits class-selector))
6133 (type-selector 'fun)
6134 (func (or module
6135 (idlwave-completing-read
6136 (format "Function in %s class: " class-selector)
6137 (idlwave-routines) 'idlwave-selector))))
6138 (setq func (idlwave-sintern-method func))
6139 (list nil-list nil-list 'function-keyword
6140 (list func nil class nil) nil)))
6142 ((eq what 'class)
6143 (list nil-list nil-list 'class nil-list nil))
6145 (t (error "Invalid value for WHAT")))))
6147 (defun idlwave-completing-read (&rest args)
6148 ;; Completing read, case insensitive
6149 (let ((old-value (default-value 'completion-ignore-case)))
6150 (unwind-protect
6151 (progn
6152 (setq-default completion-ignore-case t)
6153 (apply 'completing-read args))
6154 (setq-default completion-ignore-case old-value))))
6156 (defvar idlwave-shell-default-directory)
6157 (defun idlwave-complete-filename ()
6158 "Use the comint stuff to complete a file name."
6159 (require 'comint)
6160 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6161 (comint-completion-addsuffix nil)
6162 (default-directory
6163 (if (and (boundp 'idlwave-shell-default-directory)
6164 (stringp idlwave-shell-default-directory)
6165 (file-directory-p idlwave-shell-default-directory))
6166 idlwave-shell-default-directory
6167 default-directory)))
6168 (comint-dynamic-complete-filename)))
6170 (defun idlwave-make-full-name (class name)
6171 ;; Make a fully qualified module name including the class name
6172 (concat (if class (format "%s::" class) "") name))
6174 (defun idlwave-rinfo-assoc (name type class list)
6175 "Like `idlwave-rinfo-assq', but sintern strings first."
6176 (idlwave-rinfo-assq
6177 (idlwave-sintern-routine-or-method name class)
6178 type (idlwave-sintern-class class) list))
6180 (defun idlwave-rinfo-assq (name type class list)
6181 ;; Works like assq, but also checks type and class
6182 (catch 'exit
6183 (let (match)
6184 (while (setq match (assq name list))
6185 (and (or (eq type t)
6186 (eq (nth 1 match) type))
6187 (eq (nth 2 match) class)
6188 (throw 'exit match))
6189 (setq list (cdr (memq match list)))))))
6191 (defun idlwave-rinfo-assq-any-class (name type class list)
6192 ;; Return the first matching method on the inheritance list
6193 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6194 class rtn)
6195 (while classes
6196 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6197 (setq classes nil)))
6198 rtn))
6200 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
6201 keep-system)
6202 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6203 If WITH-FILE is passed, find the best rinfo entry with a file
6204 included. If KEEP-SYSTEM is set, don't prune system for compiled
6205 syslib files."
6206 (let ((twins (idlwave-routine-twins
6207 (idlwave-rinfo-assq-any-class name type class list)
6208 list))
6209 syslibp)
6210 (when (> (length twins) 1)
6211 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
6212 (if (and (null keep-system)
6213 (eq 'system (car (nth 3 (car twins))))
6214 (setq syslibp (idlwave-any-syslib (cdr twins)))
6215 (not (equal 1 syslibp)))
6216 ;; Its a compiled syslib, so we need to remove the system entry
6217 (setq twins (cdr twins)))
6218 (if with-file
6219 (setq twins (delq nil
6220 (mapcar (lambda (x)
6221 (if (nth 1 (nth 3 x)) x))
6222 twins)))))
6223 (car twins)))
6225 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
6226 keep-system)
6227 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6228 (idlwave-best-rinfo-assq
6229 (idlwave-sintern-routine-or-method name class)
6230 type (idlwave-sintern-class class) list with-file keep-system))
6232 (defun idlwave-any-syslib (entries)
6233 "Does the entry list ENTRIES contain a syslib entry?
6234 If yes, return the index (>=1)."
6235 (let (file (cnt 0))
6236 (catch 'exit
6237 (while entries
6238 (incf cnt)
6239 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6240 (if (and file (idlwave-syslib-p file))
6241 (throw 'exit cnt)
6242 (setq entries (cdr entries))))
6243 nil)))
6245 (defun idlwave-all-assq (key list)
6246 "Return a list of all associations of Key in LIST."
6247 (let (rtn elt)
6248 (while (setq elt (assq key list))
6249 (push elt rtn)
6250 (setq list (cdr (memq elt list))))
6251 (nreverse rtn)))
6253 (defun idlwave-all-method-classes (method &optional type)
6254 "Return all classes which have a method METHOD.
6255 TYPE is 'fun or 'pro.
6256 When TYPE is not specified, both procedures and functions will be considered."
6257 (if (null method)
6258 (mapcar 'car (idlwave-class-alist))
6259 (let (rtn)
6260 (mapc (lambda (x)
6261 (and (nth 2 x)
6262 (or (not type)
6263 (eq type (nth 1 x)))
6264 (push (nth 2 x) rtn)))
6265 (idlwave-all-assq method (idlwave-routines)))
6266 (idlwave-uniquify rtn))))
6268 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
6269 "Return all classes which have a method METHOD with keyword KEYWORD.
6270 TYPE is 'fun or 'pro.
6271 When TYPE is not specified, both procedures and functions will be considered."
6272 (if (or (null method)
6273 (null keyword))
6275 (let (rtn)
6276 (mapc (lambda (x)
6277 (and (nth 2 x) ; non-nil class
6278 (or (not type) ; correct or unspecified type
6279 (eq type (nth 1 x)))
6280 (assoc keyword (idlwave-entry-keywords x))
6281 (push (nth 2 x) rtn)))
6282 (idlwave-all-assq method (idlwave-routines)))
6283 (idlwave-uniquify rtn))))
6285 (defun idlwave-members-only (list club)
6286 "Return list of all elements in LIST which are also in CLUB."
6287 (let (rtn)
6288 (while list
6289 (if (member (car list) club)
6290 (setq rtn (cons (car list) rtn)))
6291 (setq list (cdr list)))
6292 (nreverse rtn)))
6294 (defun idlwave-nonmembers-only (list club)
6295 "Return list of all elements in LIST which are not in CLUB."
6296 (let (rtn)
6297 (while list
6298 (if (member (car list) club)
6300 (setq rtn (cons (car list) rtn)))
6301 (setq list (cdr list)))
6302 (nreverse rtn)))
6304 (defun idlwave-explicit-class-listed (info)
6305 "Return whether or not the class is listed explicitly, ala a->b::c.
6306 INFO is as returned by `idlwave-what-function' or `-procedure'."
6307 (let ((apos (nth 3 info)))
6308 (if apos
6309 (save-excursion (goto-char apos)
6310 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6312 (defvar idlwave-determine-class-special nil
6313 "List of special functions for determining class.
6314 Must accept two arguments: `apos' and `info'.")
6316 (defun idlwave-determine-class (info type)
6317 ;; Determine the class of a routine call.
6318 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6319 ;; The second element in this structure is the class. When nil, we
6320 ;; return nil. When t, try to get the class from text properties at
6321 ;; the arrow. When the object is "self", we use the class of the
6322 ;; current routine. otherwise prompt the user for a class name.
6323 ;; Also stores the selected class as a text property at the arrow.
6324 ;; TYPE is 'fun or 'pro.
6325 (let* ((class (nth 2 info))
6326 (apos (nth 3 info))
6327 (nassoc (assoc (if (stringp (car info))
6328 (upcase (car info))
6329 (car info))
6330 idlwave-query-class))
6331 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6332 idlwave-query-class))
6333 (query (cond (nassoc (cdr nassoc))
6334 (dassoc (cdr dassoc))
6335 (t t)))
6336 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
6337 (is-self
6338 (and arrow
6339 (save-excursion (goto-char apos)
6340 (forward-word -1)
6341 (let ((case-fold-search t))
6342 (looking-at "self\\>")))))
6343 (force-query idlwave-force-class-query)
6344 store special-class class-alist)
6345 (cond
6346 ((null class) nil)
6347 ((eq t class)
6348 ;; There is an object which would like to know its class
6349 (if (and arrow (get-text-property apos 'idlwave-class)
6350 idlwave-store-inquired-class
6351 (not force-query))
6352 (setq class (get-text-property apos 'idlwave-class)
6353 class (idlwave-sintern-class class)))
6354 (if (and (eq t class) is-self)
6355 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6357 ;; Before prompting, try any special class determination routines
6358 (when (and (eq t class)
6359 idlwave-determine-class-special
6360 (not force-query))
6361 (setq special-class
6362 (idlwave-call-special idlwave-determine-class-special apos))
6363 (if special-class
6364 (setq class (idlwave-sintern-class special-class)
6365 store idlwave-store-inquired-class)))
6367 ;; Prompt for a class, if we need to
6368 (when (and (eq class t)
6369 (or force-query query))
6370 (setq class-alist
6371 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6372 (setq class
6373 (idlwave-sintern-class
6374 (cond
6375 ((and (= (length class-alist) 0) (not force-query))
6376 (error "No classes available with method %s" (car info)))
6377 ((and (= (length class-alist) 1) (not force-query))
6378 (car (car class-alist)))
6380 (setq store idlwave-store-inquired-class)
6381 (idlwave-completing-read
6382 (format "Class%s: " (if (stringp (car info))
6383 (format " for %s method %s"
6384 type (car info))
6385 ""))
6386 class-alist nil nil nil 'idlwave-class-history))))))
6388 ;; Store it, if requested
6389 (when (and class (not (eq t class)))
6390 ;; We have a real class here
6391 (when (and store arrow)
6392 (condition-case ()
6393 (add-text-properties
6394 apos (+ apos 2)
6395 `(idlwave-class ,class face ,idlwave-class-arrow-face
6396 rear-nonsticky t))
6397 (error nil)))
6398 (setf (nth 2 info) class))
6399 ;; Return the class
6400 class)
6401 ;; Default as fallback
6402 (t class))))
6404 (defun idlwave-selector (a)
6405 (and (eq (nth 1 a) type-selector)
6406 (or (and (nth 2 a) (eq class-selector t))
6407 (eq (nth 2 a) class-selector)
6408 (memq (nth 2 a) super-classes))))
6410 (defun idlwave-add-file-link-selector (a)
6411 ;; Record a file link, if any, for the tested names during selection.
6412 (let ((sel (idlwave-selector a)) file)
6413 (if (and sel (setq file (idlwave-entry-has-help a)))
6414 (push (cons (car a) file) idlwave-completion-help-links))
6415 sel))
6418 (defun idlwave-where ()
6419 "Find out where we are.
6420 The return value is a list with the following stuff:
6421 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6423 PRO-LIST (PRO POINT CLASS ARROW)
6424 FUNC-LIST (FUNC POINT CLASS ARROW)
6425 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6426 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6427 be completed here.
6428 LAST-CHAR last relevant character before point (non-white non-comment,
6429 not part of current identifier or leading slash).
6431 In the lists, we have these meanings:
6432 PRO: Procedure name
6433 FUNC: Function name
6434 POINT: Where is this
6435 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6436 ARROW: Location of the arrow"
6437 (idlwave-routines)
6438 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6439 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
6440 (func-entry (idlwave-what-function bos))
6441 (func (car func-entry))
6442 (func-class (nth 1 func-entry))
6443 (func-arrow (nth 2 func-entry))
6444 (func-point (or (nth 3 func-entry) 0))
6445 (func-level (or (nth 4 func-entry) 0))
6446 (pro-entry (idlwave-what-procedure bos))
6447 (pro (car pro-entry))
6448 (pro-class (nth 1 pro-entry))
6449 (pro-arrow (nth 2 pro-entry))
6450 (pro-point (or (nth 3 pro-entry) 0))
6451 (last-char (idlwave-last-valid-char))
6452 (case-fold-search t)
6453 (match-string (buffer-substring bos (point)))
6454 cw cw-mod cw-arrow cw-class cw-point)
6455 (if (< func-point pro-point) (setq func nil))
6456 (cond
6457 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6458 match-string)
6459 (setq cw 'class))
6460 ((string-match
6461 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6462 (if (> pro-point 0)
6463 (buffer-substring pro-point (point))
6464 match-string))
6465 (setq cw 'procedure cw-class pro-class cw-point pro-point
6466 cw-arrow pro-arrow))
6467 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6468 match-string)
6469 nil)
6470 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6471 match-string)
6472 (setq cw 'class))
6473 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6474 match-string)
6475 (setq cw 'class))
6476 ((and func
6477 (> func-point pro-point)
6478 (= func-level 1)
6479 (memq last-char '(?\( ?,)))
6480 (setq cw 'function-keyword cw-mod func cw-point func-point
6481 cw-class func-class cw-arrow func-arrow))
6482 ((and pro (eq last-char ?,))
6483 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6484 cw-class pro-class cw-arrow pro-arrow))
6485 ; ((member last-char '(?\' ?\) ?\] ?!))
6486 ; ;; after these chars, a function makes no sense
6487 ; ;; FIXME: I am sure there can be more in this list
6488 ; ;; FIXME: Do we want to do this at all?
6489 ; nil)
6490 ;; Everywhere else we try a function.
6492 (setq cw 'function)
6493 (save-excursion
6494 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6495 (setq cw-arrow (copy-marker (match-beginning 0))
6496 cw-class (if (match-end 4)
6497 (idlwave-sintern-class (match-string 4))
6498 t))))))
6499 (list (list pro pro-point pro-class pro-arrow)
6500 (list func func-point func-class func-arrow)
6502 (list cw-mod cw-point cw-class cw-arrow)
6503 last-char)))
6505 (defun idlwave-this-word (&optional class)
6506 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6507 (setq class (or class "a-zA-Z0-9$_."))
6508 (save-excursion
6509 (buffer-substring
6510 (progn (skip-chars-backward class) (point))
6511 (progn (skip-chars-forward class) (point)))))
6513 (defun idlwave-what-function (&optional bound)
6514 ;; Find out if point is within the argument list of a function.
6515 ;; The return value is ("function-name" class arrow-start (point) level).
6516 ;; Level is 1 on the top level parentheses, higher further down.
6518 ;; If the optional BOUND is an integer, bound backwards directed
6519 ;; searches to this point.
6521 (catch 'exit
6522 (let (pos
6523 func-point
6524 (cnt 0)
6525 func arrow-start class)
6526 (idlwave-with-special-syntax
6527 (save-restriction
6528 (save-excursion
6529 (narrow-to-region (max 1 (or bound 0)) (point-max))
6530 ;; move back out of the current parenthesis
6531 (while (condition-case nil
6532 (progn (up-list -1) t)
6533 (error nil))
6534 (setq pos (point))
6535 (incf cnt)
6536 (when (and (= (following-char) ?\()
6537 (re-search-backward
6538 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6539 bound t))
6540 (setq func (match-string 2)
6541 func-point (goto-char (match-beginning 2))
6542 pos func-point)
6543 (if (re-search-backward
6544 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6545 (setq arrow-start (copy-marker (match-beginning 0))
6546 class (or (match-string 2) t)))
6547 (throw
6548 'exit
6549 (list
6550 (idlwave-sintern-routine-or-method func class)
6551 (idlwave-sintern-class class)
6552 arrow-start func-point cnt)))
6553 (goto-char pos))
6554 (throw 'exit nil)))))))
6556 (defun idlwave-what-procedure (&optional bound)
6557 ;; Find out if point is within the argument list of a procedure.
6558 ;; The return value is ("procedure-name" class arrow-pos (point)).
6560 ;; If the optional BOUND is an integer, bound backwards directed
6561 ;; searches to this point.
6562 (let ((pos (point)) pro-point
6563 pro class arrow-start string)
6564 (save-excursion
6565 ;;(idlwave-beginning-of-statement)
6566 (idlwave-start-of-substatement 'pre)
6567 (setq string (buffer-substring (point) pos))
6568 (if (string-match
6569 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6570 (setq pro (match-string 1 string)
6571 pro-point (+ (point) (match-beginning 1)))
6572 (if (and (idlwave-skip-object)
6573 (setq string (buffer-substring (point) pos))
6574 (string-match
6575 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6576 string))
6577 (setq pro (if (match-beginning 4)
6578 (match-string 4 string))
6579 pro-point (if (match-beginning 4)
6580 (+ (point) (match-beginning 4))
6581 pos)
6582 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6583 class (or (match-string 3 string) t)))))
6584 (list (idlwave-sintern-routine-or-method pro class)
6585 (idlwave-sintern-class class)
6586 arrow-start
6587 pro-point)))
6589 (defun idlwave-skip-object ()
6590 ;; If there is an object at point, move over it and return t.
6591 (let ((pos (point)))
6592 (if (catch 'exit
6593 (save-excursion
6594 (skip-chars-forward " ") ; white space
6595 (skip-chars-forward "*") ; de-reference
6596 (cond
6597 ((looking-at idlwave-identifier)
6598 (goto-char (match-end 0)))
6599 ((eq (following-char) ?\()
6600 nil)
6601 (t (throw 'exit nil)))
6602 (catch 'endwhile
6603 (while t
6604 (cond ((eq (following-char) ?.)
6605 (forward-char 1)
6606 (if (not (looking-at idlwave-identifier))
6607 (throw 'exit nil))
6608 (goto-char (match-end 0)))
6609 ((memq (following-char) '(?\( ?\[))
6610 (condition-case nil
6611 (forward-list 1)
6612 (error (throw 'exit nil))))
6613 (t (throw 'endwhile t)))))
6614 (if (looking-at "[ \t]*->")
6615 (throw 'exit (setq pos (match-beginning 0)))
6616 (throw 'exit nil))))
6617 (goto-char pos)
6618 nil)))
6620 (defun idlwave-last-valid-char ()
6621 "Return the last character before point which is not white or a comment
6622 and also not part of the current identifier. Since we do this in
6623 order to identify places where keywords are, we consider the initial
6624 `/' of a keyword as part of the identifier.
6625 This function is not general, can only be used for completion stuff."
6626 (catch 'exit
6627 (save-excursion
6628 ;; skip the current identifier
6629 (skip-chars-backward "a-zA-Z0-9_$")
6630 ;; also skip a leading slash which might be belong to the keyword
6631 (if (eq (preceding-char) ?/)
6632 (backward-char 1))
6633 ;; FIXME: does not check if this is a valid identifier
6634 (while t
6635 (skip-chars-backward " \t")
6636 (cond
6637 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6638 ((eq (preceding-char) ?\n)
6639 (beginning-of-line 0)
6640 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6641 ;; continuation line
6642 (goto-char (match-end 1))
6643 (throw 'exit nil)))
6644 (t (throw 'exit (preceding-char))))))))
6646 (defvar idlwave-complete-after-success-form nil
6647 "A form to evaluate after successful completion.")
6648 (defvar idlwave-complete-after-success-form-force nil
6649 "A form to evaluate after completion selection in *Completions* buffer.")
6650 (defconst idlwave-completion-mark (make-marker)
6651 "A mark pointing to the beginning of the completion string.")
6652 (defvar completion-highlight-first-word-only) ;XEmacs.
6654 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6655 &optional prepare-display-function
6656 special-selector)
6657 "Perform TYPE completion of word before point against LIST.
6658 SELECTOR is the PREDICATE argument for the completion function. Show
6659 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6660 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
6661 used only once, for `all-completions', and can be used to, e.g.,
6662 accumulate information on matching completions."
6663 (let* ((completion-ignore-case t)
6664 beg (end (point)) slash part spart completion all-completions
6665 dpart dcompletion)
6667 (unless list
6668 (error (concat prompt ": No completions available")))
6670 ;; What is already in the buffer?
6671 (save-excursion
6672 (skip-chars-backward "a-zA-Z0-9_$")
6673 (setq slash (eq (preceding-char) ?/)
6674 beg (point)
6675 idlwave-complete-after-success-form
6676 (list 'idlwave-after-successful-completion
6677 (list 'quote type) slash beg)
6678 idlwave-complete-after-success-form-force
6679 (list 'idlwave-after-successful-completion
6680 (list 'quote type) slash (list 'quote 'force))))
6682 ;; Try a completion
6683 (setq part (buffer-substring beg end)
6684 dpart (downcase part)
6685 spart (idlwave-sintern stype part)
6686 completion (try-completion part list selector)
6687 dcompletion (if (stringp completion) (downcase completion))
6688 idlwave-completion-help-links nil)
6689 (cond
6690 ((null completion)
6691 ;; nothing available.
6692 (error (concat prompt ": no completion for \"%s\"") part))
6693 ((and (not (equal dpart dcompletion))
6694 (not (eq t completion)))
6695 ;; We can add something
6696 (delete-region beg end)
6697 (insert (if (and (string= part dpart)
6698 (or (not (string= part ""))
6699 idlwave-complete-empty-string-as-lower-case)
6700 (not idlwave-completion-force-default-case))
6701 dcompletion
6702 completion))
6703 (if (eq t (try-completion completion list selector))
6704 ;; Now this is a unique match
6705 (idlwave-after-successful-completion type slash beg))
6707 ((or (eq completion t)
6708 (and (= 1 (length (setq all-completions
6709 (idlwave-uniquify
6710 (all-completions part list
6711 (or special-selector
6712 selector))))))
6713 (equal dpart dcompletion)))
6714 ;; This is already complete
6715 (idlwave-after-successful-completion type slash beg)
6716 (message "%s is already the complete %s" part isa)
6717 nil)
6719 ;; We cannot add something - offer a list.
6720 (message "Making completion list...")
6722 (unless idlwave-completion-help-links ; already set somewhere?
6723 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6724 (let ((link (get-text-property 0 'link (car x))))
6725 (if link
6726 (push (cons (car x) link)
6727 idlwave-completion-help-links))))
6728 list))
6729 (let* ((list all-completions)
6730 ;; "complete" means, this is already a valid completion
6731 (complete (memq spart all-completions))
6732 (completion-highlight-first-word-only t)) ; XEmacs
6733 ;; (completion-fixup-function ; Emacs
6734 ;; (lambda () (and (eq (preceding-char) ?>)
6735 ;; (re-search-backward " <" beg t)))))
6737 (setq list (sort list (lambda (a b)
6738 (string< (downcase a) (downcase b)))))
6739 (if prepare-display-function
6740 (setq list (funcall prepare-display-function list)))
6741 (if (and (string= part dpart)
6742 (or (not (string= part ""))
6743 idlwave-complete-empty-string-as-lower-case)
6744 (not idlwave-completion-force-default-case))
6745 (setq list (mapcar (lambda (x)
6746 (if (listp x)
6747 (setcar x (downcase (car x)))
6748 (setq x (downcase x)))
6750 list)))
6751 (idlwave-display-completion-list list prompt beg complete))
6752 t))))
6754 (defun idlwave-complete-class ()
6755 "Complete a class at point."
6756 (interactive)
6757 ;; Call `idlwave-routines' to make sure the class list will be available
6758 (idlwave-routines)
6759 ;; Check for the special case of completing empty string after pro/function
6760 (if (let ((case-fold-search t))
6761 (save-excursion
6762 (and
6763 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6764 (- (point) 15) t)
6765 (goto-char (point-min))
6766 (re-search-forward
6767 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6768 ;; Yank the full class specification
6769 (insert (match-string 2))
6770 ;; Do the completion, using list gathered from `idlwave-routines'
6771 (idlwave-complete-in-buffer
6772 'class 'class (idlwave-class-alist) nil
6773 "Select a class" "class"
6774 (lambda (list) ;; Push it to help-links if system help available
6775 (mapcar (lambda (x)
6776 (let* ((entry (idlwave-class-info x))
6777 (link (nth 1 (assq 'link entry))))
6778 (if link (push (cons x link)
6779 idlwave-completion-help-links))
6781 list)))))
6783 (defun idlwave-attach-classes (list type show-classes)
6784 ;; Attach the proper class list to a LIST of completion items.
6785 ;; TYPE, when 'kwd, shows classes for method keywords, when
6786 ;; 'class-tag, for class tags, and otherwise for methods.
6787 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6788 (if (or (null show-classes) ; don't want to see classes
6789 (null class-selector) ; not a method call
6790 (and
6791 (stringp class-selector) ; the class is already known
6792 (not super-classes))) ; no possibilities for inheritance
6793 ;; In these cases, we do not have to do anything
6794 list
6795 (let* ((do-prop (and (>= show-classes 0)
6796 (>= emacs-major-version 21)))
6797 (do-buf (not (= show-classes 0)))
6798 ;; (do-dots (featurep 'xemacs))
6799 (do-dots t)
6800 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6801 (cons class-selector super-classes)))
6802 (max (abs show-classes))
6803 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6804 classes nclasses class-info space)
6805 (mapcar
6806 (lambda (x)
6807 ;; get the classes
6808 (if (eq type 'class-tag)
6809 ;; Just one class for tags
6810 (setq classes
6811 (list
6812 (idlwave-class-or-superclass-with-tag class-selector x)))
6813 ;; Multiple classes for method or method-keyword
6814 (setq classes
6815 (if (eq type 'kwd)
6816 (idlwave-all-method-keyword-classes
6817 method-selector x type-selector)
6818 (idlwave-all-method-classes x type-selector)))
6819 (if inherit
6820 (setq classes
6821 (delq nil
6822 (mapcar (lambda (x) (if (memq x inherit) x nil))
6823 classes)))))
6824 (setq nclasses (length classes))
6825 ;; Make the separator between item and class-info
6826 (if do-dots
6827 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6828 (setq space " "))
6829 (if do-buf
6830 ;; We do want info in the buffer
6831 (if (<= nclasses max)
6832 (setq class-info (concat
6833 space
6834 "<" (mapconcat 'identity classes ",") ">"))
6835 (setq class-info (format "%s<%d classes>" space nclasses)))
6836 (setq class-info nil))
6837 (when do-prop
6838 ;; We do want properties
6839 (setq x (copy-sequence x))
6840 (put-text-property 0 (length x)
6841 'help-echo (mapconcat 'identity classes " ")
6843 (if class-info
6844 (list x class-info)
6846 list))))
6848 (defun idlwave-attach-method-classes (list)
6849 ;; Call idlwave-attach-classes with method parameters
6850 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6851 (defun idlwave-attach-keyword-classes (list)
6852 ;; Call idlwave-attach-classes with keyword parameters
6853 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6854 (defun idlwave-attach-class-tag-classes (list)
6855 ;; Call idlwave-attach-classes with class structure tags
6856 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6859 ;;----------------------------------------------------------------------
6860 ;;----------------------------------------------------------------------
6861 ;;----------------------------------------------------------------------
6862 ;;----------------------------------------------------------------------
6863 ;;----------------------------------------------------------------------
6864 (when (featurep 'xemacs)
6865 (defvar rtn)
6866 (defun idlwave-pset (item)
6867 (set 'rtn item)))
6869 (defun idlwave-popup-select (ev list title &optional sort)
6870 "Select an item in LIST with a popup menu.
6871 TITLE is the title to put atop the popup. If SORT is non-nil,
6872 sort the list before displaying."
6873 (let ((maxpopup idlwave-max-popup-menu-items)
6874 rtn menu)
6875 (cond ((null list))
6876 ((= 1 (length list))
6877 (setq rtn (car list)))
6878 ((featurep 'xemacs)
6879 (if sort (setq list (sort list (lambda (a b)
6880 (string< (upcase a) (upcase b))))))
6881 (setq menu
6882 (append (list title)
6883 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6884 x)))
6885 list)))
6886 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6887 (let ((resp (get-popup-menu-response menu)))
6888 (funcall (event-function resp) (event-object resp))))
6890 (if sort (setq list (sort list (lambda (a b)
6891 (string< (upcase a) (upcase b))))))
6892 (setq menu (cons title
6893 (list
6894 (append (list "")
6895 (mapcar (lambda(x) (cons x x)) list)))))
6896 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6897 (setq rtn (x-popup-menu ev menu))))
6898 rtn))
6900 (defun idlwave-split-menu-xemacs (menu N)
6901 "Split the MENU into submenus of maximum length N."
6902 (if (<= (length menu) (1+ N))
6903 ;; No splitting needed
6904 menu
6905 (let* ((title (car menu))
6906 (entries (cdr menu))
6907 (menu (list title))
6908 (cnt 0)
6909 (nextmenu nil))
6910 (while entries
6911 (while (and entries (< cnt N))
6912 (setq cnt (1+ cnt)
6913 nextmenu (cons (car entries) nextmenu)
6914 entries (cdr entries)))
6915 (setq nextmenu (nreverse nextmenu))
6916 (setq nextmenu (cons (format "%s...%s"
6917 (aref (car nextmenu) 0)
6918 (aref (nth (1- cnt) nextmenu) 0))
6919 nextmenu))
6920 (setq menu (cons nextmenu menu)
6921 nextmenu nil
6922 cnt 0))
6923 (nreverse menu))))
6925 (defun idlwave-split-menu-emacs (menu N)
6926 "Split the MENU into submenus of maximum length N."
6927 (if (<= (length (nth 1 menu)) (1+ N))
6928 ;; No splitting needed
6929 menu
6930 (let* ((title (car menu))
6931 (entries (cdr (nth 1 menu)))
6932 (menu nil)
6933 (cnt 0)
6934 (nextmenu nil))
6935 (while entries
6936 (while (and entries (< cnt N))
6937 (setq cnt (1+ cnt)
6938 nextmenu (cons (car entries) nextmenu)
6939 entries (cdr entries)))
6940 (setq nextmenu (nreverse nextmenu))
6941 (prin1 nextmenu)
6942 (setq nextmenu (cons (format "%s...%s"
6943 (car (car nextmenu))
6944 (car (nth (1- cnt) nextmenu)))
6945 nextmenu))
6946 (setq menu (cons nextmenu menu)
6947 nextmenu nil
6948 cnt 0))
6949 (setq menu (nreverse menu))
6950 (setq menu (cons title menu))
6951 menu)))
6953 (defvar idlwave-completion-setup-hook nil)
6955 (defun idlwave-scroll-completions (&optional message)
6956 "Scroll the completion window on this frame."
6957 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6958 (win (selected-window)))
6959 (unwind-protect
6960 (progn
6961 (select-window cwin)
6962 (condition-case nil
6963 (scroll-up)
6964 (error (if (and (listp last-command)
6965 (nth 2 last-command))
6966 (progn
6967 (select-window win)
6968 (eval idlwave-complete-after-success-form))
6969 (set-window-start cwin (point-min)))))
6970 (and message (message "%s" message)))
6971 (select-window win))))
6973 (defun idlwave-display-completion-list (list &optional message beg complete)
6974 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6975 (unless (and (get-buffer-window "*Completions*")
6976 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6977 (move-marker idlwave-completion-mark beg)
6978 (setq idlwave-before-completion-wconf (current-window-configuration)))
6980 (if (featurep 'xemacs)
6981 (idlwave-display-completion-list-xemacs
6982 list)
6983 (idlwave-display-completion-list-emacs list))
6985 ;; Store a special value in `this-command'. When `idlwave-complete'
6986 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6987 (setq this-command (list 'idlwave-display-completion-list message complete))
6989 ;; Mark the completions buffer as created by cib
6990 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6992 ;; Fontify the classes
6993 (if (and idlwave-completion-fontify-classes
6994 (consp (car list)))
6995 (idlwave-completion-fontify-classes))
6997 ;; Run the hook
6998 (run-hooks 'idlwave-completion-setup-hook)
7000 ;; Display the message
7001 (message "%s" (or message "Making completion list...done")))
7003 (defun idlwave-choose (function &rest args)
7004 "Call FUNCTION as a completion chooser and pass ARGS to it."
7005 (let ((completion-ignore-case t)) ; install correct value
7006 (apply function args))
7007 (if (and (derived-mode-p 'idlwave-shell-mode)
7008 (boundp 'font-lock-mode)
7009 (not font-lock-mode))
7010 ;; For the shell, remove the fontification of the word before point
7011 (let ((beg (save-excursion
7012 (skip-chars-backward "a-zA-Z0-9_")
7013 (point))))
7014 (remove-text-properties beg (point) '(face nil))))
7015 (eval idlwave-complete-after-success-form-force))
7017 (defun idlwave-keyboard-quit ()
7018 (interactive)
7019 (unwind-protect
7020 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7021 (idlwave-restore-wconf-after-completion))
7022 (keyboard-quit)))
7024 (defun idlwave-restore-wconf-after-completion ()
7025 "Restore the old (before completion) window configuration."
7026 (and idlwave-completion-restore-window-configuration
7027 idlwave-before-completion-wconf
7028 (set-window-configuration idlwave-before-completion-wconf)))
7030 (defun idlwave-one-key-select (sym prompt delay)
7031 "Make the user select an element from the alist in the variable SYM.
7032 The keys of the alist are expected to be strings. The function returns the
7033 car of the selected association.
7034 To do this, PROMPT is displayed and the user must hit a letter key to
7035 select an entry. If the user does not reply within DELAY seconds, a help
7036 window with the options is displayed automatically.
7037 The key which is associated with each option is generated automatically.
7038 First, the strings are checked for preselected keys, like in \"[P]rint\".
7039 If these don't exist, a letter in the string is automatically selected."
7040 (let* ((alist (symbol-value sym))
7041 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7042 '(fit-window-to-buffer)))
7043 keys-alist char)
7044 ;; First check the cache
7045 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7046 (setq keys-alist (get sym :one-key-alist-cache))
7047 ;; Need to make new list
7048 (setq keys-alist (idlwave-make-one-key-alist alist))
7049 (put sym :one-key-alist-cache keys-alist)
7050 (put sym :one-key-alist-last alist))
7051 ;; Display prompt and wait for quick reply
7052 (message "%s[%s]" prompt
7053 (mapconcat (lambda(x) (char-to-string (car x)))
7054 keys-alist ""))
7055 (if (sit-for delay)
7056 ;; No quick reply: Show help
7057 (save-window-excursion
7058 (with-output-to-temp-buffer "*Completions*"
7059 (dolist (x keys-alist)
7060 (princ (nth 1 x))
7061 (princ "\n")))
7062 (setq char (read-char)))
7063 (setq char (read-char)))
7064 (message nil)
7065 ;; Return the selected result
7066 (nth 2 (assoc char keys-alist))))
7068 ;; Used for, e.g., electric debug super-examine.
7069 (defun idlwave-make-one-key-alist (alist)
7070 "Make an alist for single key selection."
7071 (let ((l alist) keys-alist name start char help
7072 (cnt 0)
7073 (case-fold-search nil))
7074 (while l
7075 (setq name (car (car l))
7076 l (cdr l))
7077 (catch 'exit
7078 ;; First check if the configuration predetermined a key
7079 (if (string-match "\\[\\(.\\)\\]" name)
7080 (progn
7081 (setq char (string-to-char (downcase (match-string 1 name)))
7082 help (format "%c: %s" char name)
7083 keys-alist (cons (list char help name) keys-alist))
7084 (throw 'exit t)))
7085 ;; Then check for capital letters
7086 (setq start 0)
7087 (while (string-match "[A-Z]" name start)
7088 (setq start (match-end 0)
7089 char (string-to-char (downcase (match-string 0 name))))
7090 (if (not (assoc char keys-alist))
7091 (progn
7092 (setq help (format "%c: %s" char
7093 (replace-match
7094 (concat "[" (match-string 0 name) "]")
7095 t t name))
7096 keys-alist (cons (list char help name) keys-alist))
7097 (throw 'exit t))))
7098 ;; Now check for lowercase letters
7099 (setq start 0)
7100 (while (string-match "[a-z]" name start)
7101 (setq start (match-end 0)
7102 char (string-to-char (match-string 0 name)))
7103 (if (not (assoc char keys-alist))
7104 (progn
7105 (setq help (format "%c: %s" char
7106 (replace-match
7107 (concat "[" (match-string 0 name) "]")
7108 t t name))
7109 keys-alist (cons (list char help name) keys-alist))
7110 (throw 'exit t))))
7111 ;; Bummer, nothing found! Use a stupid number
7112 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7113 help (format "%c: %s" char name)
7114 keys-alist (cons (list char help name) keys-alist))))
7115 (nreverse keys-alist)))
7117 (defun idlwave-set-local (var value &optional buffer)
7118 "Set the buffer-local value of VAR in BUFFER to VALUE."
7119 (with-current-buffer (or buffer (current-buffer))
7120 (set (make-local-variable var) value)))
7122 (defun idlwave-local-value (var &optional buffer)
7123 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7124 (with-current-buffer (or buffer (current-buffer))
7125 (and (local-variable-p var (current-buffer))
7126 (symbol-value var))))
7128 ;; In XEmacs, we can use :activate-callback directly to advice the
7129 ;; choose functions. We use the private keymap only for the online
7130 ;; help feature.
7132 (defvar idlwave-completion-map nil
7133 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7135 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
7136 (with-output-to-temp-buffer "*Completions*"
7137 (apply 'display-completion-list list
7138 ':activate-callback 'idlwave-default-choose-completion
7139 cl-args))
7140 (with-current-buffer "*Completions*"
7141 (use-local-map
7142 (or idlwave-completion-map
7143 (setq idlwave-completion-map
7144 (idlwave-make-modified-completion-map-xemacs
7145 (current-local-map)))))))
7147 (defun idlwave-default-choose-completion (&rest args)
7148 "Execute `default-choose-completion' and then restore the win-conf."
7149 (apply 'idlwave-choose 'default-choose-completion args))
7151 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7152 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7153 (let ((new-map (copy-keymap old-map)))
7154 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7155 (define-key new-map [button3] (lambda ()
7156 (interactive)
7157 (setq this-command last-command)))
7158 new-map))
7160 ;; In Emacs we also replace keybindings in the completion
7161 ;; map in order to install our wrappers.
7163 (defun idlwave-display-completion-list-emacs (list)
7164 "Display completion list and install the choose wrappers."
7165 (with-output-to-temp-buffer "*Completions*"
7166 (display-completion-list list))
7167 (with-current-buffer "*Completions*"
7168 (use-local-map
7169 (or idlwave-completion-map
7170 (setq idlwave-completion-map
7171 (idlwave-make-modified-completion-map-emacs
7172 (current-local-map)))))))
7174 (defun idlwave-make-modified-completion-map-emacs (old-map)
7175 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7176 (let ((new-map (copy-keymap old-map)))
7177 (substitute-key-definition
7178 'choose-completion 'idlwave-choose-completion new-map)
7179 (substitute-key-definition
7180 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7181 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7182 new-map))
7184 (defun idlwave-choose-completion (&rest args)
7185 "Choose the completion that point is in or next to."
7186 (interactive)
7187 (apply 'idlwave-choose 'choose-completion args))
7189 (defun idlwave-mouse-choose-completion (&rest args)
7190 "Click on an alternative in the `*Completions*' buffer to choose it."
7191 (interactive "e")
7192 (apply 'idlwave-choose 'mouse-choose-completion args))
7194 ;;----------------------------------------------------------------------
7195 ;;----------------------------------------------------------------------
7197 ;;; ------------------------------------------------------------------------
7198 ;;; Structure parsing code, and code to manage class info
7201 ;; - Go again over the documentation how to write a completion
7202 ;; plugin. It is in self.el, but currently still very bad.
7203 ;; This could be in a separate file in the distribution, or
7204 ;; in an appendix for the manual.
7206 (defvar idlwave-struct-skip
7207 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7208 "Regexp for skipping continued blank or comment-only lines in structures.")
7210 (defvar idlwave-struct-tag-regexp
7211 (concat "[{,]" ;leading comma/brace
7212 idlwave-struct-skip ; 4 groups
7213 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7214 "[ \t]*:") ; the final colon
7215 "Regexp for structure tags.")
7217 (defun idlwave-struct-tags ()
7218 "Return a list of all tags in the structure defined at point.
7219 Point is expected just before the opening `{' of the struct definition."
7220 (save-excursion
7221 (let* ((borders (idlwave-struct-borders))
7222 (beg (car borders))
7223 (end (cdr borders))
7224 tags)
7225 (goto-char beg)
7226 (save-restriction
7227 (narrow-to-region beg end)
7228 (while (re-search-forward idlwave-struct-tag-regexp end t)
7229 ;; Check if we are still on the top level of the structure.
7230 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7231 (= (point) beg))
7232 (push (match-string-no-properties 5) tags))
7233 (goto-char (match-end 0))))
7234 (nreverse tags))))
7236 (defun idlwave-find-struct-tag (tag)
7237 "Find a given TAG in the structure defined at point."
7238 (let* ((borders (idlwave-struct-borders))
7239 (end (cdr borders))
7240 (case-fold-search t))
7241 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7242 end t)))
7244 (defun idlwave-struct-inherits ()
7245 "Return a list of all `inherits' names in the struct at point.
7246 Point is expected just before the opening `{' of the struct definition."
7247 (save-excursion
7248 (let* ((borders (idlwave-struct-borders))
7249 (beg (car borders))
7250 (end (cdr borders))
7251 (case-fold-search t)
7252 names)
7253 (goto-char beg)
7254 (save-restriction
7255 (narrow-to-region beg end)
7256 (while (re-search-forward
7257 (concat "[{,]" ;leading comma/brace
7258 idlwave-struct-skip ; 4 groups
7259 "inherits" ; The INHERITS tag
7260 idlwave-struct-skip ; 4 more
7261 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7262 end t)
7263 ;; Check if we are still on the top level of the structure.
7264 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7265 (= (point) beg))
7266 (push (match-string-no-properties 9) names))
7267 (goto-char (match-end 0))))
7268 (nreverse names))))
7270 (defun idlwave-in-structure ()
7271 "Return t if point is inside an IDL structure definition."
7272 (let ((beg (point)))
7273 (save-excursion
7274 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7275 (if (idlwave-find-structure-definition nil nil 'back)
7276 (let ((borders (idlwave-struct-borders)))
7277 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7278 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7280 (defun idlwave-struct-borders ()
7281 "Return the borders of the {...} after point as a cons cell."
7282 (let (beg)
7283 (save-excursion
7284 (skip-chars-forward "^{")
7285 (setq beg (point))
7286 (condition-case nil (forward-list 1)
7287 (error (goto-char beg)))
7288 (cons beg (point)))))
7290 (defun idlwave-find-structure-definition (&optional var name bound)
7291 "Search forward for a structure definition.
7292 If VAR is non-nil, search for a structure assigned to variable VAR.
7293 If NAME is non-nil, search for a named structure NAME, if a string,
7294 or a generic named structure otherwise. If BOUND is an integer, limit
7295 the search. If BOUND is the symbol `all', we search first back and
7296 then forward through the entire file. If BOUND is the symbol `back'
7297 we search only backward."
7298 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7299 (case-fold-search t)
7300 (lim (if (integerp bound) bound nil))
7301 (re (concat
7302 (if var
7303 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7304 "\\(\\)")
7305 "=" ws "\\({\\)"
7306 (if name
7307 (if (stringp name)
7308 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7309 ;; Just a generic name
7310 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7311 ""))))
7312 (if (or (and (or (eq bound 'all) (eq bound 'back))
7313 (re-search-backward re nil t))
7314 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7315 (progn
7316 (goto-char (match-beginning 3))
7317 (match-string-no-properties 5)))))
7319 (defvar idlwave-class-info nil)
7320 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7322 (add-hook 'idlwave-update-rinfo-hook
7323 (lambda () (setq idlwave-class-reset t)))
7324 (add-hook 'idlwave-after-load-rinfo-hook
7325 (lambda () (setq idlwave-class-info nil)))
7327 (defun idlwave-class-info (class)
7328 (let (list entry)
7329 (if idlwave-class-info
7330 (if idlwave-class-reset
7331 (setq
7332 idlwave-class-reset nil
7333 idlwave-class-info ; Remove any visited in a buffer
7334 (delq nil (mapcar
7335 (lambda (x)
7336 (let ((filebuf
7337 (idlwave-class-file-or-buffer
7338 (or (cdr (assq 'found-in x)) (car x)))))
7339 (if (cdr filebuf)
7341 x)))
7342 idlwave-class-info))))
7343 ;; Info is nil, put in the system stuff to start.
7344 (setq idlwave-class-info idlwave-system-class-info)
7345 (setq list idlwave-class-info)
7346 (while (setq entry (pop list))
7347 (idlwave-sintern-class-info entry)))
7348 (setq class (idlwave-sintern-class class))
7349 (or (assq class idlwave-class-info)
7350 (progn (idlwave-scan-class-info class)
7351 (assq class idlwave-class-info)))))
7353 (defun idlwave-sintern-class-info (entry)
7354 "Sintern the class names in a class-info entry."
7355 (let ((inherits (assq 'inherits entry)))
7356 (setcar entry (idlwave-sintern-class (car entry) 'set))
7357 (if inherits
7358 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7359 (cdr inherits))))))
7361 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7362 "Find class structure definition(s).
7363 If ALL-HOOK is set, find all named structure definitions in a given
7364 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7365 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7366 class/struct definition."
7367 (let ((case-fold-search t) end-lim name)
7368 (when (re-search-forward
7369 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7370 (if all-hook
7371 (progn
7372 ;; For everything there
7373 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7374 (while (setq name
7375 (idlwave-find-structure-definition nil t end-lim))
7376 (funcall all-hook name)))
7377 (idlwave-find-structure-definition nil (or alt-class class))))))
7380 (defun idlwave-class-file-or-buffer (class)
7381 "Find buffer visiting CLASS definition."
7382 (let* ((pro (concat (downcase class) "__define"))
7383 (file (idlwave-routine-source-file
7384 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7385 (idlwave-routines))))))
7386 (cons file (if file (idlwave-get-buffer-visiting file)))))
7389 (defun idlwave-scan-class-info (class)
7390 "Scan all class and named structure info in the class__define pro."
7391 (let* ((idlwave-auto-routine-info-updates nil)
7392 (filebuf (idlwave-class-file-or-buffer class))
7393 (file (car filebuf))
7394 (buf (cdr filebuf))
7395 (class (idlwave-sintern-class class)))
7396 (if (or
7397 (not file)
7398 (and ;; neither a regular file nor a visited buffer
7399 (not buf)
7400 (not (file-regular-p file))))
7401 nil ; Cannot find the file/buffer to get any info
7402 (save-excursion
7403 (if buf (set-buffer buf)
7404 ;; Read the file in temporarily
7405 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7406 (erase-buffer)
7407 (unless (derived-mode-p 'idlwave-mode)
7408 (idlwave-mode))
7409 (insert-file-contents file))
7410 (save-excursion
7411 (goto-char 1)
7412 (idlwave-find-class-definition class
7413 ;; Scan all of the structures found there
7414 (lambda (name)
7415 (let* ((this-class (idlwave-sintern-class name))
7416 (entry
7417 (list this-class
7418 (cons 'tags (idlwave-struct-tags))
7419 (cons 'inherits (idlwave-struct-inherits)))))
7420 (if (not (eq this-class class))
7421 (setq entry (nconc entry (list (cons 'found-in class)))))
7422 (idlwave-sintern-class-info entry)
7423 (push entry idlwave-class-info)))))))))
7425 (defun idlwave-class-found-in (class)
7426 "Return the FOUND-IN property of the CLASS."
7427 (cdr (assq 'found-in (idlwave-class-info class))))
7428 (defun idlwave-class-tags (class)
7429 "Return the native tags in CLASS."
7430 (cdr (assq 'tags (idlwave-class-info class))))
7431 (defun idlwave-class-inherits (class)
7432 "Return the direct superclasses of CLASS."
7433 (cdr (assq 'inherits (idlwave-class-info class))))
7436 (defun idlwave-all-class-tags (class)
7437 "Return a list of native and inherited tags in CLASS."
7438 (condition-case err
7439 (apply 'append (mapcar 'idlwave-class-tags
7440 (cons class (idlwave-all-class-inherits class))))
7441 (error
7442 (idlwave-class-tag-reset)
7443 (error "%s" (error-message-string err)))))
7446 (defun idlwave-all-class-inherits (class)
7447 "Return a list of all superclasses of CLASS (recursively expanded).
7448 The list is cached in `idlwave-class-info' for faster access."
7449 (cond
7450 ((not idlwave-support-inheritance) nil)
7451 ((eq class nil) nil)
7452 ((eq class t) nil)
7454 (let ((info (idlwave-class-info class))
7455 entry)
7456 (if (setq entry (assq 'all-inherits info))
7457 (cdr entry)
7458 ;; Save the depth of inheritance scan to check for circular references
7459 (let ((inherits (mapcar (lambda (x) (cons x 0))
7460 (idlwave-class-inherits class)))
7461 rtn all-inherits cl)
7462 (while inherits
7463 (setq cl (pop inherits)
7464 rtn (cons (car cl) rtn)
7465 inherits (append (mapcar (lambda (x)
7466 (cons x (1+ (cdr cl))))
7467 (idlwave-class-inherits (car cl)))
7468 inherits))
7469 (if (> (cdr cl) 999)
7470 (error
7471 "Class scan: inheritance depth exceeded. Circular inheritance?")
7473 (setq all-inherits (nreverse rtn))
7474 (nconc info (list (cons 'all-inherits all-inherits)))
7475 all-inherits))))))
7477 (defun idlwave-entry-keywords (entry &optional record-link)
7478 "Return the flat entry keywords alist from routine-info entry.
7479 If RECORD-LINK is non-nil, the keyword text is copied and a text
7480 property indicating the link is added."
7481 (let (kwds)
7482 (mapc
7483 (lambda (key-list)
7484 (let ((file (car key-list)))
7485 (mapcar (lambda (key-cons)
7486 (let ((key (car key-cons))
7487 (link (cdr key-cons)))
7488 (when (and record-link file)
7489 (setq key (copy-sequence key))
7490 (put-text-property
7491 0 (length key)
7492 'link
7493 (concat
7494 file
7495 (if link
7496 (concat idlwave-html-link-sep
7497 (number-to-string link))))
7498 key))
7499 (push (list key) kwds)))
7500 (cdr key-list))))
7501 (nthcdr 5 entry))
7502 (nreverse kwds)))
7504 (defun idlwave-entry-find-keyword (entry keyword)
7505 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7506 (catch 'exit
7507 (mapc
7508 (lambda (key-list)
7509 (let ((file (car key-list))
7510 (kwd (assoc keyword (cdr key-list))))
7511 (when kwd
7512 (setq kwd (cons (car kwd)
7513 (if (and file (cdr kwd))
7514 (concat file
7515 idlwave-html-link-sep
7516 (number-to-string (cdr kwd)))
7517 (cdr kwd))))
7518 (throw 'exit kwd))))
7519 (nthcdr 5 entry))))
7521 ;;==========================================================================
7523 ;; Completing class structure tags. This is a completion plugin.
7524 ;; The necessary taglist is constructed dynamically
7526 (defvar idlwave-current-tags-class nil)
7527 (defvar idlwave-current-class-tags nil)
7528 (defvar idlwave-current-native-class-tags nil)
7529 (defvar idlwave-sint-class-tags nil)
7530 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7531 (idlwave-new-sintern-type 'class-tag)
7532 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7533 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7535 (defun idlwave-complete-class-structure-tag ()
7536 "Complete a structure tag on a `self' argument in an object method."
7537 (interactive)
7538 (let ((pos (point))
7539 (case-fold-search t))
7540 (if (save-excursion
7541 ;; Check if the context is right
7542 (skip-chars-backward "a-zA-Z0-9._$")
7543 (and (< (point) (- pos 4))
7544 (looking-at "self\\.")))
7545 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7546 (super-classes (idlwave-all-class-inherits class-selector)))
7547 ;; Check if we are in a class routine
7548 (unless class-selector
7549 (error "Not in a method procedure or function"))
7550 ;; Check if we need to update the "current" class
7551 (if (not (equal class-selector idlwave-current-tags-class))
7552 (idlwave-prepare-class-tag-completion class-selector))
7553 (setq idlwave-completion-help-info
7554 (list 'idlwave-complete-class-structure-tag-help
7555 (idlwave-sintern-routine
7556 (concat class-selector "__define"))
7557 nil))
7558 ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
7559 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7560 (idlwave-complete-in-buffer
7561 'class-tag 'class-tag
7562 idlwave-current-class-tags nil
7563 (format "Select a tag of class %s" class-selector)
7564 "class tag"
7565 'idlwave-attach-class-tag-classes))
7566 t) ; return t to skip other completions
7567 nil)))
7569 (defun idlwave-class-tag-reset ()
7570 (setq idlwave-current-tags-class nil))
7572 (defun idlwave-prepare-class-tag-completion (class)
7573 "Find and parse the necessary class definitions for class structure tags."
7574 (setq idlwave-sint-class-tags nil)
7575 (setq idlwave-current-tags-class class)
7576 (setq idlwave-current-class-tags
7577 (mapcar (lambda (x)
7578 (list (idlwave-sintern-class-tag x 'set)))
7579 (idlwave-all-class-tags class)))
7580 (setq idlwave-current-native-class-tags
7581 (mapcar 'downcase (idlwave-class-tags class))))
7583 ;===========================================================================
7585 ;; Completing system variables and their structure fields
7586 ;; This is also a plugin.
7588 (defvar idlwave-sint-sysvars nil)
7589 (defvar idlwave-sint-sysvartags nil)
7590 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7591 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7592 (idlwave-new-sintern-type 'sysvar)
7593 (idlwave-new-sintern-type 'sysvartag)
7594 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7595 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7596 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7599 (defun idlwave-complete-sysvar-or-tag ()
7600 "Complete a system variable."
7601 (interactive)
7602 (let ((pos (point))
7603 (case-fold-search t))
7604 (cond ((save-excursion
7605 ;; Check if the context is right for system variable
7606 (skip-chars-backward "[a-zA-Z0-9_$]")
7607 (equal (char-before) ?!))
7608 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7609 (idlwave-complete-in-buffer 'sysvar 'sysvar
7610 idlwave-system-variables-alist nil
7611 "Select a system variable"
7612 "system variable")
7613 t) ; return t to skip other completions
7614 ((save-excursion
7615 ;; Check if the context is right for sysvar tag
7616 (skip-chars-backward "a-zA-Z0-9_$.")
7617 (and (equal (char-before) ?!)
7618 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7619 (<= (match-end 0) pos)))
7620 ;; Complete a system variable tag
7621 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7622 (entry (assq var idlwave-system-variables-alist))
7623 (tags (cdr (assq 'tags entry))))
7624 (or entry (error "!%s is not a known system variable" var))
7625 (or tags (error "System variable !%s is not a structure" var))
7626 (setq idlwave-completion-help-info
7627 (list 'idlwave-complete-sysvar-tag-help var))
7628 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7629 tags nil
7630 "Select a system variable tag"
7631 "system variable tag")
7632 t)) ; return t to skip other completions
7633 (t nil))))
7635 (defvar idlw-help-link) ;dynamic variables set by help callback
7636 (defun idlwave-complete-sysvar-help (mode word)
7637 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7638 (entry (assoc word idlwave-system-variables-alist)))
7639 (cond
7640 ((eq mode 'test)
7641 (and (stringp word) entry (nth 1 (assq 'link entry))))
7642 ((eq mode 'set)
7643 ;; Setting dynamic!!!
7644 (if entry (setq idlw-help-link (nth 1 (assq 'link entry)))))
7645 (t (error "This should not happen")))))
7647 (defun idlwave-complete-sysvar-tag-help (mode word)
7648 (let* ((var (nth 1 idlwave-completion-help-info))
7649 (entry (assoc var idlwave-system-variables-alist))
7650 (tags (cdr (assq 'tags entry)))
7651 (main (nth 1 (assq 'link entry)))
7652 target)
7653 (cond
7654 ((eq mode 'test) ; we can at least link the main
7655 (and (stringp word) entry main))
7656 ((eq mode 'set)
7657 (if entry
7658 (setq idlw-help-link
7659 (if (setq target (cdr (assoc-string word tags t)))
7660 (idlwave-substitute-link-target main target)
7661 main)))) ;; setting dynamic!!!
7662 (t (error "This should not happen")))))
7664 (defun idlwave-split-link-target (link)
7665 "Split a given LINK into link file and anchor."
7666 (if (string-match idlwave-html-link-sep link)
7667 (cons (substring link 0 (match-beginning 0))
7668 (string-to-number (substring link (match-end 0))))))
7670 (defun idlwave-substitute-link-target (link target)
7671 "Substitute the TARGET anchor for the given LINK."
7672 (let (main-base)
7673 (setq main-base (if (string-match "#" link)
7674 (substring link 0 (match-beginning 0))
7675 link))
7676 (if target
7677 (concat main-base idlwave-html-link-sep (number-to-string target))
7678 link)))
7680 ;; Fake help in the source buffer for class structure tags.
7681 ;; IDLW-HELP-LINK AND IDLW-HELP-NAME ARE GLOBAL-VARIABLES HERE.
7682 ;; (from idlwave-do-mouse-completion-help)
7683 (defvar idlw-help-name)
7684 (defvar idlw-help-link)
7685 (defvar idlwave-help-do-class-struct-tag nil)
7686 (defun idlwave-complete-class-structure-tag-help (mode word)
7687 (cond
7688 ((eq mode 'test) ; nothing gets fontified for class tags
7689 nil)
7690 ((eq mode 'set)
7691 (let (class-with found-in)
7692 (when (setq class-with
7693 (idlwave-class-or-superclass-with-tag
7694 idlwave-current-tags-class
7695 word))
7696 (if (assq (idlwave-sintern-class class-with)
7697 idlwave-system-class-info)
7698 (error "No help available for system class tags"))
7699 (if (setq found-in (idlwave-class-found-in class-with))
7700 (setq idlw-help-name (cons (concat found-in "__define") class-with))
7701 (setq idlw-help-name (concat class-with "__define")))))
7702 (setq idlw-help-link word
7703 idlwave-help-do-class-struct-tag t))
7704 (t (error "This should not happen"))))
7706 (defun idlwave-class-or-superclass-with-tag (class tag)
7707 "Find and return the CLASS or one of its superclass with the
7708 associated TAG, if any."
7709 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7711 (catch 'exit
7712 (while sclasses
7713 (setq cl (pop sclasses))
7714 (let ((tags (idlwave-class-tags cl)))
7715 (while tags
7716 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7717 (throw 'exit cl))
7718 (setq tags (cdr tags))))))))
7721 (defun idlwave-sysvars-reset ()
7722 (if (and (fboundp 'idlwave-shell-is-running)
7723 (idlwave-shell-is-running)
7724 idlwave-idlwave_routine_info-compiled)
7725 (idlwave-shell-send-command "idlwave_get_sysvars"
7726 'idlwave-process-sysvars 'hide)))
7728 (defun idlwave-process-sysvars ()
7729 (idlwave-shell-filter-sysvars)
7730 (setq idlwave-sint-sysvars nil
7731 idlwave-sint-sysvartags nil)
7732 (idlwave-sintern-sysvar-alist))
7734 (defun idlwave-sintern-sysvar-alist ()
7735 (let ((list idlwave-system-variables-alist) entry tags)
7736 (while (setq entry (pop list))
7737 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7738 (setq tags (assq 'tags entry))
7739 (if tags
7740 (setcdr tags
7741 (mapcar (lambda (x)
7742 (cons (idlwave-sintern-sysvartag (car x) 'set)
7743 (cdr x)))
7744 (cdr tags)))))))
7746 (defvar idlwave-shell-command-output)
7747 (defun idlwave-shell-filter-sysvars ()
7748 "Get any new system variables and tags."
7749 (let ((text idlwave-shell-command-output)
7750 (start 0)
7751 (old idlwave-system-variables-alist)
7752 var tags type name class link old-entry)
7753 (setq idlwave-system-variables-alist nil)
7754 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7755 text start)
7756 (setq start (match-end 0)
7757 var (match-string 1 text)
7758 tags (if (match-end 3)
7759 (idlwave-split-string (match-string 3 text))))
7760 ;; Maintain old links, if present
7761 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7762 (setq link (assq 'link old-entry))
7763 (setq idlwave-system-variables-alist
7764 (cons (list var
7765 (cons
7766 'tags
7767 (mapcar (lambda (x)
7768 (cons x
7769 (cdr (assq
7770 (idlwave-sintern-sysvartag x)
7771 (cdr (assq 'tags old-entry))))))
7772 tags)) link)
7773 idlwave-system-variables-alist)))
7774 ;; Keep the old value if query was not successful
7775 (setq idlwave-system-variables-alist
7776 (or idlwave-system-variables-alist old))))
7778 (defun idlwave-completion-fontify-classes ()
7779 "Goto the *Completions* buffer and fontify the class info."
7780 (when (featurep 'font-lock)
7781 (with-current-buffer "*Completions*"
7782 (save-excursion
7783 (goto-char (point-min))
7784 (let ((buffer-read-only nil))
7785 (while (re-search-forward "\\.*<[^>]+>" nil t)
7786 (put-text-property (match-beginning 0) (match-end 0)
7787 'face 'font-lock-string-face)))))))
7789 (defun idlwave-uniquify (list)
7790 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7791 (delq nil
7792 (mapcar (lambda (x)
7793 (unless (gethash x ht)
7794 (puthash x t ht)
7796 list))))
7798 (defun idlwave-after-successful-completion (type slash &optional verify)
7799 "Add `=' or `(' after successful completion of keyword and function.
7800 Restore the pre-completion window configuration if possible."
7801 (cond
7802 ((eq type 'procedure)
7803 nil)
7804 ((eq type 'function)
7805 (cond
7806 ((equal idlwave-function-completion-adds-paren nil) nil)
7807 ((or (equal idlwave-function-completion-adds-paren t)
7808 (equal idlwave-function-completion-adds-paren 1))
7809 (insert "("))
7810 ((equal idlwave-function-completion-adds-paren 2)
7811 (insert "()")
7812 (backward-char 1))
7813 (t nil)))
7814 ((eq type 'keyword)
7815 (if (and idlwave-keyword-completion-adds-equal
7816 (not slash))
7817 (progn (insert "=") t)
7818 nil)))
7820 ;; Restore the pre-completion window configuration if this is safe.
7822 (if (or (eq verify 'force) ; force
7823 (and
7824 (get-buffer-window "*Completions*") ; visible
7825 (idlwave-local-value 'idlwave-completion-p
7826 "*Completions*") ; cib-buffer
7827 (eq (marker-buffer idlwave-completion-mark)
7828 (current-buffer)) ; buffer OK
7829 (equal (marker-position idlwave-completion-mark)
7830 verify))) ; pos OK
7831 (idlwave-restore-wconf-after-completion))
7832 (move-marker idlwave-completion-mark nil)
7833 (setq idlwave-before-completion-wconf nil))
7835 (defun idlwave-mouse-context-help (ev &optional arg)
7836 "Call `idlwave-context-help' on the clicked location."
7837 (interactive "eP")
7838 (mouse-set-point ev)
7839 (idlwave-context-help arg))
7841 (defvar idlwave-last-context-help-pos nil)
7842 (defun idlwave-context-help (&optional arg)
7843 "Display IDL Online Help on context.
7844 If point is on a keyword, help for that keyword will be shown. If
7845 point is on a routine name or in the argument list of a routine, help
7846 for that routine will be displayed. Works for system routines and
7847 keywords, it pulls up text help. For other routines and keywords,
7848 visits the source file, finding help in the header (if
7849 `idlwave-help-source-try-header' is non-nil) or the routine definition
7850 itself."
7851 (interactive "P")
7852 (idlwave-do-context-help arg))
7854 (defun idlwave-mouse-completion-help (ev)
7855 "Display online help about the completion at point."
7856 (interactive "eP")
7857 ;; Restore last-command for next command, to make
7858 ;; scrolling/canceling of completions work.
7859 (setq this-command last-command)
7860 (idlwave-do-mouse-completion-help ev))
7862 (defun idlwave-routine-info (&optional arg external)
7863 "Display a routines calling sequence and list of keywords.
7864 When point is on the name a function or procedure, or in the argument
7865 list of a function or procedure, this command displays a help buffer with
7866 the information. When called with prefix arg, enforce class query.
7868 When point is on an object operator `->', display the class stored in
7869 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7870 arg, the class property is cleared out."
7872 (interactive "P")
7873 (idlwave-routines)
7874 (if (string-match "->" (buffer-substring
7875 (max (point-min) (1- (point)))
7876 (min (+ 2 (point)) (point-max))))
7877 ;; Cursor is on an arrow
7878 (if (get-text-property (point) 'idlwave-class)
7879 ;; arrow has class property
7880 (if arg
7881 ;; Remove property
7882 (save-excursion
7883 (backward-char 1)
7884 (when (looking-at ".?\\(->\\)")
7885 (remove-text-properties (match-beginning 1) (match-end 1)
7886 '(idlwave-class nil face nil))
7887 (message "Class property removed from arrow")))
7888 ;; Echo class property
7889 (message "Arrow has text property identifying object to be class %s"
7890 (get-text-property (point) 'idlwave-class)))
7891 ;; No property found
7892 (message "Arrow has no class text property"))
7894 ;; Not on an arrow...
7895 (let* ((idlwave-query-class nil)
7896 (idlwave-force-class-query (equal arg '(4)))
7897 (module (idlwave-what-module)))
7898 (if (car module)
7899 (apply 'idlwave-display-calling-sequence
7900 (idlwave-fix-module-if-obj_new module))
7901 (error "Don't know which calling sequence to show")))))
7903 (defun idlwave-resolve (&optional arg)
7904 "Call RESOLVE_ROUTINE on the module name at point.
7905 Like `idlwave-routine-info', this looks for a routine call at point.
7906 After confirmation in the minibuffer, it will use the shell to issue
7907 a RESOLVE call for this routine, to attempt to make it defined and its
7908 routine info available for IDLWAVE. If the routine is a method call,
7909 both `class__method' and `class__define' will be tried.
7910 With ARG, enforce query for the class of object methods."
7911 (interactive "P")
7912 (let* ((idlwave-query-class nil)
7913 (idlwave-force-class-query (equal arg '(4)))
7914 (module (idlwave-what-module))
7915 (name (idlwave-make-full-name (nth 2 module) (car module)))
7916 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7917 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7918 (kwd "")
7919 class)
7920 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7921 resolve)
7922 (setq type (match-string 1 resolve)
7923 class (if (match-beginning 2)
7924 (match-string 3 resolve)
7925 nil)
7926 name (match-string 4 resolve)))
7927 (if (string= (downcase type) "function")
7928 (setq kwd ",/is_function"))
7930 (cond
7931 ((null class)
7932 (idlwave-shell-send-command
7933 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7934 'idlwave-update-routine-info
7935 nil t))
7937 (idlwave-shell-send-command
7938 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7939 (list 'idlwave-shell-send-command
7940 (format "resolve_routine,'%s__%s'%s"
7941 (downcase class) (downcase name) kwd)
7942 '(idlwave-update-routine-info)
7943 nil t))))))
7945 (defun idlwave-find-module-this-file ()
7946 (interactive)
7947 (idlwave-find-module '(4)))
7949 (defun idlwave-find-module (&optional arg)
7950 "Find the source code of an IDL module.
7951 Works for modules for which IDLWAVE has routine info available.
7952 The function offers as default the module name `idlwave-routine-info'
7953 would use. With ARG limit to this buffer. With two prefix ARG's
7954 force class query for object methods."
7955 (interactive "P")
7956 (let* ((idlwave-query-class nil)
7957 (idlwave-force-class-query (equal arg '(16)))
7958 (this-buffer (equal arg '(4)))
7959 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7960 (default (if module
7961 (concat (idlwave-make-full-name
7962 (nth 2 module) (car module))
7963 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7964 "none"))
7965 (list
7966 (idlwave-uniquify
7967 (delq nil
7968 (mapcar (lambda (x)
7969 (if (eq 'system (car-safe (nth 3 x)))
7970 ;; Take out system routines with no source.
7972 (list
7973 (concat (idlwave-make-full-name
7974 (nth 2 x) (car x))
7975 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7976 (if this-buffer
7977 (idlwave-save-buffer-update)
7978 (idlwave-routines))))))
7979 (name (idlwave-completing-read
7980 (if (or (not this-buffer)
7981 (assoc default list))
7982 (format "Module (Default %s): " default)
7983 (format "Module in this file: "))
7984 list))
7985 type class)
7986 (if (string-match "\\`\\s-*\\'" name)
7987 ;; Nothing, use the default.
7988 (setq name default))
7989 (if (string-match "<[fp]>" name)
7990 (setq type (substring name -2 -1)
7991 name (substring name 0 -3)))
7992 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7993 (setq class (match-string 1 name)
7994 name (match-string 2 name)))
7995 (setq name (idlwave-sintern-routine-or-method name class)
7996 class (idlwave-sintern-class class)
7997 type (cond ((equal type "f") 'fun)
7998 ((equal type "p") 'pro)
7999 (t t)))
8000 (idlwave-do-find-module name type class nil this-buffer)))
8002 (defun idlwave-do-find-module (name type class
8003 &optional force-source this-buffer)
8004 (let ((name1 (idlwave-make-full-name class name))
8005 source buf1 entry
8006 (buf (current-buffer))
8007 (pos (point))
8008 file name2)
8009 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8010 'WITH-FILE)
8011 source (or force-source (nth 3 entry))
8012 name2 (if (nth 2 entry)
8013 (idlwave-make-full-name (nth 2 entry) name)
8014 name1))
8015 (if source
8016 (setq file (idlwave-routine-source-file source)))
8017 (unless file ; Try to find it on the path.
8018 (setq file
8019 (idlwave-expand-lib-file-name
8020 (if class
8021 (format "%s__define.pro" (downcase class))
8022 (format "%s.pro" (downcase name))))))
8023 (cond
8024 ((or (null name) (equal name ""))
8025 (error "Abort"))
8026 ((eq (car source) 'system)
8027 (error "Source code for system routine %s is not available"
8028 name2))
8029 ((or (not file) (not (file-regular-p file)))
8030 (error "Source code for routine %s is not available"
8031 name2))
8033 (when (not this-buffer)
8034 (setq buf1
8035 (idlwave-find-file-noselect file 'find))
8036 (pop-to-buffer buf1 t))
8037 (goto-char (point-max))
8038 (let ((case-fold-search t))
8039 (if (re-search-backward
8040 (concat "^[ \t]*\\<"
8041 (cond ((eq type 'fun) "function")
8042 ((eq type 'pro) "pro")
8043 (t "\\(pro\\|function\\)"))
8044 "\\>[ \t]+"
8045 (regexp-quote (downcase name2))
8046 "[^a-zA-Z0-9_$]")
8047 nil t)
8048 (goto-char (match-beginning 0))
8049 (pop-to-buffer buf)
8050 (goto-char pos)
8051 (error "Could not find routine %s" name2)))))))
8053 (defun idlwave-what-module ()
8054 "Return a default module for stuff near point.
8055 Used by `idlwave-routine-info' and `idlwave-find-module'."
8056 (idlwave-routines)
8057 (if (let ((case-fold-search t))
8058 (save-excursion
8059 (idlwave-beginning-of-statement)
8060 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8061 ;; This is a function or procedure definition statement
8062 ;; We return the defined routine as module.
8063 (list
8064 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8065 (match-string-no-properties 2))
8066 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8067 (idlwave-sintern-class (match-string 3)))
8069 ;; Not a definition statement - analyze precise position.
8070 (let* ((where (idlwave-where))
8071 (cw (nth 2 where))
8072 (pro (car (nth 0 where)))
8073 (func (car (nth 1 where)))
8074 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8075 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8076 (following-char)))
8078 (cond
8079 ((and (eq cw 'procedure)
8080 (not (equal this-word "")))
8081 (setq this-word (idlwave-sintern-routine-or-method
8082 this-word (nth 2 (nth 3 where))))
8083 (list this-word 'pro
8084 (idlwave-determine-class
8085 (cons this-word (cdr (nth 3 where)))
8086 'pro)))
8087 ((and (eq cw 'function)
8088 (not (equal this-word ""))
8089 (or (eq next-char ?\() ; exclude arrays, vars.
8090 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8091 (setq this-word (idlwave-sintern-routine-or-method
8092 this-word (nth 2 (nth 3 where))))
8093 (list this-word 'fun
8094 (idlwave-determine-class
8095 (cons this-word (cdr (nth 3 where)))
8096 'fun)))
8097 ((and (memq cw '(function-keyword procedure-keyword))
8098 (not (equal this-word ""))
8099 (eq next-char ?\()) ; A function!
8100 (setq this-word (idlwave-sintern-routine this-word))
8101 (list this-word 'fun nil))
8102 (func
8103 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8104 (pro
8105 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8106 (t nil)))))
8108 (defun idlwave-what-module-find-class ()
8109 "Call `idlwave-what-module' and find the inherited class if necessary."
8110 (let* ((module (idlwave-what-module))
8111 (class (nth 2 module)))
8112 (if (and (= (length module) 3)
8113 (stringp class))
8114 (list (car module)
8115 (nth 1 module)
8116 (apply 'idlwave-find-inherited-class module))
8117 module)))
8119 (defun idlwave-find-inherited-class (name type class)
8120 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8121 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8122 (if entry
8123 (nth 2 entry)
8124 class)))
8126 (defun idlwave-fix-module-if-obj_new (module)
8127 "Check if MODULE points to obj_new.
8128 If yes, and if the cursor is in the keyword region, change to the
8129 appropriate Init method."
8130 (let* ((name (car module))
8131 (pos (point))
8132 (case-fold-search t)
8133 string)
8134 (if (and (stringp name)
8135 (equal (downcase name) "obj_new")
8136 (save-excursion
8137 (idlwave-beginning-of-statement)
8138 (setq string (buffer-substring (point) pos))
8139 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8140 string)))
8141 (let ((name "Init")
8142 (class (match-string 1 string)))
8143 (setq module (list (idlwave-sintern-method "Init")
8144 'fun
8145 (idlwave-sintern-class class)))))
8146 module))
8148 (defun idlwave-fix-keywords (name type class keywords
8149 &optional super-classes system)
8150 "Update a list of keywords.
8151 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8152 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8153 demand _EXTRA in the keyword list."
8154 (let ((case-fold-search t))
8156 ;; If this is the OBJ_NEW function, try to figure out the class and use
8157 ;; the keywords from the corresponding INIT method.
8158 (if (and (equal (upcase name) "OBJ_NEW")
8159 (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
8160 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8161 (string (buffer-substring bos (point)))
8162 (case-fold-search t)
8163 class)
8164 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8165 string)
8166 (setq class (idlwave-sintern-class (match-string 1 string)))
8167 (setq idlwave-current-obj_new-class class)
8168 (setq keywords
8169 (append keywords
8170 (idlwave-entry-keywords
8171 (idlwave-rinfo-assq
8172 (idlwave-sintern-method "INIT")
8173 'fun
8174 class
8175 (idlwave-routines)) 'do-link))))))
8177 ;; If the class is `t', combine all keywords of all methods NAME
8178 (when (eq class t)
8179 (mapc (lambda (entry)
8180 (and
8181 (nth 2 entry) ; non-nil class
8182 (eq (nth 1 entry) type) ; correct type
8183 (setq keywords
8184 (append keywords
8185 (idlwave-entry-keywords entry 'do-link)))))
8186 (idlwave-all-assq name (idlwave-routines)))
8187 (setq keywords (idlwave-uniquify keywords)))
8189 ;; If we have inheritance, add all keywords from superclasses, if
8190 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8191 (when (and
8192 super-classes
8193 idlwave-keyword-class-inheritance
8194 (stringp class)
8196 system
8197 (assq (idlwave-sintern-keyword "_extra") keywords)
8198 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8199 ;; Check if one of the keyword-class regexps matches the name
8200 (let ((regexps idlwave-keyword-class-inheritance) re)
8201 (catch 'exit
8202 (while (setq re (pop regexps))
8203 (if (string-match re name) (throw 'exit t))))))
8205 (loop for entry in (idlwave-routines) do
8206 (and (nth 2 entry) ; non-nil class
8207 (memq (nth 2 entry) super-classes) ; an inherited class
8208 (eq (nth 1 entry) type) ; correct type
8209 (eq (car entry) name) ; correct name
8210 (mapc (lambda (k) (add-to-list 'keywords k))
8211 (idlwave-entry-keywords entry 'do-link))))
8212 (setq keywords (idlwave-uniquify keywords)))
8214 ;; Return the final list
8215 keywords))
8217 (defun idlwave-expand-keyword (keyword module)
8218 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8219 KEYWORD may be an exact match or an abbreviation of a keyword.
8220 If the match is exact, KEYWORD itself is returned, even if there may be other
8221 keywords of which KEYWORD is an abbreviation. This is necessary because some
8222 system routines have keywords which are prefixes of other keywords.
8223 If KEYWORD is an abbreviation of several keywords, a list of all possible
8224 completions is returned.
8225 If the abbreviation was unique, the correct keyword is returned.
8226 If it cannot be a keyword, the function return nil.
8227 If we do not know about MODULE, just return KEYWORD literally."
8228 (let* ((name (car module))
8229 (type (nth 1 module))
8230 (class (nth 2 module))
8231 (kwd (idlwave-sintern-keyword keyword))
8232 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8233 (kwd-alist (idlwave-entry-keywords entry))
8234 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8235 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8236 (completion-ignore-case t)
8237 candidates)
8238 (cond ((assq kwd kwd-alist)
8239 kwd)
8240 ((setq candidates (all-completions kwd kwd-alist))
8241 (if (= (length candidates) 1)
8242 (car candidates)
8243 candidates))
8244 ((and entry extra)
8245 ;; Inheritance may cause this keyword to be correct
8246 keyword)
8247 (entry
8248 ;; We do know the function, which does not have the keyword.
8249 nil)
8251 ;; We do not know the function, so this just might be a correct
8252 ;; keyword - return it as it is.
8253 keyword))))
8255 (defvar idlwave-rinfo-mouse-map
8256 (let ((map (make-sparse-keymap)))
8257 (define-key map
8258 (if (featurep 'xemacs) [button2] [mouse-2])
8259 'idlwave-mouse-active-rinfo)
8260 (define-key map
8261 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8262 'idlwave-mouse-active-rinfo-shift)
8263 (define-key map
8264 (if (featurep 'xemacs) [button3] [mouse-3])
8265 'idlwave-mouse-active-rinfo-right)
8266 (define-key map " " 'idlwave-active-rinfo-space)
8267 (define-key map "q" 'idlwave-quit-help)
8268 map))
8270 (defvar idlwave-rinfo-map
8271 (let ((map (make-sparse-keymap)))
8272 (define-key map "q" 'idlwave-quit-help)
8273 map))
8275 (defvar idlwave-popup-source nil)
8276 (defvar idlwave-rinfo-marker (make-marker))
8278 (defun idlwave-quit-help ()
8279 (interactive)
8280 (let ((ri-window (get-buffer-window "*Help*"))
8281 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8282 (when (and olh-window
8283 (fboundp 'idlwave-help-quit))
8284 (select-window olh-window)
8285 (idlwave-help-quit))
8286 (when (window-live-p ri-window)
8287 (delete-window ri-window))))
8289 (defun idlwave-display-calling-sequence (name type class
8290 &optional initial-class)
8291 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8292 (let* ((initial-class (or initial-class class))
8293 (entry (or (idlwave-best-rinfo-assq name type class
8294 (idlwave-routines))
8295 (idlwave-rinfo-assq name type class
8296 idlwave-unresolved-routines)))
8297 (name (or (car entry) name))
8298 (class (or (nth 2 entry) class))
8299 (superclasses (idlwave-all-class-inherits initial-class))
8300 (twins (idlwave-routine-twins entry))
8301 (dtwins (idlwave-study-twins twins))
8302 (all dtwins)
8303 (system (eq (car (nth 3 entry)) 'system))
8304 (calling-seq (nth 4 entry))
8305 (keywords (idlwave-entry-keywords entry 'do-link))
8306 (html-file (car (nth 5 entry)))
8307 (help-echo-kwd
8308 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8309 (help-echo-use
8310 "Button2/3: Online Help")
8311 (help-echo-src
8312 "Button2: Jump to source and back | Button3: Source in Help window.")
8313 (help-echo-class
8314 "Button2: Display info about same method in superclass")
8315 (col 0)
8316 (data (list name type class (current-buffer) nil initial-class))
8317 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8318 (face 'idlwave-help-link)
8319 beg props win cnt total)
8320 ;; Fix keywords, but don't add chained super-classes, since these
8321 ;; are shown separately for that super-class
8322 (setq keywords (idlwave-fix-keywords name type class keywords))
8323 (cond
8324 ((null entry)
8325 (error "No %s %s known %s" type name
8326 (if initial-class (concat "in class " initial-class) "")))
8327 ((or (null name) (equal name ""))
8328 (error "No function or procedure call at point"))
8329 ((null calling-seq)
8330 (error "Calling sequence of %s %s not available" type name))
8332 (move-marker idlwave-rinfo-marker (point))
8333 (with-current-buffer (get-buffer-create "*Help*")
8334 (use-local-map idlwave-rinfo-map)
8335 (setq buffer-read-only nil)
8336 (erase-buffer)
8337 (set (make-local-variable 'idlwave-popup-source) nil)
8338 (set (make-local-variable 'idlwave-current-obj_new-class)
8339 idlwave-current-obj_new-class)
8340 (when superclasses
8341 (setq props (list 'mouse-face 'highlight
8342 km-prop idlwave-rinfo-mouse-map
8343 'help-echo help-echo-class
8344 'data (cons 'class data)))
8345 (let ((classes (cons initial-class superclasses)) c)
8346 (insert "Classes: ")
8347 (while (setq c (pop classes))
8348 (insert " ")
8349 (setq beg (point))
8350 (insert c)
8351 (if (equal (downcase c) (downcase class))
8352 (add-text-properties beg (point) (list 'face 'bold))
8353 ;; If Method exists in a different class link it
8354 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8355 (add-text-properties beg (point) props))))
8356 (insert "\n")))
8357 (setq props (list 'mouse-face 'highlight
8358 km-prop idlwave-rinfo-mouse-map
8359 'help-echo help-echo-use
8360 'data (cons 'usage data)))
8361 (if html-file (setq props (append (list 'face face 'link html-file)
8362 props)))
8363 (insert "Usage: ")
8364 (setq beg (point))
8365 (insert (if class
8366 (format calling-seq class name class name class name)
8367 (format calling-seq name name name name))
8368 "\n")
8369 (add-text-properties beg (point) props)
8371 (insert "Keywords:")
8372 (if (null keywords)
8373 (insert " No keywords accepted.")
8374 (setq col 9)
8375 (mapc
8376 (lambda (x)
8377 (if (>= (+ col 1 (length (car x)))
8378 (window-width))
8379 (progn
8380 (insert "\n ")
8381 (setq col 9)))
8382 (insert " ")
8383 (setq beg (point)
8384 ;; Relevant keywords already have link property attached
8385 props (list 'mouse-face 'highlight
8386 km-prop idlwave-rinfo-mouse-map
8387 'data (cons 'keyword data)
8388 'help-echo help-echo-kwd
8389 'keyword (car x)))
8390 (if system (setq props (append (list 'face face) props)))
8391 (insert (car x))
8392 (add-text-properties beg (point) props)
8393 (setq col (+ col 1 (length (car x)))))
8394 keywords))
8396 (setq cnt 1 total (length all))
8397 ;; Here entry is (key file (list of type-conses))
8398 (while (setq entry (pop all))
8399 (setq props (list 'mouse-face 'highlight
8400 km-prop idlwave-rinfo-mouse-map
8401 'help-echo help-echo-src
8402 'source (list (car (car (nth 2 entry))) ;type
8403 (nth 1 entry)
8405 (cdr (car (nth 2 entry))))
8406 'data (cons 'source data)))
8407 (idlwave-insert-source-location
8408 (format "\n%-8s %s"
8409 (if (equal cnt 1)
8410 (if (> total 1) "Sources:" "Source:")
8412 (if (> total 1) "- " ""))
8413 entry props)
8414 (incf cnt)
8415 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8416 ;; No more source lines, please
8417 (insert (format
8418 "\n Source information truncated to %d entries."
8419 idlwave-rinfo-max-source-lines))
8420 (setq all nil)))
8421 (goto-char (point-min))
8422 (setq buffer-read-only t))
8423 (display-buffer "*Help*")
8424 (if (and (setq win (get-buffer-window "*Help*"))
8425 idlwave-resize-routine-help-window)
8426 (progn
8427 (let ((ww (selected-window)))
8428 (unwind-protect
8429 (progn
8430 (select-window win)
8431 (enlarge-window (- (/ (frame-height) 2)
8432 (window-height)))
8433 (shrink-window-if-larger-than-buffer))
8434 (select-window ww)))))))))
8436 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8437 "Insert a source location into the routine info buffer.
8438 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8439 to it."
8440 (let* ((key (car entry))
8441 (file (nth 1 entry))
8442 (types (nth 2 entry))
8443 (shell-flag (assq 'compiled types))
8444 (buffer-flag (assq 'buffer types))
8445 (user-flag (assq 'user types))
8446 (lib-flag (assq 'lib types))
8447 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8448 (and user-flag (idlwave-count-memq 'user types))
8449 (and lib-flag (idlwave-count-memq 'lib types))
8451 (doflags t)
8452 beg special)
8454 (insert prefix)
8456 (cond
8457 ((eq key 'system)
8458 (setq doflags nil)
8459 (insert "System "))
8461 ((eq key 'builtin)
8462 (setq doflags nil)
8463 (insert "Builtin "))
8465 ((and (not file) shell-flag)
8466 (insert "Unresolved"))
8468 ((null file)
8469 (insert "ERROR"))
8471 ((idlwave-syslib-p file)
8472 (if (string-match "obsolete" (file-name-directory file))
8473 (insert "Obsolete ")
8474 (insert "SystemLib ")))
8476 ;; New special syntax: taken directly from routine-info for
8477 ;; library catalog routines
8478 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8479 (insert (format "%-10s" special)))
8481 ;; Old special syntax: a matching regexp
8482 ((setq special (idlwave-special-lib-test file))
8483 (insert (format "%-10s" special)))
8485 ;; Catch-all with file
8486 ((idlwave-lib-p file) (insert "Library "))
8488 ;; Sanity catch all
8489 (t (insert "Other ")))
8491 (when doflags
8492 (insert (concat
8493 " ["
8494 (if lib-flag "L" "-")
8495 (if user-flag "C" "-")
8496 (if shell-flag "S" "-")
8497 (if buffer-flag "B" "-")
8498 "] ")))
8499 (when (> ndupl 1)
8500 (setq beg (point))
8501 (insert (format "(%dx) " ndupl))
8502 (add-text-properties beg (point) (list 'face 'bold)))
8503 (when (and file (not (equal file "")))
8504 (setq beg (point))
8505 (insert (apply 'abbreviate-file-name
8506 (if (featurep 'xemacs) (list file t) (list file))))
8507 (if file-props
8508 (add-text-properties beg (point) file-props)))))
8510 (defun idlwave-special-lib-test (file)
8511 "Check the path of FILE against the regexps which define special libs.
8512 Return the name of the special lib if there is a match."
8513 (let ((alist idlwave-special-lib-alist)
8514 entry rtn)
8515 (cond
8516 ((stringp file)
8517 (while (setq entry (pop alist))
8518 (if (string-match (car entry) file)
8519 (setq rtn (cdr entry)
8520 alist nil)))
8521 rtn)
8522 (t nil))))
8524 (defun idlwave-mouse-active-rinfo-right (ev)
8525 (interactive "e")
8526 (idlwave-mouse-active-rinfo ev 'right))
8528 (defun idlwave-mouse-active-rinfo-shift (ev)
8529 (interactive "e")
8530 (idlwave-mouse-active-rinfo ev nil 'shift))
8532 (defun idlwave-active-rinfo-space ()
8533 (interactive)
8534 (idlwave-mouse-active-rinfo nil 'right))
8536 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8537 "Do the mouse actions in the routine info buffer.
8538 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8539 was pressed."
8540 (interactive "e")
8541 (if ev (mouse-set-point ev))
8542 (let (data id name type class buf bufwin source link keyword
8543 word initial-class)
8544 (setq data (get-text-property (point) 'data)
8545 source (get-text-property (point) 'source)
8546 keyword (get-text-property (point) 'keyword)
8547 link (get-text-property (point) 'link)
8548 id (car data)
8549 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8550 buf (nth 4 data)
8551 initial-class (nth 6 data)
8552 word (idlwave-this-word)
8553 bufwin (get-buffer-window buf t))
8555 (cond ((eq id 'class) ; Switch class being displayed
8556 (if (window-live-p bufwin) (select-window bufwin))
8557 (idlwave-display-calling-sequence
8558 (idlwave-sintern-method name)
8559 type (idlwave-sintern-class word)
8560 initial-class))
8561 ((eq id 'usage) ; Online help on this routine
8562 (idlwave-online-help link name type class))
8563 ((eq id 'source) ; Source in help or buffer
8564 (if right ; In help
8565 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8566 (idlwave-help-source-try-header nil)
8567 ;; Fake idlwave-routines so help will find the right entry
8568 (idlwave-routines
8569 (list (list name type class source ""))))
8570 (idlwave-help-get-special-help name type class nil))
8571 ;; Otherwise just pop to the source
8572 (setq idlwave-popup-source (not idlwave-popup-source))
8573 (if idlwave-popup-source
8574 (condition-case err
8575 (idlwave-do-find-module name type class source)
8576 (error
8577 (setq idlwave-popup-source nil)
8578 (if (window-live-p bufwin) (select-window bufwin))
8579 (error (nth 1 err))))
8580 (if bufwin
8581 (select-window bufwin)
8582 (pop-to-buffer buf))
8583 (goto-char (marker-position idlwave-rinfo-marker)))))
8584 ((eq id 'keyword)
8585 (if right
8586 (idlwave-online-help link name type class keyword)
8587 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8589 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8590 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8591 (let ((bwin (get-buffer-window buffer)))
8592 (if idlwave-complete-empty-string-as-lower-case
8593 (setq keyword (downcase keyword)))
8594 (if bwin
8595 (select-window bwin)
8596 (pop-to-buffer buffer)
8597 (setq bwin (get-buffer-window buffer)))
8598 (if (eq (preceding-char) ?/)
8599 (insert keyword)
8600 (unless (save-excursion
8601 (re-search-backward
8602 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8603 (min (- (point) 100) (point-min)) t))
8604 (insert ", "))
8605 (if shift (insert "/"))
8606 (insert keyword)
8607 (if (and (not shift)
8608 idlwave-keyword-completion-adds-equal)
8609 (insert "=")))))
8611 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8612 "List the load path shadows of all routines defined in current buffer."
8613 (interactive "P")
8614 (idlwave-routines)
8615 (if (derived-mode-p 'idlwave-mode)
8616 (idlwave-list-load-path-shadows
8617 nil (idlwave-update-current-buffer-info 'save-buffer)
8618 "in current buffer")
8619 (error "Current buffer is not in idlwave-mode")))
8621 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8622 "List the load path shadows of all routines compiled under the shell.
8623 This is very useful for checking an IDL application. Just compile the
8624 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8625 routines and update IDLWAVE internal info. Then check for shadowing
8626 with this command."
8627 (interactive "P")
8628 (cond
8629 ((or (not (fboundp 'idlwave-shell-is-running))
8630 (not (idlwave-shell-is-running)))
8631 (error "Shell is not running"))
8632 ((null idlwave-compiled-routines)
8633 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8635 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8636 "in the shell"))))
8638 (defun idlwave-list-all-load-path-shadows (&optional arg)
8639 "List the load path shadows of all routines known to IDLWAVE."
8640 (interactive "P")
8641 (idlwave-list-load-path-shadows nil nil "globally"))
8643 (defvar idlwave-sort-prefer-buffer-info t
8644 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8646 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8647 "List the routines which are defined multiple times.
8648 Search the information IDLWAVE has about IDL routines for multiple
8649 definitions.
8650 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8652 When IDL hits a routine call which is not defined, it will search on
8653 the load path in order to find a definition. The output of this command
8654 can be used to detect possible name clashes during this process."
8655 (idlwave-routines) ; Make sure everything is loaded.
8656 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8657 (or (y-or-n-p
8658 "You don't have any user or library catalogs. Continue anyway? ")
8659 (error "Abort")))
8660 (let* ((routines (append idlwave-system-routines
8661 idlwave-compiled-routines
8662 idlwave-library-catalog-routines
8663 idlwave-user-catalog-routines
8664 idlwave-buffer-routines
8665 nil))
8666 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8667 (keymap (make-sparse-keymap))
8668 (props (list 'mouse-face 'highlight
8669 km-prop keymap
8670 'help-echo "Mouse2: Find source"))
8671 (nroutines (length (or special-routines routines)))
8672 (step (/ nroutines 100))
8673 (n 0)
8674 (cnt 0)
8675 (idlwave-sort-prefer-buffer-info nil)
8676 routine twins dtwins twin done props1 lroutines)
8678 (if special-routines
8679 ;; Just looking for shadows of a few special routines
8680 (setq lroutines routines
8681 routines special-routines))
8683 (message "Sorting routines...")
8684 (setq routines (sort routines
8685 (lambda (a b)
8686 (string< (downcase (idlwave-make-full-name
8687 (nth 2 a) (car a)))
8688 (downcase (idlwave-make-full-name
8689 (nth 2 b) (car b)))))))
8690 (message "Sorting routines...done")
8692 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8693 (lambda (ev)
8694 (interactive "e")
8695 (mouse-set-point ev)
8696 (apply 'idlwave-do-find-module
8697 (get-text-property (point) 'find-args))))
8698 (define-key keymap [(return)]
8699 (lambda ()
8700 (interactive)
8701 (apply 'idlwave-do-find-module
8702 (get-text-property (point) 'find-args))))
8703 (message "Compiling list...( 0%%)")
8704 (with-current-buffer (get-buffer-create "*Shadows*")
8705 (setq buffer-read-only nil)
8706 (erase-buffer)
8707 (while (setq routine (pop routines))
8708 (if (= (mod (setq n (1+ n)) step) 0)
8709 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8711 ;; Get a list of all twins
8712 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8713 (if (memq routine done)
8714 (setq dtwins nil)
8715 (setq dtwins (idlwave-study-twins twins)))
8716 ;; Mark all twins as dealt with
8717 (setq done (append twins done))
8718 (when (or (> (length dtwins) 1)
8719 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8720 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8721 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8722 (incf cnt)
8723 (insert (format "\n%s%s"
8724 (idlwave-make-full-name (nth 2 routine)
8725 (car routine))
8726 (if (eq (nth 1 routine) 'fun) "()" "")))
8727 (while (setq twin (pop dtwins))
8728 (setq props1 (append (list 'find-args
8729 (list (nth 0 routine)
8730 (nth 1 routine)
8731 (nth 2 routine)))
8732 props))
8733 (idlwave-insert-source-location "\n - " twin props1))))
8734 (goto-char (point-min))
8735 (setq buffer-read-only t))
8736 (setq loc (or loc ""))
8737 (if (> cnt 0)
8738 (progn
8739 (display-buffer (get-buffer "*Shadows*"))
8740 (message "%d case%s of shadowing found %s"
8741 cnt (if (= cnt 1) "" "s") loc))
8742 (message "No shadowing conflicts found %s" loc))))
8744 (defun idlwave-print-source (routine)
8745 (let* ((source (nth 3 routine))
8746 (stype (car source))
8747 (sfile (idlwave-routine-source-file source)))
8748 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8749 (if (and (eq stype 'compiled)
8750 (or (not (stringp sfile))
8751 (not (string-match "\\S-" sfile))))
8752 (setq stype 'unresolved))
8753 (princ (format " %-10s %s\n"
8754 stype
8755 (if sfile sfile "No source code available")))))
8757 (defun idlwave-routine-twins (entry &optional list)
8758 "Return all twin entries of ENTRY in LIST.
8759 LIST defaults to `idlwave-routines'.
8760 Twin entries are those which have the same name, type, and class.
8761 ENTRY will also be returned, as the first item of this list."
8762 (let* ((name (car entry))
8763 (type (nth 1 entry))
8764 (class (nth 2 entry))
8765 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8766 twins candidate)
8767 (while (setq candidate (pop candidates))
8768 (if (and (not (eq candidate entry))
8769 (eq type (nth 1 candidate))
8770 (eq class (nth 2 candidate)))
8771 (push candidate twins)))
8772 (if (setq candidate (idlwave-rinfo-assq name type class
8773 idlwave-unresolved-routines))
8774 (push candidate twins))
8775 (cons entry (nreverse twins))))
8777 (defun idlwave-study-twins (entries)
8778 "Return dangerous twins of first entry in ENTRIES.
8779 Dangerous twins are routines with same name, but in different files on
8780 the load path. If a file is in the system library and has an entry in
8781 the `idlwave-system-routines' list, we omit the latter as
8782 non-dangerous because many IDL routines are implemented as library
8783 routines, and may have been scanned."
8784 (let* ((entry (car entries))
8785 (idlwave-twin-name (car entry)) ;
8786 (type (nth 1 entry)) ; Must be bound for
8787 (idlwave-twin-class (nth 2 entry)) ; idlwave-routine-twin-compare
8788 (cnt 0)
8789 source type type-cons file alist syslibp key)
8790 (while (setq entry (pop entries))
8791 (incf cnt)
8792 (setq source (nth 3 entry)
8793 type (car source)
8794 type-cons (cons type (nth 3 source))
8795 file (idlwave-routine-source-file source))
8797 ;; Make KEY to index entry properly
8798 (setq key (cond ((eq type 'system) type)
8799 (file (file-truename file))
8800 (t 'unresolved)))
8802 ;; Check for an entry in the system library
8803 (if (and file
8804 (not syslibp)
8805 (idlwave-syslib-p file))
8806 (setq syslibp t))
8808 ;; If there's more than one matching entry for the same file, just
8809 ;; append the type-cons to the type list.
8810 (if (setq entry (assoc key alist))
8811 (push type-cons (nth 2 entry))
8812 (push (list key file (list type-cons)) alist)))
8814 (setq alist (nreverse alist))
8816 (when syslibp
8817 ;; File is in system *library* - remove any 'system entry
8818 (setq alist (delq (assq 'system alist) alist)))
8820 ;; If 'system remains and we've scanned the syslib, it's a builtin
8821 ;; (rather than a !DIR/lib/.pro file bundled as source).
8822 (when (and (idlwave-syslib-scanned-p)
8823 (setq entry (assoc 'system alist)))
8824 (setcar entry 'builtin))
8825 (sort alist 'idlwave-routine-twin-compare)))
8827 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8828 ;; (defvar type)
8829 (defmacro idlwave-xor (a b)
8830 `(and (or ,a ,b)
8831 (not (and ,a ,b))))
8833 (defun idlwave-routine-entry-compare (a b)
8834 "Compare two routine info entries for sorting.
8835 This is the general case. It first compares class, names, and type.
8836 If it turns out that A and B are twins (same name, class, and type),
8837 calls another routine which compares twins on the basis of their file
8838 names and path locations."
8839 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8840 (cond
8841 ((not (equal (idlwave-downcase-safe class)
8842 (idlwave-downcase-safe (nth 2 b))))
8843 ;; Class decides
8844 (cond ((null (nth 2 b)) nil)
8845 ((null class) t)
8846 (t (string< (downcase class) (downcase (nth 2 b))))))
8847 ((not (equal (downcase name) (downcase (car b))))
8848 ;; Name decides
8849 (string< (downcase name) (downcase (car b))))
8850 ((not (eq type (nth 1 b)))
8851 ;; Type decides
8852 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8854 ;; A and B are twins - so the decision is more complicated.
8855 ;; Call twin-compare with the proper arguments.
8856 (idlwave-routine-entry-compare-twins a b)))))
8858 (defun idlwave-routine-entry-compare-twins (a b)
8859 "Compare two routine entries, under the assumption that they are twins.
8860 This basically calls `idlwave-routine-twin-compare' with the correct args."
8861 (let* ((idlwave-twin-name (car a))
8862 (type (nth 1 a))
8863 (idlwave-twin-class (nth 2 a)) ; used in idlwave-routine-twin-compare
8864 (asrc (nth 3 a))
8865 (atype (car asrc))
8866 (bsrc (nth 3 b))
8867 (btype (car bsrc))
8868 (afile (idlwave-routine-source-file asrc))
8869 (bfile (idlwave-routine-source-file bsrc)))
8870 (idlwave-routine-twin-compare
8871 (if (stringp afile)
8872 (list (file-truename afile) afile (list atype))
8873 (list atype afile (list atype)))
8874 (if (stringp bfile)
8875 (list (file-truename bfile) bfile (list btype))
8876 (list btype bfile (list btype))))))
8878 ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
8879 (defvar idlwave-twin-class)
8880 (defvar idlwave-twin-name)
8882 (defun idlwave-routine-twin-compare (a b)
8883 "Compare two routine twin entries for sorting.
8884 In here, A and B are not normal routine info entries, but special
8885 lists (KEY FILENAME (TYPES...)).
8886 This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
8887 (let* (;; Dis-assemble entries
8888 (akey (car a)) (bkey (car b))
8889 (afile (nth 1 a)) (bfile (nth 1 b))
8890 (atypes (nth 2 a)) (btypes (nth 2 b))
8891 ;; System routines?
8892 (asysp (memq akey '(builtin system)))
8893 (bsysp (memq bkey '(builtin system)))
8894 ;; Compiled routines?
8895 (acompp (memq 'compiled atypes))
8896 (bcompp (memq 'compiled btypes))
8897 ;; Unresolved?
8898 (aunresp (or (eq akey 'unresolved)
8899 (and acompp (not afile))))
8900 (bunresp (or (eq bkey 'unresolved)
8901 (and bcompp (not bfile))))
8902 ;; Buffer info available?
8903 (abufp (memq 'buffer atypes))
8904 (bbufp (memq 'buffer btypes))
8905 ;; On search path?
8906 (tpath-alist (idlwave-true-path-alist))
8907 (apathp (and (stringp akey)
8908 (assoc (file-name-directory akey) tpath-alist)))
8909 (bpathp (and (stringp bkey)
8910 (assoc (file-name-directory bkey) tpath-alist)))
8911 ;; How early on search path? High number means early since we
8912 ;; measure the tail of the path list
8913 (anpath (length (memq apathp tpath-alist)))
8914 (bnpath (length (memq bpathp tpath-alist)))
8915 ;; Look at file names
8916 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8917 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8918 (fname-re (if idlwave-twin-class
8919 (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8920 (regexp-quote (downcase idlwave-twin-class))
8921 (regexp-quote (downcase idlwave-twin-name)))
8922 (format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
8923 ;; Is file name derived from the routine name?
8924 ;; Method file or class definition file?
8925 (anamep (string-match fname-re aname))
8926 (adefp (and idlwave-twin-class anamep
8927 (string= "define" (match-string 1 aname))))
8928 (bnamep (string-match fname-re bname))
8929 (bdefp (and idlwave-twin-class bnamep
8930 (string= "define" (match-string 1 bname)))))
8932 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8933 ;; doesn't it? The difficult stuff is hidden above...
8934 (cond
8935 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8936 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8937 ((and idlwave-sort-prefer-buffer-info
8938 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8939 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8940 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8941 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8942 ((and idlwave-twin-class anamep bnamep ; both file names match ->
8943 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8944 ((> anpath bnpath) t) ; Who is first on path?
8945 (t nil)))) ; Default
8947 (defun idlwave-routine-source-file (source)
8948 (if (nth 2 source)
8949 (expand-file-name (nth 1 source) (nth 2 source))
8950 (nth 1 source)))
8952 (defun idlwave-downcase-safe (string)
8953 "Downcase if string, else return unchanged."
8954 (if (stringp string)
8955 (downcase string)
8956 string))
8958 (defun idlwave-count-eq (elt list)
8959 "How often is ELT in LIST?"
8960 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8962 (defun idlwave-count-memq (elt alist)
8963 "How often is ELT a key in ALIST?"
8964 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8966 (defun idlwave-syslib-p (file)
8967 "Non-nil if FILE is in the system library."
8968 (let* ((true-syslib (file-name-as-directory
8969 (file-truename
8970 (expand-file-name "lib" (idlwave-sys-dir)))))
8971 (true-file (file-truename file)))
8972 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8974 (defun idlwave-lib-p (file)
8975 "Non-nil if FILE is in the library."
8976 (let ((true-dir (file-name-directory (file-truename file))))
8977 (assoc true-dir (idlwave-true-path-alist))))
8979 (defun idlwave-path-alist-add-flag (list-entry flag)
8980 "Add a flag to the path list entry, if not set."
8981 (let ((flags (cdr list-entry)))
8982 (add-to-list 'flags flag)
8983 (setcdr list-entry flags)))
8985 (defun idlwave-path-alist-remove-flag (list-entry flag)
8986 "Remove a flag to the path list entry, if set."
8987 (let ((flags (delq flag (cdr list-entry))))
8988 (setcdr list-entry flags)))
8990 (defun idlwave-true-path-alist ()
8991 "Return `idlwave-path-alist' alist with true-names.
8992 Info is cached, but relies on the functions setting `idlwave-path-alist'
8993 to reset the variable `idlwave-true-path-alist' to nil."
8994 (or idlwave-true-path-alist
8995 (setq idlwave-true-path-alist
8996 (mapcar (lambda(x) (cons
8997 (file-name-as-directory
8998 (file-truename
8999 (directory-file-name
9000 (car x))))
9001 (cdr x)))
9002 idlwave-path-alist))))
9004 (defun idlwave-syslib-scanned-p ()
9005 "Non-nil if the system lib file !DIR/lib has been scanned."
9006 (let* ((true-syslib (file-name-as-directory
9007 (file-truename
9008 (expand-file-name "lib" (idlwave-sys-dir))))))
9009 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9011 ;; ----------------------------------------------------------------------------
9013 ;; Online Help display
9016 ;; ----------------------------------------------------------------------------
9018 ;; Additions for use with imenu.el and func-menu.el
9019 ;; (pop-up a list of IDL units in the current file).
9022 (defun idlwave-prev-index-position ()
9023 "Search for the previous procedure or function.
9024 Return nil if not found. For use with imenu.el."
9025 (save-match-data
9026 (cond
9027 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9028 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9029 (t nil))))
9031 (defun idlwave-unit-name ()
9032 "Return the unit name.
9033 Assumes that point is at the beginning of the unit as found by
9034 `idlwave-prev-index-position'."
9035 (forward-sexp 2)
9036 (forward-sexp -1)
9037 (let ((begin (point)))
9038 (re-search-forward
9039 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9040 (if (fboundp 'buffer-substring-no-properties)
9041 (buffer-substring-no-properties begin (point))
9042 (buffer-substring begin (point)))))
9044 (defalias 'idlwave-function-menu
9045 (condition-case nil
9046 (progn
9047 (require 'func-menu)
9048 'function-menu)
9049 (error (condition-case nil
9050 (progn
9051 (require 'imenu)
9052 'imenu)
9053 (error nil)))))
9055 ;; Here we hack func-menu.el in order to support this new mode.
9056 ;; The latest versions of func-menu.el already have this stuff in, so
9057 ;; we hack only if it is not already there.
9058 (when (fboundp 'eval-after-load)
9059 (eval-after-load "func-menu"
9060 '(progn
9061 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9062 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9063 (setq fume-function-name-regexp-alist
9064 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9065 fume-function-name-regexp-alist)))
9066 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9067 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9068 (setq fume-find-function-name-method-alist
9069 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9070 fume-find-function-name-method-alist))))))
9072 (defun idlwave-edit-in-idlde ()
9073 "Edit the current file in IDL Development environment."
9074 (interactive)
9075 (start-process "idldeclient" nil
9076 idlwave-shell-explicit-file-name "-c" "-e"
9077 (buffer-file-name)))
9079 (defvar idlwave-help-use-assistant)
9080 (defun idlwave-launch-idlhelp ()
9081 "Start the IDLhelp application."
9082 (interactive)
9083 (if idlwave-help-use-assistant
9084 (idlwave-help-assistant-raise)
9085 (start-process "idlhelp" nil idlwave-help-application)))
9087 ;; Menus - using easymenu.el
9088 (defvar idlwave-mode-menu-def
9089 `("IDLWAVE"
9090 ["PRO/FUNC menu" idlwave-function-menu t]
9091 ("Motion"
9092 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9093 ["Subprogram End" idlwave-end-of-subprogram t]
9094 ["Block Start" idlwave-beginning-of-block t]
9095 ["Block End" idlwave-end-of-block t]
9096 ["Up Block" idlwave-backward-up-block t]
9097 ["Down Block" idlwave-down-block t]
9098 ["Skip Block Backward" idlwave-backward-block t]
9099 ["Skip Block Forward" idlwave-forward-block t])
9100 ("Mark"
9101 ["Subprogram" idlwave-mark-subprogram t]
9102 ["Block" idlwave-mark-block t]
9103 ["Header" idlwave-mark-doclib t])
9104 ("Format"
9105 ["Indent Entire Statement" idlwave-indent-statement
9106 :active t :keys "C-u \\[indent-for-tab-command]" ]
9107 ["Indent Subprogram" idlwave-indent-subprogram t]
9108 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9109 ["Continue/Split line" idlwave-split-line t]
9110 "--"
9111 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9112 :selected (symbol-value idlwave-fill-function)])
9113 ("Templates"
9114 ["Procedure" idlwave-procedure t]
9115 ["Function" idlwave-function t]
9116 ["Doc Header" idlwave-doc-header t]
9117 ["Log" idlwave-doc-modification t]
9118 "--"
9119 ["Case" idlwave-case t]
9120 ["For" idlwave-for t]
9121 ["Repeat" idlwave-repeat t]
9122 ["While" idlwave-while t]
9123 "--"
9124 ["Close Block" idlwave-close-block t])
9125 ("Completion"
9126 ["Complete" idlwave-complete t]
9127 ("Complete Specific"
9128 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9129 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9130 "--"
9131 ["3 Function Name" (idlwave-complete 'function) t]
9132 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9133 "--"
9134 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9135 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9136 "--"
9137 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9138 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9139 "--"
9140 ["9 Class Name" idlwave-complete-class t]))
9141 ("Routine Info"
9142 ["Show Routine Info" idlwave-routine-info t]
9143 ["Online Context Help" idlwave-context-help t]
9144 "--"
9145 ["Find Routine Source" idlwave-find-module t]
9146 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9147 "--"
9148 ["Update Routine Info" idlwave-update-routine-info t]
9149 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9150 "--"
9151 "IDL User Catalog"
9152 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9153 ["Scan Directories" (idlwave-update-routine-info '(16))
9154 (and idlwave-path-alist (not idlwave-catalog-process))]
9155 ["Scan Directories &" (idlwave-update-routine-info '(64))
9156 (and idlwave-path-alist (not idlwave-catalog-process))]
9157 "--"
9158 "Routine Shadows"
9159 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9160 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9161 ["Check Everything" idlwave-list-all-load-path-shadows t])
9162 ("Misc"
9163 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9164 "--"
9165 ["Insert TAB character" idlwave-hard-tab t])
9166 "--"
9167 ("External"
9168 ["Start IDL shell" idlwave-shell t]
9169 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9170 ["Launch IDL Help" idlwave-launch-idlhelp t])
9171 "--"
9172 ("Customize"
9173 ["Browse IDLWAVE Group" idlwave-customize t]
9174 "--"
9175 ["Build Full Customize Menu" idlwave-create-customize-menu
9176 (fboundp 'customize-menu-create)])
9177 ("Documentation"
9178 ["Describe Mode" describe-mode t]
9179 ["Abbreviation List" idlwave-list-abbrevs t]
9180 "--"
9181 ["Commentary in idlwave.el" idlwave-show-commentary t]
9182 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9183 "--"
9184 ["Info" idlwave-info t]
9185 "--"
9186 ["Help with Topic" idlwave-help-assistant-help-with-topic
9187 idlwave-help-use-assistant]
9188 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9190 (defvar idlwave-mode-debug-menu-def
9191 '("Debug"
9192 ["Start IDL shell" idlwave-shell t]
9193 ["Save and .RUN buffer" idlwave-shell-save-and-run
9194 (and (boundp 'idlwave-shell-automatic-start)
9195 idlwave-shell-automatic-start)]))
9197 (if (or (featurep 'easymenu) (load "easymenu" t))
9198 (progn
9199 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9200 "IDL and WAVE CL editing menu"
9201 idlwave-mode-menu-def)
9202 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9203 "IDL and WAVE CL editing menu"
9204 idlwave-mode-debug-menu-def)))
9206 (defun idlwave-customize ()
9207 "Call the customize function with `idlwave' as argument."
9208 (interactive)
9209 ;; Try to load the code for the shell, so that we can customize it
9210 ;; as well.
9211 (or (featurep 'idlw-shell)
9212 (load "idlw-shell" t))
9213 (customize-browse 'idlwave))
9215 (defun idlwave-create-customize-menu ()
9216 "Create a full customization menu for IDLWAVE, insert it into the menu."
9217 (interactive)
9218 (if (fboundp 'customize-menu-create)
9219 (progn
9220 ;; Try to load the code for the shell, so that we can customize it
9221 ;; as well.
9222 (or (featurep 'idlw-shell)
9223 (load "idlw-shell" t))
9224 (easy-menu-change
9225 '("IDLWAVE") "Customize"
9226 `(["Browse IDLWAVE group" idlwave-customize t]
9227 "--"
9228 ,(customize-menu-create 'idlwave)
9229 ["Set" Custom-set t]
9230 ["Save" Custom-save t]
9231 ["Reset to Current" Custom-reset-current t]
9232 ["Reset to Saved" Custom-reset-saved t]
9233 ["Reset to Standard Settings" Custom-reset-standard t]))
9234 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9235 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9237 (defun idlwave-show-commentary ()
9238 "Use the finder to view the file documentation from `idlwave.el'."
9239 (interactive)
9240 (finder-commentary "idlwave.el"))
9242 (defun idlwave-shell-show-commentary ()
9243 "Use the finder to view the file documentation from `idlw-shell.el'."
9244 (interactive)
9245 (finder-commentary "idlw-shell.el"))
9247 (defun idlwave-info ()
9248 "Read documentation for IDLWAVE in the info system."
9249 (interactive)
9250 (info "idlwave"))
9252 (defun idlwave-list-abbrevs (arg)
9253 "Show the code abbreviations define in IDLWAVE mode.
9254 This lists all abbrevs where the replacement text differs from the input text.
9255 These are the ones the users want to learn to speed up their writing.
9257 The function does *not* list abbrevs which replace a word with itself
9258 to call a hook. These hooks are used to change the case of words or
9259 to blink the matching `begin', and the user does not need to know them.
9261 With arg, list all abbrevs with the corresponding hook.
9263 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9265 (interactive "P")
9266 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9267 abbrevs
9268 str rpl func fmt (len-str 0) (len-rpl 0))
9269 (mapatoms
9270 (lambda (sym)
9271 (if (symbol-value sym)
9272 (progn
9273 (setq str (symbol-name sym)
9274 rpl (symbol-value sym)
9275 func (symbol-function sym))
9276 (if arg
9277 (setq func (prin1-to-string func))
9278 (if (and (listp func) (stringp (nth 2 func)))
9279 (setq rpl (concat "EVAL: " (nth 2 func))
9280 func "")
9281 (setq func "")))
9282 (if (or arg (not (string= rpl str)))
9283 (progn
9284 (setq len-str (max len-str (length str)))
9285 (setq len-rpl (max len-rpl (length rpl)))
9286 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9287 table)
9288 ;; sort the list
9289 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9290 ;; Make the format
9291 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9292 (with-output-to-temp-buffer "*Help*"
9293 (if arg
9294 (progn
9295 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9296 (princ "=========================================\n\n")
9297 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9298 (princ (format fmt "---" "-------" "----")))
9299 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9300 (princ "================================================\n\n")
9301 (princ (format fmt "KEY" "ACTION" ""))
9302 (princ (format fmt "---" "------" "")))
9303 (dolist (list abbrevs)
9304 (setq str (car list)
9305 rpl (nth 1 list)
9306 func (nth 2 list))
9307 (princ (format fmt str rpl func)))))
9308 ;; Make sure each abbreviation uses only one display line
9309 (with-current-buffer "*Help*"
9310 (setq truncate-lines t)))
9312 ;; Add .pro files to speedbar for support, if it's loaded
9313 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9315 ;; Set an idle timer to load the routine info.
9316 ;; Will only work on systems which support this.
9317 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9319 ;; Run the hook
9320 (run-hooks 'idlwave-load-hook)
9322 (provide 'idlwave)
9324 ;;; idlwave.el ends here