Add "Package:" file headers to denote built-in packages.
[emacs.git] / lisp / progmodes / idlwave.el
blobdc85d094810a6a45c6675eac2e4c71fb0f42a155
1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Carsten Dominik <dominik@science.uva.nl>
8 ;; Chris Chase <chase@att.com>
9 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; Version: 6.1.22
11 ;; Keywords: languages
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;;; Commentary:
30 ;; IDLWAVE enables feature-rich development and interaction with IDL,
31 ;; the Interactive Data Language. It provides a compelling,
32 ;; full-featured alternative to the IDLDE development environment
33 ;; bundled with IDL.
35 ;; In the remotely distant past, based on pascal.el, though bears
36 ;; little resemblance to it now.
38 ;; Incorporates many ideas, such as abbrevs, action routines, and
39 ;; continuation line indenting, from wave.el.
40 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
42 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
43 ;; for features, key bindings, and info.
44 ;; Also, Info format documentation is available with `M-x idlwave-info'
46 ;; New versions of IDLWAVE, documentation, and more information
47 ;; available from:
48 ;; http://idlwave.org
50 ;; INSTALLATION
51 ;; ============
53 ;; Follow the instructions in the INSTALL file of the distribution.
54 ;; In short, put this file on your load path and add the following
55 ;; lines to your .emacs file:
57 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
58 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
59 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
62 ;; SOURCE
63 ;; ======
65 ;; The newest version of this file is available from the maintainer's
66 ;; Webpage:
68 ;; http://idlwave.org
70 ;; DOCUMENTATION
71 ;; =============
73 ;; IDLWAVE is documented online in info format. A printable version
74 ;; of the documentation is available from the maintainers webpage (see
75 ;; SOURCE).
78 ;; ACKNOWLEDGMENTS
79 ;; ===============
81 ;; Thanks to the following people for their contributions and comments:
83 ;; Ulrik Dickow <dickow_at_nbi.dk>
84 ;; Eric E. Dors <edors_at_lanl.gov>
85 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
86 ;; David Huenemoerder <dph_at_space.mit.edu>
87 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
88 ;; Dick Jackson <dick_at_d-jackson.com>
89 ;; Xuyong Liu <liu_at_stsci.edu>
90 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
91 ;; Laurent Mugnier <mugnier_at_onera.fr>
92 ;; Lubos Pochman <lubos_at_rsinc.com>
93 ;; Bob Portmann <portmann_at_al.noaa.gov>
94 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
95 ;; Marty Ryba <ryba_at_ll.mit.edu>
96 ;; Paul Sorenson <aardvark62_at_msn.com>
97 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
98 ;; Phil Williams <williams_at_irc.chmcc.org>
100 ;; CUSTOMIZATION:
101 ;; =============
103 ;; IDLWAVE has extensive customize support; to learn about the
104 ;; variables which control the mode's behavior, use `M-x
105 ;; idlwave-customize'.
107 ;; You can set your own preferred values with Customize, or with Lisp
108 ;; code in .emacs. For an example of what to put into .emacs, check
109 ;; the TexInfo documentation or see a complete .emacs available at the
110 ;; website.
112 ;; KNOWN PROBLEMS:
113 ;; ==============
115 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
116 ;; Numerics, Inc. is growing less and less complete as the two
117 ;; languages grow increasingly apart. The mode probably shouldn't
118 ;; even have "WAVE" in its title, but it's catchy, and was required
119 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
121 ;; Moving the point backwards in conjunction with abbrev expansion
122 ;; does not work as I would like it, but this is a problem with
123 ;; emacs abbrev expansion done by the self-insert-command. It ends
124 ;; up inserting the character that expanded the abbrev after moving
125 ;; point backward, e.g., "\cl" expanded with a space becomes
126 ;; "LONG( )" with point before the close paren. This is solved by
127 ;; using a temporary function in `post-command-hook' - not pretty,
128 ;; but it works.
130 ;; Tabs and spaces are treated equally as whitespace when filling a
131 ;; comment paragraph. To accomplish this, tabs are permanently
132 ;; replaced by spaces in the text surrounding the paragraph, which
133 ;; may be an undesirable side-effect. Replacing tabs with spaces is
134 ;; limited to comments only and occurs only when a comment
135 ;; paragraph is filled via `idlwave-fill-paragraph'.
137 ;; Muti-statement lines (using "&") on block begin and end lines can
138 ;; ruin the formatting. For example, multiple end statements on a
139 ;; line: endif & endif. Using "&" outside of block begin/end lines
140 ;; should be okay.
142 ;; Determining the expression at point for printing and other
143 ;; examination commands is somewhat rough: currently only fairly
144 ;; simple entities are found. You can always drag-select or examine
145 ;; a pre-selected region.
147 ;; When forcing completion of method keywords, the initial
148 ;; query for a method has multiple entries for some methods. Would
149 ;; be too difficult to fix this hardly used case.
152 ;;; Code:
155 (eval-when-compile (require 'cl))
156 (require 'idlw-help)
158 ;; For XEmacs
159 (unless (fboundp 'line-beginning-position)
160 (defalias 'line-beginning-position 'point-at-bol))
161 (unless (fboundp 'line-end-position)
162 (defalias 'line-end-position 'point-at-eol))
163 (unless (fboundp 'char-valid-p)
164 (defalias 'char-valid-p 'characterp))
165 (unless (fboundp 'match-string-no-properties)
166 (defalias 'match-string-no-properties 'match-string))
168 (if (not (fboundp 'cancel-timer))
169 (condition-case nil
170 (require 'timer)
171 (error nil)))
173 (declare-function idlwave-shell-get-path-info "idlw-shell")
174 (declare-function idlwave-shell-temp-file "idlw-shell")
175 (declare-function idlwave-shell-is-running "idlw-shell")
176 (declare-function widget-value "wid-edit" (widget))
177 (declare-function comint-dynamic-complete-filename "comint" ())
179 (defgroup idlwave nil
180 "Major mode for editing IDL .pro files."
181 :tag "IDLWAVE"
182 :link '(url-link :tag "Home Page"
183 "http://idlwave.org")
184 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
185 "idlw-shell.el")
186 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
187 :link '(custom-manual "(idlwave)Top")
188 :prefix "idlwave"
189 :group 'languages)
192 ;;; Variables for indentation behavior ---------------------------------------
194 (defgroup idlwave-code-formatting nil
195 "Indentation and formatting options for IDLWAVE mode."
196 :group 'idlwave)
198 (defcustom idlwave-main-block-indent 2
199 "*Extra indentation for the main block of code.
200 That is the block between the FUNCTION/PRO statement and the END
201 statement for that program unit."
202 :group 'idlwave-code-formatting
203 :type 'integer)
205 (defcustom idlwave-block-indent 3
206 "*Extra indentation applied to block lines.
207 If you change this, you probably also want to change `idlwave-end-offset'."
208 :group 'idlwave-code-formatting
209 :type 'integer)
211 (defcustom idlwave-end-offset -3
212 "*Extra indentation applied to block END lines.
213 A value equal to negative `idlwave-block-indent' will make END lines
214 line up with the block BEGIN lines."
215 :group 'idlwave-code-formatting
216 :type 'integer)
218 (defcustom idlwave-continuation-indent 3
219 "*Extra indentation applied to continuation lines.
220 This extra offset applies to the first of a set of continuation lines.
221 The following lines receive the same indentation as the first."
222 :group 'idlwave-code-formatting
223 :type 'integer)
225 (defcustom idlwave-max-extra-continuation-indent 40
226 "*Maximum additional indentation for special continuation indent.
227 Several special indentations are tried to help line up continuation
228 lines in routine calls or definitions, other statements with
229 parentheses, or assignment statements. This variable specifies a
230 maximum amount by which this special indentation can exceed the
231 standard continuation indentation, otherwise defaulting to a fixed
232 offset. Set to 0 to effectively disable all special continuation
233 indentation, or to a large number (like 100) to enable it in all
234 cases. See also `idlwave-indent-to-open-paren', which can override
235 this variable."
236 :group 'idlwave-code-formatting
237 :type 'integer)
239 (defcustom idlwave-indent-to-open-paren t
240 "*Non-nil means, indent continuation lines to innermost open parenthesis.
241 This indentation occurs even if otherwise disallowed by
242 `idlwave-max-extra-continuation-indent'. Matching parens and the
243 interleaving args are lined up. Example:
245 x = function_a(function_b(function_c( a, b, [1,2,3, $
246 4,5,6 $
247 ], $
248 c, d $
251 When this variable is nil, paren alignment may still occur, based on
252 the value of `idlwave-max-extra-continuation-indent', which, if zero,
253 would yield:
255 x = function_a(function_b(function_c( a, b, [1,2,3, $
256 4,5,6 $
257 ], $
258 c, d $
259 )))"
260 :group 'idlwave-code-formatting
261 :type 'boolean)
263 (defcustom idlwave-indent-parens-nested nil
264 "*Non-nil means, indent continuation lines with parens by nesting
265 lines at consecutively deeper levels."
266 :group 'idlwave-code-formatting
267 :type 'boolean)
270 (defcustom idlwave-hanging-indent t
271 "*If set non-nil then comment paragraphs are indented under the
272 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
273 of the paragraph."
274 :group 'idlwave-code-formatting
275 :type 'boolean)
277 (defcustom idlwave-hang-indent-regexp "- "
278 "*Regular expression matching the position of the hanging indent
279 in the first line of a comment paragraph. The size of the indent
280 extends to the end of the match for the regular expression."
281 :group 'idlwave-code-formatting
282 :type 'regexp)
284 (defcustom idlwave-use-last-hang-indent nil
285 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
286 :group 'idlwave-code-formatting
287 :type 'boolean)
289 (defcustom idlwave-fill-comment-line-only t
290 "*If non-nil then auto fill will only operate on comment lines."
291 :group 'idlwave-code-formatting
292 :type 'boolean)
294 (defcustom idlwave-auto-fill-split-string t
295 "*If non-nil then auto fill will split strings with the IDL `+' operator.
296 When the line end falls within a string, string concatenation with the
297 '+' operator will be used to distribute a long string over lines.
298 If nil and a string is split then a terminal beep and warning are issued.
300 This variable is ignored when `idlwave-fill-comment-line-only' is
301 non-nil, since in this case code is not auto-filled."
302 :group 'idlwave-code-formatting
303 :type 'boolean)
305 (defcustom idlwave-split-line-string t
306 "*If non-nil then `idlwave-split-line' will split strings with `+'.
307 When the splitting point of a line falls inside a string, split the string
308 using the `+' string concatenation operator. If nil and a string is
309 split then a terminal beep and warning are issued."
310 :group 'idlwave-code-formatting
311 :type 'boolean)
313 (defcustom idlwave-no-change-comment ";;;"
314 "*The indentation of a comment that starts with this regular
315 expression will not be changed. Note that the indentation of a comment
316 at the beginning of a line is never changed."
317 :group 'idlwave-code-formatting
318 :type 'string)
320 (defcustom idlwave-begin-line-comment nil
321 "*A comment anchored at the beginning of line.
322 A comment matching this regular expression will not have its
323 indentation changed. If nil the default is \"^;\", i.e., any line
324 beginning with a \";\". Expressions for comments at the beginning of
325 the line should begin with \"^\"."
326 :group 'idlwave-code-formatting
327 :type '(choice (const :tag "Any line beginning with `;'" nil)
328 'regexp))
330 (defcustom idlwave-code-comment ";;[^;]"
331 "*A comment that starts with this regular expression on a line by
332 itself is indented as if it is a part of IDL code. As a result if
333 the comment is not preceded by whitespace it is unchanged."
334 :group 'idlwave-code-formatting
335 :type 'regexp)
337 ;; Comments not matching any of the above will be indented as a
338 ;; right-margin comment, i.e., to a minimum of `comment-column'.
340 ;;; Routine Info and Completion ---------------------------------------
342 (defgroup idlwave-routine-info nil
343 "Routine Info options for IDLWAVE mode."
344 :group 'idlwave)
346 (defcustom idlwave-use-library-catalogs t
347 "*Non-nil means search the IDL path for library catalog files.
349 These files, named .idlwave_catalog, document routine information for
350 individual directories and libraries of IDL .pro files. Many popular
351 libraries come with catalog files by default, so leaving this on is
352 usually a good idea."
353 :group 'idlwave-routine-info
354 :type 'boolean)
356 (defcustom idlwave-init-rinfo-when-idle-after 10
357 "*Seconds of idle time before routine info is automatically initialized.
358 Initializing the routine info can take a long time, in particular if a
359 large number of library catalogs are involved. When Emacs is idle for
360 more than the number of seconds specified by this variable, it starts
361 the initialization. The process is split into five steps, in order to
362 keep work interruption as short as possible. If one of the steps
363 finishes, and no user input has arrived in the mean time, initialization
364 proceeds immediately to the next step. A good value for this variable
365 is about 1/3 of the time initialization take in your setup. So if you
366 have a fast machine and no problems with a slow network connection,
367 don't hesitate to set this to 2 seconds. A value of 0 means, don't
368 initialize automatically, but instead wait until routine information is
369 needed, and initialize then."
370 :group 'idlwave-routine-info
371 :type 'number)
373 (defcustom idlwave-scan-all-buffers-for-routine-info t
374 "*Non-nil means, scan buffers for IDL programs when updating info.
375 The scanning is done by the command `idlwave-update-routine-info'.
376 The following values are allowed:
378 nil Don't scan any buffers.
379 t Scan all `idlwave-mode' buffers in the current editing session.
380 current Scan only the current buffer, but no other buffers."
381 :group 'idlwave-routine-info
382 :type '(choice
383 (const :tag "No buffer" nil)
384 (const :tag "All buffers" t)
385 (const :tag "Current buffer only" 'current)))
387 (defcustom idlwave-query-shell-for-routine-info t
388 "*Non-nil means query the shell for info about compiled routines.
389 Querying the shell is useful to get information about compiled modules,
390 and it is turned on by default. However, when you have a complete library
391 scan, this is not necessary."
392 :group 'idlwave-routine-info
393 :type 'boolean)
395 (defcustom idlwave-auto-routine-info-updates
396 '(find-file save-buffer kill-buffer compile-buffer)
397 "*Controls under what circumstances routine info is updated automatically.
398 Possible values:
399 nil Never
400 t All available
401 \(...) A list of circumstances. Allowed members are:
402 find-file Add info for new IDLWAVE buffers.
403 save-buffer Update buffer info when buffer is saved
404 kill-buffer Remove buffer info when buffer gets killed
405 compile-buffer Update shell info after `idlwave-shell-save-and...'"
406 :group 'idlwave-routine-info
407 :type '(choice
408 (const :tag "Never" nil)
409 (const :tag "As often as possible" t)
410 (set :tag "Checklist" :greedy t
411 (const :tag "When visiting a file" find-file)
412 (const :tag "When saving a buffer" save-buffer)
413 (const :tag "After a buffer was killed" kill-buffer)
414 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
416 (defcustom idlwave-rinfo-max-source-lines 5
417 "*Maximum number of source files displayed in the Routine Info window.
418 When an integer, it is the maximum number of source files displayed.
419 A value of t means to show all source files."
420 :group 'idlwave-routine-info
421 :type 'integer)
423 (defcustom idlwave-library-path nil
424 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
425 When selecting the directories to scan for IDL user catalog routine
426 info, IDLWAVE can, under UNIX, query the shell for the exact search
427 path \(the value of !PATH). However, under Windows and MacOS
428 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
429 variable can be set to specify the paths where IDLWAVE can find PRO
430 files. The shell will only be asked for a list of paths when this
431 variable is nil. The value is a list of directories. A directory
432 preceeded by a `+' will be searched recursively. If you set this
433 variable on a UNIX system, the shell will not be queried. See also
434 `idlwave-system-directory'."
435 :group 'idlwave-routine-info
436 :type '(repeat (directory)))
438 (defcustom idlwave-system-directory ""
439 "The IDL system directory for Windows and MacOS. Not needed under
440 UNIX. Set this to the value of the `!DIR' system variable in IDL.
441 IDLWAVE uses this to find out which of the library routines belong to
442 the official system library. All files inside the `lib' subdirectory
443 are considered system library files - so don't install private stuff
444 in this directory. On UNIX systems, IDLWAVE queries the shell for the
445 value of `!DIR'. See also `idlwave-library-path'."
446 :group 'idlwave-routine-info
447 :type 'directory)
449 ;; Configuration files
450 (defcustom idlwave-config-directory
451 (convert-standard-filename "~/.idlwave")
452 "*Directory for configuration files and user-library catalog."
453 :group 'idlwave-routine-info
454 :type 'file)
456 (defvar idlwave-user-catalog-file "idlusercat.el")
457 (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
458 (defvar idlwave-path-file "idlpath.el")
460 (defvar idlwave-libinfo-file nil
461 "*Obsolete variable, no longer used.")
463 (defcustom idlwave-special-lib-alist nil
464 "Alist of regular expressions matching special library directories.
465 When listing routine source locations, IDLWAVE gives a short hint where
466 the file defining the routine is located. By default it lists `SystemLib'
467 for routines in the system library `!DIR/lib' and `Library' for anything
468 else. This variable can define additional types. The car of each entry
469 is a regular expression matching the file name (they normally will match
470 on the path). The cdr is the string to be used as identifier. Max 10
471 chars are allowed."
472 :group 'idlwave-routine-info
473 :type '(repeat
474 (cons regexp string)))
476 (defcustom idlwave-auto-write-paths t
477 "Write out path (!PATH) and system directory (!DIR) info automatically.
478 Path info is needed to locate library catalog files. If non-nil,
479 whenever the path-list changes as a result of shell-query, etc., it is
480 written to file. Otherwise, the menu option \"Write Paths\" can be
481 used to force a write."
482 :group 'idlwave-routine-info
483 :type 'boolean)
485 (defgroup idlwave-completion nil
486 "Completion options for IDLWAVE mode."
487 :prefix "idlwave"
488 :group 'idlwave)
490 (eval-and-compile
491 (defconst idlwave-tmp
492 '(choice :tag "by applying the function"
493 (const upcase)
494 (const downcase)
495 (const capitalize)
496 (const preserve)
497 (symbol :tag "Other"))))
499 (defcustom idlwave-completion-case '((routine . upcase)
500 (keyword . upcase)
501 (class . preserve)
502 (method . preserve))
503 "Association list setting the case of completed words.
505 This variable determines the case (UPPER/lower/Capitalized...) of
506 words inserted into the buffer by completion. The preferred case can
507 be specified separately for routine names, keywords, classes and
508 methods.
509 This alist should therefore have entries for `routine' (normal
510 functions and procedures, i.e. non-methods), `keyword', `class', and
511 `method'. Plausible values are
513 upcase upcase whole word, like `BOX_CURSOR'
514 downcase downcase whole word, like `read_ppm'
515 capitalize capitalize each part, like `Widget_Control'
516 preserve preserve case as is, like `IDLgrView'
518 The value can also be any Emacs Lisp function which transforms the
519 case of characters in a string.
521 A value of `preserve' means that the case of the completed word is
522 identical to the way it was written in the definition statement of the
523 routine. This was implemented to allow for mixed-case completion, in
524 particular of object classes and methods.
525 If a completable word is defined in multiple locations, the meaning of
526 `preserve' is not unique since the different definitions might be
527 cased differently. Therefore IDLWAVE always takes the case of the
528 *first* definition it encounters during routine info collection and
529 uses the case derived from it consistently.
531 Note that a lowercase-only string in the buffer will always be completed in
532 lower case (but see the variable `idlwave-completion-force-default-case').
534 After changing this variable, you need to either restart Emacs or press
535 `C-u C-c C-i' to update the internal lists."
536 :group 'idlwave-completion
537 :type `(repeat
538 (cons (symbol :tag "Derive completion case for")
539 ,idlwave-tmp)))
541 (defcustom idlwave-completion-force-default-case nil
542 "*Non-nil means, completion will always honor `idlwave-completion-case'.
543 When nil, only the completion of a mixed case or upper case string
544 will honor the default settings in `idlwave-completion-case', while
545 the completion of lower case strings will be completed entirely in
546 lower case."
547 :group 'idlwave-completion
548 :type 'boolean)
550 (defcustom idlwave-complete-empty-string-as-lower-case nil
551 "*Non-nil means, the empty string is considered downcase for completion.
552 The case of what is already in the buffer determines the case of completions.
553 When this variable is non-nil, the empty string is considered to be downcase.
554 Completing on the empty string then offers downcase versions of the possible
555 completions."
556 :group 'idlwave-completion
557 :type 'boolean)
559 (defvar idlwave-default-completion-case-is-down nil
560 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
561 `idlwave-completion-case'.")
563 (defcustom idlwave-buffer-case-takes-precedence nil
564 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
565 To make this possible, we need to re-case everything each time we update
566 the routine info from the buffers. This is slow.
567 The default is to consider the case given in the system and library files
568 first which makes updating much faster."
569 :group 'idlwave-completion
570 :type 'boolean)
572 (defcustom idlwave-highlight-help-links-in-completion t
573 "*Non-nil means, highlight completions for which system help is available.
574 Help can then be accessed with mouse-3.
575 This option is only effective when the online help system is installed."
576 :group 'idlwave-completion
577 :type 'boolean)
579 (defcustom idlwave-support-inheritance t
580 "Non-nil means, treat inheritance with completion, online help etc.
581 When nil, IDLWAVE only knows about the native methods and tags of a class,
582 not about inherited ones."
583 :group 'idlwave-routine-info
584 :type 'boolean)
586 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
587 "List of regular expressions for class-driven keyword inheritance.
588 Keyword inheritance is often tied to class inheritance by \"chaining\"
589 up the class tree. While it cannot be assumed that the presence of an
590 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
591 certain methods this assumption is almost always true. The methods
592 for which to assume this can be set here."
593 :group 'idlwave-routine-info
594 :type '(repeat (regexp :tag "Match method:")))
597 (defcustom idlwave-completion-show-classes 1
598 "*Number of classes to show when completing object methods and keywords.
599 When completing methods or keywords for an object with unknown class,
600 the *Completions* buffer will show the valid classes for each completion
601 like this:
603 MyMethod <Class1,Class2,Class3>
605 The value of this variable may be nil to inhibit display, or an integer to
606 indicate the maximum number of classes to display.
608 On XEmacs, a full list of classes will also be placed into a `help-echo'
609 property on the competion items, so that the list of classes for the current
610 item is displayed in the echo area. If the value of this variable is a
611 negative integer, the `help-echo' property will be suppressed."
612 :group 'idlwave-completion
613 :type '(choice (const :tag "Don't show" nil)
614 (integer :tag "Number of classes shown" 1)))
616 (defcustom idlwave-completion-fontify-classes t
617 "*Non-nil means, fontify the classes in completions buffer.
618 This makes it easier to distinguish the completion items from the extra
619 class info listed. See `idlwave-completion-show-classes'."
620 :group 'idlwave-completion
621 :type 'boolean)
623 (defcustom idlwave-query-class '((method-default . nil)
624 (keyword-default . nil))
625 "Association list governing specification of object classes for completion.
627 When IDLWAVE tries to complete object-oriented methods, it usually
628 cannot determine the class of a given object from context. In order
629 to provide the user with a correct list of methods or keywords, it
630 needs to determine the appropriate class. IDLWAVE has two ways of
631 doing this (well, three ways if you count the shell... see
632 `idlwave-shell-query-for-class'):
634 1. Combine the items of all available classes which contain this
635 method for the purpose of completion. So when completing a method,
636 all methods of all known classes are available, and when completing
637 a keyword, all keywords allowed for this method in any class are
638 shown. This behavior is very much like normal completion and is
639 therefore the default. It works much better than one might think -
640 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
641 become uncomfortably long. See also
642 `idlwave-completion-show-classes'.
644 2. The second possibility is to ask the user on each occasion. To
645 make this less interruptive, IDLWAVE can store the class as a text
646 property on the object operator `->'. For a given object in the
647 source code, class selection will then be needed only once
648 - for example to complete the method. Keywords to the method can
649 then be completed directly, because the class is already known.
650 You will have to turn on the storage of the selected class
651 explicitly with the variable `idlwave-store-inquired-class'.
653 This variable allows you to configure IDLWAVE's method and
654 method-keyword completion behavior. Its value is an alist, which
655 should contain at least two elements: (method-default . VALUE) and
656 \(keyword-default . VALUE), where VALUE is either t or nil. These
657 specify if the class should be found during method and keyword
658 completion, respectively.
660 The alist may have additional entries specifying exceptions from the
661 keyword completion rule for specific methods, like INIT or
662 GETPROPERTY. In order to turn on class specification for the INIT
663 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
664 :group 'idlwave-completion
665 :type '(list
666 (cons (const method-default)
667 (boolean :tag "Determine class when completing METHODS "))
668 (cons (const keyword-default)
669 (boolean :tag "Determine class when completing KEYWORDS "))
670 (repeat
671 :tag "Exceptions to defaults"
672 :inline t
673 (cons (string :tag "MODULE" :value "")
674 (boolean :tag "Determine class for this method")))))
676 (defcustom idlwave-store-inquired-class t
677 "*Non-nil means, store class of a method call as text property on `->'.
678 IDLWAVE sometimes has to ask the user for the class associated with a
679 particular object method call. This happens during the commands
680 `idlwave-routine-info' and `idlwave-complete', depending upon the
681 value of the variable `idlwave-query-class'.
683 When you specify a class, this information can be stored as a text
684 property on the `->' arrow in the source code, so that during the same
685 editing session, IDLWAVE will not have to ask again. When this
686 variable is non-nil, IDLWAVE will store and reuse the class information.
687 The class stored can be checked and removed with `\\[idlwave-routine-info]'
688 on the arrow.
690 The default of this variable is nil, since the result of commands then
691 is more predictable. However, if you know what you are doing, it can
692 be nice to turn this on.
694 An arrow which knows the class will be highlighted with
695 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
696 displays (with prefix arg: deletes) the class stored on the arrow
697 at point."
698 :group 'idlwave-completion
699 :type 'boolean)
701 (defcustom idlwave-class-arrow-face 'bold
702 "*Face to highlight object operator arrows `->' which carry a class property.
703 When IDLWAVE stores a class name as text property on an object arrow
704 \(see variable `idlwave-store-inquired-class', it highlights the arrow
705 with this font in order to remind the user that this arrow is special."
706 :group 'idlwave-completion
707 :type 'symbol)
709 (defcustom idlwave-resize-routine-help-window t
710 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
711 :group 'idlwave-completion
712 :type 'boolean)
714 (defcustom idlwave-keyword-completion-adds-equal t
715 "*Non-nil means, completion automatically adds `=' after completed keywords."
716 :group 'idlwave-completion
717 :type 'boolean)
719 (defcustom idlwave-function-completion-adds-paren t
720 "*Non-nil means, completion automatically adds `(' after completed function.
721 nil means, don't add anything.
722 A value of `2' means, also add the closing parenthesis and position cursor
723 between the two."
724 :group 'idlwave-completion
725 :type '(choice (const :tag "Nothing" nil)
726 (const :tag "(" t)
727 (const :tag "()" 2)))
729 (defcustom idlwave-completion-restore-window-configuration t
730 "*Non-nil means, try to restore the window configuration after completion.
731 When completion is not unique, Emacs displays a list of completions.
732 This messes up your window configuration. With this variable set, IDLWAVE
733 restores the old configuration after successful completion."
734 :group 'idlwave-completion
735 :type 'boolean)
737 ;;; Variables for abbrev and action behavior -----------------------------
739 (defgroup idlwave-abbrev-and-indent-action nil
740 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
741 The variables in this group govern this."
742 :group 'idlwave)
744 (defcustom idlwave-do-actions nil
745 "*Non-nil means performs actions when indenting.
746 The actions that can be performed are listed in `idlwave-indent-action-table'."
747 :group 'idlwave-abbrev-and-indent-action
748 :type 'boolean)
750 (defcustom idlwave-abbrev-start-char "\\"
751 "*A single character string used to start abbreviations in abbrev mode.
752 Possible characters to chose from: ~`\%
753 or even '?'. '.' is not a good choice because it can make structure
754 field names act like abbrevs in certain circumstances.
756 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
757 must set it directly using `setq' in the .emacs file before idlwave.el
758 is loaded."
759 :group 'idlwave-abbrev-and-indent-action
760 :type 'string)
762 (defcustom idlwave-surround-by-blank nil
763 "*Non-nil means, enable `idlwave-surround'.
764 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
765 `idlwave-surround'.
766 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
768 Also see the default key bindings for keys using `idlwave-surround'.
769 Keys are bound and made into actions calling `idlwave-surround' with
770 `idlwave-action-and-binding'.
771 See help for `idlwave-action-and-binding' for examples.
773 Also see help for `idlwave-surround'."
774 :group 'idlwave-abbrev-and-indent-action
775 :type 'boolean)
777 (defcustom idlwave-pad-keyword t
778 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
779 Whenever `idlwave-surround' is non-nil then this affects how '=' is
780 padded for keywords and for variables. If t, pad the same as for
781 assignments. If nil then spaces are removed. With any other value,
782 spaces are left unchanged."
783 :group 'idlwave-abbrev-and-indent-action
784 :type '(choice
785 (const :tag "Pad like assignments" t)
786 (const :tag "Remove space near `='" nil)
787 (const :tag "Keep space near `='" 'keep)))
789 (defcustom idlwave-show-block t
790 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
791 :group 'idlwave-abbrev-and-indent-action
792 :type 'boolean)
794 (defcustom idlwave-expand-generic-end nil
795 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
796 :group 'idlwave-abbrev-and-indent-action
797 :type 'boolean)
799 (defcustom idlwave-reindent-end t
800 "*Non-nil means re-indent line after END was typed."
801 :group 'idlwave-abbrev-and-indent-action
802 :type 'boolean)
804 (defcustom idlwave-abbrev-move t
805 "*Non-nil means the abbrev hook can move point.
806 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
807 definitions, use the command `list-abbrevs', for abbrevs that move
808 point. Moving point is useful, for example, to place point between
809 parentheses of expanded functions.
811 See `idlwave-check-abbrev'."
812 :group 'idlwave-abbrev-and-indent-action
813 :type 'boolean)
815 (defcustom idlwave-abbrev-change-case nil
816 "*Non-nil means all abbrevs will be forced to either upper or lower case.
817 If the value t, all expanded abbrevs will be upper case.
818 If the value is 'down then abbrevs will be forced to lower case.
819 If nil, the case will not change.
820 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
821 upper case, regardless of this variable."
822 :group 'idlwave-abbrev-and-indent-action
823 :type 'boolean)
825 (defcustom idlwave-reserved-word-upcase nil
826 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
827 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
828 Has effect only if in abbrev-mode."
829 :group 'idlwave-abbrev-and-indent-action
830 :type 'boolean)
832 ;;; Action/Expand Tables.
834 ;; The average user may have difficulty modifying this directly. It
835 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
836 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
837 ;; examples of how to add an action.
839 ;; The action table is used by `idlwave-indent-line' whereas both the
840 ;; action and expand tables are used by `idlwave-indent-and-action'. In
841 ;; general, the expand table is only used when a line is explicitly
842 ;; indented. Whereas, in addition to being used when the expand table
843 ;; is used, the action table is used when a line is indirectly
844 ;; indented via line splitting, auto-filling or a new line creation.
846 ;; Example actions:
848 ;; Capitalize system vars
849 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
851 ;; Capitalize procedure name
852 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
853 ;; '(capitalize-word 1) t)
855 ;; Capitalize common block name
856 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
857 ;; '(capitalize-word 1) t)
858 ;; Capitalize label
859 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
860 ;; '(capitalize-word -1) t)
862 (defvar idlwave-indent-action-table nil
863 "*Associated array containing action lists of search string (car),
864 and function as a cdr. This table is used by `idlwave-indent-line'.
865 See documentation for `idlwave-do-action' for a complete description of
866 the action lists.
868 Additions to the table are made with `idlwave-action-and-binding' when a
869 binding is not requested.
870 See help on `idlwave-action-and-binding' for examples.")
872 (defvar idlwave-indent-expand-table nil
873 "*Associated array containing action lists of search string (car),
874 and function as a cdr. The table is used by the
875 `idlwave-indent-and-action' function. See documentation for
876 `idlwave-do-action' for a complete description of the action lists.
878 Additions to the table are made with `idlwave-action-and-binding' when a
879 binding is requested.
880 See help on `idlwave-action-and-binding' for examples.")
882 ;;; Documentation header and history keyword ---------------------------------
884 (defgroup idlwave-documentation nil
885 "Options for documenting IDLWAVE files."
886 :group 'idlwave)
888 ;; FIXME: make defcustom?
889 (defvar idlwave-file-header
890 (list nil
892 ; NAME:
896 ; PURPOSE:
900 ; CATEGORY:
904 ; CALLING SEQUENCE:
908 ; INPUTS:
912 ; OPTIONAL INPUTS:
916 ; KEYWORD PARAMETERS:
920 ; OUTPUTS:
924 ; OPTIONAL OUTPUTS:
928 ; COMMON BLOCKS:
932 ; SIDE EFFECTS:
936 ; RESTRICTIONS:
940 ; PROCEDURE:
944 ; EXAMPLE:
948 ; MODIFICATION HISTORY:
952 "*A list (PATHNAME STRING) specifying the doc-header template to use for
953 summarizing a file. If PATHNAME is non-nil then this file will be included.
954 Otherwise STRING is used. If nil, the file summary will be omitted.
955 For example you might set PATHNAME to the path for the
956 lib_template.pro file included in the IDL distribution.")
958 (defcustom idlwave-header-to-beginning-of-file t
959 "*Non-nil means, the documentation header will always be at start of file.
960 When nil, the header is positioned between the PRO/FUNCTION line of
961 the current routine and the code, allowing several routine headers in
962 a file."
963 :group 'idlwave-documentation
964 :type 'boolean)
966 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
967 "*The hook function used to update the timestamp of a function."
968 :group 'idlwave-documentation
969 :type 'function)
971 (defcustom idlwave-doc-modifications-keyword "HISTORY"
972 "*The modifications keyword to use with the log documentation commands.
973 A ':' is added to the keyword end.
974 Inserted by doc-header and used to position logs by doc-modification.
975 If nil it will not be inserted."
976 :group 'idlwave-documentation
977 :type 'string)
979 (defcustom idlwave-doclib-start "^;+\\+"
980 "*Regexp matching the start of a document library header."
981 :group 'idlwave-documentation
982 :type 'regexp)
984 (defcustom idlwave-doclib-end "^;+-"
985 "*Regexp matching the end of a document library header."
986 :group 'idlwave-documentation
987 :type 'regexp)
989 ;;; External Programs -------------------------------------------------------
991 (defgroup idlwave-external-programs nil
992 "Path locations of external commands used by IDLWAVE."
993 :group 'idlwave)
995 (defcustom idlwave-shell-explicit-file-name "idl"
996 "*If non-nil, this is the command to run IDL.
997 Should be an absolute file path or path relative to the current environment
998 execution search path. If you want to specify command line switches
999 for the IDL program, use `idlwave-shell-command-line-options'.
1001 I know the name of this variable is badly chosen, but I cannot change
1002 it without compromising backwards-compatibility."
1003 :group 'idlwave-external-programs
1004 :type 'string)
1006 (defcustom idlwave-shell-command-line-options nil
1007 "*A list of command line options for calling the IDL program.
1008 Since IDL is executed directly without going through a shell like /bin/sh,
1009 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1010 string for each argument. But you may also give a single string which
1011 contains the options whitespace-separated. Emacs will be kind enough to
1012 split it for you."
1013 :type '(choice
1014 string
1015 (repeat (string :value "")))
1016 :group 'idlwave-external-programs)
1018 (defcustom idlwave-help-application "idlhelp"
1019 "*The external application providing reference help for programming.
1020 Obsolete, if the IDL Assistant is being used for help."
1021 :group 'idlwave-external-programs
1022 :type 'string)
1024 ;;; Some Shell variables which must be defined here.-----------------------
1026 (defcustom idlwave-shell-debug-modifiers '()
1027 "List of modifiers to be used for the debugging commands.
1028 Will be used to bind debugging commands in the shell buffer and in all
1029 source buffers. These are additional convenience bindings, the debugging
1030 commands are always available with the `C-c C-d' prefix.
1031 If you set this to '(control shift), this means setting a breakpoint will
1032 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1033 are `control', `meta', `super', `hyper', `alt', and `shift'."
1034 :group 'idlwave-shell-general-setup
1035 :type '(set :tag "Specify modifiers"
1036 (const control)
1037 (const meta)
1038 (const super)
1039 (const hyper)
1040 (const alt)
1041 (const shift)))
1043 (defcustom idlwave-shell-automatic-start nil
1044 "*If non-nil attempt invoke `idlwave-shell' if not already running.
1045 This is checked when an attempt to send a command to an
1046 IDL process is made."
1047 :group 'idlwave-shell-general-setup
1048 :type 'boolean)
1050 ;;; Miscellaneous variables -------------------------------------------------
1052 (defgroup idlwave-misc nil
1053 "Miscellaneous options for IDLWAVE mode."
1054 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
1055 :group 'idlwave)
1057 (defcustom idlwave-startup-message t
1058 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1059 :group 'idlwave-misc
1060 :type 'boolean)
1062 (defcustom idlwave-default-font-lock-items
1063 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1064 common-blocks class-arrows)
1065 "Items which should be fontified on the default fontification level 2.
1066 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1067 is everything and level 2 is specified by this list.
1068 This variable must be set before IDLWAVE gets loaded.
1069 It is a list of symbols; the following symbols are allowed:
1071 pros-and-functions Procedure and Function definitions
1072 batch-files Batch Files
1073 idlwave-idl-keywords IDL Keywords
1074 label Statement Labels
1075 goto Goto Statements
1076 common-blocks Common Blocks
1077 keyword-parameters Keyword Parameters in routine definitions and calls
1078 system-variables System Variables
1079 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1080 class-arrows Object Arrows with class property"
1081 :group 'idlwave-misc
1082 :type '(set
1083 :inline t :greedy t
1084 (const :tag "Procedure and Function definitions" pros-and-functions)
1085 (const :tag "Batch Files" batch-files)
1086 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1087 (const :tag "Statement Labels" label)
1088 (const :tag "Goto Statements" goto)
1089 (const :tag "Tags in Structure Definition" structtag)
1090 (const :tag "Structure Name" structname)
1091 (const :tag "Common Blocks" common-blocks)
1092 (const :tag "Keyword Parameters" keyword-parameters)
1093 (const :tag "System Variables" system-variables)
1094 (const :tag "FIXME: Warning" fixme)
1095 (const :tag "Object Arrows with class property " class-arrows)))
1097 (defcustom idlwave-mode-hook nil
1098 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1099 :group 'idlwave-misc
1100 :type 'hook)
1102 (defcustom idlwave-load-hook nil
1103 "Normal hook. Executed when idlwave.el is loaded."
1104 :group 'idlwave-misc
1105 :type 'hook)
1107 (defvar idlwave-experimental nil
1108 "Non-nil means turn on a few experimental features.
1109 This variable is only for the maintainer, to test difficult stuff,
1110 while still distributing stable releases.
1111 As a user, you should not set this to t.")
1114 ;;; End customization variables section
1117 ;;; Non customization variables
1119 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1120 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1121 ;;; and Carsten Dominik...
1123 ;; The following are the reserved words in IDL. Maybe we should
1124 ;; highlight some more stuff as well?
1125 ;; Procedure declarations. Fontify keyword plus procedure name.
1126 (defvar idlwave-idl-keywords
1127 ;; To update this regexp, update the list of keywords and
1128 ;; evaluate the form.
1129 ;; (insert
1130 ;; (prin1-to-string
1131 ;; (concat
1132 ;; "\\<\\("
1133 ;; (regexp-opt
1134 ;; '("||" "&&" "and" "or" "xor" "not"
1135 ;; "eq" "ge" "gt" "le" "lt" "ne"
1136 ;; "for" "do" "endfor"
1137 ;; "if" "then" "endif" "else" "endelse"
1138 ;; "case" "of" "endcase"
1139 ;; "switch" "break" "continue" "endswitch"
1140 ;; "begin" "end"
1141 ;; "repeat" "until" "endrep"
1142 ;; "while" "endwhile"
1143 ;; "goto" "return"
1144 ;; "inherits" "mod"
1145 ;; "compile_opt" "forward_function"
1146 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1147 ;; "\\)\\>")))
1148 "\\<\\(&&\\|and\\|b\\(egin\\|reak\\)\\|c\\(ase\\|o\\(mpile_opt\\|ntinue\\)\\)\\|do\\|e\\(lse\\|nd\\(case\\|else\\|for\\|if\\|rep\\|switch\\|while\\)?\\|q\\)\\|for\\(ward_function\\)?\\|g\\(oto\\|[et]\\)\\|i\\(f\\|nherits\\)\\|l[et]\\|mod\\|n\\(e\\|ot\\)\\|o\\(n_\\(error\\|ioerror\\)\\|[fr]\\)\\|re\\(peat\\|turn\\)\\|switch\\|then\\|until\\|while\\|xor\\|||\\)\\>")
1151 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1152 ;; Function declarations. Fontify keyword plus function name.
1153 (pros-and-functions
1154 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1155 (1 font-lock-keyword-face)
1156 (2 font-lock-function-name-face nil t)))
1158 ;; Common blocks
1159 (common-blocks
1160 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1161 (1 font-lock-keyword-face) ; "common"
1162 (2 font-lock-reference-face nil t) ; block name
1163 ("[ \t]*\\(\\sw+\\)[ ,]*"
1164 ;; Start with point after block name and comma
1165 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1167 (1 font-lock-variable-name-face) ; variable names
1170 ;; Batch files
1171 (batch-files
1172 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1174 ;; FIXME warning.
1175 (fixme
1176 '("\\<FIXME:" (0 font-lock-warning-face t)))
1178 ;; Labels
1179 (label
1180 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1182 ;; The goto statement and its label
1183 (goto
1184 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1185 (1 font-lock-keyword-face)
1186 (2 font-lock-reference-face)))
1188 ;; Tags in structure definitions. Note that this definition
1189 ;; actually collides with labels, so we have to use the same
1190 ;; face. It also matches named subscript ranges,
1191 ;; e.g. vec{bottom:top]. No good way around this.
1192 (structtag
1193 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1195 ;; Structure names
1196 (structname
1197 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1198 (2 font-lock-function-name-face)))
1200 ;; Keyword parameters, like /xlog or ,xrange=[]
1201 ;; This is anchored to the comma preceeding the keyword.
1202 ;; Treats continuation lines, works only during whole buffer
1203 ;; fontification. Slow, use it only in fancy fontification.
1204 (keyword-parameters
1205 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1206 (6 font-lock-reference-face)))
1208 ;; System variables start with a bang.
1209 (system-variables
1210 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1211 (1 font-lock-variable-name-face)))
1213 ;; Special and unusual operators (not used because too noisy)
1214 ;; (special-operators
1215 ;; '("[<>#]" (0 font-lock-keyword-face)))
1217 ;; All operators (not used because too noisy)
1218 ;; (all-operators
1219 ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1221 ;; Arrows with text property `idlwave-class'
1222 (class-arrows
1223 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1225 (defconst idlwave-font-lock-keywords-1
1226 (list pros-and-functions batch-files)
1227 "Subdued level highlighting for IDLWAVE mode.")
1229 (defconst idlwave-font-lock-keywords-2
1230 (mapcar 'symbol-value idlwave-default-font-lock-items)
1231 "Medium level highlighting for IDLWAVE mode.")
1233 (defconst idlwave-font-lock-keywords-3
1234 (list pros-and-functions
1235 batch-files
1236 idlwave-idl-keywords
1237 label goto
1238 structtag
1239 structname
1240 common-blocks
1241 keyword-parameters
1242 system-variables
1243 class-arrows)
1244 "Gaudy level highlighting for IDLWAVE mode."))
1246 (defun idlwave-match-class-arrows (limit)
1247 ;; Match an object arrow with class property
1248 (and idlwave-store-inquired-class
1249 (re-search-forward "->" limit 'limit)
1250 (get-text-property (match-beginning 0) 'idlwave-class)))
1252 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1253 "Default expressions to highlight in IDLWAVE mode.")
1255 (defvar idlwave-font-lock-defaults
1256 '((idlwave-font-lock-keywords
1257 idlwave-font-lock-keywords-1
1258 idlwave-font-lock-keywords-2
1259 idlwave-font-lock-keywords-3)
1260 nil t
1261 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
1262 beginning-of-line))
1264 (put 'idlwave-mode 'font-lock-defaults
1265 idlwave-font-lock-defaults) ; XEmacs
1267 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1268 "Regexp to match the start of a full-line comment.
1269 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1270 only by whitespace.")
1272 (defconst idlwave-begin-block-reg
1273 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1274 "Regular expression to find the beginning of a block.
1275 The case does not matter. The search skips matches in comments.")
1277 (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1278 "Regular expression to find the beginning of a unit.
1279 The case does not matter.")
1281 (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1282 "Regular expression to find the line that indicates the end of unit.
1283 This line is the end of buffer or the start of another unit.
1284 The case does not matter. The search skips matches in comments.")
1286 (defconst idlwave-continue-line-reg "\\<\\$"
1287 "Regular expression to match a continued line.")
1289 (defconst idlwave-end-block-reg
1290 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1291 "Regular expression to find the end of a block.
1292 The case does not matter. The search skips matches in comments.")
1294 (defconst idlwave-block-matches
1295 '(("pro" . "end")
1296 ("function" . "end")
1297 ("case" . "endcase")
1298 ("else" . "endelse")
1299 ("for" . "endfor")
1300 ("then" . "endif")
1301 ("repeat" . "endrep")
1302 ("switch" . "endswitch")
1303 ("while" . "endwhile"))
1304 "Matches between statements and the corresponding END variant.
1305 The cars are the reserved words starting a block. If the block really
1306 begins with BEGIN, the cars are the reserved words before the begin
1307 which can be used to identify the block type.
1308 This is used to check for the correct END type, to close blocks and
1309 to expand generic end statements to their detailed form.")
1311 (defconst idlwave-block-match-regexp
1312 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1313 "Regular expression matching reserved words which can stand before
1314 blocks starting with a BEGIN statement. The matches must have associations
1315 `idlwave-block-matches'.")
1317 (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
1318 "Regular expression matching an IDL identifier.")
1320 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1321 "Regular expression matching IDL system variables.")
1323 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1324 "Regular expression matching IDL variable names.")
1326 (defconst idlwave-label (concat idlwave-identifier ":")
1327 "Regular expression matching IDL labels.")
1329 (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1330 "\\(\\s *" idlwave-identifier "::\\)?"
1333 (defconst idlwave-statement-match
1334 (list
1335 ;; "endif else" is the only possible "end" that can be
1336 ;; followed by a statement on the same line.
1337 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1338 ;; all other "end"s can not be followed by a statement.
1339 (cons 'end (list idlwave-end-block-reg nil))
1340 '(if . ("if\\>" "then"))
1341 '(for . ("for\\>" "do"))
1342 '(begin . ("begin\\>" nil))
1343 '(pdef . ("pro\\>\\|function\\>" nil))
1344 '(while . ("while\\>" "do"))
1345 '(repeat . ("repeat\\>" "repeat"))
1346 '(goto . ("goto\\>" nil))
1347 '(case . ("case\\>" nil))
1348 '(switch . ("switch\\>" nil))
1349 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
1350 "\\(" idlwave-method-call "\\s *\\)?"
1351 idlwave-identifier
1352 "\\s *(") nil))
1353 (cons 'call (list (concat
1354 "\\(" idlwave-method-call "\\s *\\)?"
1355 idlwave-identifier
1356 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
1357 (cons 'assign (list (concat
1358 "\\(" idlwave-variable "\\) *=") nil)))
1360 "Associated list of statement matching regular expressions.
1361 Each regular expression matches the start of an IDL statement.
1362 The first element of each association is a symbol giving the statement
1363 type. The associated value is a list. The first element of this list
1364 is a regular expression matching the start of an IDL statement for
1365 identifying the statement type. The second element of this list is a
1366 regular expression for finding a substatement for the type. The
1367 substatement starts after the end of the found match modulo
1368 whitespace. If it is nil then the statement has no substatement. The
1369 list order matters since matching an assignment statement exactly is
1370 not possible without parsing. Thus assignment statement become just
1371 the leftover unidentified statements containing an equal sign.")
1373 ;; FIXME: This var seems to only ever be set, but never actually used!
1374 (defvar idlwave-fill-function 'auto-fill-function
1375 "IDL mode auto fill function.")
1377 (defvar idlwave-comment-indent-function 'comment-indent-function
1378 "IDL mode comment indent function.")
1380 ;; Note that this is documented in the v18 manuals as being a string
1381 ;; of length one rather than a single character.
1382 ;; The code in this file accepts either format for compatibility.
1383 (defvar idlwave-comment-indent-char ?\
1384 "Character to be inserted for IDL comment indentation.
1385 Normally a space.")
1387 (defconst idlwave-continuation-char ?$
1388 "Character which is inserted as a last character on previous line by
1389 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1391 (defconst idlwave-mode-version "6.1_em22")
1393 (defmacro idlwave-keyword-abbrev (&rest args)
1394 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1395 `(quote (lambda ()
1396 ,(append '(idlwave-check-abbrev) args))))
1398 ;; If I take the time I can replace idlwave-keyword-abbrev with
1399 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1400 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1401 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1402 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1404 (defmacro idlwave-code-abbrev (&rest args)
1405 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1406 Specifically, if the abbrev is in a comment or string it is unexpanded.
1407 Otherwise ARGS forms a list that is evaluated."
1408 ;; FIXME: it would probably be better to rely on the new :enable-function
1409 ;; to enforce the "don't expand in comments or strings".
1410 `(lambda ()
1411 ,(prin1-to-string args) ;; Puts the code in the doc string
1412 (if (idlwave-quoted)
1413 (progn (unexpand-abbrev) nil)
1414 ,(append args))))
1416 (autoload 'idlwave-shell "idlw-shell"
1417 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1418 (autoload 'idlwave-shell-send-command "idlw-shell")
1419 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1420 "Run `idlwave-shell' and switch back to current window" t)
1421 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1422 "Save and run buffer under the shell." t)
1423 (autoload 'idlwave-shell-break-here "idlw-shell"
1424 "Set breakpoint in current line." t)
1425 (autoload 'idlwave-shell-run-region "idlw-shell"
1426 "Compile and run the region." t)
1428 (fset 'idlwave-debug-map (make-sparse-keymap))
1430 (defvar idlwave-mode-map
1431 (let ((map (make-sparse-keymap)))
1432 (define-key map "\C-c " 'idlwave-hard-tab)
1433 (define-key map [(control tab)] 'idlwave-hard-tab)
1434 ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
1435 (define-key map "'" 'idlwave-show-matching-quote)
1436 (define-key map "\"" 'idlwave-show-matching-quote)
1437 (define-key map "\C-g" 'idlwave-keyboard-quit)
1438 (define-key map "\C-c;" 'idlwave-toggle-comment-region)
1439 (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1440 (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
1441 (define-key map "\C-c{" 'idlwave-beginning-of-block)
1442 (define-key map "\C-c}" 'idlwave-end-of-block)
1443 (define-key map "\C-c]" 'idlwave-close-block)
1444 (define-key map [(meta control h)] 'idlwave-mark-subprogram)
1445 (define-key map "\M-\C-n" 'idlwave-forward-block)
1446 (define-key map "\M-\C-p" 'idlwave-backward-block)
1447 (define-key map "\M-\C-d" 'idlwave-down-block)
1448 (define-key map "\M-\C-u" 'idlwave-backward-up-block)
1449 (define-key map "\M-\r" 'idlwave-split-line)
1450 (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
1451 (define-key map "\C-c\C-p" 'idlwave-previous-statement)
1452 (define-key map "\C-c\C-n" 'idlwave-next-statement)
1453 ;; (define-key map "\r" 'idlwave-newline)
1454 ;; (define-key map "\t" 'idlwave-indent-line)
1455 (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
1456 (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
1457 (define-key map "\M-q" 'idlwave-fill-paragraph)
1458 (define-key map "\M-s" 'idlwave-edit-in-idlde)
1459 (define-key map "\C-c\C-h" 'idlwave-doc-header)
1460 (define-key map "\C-c\C-m" 'idlwave-doc-modification)
1461 (define-key map "\C-c\C-c" 'idlwave-case)
1462 (define-key map "\C-c\C-d" 'idlwave-debug-map)
1463 (when (and (listp idlwave-shell-debug-modifiers)
1464 (not (equal idlwave-shell-debug-modifiers '())))
1465 ;; Bind the debug commands also with the special modifiers.
1466 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1467 (mods-noshift
1468 (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
1469 (define-key map
1470 (vector (append mods-noshift (list (if shift ?C ?c))))
1471 'idlwave-shell-save-and-run)
1472 (define-key map
1473 (vector (append mods-noshift (list (if shift ?B ?b))))
1474 'idlwave-shell-break-here)
1475 (define-key map
1476 (vector (append mods-noshift (list (if shift ?E ?e))))
1477 'idlwave-shell-run-region)))
1478 (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1479 (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1480 (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1481 (define-key map "\C-c\C-f" 'idlwave-for)
1482 ;; (define-key map "\C-c\C-f" 'idlwave-function)
1483 ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
1484 (define-key map "\C-c\C-r" 'idlwave-repeat)
1485 (define-key map "\C-c\C-w" 'idlwave-while)
1486 (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1487 (define-key map "\C-c\C-s" 'idlwave-shell)
1488 (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1489 (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1490 (define-key map "\C-c\C-v" 'idlwave-find-module)
1491 (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
1492 (define-key map "\C-c?" 'idlwave-routine-info)
1493 (define-key map "\M-?" 'idlwave-context-help)
1494 (define-key map [(control meta ?\?)]
1495 'idlwave-help-assistant-help-with-topic)
1496 ;; Pickup both forms of Esc/Meta binding
1497 (define-key map [(meta tab)] 'idlwave-complete)
1498 (define-key map [?\e?\t] 'idlwave-complete)
1499 (define-key map "\M-\C-i" 'idlwave-complete)
1500 (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
1501 (define-key map "\C-c=" 'idlwave-resolve)
1502 (define-key map
1503 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1504 'idlwave-mouse-context-help)
1505 map)
1506 "Keymap used in IDL mode.")
1508 (defvar idlwave-mode-syntax-table
1509 (let ((st (make-syntax-table)))
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 ?\" "\"" st)
1522 (modify-syntax-entry ?\\ "." st)
1523 (modify-syntax-entry ?_ "_" st)
1524 (modify-syntax-entry ?{ "(}" st)
1525 (modify-syntax-entry ?} "){" st)
1526 (modify-syntax-entry ?$ "_" st)
1527 (modify-syntax-entry ?. "." st)
1528 (modify-syntax-entry ?\; "<" st)
1529 (modify-syntax-entry ?\n ">" st)
1530 (modify-syntax-entry ?\f ">" st)
1532 "Syntax table in use in `idlwave-mode' buffers.")
1534 (defvar idlwave-find-symbol-syntax-table
1535 (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
1536 (modify-syntax-entry ?$ "w" st)
1537 (modify-syntax-entry ?_ "w" st)
1538 (modify-syntax-entry ?! "w" st)
1539 (modify-syntax-entry ?. "w" st)
1541 "Syntax table that treats symbol characters as word characters.")
1543 (defmacro idlwave-with-special-syntax (&rest body)
1544 "Execute BODY with a different syntax table."
1545 `(let ((saved-syntax (syntax-table)))
1546 (unwind-protect
1547 (progn
1548 (set-syntax-table idlwave-find-symbol-syntax-table)
1549 ,@body)
1550 (set-syntax-table saved-syntax))))
1552 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1553 ; "Execute BODY with a different syntax table."
1554 ; `(let ((saved-syntax (syntax-table)))
1555 ; (unwind-protect
1556 ; (progn
1557 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1558 ; ,@body)
1559 ; (set-syntax-table saved-syntax))))
1561 (defun idlwave-action-and-binding (key cmd &optional select)
1562 "KEY and CMD are made into a key binding and an indent action.
1563 KEY is a string - same as for the `define-key' function. CMD is a
1564 function of no arguments or a list to be evaluated. CMD is bound to
1565 KEY in `idlwave-mode-map' by defining an anonymous function calling
1566 `self-insert-command' followed by CMD. If KEY contains more than one
1567 character a binding will only be set if SELECT is 'both.
1569 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1570 replacing any previous value for KEY. If a binding is not set then it
1571 will instead be placed in `idlwave-indent-action-table'.
1573 If the optional argument SELECT is nil then an action and binding are
1574 created. If SELECT is 'noaction, then a binding is always set and no
1575 action is created. If SELECT is 'both then an action and binding
1576 will both be created even if KEY contains more than one character.
1577 Otherwise, if SELECT is non-nil then only an action is created.
1579 Some examples:
1580 No spaces before and 1 after a comma
1581 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1582 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1583 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1584 Capitalize system variables - action only
1585 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1586 (if (not (equal select 'noaction))
1587 ;; Add action
1588 (let* ((table (if select 'idlwave-indent-action-table
1589 'idlwave-indent-expand-table))
1590 (table-key (regexp-quote key))
1591 (cell (assoc table-key (eval table))))
1592 (if cell
1593 ;; Replace action command
1594 (setcdr cell cmd)
1595 ;; New action
1596 (set table (append (eval table) (list (cons table-key cmd)))))))
1597 ;; Make key binding for action
1598 (if (or (and (null select) (= (length key) 1))
1599 (equal select 'noaction)
1600 (equal select 'both))
1601 (define-key idlwave-mode-map key
1602 `(lambda ()
1603 (interactive)
1604 (self-insert-command 1)
1605 ,(if (listp cmd) cmd (list cmd))))))
1607 ;; Set action and key bindings.
1608 ;; See description of the function `idlwave-action-and-binding'.
1609 ;; Automatically add spaces for the following characters
1611 ;; Actions for & are complicated by &&
1612 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1614 ;; Automatically add spaces to equal sign if not keyword. This needs
1615 ;; to go ahead of > and <, so >= and <= will be treated correctly
1616 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1618 ;; Actions for > and < are complicated by >=, <=, and ->...
1619 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1620 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1622 (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1626 ;;; Abbrev Section
1628 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1629 ;;; space is inserted (this is the space typed by the user to expanded
1630 ;;; the abbrev).
1632 (defvar idlwave-mode-abbrev-table nil
1633 "Abbreviation table used for IDLWAVE mode.")
1634 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1636 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1637 "Define-abbrev with backward compatibility.
1639 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1640 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1641 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1642 (args (list (or table idlwave-mode-abbrev-table)
1643 (if noprefix name (concat idlwave-abbrev-start-char name))
1644 expansion
1645 hook)))
1646 (condition-case nil
1647 (apply 'define-abbrev (append args '(0 t)))
1648 (error (apply 'define-abbrev args)))))
1650 (condition-case nil
1651 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1652 "w" idlwave-mode-syntax-table)
1653 (error nil))
1656 ;; Templates
1658 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1659 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1660 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1661 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1662 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1663 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1664 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1665 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1666 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1668 ;; Keywords, system functions, conversion routines
1670 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1672 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1673 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1680 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1681 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1683 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1684 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1685 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1686 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1687 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1688 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1689 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1690 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1691 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1696 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1705 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1714 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1715 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1716 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1718 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1720 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1721 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1723 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1724 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1725 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1727 ;; This section is reserved words only. (From IDL user manual)
1729 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1730 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1731 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1732 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1733 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1734 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1735 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1736 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1737 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1739 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1740 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1741 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1742 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1743 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1744 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1745 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1746 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1760 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1761 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1762 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1763 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1764 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1765 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1766 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1767 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1769 (defvar imenu-create-index-function)
1770 (defvar extract-index-name-function)
1771 (defvar prev-index-position-function)
1772 (defvar imenu-extract-index-name-function)
1773 (defvar imenu-prev-index-position-function)
1774 ;; defined later - so just make the compiler hush
1775 (defvar idlwave-mode-menu)
1776 (defvar idlwave-mode-debug-menu)
1778 ;;;###autoload
1779 (defun idlwave-mode ()
1780 "Major mode for editing IDL source files (version 6.1_em22).
1782 The main features of this mode are
1784 1. Indentation and Formatting
1785 --------------------------
1786 Like other Emacs programming modes, C-j inserts a newline and indents.
1787 TAB is used for explicit indentation of the current line.
1789 To start a continuation line, use \\[idlwave-split-line]. This
1790 function can also be used in the middle of a line to split the line
1791 at that point. When used inside a long constant string, the string
1792 is split at that point with the `+' concatenation operator.
1794 Comments are indented as follows:
1796 `;;;' Indentation remains unchanged.
1797 `;;' Indent like the surrounding code
1798 `;' Indent to a minimum column.
1800 The indentation of comments starting in column 0 is never changed.
1802 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1803 comment. The indentation of the second line of the paragraph
1804 relative to the first will be retained. Use
1805 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1806 comments. When the variable `idlwave-fill-comment-line-only' is
1807 nil, code can also be auto-filled and auto-indented.
1809 To convert pre-existing IDL code to your formatting style, mark the
1810 entire buffer with \\[mark-whole-buffer] and execute
1811 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1812 again followed by \\[indent-region] (`indent-region').
1814 2. Routine Info
1815 ------------
1816 IDLWAVE displays information about the calling sequence and the
1817 accepted keyword parameters of a procedure or function with
1818 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1819 source file of a module. These commands know about system
1820 routines, all routines in idlwave-mode buffers and (when the
1821 idlwave-shell is active) about all modules currently compiled under
1822 this shell. It also makes use of pre-compiled or custom-scanned
1823 user and library catalogs many popular libraries ship with by
1824 default. Use \\[idlwave-update-routine-info] to update this
1825 information, which is also used for completion (see item 4).
1827 3. Online IDL Help
1828 ---------------
1830 \\[idlwave-context-help] displays the IDL documentation relevant
1831 for the system variable, keyword, or routines at point. A single
1832 key stroke gets you directly to the right place in the docs. See
1833 the manual to configure where and how the HTML help is displayed.
1835 4. Completion
1836 ----------
1837 \\[idlwave-complete] completes the names of procedures, functions
1838 class names, keyword parameters, system variables and tags, class
1839 tags, structure tags, filenames and much more. It is context
1840 sensitive and figures out what is expected at point. Lower case
1841 strings are completed in lower case, other strings in mixed or
1842 upper case.
1844 5. Code Templates and Abbreviations
1845 --------------------------------
1846 Many Abbreviations are predefined to expand to code fragments and templates.
1847 The abbreviations start generally with a `\\`. Some examples:
1849 \\pr PROCEDURE template
1850 \\fu FUNCTION template
1851 \\c CASE statement template
1852 \\sw SWITCH statement template
1853 \\f FOR loop template
1854 \\r REPEAT Loop template
1855 \\w WHILE loop template
1856 \\i IF statement template
1857 \\elif IF-ELSE statement template
1858 \\b BEGIN
1860 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1861 have direct keybindings - see the list of keybindings below.
1863 \\[idlwave-doc-header] inserts a documentation header at the
1864 beginning of the current program unit (pro, function or main).
1865 Change log entries can be added to the current program unit with
1866 \\[idlwave-doc-modification].
1868 6. Automatic Case Conversion
1869 -------------------------
1870 The case of reserved words and some abbrevs is controlled by
1871 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1873 7. Automatic END completion
1874 ------------------------
1875 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1876 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1878 8. Hooks
1879 -----
1880 Loading idlwave.el runs `idlwave-load-hook'.
1881 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1883 9. Documentation and Customization
1884 -------------------------------
1885 Info documentation for this package is available. Use
1886 \\[idlwave-info] to display (complain to your sysadmin if that does
1887 not work). For Postscript, PDF, and HTML versions of the
1888 documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
1889 IDLWAVE has customize support - see the group `idlwave'.
1891 10.Keybindings
1892 -----------
1893 Here is a list of all keybindings of this mode.
1894 If some of the key bindings below show with ??, use \\[describe-key]
1895 followed by the key sequence to see what the key sequence does.
1897 \\{idlwave-mode-map}"
1899 (interactive)
1900 (kill-all-local-variables)
1902 (if idlwave-startup-message
1903 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1904 (setq idlwave-startup-message nil)
1906 (setq local-abbrev-table idlwave-mode-abbrev-table)
1907 (set-syntax-table idlwave-mode-syntax-table)
1909 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1911 (make-local-variable idlwave-comment-indent-function)
1912 (set idlwave-comment-indent-function 'idlwave-comment-hook)
1914 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1915 (set (make-local-variable 'comment-start) ";")
1916 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
1917 (set (make-local-variable 'require-final-newline) t)
1918 (set (make-local-variable 'abbrev-all-caps) t)
1919 (set (make-local-variable 'indent-tabs-mode) nil)
1920 (set (make-local-variable 'completion-ignore-case) t)
1922 (use-local-map idlwave-mode-map)
1924 (when (featurep 'easymenu)
1925 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1926 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1928 (setq mode-name "IDLWAVE")
1929 (setq major-mode 'idlwave-mode)
1930 (setq abbrev-mode t)
1932 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1933 (setq comment-end "")
1934 (set (make-local-variable 'comment-multi-line) nil)
1935 (set (make-local-variable 'paragraph-separate)
1936 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1937 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1938 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1939 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1941 ;; ChangeLog
1942 (set (make-local-variable 'add-log-current-defun-function)
1943 'idlwave-current-routine-fullname)
1945 ;; Set tag table list to use IDLTAGS as file name.
1946 (if (boundp 'tag-table-alist)
1947 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1949 ;; Font-lock additions
1950 ;; Following line is for Emacs - XEmacs uses the corresponding property
1951 ;; on the `idlwave-mode' symbol.
1952 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1953 (set (make-local-variable 'font-lock-mark-block-function)
1954 'idlwave-mark-subprogram)
1955 (set (make-local-variable 'font-lock-fontify-region-function)
1956 'idlwave-font-lock-fontify-region)
1958 ;; Imenu setup
1959 (set (make-local-variable 'imenu-create-index-function)
1960 'imenu-default-create-index-function)
1961 (set (make-local-variable 'imenu-extract-index-name-function)
1962 'idlwave-unit-name)
1963 (set (make-local-variable 'imenu-prev-index-position-function)
1964 'idlwave-prev-index-position)
1966 ;; HideShow setup
1967 (add-to-list 'hs-special-modes-alist
1968 (list 'idlwave-mode
1969 idlwave-begin-block-reg
1970 idlwave-end-block-reg
1972 'idlwave-forward-block nil))
1974 ;; Make a local post-command-hook and add our hook to it
1975 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1976 ;; (make-local-hook 'post-command-hook)
1977 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1979 ;; Make local hooks for buffer updates
1980 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1981 ;; (make-local-hook 'kill-buffer-hook)
1982 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1983 ;; (make-local-hook 'after-save-hook)
1984 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1985 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1987 ;; Setup directories and file, if necessary
1988 (idlwave-setup)
1990 ;; Update the routine info with info about current buffer?
1991 (idlwave-new-buffer-update)
1993 ;; Check help location
1994 (idlwave-help-check-locations)
1996 ;; Run the mode hook
1997 (run-mode-hooks 'idlwave-mode-hook))
1999 (defvar idlwave-setup-done nil)
2000 (defun idlwave-setup ()
2001 (unless idlwave-setup-done
2002 (if (not (file-directory-p idlwave-config-directory))
2003 (make-directory idlwave-config-directory))
2004 (setq
2005 idlwave-user-catalog-file (expand-file-name
2006 idlwave-user-catalog-file
2007 idlwave-config-directory)
2008 idlwave-xml-system-rinfo-converted-file
2009 (expand-file-name
2010 idlwave-xml-system-rinfo-converted-file
2011 idlwave-config-directory)
2012 idlwave-path-file (expand-file-name
2013 idlwave-path-file
2014 idlwave-config-directory))
2015 (idlwave-read-paths) ; we may need these early
2016 (setq idlwave-setup-done t)))
2018 (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
2019 "Fontify continuation lines correctly."
2020 (let (pos)
2021 (save-excursion
2022 (goto-char beg)
2023 (forward-line -1)
2024 (when (setq pos (idlwave-is-continuation-line))
2025 (goto-char pos)
2026 (idlwave-beginning-of-statement)
2027 (setq beg (point)))))
2028 (font-lock-default-fontify-region beg end verbose))
2031 ;; Code Formatting ----------------------------------------------------
2034 (defun idlwave-hard-tab ()
2035 "Insert TAB in buffer in current position."
2036 (interactive)
2037 (insert "\t"))
2039 ;;; This stuff is experimental
2041 (defvar idlwave-command-hook nil
2042 "If non-nil, a list that can be evaluated using `eval'.
2043 It is evaluated in the lisp function `idlwave-command-hook' which is
2044 placed in `post-command-hook'.")
2046 (defun idlwave-command-hook ()
2047 "Command run after every command.
2048 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2049 sets the variable to zero afterwards."
2050 (and idlwave-command-hook
2051 (listp idlwave-command-hook)
2052 (condition-case nil
2053 (eval idlwave-command-hook)
2054 (error nil)))
2055 (setq idlwave-command-hook nil))
2057 ;;; End experiment
2059 ;; It would be better to use expand.el for better abbrev handling and
2060 ;; versatility.
2062 (defun idlwave-check-abbrev (arg &optional reserved)
2063 "Reverse abbrev expansion if in comment or string.
2064 Argument ARG is the number of characters to move point
2065 backward if `idlwave-abbrev-move' is non-nil.
2066 If optional argument RESERVED is non-nil then the expansion
2067 consists of reserved words, which will be capitalized if
2068 `idlwave-reserved-word-upcase' is non-nil.
2069 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2070 is non-nil, unless its value is \`down in which case the abbrev will be
2071 made into all lowercase.
2072 Returns non-nil if abbrev is left expanded."
2073 (if (idlwave-quoted)
2074 (progn (unexpand-abbrev)
2075 nil)
2076 (if (and reserved idlwave-reserved-word-upcase)
2077 (upcase-region last-abbrev-location (point))
2078 (cond
2079 ((equal idlwave-abbrev-change-case 'down)
2080 (downcase-region last-abbrev-location (point)))
2081 (idlwave-abbrev-change-case
2082 (upcase-region last-abbrev-location (point)))))
2083 (if (and idlwave-abbrev-move (> arg 0))
2084 (if (boundp 'post-command-hook)
2085 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2086 (backward-char arg)))
2089 (defun idlwave-in-comment ()
2090 "Return t if point is inside a comment, nil otherwise."
2091 (save-excursion
2092 (let ((here (point)))
2093 (and (idlwave-goto-comment) (> here (point))))))
2095 (defun idlwave-goto-comment ()
2096 "Move to start of comment delimiter on current line.
2097 Moves to end of line if there is no comment delimiter.
2098 Ignores comment delimiters in strings.
2099 Returns point if comment found and nil otherwise."
2100 (let ((eos (progn (end-of-line) (point)))
2101 (data (match-data))
2102 found)
2103 ;; Look for first comment delimiter not in a string
2104 (beginning-of-line)
2105 (setq found (search-forward comment-start eos 'lim))
2106 (while (and found (idlwave-in-quote))
2107 (setq found (search-forward comment-start eos 'lim)))
2108 (store-match-data data)
2109 (and found (not (idlwave-in-quote))
2110 (progn
2111 (backward-char 1)
2112 (point)))))
2114 (defun idlwave-region-active-p ()
2115 "Should we operate on an active region?"
2116 (if (fboundp 'use-region-p)
2117 (use-region-p)
2118 (region-active-p)))
2120 (defun idlwave-show-matching-quote ()
2121 "Insert quote and show matching quote if this is end of a string."
2122 (interactive)
2123 (let ((bq (idlwave-in-quote))
2124 (inq last-command-event))
2125 (if (and bq (not (idlwave-in-comment)))
2126 (let ((delim (char-after bq)))
2127 (insert inq)
2128 (if (eq inq delim)
2129 (save-excursion
2130 (goto-char bq)
2131 (sit-for 1))))
2132 ;; Not the end of a string
2133 (insert inq))))
2135 (defun idlwave-show-begin-check ()
2136 "Ensure that the previous word was a token before `idlwave-show-begin'.
2137 An END token must be preceded by whitespace."
2138 (if (not (idlwave-quoted))
2140 (save-excursion
2141 (backward-word 1)
2142 (backward-char 1)
2143 (looking-at "[ \t\n\f]"))
2144 (idlwave-show-begin))))
2146 (defun idlwave-show-begin ()
2147 "Find the start of current block and blinks to it for a second.
2148 Also checks if the correct END statement has been used."
2149 ;; All end statements are reserved words
2150 ;; Re-indent end line
2151 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2152 ;;(backward-char 1)
2153 (let* ((pos (point-marker))
2154 (last-abbrev-marker (copy-marker last-abbrev-location))
2155 (eol-pos (save-excursion (end-of-line) (point)))
2156 begin-pos end-pos end end1 )
2157 (if idlwave-reindent-end (idlwave-indent-line))
2158 (setq last-abbrev-location (marker-position last-abbrev-marker))
2159 (when (and (idlwave-check-abbrev 0 t)
2160 idlwave-show-block)
2161 (save-excursion
2162 ;; Move inside current block
2163 (goto-char last-abbrev-marker)
2164 (idlwave-block-jump-out -1 'nomark)
2165 (setq begin-pos (point))
2166 (idlwave-block-jump-out 1 'nomark)
2167 (setq end-pos (point))
2168 (if (> end-pos eol-pos)
2169 (setq end-pos pos))
2170 (goto-char end-pos)
2171 (setq end (buffer-substring
2172 (progn
2173 (skip-chars-backward "a-zA-Z")
2174 (point))
2175 end-pos))
2176 (goto-char begin-pos)
2177 (when (setq end1 (cdr (idlwave-block-master)))
2178 (cond
2179 ((null end1)) ; no-operation
2180 ((string= (downcase end) (downcase end1))
2181 (sit-for 1))
2182 ((string= (downcase end) "end")
2183 ;; A generic end
2184 (if idlwave-expand-generic-end
2185 (save-excursion
2186 (goto-char pos)
2187 (backward-char 3)
2188 (insert (if (string= end "END") (upcase end1) end1))
2189 (delete-char 3)))
2190 (sit-for 1))
2192 (beep)
2193 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2194 end1 end)
2195 (sit-for 1))))))))
2196 ;;(delete-char 1))
2198 (defun idlwave-block-master ()
2199 (let ((case-fold-search t))
2200 (save-excursion
2201 (cond
2202 ((looking-at "pro\\|case\\|switch\\|function\\>")
2203 (assoc (downcase (match-string 0)) idlwave-block-matches))
2204 ((looking-at "begin\\>")
2205 (let ((limit (save-excursion
2206 (idlwave-beginning-of-statement)
2207 (point))))
2208 (cond
2209 ((re-search-backward ":[ \t]*\\=" limit t)
2210 ;; seems to be a case thing
2211 '("begin" . "end"))
2212 ((re-search-backward idlwave-block-match-regexp limit t)
2213 (assoc (downcase (match-string 1))
2214 idlwave-block-matches))
2216 ;; Just a normal block
2217 '("begin" . "end")))))
2218 (t nil)))))
2220 (defun idlwave-close-block ()
2221 "Terminate the current block with the correct END statement."
2222 (interactive)
2223 ;; Start new line if we are not in a new line
2224 (unless (save-excursion
2225 (skip-chars-backward " \t")
2226 (bolp))
2227 (let ((idlwave-show-block nil))
2228 (newline-and-indent)))
2229 (let ((last-abbrev-location (point))) ; for upcasing
2230 (insert "end")
2231 (idlwave-show-begin)))
2233 (defun idlwave-custom-ampersand-surround (&optional is-action)
2234 "Surround &, leaving room for && (which surround as well)."
2235 (let* ((prev-char (char-after (- (point) 2)))
2236 (next-char (char-after (point)))
2237 (amp-left (eq prev-char ?&))
2238 (amp-right (eq next-char ?&))
2239 (len (if amp-left 2 1)))
2240 (unless amp-right ;no need to do it twice, amp-left will catch it.
2241 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2243 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2244 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2245 (let* ((prev-char (char-after (- (point) 2)))
2246 (next-char (char-after (point)))
2247 (method-invoke (and gtr (eq prev-char ?-)))
2248 (len (if method-invoke 2 1)))
2249 (unless (eq next-char ?=)
2250 ;; Key binding: pad only on left, to save for possible >=/<=
2251 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2253 (defun idlwave-surround (&optional before after length is-action)
2254 "Surround the LENGTH characters before point with blanks.
2255 LENGTH defaults to 1.
2256 Optional arguments BEFORE and AFTER affect the behavior before and
2257 after the characters (see also description of `idlwave-make-space'):
2259 nil do nothing
2260 0 force no spaces
2261 integer > 0 force exactly n spaces
2262 integer < 0 at least |n| spaces
2264 The function does nothing if any of the following conditions is true:
2265 - `idlwave-surround-by-blank' is nil
2266 - the character before point is inside a string or comment"
2267 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2268 (let ((length (or length 1))) ; establish a default for LENGTH
2269 (backward-char length)
2270 (save-restriction
2271 (let ((here (point)))
2272 (skip-chars-backward " \t")
2273 (if (bolp)
2274 ;; avoid clobbering indent
2275 (progn
2276 (move-to-column (idlwave-calculate-indent))
2277 (if (<= (point) here)
2278 (narrow-to-region (point) here))
2279 (goto-char here)))
2280 (idlwave-make-space before))
2281 (skip-chars-forward " \t"))
2282 (forward-char length)
2283 (idlwave-make-space after)
2284 ;; Check to see if the line should auto wrap
2285 (if (and (equal (char-after (1- (point))) ?\ )
2286 (> (current-column) fill-column))
2287 (funcall auto-fill-function)))))
2289 (defun idlwave-make-space (n)
2290 "Make space at point.
2291 The space affected is all the spaces and tabs around point.
2292 If n is non-nil then point is left abs(n) spaces from the beginning of
2293 the contiguous space.
2294 The amount of space at point is determined by N.
2295 If the value of N is:
2296 nil - do nothing.
2297 > 0 - exactly N spaces.
2298 < 0 - a minimum of -N spaces, i.e., do not change if there are
2299 already -N spaces.
2300 0 - no spaces (i.e. remove any existing space)."
2301 (if (integerp n)
2302 (let
2303 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2304 (left (point))
2305 (end-col (progn (skip-chars-forward " \t") (current-column))))
2306 (delete-horizontal-space)
2307 (cond
2308 ((> n 0)
2309 (idlwave-indent-to (+ start-col n))
2310 (goto-char (+ left n)))
2311 ((< n 0)
2312 (idlwave-indent-to end-col (- n))
2313 (goto-char (- left n)))
2314 ;; n = 0, done
2315 ))))
2317 (defun idlwave-newline ()
2318 "Insert a newline and indent the current and previous line."
2319 (interactive)
2321 ;; Handle unterminated single and double quotes
2322 ;; If not in a comment and in a string then insertion of a newline
2323 ;; will mean unbalanced quotes.
2325 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2326 (progn (beep)
2327 (message "Warning: unbalanced quotes?")))
2328 (newline)
2330 ;; The current line is being split, the cursor should be at the
2331 ;; beginning of the new line skipping the leading indentation.
2333 ;; The reason we insert the new line before indenting is that the
2334 ;; indenting could be confused by keywords (e.g. END) on the line
2335 ;; after the split point. This prevents us from just using
2336 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2338 (beginning-of-line 0)
2339 (idlwave-indent-line)
2340 (forward-line)
2341 (idlwave-indent-line))
2344 ;; Use global variable 'comment-column' to set parallel comment
2346 ;; Modeled on lisp.el
2347 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2348 (defun idlwave-comment-hook ()
2349 "Compute indent for the beginning of the IDL comment delimiter."
2350 (if (or (looking-at idlwave-no-change-comment)
2351 (looking-at (or idlwave-begin-line-comment "^;")))
2352 (current-column)
2353 (if (looking-at idlwave-code-comment)
2354 (if (save-excursion (skip-chars-backward " \t") (bolp))
2355 ;; On line by itself, indent as code
2356 (let ((tem (idlwave-calculate-indent)))
2357 (if (listp tem) (car tem) tem))
2358 ;; after code - do not change
2359 (current-column))
2360 (skip-chars-backward " \t")
2361 (max (if (bolp) 0 (1+ (current-column)))
2362 comment-column))))
2364 (defun idlwave-split-line ()
2365 "Continue line by breaking line at point and indent the lines.
2366 For a code line insert continuation marker. If the line is a line comment
2367 then the new line will contain a comment with the same indentation.
2368 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2369 non-nil."
2370 (interactive)
2371 ;; Expand abbreviation, just like normal RET would.
2372 (and abbrev-mode (expand-abbrev))
2373 (let (beg)
2374 (if (not (idlwave-in-comment))
2375 ;; For code line add continuation.
2376 ;; Check if splitting a string.
2377 (progn
2378 (if (setq beg (idlwave-in-quote))
2379 (if idlwave-split-line-string
2380 ;; Split the string.
2381 (progn (insert (setq beg (char-after beg)) " + "
2382 idlwave-continuation-char beg)
2383 (backward-char 1)
2384 (newline-and-indent)
2385 (forward-char 1))
2386 ;; Do not split the string.
2387 (beep)
2388 (message "Warning: continuation inside string!!")
2389 (insert " " idlwave-continuation-char))
2390 ;; Not splitting a string.
2391 (if (not (member (char-before) '(?\ ?\t)))
2392 (insert " "))
2393 (insert idlwave-continuation-char)
2394 (newline-and-indent)))
2395 (indent-new-comment-line))
2396 ;; Indent previous line
2397 (setq beg (- (point-max) (point)))
2398 (forward-line -1)
2399 (idlwave-indent-line)
2400 (goto-char (- (point-max) beg))
2401 ;; Reindent new line
2402 (idlwave-indent-line)))
2404 (defun idlwave-beginning-of-subprogram (&optional nomark)
2405 "Move point to the beginning of the current program unit.
2406 If NOMARK is non-nil, do not push mark."
2407 (interactive)
2408 (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
2410 (defun idlwave-end-of-subprogram (&optional nomark)
2411 "Move point to the start of the next program unit.
2412 If NOMARK is non-nil, do not push mark."
2413 (interactive)
2414 (idlwave-end-of-statement)
2415 (idlwave-find-key idlwave-end-unit-reg 1 nomark))
2417 (defun idlwave-mark-statement ()
2418 "Mark current IDL statement."
2419 (interactive)
2420 (idlwave-end-of-statement)
2421 (let ((end (point)))
2422 (idlwave-beginning-of-statement)
2423 (push-mark end nil t)))
2425 (defun idlwave-mark-block ()
2426 "Mark containing block."
2427 (interactive)
2428 (idlwave-end-of-statement)
2429 (idlwave-backward-up-block -1)
2430 (idlwave-end-of-statement)
2431 (let ((end (point)))
2432 (idlwave-backward-block)
2433 (idlwave-beginning-of-statement)
2434 (push-mark end nil t)))
2437 (defun idlwave-mark-subprogram ()
2438 "Put mark at beginning of program, point at end.
2439 The marks are pushed."
2440 (interactive)
2441 (idlwave-end-of-statement)
2442 (idlwave-beginning-of-subprogram)
2443 (let ((beg (point)))
2444 (idlwave-forward-block)
2445 (push-mark beg nil t))
2446 (exchange-point-and-mark))
2448 (defun idlwave-backward-up-block (&optional arg)
2449 "Move to beginning of enclosing block if prefix ARG >= 0.
2450 If prefix ARG < 0 then move forward to enclosing block end."
2451 (interactive "p")
2452 (idlwave-block-jump-out (- arg) 'nomark))
2454 (defun idlwave-beginning-of-block ()
2455 "Go to the beginning of the current block."
2456 (interactive)
2457 (idlwave-block-jump-out -1 'nomark)
2458 (forward-word 1))
2460 (defun idlwave-end-of-block ()
2461 "Go to the beginning of the current block."
2462 (interactive)
2463 (idlwave-block-jump-out 1 'nomark)
2464 (backward-word 1))
2466 (defun idlwave-forward-block (&optional arg)
2467 "Move across next nested block."
2468 (interactive)
2469 (let ((arg (or arg 1)))
2470 (if (idlwave-down-block arg)
2471 (idlwave-block-jump-out arg 'nomark))))
2473 (defun idlwave-backward-block ()
2474 "Move backward across previous nested block."
2475 (interactive)
2476 (if (idlwave-down-block -1)
2477 (idlwave-block-jump-out -1 'nomark)))
2479 (defun idlwave-down-block (&optional arg)
2480 "Go down a block.
2481 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2482 Returns non-nil if successfull."
2483 (interactive "p")
2484 (let (status)
2485 (if (< arg 0)
2486 ;; Backward
2487 (let ((eos (save-excursion
2488 (idlwave-block-jump-out -1 'nomark)
2489 (point))))
2490 (if (setq status (idlwave-find-key
2491 idlwave-end-block-reg -1 'nomark eos))
2492 (idlwave-beginning-of-statement)
2493 (message "No nested block before beginning of containing block.")))
2494 ;; Forward
2495 (let ((eos (save-excursion
2496 (idlwave-block-jump-out 1 'nomark)
2497 (point))))
2498 (if (setq status (idlwave-find-key
2499 idlwave-begin-block-reg 1 'nomark eos))
2500 (idlwave-end-of-statement)
2501 (message "No nested block before end of containing block."))))
2502 status))
2504 (defun idlwave-mark-doclib ()
2505 "Put point at beginning of doc library header, mark at end.
2506 The marks are pushed."
2507 (interactive)
2508 (let (beg
2509 (here (point)))
2510 (goto-char (point-max))
2511 (if (re-search-backward idlwave-doclib-start nil t)
2512 (progn
2513 (setq beg (progn (beginning-of-line) (point)))
2514 (if (re-search-forward idlwave-doclib-end nil t)
2515 (progn
2516 (forward-line 1)
2517 (push-mark beg nil t)
2518 (message "Could not find end of doc library header.")))
2519 (message "Could not find doc library header start.")
2520 (goto-char here)))))
2522 (defun idlwave-current-routine-fullname ()
2523 (let ((name (idlwave-current-routine)))
2524 (idlwave-make-full-name (nth 2 name) (car name))))
2526 (defun idlwave-current-routine ()
2527 "Return (NAME TYPE CLASS) of current routine."
2528 (idlwave-routines)
2529 (save-excursion
2530 (idlwave-beginning-of-subprogram 'nomark)
2531 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2532 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2533 'pro 'function))
2534 (class (idlwave-sintern-class (match-string 3)))
2535 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2536 (list name type class)))))
2538 (defvar idlwave-shell-prompt-pattern)
2539 (defun idlwave-beginning-of-statement ()
2540 "Move to beginning of the current statement.
2541 Skips back past statement continuations.
2542 Point is placed at the beginning of the line whether or not this is an
2543 actual statement."
2544 (interactive)
2545 (cond
2546 ((eq major-mode 'idlwave-shell-mode)
2547 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2548 (goto-char (match-end 0))))
2550 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2551 (idlwave-previous-statement)
2552 (beginning-of-line)))))
2554 (defun idlwave-previous-statement ()
2555 "Move point to beginning of the previous statement.
2556 Returns t if the current line before moving is the beginning of
2557 the first non-comment statement in the file, and nil otherwise."
2558 (interactive)
2559 (let (first-statement)
2560 (if (not (= (forward-line -1) 0))
2561 ;; first line in file
2563 ;; skip blank lines, label lines, include lines and line comments
2564 (while (and
2565 ;; The current statement is the first statement until we
2566 ;; reach another statement.
2567 (setq first-statement
2569 (looking-at idlwave-comment-line-start-skip)
2570 (looking-at "[ \t]*$")
2571 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2572 (looking-at "^@")))
2573 (= (forward-line -1) 0)))
2574 ;; skip continuation lines
2575 (while (and
2576 (save-excursion
2577 (forward-line -1)
2578 (idlwave-is-continuation-line))
2579 (= (forward-line -1) 0)))
2580 first-statement)))
2582 (defun idlwave-end-of-statement ()
2583 "Move point to the end of the current IDL statement.
2584 If not in a statement just moves to end of line. Returns position."
2585 (interactive)
2586 (while (and (idlwave-is-continuation-line)
2587 (= (forward-line 1) 0))
2588 (while (and (idlwave-is-comment-or-empty-line)
2589 (= (forward-line 1) 0))))
2590 (end-of-line)
2591 (point))
2593 (defun idlwave-end-of-statement0 ()
2594 "Move point to the end of the current IDL statement.
2595 If not in a statement just moves to end of line. Returns position."
2596 (interactive)
2597 (while (and (idlwave-is-continuation-line)
2598 (= (forward-line 1) 0)))
2599 (end-of-line)
2600 (point))
2602 (defun idlwave-next-statement ()
2603 "Move point to beginning of the next IDL statement.
2604 Returns t if that statement is the last non-comment IDL statement
2605 in the file, and nil otherwise."
2606 (interactive)
2607 (let (last-statement)
2608 (idlwave-end-of-statement)
2609 ;; skip blank lines, label lines, include lines and line comments
2610 (while (and (= (forward-line 1) 0)
2611 ;; The current statement is the last statement until
2612 ;; we reach a new statement.
2613 (setq last-statement
2615 (looking-at idlwave-comment-line-start-skip)
2616 (looking-at "[ \t]*$")
2617 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2618 (looking-at "^@")))))
2619 last-statement))
2621 (defun idlwave-skip-multi-commands (&optional lim)
2622 "Skip past multiple commands on a line (with `&')."
2623 (let ((save-point (point)))
2624 (when (re-search-forward ".*&" lim t)
2625 (goto-char (match-end 0))
2626 (if (idlwave-quoted)
2627 (goto-char save-point)
2628 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2629 (point)))
2631 (defun idlwave-skip-label-or-case ()
2632 "Skip label or case statement element.
2633 Returns position after label.
2634 If there is no label point is not moved and nil is returned."
2635 ;; Case expressions and labels are terminated by a colon.
2636 ;; So we find the first colon in the line and make sure
2637 ;; - no `?' is before it (might be a ? b : c)
2638 ;; - it is not in a comment
2639 ;; - not in a string constant
2640 ;; - not in parenthesis (like a[0:3])
2641 ;; - not followed by another ":" in explicit class, ala a->b::c
2642 ;; As many in this mode, this function is heuristic and not an exact
2643 ;; parser.
2644 (let* ((start (point))
2645 (eos (save-excursion (idlwave-end-of-statement) (point)))
2646 (end (idlwave-find-key ":" 1 'nomark eos)))
2647 (if (and end
2648 (= (nth 0 (parse-partial-sexp start end)) 0)
2649 (not (string-match "\\?" (buffer-substring start end)))
2650 (not (string-match "^::" (buffer-substring end eos))))
2651 (progn
2652 (forward-char)
2653 (point))
2654 (goto-char start)
2655 nil)))
2657 (defun idlwave-start-of-substatement (&optional pre)
2658 "Move to start of next IDL substatement after point.
2659 Uses the type of the current IDL statement to determine if the next
2660 statement is on a new line or is a subpart of the current statement.
2661 Returns point at start of substatement modulo whitespace.
2662 If optional argument is non-nil move to beginning of current
2663 substatement."
2664 (let ((orig (point))
2665 (eos (idlwave-end-of-statement))
2666 (ifnest 0)
2667 st nst last)
2668 (idlwave-beginning-of-statement)
2669 (idlwave-skip-label-or-case)
2670 (if (< (point) orig)
2671 (idlwave-skip-multi-commands orig))
2672 (setq last (point))
2673 ;; Continue looking for substatements until we are past orig
2674 (while (and (<= (point) orig) (not (eobp)))
2675 (setq last (point))
2676 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2677 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2678 (cond ((and nst
2679 (idlwave-find-key nst 1 'nomark eos))
2680 (goto-char (match-end 0)))
2681 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2682 (setq ifnest (1- ifnest))
2683 (goto-char (match-end 0)))
2684 (t (setq ifnest 0)
2685 (idlwave-next-statement))))
2686 (if pre (goto-char last))
2687 ;; If a continuation line starts here, move to next line
2688 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2689 (beginning-of-line 2))
2690 (point)))
2692 (defun idlwave-statement-type ()
2693 "Return the type of the current IDL statement.
2694 Uses `idlwave-statement-match' to return a cons of (type . point) with
2695 point the ending position where the type was determined. Type is the
2696 association from `idlwave-statement-match', i.e. the cons cell from the
2697 list not just the type symbol. Returns nil if not an identifiable
2698 statement."
2699 (save-excursion
2700 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2701 ;; and possibly comments
2702 (while (looking-at "[ \t]*\\$")
2703 (forward-line 1))
2704 (skip-chars-forward " \t")
2705 (let ((st idlwave-statement-match)
2706 (case-fold-search t))
2707 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2708 (setq st (cdr st))))
2709 (if st
2710 (append st (match-end 0))))))
2712 (defun idlwave-expand-equal (&optional before after is-action)
2713 "Pad '=' with spaces.
2714 Two cases: Assignment statement, and keyword assignment.
2715 Which case is determined using `idlwave-start-of-substatement' and
2716 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2717 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2718 is treated just like assignment statements. When nil, spaces are
2719 removed for keyword assignment. Any other value keeps the current space
2720 around the `='. Limits in for loops are treated as keyword assignment.
2722 Starting with IDL 6.0, a number of op= assignments are available.
2723 Since ambiguities of the form:
2725 r and= b
2726 rand= b
2728 can occur, alphanumeric operator assignment will never be pre-padded,
2729 only post-padded. You must use a space before these to disambiguate
2730 \(not just for padding, but for proper parsing by IDL too!). Other
2731 operators, such as ##=, ^=, etc., will be pre-padded.
2733 IS-ACTION is ignored.
2735 See `idlwave-surround'."
2736 (if idlwave-surround-by-blank
2737 (let
2738 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2739 (an-ops
2740 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2741 (len 1))
2743 (save-excursion
2744 (let ((case-fold-search t))
2745 (backward-char)
2746 (if (or
2747 (re-search-backward non-an-ops nil t)
2748 ;; Why doesn't ##? work for both?
2749 (re-search-backward "\\(#\\)\\=" nil t))
2750 (setq len (1+ (length (match-string 1))))
2751 (when (re-search-backward an-ops nil t)
2752 ;(setq begin nil) ; won't modify begin
2753 (setq len (1+ (length (match-string 1))))))))
2755 (if (eq t idlwave-pad-keyword)
2756 ;; Everything gets padded equally
2757 (idlwave-surround before after len)
2758 ;; Treating keywords/for variables specially...
2759 (let ((st (save-excursion ; To catch "for" variables
2760 (idlwave-start-of-substatement t)
2761 (idlwave-statement-type)))
2762 (what (save-excursion ; To catch keywords
2763 (skip-chars-backward "= \t")
2764 (nth 2 (idlwave-where)))))
2765 (cond ((or (memq what '(function-keyword procedure-keyword))
2766 (memq (caar st) '(for pdef)))
2767 (cond
2768 ((null idlwave-pad-keyword)
2769 (idlwave-surround 0 0)
2770 ) ; remove space
2771 (t))) ; leave any spaces alone
2772 (t (idlwave-surround before after len))))))))
2775 (defun idlwave-indent-and-action (&optional arg)
2776 "Call `idlwave-indent-line' and do expand actions.
2777 With prefix ARG non-nil, indent the entire sub-statement."
2778 (interactive "p")
2779 (save-excursion
2780 (if (and idlwave-expand-generic-end
2781 (re-search-backward "\\<\\(end\\)\\s-*\\="
2782 (max 0 (- (point) 10)) t)
2783 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2784 (progn (goto-char (match-end 1))
2785 ;;Expand the END abbreviation, just as RET or Space would have.
2786 (if abbrev-mode (expand-abbrev)
2787 (idlwave-show-begin)))))
2788 (when (and (not arg) current-prefix-arg)
2789 (setq arg current-prefix-arg)
2790 (setq current-prefix-arg nil))
2791 (if arg
2792 (idlwave-indent-statement)
2793 (idlwave-indent-line t)))
2795 (defun idlwave-indent-line (&optional expand)
2796 "Indent current IDL line as code or as a comment.
2797 The actions in `idlwave-indent-action-table' are performed.
2798 If the optional argument EXPAND is non-nil then the actions in
2799 `idlwave-indent-expand-table' are performed."
2800 (interactive)
2801 ;; Move point out of left margin.
2802 (if (save-excursion
2803 (skip-chars-backward " \t")
2804 (bolp))
2805 (skip-chars-forward " \t"))
2806 (let ((mloc (point-marker)))
2807 (save-excursion
2808 (beginning-of-line)
2809 (if (looking-at idlwave-comment-line-start-skip)
2810 ;; Indentation for a line comment
2811 (progn
2812 (skip-chars-forward " \t")
2813 (idlwave-indent-left-margin (idlwave-comment-hook)))
2815 ;; Code Line
2817 ;; Before indenting, run action routines.
2819 (if (and expand idlwave-do-actions)
2820 (mapc 'idlwave-do-action idlwave-indent-expand-table))
2822 (if idlwave-do-actions
2823 (mapc 'idlwave-do-action idlwave-indent-action-table))
2825 ;; No longer expand abbrevs on the line. The user can do this
2826 ;; manually using expand-region-abbrevs.
2828 ;; Indent for code line
2830 (beginning-of-line)
2831 (if (or
2832 ;; a label line
2833 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2834 ;; a batch command
2835 (looking-at "^[ \t]*@"))
2836 ;; leave flush left
2838 ;; indent the line
2839 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2840 ;; Adjust parallel comment
2841 (end-of-line)
2842 (if (idlwave-in-comment)
2843 ;; Emacs 21 is too smart with fill-column on comment indent
2844 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2845 (1- (frame-width))
2846 fill-column)))
2847 (indent-for-comment)))))
2848 (goto-char mloc)
2849 ;; Get rid of marker
2850 (set-marker mloc nil)))
2852 (defun idlwave-do-action (action)
2853 "Perform an action repeatedly on a line.
2854 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2855 either a function name to be called with `funcall' or a list to be
2856 evaluated with `eval'. The action performed by FUNC should leave
2857 point after the match for REG - otherwise an infinite loop may be
2858 entered. FUNC is always passed a final argument of 'is-action, so it
2859 can discriminate between being run as an action, or a key binding."
2860 (let ((action-key (car action))
2861 (action-routine (cdr action)))
2862 (beginning-of-line)
2863 (while (idlwave-look-at action-key)
2864 (if (listp action-routine)
2865 (eval (append action-routine '('is-action)))
2866 (funcall action-routine 'is-action)))))
2868 (defun idlwave-indent-to (col &optional min)
2869 "Indent from point with spaces until column COL.
2870 Inserts space before markers at point."
2871 (if (not min) (setq min 0))
2872 (insert-before-markers
2873 (make-string (max min (- col (current-column))) ?\ )))
2875 (defun idlwave-indent-left-margin (col)
2876 "Indent the current line to column COL.
2877 Indents such that first non-whitespace character is at column COL
2878 Inserts spaces before markers at point."
2879 (save-excursion
2880 (beginning-of-line)
2881 (delete-horizontal-space)
2882 (idlwave-indent-to col)))
2884 (defun idlwave-indent-subprogram ()
2885 "Indent program unit which contains point."
2886 (interactive)
2887 (save-excursion
2888 (idlwave-end-of-statement)
2889 (idlwave-beginning-of-subprogram)
2890 (let ((beg (point)))
2891 (idlwave-forward-block)
2892 (message "Indenting subprogram...")
2893 (indent-region beg (point) nil))
2894 (message "Indenting subprogram...done.")))
2896 (defun idlwave-indent-statement ()
2897 "Indent current statement, including all continuation lines."
2898 (interactive)
2899 (save-excursion
2900 (idlwave-beginning-of-statement)
2901 (let ((beg (point)))
2902 (idlwave-end-of-statement)
2903 (indent-region beg (point) nil))))
2905 (defun idlwave-calculate-indent ()
2906 "Return appropriate indentation for current line as IDL code."
2907 (save-excursion
2908 (beginning-of-line)
2909 (cond
2910 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2911 ;; function
2912 ((idlwave-look-at idlwave-begin-unit-reg)
2914 ;; Check for continuation line
2915 ((save-excursion
2916 (and (= (forward-line -1) 0)
2917 (idlwave-is-continuation-line)))
2918 (idlwave-calculate-cont-indent))
2919 ;; calculate indent based on previous and current statements
2920 (t (let* (beg-prev-pos
2921 (the-indent
2922 ;; calculate indent based on previous statement
2923 (save-excursion
2924 (cond
2925 ;; Beginning of file
2926 ((prog1
2927 (idlwave-previous-statement)
2928 (setq beg-prev-pos (point)))
2930 ;; Main block
2931 ((idlwave-look-at idlwave-begin-unit-reg t)
2932 (+ (idlwave-current-statement-indent)
2933 idlwave-main-block-indent))
2934 ;; Begin block
2935 ((idlwave-look-at idlwave-begin-block-reg t)
2936 (+ (idlwave-min-current-statement-indent)
2937 idlwave-block-indent))
2938 ;; End Block
2939 ((idlwave-look-at idlwave-end-block-reg t)
2940 (progn
2941 ;; Match to the *beginning* of the block opener
2942 (goto-char beg-prev-pos)
2943 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2944 (idlwave-min-current-statement-indent)))
2945 ;; idlwave-end-offset
2946 ;; idlwave-block-indent))
2948 ;; Default to current indent
2949 ((idlwave-current-statement-indent))))))
2950 ;; adjust the indentation based on the current statement
2951 (cond
2952 ;; End block
2953 ((idlwave-look-at idlwave-end-block-reg)
2954 (+ the-indent idlwave-end-offset))
2955 (the-indent)))))))
2958 ;; Parentheses indent
2961 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2962 "Calculate the continuation indent inside a paren group.
2963 Returns a cons-cell with (open . indent), where open is the
2964 location of the open paren."
2965 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2966 ;; Found an innermost open paren.
2967 (when open
2968 (goto-char open)
2969 ;; Line up with next word unless this is a closing paren.
2970 (cons open
2971 (cond
2972 ;; Plain Kernighan-style nested indent
2973 (idlwave-indent-parens-nested
2974 (+ idlwave-continuation-indent (idlwave-current-indent)))
2976 ;; This is a closed paren - line up under open paren.
2977 (close-exp
2978 (current-column))
2980 ;; Empty (or just comment) follows -- revert to basic indent
2981 ((progn
2982 ;; Skip paren
2983 (forward-char 1)
2984 (looking-at "[ \t$]*\\(;.*\\)?$"))
2985 nil)
2987 ;; Line up with first word after any blank space
2988 ((progn
2989 (skip-chars-forward " \t")
2990 (current-column))))))))
2992 (defun idlwave-calculate-cont-indent ()
2993 "Calculates the IDL continuation indent column from the previous statement.
2994 Note that here previous statement usually means the beginning of the
2995 current statement if this statement is a continuation of the previous
2996 line. Various special types of continuations, including assignments,
2997 routine definitions, and parenthetical groupings, are treated separately."
2998 (save-excursion
2999 (let* ((case-fold-search t)
3000 (end-reg (progn (beginning-of-line) (point)))
3001 (beg-last-statement (save-excursion (idlwave-previous-statement)
3002 (point)))
3003 (beg-reg (progn (idlwave-start-of-substatement 'pre)
3004 (if (eq (line-beginning-position) end-reg)
3005 (goto-char beg-last-statement)
3006 (point))))
3007 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
3008 idlwave-continuation-indent))
3009 fancy-nonparen-indent fancy-paren-indent)
3010 (cond
3011 ;; Align then with its matching if, etc.
3012 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
3013 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
3014 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
3015 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3016 "[ \t]*until")
3017 ("\\<case\\>" . "[ \t]*of")))
3018 match cont-re)
3019 (goto-char end-reg)
3020 (and
3021 (setq cont-re
3022 (catch 'exit
3023 (while (setq match (car matchers))
3024 (if (looking-at (cdr match))
3025 (throw 'exit (car match)))
3026 (setq matchers (cdr matchers)))))
3027 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3028 (if (looking-at "end") ;; that one's special
3029 (- (idlwave-current-indent)
3030 (+ idlwave-block-indent idlwave-end-offset))
3031 (idlwave-current-indent)))
3033 ;; Indent in from the previous line for continuing statements
3034 ((let ((matchers '("\\<then\\>"
3035 "\\<do\\>"
3036 "\\<repeat\\>"
3037 "\\<else\\>"))
3038 match)
3039 (catch 'exit
3040 (goto-char end-reg)
3041 (if (/= (forward-line -1) 0)
3042 (throw 'exit nil))
3043 (while (setq match (car matchers))
3044 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3045 "\\(;.*\\)?$"))
3046 (throw 'exit t))
3047 (setq matchers (cdr matchers)))))
3048 (+ idlwave-continuation-indent (idlwave-current-indent)))
3050 ;; Parenthetical indent, either traditional or Kernighan style
3051 ((setq fancy-paren-indent
3052 (let* ((end-reg end-reg)
3053 (close-exp (progn
3054 (goto-char end-reg)
3055 (skip-chars-forward " \t")
3056 (looking-at "\\s)")))
3057 indent-cons)
3058 (catch 'loop
3059 (while (setq indent-cons (idlwave-calculate-paren-indent
3060 beg-reg end-reg close-exp))
3061 ;; First permitted containing paren
3062 (if (or
3063 idlwave-indent-to-open-paren
3064 idlwave-indent-parens-nested
3065 (null (cdr indent-cons))
3066 (< (- (cdr indent-cons) basic-indent)
3067 idlwave-max-extra-continuation-indent))
3068 (throw 'loop (cdr indent-cons)))
3069 (setq end-reg (car indent-cons))))))
3070 fancy-paren-indent)
3072 ;; A continued assignment, or procedure call/definition
3073 ((and
3074 (> idlwave-max-extra-continuation-indent 0)
3075 (setq fancy-nonparen-indent
3076 (progn
3077 (goto-char beg-reg)
3078 (while (idlwave-look-at "&")) ; skip continued statements
3079 (cond
3080 ;; A continued Procedure call or definition
3081 ((progn
3082 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3083 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3084 (goto-char (match-end 0))
3085 ;; Comment only, or blank line with "$"? Basic indent.
3086 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3088 (current-column)))
3090 ;; Continued assignment (with =):
3091 ((catch 'assign ;
3092 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3093 (goto-char (match-end 0))
3094 (if (null (idlwave-what-function beg-reg))
3095 (throw 'assign t))))
3096 (unless (or
3097 (idlwave-in-quote)
3098 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3099 (save-excursion
3100 (goto-char beg-last-statement)
3101 (eq (caar (idlwave-statement-type)) 'for)))
3102 (current-column))))))
3103 (< (- fancy-nonparen-indent basic-indent)
3104 idlwave-max-extra-continuation-indent))
3105 (if fancy-paren-indent ;calculated but disallowed paren indent
3106 (+ fancy-nonparen-indent idlwave-continuation-indent)
3107 fancy-nonparen-indent))
3109 ;; Basic indent, by default
3110 (t basic-indent)))))
3114 (defun idlwave-find-key (key-re &optional dir nomark limit)
3115 "Move to next match of the regular expression KEY-RE.
3116 Matches inside comments or string constants will be ignored.
3117 If DIR is negative, the search will be backwards.
3118 At a successful match, the mark is pushed unless NOMARK is non-nil.
3119 Searches are limited to LIMIT.
3120 Searches are case-insensitive and use a special syntax table which
3121 treats `$' and `_' as word characters.
3122 Return value is the beginning of the match or (in case of failure) nil."
3123 (setq dir (or dir 0))
3124 (let ((case-fold-search t)
3125 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3126 found)
3127 (idlwave-with-special-syntax
3128 (save-excursion
3129 (catch 'exit
3130 (while (funcall search-func key-re limit t)
3131 (if (not (idlwave-quoted))
3132 (throw 'exit (setq found (match-beginning 0)))
3133 (if (or (and (> dir 0) (eobp))
3134 (and (< dir 0) (bobp)))
3135 (throw 'exit nil)))))))
3136 (if found
3137 (progn
3138 (if (not nomark) (push-mark))
3139 (goto-char found)
3140 found)
3141 nil)))
3143 (defun idlwave-block-jump-out (&optional dir nomark)
3144 "When optional argument DIR is non-negative, move forward to end of
3145 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3146 regular expressions. When DIR is negative, move backwards to block beginning.
3147 Recursively calls itself to skip over nested blocks. DIR defaults to
3148 forward. Calls `push-mark' unless the optional argument NOMARK is
3149 non-nil. Movement is limited by the start of program units because of
3150 possibility of unbalanced blocks."
3151 (interactive "P")
3152 (or dir (setq dir 0))
3153 (let* ((here (point))
3154 (case-fold-search t)
3155 (limit (if (>= dir 0) (point-max) (point-min)))
3156 (block-limit (if (>= dir 0)
3157 idlwave-begin-block-reg
3158 idlwave-end-block-reg))
3159 found
3160 (block-reg (concat idlwave-begin-block-reg "\\|"
3161 idlwave-end-block-reg))
3162 (unit-limit (or (save-excursion
3163 (if (< dir 0)
3164 (idlwave-find-key
3165 idlwave-begin-unit-reg dir t limit)
3166 (end-of-line)
3167 (idlwave-find-key
3168 idlwave-end-unit-reg dir t limit)))
3169 limit)))
3170 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3171 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3172 (while (and found (looking-at block-limit))
3173 (if (>= dir 0) (forward-word 1))
3174 (idlwave-block-jump-out dir t)
3175 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3176 (if (not nomark) (push-mark here))
3177 (if (not found) (goto-char unit-limit)
3178 (if (>= dir 0) (forward-word 1)))))
3180 (defun idlwave-min-current-statement-indent (&optional end-reg)
3181 "The minimum indent in the current statement."
3182 (idlwave-beginning-of-statement)
3183 (if (not (idlwave-is-continuation-line))
3184 (idlwave-current-indent)
3185 (let ((min (idlwave-current-indent)) comm-or-empty)
3186 (while (and (= (forward-line 1) 0)
3187 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3188 (idlwave-is-continuation-line))
3189 (or (null end-reg) (< (point) end-reg)))
3190 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3191 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3193 (min min (idlwave-current-indent))))))
3195 (defun idlwave-current-statement-indent (&optional last-line)
3196 "Return indentation of the current statement.
3197 If in a statement, moves to beginning of statement before finding indent."
3198 (if last-line
3199 (idlwave-end-of-statement)
3200 (idlwave-beginning-of-statement))
3201 (idlwave-current-indent))
3203 (defun idlwave-current-indent ()
3204 "Return the column of the indentation of the current line.
3205 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3206 (save-excursion
3207 (beginning-of-line)
3208 (skip-chars-forward " \t")
3209 ;; if we are at the end of blank line return 0
3210 (cond ((eolp) 0)
3211 ((current-column)))))
3213 (defun idlwave-is-continuation-line ()
3214 "Test if current line is continuation line.
3215 Blank or comment-only lines following regular continuation lines (with
3216 `$') count as continuations too."
3217 (let (p)
3218 (save-excursion
3220 (idlwave-look-at "\\<\\$")
3221 (catch 'loop
3222 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3223 (eq (forward-line -1) 0))
3224 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
3226 (defun idlwave-is-comment-line ()
3227 "Test if the current line is a comment line."
3228 (save-excursion
3229 (beginning-of-line 1)
3230 (looking-at "[ \t]*;")))
3232 (defun idlwave-is-comment-or-empty-line ()
3233 "Test if the current line is a comment line."
3234 (save-excursion
3235 (beginning-of-line 1)
3236 (looking-at "[ \t]*[;\n]")))
3238 (defun idlwave-look-at (regexp &optional cont beg)
3239 "Search current line from current point for REGEXP.
3240 If optional argument CONT is non-nil, searches to the end of
3241 the current statement.
3242 If optional arg BEG is non-nil, search starts from the beginning of the
3243 current statement.
3244 Ignores matches that end in a comment or inside a string expression.
3245 Returns point if successful, nil otherwise.
3246 This function produces unexpected results if REGEXP contains quotes or
3247 a comment delimiter. The search is case insensitive.
3248 If successful leaves point after the match, otherwise, does not move point."
3249 (let ((here (point))
3250 (case-fold-search t)
3251 (eos (save-excursion
3252 (if cont (idlwave-end-of-statement) (end-of-line))
3253 (point)))
3254 found)
3255 (idlwave-with-special-syntax
3256 (if beg (idlwave-beginning-of-statement))
3257 (while (and (setq found (re-search-forward regexp eos t))
3258 (idlwave-quoted))))
3259 (if (not found) (goto-char here))
3260 found))
3262 (defun idlwave-fill-paragraph (&optional nohang)
3263 "Fill paragraphs in comments.
3264 A paragraph is made up of all contiguous lines having the same comment
3265 leader (the leading whitespace before the comment delimiter and the
3266 comment delimiter). In addition, paragraphs are separated by blank
3267 line comments. The indentation is given by the hanging indent of the
3268 first line, otherwise by the minimum indentation of the lines after
3269 the first line. The indentation of the first line does not change.
3270 Does not effect code lines. Does not fill comments on the same line
3271 with code. The hanging indent is given by the end of the first match
3272 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3273 If the optional argument NOHANG is non-nil then the hanging indent is
3274 ignored."
3275 (interactive "P")
3276 ;; check if this is a line comment
3277 (if (save-excursion
3278 (beginning-of-line)
3279 (skip-chars-forward " \t")
3280 (looking-at comment-start))
3281 (let
3282 ((indent 999)
3283 pre here diff fill-prefix-reg bcl first-indent
3284 hang start end)
3285 ;; Change tabs to spaces in the surrounding paragraph.
3286 ;; The surrounding paragraph will be the largest containing block of
3287 ;; contiguous line comments. Thus, we may be changing tabs in
3288 ;; a much larger area than is needed, but this is the easiest
3289 ;; brute force way to do it.
3291 ;; This has the undesirable side effect of replacing the tabs
3292 ;; permanently without the user's request or knowledge.
3293 (save-excursion
3294 (backward-paragraph)
3295 (setq start (point)))
3296 (save-excursion
3297 (forward-paragraph)
3298 (setq end (point)))
3299 (untabify start end)
3301 (setq here (point))
3302 (beginning-of-line)
3303 (setq bcl (point))
3304 (re-search-forward
3305 (concat "^[ \t]*" comment-start "+")
3306 (save-excursion (end-of-line) (point))
3308 ;; Get the comment leader on the line and its length
3309 (setq pre (current-column))
3310 ;; the comment leader is the indentation plus exactly the
3311 ;; number of consecutive ";".
3312 (setq fill-prefix-reg
3313 (concat
3314 (setq fill-prefix
3315 (regexp-quote
3316 (buffer-substring (save-excursion
3317 (beginning-of-line) (point))
3318 (point))))
3319 "[^;]"))
3321 ;; Mark the beginning and end of the paragraph
3322 (goto-char bcl)
3323 (while (and (looking-at fill-prefix-reg)
3324 (not (looking-at paragraph-separate))
3325 (not (bobp)))
3326 (forward-line -1))
3327 ;; Move to first line of paragraph
3328 (if (/= (point) bcl)
3329 (forward-line 1))
3330 (setq start (point))
3331 (goto-char bcl)
3332 (while (and (looking-at fill-prefix-reg)
3333 (not (looking-at paragraph-separate))
3334 (not (eobp)))
3335 (forward-line 1))
3336 (beginning-of-line)
3337 (if (or (not (looking-at fill-prefix-reg))
3338 (looking-at paragraph-separate))
3339 (forward-line -1))
3340 (end-of-line)
3341 ;; if at end of buffer add a newline (need this because
3342 ;; fill-region needs END to be at the beginning of line after
3343 ;; the paragraph or it will add a line).
3344 (if (eobp)
3345 (progn (insert ?\n) (backward-char 1)))
3346 ;; Set END to the beginning of line after the paragraph
3347 ;; END is calculated as distance from end of buffer
3348 (setq end (- (point-max) (point) 1))
3350 ;; Calculate the indentation for the paragraph.
3352 ;; In the following while statements, after one iteration
3353 ;; point will be at the beginning of a line in which case
3354 ;; the while will not be executed for the
3355 ;; the first paragraph line and thus will not affect the
3356 ;; indentation.
3358 ;; First check to see if indentation is based on hanging indent.
3359 (if (and (not nohang) idlwave-hanging-indent
3360 (setq hang
3361 (save-excursion
3362 (goto-char start)
3363 (idlwave-calc-hanging-indent))))
3364 ;; Adjust lines of paragraph by inserting spaces so that
3365 ;; each line's indent is at least as great as the hanging
3366 ;; indent. This is needed for fill-paragraph to work with
3367 ;; a fill-prefix.
3368 (progn
3369 (setq indent hang)
3370 (beginning-of-line)
3371 (while (> (point) start)
3372 (re-search-forward comment-start-skip
3373 (save-excursion (end-of-line) (point))
3375 (if (> (setq diff (- indent (current-column))) 0)
3376 (progn
3377 (if (>= here (point))
3378 ;; adjust the original location for the
3379 ;; inserted text.
3380 (setq here (+ here diff)))
3381 (insert (make-string diff ?\ ))))
3382 (forward-line -1))
3385 ;; No hang. Instead find minimum indentation of paragraph
3386 ;; after first line.
3387 ;; For the following while statement, since START is at the
3388 ;; beginning of line and END is at the end of line
3389 ;; point is greater than START at least once (which would
3390 ;; be the case for a single line paragraph).
3391 (while (> (point) start)
3392 (beginning-of-line)
3393 (setq indent
3394 (min indent
3395 (progn
3396 (re-search-forward
3397 comment-start-skip
3398 (save-excursion (end-of-line) (point))
3400 (current-column))))
3401 (forward-line -1))
3403 (setq fill-prefix (concat fill-prefix
3404 (make-string (- indent pre)
3405 ?\ )))
3406 ;; first-line indent
3407 (setq first-indent
3408 (max
3409 (progn
3410 (re-search-forward
3411 comment-start-skip
3412 (save-excursion (end-of-line) (point))
3414 (current-column))
3415 indent))
3417 ;; try to keep point at its original place
3418 (goto-char here)
3420 ;; In place of the more modern fill-region-as-paragraph, a hack
3421 ;; to keep whitespace untouched on the first line within the
3422 ;; indent length and to preserve any indent on the first line
3423 ;; (first indent).
3424 (save-excursion
3425 (setq diff
3426 (buffer-substring start (+ start first-indent -1)))
3427 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3428 (fill-region-as-paragraph
3429 start
3430 (- (point-max) end)
3431 (current-justification)
3432 nil)
3433 (delete-region start (+ start first-indent -1))
3434 (goto-char start)
3435 (insert diff))
3436 ;; When we want the point at the beginning of the comment
3437 ;; body fill-region will put it at the beginning of the line.
3438 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3439 (setq fill-prefix nil))))
3441 (defun idlwave-calc-hanging-indent ()
3442 "Calculate the position of the hanging indent for the comment paragraph.
3443 The hanging indent position is given by the first match with the
3444 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3445 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3446 on the line.
3447 If not found returns nil."
3448 (if idlwave-use-last-hang-indent
3449 (save-excursion
3450 (end-of-line)
3451 (if (re-search-backward
3452 idlwave-hang-indent-regexp
3453 (save-excursion (beginning-of-line) (point))
3455 (+ (current-column) (length idlwave-hang-indent-regexp))))
3456 (save-excursion
3457 (beginning-of-line)
3458 (if (re-search-forward
3459 idlwave-hang-indent-regexp
3460 (save-excursion (end-of-line) (point))
3462 (current-column)))))
3464 (defun idlwave-auto-fill ()
3465 "Called to break lines in auto fill mode.
3466 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3467 non-nil. Places a continuation character at the end of the line if
3468 not in a comment. Splits strings with IDL concatenation operator `+'
3469 if `idlwave-auto-fill-split-string' is non-nil."
3470 (if (<= (current-column) fill-column)
3471 nil ; do not to fill
3472 (if (or (not idlwave-fill-comment-line-only)
3473 (save-excursion
3474 ;; Check for comment line
3475 (beginning-of-line)
3476 (looking-at idlwave-comment-line-start-skip)))
3477 (let (beg)
3478 (idlwave-indent-line)
3479 ;; Prevent actions do-auto-fill which calls indent-line-function.
3480 (let (idlwave-do-actions
3481 (paragraph-separate ".")
3482 (fill-nobreak-predicate
3483 (if (and (idlwave-in-quote)
3484 idlwave-auto-fill-split-string)
3485 (lambda () ;; We'll need 5 spaces for " ' + $"
3486 (<= (- fill-column (current-column)) 5)
3487 ))))
3488 (do-auto-fill))
3489 (save-excursion
3490 (end-of-line 0)
3491 ;; Indent the split line
3492 (idlwave-indent-line))
3493 (if (save-excursion
3494 (beginning-of-line)
3495 (looking-at idlwave-comment-line-start-skip))
3496 ;; A continued line comment
3497 ;; We treat continued line comments as part of a comment
3498 ;; paragraph. So we check for a hanging indent.
3499 (if idlwave-hanging-indent
3500 (let ((here (- (point-max) (point)))
3501 (indent
3502 (save-excursion
3503 (forward-line -1)
3504 (idlwave-calc-hanging-indent))))
3505 (if indent
3506 (progn
3507 ;; Remove whitespace between comment delimiter and
3508 ;; text, insert spaces for appropriate indentation.
3509 (beginning-of-line)
3510 (re-search-forward
3511 comment-start-skip
3512 (save-excursion (end-of-line) (point)) t)
3513 (delete-horizontal-space)
3514 (idlwave-indent-to indent)
3515 (goto-char (- (point-max) here)))
3517 ;; Split code or comment?
3518 (if (save-excursion
3519 (end-of-line 0)
3520 (idlwave-in-comment))
3521 ;; Splitting a non-full-line comment.
3522 ;; Insert the comment delimiter from split line
3523 (progn
3524 (save-excursion
3525 (beginning-of-line)
3526 (skip-chars-forward " \t")
3527 ;; Insert blank to keep off beginning of line
3528 (insert " "
3529 (save-excursion
3530 (forward-line -1)
3531 (buffer-substring (idlwave-goto-comment)
3532 (progn
3533 (skip-chars-forward "; ")
3534 (point))))))
3535 (idlwave-indent-line))
3536 ;; Split code line - add continuation character
3537 (save-excursion
3538 (end-of-line 0)
3539 ;; Check to see if we split a string
3540 (if (and (setq beg (idlwave-in-quote))
3541 idlwave-auto-fill-split-string)
3542 ;; Split the string and concatenate.
3543 ;; The first extra space is for the space
3544 ;; the line was split. That space was removed.
3545 (insert " " (char-after beg) " +"))
3546 (insert " $"))
3547 (if beg
3548 (if idlwave-auto-fill-split-string
3549 ;; Make the second part of continued string
3550 (save-excursion
3551 (beginning-of-line)
3552 (skip-chars-forward " \t")
3553 (insert (char-after beg)))
3554 ;; Warning
3555 (beep)
3556 (message "Warning: continuation inside a string.")))
3557 ;; Although do-auto-fill (via indent-new-comment-line) calls
3558 ;; idlwave-indent-line for the new line, re-indent again
3559 ;; because of the addition of the continuation character.
3560 (idlwave-indent-line))
3561 )))))
3563 (defun idlwave-auto-fill-mode (arg)
3564 "Toggle auto-fill mode for IDL mode.
3565 With arg, turn auto-fill mode on if arg is positive.
3566 In auto-fill mode, inserting a space at a column beyond `fill-column'
3567 automatically breaks the line at a previous space."
3568 (interactive "P")
3569 (prog1 (set idlwave-fill-function
3570 (if (if (null arg)
3571 (not (symbol-value idlwave-fill-function))
3572 (> (prefix-numeric-value arg) 0))
3573 'idlwave-auto-fill
3574 nil))
3575 ;; update mode-line
3576 (set-buffer-modified-p (buffer-modified-p))))
3578 ;(defun idlwave-fill-routine-call ()
3579 ; "Fill a routine definition or statement, indenting appropriately."
3580 ; (let ((where (idlwave-where)))))
3583 (defun idlwave-doc-header (&optional nomark)
3584 "Insert a documentation header at the beginning of the unit.
3585 Inserts the value of the variable `idlwave-file-header'. Sets mark
3586 before moving to do insertion unless the optional prefix argument
3587 NOMARK is non-nil."
3588 (interactive "P")
3589 (or nomark (push-mark))
3590 ;; make sure we catch the current line if it begins the unit
3591 (if idlwave-header-to-beginning-of-file
3592 (goto-char (point-min))
3593 (end-of-line)
3594 (idlwave-beginning-of-subprogram)
3595 (beginning-of-line)
3596 ;; skip function or procedure line
3597 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3598 (progn
3599 (idlwave-end-of-statement)
3600 (if (> (forward-line 1) 0) (insert "\n")))))
3601 (let ((pos (point)))
3602 (if idlwave-file-header
3603 (cond ((car idlwave-file-header)
3604 (insert-file-contents (car idlwave-file-header)))
3605 ((stringp (car (cdr idlwave-file-header)))
3606 (insert (car (cdr idlwave-file-header))))))
3607 (goto-char pos)))
3609 (defun idlwave-default-insert-timestamp ()
3610 "Default timestamp insertion function."
3611 (insert (current-time-string))
3612 (insert ", " (user-full-name))
3613 (if (boundp 'user-mail-address)
3614 (insert " <" user-mail-address ">")
3615 (insert " <" (user-login-name) "@" (system-name) ">"))
3616 ;; Remove extra spaces from line
3617 (idlwave-fill-paragraph)
3618 ;; Insert a blank line comment to separate from the date entry -
3619 ;; will keep the entry from flowing onto date line if re-filled.
3620 (insert "\n;\n;\t\t"))
3622 (defun idlwave-doc-modification ()
3623 "Insert a brief modification log at the beginning of the current program.
3624 Looks for an occurrence of the value of user variable
3625 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3626 name and places the point for the user to add a log. Before moving, saves
3627 location on mark ring so that the user can return to previous point."
3628 (interactive)
3629 (push-mark)
3630 (let* (beg end)
3631 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3632 (progn
3633 (goto-char (point-min))
3634 (re-search-forward idlwave-doclib-start nil t)))
3635 (setq beg (match-beginning 0))
3636 (re-search-forward idlwave-doclib-end nil t)
3637 (setq end (match-end 0)))
3638 (progn
3639 (goto-char beg)
3640 (if (re-search-forward
3641 (concat idlwave-doc-modifications-keyword ":")
3642 end t)
3643 (end-of-line)
3644 (goto-char end)
3645 (end-of-line -1)
3646 (insert "\n" comment-start "\n")
3647 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3648 (insert "\n;\n;\t")
3649 (run-hooks 'idlwave-timestamp-hook))
3650 (error "No valid DOCLIB header"))))
3653 ;; CJC 3/16/93
3654 ;; Interface to expand-region-abbrevs which did not work when the
3655 ;; abbrev hook associated with an abbrev moves point backwards
3656 ;; after abbrev expansion, e.g., as with the abbrev '.n'.
3657 ;; The original would enter an infinite loop in attempting to expand
3658 ;; .n (it would continually expand and unexpand the abbrev without expanding
3659 ;; because the point would keep going back to the beginning of the
3660 ;; abbrev instead of to the end of the abbrev). We now keep the
3661 ;; abbrev hook from moving backwards.
3663 (defun idlwave-expand-region-abbrevs (start end)
3664 "Expand each abbrev occurrence in the region.
3665 Calling from a program, arguments are START END."
3666 (interactive "r")
3667 (save-excursion
3668 (goto-char (min start end))
3669 (let ((idlwave-show-block nil) ;Do not blink
3670 (idlwave-abbrev-move nil)) ;Do not move
3671 (expand-region-abbrevs start end 'noquery))))
3673 (defun idlwave-quoted ()
3674 "Return t if point is in a comment or quoted string.
3675 Returns nil otherwise."
3676 (or (idlwave-in-comment) (idlwave-in-quote)))
3678 (defun idlwave-in-quote ()
3679 "Return location of the opening quote
3680 if point is in a IDL string constant, nil otherwise.
3681 Ignores comment delimiters on the current line.
3682 Properly handles nested quotation marks and octal
3683 constants - a double quote followed by an octal digit."
3684 ;; Treat an octal inside an apostrophe to be a normal string. Treat a
3685 ;; double quote followed by an octal digit to be an octal constant
3686 ;; rather than a string. Therefore, there is no terminating double
3687 ;; quote.
3688 (save-excursion
3689 ;; Because single and double quotes can quote each other we must
3690 ;; search for the string start from the beginning of line.
3691 (let* ((start (point))
3692 (eol (progn (end-of-line) (point)))
3693 (bq (progn (beginning-of-line) (point)))
3694 (endq (point))
3695 (data (match-data))
3696 delim
3697 found)
3698 (while (< endq start)
3699 ;; Find string start
3700 ;; Don't find an octal constant beginning with a double quote
3701 (if (re-search-forward "[\"']" eol 'lim)
3702 ;; Find the string end.
3703 ;; In IDL, two consecutive delimiters after the start of a
3704 ;; string act as an
3705 ;; escape for the delimiter in the string.
3706 ;; Two consecutive delimiters alone (i.e., not after the
3707 ;; start of a string) is the null string.
3708 (progn
3709 ;; Move to position after quote
3710 (goto-char (1+ (match-beginning 0)))
3711 (setq bq (1- (point)))
3712 ;; Get the string delimiter
3713 (setq delim (char-to-string (preceding-char)))
3714 ;; Check for null string
3715 (if (looking-at delim)
3716 (progn (setq endq (point)) (forward-char 1))
3717 ;; Look for next unpaired delimiter
3718 (setq found (search-forward delim eol 'lim))
3719 (while (looking-at delim)
3720 (forward-char 1)
3721 (setq found (search-forward delim eol 'lim)))
3722 (setq endq (if found (1- (point)) (point)))
3724 (progn (setq bq (point)) (setq endq (point)))))
3725 (store-match-data data)
3726 ;; return string beginning position or nil
3727 (if (> start bq) bq))))
3729 (defun idlwave-is-pointer-dereference (&optional limit)
3730 "Determine if the character after point is a pointer dereference *."
3731 (and
3732 (eq (char-after) ?\*)
3733 (not (idlwave-in-quote))
3734 (save-excursion
3735 (forward-char)
3736 (re-search-backward (concat "\\(" idlwave-idl-keywords
3737 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
3740 ;; Statement templates
3742 ;; Replace these with a general template function, something like
3743 ;; expand.el (I think there was also something with a name similar to
3744 ;; dmacro.el)
3746 (defun idlwave-template (s1 s2 &optional prompt noindent)
3747 "Build a template with optional prompt expression.
3749 Opens a line if point is not followed by a newline modulo intervening
3750 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3751 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3752 adjusted according to `idlwave-abbrev-change-case'. If optional
3753 argument PROMPT is a string then it is displayed as a message in the
3754 minibuffer. The PROMPT serves as a reminder to the user of an
3755 expression to enter.
3757 The lines containing S1 and S2 are reindented using `indent-region'
3758 unless the optional second argument NOINDENT is non-nil."
3759 (if (eq major-mode 'idlwave-shell-mode)
3760 ;; This is a gross hack to avoit template abbrev expansion
3761 ;; in the shell. FIXME: This is a dirty hack.
3762 (if (and (eq this-command 'self-insert-command)
3763 (equal last-abbrev-location (point)))
3764 (insert last-abbrev-text)
3765 (error "No templates in idlwave-shell"))
3766 (cond ((eq idlwave-abbrev-change-case 'down)
3767 (setq s1 (downcase s1) s2 (downcase s2)))
3768 (idlwave-abbrev-change-case
3769 (setq s1 (upcase s1) s2 (upcase s2))))
3770 (let ((beg (save-excursion (beginning-of-line) (point)))
3771 end)
3772 (if (not (looking-at "\\s-*\n"))
3773 (open-line 1))
3774 (insert s1)
3775 (save-excursion
3776 (insert s2)
3777 (setq end (point)))
3778 (if (not noindent)
3779 (indent-region beg end nil))
3780 (if (stringp prompt)
3781 (message "%s" prompt)))))
3783 (defun idlwave-rw-case (string)
3784 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3785 (if idlwave-reserved-word-upcase
3786 (upcase string)
3787 string))
3789 (defun idlwave-elif ()
3790 "Build skeleton IDL if-else block."
3791 (interactive)
3792 (idlwave-template
3793 (idlwave-rw-case "if")
3794 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3795 "Condition expression"))
3797 (defun idlwave-case ()
3798 "Build skeleton IDL case statement."
3799 (interactive)
3800 (idlwave-template
3801 (idlwave-rw-case "case")
3802 (idlwave-rw-case " of\n\nendcase")
3803 "Selector expression"))
3805 (defun idlwave-switch ()
3806 "Build skeleton IDL switch statement."
3807 (interactive)
3808 (idlwave-template
3809 (idlwave-rw-case "switch")
3810 (idlwave-rw-case " of\n\nendswitch")
3811 "Selector expression"))
3813 (defun idlwave-for ()
3814 "Build skeleton IDL loop statement."
3815 (interactive)
3816 (idlwave-template
3817 (idlwave-rw-case "for")
3818 (idlwave-rw-case " do begin\n\nendfor")
3819 "Loop expression"))
3821 (defun idlwave-if ()
3822 "Build skeleton IDL if statement."
3823 (interactive)
3824 (idlwave-template
3825 (idlwave-rw-case "if")
3826 (idlwave-rw-case " then begin\n\nendif")
3827 "Scalar logical expression"))
3829 (defun idlwave-procedure ()
3830 (interactive)
3831 (idlwave-template
3832 (idlwave-rw-case "pro")
3833 (idlwave-rw-case "\n\nreturn\nend")
3834 "Procedure name"))
3836 (defun idlwave-function ()
3837 (interactive)
3838 (idlwave-template
3839 (idlwave-rw-case "function")
3840 (idlwave-rw-case "\n\nreturn\nend")
3841 "Function name"))
3843 (defun idlwave-repeat ()
3844 (interactive)
3845 (idlwave-template
3846 (idlwave-rw-case "repeat begin\n\nendrep until")
3847 (idlwave-rw-case "")
3848 "Exit condition"))
3850 (defun idlwave-while ()
3851 (interactive)
3852 (idlwave-template
3853 (idlwave-rw-case "while")
3854 (idlwave-rw-case " do begin\n\nendwhile")
3855 "Entry condition"))
3857 (defun idlwave-split-string (string &optional pattern)
3858 "Return a list of substrings of STRING which are separated by PATTERN.
3859 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3860 (or pattern
3861 (setq pattern "[ \f\t\n\r\v]+"))
3862 (let (parts (start 0))
3863 (while (string-match pattern string start)
3864 (setq parts (cons (substring string start (match-beginning 0)) parts)
3865 start (match-end 0)))
3866 (nreverse (cons (substring string start) parts))))
3868 (defun idlwave-replace-string (string replace_string replace_with)
3869 (let* ((start 0)
3870 (last (length string))
3871 (ret_string "")
3872 end)
3873 (while (setq end (string-match replace_string string start))
3874 (setq ret_string
3875 (concat ret_string (substring string start end) replace_with))
3876 (setq start (match-end 0)))
3877 (setq ret_string (concat ret_string (substring string start last)))))
3879 (defun idlwave-get-buffer-visiting (file)
3880 ;; Return the buffer currently visiting FILE
3881 (cond
3882 ((boundp 'find-file-compare-truenames) ; XEmacs
3883 (let ((find-file-compare-truenames t))
3884 (get-file-buffer file)))
3885 ((fboundp 'find-buffer-visiting) ; Emacs
3886 (find-buffer-visiting file))
3887 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3889 (defvar idlwave-outlawed-buffers nil
3890 "List of buffers pulled up by IDLWAVE for special reasons.
3891 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3893 (defun idlwave-find-file-noselect (file &optional why)
3894 ;; Return a buffer visiting file.
3895 (or (idlwave-get-buffer-visiting file)
3896 (let ((buf (find-file-noselect file)))
3897 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3898 buf)))
3900 (defun idlwave-kill-autoloaded-buffers ()
3901 "Kill buffers created automatically by IDLWAVE.
3902 Function prompts for a letter to identify the buffers to kill.
3903 Possible letters are:
3905 f Buffers created by the command \\[idlwave-find-module] or mouse
3906 clicks in the routine info window.
3907 s Buffers created by the IDLWAVE Shell to display where execution
3908 stopped or an error was found.
3909 a Both of the above.
3911 Buffers containing unsaved changes require confirmation before they are killed."
3912 (interactive)
3913 (if (null idlwave-outlawed-buffers)
3914 (error "No IDLWAVE-created buffers available")
3915 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3916 (idlwave-count-outlawed-buffers 'find)
3917 (idlwave-count-outlawed-buffers 'shell)))
3918 (let ((c (read-char)))
3919 (cond
3920 ((member c '(?f ?\C-f))
3921 (idlwave-do-kill-autoloaded-buffers 'find))
3922 ((member c '(?s ?\C-s))
3923 (idlwave-do-kill-autoloaded-buffers 'shell))
3924 ((member c '(?a ?\C-a))
3925 (idlwave-do-kill-autoloaded-buffers t))
3926 (t (error "Abort"))))))
3928 (defun idlwave-count-outlawed-buffers (tag)
3929 "How many outlawed buffers have tag TAG?"
3930 (length (delq nil
3931 (mapcar
3932 (lambda (x) (eq (cdr x) tag))
3933 idlwave-outlawed-buffers))))
3935 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3936 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3937 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3938 (cnt 0)
3939 entry)
3940 (while (setq entry (pop list))
3941 (if (buffer-live-p (car entry))
3942 (and (or (memq t reasons)
3943 (memq (cdr entry) reasons))
3944 (kill-buffer (car entry))
3945 (incf cnt)
3946 (setq idlwave-outlawed-buffers
3947 (delq entry idlwave-outlawed-buffers)))
3948 (setq idlwave-outlawed-buffers
3949 (delq entry idlwave-outlawed-buffers))))
3950 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3952 (defun idlwave-revoke-license-to-kill ()
3953 "Remove BUFFER from the buffers which may be killed.
3954 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3955 Intended for `after-save-hook'."
3956 (let* ((buf (current-buffer))
3957 (entry (assq buf idlwave-outlawed-buffers)))
3958 ;; Revoke license
3959 (if entry
3960 (setq idlwave-outlawed-buffers
3961 (delq entry idlwave-outlawed-buffers)))
3962 ;; Remove this function from the hook.
3963 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3965 (defvar idlwave-path-alist)
3966 (defun idlwave-locate-lib-file (file)
3967 ;; Find FILE on the scanned lib path and return a buffer visiting it
3968 (let* ((dirs idlwave-path-alist)
3969 dir efile)
3970 (catch 'exit
3971 (while (setq dir (car (pop dirs)))
3972 (if (file-regular-p
3973 (setq efile (expand-file-name file dir)))
3974 (throw 'exit efile))))))
3976 (defun idlwave-expand-lib-file-name (file)
3977 ;; Find FILE on the scanned lib path and return a buffer visiting it
3978 ;; This is for, e.g., finding source with no user catalog
3979 (cond
3980 ((null file) nil)
3981 ((file-name-absolute-p file) file)
3982 (t (idlwave-locate-lib-file file))))
3984 (defun idlwave-make-tags ()
3985 "Create the IDL tags file IDLTAGS in the current directory from
3986 the list of directories specified in the minibuffer. Directories may be
3987 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3988 specified top directories are searched if the directory name is prefixed
3989 by @. Specify @ directories with care, it may take a long, long time if
3990 you specify /."
3991 (interactive)
3992 (let (directory directories cmd append status numdirs dir getsubdirs
3993 buffer save_buffer files numfiles item errbuf)
3996 ;; Read list of directories
3997 (setq directory (read-string "Tag Directories: " "."))
3998 (setq directories (idlwave-split-string directory "[ \t]+"))
4000 ;; Set etags command, vars
4001 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
4002 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4003 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4004 (setq append " ")
4005 (setq status 0)
4007 ;; For each directory
4008 (setq numdirs 0)
4009 (setq dir (nth numdirs directories))
4010 (while (and dir)
4012 ;; Find the subdirectories
4013 (if (string-match "^[@]\\(.+\\)$" dir)
4014 (setq getsubdirs t) (setq getsubdirs nil))
4015 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
4016 (setq dir (expand-file-name dir))
4017 (if (file-directory-p dir)
4018 (progn
4019 (if (and getsubdirs)
4020 (progn
4021 (setq buffer (get-buffer-create "*idltags*"))
4022 (call-process "sh" nil buffer nil "-c"
4023 (concat "find " dir " -type d -print"))
4024 (setq save_buffer (current-buffer))
4025 (set-buffer buffer)
4026 (setq files (idlwave-split-string
4027 (idlwave-replace-string
4028 (buffer-substring 1 (point-max))
4029 "\n" "/*.pro ")
4030 "[ \t]+"))
4031 (set-buffer save_buffer)
4032 (kill-buffer buffer))
4033 (setq files (list (concat dir "/*.pro"))))
4035 ;; For each subdirectory
4036 (setq numfiles 0)
4037 (setq item (nth numfiles files))
4038 (while (and item)
4040 ;; Call etags
4041 (if (not (string-match "^[ \\t]*$" item))
4042 (progn
4043 (message "%s" (concat "Tagging " item "..."))
4044 (setq errbuf (get-buffer-create "*idltags-error*"))
4045 (setq status (+ status
4046 (if (eq 0 (call-process
4047 "sh" nil errbuf nil "-c"
4048 (concat cmd append item)))
4050 1)))
4052 ;; Append additional tags
4053 (setq append " --append ")
4054 (setq numfiles (1+ numfiles))
4055 (setq item (nth numfiles files)))
4056 (progn
4057 (setq numfiles (1+ numfiles))
4058 (setq item (nth numfiles files))
4061 (setq numdirs (1+ numdirs))
4062 (setq dir (nth numdirs directories)))
4063 (progn
4064 (setq numdirs (1+ numdirs))
4065 (setq dir (nth numdirs directories)))))
4067 (setq errbuf (get-buffer-create "*idltags-error*"))
4068 (if (= status 0)
4069 (kill-buffer errbuf))
4070 (message "")
4073 (defun idlwave-toggle-comment-region (beg end &optional n)
4074 "Comment the lines in the region if the first non-blank line is
4075 commented, and conversely, uncomment region. If optional prefix arg
4076 N is non-nil, then for N positive, add N comment delimiters or for N
4077 negative, remove N comment delimiters.
4078 Uses `comment-region' which does not place comment delimiters on
4079 blank lines."
4080 (interactive "r\nP")
4081 (if n
4082 (comment-region beg end (prefix-numeric-value n))
4083 (save-excursion
4084 (goto-char beg)
4085 (beginning-of-line)
4086 ;; skip blank lines
4087 (skip-chars-forward " \t\n")
4088 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4089 (if (fboundp 'uncomment-region)
4090 (uncomment-region beg end)
4091 (comment-region beg end
4092 (- (length (buffer-substring
4093 (match-beginning 1)
4094 (match-end 1))))))
4095 (comment-region beg end)))))
4098 ;; ----------------------------------------------------------------------------
4099 ;; ----------------------------------------------------------------------------
4100 ;; ----------------------------------------------------------------------------
4101 ;; ----------------------------------------------------------------------------
4103 ;; Completion and Routine Info
4106 ;; String "intern" functions
4108 ;; For the completion and routine info function, we want to normalize
4109 ;; the case of procedure names etc. We do this by "interning" these
4110 ;; string is a hand-crafted way. Hashes are used to map the downcase
4111 ;; version of the strings to the cased versions. Most *-sint-*
4112 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4113 ;; system hash. The former is re-scanned, and the latter takes case
4114 ;; precedence.
4116 ;; Since these cased versions are really lisp objects, we can use `eq'
4117 ;; to search, which is a large performance boost. All new strings
4118 ;; need to be "sinterned". We do this as early as possible after
4119 ;; getting these strings from completion or buffer substrings. So
4120 ;; most of the code can simply assume to deal with "sinterned"
4121 ;; strings. The only exception is that the functions which scan whole
4122 ;; buffers for routine information do not intern the grabbed strings.
4123 ;; This is only done afterwards. Therefore in these functions it is
4124 ;; *not* safe to assume the strings can be compared with `eq' and be
4125 ;; fed into the routine assq functions.
4127 ;; Here we define the hashing functions.
4129 ;; The variables which hold the hashes.
4130 (defvar idlwave-sint-routines '(nil))
4131 (defvar idlwave-sint-keywords '(nil))
4132 (defvar idlwave-sint-methods '(nil))
4133 (defvar idlwave-sint-classes '(nil))
4134 (defvar idlwave-sint-dirs '(nil))
4135 (defvar idlwave-sint-libnames '(nil))
4137 (defun idlwave-reset-sintern (&optional what)
4138 "Reset all sintern hashes."
4139 ;; Make sure the hash functions are accessible.
4140 (unless (and (fboundp 'gethash)
4141 (fboundp 'puthash))
4142 (require 'cl)
4143 (or (fboundp 'puthash)
4144 (defalias 'puthash 'cl-puthash)))
4145 (let ((entries '((idlwave-sint-routines 1000 10)
4146 (idlwave-sint-keywords 1000 10)
4147 (idlwave-sint-methods 100 10)
4148 (idlwave-sint-classes 10 10))))
4150 ;; Make sure these are lists
4151 (loop for entry in entries
4152 for var = (car entry)
4153 do (if (not (consp (symbol-value var))) (set var (list nil))))
4155 ;; Reset the system & library hash
4156 (when (or (eq what t) (eq what 'syslib)
4157 (null (cdr idlwave-sint-routines)))
4158 (loop for entry in entries
4159 for var = (car entry) for size = (nth 1 entry)
4160 do (setcdr (symbol-value var)
4161 (make-hash-table ':size size ':test 'equal)))
4162 (setq idlwave-sint-dirs nil
4163 idlwave-sint-libnames nil))
4165 ;; Reset the buffer & shell hash
4166 (when (or (eq what t) (eq what 'bufsh)
4167 (null (car idlwave-sint-routines)))
4168 (loop for entry in entries
4169 for var = (car entry) for size = (nth 1 entry)
4170 do (setcar (symbol-value var)
4171 (make-hash-table ':size size ':test 'equal))))))
4173 (defun idlwave-sintern-routine-or-method (name &optional class set)
4174 (if class
4175 (idlwave-sintern-method name set)
4176 (idlwave-sintern-routine name set)))
4178 (defun idlwave-sintern (stype &rest args)
4179 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4181 ;;(defmacro idlwave-sintern (type var)
4182 ;; `(cond ((not (stringp name)) name)
4183 ;; ((gethash (downcase name) (cdr ,var)))
4184 ;; ((gethash (downcase name) (car ,var)))
4185 ;; (set (idlwave-sintern-set name ,type ,var set))
4186 ;; (name)))
4188 (defun idlwave-sintern-routine (name &optional set)
4189 (cond ((not (stringp name)) name)
4190 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4191 ((gethash (downcase name) (car idlwave-sint-routines)))
4192 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4193 (name)))
4194 (defun idlwave-sintern-keyword (name &optional set)
4195 (cond ((not (stringp name)) name)
4196 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4197 ((gethash (downcase name) (car idlwave-sint-keywords)))
4198 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4199 (name)))
4200 (defun idlwave-sintern-method (name &optional set)
4201 (cond ((not (stringp name)) name)
4202 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4203 ((gethash (downcase name) (car idlwave-sint-methods)))
4204 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4205 (name)))
4206 (defun idlwave-sintern-class (name &optional set)
4207 (cond ((not (stringp name)) name)
4208 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4209 ((gethash (downcase name) (car idlwave-sint-classes)))
4210 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4211 (name)))
4213 (defun idlwave-sintern-dir (dir &optional set)
4214 (car (or (member dir idlwave-sint-dirs)
4215 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4216 (defun idlwave-sintern-libname (name &optional set)
4217 (car (or (member name idlwave-sint-libnames)
4218 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4220 (defun idlwave-sintern-set (name type tables set)
4221 (let* ((func (or (cdr (assq type idlwave-completion-case))
4222 'identity))
4223 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4224 (table (if (eq set 'sys) (cdr tables) (car tables))))
4225 (puthash (downcase name) iname table)
4226 iname))
4228 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4229 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4230 (mapc (lambda(x)
4231 (setcar x (idlwave-sintern-keyword (car x) set)))
4232 (cdr kwd-list))
4233 kwd-list)
4235 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4236 "Sintern all strings in the rinfo LIST.
4237 With optional parameter SET: also set new patterns. Probably this
4238 will always have to be t. If DEFAULT-DIR is passed, it is used as
4239 the base of the directory."
4240 (let (entry name type class kwds res source call new)
4241 (while list
4242 (setq entry (car list)
4243 list (cdr list)
4244 name (car entry)
4245 type (nth 1 entry)
4246 class (nth 2 entry)
4247 source (nth 3 entry)
4248 call (nth 4 entry)
4249 kwds (nthcdr 5 entry))
4251 ;; The class and name
4252 (if class
4253 (progn
4254 (if (symbolp class) (setq class (symbol-name class)))
4255 (setq class (idlwave-sintern-class class set))
4256 (setq name (idlwave-sintern-method name set)))
4257 (setq name (idlwave-sintern-routine name set)))
4259 ;; The source
4260 (let ((source-type (car source))
4261 (source-file (nth 1 source))
4262 (source-dir (if default-dir
4263 (file-name-as-directory default-dir)
4264 (nth 2 source)))
4265 (source-lib (nth 3 source)))
4266 (if (stringp source-dir)
4267 (setq source-dir (idlwave-sintern-dir source-dir set)))
4268 (if (stringp source-lib)
4269 (setq source-lib (idlwave-sintern-libname source-lib set)))
4270 (setq source (list source-type source-file source-dir source-lib)))
4272 ;; The keywords
4273 (setq kwds (mapcar (lambda (x)
4274 (idlwave-sintern-keyword-list x set))
4275 kwds))
4277 ;; Build a canonicalized list
4278 (setq new (nconc (list name type class source call) kwds)
4279 res (cons new res)))
4280 (nreverse res)))
4282 ;; Creating new sintern tables
4284 (defun idlwave-new-sintern-type (tag)
4285 "Define a variable and a function to sintern the new type TAG.
4286 This defines the function `idlwave-sintern-TAG' and the variable
4287 `idlwave-sint-TAGs'."
4288 (let* ((name (symbol-name tag))
4289 (names (concat name "s"))
4290 (var (intern (concat "idlwave-sint-" names)))
4291 (func (intern (concat "idlwave-sintern-" name))))
4292 (set var nil) ; initial value of the association list
4293 (fset func ; set the function
4294 `(lambda (name &optional set)
4295 (cond ((not (stringp name)) name)
4296 ((cdr (assoc (downcase name) ,var)))
4297 (set
4298 (setq ,var (cons (cons (downcase name) name) ,var))
4299 name)
4300 (name))))))
4302 (defun idlwave-reset-sintern-type (tag)
4303 "Reset the sintern variable associated with TAG."
4304 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4306 ;;---------------------------------------------------------------------------
4309 ;; The variables which hold the information
4310 (defvar idlwave-system-routines nil
4311 "Holds the routine-info obtained by scanning buffers.")
4312 (defvar idlwave-buffer-routines nil
4313 "Holds the routine-info obtained by scanning buffers.")
4314 (defvar idlwave-compiled-routines nil
4315 "Holds the routine-info obtained by asking the shell.")
4316 (defvar idlwave-unresolved-routines nil
4317 "Holds the unresolved routine-info obtained by asking the shell.")
4318 (defvar idlwave-user-catalog-routines nil
4319 "Holds the procedure routine-info from the user scan.")
4320 (defvar idlwave-library-catalog-routines nil
4321 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4322 (defvar idlwave-library-catalog-libname nil
4323 "Name of library catalog loaded from .idlwave_catalog files.")
4324 (defvar idlwave-path-alist nil
4325 "Alist with !PATH directories and zero or more flags if the dir has
4326 been scanned in a user catalog ('user) or discovered in a library
4327 catalog \('lib).")
4328 (defvar idlwave-true-path-alist nil
4329 "Like `idlwave-path-alist', but with true filenames.")
4330 (defvar idlwave-routines nil
4331 "Holds the combined procedure/function/method routine-info.")
4332 (defvar idlwave-class-alist nil
4333 "Holds the class names known to IDLWAVE.")
4334 (defvar idlwave-class-history nil
4335 "The history of classes selected with the minibuffer.")
4336 (defvar idlwave-force-class-query nil)
4337 (defvar idlwave-before-completion-wconf nil
4338 "The window configuration just before the completion buffer was displayed.")
4339 (defvar idlwave-last-system-routine-info-cons-cell nil
4340 "The last cons cell in the system routine info.")
4343 ;; The code to get routine info from different sources.
4345 (defvar idlwave-system-routines)
4346 (defvar idlwave-catalog-process nil
4347 "The background process currently updating the catalog.")
4349 (defun idlwave-routines ()
4350 "Provide a list of IDL routines.
4351 This routine loads the builtin routines on the first call.
4352 Later it only returns the value of the variable."
4353 (if (and idlwave-catalog-process
4354 (processp idlwave-catalog-process))
4355 (progn
4356 (cond
4357 ((equal (process-status idlwave-catalog-process) 'exit)
4358 (message "updating........")
4359 (setq idlwave-catalog-process nil)
4360 (idlwave-update-routine-info '(4)))
4361 ((equal (process-status idlwave-catalog-process) 'run)
4362 ;; Keep it running...
4365 ;; Something is wrong, get rid of the process
4366 (message "Problem with catalog process") (beep)
4367 (condition-case nil
4368 (kill-process idlwave-catalog-process)
4369 (error nil))
4370 (setq idlwave-catalog-process nil)))))
4371 (or idlwave-routines
4372 (progn
4373 (idlwave-update-routine-info)
4374 ;; return the current value
4375 idlwave-routines)))
4377 (defvar idlwave-update-rinfo-hook nil
4378 "List of functions which should run after a global rinfo update.
4379 Does not run after automatic updates of buffer or the shell.")
4381 (defun idlwave-rescan-catalog-directories ()
4382 "Rescan the previously selected directories. For batch processing."
4383 (idlwave-update-routine-info '(16)))
4385 (defun idlwave-rescan-asynchronously ()
4386 "Dispatch another Emacs instance to update the idlwave catalog.
4387 After the process finishes normally, the first access to routine info
4388 will re-read the catalog."
4389 (interactive)
4390 (if (processp idlwave-catalog-process)
4391 (if (eq (process-status idlwave-catalog-process) 'run)
4392 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4393 (progn
4394 (condition-case nil
4395 (kill-process idlwave-catalog-process)
4396 (error nil))
4397 (error "Process killed, no new process started"))
4398 (error "Quit"))
4399 (condition-case nil
4400 (kill-process idlwave-catalog-process)
4401 (error nil))))
4402 (if (or (not idlwave-user-catalog-file)
4403 (not (stringp idlwave-user-catalog-file))
4404 (not (file-regular-p idlwave-user-catalog-file)))
4405 (error "No catalog has been produced yet"))
4406 (let* ((emacs (concat invocation-directory invocation-name))
4407 (args (list "-batch"
4408 "-l" (expand-file-name "~/.emacs")
4409 "-l" "idlwave"
4410 "-f" "idlwave-rescan-catalog-directories"))
4411 (process (apply 'start-process "idlcat"
4412 nil emacs args)))
4413 (setq idlwave-catalog-process process)
4414 (set-process-sentinel
4415 process
4416 (lambda (pro why)
4417 (when (string-match "finished" why)
4418 (setq idlwave-routines nil
4419 idlwave-system-routines nil
4420 idlwave-catalog-process nil)
4421 (or (idlwave-start-load-rinfo-timer)
4422 (idlwave-update-routine-info '(4))))))
4423 (message "Background job started to update catalog file")))
4426 ;; Format for all routine info user catalog, library catalogs, etc.:
4428 ;; ("ROUTINE" type class
4429 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4430 ;; (buffer pro_file dir) | (compiled pro_file dir)
4431 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4432 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4434 ;; DIR will be supplied dynamically while loading library catalogs,
4435 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4436 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4437 ;; be nil, as can LINK1, etc., if no HTML help is available.
4440 (defvar idlwave-load-rinfo-idle-timer)
4441 (defvar idlwave-shell-path-query)
4443 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4444 "Update the internal routine-info lists.
4445 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4446 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4447 about individual routines.
4449 The information can come from 4 sources:
4450 1. IDL programs in the current editing session
4451 2. Compiled modules in an IDL shell running as Emacs subprocess
4452 3. A list which covers the IDL system routines.
4453 4. A list which covers the prescanned library files.
4455 Scans all IDLWAVE-mode buffers of the current editing session (see
4456 `idlwave-scan-all-buffers-for-routine-info').
4457 When an IDL shell is running, this command also queries the IDL program
4458 for currently compiled routines.
4460 With prefix ARG, also reload the system and library lists.
4461 With two prefix ARG's, also rescans the chosen user catalog tree.
4462 With three prefix args, dispatch asynchronous process to do the update.
4464 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4465 lists, but instead wait for the shell query to complete and
4466 asynchronously finish updating routine info. This is set
4467 automatically when called interactively. When you need routine
4468 information updated immediately, leave NO-CONCATENATE nil."
4469 (interactive "P\np")
4470 ;; Stop any idle processing
4471 (if (or (and (fboundp 'itimerp)
4472 (itimerp idlwave-load-rinfo-idle-timer))
4473 (and (fboundp 'timerp)
4474 (timerp idlwave-load-rinfo-idle-timer)))
4475 (cancel-timer idlwave-load-rinfo-idle-timer))
4476 (cond
4477 ((equal arg '(64))
4478 ;; Start a background process which updates the catalog.
4479 (idlwave-rescan-asynchronously))
4480 ((equal arg '(16))
4481 ;; Update the user catalog now, and wait for them.
4482 (idlwave-create-user-catalog-file t))
4484 (let* ((load (or arg
4485 idlwave-buffer-case-takes-precedence
4486 (null idlwave-routines)))
4487 ;; The override-idle means, even if the idle timer has done some
4488 ;; preparing work, load and renormalize everything anyway.
4489 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4491 (setq idlwave-buffer-routines nil
4492 idlwave-compiled-routines nil
4493 idlwave-unresolved-routines nil)
4494 ;; Reset the appropriate hashes
4495 (if (get 'idlwave-reset-sintern 'done-by-idle)
4496 ;; reset was already done in idle time, so skip this step now once
4497 (put 'idlwave-reset-sintern 'done-by-idle nil)
4498 (idlwave-reset-sintern (cond (load t)
4499 ((null idlwave-system-routines) t)
4500 (t 'bufsh))))
4502 (if idlwave-buffer-case-takes-precedence
4503 ;; We can safely scan the buffer stuff first
4504 (progn
4505 (idlwave-update-buffer-routine-info)
4506 (and load (idlwave-load-all-rinfo override-idle)))
4507 ;; We first do the system info, and then the buffers
4508 (and load (idlwave-load-all-rinfo override-idle))
4509 (idlwave-update-buffer-routine-info))
4511 ;; Let's see if there is a shell
4512 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4513 (idlwave-shell-is-running)))
4514 (ask-shell (and shell-is-running
4515 idlwave-query-shell-for-routine-info)))
4517 ;; Load the library catalogs again, first re-scanning the path
4518 (when arg
4519 (if shell-is-running
4520 (idlwave-shell-send-command idlwave-shell-path-query
4521 '(progn
4522 (idlwave-shell-get-path-info)
4523 (idlwave-scan-library-catalogs))
4524 'hide)
4525 (idlwave-scan-library-catalogs)))
4527 (if (or (not ask-shell)
4528 (not no-concatenate))
4529 ;; 1. If we are not going to ask the shell, we need to do the
4530 ;; concatenation now.
4531 ;; 2. When this function is called non-interactively, it
4532 ;; means that someone needs routine info *now*. The
4533 ;; shell update causes the concatenation to be
4534 ;; *delayed*, so not in time for the current command.
4535 ;; Therefore, we do a concatenation now, even though
4536 ;; the shell might do it again.
4537 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4539 (when ask-shell
4540 ;; Ask the shell about the routines it knows of.
4541 (message "Querying the shell")
4542 (idlwave-shell-update-routine-info nil t)))))))
4545 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4546 (defvar idlwave-load-rinfo-idle-timer nil)
4547 (defun idlwave-start-load-rinfo-timer ()
4548 (if (or (and (fboundp 'itimerp)
4549 (itimerp idlwave-load-rinfo-idle-timer))
4550 (and (fboundp 'timerp)
4551 (timerp idlwave-load-rinfo-idle-timer)))
4552 (cancel-timer idlwave-load-rinfo-idle-timer))
4553 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4554 (setq idlwave-load-rinfo-idle-timer nil)
4555 (if (and idlwave-init-rinfo-when-idle-after
4556 (numberp idlwave-init-rinfo-when-idle-after)
4557 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4558 (not idlwave-routines))
4559 (condition-case nil
4560 (progn
4561 (setq idlwave-load-rinfo-idle-timer
4562 (run-with-idle-timer
4563 idlwave-init-rinfo-when-idle-after
4564 nil 'idlwave-load-rinfo-next-step)))
4565 (error nil))))
4567 (defvar idlwave-library-routines nil "Obsolete variable.")
4569 ;;------ XML Help routine info system
4570 (defun idlwave-load-system-routine-info ()
4571 ;; Load the system routine info from the cached routine info file,
4572 ;; which, if necessary, will be re-created from the XML file on
4573 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4574 ;; file distributed with older IDLWAVE versions (<6.0)
4575 (unless (and (load idlwave-xml-system-rinfo-converted-file
4576 'noerror 'nomessage)
4577 (idlwave-xml-system-routine-info-up-to-date))
4578 ;; See if we can create it from XML source
4579 (condition-case nil
4580 (idlwave-convert-xml-system-routine-info)
4581 (error
4582 (unless (load idlwave-xml-system-rinfo-converted-file
4583 'noerror 'nomessage)
4584 (if idlwave-system-routines
4585 (message
4586 "Failed to load converted routine info, using old conversion.")
4587 (message
4588 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4589 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4590 (message
4591 "Could not locate any system routine information."))))))))
4593 (defun idlwave-xml-system-routine-info-up-to-date()
4594 (let* ((dir (file-name-as-directory
4595 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4596 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4597 (file-newer-than-file-p ;converted file is newer than catalog
4598 idlwave-xml-system-rinfo-converted-file
4599 catalog-file)))
4601 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4602 (defvar idlwave-system-variables-alist nil
4603 "Alist of system variables and the associated structure tags.
4604 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4605 (defvar idlwave-executive-commands-alist nil
4606 "Alist of system variables and their help files.")
4607 (defvar idlwave-help-special-topic-words nil)
4610 (defun idlwave-shorten-syntax (syntax name &optional class)
4611 ;; From a list of syntax statements, shorten with %s and group with "or"
4612 (let ((case-fold-search t))
4613 (mapconcat
4614 (lambda (x)
4615 (while (string-match name x)
4616 (setq x (replace-match "%s" t t x)))
4617 (if class
4618 (while (string-match class x)
4619 (setq x (replace-match "%s" t t x))))
4621 (nreverse syntax)
4622 " or ")))
4624 (defun idlwave-xml-create-class-method-lists (xml-entry)
4625 ;; Create a class list entry from the xml parsed list., returning a
4626 ;; cons of form (class-entry method-entries).
4627 (let* ((nameblock (nth 1 xml-entry))
4628 (class (cdr (assq 'name nameblock)))
4629 (link (cdr (assq 'link nameblock)))
4630 (params (cddr xml-entry))
4631 (case-fold-search t)
4632 class-entry
4633 method methods-entry extra-kwds
4634 props get-props set-props init-props inherits
4635 pelem ptype)
4636 (while params
4637 (setq pelem (car params))
4638 (when (listp pelem)
4639 (setq ptype (car pelem)
4640 props (car (cdr pelem)))
4641 (cond
4642 ((eq ptype 'SUPERCLASS)
4643 (let ((pname (cdr (assq 'name props)))
4644 (plink (cdr (assq 'link props))))
4645 (unless (and (string= pname "None")
4646 (string= plink "None"))
4647 (push pname inherits))))
4649 ((eq ptype 'PROPERTY)
4650 (let ((pname (cdr (assq 'name props)))
4651 (plink (cdr (assq 'link props)))
4652 (get (string= (cdr (assq 'get props)) "Yes"))
4653 (set (string= (cdr (assq 'set props)) "Yes"))
4654 (init (string= (cdr (assq 'init props)) "Yes")))
4655 (if get (push (list pname plink) get-props))
4656 (if set (push (list pname plink) set-props))
4657 (if init (push (list pname plink) init-props))))
4659 ((eq ptype 'METHOD)
4660 (setq method (cdr (assq 'name props)))
4661 (setq extra-kwds ;;Assume all property keywords are gathered already
4662 (cond
4663 ((string-match (concat class "::Init") method)
4664 (put 'init-props 'matched t)
4665 init-props)
4666 ((string-match (concat class "::GetProperty") method)
4667 (put 'get-props 'matched t)
4668 get-props)
4669 ((string-match (concat class "::SetProperty") method)
4670 (put 'set-props 'matched t)
4671 set-props)
4672 (t nil)))
4673 (setq methods-entry
4674 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4675 methods-entry)))
4676 (t)))
4677 (setq params (cdr params)))
4678 ;;(unless (get 'init-props 'matched)
4679 ;; (message "Failed to match Init in class %s" class))
4680 ;;(unless (get 'get-props 'matched)
4681 ;; (message "Failed to match GetProperty in class %s" class))
4682 ;;(unless (get 'set-props 'matched)
4683 ;; (message "Failed to match SetProperty in class %s" class))
4684 (setq class-entry
4685 (if inherits
4686 (list class (append '(inherits) inherits) (list 'link link))
4687 (list class (list 'link link))))
4688 (cons class-entry methods-entry)))
4690 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4691 ;; Create correctly structured list elements from ROUTINE or METHOD
4692 ;; XML list structures. Return a list of list elements, with more
4693 ;; than one sub-list possible if a routine can serve as both
4694 ;; procedure and function (e.g. call_method).
4695 (let* ((nameblock (nth 1 xml-entry))
4696 (name (cdr (assq 'name nameblock)))
4697 (link (cdr (assq 'link nameblock)))
4698 (params (cddr xml-entry))
4699 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4700 (case-fold-search t)
4701 syntax kwd klink pref-list kwds pelem ptype props result type)
4702 (if class ;; strip out class name from class method name string
4703 (if (string-match (concat class "::") name)
4704 (setq name (substring name (match-end 0)))))
4705 (while params
4706 (setq pelem (car params))
4707 (when (listp pelem)
4708 (setq ptype (car pelem)
4709 props (car (cdr pelem)))
4710 (cond
4711 ((eq ptype 'SYNTAX)
4712 (setq syntax (cdr (assq 'name props)))
4713 (if (string-match "-&gt;" syntax)
4714 (setq syntax (replace-match "->" t nil syntax)))
4715 (setq type (cdr (assq 'type props)))
4716 (push syntax
4717 (aref syntax-vec (cond
4718 ((string-match "^pro" type) 0)
4719 ((string-match "^fun" type) 1)
4720 ((string-match "^exec" type) 2)))))
4721 ((eq ptype 'KEYWORD)
4722 (setq kwd (cdr (assq 'name props))
4723 klink (cdr (assq 'link props)))
4724 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4725 (progn
4726 (setq pref-list
4727 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4728 kwd (substring kwd (match-end 0)))
4729 (loop for x in pref-list do
4730 (push (list (concat x kwd) klink) kwds)))
4731 (push (list kwd klink) kwds)))
4733 (t))); Do nothing for the others
4734 (setq params (cdr params)))
4736 ;; Debug
4737 ;; (if (and (null (aref syntax-vec 0))
4738 ;; (null (aref syntax-vec 1))
4739 ;; (null (aref syntax-vec 2)))
4740 ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4741 ;; (if class
4742 ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4743 ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4745 ;; Executive commands are treated specially
4746 (if (aref syntax-vec 2)
4747 (cons (substring name 1) link)
4748 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4749 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4750 (loop for idx from 0 to 1 do
4751 (if (aref syntax-vec idx)
4752 (push (append (list name (if (eq idx 0) 'pro 'fun)
4753 class '(system)
4754 (idlwave-shorten-syntax
4755 (aref syntax-vec idx) name class))
4756 kwds) result)))
4757 result)))
4760 (defun idlwave-rinfo-group-keywords (kwds master-link)
4761 ;; Group keywords by link file, as a list with elements
4762 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4763 (let (kwd link anchor linkfiles block master-elt)
4764 (while kwds
4765 (setq kwd (car kwds)
4766 link (idlwave-split-link-target (nth 1 kwd))
4767 anchor (cdr link)
4768 link (car link)
4769 kwd (car kwd))
4770 (if (setq block (assoc link linkfiles))
4771 (push (cons kwd anchor) (cdr block))
4772 (push (list link (cons kwd anchor)) linkfiles))
4773 (setq kwds (cdr kwds)))
4774 ;; Ensure the master link is there
4775 (if (setq master-elt (assoc master-link linkfiles))
4776 (if (eq (car linkfiles) master-elt)
4777 linkfiles
4778 (cons master-elt (delq master-elt linkfiles)))
4779 (push (list master-link) linkfiles))))
4781 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4782 ;; Clean up the syntax of routines which are actually aliases by
4783 ;; removing the "OR" from the statements
4784 (let (syntax entry)
4785 (loop for x in aliases do
4786 (setq entry (assoc x idlwave-system-routines))
4787 (when entry
4788 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4789 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4791 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4792 ;; Duplicate and trim original routine aliases from rinfo list
4793 ;; This if for, e.g. OPENR/OPENW/OPENU
4794 (let (alias remove-list new parts all-parts)
4795 (loop for x in aliases do
4796 (when (setq parts (split-string (cdr x) "/"))
4797 (setq new (assoc (cdr x) all-parts))
4798 (unless new
4799 (setq new (cons (cdr x) parts))
4800 (push new all-parts))
4801 (setcdr new (delete (car x) (cdr new)))))
4803 ;; Add any missing aliases (separate by slashes)
4804 (loop for x in all-parts do
4805 (if (cdr x)
4806 (push (cons (nth 1 x) (car x)) aliases)))
4808 (loop for x in aliases do
4809 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4810 (unless (memq alias remove-list) (push alias remove-list))
4811 (setq alias (copy-sequence alias))
4812 (setcar alias (car x))
4813 (push alias idlwave-system-routines)))
4814 (loop for x in remove-list do
4815 (delq x idlwave-system-routines))))
4817 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4818 ;; Duplicate and trim original routine aliases from rinfo list
4819 ;; This if for, e.g. !X, !Y, !Z.
4820 (let (alias remove-list)
4821 (loop for x in aliases do
4822 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4823 (unless (memq alias remove-list) (push alias remove-list))
4824 (setq alias (copy-sequence alias))
4825 (setcar alias (car x))
4826 (push alias idlwave-system-variables-alist)))
4827 (loop for x in remove-list do
4828 (delq x idlwave-system-variables-alist))))
4831 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4832 ;; Create a sysvar list entry from the xml parsed list.
4833 (let* ((nameblock (nth 1 xml-entry))
4834 (name (cdr (assq 'name nameblock)))
4835 (sysvar (substring name (progn (string-match "^ *!" name)
4836 (match-end 0))))
4837 (link (cdr (assq 'link nameblock)))
4838 (params (cddr xml-entry))
4839 (case-fold-search t)
4840 pelem ptype props tags)
4841 (while params
4842 (setq pelem (car params))
4843 (when (listp pelem)
4844 (setq ptype (car pelem)
4845 props (car (cdr pelem)))
4846 (cond
4847 ((eq ptype 'FIELD)
4848 (push (cons (cdr (assq 'name props))
4849 (cdr
4850 (idlwave-split-link-target (cdr (assq 'link props)))))
4851 tags))))
4852 (setq params (cdr params)))
4853 (delq nil
4854 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4857 (defvar idlwave-xml-routine-info-file nil)
4859 (defun idlwave-save-routine-info ()
4860 (if idlwave-xml-routine-info-file
4861 (with-temp-file idlwave-xml-system-rinfo-converted-file
4862 (insert
4863 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4864 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4865 ;; Automatically generated from source file:
4866 ;; " idlwave-xml-routine-info-file "
4867 ;; on " (current-time-string) "
4868 ;; Do not edit."))
4869 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4870 idlwave-xml-routine-info-file))
4871 (insert "\n(setq idlwave-system-routines\n '")
4872 (prin1 idlwave-system-routines (current-buffer))
4873 (insert ")")
4874 (insert "\n(setq idlwave-system-variables-alist\n '")
4875 (prin1 idlwave-system-variables-alist (current-buffer))
4876 (insert ")")
4877 (insert "\n(setq idlwave-system-class-info\n '")
4878 (prin1 idlwave-system-class-info (current-buffer))
4879 (insert ")")
4880 (insert "\n(setq idlwave-executive-commands-alist\n '")
4881 (prin1 idlwave-executive-commands-alist (current-buffer))
4882 (insert ")")
4883 (insert "\n(setq idlwave-help-special-topic-words\n '")
4884 (prin1 idlwave-help-special-topic-words (current-buffer))
4885 (insert ")"))))
4887 (defun idlwave-convert-xml-system-routine-info ()
4888 "Convert XML supplied IDL routine info into internal form.
4889 Cache to disk for quick recovery."
4890 (interactive)
4891 (let* ((dir (file-name-as-directory
4892 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4893 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4894 (elem-cnt 0)
4895 props rinfo msg-cnt elem type nelem class-result alias
4896 routines routine-aliases statement-aliases sysvar-aliases)
4897 (if (not (file-exists-p catalog-file))
4898 (error "No such XML routine info file: %s" catalog-file)
4899 (if (not (file-readable-p catalog-file))
4900 (error "Cannot read XML routine info file: %s" catalog-file)))
4901 (message "Reading XML routine info...")
4902 (setq rinfo (xml-parse-file catalog-file))
4903 (message "Reading XML routine info...done")
4904 (setq rinfo (assq 'CATALOG rinfo))
4905 (unless rinfo (error "Failed to parse XML routine info"))
4906 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4908 (setq rinfo (cddr rinfo))
4910 (setq nelem (length rinfo)
4911 msg-cnt (/ nelem 20))
4913 (setq idlwave-xml-routine-info-file nil)
4914 (message "Converting XML routine info...")
4915 (setq idlwave-system-routines nil
4916 idlwave-system-variables-alist nil
4917 idlwave-system-class-info nil
4918 idlwave-executive-commands-alist nil
4919 idlwave-help-special-topic-words nil)
4921 (while rinfo
4922 (setq elem (car rinfo)
4923 rinfo (cdr rinfo))
4924 (incf elem-cnt)
4925 (when (listp elem)
4926 (setq type (car elem)
4927 props (car (cdr elem)))
4928 (if (= (mod elem-cnt msg-cnt) 0)
4929 (message "Converting XML routine info...%2d%%"
4930 (/ (* elem-cnt 100) nelem)))
4931 (cond
4932 ((eq type 'ROUTINE)
4933 (if (setq alias (assq 'alias_to props))
4934 (push (cons (cdr (assq 'name props)) (cdr alias))
4935 routine-aliases)
4936 (setq routines (idlwave-xml-create-rinfo-list elem))
4937 (if (listp (cdr routines))
4938 (setq idlwave-system-routines
4939 (nconc idlwave-system-routines routines))
4940 ;; a cons cell is an executive commands
4941 (push routines idlwave-executive-commands-alist))))
4943 ((eq type 'CLASS)
4944 (setq class-result (idlwave-xml-create-class-method-lists elem))
4945 (push (car class-result) idlwave-system-class-info)
4946 (setq idlwave-system-routines
4947 (nconc idlwave-system-routines (cdr class-result))))
4949 ((eq type 'STATEMENT)
4950 (push (cons (cdr (assq 'name props))
4951 (cdr (assq 'link props)))
4952 idlwave-help-special-topic-words)
4953 ;; Save the links to those which are statement aliases (not routines)
4954 (if (setq alias (assq 'alias_to props))
4955 (unless (member (cdr alias) statement-aliases)
4956 (push (cdr alias) statement-aliases))))
4958 ((eq type 'SYSVAR)
4959 (if (setq alias (cdr (assq 'alias_to props)))
4960 (push (cons (substring (cdr (assq 'name props)) 1)
4961 (substring alias 1))
4962 sysvar-aliases)
4963 (push (idlwave-xml-create-sysvar-alist elem)
4964 idlwave-system-variables-alist)))
4965 (t))))
4966 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4967 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4968 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4970 (setq idlwave-xml-routine-info-file catalog-file)
4971 (idlwave-save-routine-info)
4972 (message "Converting XML routine info...done")))
4975 ;; ("ROUTINE" type class
4976 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4977 ;; (buffer pro_file dir) | (compiled pro_file dir)
4978 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4979 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4982 (defun idlwave-load-rinfo-next-step ()
4983 (let ((inhibit-quit t)
4984 (arr idlwave-load-rinfo-steps-done))
4985 (if (catch 'exit
4986 (when (not (aref arr 0))
4987 (message "Loading system routine info in idle time...")
4988 (idlwave-load-system-routine-info)
4989 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4990 (message "Loading system routine info in idle time...done")
4991 (aset arr 0 t)
4992 (throw 'exit t))
4994 (when (not (aref arr 1))
4995 (message "Normalizing idlwave-system-routines in idle time...")
4996 (idlwave-reset-sintern t)
4997 (put 'idlwave-reset-sintern 'done-by-idle t)
4998 (setq idlwave-system-routines
4999 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5000 (message "Normalizing idlwave-system-routines in idle time...done")
5001 (aset arr 1 t)
5002 (throw 'exit t))
5004 (when (not (aref arr 2))
5005 (when (and (stringp idlwave-user-catalog-file)
5006 (file-regular-p idlwave-user-catalog-file))
5007 (message "Loading user catalog in idle time...")
5008 (condition-case nil
5009 (load-file idlwave-user-catalog-file)
5010 (error (throw 'exit nil)))
5011 ;; Check for the old style catalog and warn
5012 (if (and
5013 (boundp 'idlwave-library-routines)
5014 idlwave-library-routines)
5015 (progn
5016 (setq idlwave-library-routines nil)
5017 (ding)
5018 (message "Outdated user catalog: %s... recreate"
5019 idlwave-user-catalog-file))
5020 (message "Loading user catalog in idle time...done")))
5021 (aset arr 2 t)
5022 (throw 'exit t))
5024 (when (not (aref arr 3))
5025 (when idlwave-user-catalog-routines
5026 (message "Normalizing user catalog routines in idle time...")
5027 (setq idlwave-user-catalog-routines
5028 (idlwave-sintern-rinfo-list
5029 idlwave-user-catalog-routines 'sys))
5030 (message
5031 "Normalizing user catalog routines in idle time...done"))
5032 (aset arr 3 t)
5033 (throw 'exit t))
5035 (when (not (aref arr 4))
5036 (idlwave-scan-library-catalogs
5037 "Loading and normalizing library catalogs in idle time...")
5038 (aset arr 4 t)
5039 (throw 'exit t))
5040 (when (not (aref arr 5))
5041 (message "Finishing initialization in idle time...")
5042 (idlwave-routines)
5043 (message "Finishing initialization in idle time...done")
5044 (aset arr 5 t)
5045 (throw 'exit nil)))
5046 ;; restart the timer
5047 (if (sit-for 1)
5048 (idlwave-load-rinfo-next-step)
5049 (setq idlwave-load-rinfo-idle-timer
5050 (run-with-idle-timer
5051 idlwave-init-rinfo-when-idle-after
5052 nil 'idlwave-load-rinfo-next-step))))))
5054 (defvar idlwave-after-load-rinfo-hook nil)
5056 (defun idlwave-load-all-rinfo (&optional force)
5057 ;; Load and case-treat the system, user catalog, and library routine
5058 ;; info files.
5060 ;; System
5061 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
5062 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5063 (idlwave-load-system-routine-info))
5064 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5065 (message "Normalizing idlwave-system-routines...")
5066 (setq idlwave-system-routines
5067 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5068 (message "Normalizing idlwave-system-routines...done"))
5069 (when idlwave-system-routines
5070 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5071 (setq idlwave-last-system-routine-info-cons-cell
5072 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5074 ;; User catalog
5075 (when (and (stringp idlwave-user-catalog-file)
5076 (file-regular-p idlwave-user-catalog-file))
5077 (condition-case nil
5078 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5079 (load-file idlwave-user-catalog-file))
5080 (error nil))
5081 (when (and
5082 (boundp 'idlwave-library-routines)
5083 idlwave-library-routines)
5084 (setq idlwave-library-routines nil)
5085 (error "Outdated user catalog: %s... recreate"
5086 idlwave-user-catalog-file))
5087 (setq idlwave-true-path-alist nil)
5088 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5089 (message "Normalizing user catalog routines...")
5090 (setq idlwave-user-catalog-routines
5091 (idlwave-sintern-rinfo-list
5092 idlwave-user-catalog-routines 'sys))
5093 (message "Normalizing user catalog routines...done")))
5095 ;; Library catalog
5096 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5097 (idlwave-scan-library-catalogs
5098 "Loading and normalizing library catalogs..."))
5099 (run-hooks 'idlwave-after-load-rinfo-hook))
5102 (defun idlwave-update-buffer-routine-info ()
5103 (let (res)
5104 (cond
5105 ((eq idlwave-scan-all-buffers-for-routine-info t)
5106 ;; Scan all buffers, current buffer last
5107 (message "Scanning all buffers...")
5108 (setq res (idlwave-get-routine-info-from-buffers
5109 (reverse (buffer-list)))))
5110 ((null idlwave-scan-all-buffers-for-routine-info)
5111 ;; Don't scan any buffers
5112 (setq res nil))
5114 ;; Just scan this buffer
5115 (if (eq major-mode 'idlwave-mode)
5116 (progn
5117 (message "Scanning current buffer...")
5118 (setq res (idlwave-get-routine-info-from-buffers
5119 (list (current-buffer))))))))
5120 ;; Put the result into the correct variable
5121 (setq idlwave-buffer-routines
5122 (idlwave-sintern-rinfo-list res 'set))))
5124 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
5125 "Put the different sources for routine information together."
5126 ;; The sequence here is important because earlier definitions shadow
5127 ;; later ones. We assume that if things in the buffers are newer
5128 ;; then in the shell of the system, they are meant to be different.
5129 (setcdr idlwave-last-system-routine-info-cons-cell
5130 (append idlwave-buffer-routines
5131 idlwave-compiled-routines
5132 idlwave-library-catalog-routines
5133 idlwave-user-catalog-routines))
5134 (setq idlwave-class-alist nil)
5136 ;; Give a message with information about the number of routines we have.
5137 (unless quiet
5138 (message
5139 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5140 (length idlwave-buffer-routines)
5141 (length idlwave-compiled-routines)
5142 (length idlwave-library-catalog-routines)
5143 (length idlwave-user-catalog-routines)
5144 (length idlwave-system-routines)))
5145 (if run-hook
5146 (run-hooks 'idlwave-update-rinfo-hook)))
5148 (defun idlwave-class-alist ()
5149 "Return the class alist - make it if necessary."
5150 (or idlwave-class-alist
5151 (let (class)
5152 (loop for x in idlwave-routines do
5153 (when (and (setq class (nth 2 x))
5154 (not (assq class idlwave-class-alist)))
5155 (push (list class) idlwave-class-alist)))
5156 idlwave-class-alist)))
5158 ;; Three functions for the hooks
5159 (defun idlwave-save-buffer-update ()
5160 (idlwave-update-current-buffer-info 'save-buffer))
5161 (defun idlwave-kill-buffer-update ()
5162 (idlwave-update-current-buffer-info 'kill-buffer))
5163 (defun idlwave-new-buffer-update ()
5164 (idlwave-update-current-buffer-info 'find-file))
5166 (defun idlwave-update-current-buffer-info (why)
5167 "Update `idlwave-routines' for current buffer.
5168 Can run from `after-save-hook'."
5169 (when (and (eq major-mode 'idlwave-mode)
5170 (or (eq t idlwave-auto-routine-info-updates)
5171 (memq why idlwave-auto-routine-info-updates))
5172 idlwave-scan-all-buffers-for-routine-info
5173 idlwave-routines)
5174 (condition-case nil
5175 (let (routines)
5176 (idlwave-replace-buffer-routine-info
5177 (buffer-file-name)
5178 (if (eq why 'kill-buffer)
5180 (setq routines
5181 (idlwave-sintern-rinfo-list
5182 (idlwave-get-routine-info-from-buffers
5183 (list (current-buffer))) 'set))))
5184 (idlwave-concatenate-rinfo-lists 'quiet)
5185 routines)
5186 (error nil))))
5188 (defun idlwave-replace-buffer-routine-info (file new)
5189 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5190 (let ((list idlwave-buffer-routines)
5191 found)
5192 (while list
5193 ;; The following test uses eq to make sure it works correctly
5194 ;; when two buffers visit the same file. Then the file names
5195 ;; will be equal, but not eq.
5196 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
5197 (progn
5198 (setcar list nil)
5199 (setq found t))
5200 (if found
5201 ;; End of that section reached. Jump.
5202 (setq list nil)))
5203 (setq list (cdr list)))
5204 (setq idlwave-buffer-routines
5205 (append new (delq nil idlwave-buffer-routines)))))
5207 ;;----- Scanning buffers -------------------
5209 (defun idlwave-get-routine-info-from-buffers (buffers)
5210 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5211 (let (buf routine-lists res)
5212 (save-excursion
5213 (while (setq buf (pop buffers))
5214 (set-buffer buf)
5215 (if (and (eq major-mode 'idlwave-mode)
5216 buffer-file-name)
5217 ;; yes, this buffer has the right mode.
5218 (progn (setq res (condition-case nil
5219 (idlwave-get-buffer-routine-info)
5220 (error nil)))
5221 (push res routine-lists)))))
5222 ;; Concatenate the individual lists and return the result
5223 (apply 'nconc routine-lists)))
5225 (defun idlwave-get-buffer-routine-info ()
5226 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5227 (let* ((case-fold-search t)
5228 routine-list string entry)
5229 (save-excursion
5230 (save-restriction
5231 (widen)
5232 (goto-char (point-min))
5233 (while (re-search-forward
5234 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
5235 (setq string (buffer-substring-no-properties
5236 (match-beginning 0)
5237 (progn
5238 (idlwave-end-of-statement)
5239 (point))))
5240 (setq entry (idlwave-parse-definition string))
5241 (push entry routine-list))))
5242 routine-list))
5244 (defvar idlwave-scanning-lib-dir)
5245 (defvar idlwave-scanning-lib)
5246 (defun idlwave-parse-definition (string)
5247 "Parse a module definition."
5248 (let ((case-fold-search t)
5249 start name args type keywords class)
5250 ;; Remove comments
5251 (while (string-match ";.*" string)
5252 (setq string (replace-match "" t t string)))
5253 ;; Remove the continuation line stuff
5254 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5255 (setq string (replace-match "\\1 " t nil string)))
5256 (while (string-match "\n" string)
5257 (setq string (replace-match " " t nil string)))
5258 ;; Match the name and type.
5259 (when (string-match
5260 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5261 (setq start (match-end 0))
5262 (setq type (downcase (match-string 1 string)))
5263 (if (match-beginning 3)
5264 (setq class (match-string 3 string)))
5265 (setq name (match-string 4 string)))
5266 ;; Match normal args and keyword args
5267 (while (string-match
5268 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5269 string start)
5270 (setq start (match-end 0))
5271 (if (match-beginning 3)
5272 (push (match-string 1 string) keywords)
5273 (push (match-string 1 string) args)))
5274 ;; Normalize and sort.
5275 (setq args (nreverse args))
5276 (setq keywords (sort keywords (lambda (a b)
5277 (string< (downcase a) (downcase b)))))
5278 ;; Make and return the entry
5279 ;; We don't know which argument are optional, so this information
5280 ;; will not be contained in the calling sequence.
5281 (list name
5282 (if (equal type "pro") 'pro 'fun)
5283 class
5284 (cond ((not (boundp 'idlwave-scanning-lib))
5285 (list 'buffer (buffer-file-name)))
5286 ; ((string= (downcase
5287 ; (file-name-sans-extension
5288 ; (file-name-nondirectory (buffer-file-name))))
5289 ; (downcase name))
5290 ; (list 'lib))
5291 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5292 (t (list 'user (file-name-nondirectory (buffer-file-name))
5293 idlwave-scanning-lib-dir "UserLib")))
5294 (concat
5295 (if (string= type "function") "Result = " "")
5296 (if class "Obj ->[%s::]" "")
5297 "%s"
5298 (if args
5299 (concat
5300 (if (string= type "function") "(" ", ")
5301 (mapconcat 'identity args ", ")
5302 (if (string= type "function") ")" ""))))
5303 (if keywords
5304 (cons nil (mapcar 'list keywords)) ;No help file
5305 nil))))
5308 ;;----- Scanning the user catalog -------------------
5310 (defun idlwave-sys-dir ()
5311 "Return the syslib directory, or a dummy that never matches."
5312 (cond
5313 ((and idlwave-system-directory
5314 (not (string= idlwave-system-directory "")))
5315 idlwave-system-directory)
5316 ((getenv "IDL_DIR"))
5317 (t "@@@@@@@@")))
5320 (defun idlwave-create-user-catalog-file (&optional arg)
5321 "Scan all files on selected dirs of IDL search path for routine information.
5323 A widget checklist will allow you to choose the directories. Write
5324 the result as a file `idlwave-user-catalog-file'. When this file
5325 exists, it will be automatically loaded to give routine information
5326 about library routines. With ARG, just rescan the same directories
5327 as last time - so no widget will pop up."
5328 (interactive "P")
5329 ;; Make sure the file is loaded if it exists.
5330 (if (and (stringp idlwave-user-catalog-file)
5331 (file-regular-p idlwave-user-catalog-file))
5332 (condition-case nil
5333 (load-file idlwave-user-catalog-file)
5334 (error nil)))
5335 ;; Make sure the file name makes sense
5336 (unless (and (stringp idlwave-user-catalog-file)
5337 (> (length idlwave-user-catalog-file) 0)
5338 (file-accessible-directory-p
5339 (file-name-directory idlwave-user-catalog-file))
5340 (not (string= "" (file-name-nondirectory
5341 idlwave-user-catalog-file))))
5342 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5344 (cond
5345 ;; Rescan the known directories
5346 ((and arg idlwave-path-alist
5347 (consp (car idlwave-path-alist)))
5348 (idlwave-scan-user-lib-files idlwave-path-alist))
5350 ;; Expand the directories from library-path and run the widget
5351 (idlwave-library-path
5352 (idlwave-display-user-catalog-widget
5353 (if idlwave-true-path-alist
5354 ;; Propagate any flags on the existing path-alist
5355 (mapcar (lambda (x)
5356 (let ((path-entry (assoc (file-truename x)
5357 idlwave-true-path-alist)))
5358 (if path-entry
5359 (cons x (cdr path-entry))
5360 (list x))))
5361 (idlwave-expand-path idlwave-library-path))
5362 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5364 ;; Ask the shell for the path and then run the widget
5366 (message "Asking the shell for IDL path...")
5367 (require 'idlw-shell)
5368 (idlwave-shell-send-command idlwave-shell-path-query
5369 '(idlwave-user-catalog-command-hook nil)
5370 'hide))))
5373 ;; Parse shell path information and select among it.
5374 (defun idlwave-user-catalog-command-hook (&optional arg)
5375 ;; Command hook used by `idlwave-create-user-catalog-file'.
5376 (if arg
5377 ;; Scan immediately
5378 (idlwave-scan-user-lib-files idlwave-path-alist)
5379 ;; Set the path and display the widget
5380 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5381 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5382 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5384 (defconst idlwave-user-catalog-widget-help-string
5385 "This is the front-end to the creation of the IDLWAVE user catalog.
5386 Please select the directories on IDL's search path from which you
5387 would like to extract routine information, to be stored in the file:
5391 If this is not the correct file, first set variable
5392 `idlwave-user-catalog-file', and call this command again.
5394 N.B. Many libraries include pre-scanned catalog files
5395 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5396 not be scanned. You can scan your own libraries off-line using the
5397 perl script `idlwave_catalog'.
5399 After selecting the directories, choose [Scan & Save] to scan the library
5400 directories and save the routine info.
5401 \n")
5403 (defvar idlwave-widget)
5404 (defvar widget-keymap)
5405 (defun idlwave-display-user-catalog-widget (dirs-list)
5406 "Create the widget to select IDL search path directories for scanning."
5407 (interactive)
5408 (require 'widget)
5409 (require 'wid-edit)
5410 (unless dirs-list
5411 (error "Don't know IDL's search path"))
5413 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5414 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5415 (kill-all-local-variables)
5416 (make-local-variable 'idlwave-widget)
5417 (widget-insert (format idlwave-user-catalog-widget-help-string
5418 idlwave-user-catalog-file))
5420 (widget-create 'push-button
5421 :notify 'idlwave-widget-scan-user-lib-files
5422 "Scan & Save")
5423 (widget-insert " ")
5424 (widget-create 'push-button
5425 :notify 'idlwave-delete-user-catalog-file
5426 "Delete File")
5427 (widget-insert " ")
5428 (widget-create 'push-button
5429 :notify
5430 (lambda (&rest ignore)
5431 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5432 (dolist (x path-list)
5433 (unless (memq 'lib (cdr x))
5434 (idlwave-path-alist-add-flag x 'user)))
5435 (idlwave-display-user-catalog-widget path-list)))
5436 "Select All Non-Lib")
5437 (widget-insert " ")
5438 (widget-create 'push-button
5439 :notify
5440 (lambda (&rest ignore)
5441 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5442 (dolist (x path-list)
5443 (idlwave-path-alist-remove-flag x 'user))
5444 (idlwave-display-user-catalog-widget path-list)))
5445 "Deselect All")
5446 (widget-insert " ")
5447 (widget-create 'push-button
5448 :notify (lambda (&rest ignore)
5449 (kill-buffer (current-buffer)))
5450 "Quit")
5451 (widget-insert "\n\n")
5453 (widget-insert "Select Directories: \n")
5455 (setq idlwave-widget
5456 (apply 'widget-create
5457 'checklist
5458 :value (delq nil (mapcar (lambda (x)
5459 (if (memq 'user (cdr x))
5460 (car x)))
5461 dirs-list))
5462 :greedy t
5463 :tag "List of directories"
5464 (mapcar (lambda (x)
5465 (list 'item
5466 (if (memq 'lib (cdr x))
5467 (concat "[LIB] " (car x) )
5468 (car x)))) dirs-list)))
5469 (widget-put idlwave-widget :path-dirs dirs-list)
5470 (widget-insert "\n")
5471 (use-local-map widget-keymap)
5472 (widget-setup)
5473 (goto-char (point-min))
5474 (delete-other-windows))
5476 (defun idlwave-delete-user-catalog-file (&rest ignore)
5477 (if (yes-or-no-p
5478 (format "Delete file %s " idlwave-user-catalog-file))
5479 (progn
5480 (delete-file idlwave-user-catalog-file)
5481 (message "%s has been deleted" idlwave-user-catalog-file))))
5483 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5484 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5485 (let* ((widget idlwave-widget)
5486 (selected-dirs (widget-value widget))
5487 (path-alist (widget-get widget :path-dirs))
5488 (this-path-alist path-alist)
5489 dir-entry)
5490 (while (setq dir-entry (pop this-path-alist))
5491 (if (member
5492 (if (memq 'lib (cdr dir-entry))
5493 (concat "[LIB] " (car dir-entry))
5494 (car dir-entry))
5495 selected-dirs)
5496 (idlwave-path-alist-add-flag dir-entry 'user)
5497 (idlwave-path-alist-remove-flag dir-entry 'user)))
5498 (idlwave-scan-user-lib-files path-alist)))
5500 (defvar font-lock-mode)
5501 (defun idlwave-scan-user-lib-files (path-alist)
5502 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5503 (let* ((idlwave-scanning-lib t)
5504 (idlwave-scanning-lib-dir "")
5505 (idlwave-completion-case nil)
5506 dirs-alist dir files file)
5507 (setq idlwave-user-catalog-routines nil
5508 idlwave-path-alist path-alist ; for library-path instead
5509 idlwave-true-path-alist nil)
5510 (if idlwave-auto-write-paths (idlwave-write-paths))
5511 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5512 (idlwave-mode)
5513 (setq dirs-alist (reverse path-alist))
5514 (while (setq dir (pop dirs-alist))
5515 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5516 (setq dir (car dir))
5517 (setq idlwave-scanning-lib-dir dir)
5518 (when (file-directory-p dir)
5519 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5520 (while (setq file (pop files))
5521 (when (file-regular-p file)
5522 (if (not (file-readable-p file))
5523 (message "Skipping %s (no read permission)" file)
5524 (message "Scanning %s..." file)
5525 (erase-buffer)
5526 (insert-file-contents file 'visit)
5527 (setq idlwave-user-catalog-routines
5528 (append (idlwave-get-routine-info-from-buffers
5529 (list (current-buffer)))
5530 idlwave-user-catalog-routines)))))))))
5531 (message "Creating user catalog file...")
5532 (kill-buffer "*idlwave-scan.pro*")
5533 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5534 (let ((font-lock-maximum-size 0)
5535 (auto-mode-alist nil))
5536 (find-file idlwave-user-catalog-file))
5537 (if (and (boundp 'font-lock-mode)
5538 font-lock-mode)
5539 (font-lock-mode 0))
5540 (erase-buffer)
5541 (insert ";; IDLWAVE user catalog file\n")
5542 (insert (format ";; Created %s\n\n" (current-time-string)))
5544 ;; Define the routine info list
5545 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5546 (let ((standard-output (current-buffer)))
5547 (mapc (lambda (x)
5548 (insert "\n ")
5549 (prin1 x)
5550 (goto-char (point-max)))
5551 idlwave-user-catalog-routines))
5552 (insert (format "))\n\n;;; %s ends here\n"
5553 (file-name-nondirectory idlwave-user-catalog-file)))
5554 (goto-char (point-min))
5555 ;; Save the buffer
5556 (save-buffer 0)
5557 (kill-buffer (current-buffer)))
5558 (message "Creating user catalog file...done")
5559 (message "Info for %d routines saved in %s"
5560 (length idlwave-user-catalog-routines)
5561 idlwave-user-catalog-file)
5562 (sit-for 2)
5563 (idlwave-update-routine-info t))
5565 (defun idlwave-read-paths ()
5566 (if (and (stringp idlwave-path-file)
5567 (file-regular-p idlwave-path-file))
5568 (condition-case nil
5569 (load idlwave-path-file t t t)
5570 (error nil))))
5572 (defun idlwave-write-paths ()
5573 (interactive)
5574 (when (and idlwave-path-alist idlwave-system-directory)
5575 (let ((font-lock-maximum-size 0)
5576 (auto-mode-alist nil))
5577 (find-file idlwave-path-file))
5578 (if (and (boundp 'font-lock-mode)
5579 font-lock-mode)
5580 (font-lock-mode 0))
5581 (erase-buffer)
5582 (insert ";; IDLWAVE paths\n")
5583 (insert (format ";; Created %s\n\n" (current-time-string)))
5584 ;; Define the variable which knows the value of "!DIR"
5585 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5586 idlwave-system-directory))
5588 ;; Define the variable which contains a list of all scanned directories
5589 (insert "\n(setq idlwave-path-alist\n '(")
5590 (let ((standard-output (current-buffer)))
5591 (mapc (lambda (x)
5592 (insert "\n ")
5593 (prin1 x)
5594 (goto-char (point-max)))
5595 idlwave-path-alist))
5596 (insert "))\n")
5597 (save-buffer 0)
5598 (kill-buffer (current-buffer))))
5601 (defun idlwave-expand-path (path &optional default-dir)
5602 ;; Expand parts of path starting with '+' recursively into directory list.
5603 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5604 (message "Expanding path...")
5605 (let (path1 dir recursive)
5606 (while (setq dir (pop path))
5607 (if (setq recursive (string= (substring dir 0 1) "+"))
5608 (setq dir (substring dir 1)))
5609 (if (and recursive
5610 (not (file-name-absolute-p dir)))
5611 (setq dir (expand-file-name dir default-dir)))
5612 (if recursive
5613 ;; Expand recursively
5614 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5615 ;; Keep unchanged
5616 (push dir path1)))
5617 (message "Expanding path...done")
5618 (nreverse path1)))
5620 (defun idlwave-recursive-directory-list (dir)
5621 ;; Return a list of all directories below DIR, including DIR itself
5622 (let ((path (list dir)) path1 file files)
5623 (while (setq dir (pop path))
5624 (when (file-directory-p dir)
5625 (setq files (nreverse (directory-files dir t "[^.]")))
5626 (while (setq file (pop files))
5627 (if (file-directory-p file)
5628 (push (file-name-as-directory file) path)))
5629 (push dir path1)))
5630 path1))
5633 ;;----- Scanning the library catalogs ------------------
5638 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5639 "Scan for library catalog files (.idlwave_catalog) and ingest.
5641 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5642 instead, if present) are searched. Print MESSAGE-BASE along with the
5643 libraries being loaded, if passed, and skip loading/normalizing if
5644 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5645 be set to nil to disable library catalog scanning."
5646 (when idlwave-use-library-catalogs
5647 (let ((dirs
5648 (if idlwave-library-path
5649 (idlwave-expand-path idlwave-library-path)
5650 (mapcar 'car idlwave-path-alist)))
5651 (old-libname "")
5652 dir-entry dir catalog all-routines)
5653 (if message-base (message message-base))
5654 (while (setq dir (pop dirs))
5655 (catch 'continue
5656 (when (file-readable-p
5657 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5658 (unless no-load
5659 (setq idlwave-library-catalog-routines nil)
5660 ;; Load the catalog file
5661 (condition-case nil
5662 (load catalog t t t)
5663 (error (throw 'continue t)))
5664 (when (and
5665 message-base
5666 (not (string= idlwave-library-catalog-libname
5667 old-libname)))
5668 (message "%s" (concat message-base
5669 idlwave-library-catalog-libname))
5670 (setq old-libname idlwave-library-catalog-libname))
5671 (when idlwave-library-catalog-routines
5672 (setq all-routines
5673 (append
5674 (idlwave-sintern-rinfo-list
5675 idlwave-library-catalog-routines 'sys dir)
5676 all-routines))))
5678 ;; Add a 'lib flag if on path-alist
5679 (when (and idlwave-path-alist
5680 (setq dir-entry (assoc dir idlwave-path-alist)))
5681 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5682 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5683 (if message-base (message (concat message-base "done"))))))
5685 ;;----- Communicating with the Shell -------------------
5687 ;; First, here is the idl program which can be used to query IDL for
5688 ;; defined routines.
5689 (defconst idlwave-routine-info.pro
5691 ;; START OF IDLWAVE SUPPORT ROUTINES
5692 pro idlwave_print_safe,item,limit
5693 catch,err
5694 if err ne 0 then begin
5695 print,'Could not print item.'
5696 return
5697 endif
5698 if n_elements(item) gt limit then $
5699 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5700 else print,item
5703 pro idlwave_print_info_entry,name,func=func,separator=sep
5704 ;; See if it's an object method
5705 if name eq '' then return
5706 func = keyword_set(func)
5707 methsep = strpos(name,'::')
5708 meth = methsep ne -1
5710 ;; Get routine info
5711 pars = routine_info(name,/parameters,functions=func)
5712 source = routine_info(name,/source,functions=func)
5713 nargs = pars.num_args
5714 nkw = pars.num_kw_args
5715 if nargs gt 0 then args = pars.args
5716 if nkw gt 0 then kwargs = pars.kw_args
5718 ;; Trim the class, and make the name
5719 if meth then begin
5720 class = strmid(name,0,methsep)
5721 name = strmid(name,methsep+2,strlen(name)-1)
5722 if nargs gt 0 then begin
5723 ;; remove the self argument
5724 wh = where(args ne 'SELF',nargs)
5725 if nargs gt 0 then args = args[wh]
5726 endif
5727 endif else begin
5728 ;; No class, just a normal routine.
5729 class = \"\"
5730 endelse
5732 ;; Calling sequence
5733 cs = \"\"
5734 if func then cs = 'Result = '
5735 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5736 cs = cs + '%s'
5737 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5738 if nargs gt 0 then begin
5739 for j=0,nargs-1 do begin
5740 cs = cs + args[j]
5741 if j lt nargs-1 then cs = cs + ', '
5742 endfor
5744 if func then cs = cs + ')'
5745 ;; Keyword arguments
5746 kwstring = ''
5747 if nkw gt 0 then begin
5748 for j=0,nkw-1 do begin
5749 kwstring = kwstring + ' ' + kwargs[j]
5750 endfor
5751 endif
5753 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5755 print,ret + ': ' + name + sep + class + sep + source[0].path $
5756 + sep + cs + sep + kwstring
5759 pro idlwave_routine_info,file
5760 on_error,1
5761 sep = '<@>'
5762 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5763 all = routine_info()
5764 fileQ=n_elements(file) ne 0
5765 if fileQ then file=strtrim(file,2)
5766 for i=0L,n_elements(all)-1L do begin
5767 if fileQ then begin
5768 if (routine_info(all[i],/SOURCE)).path eq file then $
5769 idlwave_print_info_entry,all[i],separator=sep
5770 endif else idlwave_print_info_entry,all[i],separator=sep
5771 endfor
5772 all = routine_info(/functions)
5773 for i=0L,n_elements(all)-1L do begin
5774 if fileQ then begin
5775 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5776 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5777 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5778 endfor
5779 print,'>>>END OF IDLWAVE ROUTINE INFO'
5782 pro idlwave_get_sysvars
5783 on_error,1
5784 catch,error_status
5785 if error_status ne 0 then begin
5786 print, 'Cannot get info about system variables'
5787 endif else begin
5788 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5789 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5790 v = strsplit(s,' +',/regex,/extract) ; get variables
5791 for i=0L,n_elements(v)-1 do begin
5792 t = [''] ; get tag list
5793 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5794 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5795 endfor
5796 endelse
5799 pro idlwave_get_class_tags, class
5800 res = execute('tags=tag_names({'+class+'})')
5801 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5803 ;; END OF IDLWAVE SUPPORT ROUTINES
5805 "The IDL programs to get info from the shell.")
5807 (defvar idlwave-idlwave_routine_info-compiled nil
5808 "Remember if the routine info procedure is already compiled.")
5810 (defvar idlwave-shell-temp-pro-file)
5811 (defvar idlwave-shell-temp-rinfo-save-file)
5813 (defun idlwave-shell-compile-helper-routines (&optional wait)
5814 (unless (and idlwave-idlwave_routine_info-compiled
5815 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5816 (with-current-buffer (idlwave-find-file-noselect
5817 (idlwave-shell-temp-file 'pro))
5818 (erase-buffer)
5819 (insert idlwave-routine-info.pro)
5820 (save-buffer 0))
5821 (idlwave-shell-send-command
5822 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
5823 nil 'hide wait)
5824 (idlwave-shell-send-command
5825 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5826 (idlwave-shell-temp-file 'rinfo))
5827 nil 'hide)
5828 (setq idlwave-idlwave_routine_info-compiled t))
5830 ;; Restore if necessary. Must use execute to hide lame routine_info
5831 ;; errors on undefinded routine
5832 (idlwave-shell-send-command
5833 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5834 idlwave-shell-temp-rinfo-save-file
5835 idlwave-shell-temp-rinfo-save-file)
5836 nil 'hide))
5839 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5840 "Query the shell for routine_info of compiled modules and update the lists."
5841 ;; Save and compile the procedure. The compiled procedure is then
5842 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5843 ;; need to test for and possibly RESTORE the procedure each time we
5844 ;; use it, since the user may have killed or redefined it. In
5845 ;; particular, .RESET_SESSION will kill all user procedures. If
5846 ;; FILE is set, only update routine info for routines in that file.
5848 (idlwave-shell-compile-helper-routines wait)
5849 ; execute the routine_info procedure, and analyze the output
5850 (idlwave-shell-send-command
5851 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
5852 `(progn
5853 (idlwave-shell-routine-info-filter)
5854 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5855 'hide wait))
5857 ;; ---------------------------------------------------------------------------
5859 ;; Completion and displaying routine calling sequences
5861 (defvar idlwave-completion-help-info nil)
5862 (defvar idlwave-completion-help-links nil)
5863 (defvar idlwave-current-obj_new-class nil)
5864 (defvar idlwave-complete-special nil)
5865 (defvar method-selector)
5866 (defvar class-selector)
5867 (defvar type-selector)
5868 (defvar super-classes)
5870 (defun idlwave-complete (&optional arg module class)
5871 "Complete a function, procedure or keyword name at point.
5872 This function is smart and figures out what can be completed
5873 at this point.
5874 - At the beginning of a statement it completes procedure names.
5875 - In the middle of a statement it completes function names.
5876 - After a `(' or `,' in the argument list of a function or procedure,
5877 it completes a keyword of the relevant function or procedure.
5878 - In the first arg of `OBJ_NEW', it completes a class name.
5880 When several completions are possible, a list will be displayed in
5881 the *Completions* buffer. If this list is too long to fit into the
5882 window, scrolling can be achieved by repeatedly pressing
5883 \\[idlwave-complete].
5885 The function also knows about object methods. When it needs a class
5886 name, the action depends upon `idlwave-query-class', which see. You
5887 can force IDLWAVE to ask you for a class name with a
5888 \\[universal-argument] prefix argument to this command.
5890 See also the variables `idlwave-keyword-completion-adds-equal' and
5891 `idlwave-function-completion-adds-paren'.
5893 The optional ARG can be used to specify the completion type in order
5894 to override IDLWAVE's idea of what should be completed at point.
5895 Possible values are:
5897 0 <=> query for the completion type
5898 1 <=> 'procedure
5899 2 <=> 'procedure-keyword
5900 3 <=> 'function
5901 4 <=> 'function-keyword
5902 5 <=> 'procedure-method
5903 6 <=> 'procedure-method-keyword
5904 7 <=> 'function-method
5905 8 <=> 'function-method-keyword
5906 9 <=> 'class
5908 As a special case, the universal argument C-u forces completion of
5909 function names in places where the default would be a keyword.
5911 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5912 completion.
5914 For Lisp programmers only:
5915 When we force a keyword, optional argument MODULE can contain the module name.
5916 When we force a method or a method keyword, CLASS can specify the class."
5917 (interactive "P")
5918 (idlwave-routines)
5919 (let* ((where-list
5920 (if (and arg
5921 (or (and (integerp arg) (not (equal arg '(16))))
5922 (symbolp arg)))
5923 (idlwave-make-force-complete-where-list arg module class)
5924 (idlwave-where)))
5925 (what (nth 2 where-list))
5926 (idlwave-force-class-query (equal arg '(4)))
5927 (completion-regexp-list
5928 (if (equal arg '(16))
5929 (list (read-string (concat "Completion Regexp: "))))))
5931 (if (and module (string-match "::" module))
5932 (setq class (substring module 0 (match-beginning 0))
5933 module (substring module (match-end 0))))
5935 (cond
5937 ((and (null arg)
5938 (eq (car-safe last-command) 'idlwave-display-completion-list)
5939 (get-buffer-window "*Completions*"))
5940 (setq this-command last-command)
5941 (idlwave-scroll-completions))
5943 ;; Complete a filename in quotes
5944 ((and (idlwave-in-quote)
5945 (not (eq what 'class)))
5946 (idlwave-complete-filename))
5948 ;; Check for any special completion functions
5949 ((and idlwave-complete-special
5950 (idlwave-call-special idlwave-complete-special)))
5952 ((null what)
5953 (error "Nothing to complete here"))
5955 ;; Complete a class
5956 ((eq what 'class)
5957 (setq idlwave-completion-help-info '(class))
5958 (idlwave-complete-class))
5960 ((eq what 'procedure)
5961 ;; Complete a procedure name
5962 (let* ((cw-list (nth 3 where-list))
5963 (class-selector (idlwave-determine-class cw-list 'pro))
5964 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5965 (idlwave-all-class-inherits class-selector)))
5966 (isa (concat "procedure" (if class-selector "-method" "")))
5967 (type-selector 'pro))
5968 (setq idlwave-completion-help-info
5969 (list 'routine nil type-selector class-selector nil super-classes))
5970 (idlwave-complete-in-buffer
5971 'procedure (if class-selector 'method 'routine)
5972 (idlwave-routines) 'idlwave-selector
5973 (format "Select a %s name%s"
5975 (if class-selector
5976 (format " (class is %s)"
5977 (if (eq class-selector t)
5978 "unknown" class-selector))
5979 ""))
5981 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5983 ((eq what 'function)
5984 ;; Complete a function name
5985 (let* ((cw-list (nth 3 where-list))
5986 (class-selector (idlwave-determine-class cw-list 'fun))
5987 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5988 (idlwave-all-class-inherits class-selector)))
5989 (isa (concat "function" (if class-selector "-method" "")))
5990 (type-selector 'fun))
5991 (setq idlwave-completion-help-info
5992 (list 'routine nil type-selector class-selector nil super-classes))
5993 (idlwave-complete-in-buffer
5994 'function (if class-selector 'method 'routine)
5995 (idlwave-routines) 'idlwave-selector
5996 (format "Select a %s name%s"
5998 (if class-selector
5999 (format " (class is %s)"
6000 (if (eq class-selector t)
6001 "unknown" class-selector))
6002 ""))
6004 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
6006 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
6007 (equal arg '(4)))
6008 (idlwave-complete 3))
6010 ((eq what 'procedure-keyword)
6011 ;; Complete a procedure keyword
6012 (let* ((where (nth 3 where-list))
6013 (name (car where))
6014 (method-selector name)
6015 (type-selector 'pro)
6016 (class (idlwave-determine-class where 'pro))
6017 (class-selector class)
6018 (super-classes (idlwave-all-class-inherits class-selector))
6019 (isa (format "procedure%s-keyword" (if class "-method" "")))
6020 (entry (idlwave-best-rinfo-assq
6021 name 'pro class (idlwave-routines)))
6022 (system (if entry (eq (car (nth 3 entry)) 'system)))
6023 (list (idlwave-entry-keywords entry 'do-link)))
6024 (unless (or entry (eq class t))
6025 (error "Nothing known about procedure %s"
6026 (idlwave-make-full-name class name)))
6027 (setq list (idlwave-fix-keywords name 'pro class list
6028 super-classes system))
6029 (unless list (error "No keywords available for procedure %s"
6030 (idlwave-make-full-name class name)))
6031 (setq idlwave-completion-help-info
6032 (list 'keyword name type-selector class-selector entry super-classes))
6033 (idlwave-complete-in-buffer
6034 'keyword 'keyword list nil
6035 (format "Select keyword for procedure %s%s"
6036 (idlwave-make-full-name class name)
6037 (if (or (member '("_EXTRA") list)
6038 (member '("_REF_EXTRA") list))
6039 " (note _EXTRA)" ""))
6041 'idlwave-attach-keyword-classes)))
6043 ((eq what 'function-keyword)
6044 ;; Complete a function keyword
6045 (let* ((where (nth 3 where-list))
6046 (name (car where))
6047 (method-selector name)
6048 (type-selector 'fun)
6049 (class (idlwave-determine-class where 'fun))
6050 (class-selector class)
6051 (super-classes (idlwave-all-class-inherits class-selector))
6052 (isa (format "function%s-keyword" (if class "-method" "")))
6053 (entry (idlwave-best-rinfo-assq
6054 name 'fun class (idlwave-routines)))
6055 (system (if entry (eq (car (nth 3 entry)) 'system)))
6056 (list (idlwave-entry-keywords entry 'do-link))
6057 msg-name)
6058 (unless (or entry (eq class t))
6059 (error "Nothing known about function %s"
6060 (idlwave-make-full-name class name)))
6061 (setq list (idlwave-fix-keywords name 'fun class list
6062 super-classes system))
6063 ;; OBJ_NEW: Messages mention the proper Init method
6064 (setq msg-name (if (and (null class)
6065 (string= (upcase name) "OBJ_NEW"))
6066 (concat idlwave-current-obj_new-class
6067 "::Init (via OBJ_NEW)")
6068 (idlwave-make-full-name class name)))
6069 (unless list (error "No keywords available for function %s"
6070 msg-name))
6071 (setq idlwave-completion-help-info
6072 (list 'keyword name type-selector class-selector nil super-classes))
6073 (idlwave-complete-in-buffer
6074 'keyword 'keyword list nil
6075 (format "Select keyword for function %s%s" msg-name
6076 (if (or (member '("_EXTRA") list)
6077 (member '("_REF_EXTRA") list))
6078 " (note _EXTRA)" ""))
6080 'idlwave-attach-keyword-classes)))
6082 (t (error "This should not happen (idlwave-complete)")))))
6084 (defvar idlwave-complete-special nil
6085 "List of special completion functions.
6086 These functions are called for each completion. Each function must
6087 check if its own special completion context is present. If yes, it
6088 should use `idlwave-complete-in-buffer' to do some completion and
6089 return t. If such a function returns t, *no further* attempts to
6090 complete other contexts will be done. If the function returns nil,
6091 other completions will be tried.")
6093 (defun idlwave-call-special (functions &rest args)
6094 (let ((funcs functions)
6095 fun ret)
6096 (catch 'exit
6097 (while (setq fun (pop funcs))
6098 (if (setq ret (apply fun args))
6099 (throw 'exit ret)))
6100 nil)))
6102 (defun idlwave-make-force-complete-where-list (what &optional module class)
6103 ;; Return an artificial WHERE specification to force the completion
6104 ;; routine to complete a specific item independent of context.
6105 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6106 ;; MODULE and CLASS can be used to specify the routine name and class.
6107 ;; The class name will also be found in MODULE if that is like "class::mod".
6108 (let* ((what-list '(("procedure") ("procedure-keyword")
6109 ("function") ("function-keyword")
6110 ("procedure-method") ("procedure-method-keyword")
6111 ("function-method") ("function-method-keyword")
6112 ("class")))
6113 (module (idlwave-sintern-routine-or-method module class))
6114 (class (idlwave-sintern-class class))
6115 (what (cond
6116 ((equal what 0)
6117 (setq what
6118 (intern (completing-read
6119 "Complete what? " what-list nil t))))
6120 ((integerp what)
6121 (setq what (intern (car (nth (1- what) what-list)))))
6122 ((and what
6123 (symbolp what)
6124 (assoc (symbol-name what) what-list))
6125 what)
6126 (t (error "Invalid WHAT"))))
6127 (nil-list '(nil nil nil nil))
6128 (class-list (list nil nil (or class t) nil)))
6130 (cond
6132 ((eq what 'procedure)
6133 (list nil-list nil-list 'procedure nil-list nil))
6135 ((eq what 'procedure-keyword)
6136 (let* ((class-selector nil)
6137 (super-classes nil)
6138 (type-selector 'pro)
6139 (pro (or module
6140 (idlwave-completing-read
6141 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6142 (setq pro (idlwave-sintern-routine pro))
6143 (list nil-list nil-list 'procedure-keyword
6144 (list pro nil nil nil) nil)))
6146 ((eq what 'function)
6147 (list nil-list nil-list 'function nil-list nil))
6149 ((eq what 'function-keyword)
6150 (let* ((class-selector nil)
6151 (super-classes nil)
6152 (type-selector 'fun)
6153 (func (or module
6154 (idlwave-completing-read
6155 "Function: " (idlwave-routines) 'idlwave-selector))))
6156 (setq func (idlwave-sintern-routine func))
6157 (list nil-list nil-list 'function-keyword
6158 (list func nil nil nil) nil)))
6160 ((eq what 'procedure-method)
6161 (list nil-list nil-list 'procedure class-list nil))
6163 ((eq what 'procedure-method-keyword)
6164 (let* ((class (idlwave-determine-class class-list 'pro))
6165 (class-selector class)
6166 (super-classes (idlwave-all-class-inherits class-selector))
6167 (type-selector 'pro)
6168 (pro (or module
6169 (idlwave-completing-read
6170 (format "Procedure in %s class: " class-selector)
6171 (idlwave-routines) 'idlwave-selector))))
6172 (setq pro (idlwave-sintern-method pro))
6173 (list nil-list nil-list 'procedure-keyword
6174 (list pro nil class nil) nil)))
6176 ((eq what 'function-method)
6177 (list nil-list nil-list 'function class-list nil))
6179 ((eq what 'function-method-keyword)
6180 (let* ((class (idlwave-determine-class class-list 'fun))
6181 (class-selector class)
6182 (super-classes (idlwave-all-class-inherits class-selector))
6183 (type-selector 'fun)
6184 (func (or module
6185 (idlwave-completing-read
6186 (format "Function in %s class: " class-selector)
6187 (idlwave-routines) 'idlwave-selector))))
6188 (setq func (idlwave-sintern-method func))
6189 (list nil-list nil-list 'function-keyword
6190 (list func nil class nil) nil)))
6192 ((eq what 'class)
6193 (list nil-list nil-list 'class nil-list nil))
6195 (t (error "Invalid value for WHAT")))))
6197 (defun idlwave-completing-read (&rest args)
6198 ;; Completing read, case insensitive
6199 (let ((old-value (default-value 'completion-ignore-case)))
6200 (unwind-protect
6201 (progn
6202 (setq-default completion-ignore-case t)
6203 (apply 'completing-read args))
6204 (setq-default completion-ignore-case old-value))))
6206 (defvar idlwave-shell-default-directory)
6207 (defun idlwave-complete-filename ()
6208 "Use the comint stuff to complete a file name."
6209 (require 'comint)
6210 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6211 (comint-completion-addsuffix nil)
6212 (default-directory
6213 (if (and (boundp 'idlwave-shell-default-directory)
6214 (stringp idlwave-shell-default-directory)
6215 (file-directory-p idlwave-shell-default-directory))
6216 idlwave-shell-default-directory
6217 default-directory)))
6218 (comint-dynamic-complete-filename)))
6220 (defun idlwave-make-full-name (class name)
6221 ;; Make a fully qualified module name including the class name
6222 (concat (if class (format "%s::" class) "") name))
6224 (defun idlwave-rinfo-assoc (name type class list)
6225 "Like `idlwave-rinfo-assq', but sintern strings first."
6226 (idlwave-rinfo-assq
6227 (idlwave-sintern-routine-or-method name class)
6228 type (idlwave-sintern-class class) list))
6230 (defun idlwave-rinfo-assq (name type class list)
6231 ;; Works like assq, but also checks type and class
6232 (catch 'exit
6233 (let (match)
6234 (while (setq match (assq name list))
6235 (and (or (eq type t)
6236 (eq (nth 1 match) type))
6237 (eq (nth 2 match) class)
6238 (throw 'exit match))
6239 (setq list (cdr (memq match list)))))))
6241 (defun idlwave-rinfo-assq-any-class (name type class list)
6242 ;; Return the first matching method on the inheritance list
6243 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6244 class rtn)
6245 (while classes
6246 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6247 (setq classes nil)))
6248 rtn))
6250 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
6251 keep-system)
6252 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6253 If WITH-FILE is passed, find the best rinfo entry with a file
6254 included. If KEEP-SYSTEM is set, don't prune system for compiled
6255 syslib files."
6256 (let ((twins (idlwave-routine-twins
6257 (idlwave-rinfo-assq-any-class name type class list)
6258 list))
6259 syslibp)
6260 (when (> (length twins) 1)
6261 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
6262 (if (and (null keep-system)
6263 (eq 'system (car (nth 3 (car twins))))
6264 (setq syslibp (idlwave-any-syslib (cdr twins)))
6265 (not (equal 1 syslibp)))
6266 ;; Its a compiled syslib, so we need to remove the system entry
6267 (setq twins (cdr twins)))
6268 (if with-file
6269 (setq twins (delq nil
6270 (mapcar (lambda (x)
6271 (if (nth 1 (nth 3 x)) x))
6272 twins)))))
6273 (car twins)))
6275 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
6276 keep-system)
6277 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6278 (idlwave-best-rinfo-assq
6279 (idlwave-sintern-routine-or-method name class)
6280 type (idlwave-sintern-class class) list with-file keep-system))
6282 (defun idlwave-any-syslib (entries)
6283 "Does the entry list ENTRIES contain a syslib entry?
6284 If yes, return the index (>=1)."
6285 (let (file (cnt 0))
6286 (catch 'exit
6287 (while entries
6288 (incf cnt)
6289 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6290 (if (and file (idlwave-syslib-p file))
6291 (throw 'exit cnt)
6292 (setq entries (cdr entries))))
6293 nil)))
6295 (defun idlwave-all-assq (key list)
6296 "Return a list of all associations of Key in LIST."
6297 (let (rtn elt)
6298 (while (setq elt (assq key list))
6299 (push elt rtn)
6300 (setq list (cdr (memq elt list))))
6301 (nreverse rtn)))
6303 (defun idlwave-all-method-classes (method &optional type)
6304 "Return all classes which have a method METHOD.
6305 TYPE is 'fun or 'pro.
6306 When TYPE is not specified, both procedures and functions will be considered."
6307 (if (null method)
6308 (mapcar 'car (idlwave-class-alist))
6309 (let (rtn)
6310 (mapc (lambda (x)
6311 (and (nth 2 x)
6312 (or (not type)
6313 (eq type (nth 1 x)))
6314 (push (nth 2 x) rtn)))
6315 (idlwave-all-assq method (idlwave-routines)))
6316 (idlwave-uniquify rtn))))
6318 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
6319 "Return all classes which have a method METHOD with keyword KEYWORD.
6320 TYPE is 'fun or 'pro.
6321 When TYPE is not specified, both procedures and functions will be considered."
6322 (if (or (null method)
6323 (null keyword))
6325 (let (rtn)
6326 (mapc (lambda (x)
6327 (and (nth 2 x) ; non-nil class
6328 (or (not type) ; correct or unspecified type
6329 (eq type (nth 1 x)))
6330 (assoc keyword (idlwave-entry-keywords x))
6331 (push (nth 2 x) rtn)))
6332 (idlwave-all-assq method (idlwave-routines)))
6333 (idlwave-uniquify rtn))))
6335 (defun idlwave-members-only (list club)
6336 "Return list of all elements in LIST which are also in CLUB."
6337 (let (rtn)
6338 (while list
6339 (if (member (car list) club)
6340 (setq rtn (cons (car list) rtn)))
6341 (setq list (cdr list)))
6342 (nreverse rtn)))
6344 (defun idlwave-nonmembers-only (list club)
6345 "Return list of all elements in LIST which are not in CLUB."
6346 (let (rtn)
6347 (while list
6348 (if (member (car list) club)
6350 (setq rtn (cons (car list) rtn)))
6351 (setq list (cdr list)))
6352 (nreverse rtn)))
6354 (defun idlwave-explicit-class-listed (info)
6355 "Return whether or not the class is listed explicitly, ala a->b::c.
6356 INFO is as returned by `idlwave-what-function' or `-procedure'."
6357 (let ((apos (nth 3 info)))
6358 (if apos
6359 (save-excursion (goto-char apos)
6360 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6362 (defvar idlwave-determine-class-special nil
6363 "List of special functions for determining class.
6364 Must accept two arguments: `apos' and `info'.")
6366 (defun idlwave-determine-class (info type)
6367 ;; Determine the class of a routine call.
6368 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6369 ;; The second element in this structure is the class. When nil, we
6370 ;; return nil. When t, try to get the class from text properties at
6371 ;; the arrow. When the object is "self", we use the class of the
6372 ;; current routine. otherwise prompt the user for a class name.
6373 ;; Also stores the selected class as a text property at the arrow.
6374 ;; TYPE is 'fun or 'pro.
6375 (let* ((class (nth 2 info))
6376 (apos (nth 3 info))
6377 (nassoc (assoc (if (stringp (car info))
6378 (upcase (car info))
6379 (car info))
6380 idlwave-query-class))
6381 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6382 idlwave-query-class))
6383 (query (cond (nassoc (cdr nassoc))
6384 (dassoc (cdr dassoc))
6385 (t t)))
6386 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
6387 (is-self
6388 (and arrow
6389 (save-excursion (goto-char apos)
6390 (forward-word -1)
6391 (let ((case-fold-search t))
6392 (looking-at "self\\>")))))
6393 (force-query idlwave-force-class-query)
6394 store special-class class-alist)
6395 (cond
6396 ((null class) nil)
6397 ((eq t class)
6398 ;; There is an object which would like to know its class
6399 (if (and arrow (get-text-property apos 'idlwave-class)
6400 idlwave-store-inquired-class
6401 (not force-query))
6402 (setq class (get-text-property apos 'idlwave-class)
6403 class (idlwave-sintern-class class)))
6404 (if (and (eq t class) is-self)
6405 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6407 ;; Before prompting, try any special class determination routines
6408 (when (and (eq t class)
6409 idlwave-determine-class-special
6410 (not force-query))
6411 (setq special-class
6412 (idlwave-call-special idlwave-determine-class-special apos))
6413 (if special-class
6414 (setq class (idlwave-sintern-class special-class)
6415 store idlwave-store-inquired-class)))
6417 ;; Prompt for a class, if we need to
6418 (when (and (eq class t)
6419 (or force-query query))
6420 (setq class-alist
6421 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6422 (setq class
6423 (idlwave-sintern-class
6424 (cond
6425 ((and (= (length class-alist) 0) (not force-query))
6426 (error "No classes available with method %s" (car info)))
6427 ((and (= (length class-alist) 1) (not force-query))
6428 (car (car class-alist)))
6430 (setq store idlwave-store-inquired-class)
6431 (idlwave-completing-read
6432 (format "Class%s: " (if (stringp (car info))
6433 (format " for %s method %s"
6434 type (car info))
6435 ""))
6436 class-alist nil nil nil 'idlwave-class-history))))))
6438 ;; Store it, if requested
6439 (when (and class (not (eq t class)))
6440 ;; We have a real class here
6441 (when (and store arrow)
6442 (condition-case ()
6443 (add-text-properties
6444 apos (+ apos 2)
6445 `(idlwave-class ,class face ,idlwave-class-arrow-face
6446 rear-nonsticky t))
6447 (error nil)))
6448 (setf (nth 2 info) class))
6449 ;; Return the class
6450 class)
6451 ;; Default as fallback
6452 (t class))))
6454 (defun idlwave-selector (a)
6455 (and (eq (nth 1 a) type-selector)
6456 (or (and (nth 2 a) (eq class-selector t))
6457 (eq (nth 2 a) class-selector)
6458 (memq (nth 2 a) super-classes))))
6460 (defun idlwave-add-file-link-selector (a)
6461 ;; Record a file link, if any, for the tested names during selection.
6462 (let ((sel (idlwave-selector a)) file)
6463 (if (and sel (setq file (idlwave-entry-has-help a)))
6464 (push (cons (car a) file) idlwave-completion-help-links))
6465 sel))
6468 (defun idlwave-where ()
6469 "Find out where we are.
6470 The return value is a list with the following stuff:
6471 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6473 PRO-LIST (PRO POINT CLASS ARROW)
6474 FUNC-LIST (FUNC POINT CLASS ARROW)
6475 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6476 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6477 be completed here.
6478 LAST-CHAR last relevant character before point (non-white non-comment,
6479 not part of current identifier or leading slash).
6481 In the lists, we have these meanings:
6482 PRO: Procedure name
6483 FUNC: Function name
6484 POINT: Where is this
6485 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6486 ARROW: Location of the arrow"
6487 (idlwave-routines)
6488 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6489 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
6490 (func-entry (idlwave-what-function bos))
6491 (func (car func-entry))
6492 (func-class (nth 1 func-entry))
6493 (func-arrow (nth 2 func-entry))
6494 (func-point (or (nth 3 func-entry) 0))
6495 (func-level (or (nth 4 func-entry) 0))
6496 (pro-entry (idlwave-what-procedure bos))
6497 (pro (car pro-entry))
6498 (pro-class (nth 1 pro-entry))
6499 (pro-arrow (nth 2 pro-entry))
6500 (pro-point (or (nth 3 pro-entry) 0))
6501 (last-char (idlwave-last-valid-char))
6502 (case-fold-search t)
6503 (match-string (buffer-substring bos (point)))
6504 cw cw-mod cw-arrow cw-class cw-point)
6505 (if (< func-point pro-point) (setq func nil))
6506 (cond
6507 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6508 match-string)
6509 (setq cw 'class))
6510 ((string-match
6511 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6512 (if (> pro-point 0)
6513 (buffer-substring pro-point (point))
6514 match-string))
6515 (setq cw 'procedure cw-class pro-class cw-point pro-point
6516 cw-arrow pro-arrow))
6517 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6518 match-string)
6519 nil)
6520 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6521 match-string)
6522 (setq cw 'class))
6523 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6524 match-string)
6525 (setq cw 'class))
6526 ((and func
6527 (> func-point pro-point)
6528 (= func-level 1)
6529 (memq last-char '(?\( ?,)))
6530 (setq cw 'function-keyword cw-mod func cw-point func-point
6531 cw-class func-class cw-arrow func-arrow))
6532 ((and pro (eq last-char ?,))
6533 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6534 cw-class pro-class cw-arrow pro-arrow))
6535 ; ((member last-char '(?\' ?\) ?\] ?!))
6536 ; ;; after these chars, a function makes no sense
6537 ; ;; FIXME: I am sure there can be more in this list
6538 ; ;; FIXME: Do we want to do this at all?
6539 ; nil)
6540 ;; Everywhere else we try a function.
6542 (setq cw 'function)
6543 (save-excursion
6544 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6545 (setq cw-arrow (copy-marker (match-beginning 0))
6546 cw-class (if (match-end 4)
6547 (idlwave-sintern-class (match-string 4))
6548 t))))))
6549 (list (list pro pro-point pro-class pro-arrow)
6550 (list func func-point func-class func-arrow)
6552 (list cw-mod cw-point cw-class cw-arrow)
6553 last-char)))
6555 (defun idlwave-this-word (&optional class)
6556 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6557 (setq class (or class "a-zA-Z0-9$_."))
6558 (save-excursion
6559 (buffer-substring
6560 (progn (skip-chars-backward class) (point))
6561 (progn (skip-chars-forward class) (point)))))
6563 (defun idlwave-what-function (&optional bound)
6564 ;; Find out if point is within the argument list of a function.
6565 ;; The return value is ("function-name" class arrow-start (point) level).
6566 ;; Level is 1 on the top level parentheses, higher further down.
6568 ;; If the optional BOUND is an integer, bound backwards directed
6569 ;; searches to this point.
6571 (catch 'exit
6572 (let (pos
6573 func-point
6574 (cnt 0)
6575 func arrow-start class)
6576 (idlwave-with-special-syntax
6577 (save-restriction
6578 (save-excursion
6579 (narrow-to-region (max 1 (or bound 0)) (point-max))
6580 ;; move back out of the current parenthesis
6581 (while (condition-case nil
6582 (progn (up-list -1) t)
6583 (error nil))
6584 (setq pos (point))
6585 (incf cnt)
6586 (when (and (= (following-char) ?\()
6587 (re-search-backward
6588 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6589 bound t))
6590 (setq func (match-string 2)
6591 func-point (goto-char (match-beginning 2))
6592 pos func-point)
6593 (if (re-search-backward
6594 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6595 (setq arrow-start (copy-marker (match-beginning 0))
6596 class (or (match-string 2) t)))
6597 (throw
6598 'exit
6599 (list
6600 (idlwave-sintern-routine-or-method func class)
6601 (idlwave-sintern-class class)
6602 arrow-start func-point cnt)))
6603 (goto-char pos))
6604 (throw 'exit nil)))))))
6606 (defun idlwave-what-procedure (&optional bound)
6607 ;; Find out if point is within the argument list of a procedure.
6608 ;; The return value is ("procedure-name" class arrow-pos (point)).
6610 ;; If the optional BOUND is an integer, bound backwards directed
6611 ;; searches to this point.
6612 (let ((pos (point)) pro-point
6613 pro class arrow-start string)
6614 (save-excursion
6615 ;;(idlwave-beginning-of-statement)
6616 (idlwave-start-of-substatement 'pre)
6617 (setq string (buffer-substring (point) pos))
6618 (if (string-match
6619 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6620 (setq pro (match-string 1 string)
6621 pro-point (+ (point) (match-beginning 1)))
6622 (if (and (idlwave-skip-object)
6623 (setq string (buffer-substring (point) pos))
6624 (string-match
6625 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6626 string))
6627 (setq pro (if (match-beginning 4)
6628 (match-string 4 string))
6629 pro-point (if (match-beginning 4)
6630 (+ (point) (match-beginning 4))
6631 pos)
6632 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6633 class (or (match-string 3 string) t)))))
6634 (list (idlwave-sintern-routine-or-method pro class)
6635 (idlwave-sintern-class class)
6636 arrow-start
6637 pro-point)))
6639 (defun idlwave-skip-object ()
6640 ;; If there is an object at point, move over it and return t.
6641 (let ((pos (point)))
6642 (if (catch 'exit
6643 (save-excursion
6644 (skip-chars-forward " ") ; white space
6645 (skip-chars-forward "*") ; de-reference
6646 (cond
6647 ((looking-at idlwave-identifier)
6648 (goto-char (match-end 0)))
6649 ((eq (following-char) ?\()
6650 nil)
6651 (t (throw 'exit nil)))
6652 (catch 'endwhile
6653 (while t
6654 (cond ((eq (following-char) ?.)
6655 (forward-char 1)
6656 (if (not (looking-at idlwave-identifier))
6657 (throw 'exit nil))
6658 (goto-char (match-end 0)))
6659 ((memq (following-char) '(?\( ?\[))
6660 (condition-case nil
6661 (forward-list 1)
6662 (error (throw 'exit nil))))
6663 (t (throw 'endwhile t)))))
6664 (if (looking-at "[ \t]*->")
6665 (throw 'exit (setq pos (match-beginning 0)))
6666 (throw 'exit nil))))
6667 (goto-char pos)
6668 nil)))
6670 (defun idlwave-last-valid-char ()
6671 "Return the last character before point which is not white or a comment
6672 and also not part of the current identifier. Since we do this in
6673 order to identify places where keywords are, we consider the initial
6674 `/' of a keyword as part of the identifier.
6675 This function is not general, can only be used for completion stuff."
6676 (catch 'exit
6677 (save-excursion
6678 ;; skip the current identifier
6679 (skip-chars-backward "a-zA-Z0-9_$")
6680 ;; also skip a leading slash which might be belong to the keyword
6681 (if (eq (preceding-char) ?/)
6682 (backward-char 1))
6683 ;; FIXME: does not check if this is a valid identifier
6684 (while t
6685 (skip-chars-backward " \t")
6686 (cond
6687 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6688 ((eq (preceding-char) ?\n)
6689 (beginning-of-line 0)
6690 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6691 ;; continuation line
6692 (goto-char (match-end 1))
6693 (throw 'exit nil)))
6694 (t (throw 'exit (preceding-char))))))))
6696 (defvar idlwave-complete-after-success-form nil
6697 "A form to evaluate after successful completion.")
6698 (defvar idlwave-complete-after-success-form-force nil
6699 "A form to evaluate after completion selection in *Completions* buffer.")
6700 (defconst idlwave-completion-mark (make-marker)
6701 "A mark pointing to the beginning of the completion string.")
6702 (defvar completion-highlight-first-word-only) ;XEmacs.
6704 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6705 &optional prepare-display-function
6706 special-selector)
6707 "Perform TYPE completion of word before point against LIST.
6708 SELECTOR is the PREDICATE argument for the completion function. Show
6709 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6710 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
6711 used only once, for `all-completions', and can be used to, e.g.,
6712 accumulate information on matching completions."
6713 (let* ((completion-ignore-case t)
6714 beg (end (point)) slash part spart completion all-completions
6715 dpart dcompletion)
6717 (unless list
6718 (error (concat prompt ": No completions available")))
6720 ;; What is already in the buffer?
6721 (save-excursion
6722 (skip-chars-backward "a-zA-Z0-9_$")
6723 (setq slash (eq (preceding-char) ?/)
6724 beg (point)
6725 idlwave-complete-after-success-form
6726 (list 'idlwave-after-successful-completion
6727 (list 'quote type) slash beg)
6728 idlwave-complete-after-success-form-force
6729 (list 'idlwave-after-successful-completion
6730 (list 'quote type) slash (list 'quote 'force))))
6732 ;; Try a completion
6733 (setq part (buffer-substring beg end)
6734 dpart (downcase part)
6735 spart (idlwave-sintern stype part)
6736 completion (try-completion part list selector)
6737 dcompletion (if (stringp completion) (downcase completion))
6738 idlwave-completion-help-links nil)
6739 (cond
6740 ((null completion)
6741 ;; nothing available.
6742 (error (concat prompt ": no completion for \"%s\"") part))
6743 ((and (not (equal dpart dcompletion))
6744 (not (eq t completion)))
6745 ;; We can add something
6746 (delete-region beg end)
6747 (insert (if (and (string= part dpart)
6748 (or (not (string= part ""))
6749 idlwave-complete-empty-string-as-lower-case)
6750 (not idlwave-completion-force-default-case))
6751 dcompletion
6752 completion))
6753 (if (eq t (try-completion completion list selector))
6754 ;; Now this is a unique match
6755 (idlwave-after-successful-completion type slash beg))
6757 ((or (eq completion t)
6758 (and (= 1 (length (setq all-completions
6759 (idlwave-uniquify
6760 (all-completions part list
6761 (or special-selector
6762 selector))))))
6763 (equal dpart dcompletion)))
6764 ;; This is already complete
6765 (idlwave-after-successful-completion type slash beg)
6766 (message "%s is already the complete %s" part isa)
6767 nil)
6769 ;; We cannot add something - offer a list.
6770 (message "Making completion list...")
6772 (unless idlwave-completion-help-links ; already set somewhere?
6773 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6774 (let ((link (get-text-property 0 'link (car x))))
6775 (if link
6776 (push (cons (car x) link)
6777 idlwave-completion-help-links))))
6778 list))
6779 (let* ((list all-completions)
6780 ;; "complete" means, this is already a valid completion
6781 (complete (memq spart all-completions))
6782 (completion-highlight-first-word-only t)) ; XEmacs
6783 ;; (completion-fixup-function ; Emacs
6784 ;; (lambda () (and (eq (preceding-char) ?>)
6785 ;; (re-search-backward " <" beg t)))))
6787 (setq list (sort list (lambda (a b)
6788 (string< (downcase a) (downcase b)))))
6789 (if prepare-display-function
6790 (setq list (funcall prepare-display-function list)))
6791 (if (and (string= part dpart)
6792 (or (not (string= part ""))
6793 idlwave-complete-empty-string-as-lower-case)
6794 (not idlwave-completion-force-default-case))
6795 (setq list (mapcar (lambda (x)
6796 (if (listp x)
6797 (setcar x (downcase (car x)))
6798 (setq x (downcase x)))
6800 list)))
6801 (idlwave-display-completion-list list prompt beg complete))
6802 t))))
6804 (defun idlwave-complete-class ()
6805 "Complete a class at point."
6806 (interactive)
6807 ;; Call `idlwave-routines' to make sure the class list will be available
6808 (idlwave-routines)
6809 ;; Check for the special case of completing empty string after pro/function
6810 (if (let ((case-fold-search t))
6811 (save-excursion
6812 (and
6813 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6814 (- (point) 15) t)
6815 (goto-char (point-min))
6816 (re-search-forward
6817 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6818 ;; Yank the full class specification
6819 (insert (match-string 2))
6820 ;; Do the completion, using list gathered from `idlwave-routines'
6821 (idlwave-complete-in-buffer
6822 'class 'class (idlwave-class-alist) nil
6823 "Select a class" "class"
6824 (lambda (list) ;; Push it to help-links if system help available
6825 (mapcar (lambda (x)
6826 (let* ((entry (idlwave-class-info x))
6827 (link (nth 1 (assq 'link entry))))
6828 (if link (push (cons x link)
6829 idlwave-completion-help-links))
6831 list)))))
6833 (defun idlwave-attach-classes (list type show-classes)
6834 ;; Attach the proper class list to a LIST of completion items.
6835 ;; TYPE, when 'kwd, shows classes for method keywords, when
6836 ;; 'class-tag, for class tags, and otherwise for methods.
6837 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6838 (if (or (null show-classes) ; don't want to see classes
6839 (null class-selector) ; not a method call
6840 (and
6841 (stringp class-selector) ; the class is already known
6842 (not super-classes))) ; no possibilities for inheritance
6843 ;; In these cases, we do not have to do anything
6844 list
6845 (let* ((do-prop (and (>= show-classes 0)
6846 (>= emacs-major-version 21)))
6847 (do-buf (not (= show-classes 0)))
6848 ;; (do-dots (featurep 'xemacs))
6849 (do-dots t)
6850 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6851 (cons class-selector super-classes)))
6852 (max (abs show-classes))
6853 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6854 classes nclasses class-info space)
6855 (mapcar
6856 (lambda (x)
6857 ;; get the classes
6858 (if (eq type 'class-tag)
6859 ;; Just one class for tags
6860 (setq classes
6861 (list
6862 (idlwave-class-or-superclass-with-tag class-selector x)))
6863 ;; Multiple classes for method or method-keyword
6864 (setq classes
6865 (if (eq type 'kwd)
6866 (idlwave-all-method-keyword-classes
6867 method-selector x type-selector)
6868 (idlwave-all-method-classes x type-selector)))
6869 (if inherit
6870 (setq classes
6871 (delq nil
6872 (mapcar (lambda (x) (if (memq x inherit) x nil))
6873 classes)))))
6874 (setq nclasses (length classes))
6875 ;; Make the separator between item and class-info
6876 (if do-dots
6877 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6878 (setq space " "))
6879 (if do-buf
6880 ;; We do want info in the buffer
6881 (if (<= nclasses max)
6882 (setq class-info (concat
6883 space
6884 "<" (mapconcat 'identity classes ",") ">"))
6885 (setq class-info (format "%s<%d classes>" space nclasses)))
6886 (setq class-info nil))
6887 (when do-prop
6888 ;; We do want properties
6889 (setq x (copy-sequence x))
6890 (put-text-property 0 (length x)
6891 'help-echo (mapconcat 'identity classes " ")
6893 (if class-info
6894 (list x class-info)
6896 list))))
6898 (defun idlwave-attach-method-classes (list)
6899 ;; Call idlwave-attach-classes with method parameters
6900 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6901 (defun idlwave-attach-keyword-classes (list)
6902 ;; Call idlwave-attach-classes with keyword parameters
6903 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6904 (defun idlwave-attach-class-tag-classes (list)
6905 ;; Call idlwave-attach-classes with class structure tags
6906 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6909 ;;----------------------------------------------------------------------
6910 ;;----------------------------------------------------------------------
6911 ;;----------------------------------------------------------------------
6912 ;;----------------------------------------------------------------------
6913 ;;----------------------------------------------------------------------
6914 (defvar rtn)
6915 (defun idlwave-pset (item)
6916 (set 'rtn item))
6918 (defun idlwave-popup-select (ev list title &optional sort)
6919 "Select an item in LIST with a popup menu.
6920 TITLE is the title to put atop the popup. If SORT is non-nil,
6921 sort the list before displaying."
6922 (let ((maxpopup idlwave-max-popup-menu-items)
6923 rtn menu)
6924 (cond ((null list))
6925 ((= 1 (length list))
6926 (setq rtn (car list)))
6927 ((featurep 'xemacs)
6928 (if sort (setq list (sort list (lambda (a b)
6929 (string< (upcase a) (upcase b))))))
6930 (setq menu
6931 (append (list title)
6932 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6933 x)))
6934 list)))
6935 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6936 (let ((resp (get-popup-menu-response menu)))
6937 (funcall (event-function resp) (event-object resp))))
6939 (if sort (setq list (sort list (lambda (a b)
6940 (string< (upcase a) (upcase b))))))
6941 (setq menu (cons title
6942 (list
6943 (append (list "")
6944 (mapcar (lambda(x) (cons x x)) list)))))
6945 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6946 (setq rtn (x-popup-menu ev menu))))
6947 rtn))
6949 (defun idlwave-split-menu-xemacs (menu N)
6950 "Split the MENU into submenus of maximum length N."
6951 (if (<= (length menu) (1+ N))
6952 ;; No splitting needed
6953 menu
6954 (let* ((title (car menu))
6955 (entries (cdr menu))
6956 (menu (list title))
6957 (cnt 0)
6958 (nextmenu nil))
6959 (while entries
6960 (while (and entries (< cnt N))
6961 (setq cnt (1+ cnt)
6962 nextmenu (cons (car entries) nextmenu)
6963 entries (cdr entries)))
6964 (setq nextmenu (nreverse nextmenu))
6965 (setq nextmenu (cons (format "%s...%s"
6966 (aref (car nextmenu) 0)
6967 (aref (nth (1- cnt) nextmenu) 0))
6968 nextmenu))
6969 (setq menu (cons nextmenu menu)
6970 nextmenu nil
6971 cnt 0))
6972 (nreverse menu))))
6974 (defun idlwave-split-menu-emacs (menu N)
6975 "Split the MENU into submenus of maximum length N."
6976 (if (<= (length (nth 1 menu)) (1+ N))
6977 ;; No splitting needed
6978 menu
6979 (let* ((title (car menu))
6980 (entries (cdr (nth 1 menu)))
6981 (menu nil)
6982 (cnt 0)
6983 (nextmenu nil))
6984 (while entries
6985 (while (and entries (< cnt N))
6986 (setq cnt (1+ cnt)
6987 nextmenu (cons (car entries) nextmenu)
6988 entries (cdr entries)))
6989 (setq nextmenu (nreverse nextmenu))
6990 (prin1 nextmenu)
6991 (setq nextmenu (cons (format "%s...%s"
6992 (car (car nextmenu))
6993 (car (nth (1- cnt) nextmenu)))
6994 nextmenu))
6995 (setq menu (cons nextmenu menu)
6996 nextmenu nil
6997 cnt 0))
6998 (setq menu (nreverse menu))
6999 (setq menu (cons title menu))
7000 menu)))
7002 (defvar idlwave-completion-setup-hook nil)
7004 (defun idlwave-scroll-completions (&optional message)
7005 "Scroll the completion window on this frame."
7006 (let ((cwin (get-buffer-window "*Completions*" 'visible))
7007 (win (selected-window)))
7008 (unwind-protect
7009 (progn
7010 (select-window cwin)
7011 (condition-case nil
7012 (scroll-up)
7013 (error (if (and (listp last-command)
7014 (nth 2 last-command))
7015 (progn
7016 (select-window win)
7017 (eval idlwave-complete-after-success-form))
7018 (set-window-start cwin (point-min)))))
7019 (and message (message "%s" message)))
7020 (select-window win))))
7022 (defun idlwave-display-completion-list (list &optional message beg complete)
7023 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7024 (unless (and (get-buffer-window "*Completions*")
7025 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
7026 (move-marker idlwave-completion-mark beg)
7027 (setq idlwave-before-completion-wconf (current-window-configuration)))
7029 (if (featurep 'xemacs)
7030 (idlwave-display-completion-list-xemacs
7031 list)
7032 (idlwave-display-completion-list-emacs list))
7034 ;; Store a special value in `this-command'. When `idlwave-complete'
7035 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7036 (setq this-command (list 'idlwave-display-completion-list message complete))
7038 ;; Mark the completions buffer as created by cib
7039 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
7041 ;; Fontify the classes
7042 (if (and idlwave-completion-fontify-classes
7043 (consp (car list)))
7044 (idlwave-completion-fontify-classes))
7046 ;; Run the hook
7047 (run-hooks 'idlwave-completion-setup-hook)
7049 ;; Display the message
7050 (message "%s" (or message "Making completion list...done")))
7052 (defun idlwave-choose (function &rest args)
7053 "Call FUNCTION as a completion chooser and pass ARGS to it."
7054 (let ((completion-ignore-case t)) ; install correct value
7055 (apply function args))
7056 (if (and (eq major-mode 'idlwave-shell-mode)
7057 (boundp 'font-lock-mode)
7058 (not font-lock-mode))
7059 ;; For the shell, remove the fontification of the word before point
7060 (let ((beg (save-excursion
7061 (skip-chars-backward "a-zA-Z0-9_")
7062 (point))))
7063 (remove-text-properties beg (point) '(face nil))))
7064 (eval idlwave-complete-after-success-form-force))
7066 (defun idlwave-keyboard-quit ()
7067 (interactive)
7068 (unwind-protect
7069 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7070 (idlwave-restore-wconf-after-completion))
7071 (keyboard-quit)))
7073 (defun idlwave-restore-wconf-after-completion ()
7074 "Restore the old (before completion) window configuration."
7075 (and idlwave-completion-restore-window-configuration
7076 idlwave-before-completion-wconf
7077 (set-window-configuration idlwave-before-completion-wconf)))
7079 (defun idlwave-one-key-select (sym prompt delay)
7080 "Make the user select an element from the alist in the variable SYM.
7081 The keys of the alist are expected to be strings. The function returns the
7082 car of the selected association.
7083 To do this, PROMPT is displayed and the user must hit a letter key to
7084 select an entry. If the user does not reply within DELAY seconds, a help
7085 window with the options is displayed automatically.
7086 The key which is associated with each option is generated automatically.
7087 First, the strings are checked for preselected keys, like in \"[P]rint\".
7088 If these don't exist, a letter in the string is automatically selected."
7089 (let* ((alist (symbol-value sym))
7090 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7091 '(fit-window-to-buffer)))
7092 keys-alist char)
7093 ;; First check the cache
7094 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7095 (setq keys-alist (get sym :one-key-alist-cache))
7096 ;; Need to make new list
7097 (setq keys-alist (idlwave-make-one-key-alist alist))
7098 (put sym :one-key-alist-cache keys-alist)
7099 (put sym :one-key-alist-last alist))
7100 ;; Display prompt and wait for quick reply
7101 (message "%s[%s]" prompt
7102 (mapconcat (lambda(x) (char-to-string (car x)))
7103 keys-alist ""))
7104 (if (sit-for delay)
7105 ;; No quick reply: Show help
7106 (save-window-excursion
7107 (with-output-to-temp-buffer "*Completions*"
7108 (mapcar (lambda(x)
7109 (princ (nth 1 x))
7110 (princ "\n"))
7111 keys-alist))
7112 (setq char (read-char)))
7113 (setq char (read-char)))
7114 (message nil)
7115 ;; Return the selected result
7116 (nth 2 (assoc char keys-alist))))
7118 ;; Used for, e.g., electric debug super-examine.
7119 (defun idlwave-make-one-key-alist (alist)
7120 "Make an alist for single key selection."
7121 (let ((l alist) keys-alist name start char help
7122 (cnt 0)
7123 (case-fold-search nil))
7124 (while l
7125 (setq name (car (car l))
7126 l (cdr l))
7127 (catch 'exit
7128 ;; First check if the configuration predetermined a key
7129 (if (string-match "\\[\\(.\\)\\]" name)
7130 (progn
7131 (setq char (string-to-char (downcase (match-string 1 name)))
7132 help (format "%c: %s" char name)
7133 keys-alist (cons (list char help name) keys-alist))
7134 (throw 'exit t)))
7135 ;; Then check for capital letters
7136 (setq start 0)
7137 (while (string-match "[A-Z]" name start)
7138 (setq start (match-end 0)
7139 char (string-to-char (downcase (match-string 0 name))))
7140 (if (not (assoc char keys-alist))
7141 (progn
7142 (setq help (format "%c: %s" char
7143 (replace-match
7144 (concat "[" (match-string 0 name) "]")
7145 t t name))
7146 keys-alist (cons (list char help name) keys-alist))
7147 (throw 'exit t))))
7148 ;; Now check for lowercase letters
7149 (setq start 0)
7150 (while (string-match "[a-z]" name start)
7151 (setq start (match-end 0)
7152 char (string-to-char (match-string 0 name)))
7153 (if (not (assoc char keys-alist))
7154 (progn
7155 (setq help (format "%c: %s" char
7156 (replace-match
7157 (concat "[" (match-string 0 name) "]")
7158 t t name))
7159 keys-alist (cons (list char help name) keys-alist))
7160 (throw 'exit t))))
7161 ;; Bummer, nothing found! Use a stupid number
7162 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7163 help (format "%c: %s" char name)
7164 keys-alist (cons (list char help name) keys-alist))))
7165 (nreverse keys-alist)))
7167 (defun idlwave-set-local (var value &optional buffer)
7168 "Set the buffer-local value of VAR in BUFFER to VALUE."
7169 (with-current-buffer (or buffer (current-buffer))
7170 (set (make-local-variable var) value)))
7172 (defun idlwave-local-value (var &optional buffer)
7173 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7174 (with-current-buffer (or buffer (current-buffer))
7175 (and (local-variable-p var (current-buffer))
7176 (symbol-value var))))
7178 ;; In XEmacs, we can use :activate-callback directly to advice the
7179 ;; choose functions. We use the private keymap only for the online
7180 ;; help feature.
7182 (defvar idlwave-completion-map nil
7183 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7185 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
7186 (with-output-to-temp-buffer "*Completions*"
7187 (apply 'display-completion-list list
7188 ':activate-callback 'idlwave-default-choose-completion
7189 cl-args))
7190 (with-current-buffer "*Completions*"
7191 (use-local-map
7192 (or idlwave-completion-map
7193 (setq idlwave-completion-map
7194 (idlwave-make-modified-completion-map-xemacs
7195 (current-local-map)))))))
7197 (defun idlwave-default-choose-completion (&rest args)
7198 "Execute `default-choose-completion' and then restore the win-conf."
7199 (apply 'idlwave-choose 'default-choose-completion args))
7201 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7202 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7203 (let ((new-map (copy-keymap old-map)))
7204 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7205 (define-key new-map [button3] (lambda ()
7206 (interactive)
7207 (setq this-command last-command)))
7208 new-map))
7210 ;; In Emacs we also replace keybindings in the completion
7211 ;; map in order to install our wrappers.
7213 (defun idlwave-display-completion-list-emacs (list)
7214 "Display completion list and install the choose wrappers."
7215 (with-output-to-temp-buffer "*Completions*"
7216 (display-completion-list list))
7217 (with-current-buffer "*Completions*"
7218 (use-local-map
7219 (or idlwave-completion-map
7220 (setq idlwave-completion-map
7221 (idlwave-make-modified-completion-map-emacs
7222 (current-local-map)))))))
7224 (defun idlwave-make-modified-completion-map-emacs (old-map)
7225 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7226 (let ((new-map (copy-keymap old-map)))
7227 (substitute-key-definition
7228 'choose-completion 'idlwave-choose-completion new-map)
7229 (substitute-key-definition
7230 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7231 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7232 new-map))
7234 (defun idlwave-choose-completion (&rest args)
7235 "Choose the completion that point is in or next to."
7236 (interactive)
7237 (apply 'idlwave-choose 'choose-completion args))
7239 (defun idlwave-mouse-choose-completion (&rest args)
7240 "Click on an alternative in the `*Completions*' buffer to choose it."
7241 (interactive "e")
7242 (apply 'idlwave-choose 'mouse-choose-completion args))
7244 ;;----------------------------------------------------------------------
7245 ;;----------------------------------------------------------------------
7247 ;;; ------------------------------------------------------------------------
7248 ;;; Stucture parsing code, and code to manage class info
7251 ;; - Go again over the documentation how to write a completion
7252 ;; plugin. It is in self.el, but currently still very bad.
7253 ;; This could be in a separate file in the distribution, or
7254 ;; in an appendix for the manual.
7256 (defvar idlwave-struct-skip
7257 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7258 "Regexp for skipping continued blank or comment-only lines in structures.")
7260 (defvar idlwave-struct-tag-regexp
7261 (concat "[{,]" ;leading comma/brace
7262 idlwave-struct-skip ; 4 groups
7263 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7264 "[ \t]*:") ; the final colon
7265 "Regexp for structure tags.")
7267 (defun idlwave-struct-tags ()
7268 "Return a list of all tags in the structure defined at point.
7269 Point is expected just before the opening `{' of the struct definition."
7270 (save-excursion
7271 (let* ((borders (idlwave-struct-borders))
7272 (beg (car borders))
7273 (end (cdr borders))
7274 tags)
7275 (goto-char beg)
7276 (save-restriction
7277 (narrow-to-region beg end)
7278 (while (re-search-forward idlwave-struct-tag-regexp end t)
7279 ;; Check if we are still on the top level of the structure.
7280 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7281 (= (point) beg))
7282 (push (match-string-no-properties 5) tags))
7283 (goto-char (match-end 0))))
7284 (nreverse tags))))
7286 (defun idlwave-find-struct-tag (tag)
7287 "Find a given TAG in the structure defined at point."
7288 (let* ((borders (idlwave-struct-borders))
7289 (end (cdr borders))
7290 (case-fold-search t))
7291 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7292 end t)))
7294 (defun idlwave-struct-inherits ()
7295 "Return a list of all `inherits' names in the struct at point.
7296 Point is expected just before the opening `{' of the struct definition."
7297 (save-excursion
7298 (let* ((borders (idlwave-struct-borders))
7299 (beg (car borders))
7300 (end (cdr borders))
7301 (case-fold-search t)
7302 names)
7303 (goto-char beg)
7304 (save-restriction
7305 (narrow-to-region beg end)
7306 (while (re-search-forward
7307 (concat "[{,]" ;leading comma/brace
7308 idlwave-struct-skip ; 4 groups
7309 "inherits" ; The INHERITS tag
7310 idlwave-struct-skip ; 4 more
7311 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7312 end t)
7313 ;; Check if we are still on the top level of the structure.
7314 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7315 (= (point) beg))
7316 (push (match-string-no-properties 9) names))
7317 (goto-char (match-end 0))))
7318 (nreverse names))))
7320 (defun idlwave-in-structure ()
7321 "Return t if point is inside an IDL structure definition."
7322 (let ((beg (point)))
7323 (save-excursion
7324 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7325 (if (idlwave-find-structure-definition nil nil 'back)
7326 (let ((borders (idlwave-struct-borders)))
7327 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7328 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7330 (defun idlwave-struct-borders ()
7331 "Return the borders of the {...} after point as a cons cell."
7332 (let (beg)
7333 (save-excursion
7334 (skip-chars-forward "^{")
7335 (setq beg (point))
7336 (condition-case nil (forward-list 1)
7337 (error (goto-char beg)))
7338 (cons beg (point)))))
7340 (defun idlwave-find-structure-definition (&optional var name bound)
7341 "Search forward for a structure definition.
7342 If VAR is non-nil, search for a structure assigned to variable VAR.
7343 If NAME is non-nil, search for a named structure NAME, if a string,
7344 or a generic named structure otherwise. If BOUND is an integer, limit
7345 the search. If BOUND is the symbol `all', we search first back and
7346 then forward through the entire file. If BOUND is the symbol `back'
7347 we search only backward."
7348 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7349 (case-fold-search t)
7350 (lim (if (integerp bound) bound nil))
7351 (re (concat
7352 (if var
7353 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7354 "\\(\\)")
7355 "=" ws "\\({\\)"
7356 (if name
7357 (if (stringp name)
7358 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7359 ;; Just a generic name
7360 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7361 ""))))
7362 (if (or (and (or (eq bound 'all) (eq bound 'back))
7363 (re-search-backward re nil t))
7364 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7365 (progn
7366 (goto-char (match-beginning 3))
7367 (match-string-no-properties 5)))))
7369 (defvar idlwave-class-info nil)
7370 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7372 (add-hook 'idlwave-update-rinfo-hook
7373 (lambda () (setq idlwave-class-reset t)))
7374 (add-hook 'idlwave-after-load-rinfo-hook
7375 (lambda () (setq idlwave-class-info nil)))
7377 (defun idlwave-class-info (class)
7378 (let (list entry)
7379 (if idlwave-class-info
7380 (if idlwave-class-reset
7381 (setq
7382 idlwave-class-reset nil
7383 idlwave-class-info ; Remove any visited in a buffer
7384 (delq nil (mapcar
7385 (lambda (x)
7386 (let ((filebuf
7387 (idlwave-class-file-or-buffer
7388 (or (cdr (assq 'found-in x)) (car x)))))
7389 (if (cdr filebuf)
7391 x)))
7392 idlwave-class-info))))
7393 ;; Info is nil, put in the system stuff to start.
7394 (setq idlwave-class-info idlwave-system-class-info)
7395 (setq list idlwave-class-info)
7396 (while (setq entry (pop list))
7397 (idlwave-sintern-class-info entry)))
7398 (setq class (idlwave-sintern-class class))
7399 (or (assq class idlwave-class-info)
7400 (progn (idlwave-scan-class-info class)
7401 (assq class idlwave-class-info)))))
7403 (defun idlwave-sintern-class-info (entry)
7404 "Sintern the class names in a class-info entry."
7405 (let ((inherits (assq 'inherits entry)))
7406 (setcar entry (idlwave-sintern-class (car entry) 'set))
7407 (if inherits
7408 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7409 (cdr inherits))))))
7411 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7412 "Find class structure definition(s).
7413 If ALL-HOOK is set, find all named structure definitions in a given
7414 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7415 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7416 class/struct definition."
7417 (let ((case-fold-search t) end-lim name)
7418 (when (re-search-forward
7419 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7420 (if all-hook
7421 (progn
7422 ;; For everything there
7423 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7424 (while (setq name
7425 (idlwave-find-structure-definition nil t end-lim))
7426 (funcall all-hook name)))
7427 (idlwave-find-structure-definition nil (or alt-class class))))))
7430 (defun idlwave-class-file-or-buffer (class)
7431 "Find buffer visiting CLASS definition."
7432 (let* ((pro (concat (downcase class) "__define"))
7433 (file (idlwave-routine-source-file
7434 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7435 (idlwave-routines))))))
7436 (cons file (if file (idlwave-get-buffer-visiting file)))))
7439 (defun idlwave-scan-class-info (class)
7440 "Scan all class and named structure info in the class__define pro."
7441 (let* ((idlwave-auto-routine-info-updates nil)
7442 (filebuf (idlwave-class-file-or-buffer class))
7443 (file (car filebuf))
7444 (buf (cdr filebuf))
7445 (class (idlwave-sintern-class class)))
7446 (if (or
7447 (not file)
7448 (and ;; neither a regular file nor a visited buffer
7449 (not buf)
7450 (not (file-regular-p file))))
7451 nil ; Cannot find the file/buffer to get any info
7452 (save-excursion
7453 (if buf (set-buffer buf)
7454 ;; Read the file in temporarily
7455 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7456 (erase-buffer)
7457 (unless (eq major-mode 'idlwave-mode)
7458 (idlwave-mode))
7459 (insert-file-contents file))
7460 (save-excursion
7461 (goto-char 1)
7462 (idlwave-find-class-definition class
7463 ;; Scan all of the structures found there
7464 (lambda (name)
7465 (let* ((this-class (idlwave-sintern-class name))
7466 (entry
7467 (list this-class
7468 (cons 'tags (idlwave-struct-tags))
7469 (cons 'inherits (idlwave-struct-inherits)))))
7470 (if (not (eq this-class class))
7471 (setq entry (nconc entry (list (cons 'found-in class)))))
7472 (idlwave-sintern-class-info entry)
7473 (push entry idlwave-class-info)))))))))
7475 (defun idlwave-class-found-in (class)
7476 "Return the FOUND-IN property of the CLASS."
7477 (cdr (assq 'found-in (idlwave-class-info class))))
7478 (defun idlwave-class-tags (class)
7479 "Return the native tags in CLASS."
7480 (cdr (assq 'tags (idlwave-class-info class))))
7481 (defun idlwave-class-inherits (class)
7482 "Return the direct superclasses of CLASS."
7483 (cdr (assq 'inherits (idlwave-class-info class))))
7486 (defun idlwave-all-class-tags (class)
7487 "Return a list of native and inherited tags in CLASS."
7488 (condition-case err
7489 (apply 'append (mapcar 'idlwave-class-tags
7490 (cons class (idlwave-all-class-inherits class))))
7491 (error
7492 (idlwave-class-tag-reset)
7493 (error "%s" (error-message-string err)))))
7496 (defun idlwave-all-class-inherits (class)
7497 "Return a list of all superclasses of CLASS (recursively expanded).
7498 The list is cached in `idlwave-class-info' for faster access."
7499 (cond
7500 ((not idlwave-support-inheritance) nil)
7501 ((eq class nil) nil)
7502 ((eq class t) nil)
7504 (let ((info (idlwave-class-info class))
7505 entry)
7506 (if (setq entry (assq 'all-inherits info))
7507 (cdr entry)
7508 ;; Save the depth of inheritance scan to check for circular references
7509 (let ((inherits (mapcar (lambda (x) (cons x 0))
7510 (idlwave-class-inherits class)))
7511 rtn all-inherits cl)
7512 (while inherits
7513 (setq cl (pop inherits)
7514 rtn (cons (car cl) rtn)
7515 inherits (append (mapcar (lambda (x)
7516 (cons x (1+ (cdr cl))))
7517 (idlwave-class-inherits (car cl)))
7518 inherits))
7519 (if (> (cdr cl) 999)
7520 (error
7521 "Class scan: inheritance depth exceeded. Circular inheritance?")
7523 (setq all-inherits (nreverse rtn))
7524 (nconc info (list (cons 'all-inherits all-inherits)))
7525 all-inherits))))))
7527 (defun idlwave-entry-keywords (entry &optional record-link)
7528 "Return the flat entry keywords alist from routine-info entry.
7529 If RECORD-LINK is non-nil, the keyword text is copied and a text
7530 property indicating the link is added."
7531 (let (kwds)
7532 (mapc
7533 (lambda (key-list)
7534 (let ((file (car key-list)))
7535 (mapcar (lambda (key-cons)
7536 (let ((key (car key-cons))
7537 (link (cdr key-cons)))
7538 (when (and record-link file)
7539 (setq key (copy-sequence key))
7540 (put-text-property
7541 0 (length key)
7542 'link
7543 (concat
7544 file
7545 (if link
7546 (concat idlwave-html-link-sep
7547 (number-to-string link))))
7548 key))
7549 (push (list key) kwds)))
7550 (cdr key-list))))
7551 (nthcdr 5 entry))
7552 (nreverse kwds)))
7554 (defun idlwave-entry-find-keyword (entry keyword)
7555 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7556 (catch 'exit
7557 (mapc
7558 (lambda (key-list)
7559 (let ((file (car key-list))
7560 (kwd (assoc keyword (cdr key-list))))
7561 (when kwd
7562 (setq kwd (cons (car kwd)
7563 (if (and file (cdr kwd))
7564 (concat file
7565 idlwave-html-link-sep
7566 (number-to-string (cdr kwd)))
7567 (cdr kwd))))
7568 (throw 'exit kwd))))
7569 (nthcdr 5 entry))))
7571 ;;==========================================================================
7573 ;; Completing class structure tags. This is a completion plugin.
7574 ;; The necessary taglist is constructed dynamically
7576 (defvar idlwave-current-tags-class nil)
7577 (defvar idlwave-current-class-tags nil)
7578 (defvar idlwave-current-native-class-tags nil)
7579 (defvar idlwave-sint-class-tags nil)
7580 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7581 (idlwave-new-sintern-type 'class-tag)
7582 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7583 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7585 (defun idlwave-complete-class-structure-tag ()
7586 "Complete a structure tag on a `self' argument in an object method."
7587 (interactive)
7588 (let ((pos (point))
7589 (case-fold-search t))
7590 (if (save-excursion
7591 ;; Check if the context is right
7592 (skip-chars-backward "a-zA-Z0-9._$")
7593 (and (< (point) (- pos 4))
7594 (looking-at "self\\.")))
7595 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7596 (super-classes (idlwave-all-class-inherits class-selector)))
7597 ;; Check if we are in a class routine
7598 (unless class-selector
7599 (error "Not in a method procedure or function"))
7600 ;; Check if we need to update the "current" class
7601 (if (not (equal class-selector idlwave-current-tags-class))
7602 (idlwave-prepare-class-tag-completion class-selector))
7603 (setq idlwave-completion-help-info
7604 (list 'idlwave-complete-class-structure-tag-help
7605 (idlwave-sintern-routine
7606 (concat class-selector "__define"))
7607 nil))
7608 ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
7609 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7610 (idlwave-complete-in-buffer
7611 'class-tag 'class-tag
7612 idlwave-current-class-tags nil
7613 (format "Select a tag of class %s" class-selector)
7614 "class tag"
7615 'idlwave-attach-class-tag-classes))
7616 t) ; return t to skip other completions
7617 nil)))
7619 (defun idlwave-class-tag-reset ()
7620 (setq idlwave-current-tags-class nil))
7622 (defun idlwave-prepare-class-tag-completion (class)
7623 "Find and parse the necessary class definitions for class structure tags."
7624 (setq idlwave-sint-class-tags nil)
7625 (setq idlwave-current-tags-class class)
7626 (setq idlwave-current-class-tags
7627 (mapcar (lambda (x)
7628 (list (idlwave-sintern-class-tag x 'set)))
7629 (idlwave-all-class-tags class)))
7630 (setq idlwave-current-native-class-tags
7631 (mapcar 'downcase (idlwave-class-tags class))))
7633 ;===========================================================================
7635 ;; Completing system variables and their structure fields
7636 ;; This is also a plugin.
7638 (defvar idlwave-sint-sysvars nil)
7639 (defvar idlwave-sint-sysvartags nil)
7640 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7641 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7642 (idlwave-new-sintern-type 'sysvar)
7643 (idlwave-new-sintern-type 'sysvartag)
7644 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7645 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7646 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7649 (defun idlwave-complete-sysvar-or-tag ()
7650 "Complete a system variable."
7651 (interactive)
7652 (let ((pos (point))
7653 (case-fold-search t))
7654 (cond ((save-excursion
7655 ;; Check if the context is right for system variable
7656 (skip-chars-backward "[a-zA-Z0-9_$]")
7657 (equal (char-before) ?!))
7658 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7659 (idlwave-complete-in-buffer 'sysvar 'sysvar
7660 idlwave-system-variables-alist nil
7661 "Select a system variable"
7662 "system variable")
7663 t) ; return t to skip other completions
7664 ((save-excursion
7665 ;; Check if the context is right for sysvar tag
7666 (skip-chars-backward "a-zA-Z0-9_$.")
7667 (and (equal (char-before) ?!)
7668 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7669 (<= (match-end 0) pos)))
7670 ;; Complete a system variable tag
7671 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7672 (entry (assq var idlwave-system-variables-alist))
7673 (tags (cdr (assq 'tags entry))))
7674 (or entry (error "!%s is not a known system variable" var))
7675 (or tags (error "System variable !%s is not a structure" var))
7676 (setq idlwave-completion-help-info
7677 (list 'idlwave-complete-sysvar-tag-help var))
7678 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7679 tags nil
7680 "Select a system variable tag"
7681 "system variable tag")
7682 t)) ; return t to skip other completions
7683 (t nil))))
7685 (defvar link) ;dynamic variables set by help callback
7686 (defvar props)
7687 (defun idlwave-complete-sysvar-help (mode word)
7688 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7689 (entry (assoc word idlwave-system-variables-alist)))
7690 (cond
7691 ((eq mode 'test)
7692 (and (stringp word) entry (nth 1 (assq 'link entry))))
7693 ((eq mode 'set)
7694 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7695 (t (error "This should not happen")))))
7697 (defun idlwave-complete-sysvar-tag-help (mode word)
7698 (let* ((var (nth 1 idlwave-completion-help-info))
7699 (entry (assoc var idlwave-system-variables-alist))
7700 (tags (cdr (assq 'tags entry)))
7701 (main (nth 1 (assq 'link entry)))
7702 target)
7703 (cond
7704 ((eq mode 'test) ; we can at least link the main
7705 (and (stringp word) entry main))
7706 ((eq mode 'set)
7707 (if entry
7708 (setq link
7709 (if (setq target (cdr (assoc-string word tags t)))
7710 (idlwave-substitute-link-target main target)
7711 main)))) ;; setting dynamic!!!
7712 (t (error "This should not happen")))))
7714 (defun idlwave-split-link-target (link)
7715 "Split a given LINK into link file and anchor."
7716 (if (string-match idlwave-html-link-sep link)
7717 (cons (substring link 0 (match-beginning 0))
7718 (string-to-number (substring link (match-end 0))))))
7720 (defun idlwave-substitute-link-target (link target)
7721 "Substitute the TARGET anchor for the given LINK."
7722 (let (main-base)
7723 (setq main-base (if (string-match "#" link)
7724 (substring link 0 (match-beginning 0))
7725 link))
7726 (if target
7727 (concat main-base idlwave-html-link-sep (number-to-string target))
7728 link)))
7730 ;; Fake help in the source buffer for class structure tags.
7731 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7732 (defvar name)
7733 (defvar kwd)
7734 (defvar idlwave-help-do-class-struct-tag nil)
7735 (defun idlwave-complete-class-structure-tag-help (mode word)
7736 (cond
7737 ((eq mode 'test) ; nothing gets fontified for class tags
7738 nil)
7739 ((eq mode 'set)
7740 (let (class-with found-in)
7741 (when (setq class-with
7742 (idlwave-class-or-superclass-with-tag
7743 idlwave-current-tags-class
7744 word))
7745 (if (assq (idlwave-sintern-class class-with)
7746 idlwave-system-class-info)
7747 (error "No help available for system class tags"))
7748 (if (setq found-in (idlwave-class-found-in class-with))
7749 (setq name (cons (concat found-in "__define") class-with))
7750 (setq name (concat class-with "__define")))))
7751 (setq kwd word
7752 idlwave-help-do-class-struct-tag t))
7753 (t (error "This should not happen"))))
7755 (defun idlwave-class-or-superclass-with-tag (class tag)
7756 "Find and return the CLASS or one of its superclass with the
7757 associated TAG, if any."
7758 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7760 (catch 'exit
7761 (while sclasses
7762 (setq cl (pop sclasses))
7763 (let ((tags (idlwave-class-tags cl)))
7764 (while tags
7765 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7766 (throw 'exit cl))
7767 (setq tags (cdr tags))))))))
7770 (defun idlwave-sysvars-reset ()
7771 (if (and (fboundp 'idlwave-shell-is-running)
7772 (idlwave-shell-is-running)
7773 idlwave-idlwave_routine_info-compiled)
7774 (idlwave-shell-send-command "idlwave_get_sysvars"
7775 'idlwave-process-sysvars 'hide)))
7777 (defun idlwave-process-sysvars ()
7778 (idlwave-shell-filter-sysvars)
7779 (setq idlwave-sint-sysvars nil
7780 idlwave-sint-sysvartags nil)
7781 (idlwave-sintern-sysvar-alist))
7783 (defun idlwave-sintern-sysvar-alist ()
7784 (let ((list idlwave-system-variables-alist) entry tags)
7785 (while (setq entry (pop list))
7786 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7787 (setq tags (assq 'tags entry))
7788 (if tags
7789 (setcdr tags
7790 (mapcar (lambda (x)
7791 (cons (idlwave-sintern-sysvartag (car x) 'set)
7792 (cdr x)))
7793 (cdr tags)))))))
7795 (defvar idlwave-shell-command-output)
7796 (defun idlwave-shell-filter-sysvars ()
7797 "Get any new system variables and tags."
7798 (let ((text idlwave-shell-command-output)
7799 (start 0)
7800 (old idlwave-system-variables-alist)
7801 var tags type name class link old-entry)
7802 (setq idlwave-system-variables-alist nil)
7803 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7804 text start)
7805 (setq start (match-end 0)
7806 var (match-string 1 text)
7807 tags (if (match-end 3)
7808 (idlwave-split-string (match-string 3 text))))
7809 ;; Maintain old links, if present
7810 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7811 (setq link (assq 'link old-entry))
7812 (setq idlwave-system-variables-alist
7813 (cons (list var
7814 (cons
7815 'tags
7816 (mapcar (lambda (x)
7817 (cons x
7818 (cdr (assq
7819 (idlwave-sintern-sysvartag x)
7820 (cdr (assq 'tags old-entry))))))
7821 tags)) link)
7822 idlwave-system-variables-alist)))
7823 ;; Keep the old value if query was not successful
7824 (setq idlwave-system-variables-alist
7825 (or idlwave-system-variables-alist old))))
7827 (defun idlwave-completion-fontify-classes ()
7828 "Goto the *Completions* buffer and fontify the class info."
7829 (when (featurep 'font-lock)
7830 (with-current-buffer "*Completions*"
7831 (save-excursion
7832 (goto-char (point-min))
7833 (let ((buffer-read-only nil))
7834 (while (re-search-forward "\\.*<[^>]+>" nil t)
7835 (put-text-property (match-beginning 0) (match-end 0)
7836 'face 'font-lock-string-face)))))))
7838 (defun idlwave-uniquify (list)
7839 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7840 (delq nil
7841 (mapcar (lambda (x)
7842 (unless (gethash x ht)
7843 (puthash x t ht)
7845 list))))
7847 (defun idlwave-after-successful-completion (type slash &optional verify)
7848 "Add `=' or `(' after successful completion of keyword and function.
7849 Restore the pre-completion window configuration if possible."
7850 (cond
7851 ((eq type 'procedure)
7852 nil)
7853 ((eq type 'function)
7854 (cond
7855 ((equal idlwave-function-completion-adds-paren nil) nil)
7856 ((or (equal idlwave-function-completion-adds-paren t)
7857 (equal idlwave-function-completion-adds-paren 1))
7858 (insert "("))
7859 ((equal idlwave-function-completion-adds-paren 2)
7860 (insert "()")
7861 (backward-char 1))
7862 (t nil)))
7863 ((eq type 'keyword)
7864 (if (and idlwave-keyword-completion-adds-equal
7865 (not slash))
7866 (progn (insert "=") t)
7867 nil)))
7869 ;; Restore the pre-completion window configuration if this is safe.
7871 (if (or (eq verify 'force) ; force
7872 (and
7873 (get-buffer-window "*Completions*") ; visible
7874 (idlwave-local-value 'idlwave-completion-p
7875 "*Completions*") ; cib-buffer
7876 (eq (marker-buffer idlwave-completion-mark)
7877 (current-buffer)) ; buffer OK
7878 (equal (marker-position idlwave-completion-mark)
7879 verify))) ; pos OK
7880 (idlwave-restore-wconf-after-completion))
7881 (move-marker idlwave-completion-mark nil)
7882 (setq idlwave-before-completion-wconf nil))
7884 (defun idlwave-mouse-context-help (ev &optional arg)
7885 "Call `idlwave-context-help' on the clicked location."
7886 (interactive "eP")
7887 (mouse-set-point ev)
7888 (idlwave-context-help arg))
7890 (defvar idlwave-last-context-help-pos nil)
7891 (defun idlwave-context-help (&optional arg)
7892 "Display IDL Online Help on context.
7893 If point is on a keyword, help for that keyword will be shown. If
7894 point is on a routine name or in the argument list of a routine, help
7895 for that routine will be displayed. Works for system routines and
7896 keywords, it pulls up text help. For other routies and keywords,
7897 visits the source file, finding help in the header (if
7898 `idlwave-help-source-try-header' is non-nil) or the routine definition
7899 itself."
7900 (interactive "P")
7901 (idlwave-do-context-help arg))
7903 (defun idlwave-mouse-completion-help (ev)
7904 "Display online help about the completion at point."
7905 (interactive "eP")
7906 ;; Restore last-command for next command, to make
7907 ;; scrolling/cancelling of completions work.
7908 (setq this-command last-command)
7909 (idlwave-do-mouse-completion-help ev))
7911 (defun idlwave-routine-info (&optional arg external)
7912 "Display a routines calling sequence and list of keywords.
7913 When point is on the name a function or procedure, or in the argument
7914 list of a function or procedure, this command displays a help buffer with
7915 the information. When called with prefix arg, enforce class query.
7917 When point is on an object operator `->', display the class stored in
7918 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7919 arg, the class property is cleared out."
7921 (interactive "P")
7922 (idlwave-routines)
7923 (if (string-match "->" (buffer-substring
7924 (max (point-min) (1- (point)))
7925 (min (+ 2 (point)) (point-max))))
7926 ;; Cursor is on an arrow
7927 (if (get-text-property (point) 'idlwave-class)
7928 ;; arrow has class property
7929 (if arg
7930 ;; Remove property
7931 (save-excursion
7932 (backward-char 1)
7933 (when (looking-at ".?\\(->\\)")
7934 (remove-text-properties (match-beginning 1) (match-end 1)
7935 '(idlwave-class nil face nil))
7936 (message "Class property removed from arrow")))
7937 ;; Echo class property
7938 (message "Arrow has text property identifying object to be class %s"
7939 (get-text-property (point) 'idlwave-class)))
7940 ;; No property found
7941 (message "Arrow has no class text property"))
7943 ;; Not on an arrow...
7944 (let* ((idlwave-query-class nil)
7945 (idlwave-force-class-query (equal arg '(4)))
7946 (module (idlwave-what-module)))
7947 (if (car module)
7948 (apply 'idlwave-display-calling-sequence
7949 (idlwave-fix-module-if-obj_new module))
7950 (error "Don't know which calling sequence to show")))))
7952 (defun idlwave-resolve (&optional arg)
7953 "Call RESOLVE_ROUTINE on the module name at point.
7954 Like `idlwave-routine-info', this looks for a routine call at point.
7955 After confirmation in the minibuffer, it will use the shell to issue
7956 a RESOLVE call for this routine, to attempt to make it defined and its
7957 routine info available for IDLWAVE. If the routine is a method call,
7958 both `class__method' and `class__define' will be tried.
7959 With ARG, enforce query for the class of object methods."
7960 (interactive "P")
7961 (let* ((idlwave-query-class nil)
7962 (idlwave-force-class-query (equal arg '(4)))
7963 (module (idlwave-what-module))
7964 (name (idlwave-make-full-name (nth 2 module) (car module)))
7965 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7966 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7967 (kwd "")
7968 class)
7969 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7970 resolve)
7971 (setq type (match-string 1 resolve)
7972 class (if (match-beginning 2)
7973 (match-string 3 resolve)
7974 nil)
7975 name (match-string 4 resolve)))
7976 (if (string= (downcase type) "function")
7977 (setq kwd ",/is_function"))
7979 (cond
7980 ((null class)
7981 (idlwave-shell-send-command
7982 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7983 'idlwave-update-routine-info
7984 nil t))
7986 (idlwave-shell-send-command
7987 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7988 (list 'idlwave-shell-send-command
7989 (format "resolve_routine,'%s__%s'%s"
7990 (downcase class) (downcase name) kwd)
7991 '(idlwave-update-routine-info)
7992 nil t))))))
7994 (defun idlwave-find-module-this-file ()
7995 (interactive)
7996 (idlwave-find-module '(4)))
7998 (defun idlwave-find-module (&optional arg)
7999 "Find the source code of an IDL module.
8000 Works for modules for which IDLWAVE has routine info available.
8001 The function offers as default the module name `idlwave-routine-info'
8002 would use. With ARG limit to this buffer. With two prefix ARG's
8003 force class query for object methods."
8004 (interactive "P")
8005 (let* ((idlwave-query-class nil)
8006 (idlwave-force-class-query (equal arg '(16)))
8007 (this-buffer (equal arg '(4)))
8008 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
8009 (default (if module
8010 (concat (idlwave-make-full-name
8011 (nth 2 module) (car module))
8012 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8013 "none"))
8014 (list
8015 (idlwave-uniquify
8016 (delq nil
8017 (mapcar (lambda (x)
8018 (if (eq 'system (car-safe (nth 3 x)))
8019 ;; Take out system routines with no source.
8021 (list
8022 (concat (idlwave-make-full-name
8023 (nth 2 x) (car x))
8024 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8025 (if this-buffer
8026 (idlwave-save-buffer-update)
8027 (idlwave-routines))))))
8028 (name (idlwave-completing-read
8029 (if (or (not this-buffer)
8030 (assoc default list))
8031 (format "Module (Default %s): " default)
8032 (format "Module in this file: "))
8033 list))
8034 type class)
8035 (if (string-match "\\`\\s-*\\'" name)
8036 ;; Nothing, use the default.
8037 (setq name default))
8038 (if (string-match "<[fp]>" name)
8039 (setq type (substring name -2 -1)
8040 name (substring name 0 -3)))
8041 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8042 (setq class (match-string 1 name)
8043 name (match-string 2 name)))
8044 (setq name (idlwave-sintern-routine-or-method name class)
8045 class (idlwave-sintern-class class)
8046 type (cond ((equal type "f") 'fun)
8047 ((equal type "p") 'pro)
8048 (t t)))
8049 (idlwave-do-find-module name type class nil this-buffer)))
8051 (defun idlwave-do-find-module (name type class
8052 &optional force-source this-buffer)
8053 (let ((name1 (idlwave-make-full-name class name))
8054 source buf1 entry
8055 (buf (current-buffer))
8056 (pos (point))
8057 file name2)
8058 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8059 'WITH-FILE)
8060 source (or force-source (nth 3 entry))
8061 name2 (if (nth 2 entry)
8062 (idlwave-make-full-name (nth 2 entry) name)
8063 name1))
8064 (if source
8065 (setq file (idlwave-routine-source-file source)))
8066 (unless file ; Try to find it on the path.
8067 (setq file
8068 (idlwave-expand-lib-file-name
8069 (if class
8070 (format "%s__define.pro" (downcase class))
8071 (format "%s.pro" (downcase name))))))
8072 (cond
8073 ((or (null name) (equal name ""))
8074 (error "Abort"))
8075 ((eq (car source) 'system)
8076 (error "Source code for system routine %s is not available"
8077 name2))
8078 ((or (not file) (not (file-regular-p file)))
8079 (error "Source code for routine %s is not available"
8080 name2))
8082 (when (not this-buffer)
8083 (setq buf1
8084 (idlwave-find-file-noselect file 'find))
8085 (pop-to-buffer buf1 t))
8086 (goto-char (point-max))
8087 (let ((case-fold-search t))
8088 (if (re-search-backward
8089 (concat "^[ \t]*\\<"
8090 (cond ((eq type 'fun) "function")
8091 ((eq type 'pro) "pro")
8092 (t "\\(pro\\|function\\)"))
8093 "\\>[ \t]+"
8094 (regexp-quote (downcase name2))
8095 "[^a-zA-Z0-9_$]")
8096 nil t)
8097 (goto-char (match-beginning 0))
8098 (pop-to-buffer buf)
8099 (goto-char pos)
8100 (error "Could not find routine %s" name2)))))))
8102 (defun idlwave-what-module ()
8103 "Return a default module for stuff near point.
8104 Used by `idlwave-routine-info' and `idlwave-find-module'."
8105 (idlwave-routines)
8106 (if (let ((case-fold-search t))
8107 (save-excursion
8108 (idlwave-beginning-of-statement)
8109 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8110 ;; This is a function or procedure definition statement
8111 ;; We return the defined routine as module.
8112 (list
8113 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8114 (match-string-no-properties 2))
8115 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8116 (idlwave-sintern-class (match-string 3)))
8118 ;; Not a definition statement - analyze precise position.
8119 (let* ((where (idlwave-where))
8120 (cw (nth 2 where))
8121 (pro (car (nth 0 where)))
8122 (func (car (nth 1 where)))
8123 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8124 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8125 (following-char)))
8127 (cond
8128 ((and (eq cw 'procedure)
8129 (not (equal this-word "")))
8130 (setq this-word (idlwave-sintern-routine-or-method
8131 this-word (nth 2 (nth 3 where))))
8132 (list this-word 'pro
8133 (idlwave-determine-class
8134 (cons this-word (cdr (nth 3 where)))
8135 'pro)))
8136 ((and (eq cw 'function)
8137 (not (equal this-word ""))
8138 (or (eq next-char ?\() ; exclude arrays, vars.
8139 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8140 (setq this-word (idlwave-sintern-routine-or-method
8141 this-word (nth 2 (nth 3 where))))
8142 (list this-word 'fun
8143 (idlwave-determine-class
8144 (cons this-word (cdr (nth 3 where)))
8145 'fun)))
8146 ((and (memq cw '(function-keyword procedure-keyword))
8147 (not (equal this-word ""))
8148 (eq next-char ?\()) ; A function!
8149 (setq this-word (idlwave-sintern-routine this-word))
8150 (list this-word 'fun nil))
8151 (func
8152 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8153 (pro
8154 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8155 (t nil)))))
8157 (defun idlwave-what-module-find-class ()
8158 "Call `idlwave-what-module' and find the inherited class if necessary."
8159 (let* ((module (idlwave-what-module))
8160 (class (nth 2 module)))
8161 (if (and (= (length module) 3)
8162 (stringp class))
8163 (list (car module)
8164 (nth 1 module)
8165 (apply 'idlwave-find-inherited-class module))
8166 module)))
8168 (defun idlwave-find-inherited-class (name type class)
8169 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8170 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8171 (if entry
8172 (nth 2 entry)
8173 class)))
8175 (defun idlwave-fix-module-if-obj_new (module)
8176 "Check if MODULE points to obj_new.
8177 If yes, and if the cursor is in the keyword region, change to the
8178 appropriate Init method."
8179 (let* ((name (car module))
8180 (pos (point))
8181 (case-fold-search t)
8182 string)
8183 (if (and (stringp name)
8184 (equal (downcase name) "obj_new")
8185 (save-excursion
8186 (idlwave-beginning-of-statement)
8187 (setq string (buffer-substring (point) pos))
8188 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8189 string)))
8190 (let ((name "Init")
8191 (class (match-string 1 string)))
8192 (setq module (list (idlwave-sintern-method "Init")
8193 'fun
8194 (idlwave-sintern-class class)))))
8195 module))
8197 (defun idlwave-fix-keywords (name type class keywords
8198 &optional super-classes system)
8199 "Update a list of keywords.
8200 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8201 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8202 demand _EXTRA in the keyword list."
8203 (let ((case-fold-search t))
8205 ;; If this is the OBJ_NEW function, try to figure out the class and use
8206 ;; the keywords from the corresponding INIT method.
8207 (if (and (equal (upcase name) "OBJ_NEW")
8208 (or (eq major-mode 'idlwave-mode)
8209 (eq major-mode 'idlwave-shell-mode)))
8210 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8211 (string (buffer-substring bos (point)))
8212 (case-fold-search t)
8213 class)
8214 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8215 string)
8216 (setq class (idlwave-sintern-class (match-string 1 string)))
8217 (setq idlwave-current-obj_new-class class)
8218 (setq keywords
8219 (append keywords
8220 (idlwave-entry-keywords
8221 (idlwave-rinfo-assq
8222 (idlwave-sintern-method "INIT")
8223 'fun
8224 class
8225 (idlwave-routines)) 'do-link))))))
8227 ;; If the class is `t', combine all keywords of all methods NAME
8228 (when (eq class t)
8229 (mapc (lambda (entry)
8230 (and
8231 (nth 2 entry) ; non-nil class
8232 (eq (nth 1 entry) type) ; correct type
8233 (setq keywords
8234 (append keywords
8235 (idlwave-entry-keywords entry 'do-link)))))
8236 (idlwave-all-assq name (idlwave-routines)))
8237 (setq keywords (idlwave-uniquify keywords)))
8239 ;; If we have inheritance, add all keywords from superclasses, if
8240 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8241 (when (and
8242 super-classes
8243 idlwave-keyword-class-inheritance
8244 (stringp class)
8246 system
8247 (assq (idlwave-sintern-keyword "_extra") keywords)
8248 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8249 ;; Check if one of the keyword-class regexps matches the name
8250 (let ((regexps idlwave-keyword-class-inheritance) re)
8251 (catch 'exit
8252 (while (setq re (pop regexps))
8253 (if (string-match re name) (throw 'exit t))))))
8255 (loop for entry in (idlwave-routines) do
8256 (and (nth 2 entry) ; non-nil class
8257 (memq (nth 2 entry) super-classes) ; an inherited class
8258 (eq (nth 1 entry) type) ; correct type
8259 (eq (car entry) name) ; correct name
8260 (mapc (lambda (k) (add-to-list 'keywords k))
8261 (idlwave-entry-keywords entry 'do-link))))
8262 (setq keywords (idlwave-uniquify keywords)))
8264 ;; Return the final list
8265 keywords))
8267 (defun idlwave-expand-keyword (keyword module)
8268 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8269 KEYWORD may be an exact match or an abbreviation of a keyword.
8270 If the match is exact, KEYWORD itself is returned, even if there may be other
8271 keywords of which KEYWORD is an abbreviation. This is necessary because some
8272 system routines have keywords which are prefixes of other keywords.
8273 If KEYWORD is an abbreviation of several keywords, a list of all possible
8274 completions is returned.
8275 If the abbreviation was unique, the correct keyword is returned.
8276 If it cannot be a keyword, the function return nil.
8277 If we do not know about MODULE, just return KEYWORD literally."
8278 (let* ((name (car module))
8279 (type (nth 1 module))
8280 (class (nth 2 module))
8281 (kwd (idlwave-sintern-keyword keyword))
8282 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8283 (kwd-alist (idlwave-entry-keywords entry))
8284 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8285 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8286 (completion-ignore-case t)
8287 candidates)
8288 (cond ((assq kwd kwd-alist)
8289 kwd)
8290 ((setq candidates (all-completions kwd kwd-alist))
8291 (if (= (length candidates) 1)
8292 (car candidates)
8293 candidates))
8294 ((and entry extra)
8295 ;; Inheritance may cause this keyword to be correct
8296 keyword)
8297 (entry
8298 ;; We do know the function, which does not have the keyword.
8299 nil)
8301 ;; We do not know the function, so this just might be a correct
8302 ;; keyword - return it as it is.
8303 keyword))))
8305 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8306 (defvar idlwave-rinfo-map (make-sparse-keymap))
8307 (define-key idlwave-rinfo-mouse-map
8308 (if (featurep 'xemacs) [button2] [mouse-2])
8309 'idlwave-mouse-active-rinfo)
8310 (define-key idlwave-rinfo-mouse-map
8311 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8312 'idlwave-mouse-active-rinfo-shift)
8313 (define-key idlwave-rinfo-mouse-map
8314 (if (featurep 'xemacs) [button3] [mouse-3])
8315 'idlwave-mouse-active-rinfo-right)
8316 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8317 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8318 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8319 (defvar idlwave-popup-source nil)
8320 (defvar idlwave-rinfo-marker (make-marker))
8322 (defun idlwave-quit-help ()
8323 (interactive)
8324 (let ((ri-window (get-buffer-window "*Help*"))
8325 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8326 (when (and olh-window
8327 (fboundp 'idlwave-help-quit))
8328 (select-window olh-window)
8329 (idlwave-help-quit))
8330 (when (window-live-p ri-window)
8331 (delete-window ri-window))))
8333 (defun idlwave-display-calling-sequence (name type class
8334 &optional initial-class)
8335 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8336 (let* ((initial-class (or initial-class class))
8337 (entry (or (idlwave-best-rinfo-assq name type class
8338 (idlwave-routines))
8339 (idlwave-rinfo-assq name type class
8340 idlwave-unresolved-routines)))
8341 (name (or (car entry) name))
8342 (class (or (nth 2 entry) class))
8343 (superclasses (idlwave-all-class-inherits initial-class))
8344 (twins (idlwave-routine-twins entry))
8345 (dtwins (idlwave-study-twins twins))
8346 (all dtwins)
8347 (system (eq (car (nth 3 entry)) 'system))
8348 (calling-seq (nth 4 entry))
8349 (keywords (idlwave-entry-keywords entry 'do-link))
8350 (html-file (car (nth 5 entry)))
8351 (help-echo-kwd
8352 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8353 (help-echo-use
8354 "Button2/3: Online Help")
8355 (help-echo-src
8356 "Button2: Jump to source and back | Button3: Source in Help window.")
8357 (help-echo-class
8358 "Button2: Display info about same method in superclass")
8359 (col 0)
8360 (data (list name type class (current-buffer) nil initial-class))
8361 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8362 (face 'idlwave-help-link)
8363 beg props win cnt total)
8364 ;; Fix keywords, but don't add chained super-classes, since these
8365 ;; are shown separately for that super-class
8366 (setq keywords (idlwave-fix-keywords name type class keywords))
8367 (cond
8368 ((null entry)
8369 (error "No %s %s known %s" type name
8370 (if initial-class (concat "in class " initial-class) "")))
8371 ((or (null name) (equal name ""))
8372 (error "No function or procedure call at point"))
8373 ((null calling-seq)
8374 (error "Calling sequence of %s %s not available" type name))
8376 (move-marker idlwave-rinfo-marker (point))
8377 (with-current-buffer (get-buffer-create "*Help*")
8378 (use-local-map idlwave-rinfo-map)
8379 (setq buffer-read-only nil)
8380 (erase-buffer)
8381 (set (make-local-variable 'idlwave-popup-source) nil)
8382 (set (make-local-variable 'idlwave-current-obj_new-class)
8383 idlwave-current-obj_new-class)
8384 (when superclasses
8385 (setq props (list 'mouse-face 'highlight
8386 km-prop idlwave-rinfo-mouse-map
8387 'help-echo help-echo-class
8388 'data (cons 'class data)))
8389 (let ((classes (cons initial-class superclasses)) c)
8390 (insert "Classes: ")
8391 (while (setq c (pop classes))
8392 (insert " ")
8393 (setq beg (point))
8394 (insert c)
8395 (if (equal (downcase c) (downcase class))
8396 (add-text-properties beg (point) (list 'face 'bold))
8397 ;; If Method exists in a different class link it
8398 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8399 (add-text-properties beg (point) props))))
8400 (insert "\n")))
8401 (setq props (list 'mouse-face 'highlight
8402 km-prop idlwave-rinfo-mouse-map
8403 'help-echo help-echo-use
8404 'data (cons 'usage data)))
8405 (if html-file (setq props (append (list 'face face 'link html-file)
8406 props)))
8407 (insert "Usage: ")
8408 (setq beg (point))
8409 (insert (if class
8410 (format calling-seq class name class name class name)
8411 (format calling-seq name name name name))
8412 "\n")
8413 (add-text-properties beg (point) props)
8415 (insert "Keywords:")
8416 (if (null keywords)
8417 (insert " No keywords accepted.")
8418 (setq col 9)
8419 (mapc
8420 (lambda (x)
8421 (if (>= (+ col 1 (length (car x)))
8422 (window-width))
8423 (progn
8424 (insert "\n ")
8425 (setq col 9)))
8426 (insert " ")
8427 (setq beg (point)
8428 ;; Relevant keywords already have link property attached
8429 props (list 'mouse-face 'highlight
8430 km-prop idlwave-rinfo-mouse-map
8431 'data (cons 'keyword data)
8432 'help-echo help-echo-kwd
8433 'keyword (car x)))
8434 (if system (setq props (append (list 'face face) props)))
8435 (insert (car x))
8436 (add-text-properties beg (point) props)
8437 (setq col (+ col 1 (length (car x)))))
8438 keywords))
8440 (setq cnt 1 total (length all))
8441 ;; Here entry is (key file (list of type-conses))
8442 (while (setq entry (pop all))
8443 (setq props (list 'mouse-face 'highlight
8444 km-prop idlwave-rinfo-mouse-map
8445 'help-echo help-echo-src
8446 'source (list (car (car (nth 2 entry))) ;type
8447 (nth 1 entry)
8449 (cdr (car (nth 2 entry))))
8450 'data (cons 'source data)))
8451 (idlwave-insert-source-location
8452 (format "\n%-8s %s"
8453 (if (equal cnt 1)
8454 (if (> total 1) "Sources:" "Source:")
8456 (if (> total 1) "- " ""))
8457 entry props)
8458 (incf cnt)
8459 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8460 ;; No more source lines, please
8461 (insert (format
8462 "\n Source information truncated to %d entries."
8463 idlwave-rinfo-max-source-lines))
8464 (setq all nil)))
8465 (goto-char (point-min))
8466 (setq buffer-read-only t))
8467 (display-buffer "*Help*")
8468 (if (and (setq win (get-buffer-window "*Help*"))
8469 idlwave-resize-routine-help-window)
8470 (progn
8471 (let ((ww (selected-window)))
8472 (unwind-protect
8473 (progn
8474 (select-window win)
8475 (enlarge-window (- (/ (frame-height) 2)
8476 (window-height)))
8477 (shrink-window-if-larger-than-buffer))
8478 (select-window ww)))))))))
8480 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8481 "Insert a source location into the routine info buffer.
8482 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8483 to it."
8484 (let* ((key (car entry))
8485 (file (nth 1 entry))
8486 (types (nth 2 entry))
8487 (shell-flag (assq 'compiled types))
8488 (buffer-flag (assq 'buffer types))
8489 (user-flag (assq 'user types))
8490 (lib-flag (assq 'lib types))
8491 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8492 (and user-flag (idlwave-count-memq 'user types))
8493 (and lib-flag (idlwave-count-memq 'lib types))
8495 (doflags t)
8496 beg special)
8498 (insert prefix)
8500 (cond
8501 ((eq key 'system)
8502 (setq doflags nil)
8503 (insert "System "))
8505 ((eq key 'builtin)
8506 (setq doflags nil)
8507 (insert "Builtin "))
8509 ((and (not file) shell-flag)
8510 (insert "Unresolved"))
8512 ((null file)
8513 (insert "ERROR"))
8515 ((idlwave-syslib-p file)
8516 (if (string-match "obsolete" (file-name-directory file))
8517 (insert "Obsolete ")
8518 (insert "SystemLib ")))
8520 ;; New special syntax: taken directly from routine-info for
8521 ;; library catalog routines
8522 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8523 (insert (format "%-10s" special)))
8525 ;; Old special syntax: a matching regexp
8526 ((setq special (idlwave-special-lib-test file))
8527 (insert (format "%-10s" special)))
8529 ;; Catch-all with file
8530 ((idlwave-lib-p file) (insert "Library "))
8532 ;; Sanity catch all
8533 (t (insert "Other ")))
8535 (when doflags
8536 (insert (concat
8537 " ["
8538 (if lib-flag "L" "-")
8539 (if user-flag "C" "-")
8540 (if shell-flag "S" "-")
8541 (if buffer-flag "B" "-")
8542 "] ")))
8543 (when (> ndupl 1)
8544 (setq beg (point))
8545 (insert (format "(%dx) " ndupl))
8546 (add-text-properties beg (point) (list 'face 'bold)))
8547 (when (and file (not (equal file "")))
8548 (setq beg (point))
8549 (insert (apply 'abbreviate-file-name
8550 (if (featurep 'xemacs) (list file t) (list file))))
8551 (if file-props
8552 (add-text-properties beg (point) file-props)))))
8554 (defun idlwave-special-lib-test (file)
8555 "Check the path of FILE against the regexps which define special libs.
8556 Return the name of the special lib if there is a match."
8557 (let ((alist idlwave-special-lib-alist)
8558 entry rtn)
8559 (cond
8560 ((stringp file)
8561 (while (setq entry (pop alist))
8562 (if (string-match (car entry) file)
8563 (setq rtn (cdr entry)
8564 alist nil)))
8565 rtn)
8566 (t nil))))
8568 (defun idlwave-mouse-active-rinfo-right (ev)
8569 (interactive "e")
8570 (idlwave-mouse-active-rinfo ev 'right))
8572 (defun idlwave-mouse-active-rinfo-shift (ev)
8573 (interactive "e")
8574 (idlwave-mouse-active-rinfo ev nil 'shift))
8576 (defun idlwave-active-rinfo-space ()
8577 (interactive)
8578 (idlwave-mouse-active-rinfo nil 'right))
8580 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8581 "Do the mouse actions in the routine info buffer.
8582 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8583 was pressed."
8584 (interactive "e")
8585 (if ev (mouse-set-point ev))
8586 (let (data id name type class buf bufwin source link keyword
8587 word initial-class)
8588 (setq data (get-text-property (point) 'data)
8589 source (get-text-property (point) 'source)
8590 keyword (get-text-property (point) 'keyword)
8591 link (get-text-property (point) 'link)
8592 id (car data)
8593 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8594 buf (nth 4 data)
8595 initial-class (nth 6 data)
8596 word (idlwave-this-word)
8597 bufwin (get-buffer-window buf t))
8599 (cond ((eq id 'class) ; Switch class being displayed
8600 (if (window-live-p bufwin) (select-window bufwin))
8601 (idlwave-display-calling-sequence
8602 (idlwave-sintern-method name)
8603 type (idlwave-sintern-class word)
8604 initial-class))
8605 ((eq id 'usage) ; Online help on this routine
8606 (idlwave-online-help link name type class))
8607 ((eq id 'source) ; Source in help or buffer
8608 (if right ; In help
8609 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8610 (idlwave-help-source-try-header nil)
8611 ;; Fake idlwave-routines so help will find the right entry
8612 (idlwave-routines
8613 (list (list name type class source ""))))
8614 (idlwave-help-get-special-help name type class nil))
8615 ;; Otherwise just pop to the source
8616 (setq idlwave-popup-source (not idlwave-popup-source))
8617 (if idlwave-popup-source
8618 (condition-case err
8619 (idlwave-do-find-module name type class source)
8620 (error
8621 (setq idlwave-popup-source nil)
8622 (if (window-live-p bufwin) (select-window bufwin))
8623 (error (nth 1 err))))
8624 (if bufwin
8625 (select-window bufwin)
8626 (pop-to-buffer buf))
8627 (goto-char (marker-position idlwave-rinfo-marker)))))
8628 ((eq id 'keyword)
8629 (if right
8630 (idlwave-online-help link name type class keyword)
8631 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8633 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8634 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8635 (let ((bwin (get-buffer-window buffer)))
8636 (if idlwave-complete-empty-string-as-lower-case
8637 (setq keyword (downcase keyword)))
8638 (if bwin
8639 (select-window bwin)
8640 (pop-to-buffer buffer)
8641 (setq bwin (get-buffer-window buffer)))
8642 (if (eq (preceding-char) ?/)
8643 (insert keyword)
8644 (unless (save-excursion
8645 (re-search-backward
8646 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8647 (min (- (point) 100) (point-min)) t))
8648 (insert ", "))
8649 (if shift (insert "/"))
8650 (insert keyword)
8651 (if (and (not shift)
8652 idlwave-keyword-completion-adds-equal)
8653 (insert "=")))))
8655 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8656 "List the load path shadows of all routines defined in current buffer."
8657 (interactive "P")
8658 (idlwave-routines)
8659 (if (eq major-mode 'idlwave-mode)
8660 (idlwave-list-load-path-shadows
8661 nil (idlwave-update-current-buffer-info 'save-buffer)
8662 "in current buffer")
8663 (error "Current buffer is not in idlwave-mode")))
8665 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8666 "List the load path shadows of all routines compiled under the shell.
8667 This is very useful for checking an IDL application. Just compile the
8668 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8669 routines and update IDLWAVE internal info. Then check for shadowing
8670 with this command."
8671 (interactive "P")
8672 (cond
8673 ((or (not (fboundp 'idlwave-shell-is-running))
8674 (not (idlwave-shell-is-running)))
8675 (error "Shell is not running"))
8676 ((null idlwave-compiled-routines)
8677 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8679 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8680 "in the shell"))))
8682 (defun idlwave-list-all-load-path-shadows (&optional arg)
8683 "List the load path shadows of all routines known to IDLWAVE."
8684 (interactive "P")
8685 (idlwave-list-load-path-shadows nil nil "globally"))
8687 (defvar idlwave-sort-prefer-buffer-info t
8688 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8690 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8691 "List the routines which are defined multiple times.
8692 Search the information IDLWAVE has about IDL routines for multiple
8693 definitions.
8694 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8696 When IDL hits a routine call which is not defined, it will search on
8697 the load path in order to find a definition. The output of this command
8698 can be used to detect possible name clashes during this process."
8699 (idlwave-routines) ; Make sure everything is loaded.
8700 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8701 (or (y-or-n-p
8702 "You don't have any user or library catalogs. Continue anyway? ")
8703 (error "Abort")))
8704 (let* ((routines (append idlwave-system-routines
8705 idlwave-compiled-routines
8706 idlwave-library-catalog-routines
8707 idlwave-user-catalog-routines
8708 idlwave-buffer-routines
8709 nil))
8710 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8711 (keymap (make-sparse-keymap))
8712 (props (list 'mouse-face 'highlight
8713 km-prop keymap
8714 'help-echo "Mouse2: Find source"))
8715 (nroutines (length (or special-routines routines)))
8716 (step (/ nroutines 100))
8717 (n 0)
8718 (cnt 0)
8719 (idlwave-sort-prefer-buffer-info nil)
8720 routine twins dtwins twin done props1 lroutines)
8722 (if special-routines
8723 ;; Just looking for shadows of a few special routines
8724 (setq lroutines routines
8725 routines special-routines))
8727 (message "Sorting routines...")
8728 (setq routines (sort routines
8729 (lambda (a b)
8730 (string< (downcase (idlwave-make-full-name
8731 (nth 2 a) (car a)))
8732 (downcase (idlwave-make-full-name
8733 (nth 2 b) (car b)))))))
8734 (message "Sorting routines...done")
8736 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8737 (lambda (ev)
8738 (interactive "e")
8739 (mouse-set-point ev)
8740 (apply 'idlwave-do-find-module
8741 (get-text-property (point) 'find-args))))
8742 (define-key keymap [(return)]
8743 (lambda ()
8744 (interactive)
8745 (apply 'idlwave-do-find-module
8746 (get-text-property (point) 'find-args))))
8747 (message "Compiling list...( 0%%)")
8748 (with-current-buffer (get-buffer-create "*Shadows*")
8749 (setq buffer-read-only nil)
8750 (erase-buffer)
8751 (while (setq routine (pop routines))
8752 (if (= (mod (setq n (1+ n)) step) 0)
8753 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8755 ;; Get a list of all twins
8756 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8757 (if (memq routine done)
8758 (setq dtwins nil)
8759 (setq dtwins (idlwave-study-twins twins)))
8760 ;; Mark all twins as dealt with
8761 (setq done (append twins done))
8762 (when (or (> (length dtwins) 1)
8763 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8764 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8765 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8766 (incf cnt)
8767 (insert (format "\n%s%s"
8768 (idlwave-make-full-name (nth 2 routine)
8769 (car routine))
8770 (if (eq (nth 1 routine) 'fun) "()" "")))
8771 (while (setq twin (pop dtwins))
8772 (setq props1 (append (list 'find-args
8773 (list (nth 0 routine)
8774 (nth 1 routine)
8775 (nth 2 routine)))
8776 props))
8777 (idlwave-insert-source-location "\n - " twin props1))))
8778 (goto-char (point-min))
8779 (setq buffer-read-only t))
8780 (setq loc (or loc ""))
8781 (if (> cnt 0)
8782 (progn
8783 (display-buffer (get-buffer "*Shadows*"))
8784 (message "%d case%s of shadowing found %s"
8785 cnt (if (= cnt 1) "" "s") loc))
8786 (message "No shadowing conflicts found %s" loc))))
8788 (defun idlwave-print-source (routine)
8789 (let* ((source (nth 3 routine))
8790 (stype (car source))
8791 (sfile (idlwave-routine-source-file source)))
8792 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8793 (if (and (eq stype 'compiled)
8794 (or (not (stringp sfile))
8795 (not (string-match "\\S-" sfile))))
8796 (setq stype 'unresolved))
8797 (princ (format " %-10s %s\n"
8798 stype
8799 (if sfile sfile "No source code available")))))
8801 (defun idlwave-routine-twins (entry &optional list)
8802 "Return all twin entries of ENTRY in LIST.
8803 LIST defaults to `idlwave-routines'.
8804 Twin entries are those which have the same name, type, and class.
8805 ENTRY will also be returned, as the first item of this list."
8806 (let* ((name (car entry))
8807 (type (nth 1 entry))
8808 (class (nth 2 entry))
8809 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8810 twins candidate)
8811 (while (setq candidate (pop candidates))
8812 (if (and (not (eq candidate entry))
8813 (eq type (nth 1 candidate))
8814 (eq class (nth 2 candidate)))
8815 (push candidate twins)))
8816 (if (setq candidate (idlwave-rinfo-assq name type class
8817 idlwave-unresolved-routines))
8818 (push candidate twins))
8819 (cons entry (nreverse twins))))
8821 (defun idlwave-study-twins (entries)
8822 "Return dangerous twins of first entry in ENTRIES.
8823 Dangerous twins are routines with same name, but in different files on
8824 the load path. If a file is in the system library and has an entry in
8825 the `idlwave-system-routines' list, we omit the latter as
8826 non-dangerous because many IDL routines are implemented as library
8827 routines, and may have been scanned."
8828 (let* ((entry (car entries))
8829 (name (car entry)) ;
8830 (type (nth 1 entry)) ; Must be bound for
8831 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8832 (cnt 0)
8833 source type type-cons file alist syslibp key)
8834 (while (setq entry (pop entries))
8835 (incf cnt)
8836 (setq source (nth 3 entry)
8837 type (car source)
8838 type-cons (cons type (nth 3 source))
8839 file (idlwave-routine-source-file source))
8841 ;; Make KEY to index entry properly
8842 (setq key (cond ((eq type 'system) type)
8843 (file (file-truename file))
8844 (t 'unresolved)))
8846 ;; Check for an entry in the system library
8847 (if (and file
8848 (not syslibp)
8849 (idlwave-syslib-p file))
8850 (setq syslibp t))
8852 ;; If there's more than one matching entry for the same file, just
8853 ;; append the type-cons to the type list.
8854 (if (setq entry (assoc key alist))
8855 (push type-cons (nth 2 entry))
8856 (push (list key file (list type-cons)) alist)))
8858 (setq alist (nreverse alist))
8860 (when syslibp
8861 ;; File is in system *library* - remove any 'system entry
8862 (setq alist (delq (assq 'system alist) alist)))
8864 ;; If 'system remains and we've scanned the syslib, it's a builtin
8865 ;; (rather than a !DIR/lib/.pro file bundled as source).
8866 (when (and (idlwave-syslib-scanned-p)
8867 (setq entry (assoc 'system alist)))
8868 (setcar entry 'builtin))
8869 (sort alist 'idlwave-routine-twin-compare)))
8871 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8872 ;; (defvar type)
8873 ;; (defvar class)
8874 (defmacro idlwave-xor (a b)
8875 `(and (or ,a ,b)
8876 (not (and ,a ,b))))
8878 (defun idlwave-routine-entry-compare (a b)
8879 "Compare two routine info entries for sorting.
8880 This is the general case. It first compares class, names, and type.
8881 If it turns out that A and B are twins (same name, class, and type),
8882 calls another routine which compares twins on the basis of their file
8883 names and path locations."
8884 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8885 (cond
8886 ((not (equal (idlwave-downcase-safe class)
8887 (idlwave-downcase-safe (nth 2 b))))
8888 ;; Class decides
8889 (cond ((null (nth 2 b)) nil)
8890 ((null class) t)
8891 (t (string< (downcase class) (downcase (nth 2 b))))))
8892 ((not (equal (downcase name) (downcase (car b))))
8893 ;; Name decides
8894 (string< (downcase name) (downcase (car b))))
8895 ((not (eq type (nth 1 b)))
8896 ;; Type decides
8897 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8899 ;; A and B are twins - so the decision is more complicated.
8900 ;; Call twin-compare with the proper arguments.
8901 (idlwave-routine-entry-compare-twins a b)))))
8903 (defun idlwave-routine-entry-compare-twins (a b)
8904 "Compare two routine entries, under the assumption that they are twins.
8905 This basically calls `idlwave-routine-twin-compare' with the correct args."
8906 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8907 (asrc (nth 3 a))
8908 (atype (car asrc))
8909 (bsrc (nth 3 b))
8910 (btype (car bsrc))
8911 (afile (idlwave-routine-source-file asrc))
8912 (bfile (idlwave-routine-source-file bsrc)))
8913 (idlwave-routine-twin-compare
8914 (if (stringp afile)
8915 (list (file-truename afile) afile (list atype))
8916 (list atype afile (list atype)))
8917 (if (stringp bfile)
8918 (list (file-truename bfile) bfile (list btype))
8919 (list btype bfile (list btype))))
8922 ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
8923 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8924 (defvar class)
8926 (defun idlwave-routine-twin-compare (a b)
8927 "Compare two routine twin entries for sorting.
8928 In here, A and B are not normal routine info entries, but special
8929 lists (KEY FILENAME (TYPES...)).
8930 This expects NAME TYPE CLASS to be bound to the right values."
8931 (let* (;; Dis-assemble entries
8932 (akey (car a)) (bkey (car b))
8933 (afile (nth 1 a)) (bfile (nth 1 b))
8934 (atypes (nth 2 a)) (btypes (nth 2 b))
8935 ;; System routines?
8936 (asysp (memq akey '(builtin system)))
8937 (bsysp (memq bkey '(builtin system)))
8938 ;; Compiled routines?
8939 (acompp (memq 'compiled atypes))
8940 (bcompp (memq 'compiled btypes))
8941 ;; Unresolved?
8942 (aunresp (or (eq akey 'unresolved)
8943 (and acompp (not afile))))
8944 (bunresp (or (eq bkey 'unresolved)
8945 (and bcompp (not bfile))))
8946 ;; Buffer info available?
8947 (abufp (memq 'buffer atypes))
8948 (bbufp (memq 'buffer btypes))
8949 ;; On search path?
8950 (tpath-alist (idlwave-true-path-alist))
8951 (apathp (and (stringp akey)
8952 (assoc (file-name-directory akey) tpath-alist)))
8953 (bpathp (and (stringp bkey)
8954 (assoc (file-name-directory bkey) tpath-alist)))
8955 ;; How early on search path? High number means early since we
8956 ;; measure the tail of the path list
8957 (anpath (length (memq apathp tpath-alist)))
8958 (bnpath (length (memq bpathp tpath-alist)))
8959 ;; Look at file names
8960 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8961 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8962 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8963 (regexp-quote (downcase class))
8964 (regexp-quote (downcase name)))
8965 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8966 ;; Is file name derived from the routine name?
8967 ;; Method file or class definition file?
8968 (anamep (string-match fname-re aname))
8969 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8970 (bnamep (string-match fname-re bname))
8971 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8973 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8974 ;; doesn't it? The difficult stuff is hidden above...
8975 (cond
8976 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8977 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8978 ((and idlwave-sort-prefer-buffer-info
8979 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8980 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8981 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8982 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8983 ((and class anamep bnamep ; both file names match ->
8984 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8985 ((> anpath bnpath) t) ; Who is first on path?
8986 (t nil)))) ; Default
8988 (defun idlwave-routine-source-file (source)
8989 (if (nth 2 source)
8990 (expand-file-name (nth 1 source) (nth 2 source))
8991 (nth 1 source)))
8993 (defun idlwave-downcase-safe (string)
8994 "Donwcase if string, else return unchanged."
8995 (if (stringp string)
8996 (downcase string)
8997 string))
8999 (defun idlwave-count-eq (elt list)
9000 "How often is ELT in LIST?"
9001 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9003 (defun idlwave-count-memq (elt alist)
9004 "How often is ELT a key in ALIST?"
9005 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9007 (defun idlwave-syslib-p (file)
9008 "Non-nil if FILE is in the system library."
9009 (let* ((true-syslib (file-name-as-directory
9010 (file-truename
9011 (expand-file-name "lib" (idlwave-sys-dir)))))
9012 (true-file (file-truename file)))
9013 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9015 (defun idlwave-lib-p (file)
9016 "Non-nil if FILE is in the library."
9017 (let ((true-dir (file-name-directory (file-truename file))))
9018 (assoc true-dir (idlwave-true-path-alist))))
9020 (defun idlwave-path-alist-add-flag (list-entry flag)
9021 "Add a flag to the path list entry, if not set."
9022 (let ((flags (cdr list-entry)))
9023 (add-to-list 'flags flag)
9024 (setcdr list-entry flags)))
9026 (defun idlwave-path-alist-remove-flag (list-entry flag)
9027 "Remove a flag to the path list entry, if set."
9028 (let ((flags (delq flag (cdr list-entry))))
9029 (setcdr list-entry flags)))
9031 (defun idlwave-true-path-alist ()
9032 "Return `idlwave-path-alist' alist with true-names.
9033 Info is cached, but relies on the functions setting `idlwave-path-alist'
9034 to reset the variable `idlwave-true-path-alist' to nil."
9035 (or idlwave-true-path-alist
9036 (setq idlwave-true-path-alist
9037 (mapcar (lambda(x) (cons
9038 (file-name-as-directory
9039 (file-truename
9040 (directory-file-name
9041 (car x))))
9042 (cdr x)))
9043 idlwave-path-alist))))
9045 (defun idlwave-syslib-scanned-p ()
9046 "Non-nil if the system lib file !DIR/lib has been scanned."
9047 (let* ((true-syslib (file-name-as-directory
9048 (file-truename
9049 (expand-file-name "lib" (idlwave-sys-dir))))))
9050 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9052 ;; ----------------------------------------------------------------------------
9054 ;; Online Help display
9057 ;; ----------------------------------------------------------------------------
9059 ;; Additions for use with imenu.el and func-menu.el
9060 ;; (pop-up a list of IDL units in the current file).
9063 (defun idlwave-prev-index-position ()
9064 "Search for the previous procedure or function.
9065 Return nil if not found. For use with imenu.el."
9066 (save-match-data
9067 (cond
9068 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9069 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9070 (t nil))))
9072 (defun idlwave-unit-name ()
9073 "Return the unit name.
9074 Assumes that point is at the beginning of the unit as found by
9075 `idlwave-prev-index-position'."
9076 (forward-sexp 2)
9077 (forward-sexp -1)
9078 (let ((begin (point)))
9079 (re-search-forward
9080 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9081 (if (fboundp 'buffer-substring-no-properties)
9082 (buffer-substring-no-properties begin (point))
9083 (buffer-substring begin (point)))))
9085 (defalias 'idlwave-function-menu
9086 (condition-case nil
9087 (progn
9088 (require 'func-menu)
9089 'function-menu)
9090 (error (condition-case nil
9091 (progn
9092 (require 'imenu)
9093 'imenu)
9094 (error nil)))))
9096 ;; Here we hack func-menu.el in order to support this new mode.
9097 ;; The latest versions of func-menu.el already have this stuff in, so
9098 ;; we hack only if it is not already there.
9099 (when (fboundp 'eval-after-load)
9100 (eval-after-load "func-menu"
9101 '(progn
9102 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9103 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9104 (setq fume-function-name-regexp-alist
9105 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9106 fume-function-name-regexp-alist)))
9107 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9108 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9109 (setq fume-find-function-name-method-alist
9110 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9111 fume-find-function-name-method-alist))))))
9113 (defun idlwave-edit-in-idlde ()
9114 "Edit the current file in IDL Development environment."
9115 (interactive)
9116 (start-process "idldeclient" nil
9117 idlwave-shell-explicit-file-name "-c" "-e"
9118 (buffer-file-name)))
9120 (defvar idlwave-help-use-assistant)
9121 (defun idlwave-launch-idlhelp ()
9122 "Start the IDLhelp application."
9123 (interactive)
9124 (if idlwave-help-use-assistant
9125 (idlwave-help-assistant-raise)
9126 (start-process "idlhelp" nil idlwave-help-application)))
9128 ;; Menus - using easymenu.el
9129 (defvar idlwave-mode-menu-def
9130 `("IDLWAVE"
9131 ["PRO/FUNC menu" idlwave-function-menu t]
9132 ("Motion"
9133 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9134 ["Subprogram End" idlwave-end-of-subprogram t]
9135 ["Block Start" idlwave-beginning-of-block t]
9136 ["Block End" idlwave-end-of-block t]
9137 ["Up Block" idlwave-backward-up-block t]
9138 ["Down Block" idlwave-down-block t]
9139 ["Skip Block Backward" idlwave-backward-block t]
9140 ["Skip Block Forward" idlwave-forward-block t])
9141 ("Mark"
9142 ["Subprogram" idlwave-mark-subprogram t]
9143 ["Block" idlwave-mark-block t]
9144 ["Header" idlwave-mark-doclib t])
9145 ("Format"
9146 ["Indent Entire Statement" idlwave-indent-statement
9147 :active t :keys "C-u \\[indent-for-tab-command]" ]
9148 ["Indent Subprogram" idlwave-indent-subprogram t]
9149 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9150 ["Continue/Split line" idlwave-split-line t]
9151 "--"
9152 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9153 :selected (symbol-value idlwave-fill-function)])
9154 ("Templates"
9155 ["Procedure" idlwave-procedure t]
9156 ["Function" idlwave-function t]
9157 ["Doc Header" idlwave-doc-header t]
9158 ["Log" idlwave-doc-modification t]
9159 "--"
9160 ["Case" idlwave-case t]
9161 ["For" idlwave-for t]
9162 ["Repeat" idlwave-repeat t]
9163 ["While" idlwave-while t]
9164 "--"
9165 ["Close Block" idlwave-close-block t])
9166 ("Completion"
9167 ["Complete" idlwave-complete t]
9168 ("Complete Specific"
9169 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9170 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9171 "--"
9172 ["3 Function Name" (idlwave-complete 'function) t]
9173 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9174 "--"
9175 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9176 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9177 "--"
9178 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9179 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9180 "--"
9181 ["9 Class Name" idlwave-complete-class t]))
9182 ("Routine Info"
9183 ["Show Routine Info" idlwave-routine-info t]
9184 ["Online Context Help" idlwave-context-help t]
9185 "--"
9186 ["Find Routine Source" idlwave-find-module t]
9187 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9188 "--"
9189 ["Update Routine Info" idlwave-update-routine-info t]
9190 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9191 "--"
9192 "IDL User Catalog"
9193 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9194 ["Scan Directories" (idlwave-update-routine-info '(16))
9195 (and idlwave-path-alist (not idlwave-catalog-process))]
9196 ["Scan Directories &" (idlwave-update-routine-info '(64))
9197 (and idlwave-path-alist (not idlwave-catalog-process))]
9198 "--"
9199 "Routine Shadows"
9200 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9201 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9202 ["Check Everything" idlwave-list-all-load-path-shadows t])
9203 ("Misc"
9204 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9205 "--"
9206 ["Insert TAB character" idlwave-hard-tab t])
9207 "--"
9208 ("External"
9209 ["Start IDL shell" idlwave-shell t]
9210 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9211 ["Launch IDL Help" idlwave-launch-idlhelp t])
9212 "--"
9213 ("Customize"
9214 ["Browse IDLWAVE Group" idlwave-customize t]
9215 "--"
9216 ["Build Full Customize Menu" idlwave-create-customize-menu
9217 (fboundp 'customize-menu-create)])
9218 ("Documentation"
9219 ["Describe Mode" describe-mode t]
9220 ["Abbreviation List" idlwave-list-abbrevs t]
9221 "--"
9222 ["Commentary in idlwave.el" idlwave-show-commentary t]
9223 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9224 "--"
9225 ["Info" idlwave-info t]
9226 "--"
9227 ["Help with Topic" idlwave-help-assistant-help-with-topic
9228 idlwave-help-use-assistant]
9229 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9231 (defvar idlwave-mode-debug-menu-def
9232 '("Debug"
9233 ["Start IDL shell" idlwave-shell t]
9234 ["Save and .RUN buffer" idlwave-shell-save-and-run
9235 (and (boundp 'idlwave-shell-automatic-start)
9236 idlwave-shell-automatic-start)]))
9238 (if (or (featurep 'easymenu) (load "easymenu" t))
9239 (progn
9240 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9241 "IDL and WAVE CL editing menu"
9242 idlwave-mode-menu-def)
9243 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9244 "IDL and WAVE CL editing menu"
9245 idlwave-mode-debug-menu-def)))
9247 (defun idlwave-customize ()
9248 "Call the customize function with `idlwave' as argument."
9249 (interactive)
9250 ;; Try to load the code for the shell, so that we can customize it
9251 ;; as well.
9252 (or (featurep 'idlw-shell)
9253 (load "idlw-shell" t))
9254 (customize-browse 'idlwave))
9256 (defun idlwave-create-customize-menu ()
9257 "Create a full customization menu for IDLWAVE, insert it into the menu."
9258 (interactive)
9259 (if (fboundp 'customize-menu-create)
9260 (progn
9261 ;; Try to load the code for the shell, so that we can customize it
9262 ;; as well.
9263 (or (featurep 'idlw-shell)
9264 (load "idlw-shell" t))
9265 (easy-menu-change
9266 '("IDLWAVE") "Customize"
9267 `(["Browse IDLWAVE group" idlwave-customize t]
9268 "--"
9269 ,(customize-menu-create 'idlwave)
9270 ["Set" Custom-set t]
9271 ["Save" Custom-save t]
9272 ["Reset to Current" Custom-reset-current t]
9273 ["Reset to Saved" Custom-reset-saved t]
9274 ["Reset to Standard Settings" Custom-reset-standard t]))
9275 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9276 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9278 (defun idlwave-show-commentary ()
9279 "Use the finder to view the file documentation from `idlwave.el'."
9280 (interactive)
9281 (finder-commentary "idlwave.el"))
9283 (defun idlwave-shell-show-commentary ()
9284 "Use the finder to view the file documentation from `idlw-shell.el'."
9285 (interactive)
9286 (finder-commentary "idlw-shell.el"))
9288 (defun idlwave-info ()
9289 "Read documentation for IDLWAVE in the info system."
9290 (interactive)
9291 (info "idlwave"))
9293 (defun idlwave-list-abbrevs (arg)
9294 "Show the code abbreviations define in IDLWAVE mode.
9295 This lists all abbrevs where the replacement text differs from the input text.
9296 These are the ones the users want to learn to speed up their writing.
9298 The function does *not* list abbrevs which replace a word with itself
9299 to call a hook. These hooks are used to change the case of words or
9300 to blink the matching `begin', and the user does not need to know them.
9302 With arg, list all abbrevs with the corresponding hook.
9304 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9306 (interactive "P")
9307 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9308 abbrevs
9309 str rpl func fmt (len-str 0) (len-rpl 0))
9310 (mapatoms
9311 (lambda (sym)
9312 (if (symbol-value sym)
9313 (progn
9314 (setq str (symbol-name sym)
9315 rpl (symbol-value sym)
9316 func (symbol-function sym))
9317 (if arg
9318 (setq func (prin1-to-string func))
9319 (if (and (listp func) (stringp (nth 2 func)))
9320 (setq rpl (concat "EVAL: " (nth 2 func))
9321 func "")
9322 (setq func "")))
9323 (if (or arg (not (string= rpl str)))
9324 (progn
9325 (setq len-str (max len-str (length str)))
9326 (setq len-rpl (max len-rpl (length rpl)))
9327 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9328 table)
9329 ;; sort the list
9330 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9331 ;; Make the format
9332 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9333 (with-output-to-temp-buffer "*Help*"
9334 (if arg
9335 (progn
9336 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9337 (princ "=========================================\n\n")
9338 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9339 (princ (format fmt "---" "-------" "----")))
9340 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9341 (princ "================================================\n\n")
9342 (princ (format fmt "KEY" "ACTION" ""))
9343 (princ (format fmt "---" "------" "")))
9344 (mapcar
9345 (lambda (list)
9346 (setq str (car list)
9347 rpl (nth 1 list)
9348 func (nth 2 list))
9349 (princ (format fmt str rpl func)))
9350 abbrevs)))
9351 ;; Make sure each abbreviation uses only one display line
9352 (with-current-buffer "*Help*"
9353 (setq truncate-lines t)))
9355 ;; Add .pro files to speedbar for support, if it's loaded
9356 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9358 ;; Set an idle timer to load the routine info.
9359 ;; Will only work on systems which support this.
9360 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9362 ;; Run the hook
9363 (run-hooks 'idlwave-load-hook)
9365 (provide 'idlwave)
9367 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
9368 ;;; idlwave.el ends here