Trivial fixes for epg.el.
[emacs.git] / lisp / progmodes / idlwave.el
blobb2858f1479df0fbeacd4a3c901a18c828e9bda63
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_em22
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 (defvar idlwave-fill-function 'auto-fill-function
1374 "IDL mode auto fill function.")
1376 (defvar idlwave-comment-indent-function 'comment-indent-function
1377 "IDL mode comment indent function.")
1379 ;; Note that this is documented in the v18 manuals as being a string
1380 ;; of length one rather than a single character.
1381 ;; The code in this file accepts either format for compatibility.
1382 (defvar idlwave-comment-indent-char ?\
1383 "Character to be inserted for IDL comment indentation.
1384 Normally a space.")
1386 (defconst idlwave-continuation-char ?$
1387 "Character which is inserted as a last character on previous line by
1388 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1390 (defconst idlwave-mode-version "6.1_em22")
1392 (defmacro idlwave-keyword-abbrev (&rest args)
1393 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1394 `(quote (lambda ()
1395 ,(append '(idlwave-check-abbrev) args))))
1397 ;; If I take the time I can replace idlwave-keyword-abbrev with
1398 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1399 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1400 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1401 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1403 (defmacro idlwave-code-abbrev (&rest args)
1404 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1405 Specifically, if the abbrev is in a comment or string it is unexpanded.
1406 Otherwise ARGS forms a list that is evaluated."
1407 ;; FIXME: it would probably be better to rely on the new :enable-function
1408 ;; to enforce the "don't expand in comments or strings".
1409 `(lambda ()
1410 ,(prin1-to-string args) ;; Puts the code in the doc string
1411 (if (idlwave-quoted)
1412 (progn (unexpand-abbrev) nil)
1413 ,(append args))))
1415 (autoload 'idlwave-shell "idlw-shell"
1416 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1417 (autoload 'idlwave-shell-send-command "idlw-shell")
1418 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1419 "Run `idlwave-shell' and switch back to current window" t)
1420 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1421 "Save and run buffer under the shell." t)
1422 (autoload 'idlwave-shell-break-here "idlw-shell"
1423 "Set breakpoint in current line." t)
1424 (autoload 'idlwave-shell-run-region "idlw-shell"
1425 "Compile and run the region." t)
1427 (fset 'idlwave-debug-map (make-sparse-keymap))
1429 (defvar idlwave-mode-map
1430 (let ((map (make-sparse-keymap)))
1431 (define-key map "\C-c " 'idlwave-hard-tab)
1432 (define-key map [(control tab)] 'idlwave-hard-tab)
1433 ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
1434 (define-key map "'" 'idlwave-show-matching-quote)
1435 (define-key map "\"" 'idlwave-show-matching-quote)
1436 (define-key map "\C-g" 'idlwave-keyboard-quit)
1437 (define-key map "\C-c;" 'idlwave-toggle-comment-region)
1438 (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1439 (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
1440 (define-key map "\C-c{" 'idlwave-beginning-of-block)
1441 (define-key map "\C-c}" 'idlwave-end-of-block)
1442 (define-key map "\C-c]" 'idlwave-close-block)
1443 (define-key map [(meta control h)] 'idlwave-mark-subprogram)
1444 (define-key map "\M-\C-n" 'idlwave-forward-block)
1445 (define-key map "\M-\C-p" 'idlwave-backward-block)
1446 (define-key map "\M-\C-d" 'idlwave-down-block)
1447 (define-key map "\M-\C-u" 'idlwave-backward-up-block)
1448 (define-key map "\M-\r" 'idlwave-split-line)
1449 (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
1450 (define-key map "\C-c\C-p" 'idlwave-previous-statement)
1451 (define-key map "\C-c\C-n" 'idlwave-next-statement)
1452 ;; (define-key map "\r" 'idlwave-newline)
1453 ;; (define-key map "\t" 'idlwave-indent-line)
1454 (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
1455 (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
1456 (define-key map "\M-q" 'idlwave-fill-paragraph)
1457 (define-key map "\M-s" 'idlwave-edit-in-idlde)
1458 (define-key map "\C-c\C-h" 'idlwave-doc-header)
1459 (define-key map "\C-c\C-m" 'idlwave-doc-modification)
1460 (define-key map "\C-c\C-c" 'idlwave-case)
1461 (define-key map "\C-c\C-d" 'idlwave-debug-map)
1462 (when (and (listp idlwave-shell-debug-modifiers)
1463 (not (equal idlwave-shell-debug-modifiers '())))
1464 ;; Bind the debug commands also with the special modifiers.
1465 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1466 (mods-noshift
1467 (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
1468 (define-key map
1469 (vector (append mods-noshift (list (if shift ?C ?c))))
1470 'idlwave-shell-save-and-run)
1471 (define-key map
1472 (vector (append mods-noshift (list (if shift ?B ?b))))
1473 'idlwave-shell-break-here)
1474 (define-key map
1475 (vector (append mods-noshift (list (if shift ?E ?e))))
1476 'idlwave-shell-run-region)))
1477 (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1478 (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1479 (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1480 (define-key map "\C-c\C-f" 'idlwave-for)
1481 ;; (define-key map "\C-c\C-f" 'idlwave-function)
1482 ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
1483 (define-key map "\C-c\C-r" 'idlwave-repeat)
1484 (define-key map "\C-c\C-w" 'idlwave-while)
1485 (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1486 (define-key map "\C-c\C-s" 'idlwave-shell)
1487 (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1488 (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1489 (define-key map "\C-c\C-v" 'idlwave-find-module)
1490 (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
1491 (define-key map "\C-c?" 'idlwave-routine-info)
1492 (define-key map "\M-?" 'idlwave-context-help)
1493 (define-key map [(control meta ?\?)]
1494 'idlwave-help-assistant-help-with-topic)
1495 ;; Pickup both forms of Esc/Meta binding
1496 (define-key map [(meta tab)] 'idlwave-complete)
1497 (define-key map [?\e?\t] 'idlwave-complete)
1498 (define-key map "\M-\C-i" 'idlwave-complete)
1499 (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
1500 (define-key map "\C-c=" 'idlwave-resolve)
1501 (define-key map
1502 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1503 'idlwave-mouse-context-help)
1504 map)
1505 "Keymap used in IDL mode.")
1507 (defvar idlwave-mode-syntax-table
1508 (let ((st (make-syntax-table)))
1509 (modify-syntax-entry ?+ "." st)
1510 (modify-syntax-entry ?- "." st)
1511 (modify-syntax-entry ?* "." st)
1512 (modify-syntax-entry ?/ "." st)
1513 (modify-syntax-entry ?^ "." st)
1514 (modify-syntax-entry ?# "." st)
1515 (modify-syntax-entry ?= "." st)
1516 (modify-syntax-entry ?% "." st)
1517 (modify-syntax-entry ?< "." st)
1518 (modify-syntax-entry ?> "." st)
1519 (modify-syntax-entry ?\' "\"" st)
1520 (modify-syntax-entry ?\" "\"" st)
1521 (modify-syntax-entry ?\\ "." 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 ?\n ">" st)
1529 (modify-syntax-entry ?\f ">" st)
1531 "Syntax table in use in `idlwave-mode' buffers.")
1533 (defvar idlwave-find-symbol-syntax-table
1534 (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
1535 (modify-syntax-entry ?$ "w" st)
1536 (modify-syntax-entry ?_ "w" st)
1537 (modify-syntax-entry ?! "w" st)
1538 (modify-syntax-entry ?. "w" st)
1540 "Syntax table that treats symbol characters as word characters.")
1542 (defmacro idlwave-with-special-syntax (&rest body)
1543 "Execute BODY with a different syntax table."
1544 `(let ((saved-syntax (syntax-table)))
1545 (unwind-protect
1546 (progn
1547 (set-syntax-table idlwave-find-symbol-syntax-table)
1548 ,@body)
1549 (set-syntax-table saved-syntax))))
1551 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1552 ; "Execute BODY with a different syntax table."
1553 ; `(let ((saved-syntax (syntax-table)))
1554 ; (unwind-protect
1555 ; (progn
1556 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1557 ; ,@body)
1558 ; (set-syntax-table saved-syntax))))
1560 (defun idlwave-action-and-binding (key cmd &optional select)
1561 "KEY and CMD are made into a key binding and an indent action.
1562 KEY is a string - same as for the `define-key' function. CMD is a
1563 function of no arguments or a list to be evaluated. CMD is bound to
1564 KEY in `idlwave-mode-map' by defining an anonymous function calling
1565 `self-insert-command' followed by CMD. If KEY contains more than one
1566 character a binding will only be set if SELECT is 'both.
1568 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1569 replacing any previous value for KEY. If a binding is not set then it
1570 will instead be placed in `idlwave-indent-action-table'.
1572 If the optional argument SELECT is nil then an action and binding are
1573 created. If SELECT is 'noaction, then a binding is always set and no
1574 action is created. If SELECT is 'both then an action and binding
1575 will both be created even if KEY contains more than one character.
1576 Otherwise, if SELECT is non-nil then only an action is created.
1578 Some examples:
1579 No spaces before and 1 after a comma
1580 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1581 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1582 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1583 Capitalize system variables - action only
1584 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1585 (if (not (equal select 'noaction))
1586 ;; Add action
1587 (let* ((table (if select 'idlwave-indent-action-table
1588 'idlwave-indent-expand-table))
1589 (table-key (regexp-quote key))
1590 (cell (assoc table-key (eval table))))
1591 (if cell
1592 ;; Replace action command
1593 (setcdr cell cmd)
1594 ;; New action
1595 (set table (append (eval table) (list (cons table-key cmd)))))))
1596 ;; Make key binding for action
1597 (if (or (and (null select) (= (length key) 1))
1598 (equal select 'noaction)
1599 (equal select 'both))
1600 (define-key idlwave-mode-map key
1601 `(lambda ()
1602 (interactive)
1603 (self-insert-command 1)
1604 ,(if (listp cmd) cmd (list cmd))))))
1606 ;; Set action and key bindings.
1607 ;; See description of the function `idlwave-action-and-binding'.
1608 ;; Automatically add spaces for the following characters
1610 ;; Actions for & are complicated by &&
1611 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1613 ;; Automatically add spaces to equal sign if not keyword. This needs
1614 ;; to go ahead of > and <, so >= and <= will be treated correctly
1615 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1617 ;; Actions for > and < are complicated by >=, <=, and ->...
1618 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1619 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1621 (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1625 ;;; Abbrev Section
1627 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1628 ;;; space is inserted (this is the space typed by the user to expanded
1629 ;;; the abbrev).
1631 (defvar idlwave-mode-abbrev-table nil
1632 "Abbreviation table used for IDLWAVE mode.")
1633 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1635 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1636 "Define-abbrev with backward compatibility.
1638 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1639 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1640 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1641 (args (list (or table idlwave-mode-abbrev-table)
1642 (if noprefix name (concat idlwave-abbrev-start-char name))
1643 expansion
1644 hook)))
1645 (condition-case nil
1646 (apply 'define-abbrev (append args '(0 t)))
1647 (error (apply 'define-abbrev args)))))
1649 (condition-case nil
1650 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1651 "w" idlwave-mode-syntax-table)
1652 (error nil))
1655 ;; Templates
1657 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1658 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1659 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1660 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1661 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1662 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1663 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1664 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1665 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1667 ;; Keywords, system functions, conversion routines
1669 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1671 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1672 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1673 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1680 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1681 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1683 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1684 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1685 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1686 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1687 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1688 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1689 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1690 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1692 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1695 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1705 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1713 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1714 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1715 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1716 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1718 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1720 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1721 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1723 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1724 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1726 ;; This section is reserved words only. (From IDL user manual)
1728 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1729 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1730 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1731 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1732 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1733 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1734 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1735 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1736 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1737 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1739 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1740 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1741 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1742 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1743 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1744 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1745 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1746 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1760 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1761 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1762 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1763 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1764 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1765 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1766 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1768 (defvar imenu-create-index-function)
1769 (defvar extract-index-name-function)
1770 (defvar prev-index-position-function)
1771 (defvar imenu-extract-index-name-function)
1772 (defvar imenu-prev-index-position-function)
1773 ;; defined later - so just make the compiler hush
1774 (defvar idlwave-mode-menu)
1775 (defvar idlwave-mode-debug-menu)
1777 ;;;###autoload
1778 (defun idlwave-mode ()
1779 "Major mode for editing IDL source files (version 6.1_em22).
1781 The main features of this mode are
1783 1. Indentation and Formatting
1784 --------------------------
1785 Like other Emacs programming modes, C-j inserts a newline and indents.
1786 TAB is used for explicit indentation of the current line.
1788 To start a continuation line, use \\[idlwave-split-line]. This
1789 function can also be used in the middle of a line to split the line
1790 at that point. When used inside a long constant string, the string
1791 is split at that point with the `+' concatenation operator.
1793 Comments are indented as follows:
1795 `;;;' Indentation remains unchanged.
1796 `;;' Indent like the surrounding code
1797 `;' Indent to a minimum column.
1799 The indentation of comments starting in column 0 is never changed.
1801 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1802 comment. The indentation of the second line of the paragraph
1803 relative to the first will be retained. Use
1804 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1805 comments. When the variable `idlwave-fill-comment-line-only' is
1806 nil, code can also be auto-filled and auto-indented.
1808 To convert pre-existing IDL code to your formatting style, mark the
1809 entire buffer with \\[mark-whole-buffer] and execute
1810 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1811 again followed by \\[indent-region] (`indent-region').
1813 2. Routine Info
1814 ------------
1815 IDLWAVE displays information about the calling sequence and the
1816 accepted keyword parameters of a procedure or function with
1817 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1818 source file of a module. These commands know about system
1819 routines, all routines in idlwave-mode buffers and (when the
1820 idlwave-shell is active) about all modules currently compiled under
1821 this shell. It also makes use of pre-compiled or custom-scanned
1822 user and library catalogs many popular libraries ship with by
1823 default. Use \\[idlwave-update-routine-info] to update this
1824 information, which is also used for completion (see item 4).
1826 3. Online IDL Help
1827 ---------------
1829 \\[idlwave-context-help] displays the IDL documentation relevant
1830 for the system variable, keyword, or routines at point. A single
1831 key stroke gets you directly to the right place in the docs. See
1832 the manual to configure where and how the HTML help is displayed.
1834 4. Completion
1835 ----------
1836 \\[idlwave-complete] completes the names of procedures, functions
1837 class names, keyword parameters, system variables and tags, class
1838 tags, structure tags, filenames and much more. It is context
1839 sensitive and figures out what is expected at point. Lower case
1840 strings are completed in lower case, other strings in mixed or
1841 upper case.
1843 5. Code Templates and Abbreviations
1844 --------------------------------
1845 Many Abbreviations are predefined to expand to code fragments and templates.
1846 The abbreviations start generally with a `\\`. Some examples:
1848 \\pr PROCEDURE template
1849 \\fu FUNCTION template
1850 \\c CASE statement template
1851 \\sw SWITCH statement template
1852 \\f FOR loop template
1853 \\r REPEAT Loop template
1854 \\w WHILE loop template
1855 \\i IF statement template
1856 \\elif IF-ELSE statement template
1857 \\b BEGIN
1859 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1860 have direct keybindings - see the list of keybindings below.
1862 \\[idlwave-doc-header] inserts a documentation header at the
1863 beginning of the current program unit (pro, function or main).
1864 Change log entries can be added to the current program unit with
1865 \\[idlwave-doc-modification].
1867 6. Automatic Case Conversion
1868 -------------------------
1869 The case of reserved words and some abbrevs is controlled by
1870 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1872 7. Automatic END completion
1873 ------------------------
1874 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1875 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1877 8. Hooks
1878 -----
1879 Loading idlwave.el runs `idlwave-load-hook'.
1880 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1882 9. Documentation and Customization
1883 -------------------------------
1884 Info documentation for this package is available. Use
1885 \\[idlwave-info] to display (complain to your sysadmin if that does
1886 not work). For Postscript, PDF, and HTML versions of the
1887 documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
1888 IDLWAVE has customize support - see the group `idlwave'.
1890 10.Keybindings
1891 -----------
1892 Here is a list of all keybindings of this mode.
1893 If some of the key bindings below show with ??, use \\[describe-key]
1894 followed by the key sequence to see what the key sequence does.
1896 \\{idlwave-mode-map}"
1898 (interactive)
1899 (kill-all-local-variables)
1901 (if idlwave-startup-message
1902 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1903 (setq idlwave-startup-message nil)
1905 (setq local-abbrev-table idlwave-mode-abbrev-table)
1906 (set-syntax-table idlwave-mode-syntax-table)
1908 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1910 (make-local-variable idlwave-comment-indent-function)
1911 (set idlwave-comment-indent-function 'idlwave-comment-hook)
1913 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1914 (set (make-local-variable 'comment-start) ";")
1915 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
1916 (set (make-local-variable 'require-final-newline) t)
1917 (set (make-local-variable 'abbrev-all-caps) t)
1918 (set (make-local-variable 'indent-tabs-mode) nil)
1919 (set (make-local-variable 'completion-ignore-case) t)
1921 (use-local-map idlwave-mode-map)
1923 (when (featurep 'easymenu)
1924 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1925 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1927 (setq mode-name "IDLWAVE")
1928 (setq major-mode 'idlwave-mode)
1929 (setq abbrev-mode t)
1931 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1932 (setq comment-end "")
1933 (set (make-local-variable 'comment-multi-line) nil)
1934 (set (make-local-variable 'paragraph-separate)
1935 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1936 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1937 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1938 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1940 ;; ChangeLog
1941 (set (make-local-variable 'add-log-current-defun-function)
1942 'idlwave-current-routine-fullname)
1944 ;; Set tag table list to use IDLTAGS as file name.
1945 (if (boundp 'tag-table-alist)
1946 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1948 ;; Font-lock additions
1949 ;; Following line is for Emacs - XEmacs uses the corresponding property
1950 ;; on the `idlwave-mode' symbol.
1951 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1952 (set (make-local-variable 'font-lock-mark-block-function)
1953 'idlwave-mark-subprogram)
1954 (set (make-local-variable 'font-lock-fontify-region-function)
1955 'idlwave-font-lock-fontify-region)
1957 ;; Imenu setup
1958 (set (make-local-variable 'imenu-create-index-function)
1959 'imenu-default-create-index-function)
1960 (set (make-local-variable 'imenu-extract-index-name-function)
1961 'idlwave-unit-name)
1962 (set (make-local-variable 'imenu-prev-index-position-function)
1963 'idlwave-prev-index-position)
1965 ;; HideShow setup
1966 (add-to-list 'hs-special-modes-alist
1967 (list 'idlwave-mode
1968 idlwave-begin-block-reg
1969 idlwave-end-block-reg
1971 'idlwave-forward-block nil))
1973 ;; Make a local post-command-hook and add our hook to it
1974 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1975 ;; (make-local-hook 'post-command-hook)
1976 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1978 ;; Make local hooks for buffer updates
1979 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1980 ;; (make-local-hook 'kill-buffer-hook)
1981 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1982 ;; (make-local-hook 'after-save-hook)
1983 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1984 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1986 ;; Setup directories and file, if necessary
1987 (idlwave-setup)
1989 ;; Update the routine info with info about current buffer?
1990 (idlwave-new-buffer-update)
1992 ;; Check help location
1993 (idlwave-help-check-locations)
1995 ;; Run the mode hook
1996 (run-mode-hooks 'idlwave-mode-hook))
1998 (defvar idlwave-setup-done nil)
1999 (defun idlwave-setup ()
2000 (unless idlwave-setup-done
2001 (if (not (file-directory-p idlwave-config-directory))
2002 (make-directory idlwave-config-directory))
2003 (setq
2004 idlwave-user-catalog-file (expand-file-name
2005 idlwave-user-catalog-file
2006 idlwave-config-directory)
2007 idlwave-xml-system-rinfo-converted-file
2008 (expand-file-name
2009 idlwave-xml-system-rinfo-converted-file
2010 idlwave-config-directory)
2011 idlwave-path-file (expand-file-name
2012 idlwave-path-file
2013 idlwave-config-directory))
2014 (idlwave-read-paths) ; we may need these early
2015 (setq idlwave-setup-done t)))
2017 (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
2018 "Fontify continuation lines correctly."
2019 (let (pos)
2020 (save-excursion
2021 (goto-char beg)
2022 (forward-line -1)
2023 (when (setq pos (idlwave-is-continuation-line))
2024 (goto-char pos)
2025 (idlwave-beginning-of-statement)
2026 (setq beg (point)))))
2027 (font-lock-default-fontify-region beg end verbose))
2030 ;; Code Formatting ----------------------------------------------------
2033 (defun idlwave-hard-tab ()
2034 "Insert TAB in buffer in current position."
2035 (interactive)
2036 (insert "\t"))
2038 ;;; This stuff is experimental
2040 (defvar idlwave-command-hook nil
2041 "If non-nil, a list that can be evaluated using `eval'.
2042 It is evaluated in the lisp function `idlwave-command-hook' which is
2043 placed in `post-command-hook'.")
2045 (defun idlwave-command-hook ()
2046 "Command run after every command.
2047 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2048 sets the variable to zero afterwards."
2049 (and idlwave-command-hook
2050 (listp idlwave-command-hook)
2051 (condition-case nil
2052 (eval idlwave-command-hook)
2053 (error nil)))
2054 (setq idlwave-command-hook nil))
2056 ;;; End experiment
2058 ;; It would be better to use expand.el for better abbrev handling and
2059 ;; versatility.
2061 (defun idlwave-check-abbrev (arg &optional reserved)
2062 "Reverse abbrev expansion if in comment or string.
2063 Argument ARG is the number of characters to move point
2064 backward if `idlwave-abbrev-move' is non-nil.
2065 If optional argument RESERVED is non-nil then the expansion
2066 consists of reserved words, which will be capitalized if
2067 `idlwave-reserved-word-upcase' is non-nil.
2068 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2069 is non-nil, unless its value is \`down in which case the abbrev will be
2070 made into all lowercase.
2071 Returns non-nil if abbrev is left expanded."
2072 (if (idlwave-quoted)
2073 (progn (unexpand-abbrev)
2074 nil)
2075 (if (and reserved idlwave-reserved-word-upcase)
2076 (upcase-region last-abbrev-location (point))
2077 (cond
2078 ((equal idlwave-abbrev-change-case 'down)
2079 (downcase-region last-abbrev-location (point)))
2080 (idlwave-abbrev-change-case
2081 (upcase-region last-abbrev-location (point)))))
2082 (if (and idlwave-abbrev-move (> arg 0))
2083 (if (boundp 'post-command-hook)
2084 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2085 (backward-char arg)))
2088 (defun idlwave-in-comment ()
2089 "Return t if point is inside a comment, nil otherwise."
2090 (save-excursion
2091 (let ((here (point)))
2092 (and (idlwave-goto-comment) (> here (point))))))
2094 (defun idlwave-goto-comment ()
2095 "Move to start of comment delimiter on current line.
2096 Moves to end of line if there is no comment delimiter.
2097 Ignores comment delimiters in strings.
2098 Returns point if comment found and nil otherwise."
2099 (let ((eos (progn (end-of-line) (point)))
2100 (data (match-data))
2101 found)
2102 ;; Look for first comment delimiter not in a string
2103 (beginning-of-line)
2104 (setq found (search-forward comment-start eos 'lim))
2105 (while (and found (idlwave-in-quote))
2106 (setq found (search-forward comment-start eos 'lim)))
2107 (store-match-data data)
2108 (and found (not (idlwave-in-quote))
2109 (progn
2110 (backward-char 1)
2111 (point)))))
2113 (defun idlwave-region-active-p ()
2114 "Should we operate on an active region?"
2115 (if (fboundp 'use-region-p)
2116 (use-region-p)
2117 (region-active-p)))
2119 (defun idlwave-show-matching-quote ()
2120 "Insert quote and show matching quote if this is end of a string."
2121 (interactive)
2122 (let ((bq (idlwave-in-quote))
2123 (inq last-command-event))
2124 (if (and bq (not (idlwave-in-comment)))
2125 (let ((delim (char-after bq)))
2126 (insert inq)
2127 (if (eq inq delim)
2128 (save-excursion
2129 (goto-char bq)
2130 (sit-for 1))))
2131 ;; Not the end of a string
2132 (insert inq))))
2134 (defun idlwave-show-begin-check ()
2135 "Ensure that the previous word was a token before `idlwave-show-begin'.
2136 An END token must be preceded by whitespace."
2137 (if (not (idlwave-quoted))
2139 (save-excursion
2140 (backward-word 1)
2141 (backward-char 1)
2142 (looking-at "[ \t\n\f]"))
2143 (idlwave-show-begin))))
2145 (defun idlwave-show-begin ()
2146 "Find the start of current block and blinks to it for a second.
2147 Also checks if the correct END statement has been used."
2148 ;; All end statements are reserved words
2149 ;; Re-indent end line
2150 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2151 ;;(backward-char 1)
2152 (let* ((pos (point-marker))
2153 (last-abbrev-marker (copy-marker last-abbrev-location))
2154 (eol-pos (save-excursion (end-of-line) (point)))
2155 begin-pos end-pos end end1 )
2156 (if idlwave-reindent-end (idlwave-indent-line))
2157 (setq last-abbrev-location (marker-position last-abbrev-marker))
2158 (when (and (idlwave-check-abbrev 0 t)
2159 idlwave-show-block)
2160 (save-excursion
2161 ;; Move inside current block
2162 (goto-char last-abbrev-marker)
2163 (idlwave-block-jump-out -1 'nomark)
2164 (setq begin-pos (point))
2165 (idlwave-block-jump-out 1 'nomark)
2166 (setq end-pos (point))
2167 (if (> end-pos eol-pos)
2168 (setq end-pos pos))
2169 (goto-char end-pos)
2170 (setq end (buffer-substring
2171 (progn
2172 (skip-chars-backward "a-zA-Z")
2173 (point))
2174 end-pos))
2175 (goto-char begin-pos)
2176 (when (setq end1 (cdr (idlwave-block-master)))
2177 (cond
2178 ((null end1)) ; no-operation
2179 ((string= (downcase end) (downcase end1))
2180 (sit-for 1))
2181 ((string= (downcase end) "end")
2182 ;; A generic end
2183 (if idlwave-expand-generic-end
2184 (save-excursion
2185 (goto-char pos)
2186 (backward-char 3)
2187 (insert (if (string= end "END") (upcase end1) end1))
2188 (delete-char 3)))
2189 (sit-for 1))
2191 (beep)
2192 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2193 end1 end)
2194 (sit-for 1))))))))
2195 ;;(delete-char 1))
2197 (defun idlwave-block-master ()
2198 (let ((case-fold-search t))
2199 (save-excursion
2200 (cond
2201 ((looking-at "pro\\|case\\|switch\\|function\\>")
2202 (assoc (downcase (match-string 0)) idlwave-block-matches))
2203 ((looking-at "begin\\>")
2204 (let ((limit (save-excursion
2205 (idlwave-beginning-of-statement)
2206 (point))))
2207 (cond
2208 ((re-search-backward ":[ \t]*\\=" limit t)
2209 ;; seems to be a case thing
2210 '("begin" . "end"))
2211 ((re-search-backward idlwave-block-match-regexp limit t)
2212 (assoc (downcase (match-string 1))
2213 idlwave-block-matches))
2215 ;; Just a normal block
2216 '("begin" . "end")))))
2217 (t nil)))))
2219 (defun idlwave-close-block ()
2220 "Terminate the current block with the correct END statement."
2221 (interactive)
2222 ;; Start new line if we are not in a new line
2223 (unless (save-excursion
2224 (skip-chars-backward " \t")
2225 (bolp))
2226 (let ((idlwave-show-block nil))
2227 (newline-and-indent)))
2228 (let ((last-abbrev-location (point))) ; for upcasing
2229 (insert "end")
2230 (idlwave-show-begin)))
2232 (defun idlwave-custom-ampersand-surround (&optional is-action)
2233 "Surround &, leaving room for && (which surround as well)."
2234 (let* ((prev-char (char-after (- (point) 2)))
2235 (next-char (char-after (point)))
2236 (amp-left (eq prev-char ?&))
2237 (amp-right (eq next-char ?&))
2238 (len (if amp-left 2 1)))
2239 (unless amp-right ;no need to do it twice, amp-left will catch it.
2240 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2242 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2243 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2244 (let* ((prev-char (char-after (- (point) 2)))
2245 (next-char (char-after (point)))
2246 (method-invoke (and gtr (eq prev-char ?-)))
2247 (len (if method-invoke 2 1)))
2248 (unless (eq next-char ?=)
2249 ;; Key binding: pad only on left, to save for possible >=/<=
2250 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2252 (defun idlwave-surround (&optional before after length is-action)
2253 "Surround the LENGTH characters before point with blanks.
2254 LENGTH defaults to 1.
2255 Optional arguments BEFORE and AFTER affect the behavior before and
2256 after the characters (see also description of `idlwave-make-space'):
2258 nil do nothing
2259 0 force no spaces
2260 integer > 0 force exactly n spaces
2261 integer < 0 at least |n| spaces
2263 The function does nothing if any of the following conditions is true:
2264 - `idlwave-surround-by-blank' is nil
2265 - the character before point is inside a string or comment"
2266 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2267 (let ((length (or length 1))) ; establish a default for LENGTH
2268 (backward-char length)
2269 (save-restriction
2270 (let ((here (point)))
2271 (skip-chars-backward " \t")
2272 (if (bolp)
2273 ;; avoid clobbering indent
2274 (progn
2275 (move-to-column (idlwave-calculate-indent))
2276 (if (<= (point) here)
2277 (narrow-to-region (point) here))
2278 (goto-char here)))
2279 (idlwave-make-space before))
2280 (skip-chars-forward " \t"))
2281 (forward-char length)
2282 (idlwave-make-space after)
2283 ;; Check to see if the line should auto wrap
2284 (if (and (equal (char-after (1- (point))) ?\ )
2285 (> (current-column) fill-column))
2286 (funcall auto-fill-function)))))
2288 (defun idlwave-make-space (n)
2289 "Make space at point.
2290 The space affected is all the spaces and tabs around point.
2291 If n is non-nil then point is left abs(n) spaces from the beginning of
2292 the contiguous space.
2293 The amount of space at point is determined by N.
2294 If the value of N is:
2295 nil - do nothing.
2296 > 0 - exactly N spaces.
2297 < 0 - a minimum of -N spaces, i.e., do not change if there are
2298 already -N spaces.
2299 0 - no spaces (i.e. remove any existing space)."
2300 (if (integerp n)
2301 (let
2302 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2303 (left (point))
2304 (end-col (progn (skip-chars-forward " \t") (current-column))))
2305 (delete-horizontal-space)
2306 (cond
2307 ((> n 0)
2308 (idlwave-indent-to (+ start-col n))
2309 (goto-char (+ left n)))
2310 ((< n 0)
2311 (idlwave-indent-to end-col (- n))
2312 (goto-char (- left n)))
2313 ;; n = 0, done
2314 ))))
2316 (defun idlwave-newline ()
2317 "Insert a newline and indent the current and previous line."
2318 (interactive)
2320 ;; Handle unterminated single and double quotes
2321 ;; If not in a comment and in a string then insertion of a newline
2322 ;; will mean unbalanced quotes.
2324 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2325 (progn (beep)
2326 (message "Warning: unbalanced quotes?")))
2327 (newline)
2329 ;; The current line is being split, the cursor should be at the
2330 ;; beginning of the new line skipping the leading indentation.
2332 ;; The reason we insert the new line before indenting is that the
2333 ;; indenting could be confused by keywords (e.g. END) on the line
2334 ;; after the split point. This prevents us from just using
2335 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2337 (beginning-of-line 0)
2338 (idlwave-indent-line)
2339 (forward-line)
2340 (idlwave-indent-line))
2343 ;; Use global variable 'comment-column' to set parallel comment
2345 ;; Modeled on lisp.el
2346 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2347 (defun idlwave-comment-hook ()
2348 "Compute indent for the beginning of the IDL comment delimiter."
2349 (if (or (looking-at idlwave-no-change-comment)
2350 (looking-at (or idlwave-begin-line-comment "^;")))
2351 (current-column)
2352 (if (looking-at idlwave-code-comment)
2353 (if (save-excursion (skip-chars-backward " \t") (bolp))
2354 ;; On line by itself, indent as code
2355 (let ((tem (idlwave-calculate-indent)))
2356 (if (listp tem) (car tem) tem))
2357 ;; after code - do not change
2358 (current-column))
2359 (skip-chars-backward " \t")
2360 (max (if (bolp) 0 (1+ (current-column)))
2361 comment-column))))
2363 (defun idlwave-split-line ()
2364 "Continue line by breaking line at point and indent the lines.
2365 For a code line insert continuation marker. If the line is a line comment
2366 then the new line will contain a comment with the same indentation.
2367 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2368 non-nil."
2369 (interactive)
2370 ;; Expand abbreviation, just like normal RET would.
2371 (and abbrev-mode (expand-abbrev))
2372 (let (beg)
2373 (if (not (idlwave-in-comment))
2374 ;; For code line add continuation.
2375 ;; Check if splitting a string.
2376 (progn
2377 (if (setq beg (idlwave-in-quote))
2378 (if idlwave-split-line-string
2379 ;; Split the string.
2380 (progn (insert (setq beg (char-after beg)) " + "
2381 idlwave-continuation-char beg)
2382 (backward-char 1)
2383 (newline-and-indent)
2384 (forward-char 1))
2385 ;; Do not split the string.
2386 (beep)
2387 (message "Warning: continuation inside string!!")
2388 (insert " " idlwave-continuation-char))
2389 ;; Not splitting a string.
2390 (if (not (member (char-before) '(?\ ?\t)))
2391 (insert " "))
2392 (insert idlwave-continuation-char)
2393 (newline-and-indent)))
2394 (indent-new-comment-line))
2395 ;; Indent previous line
2396 (setq beg (- (point-max) (point)))
2397 (forward-line -1)
2398 (idlwave-indent-line)
2399 (goto-char (- (point-max) beg))
2400 ;; Reindent new line
2401 (idlwave-indent-line)))
2403 (defun idlwave-beginning-of-subprogram (&optional nomark)
2404 "Move point to the beginning of the current program unit.
2405 If NOMARK is non-nil, do not push mark."
2406 (interactive)
2407 (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
2409 (defun idlwave-end-of-subprogram (&optional nomark)
2410 "Move point to the start of the next program unit.
2411 If NOMARK is non-nil, do not push mark."
2412 (interactive)
2413 (idlwave-end-of-statement)
2414 (idlwave-find-key idlwave-end-unit-reg 1 nomark))
2416 (defun idlwave-mark-statement ()
2417 "Mark current IDL statement."
2418 (interactive)
2419 (idlwave-end-of-statement)
2420 (let ((end (point)))
2421 (idlwave-beginning-of-statement)
2422 (push-mark end nil t)))
2424 (defun idlwave-mark-block ()
2425 "Mark containing block."
2426 (interactive)
2427 (idlwave-end-of-statement)
2428 (idlwave-backward-up-block -1)
2429 (idlwave-end-of-statement)
2430 (let ((end (point)))
2431 (idlwave-backward-block)
2432 (idlwave-beginning-of-statement)
2433 (push-mark end nil t)))
2436 (defun idlwave-mark-subprogram ()
2437 "Put mark at beginning of program, point at end.
2438 The marks are pushed."
2439 (interactive)
2440 (idlwave-end-of-statement)
2441 (idlwave-beginning-of-subprogram)
2442 (let ((beg (point)))
2443 (idlwave-forward-block)
2444 (push-mark beg nil t))
2445 (exchange-point-and-mark))
2447 (defun idlwave-backward-up-block (&optional arg)
2448 "Move to beginning of enclosing block if prefix ARG >= 0.
2449 If prefix ARG < 0 then move forward to enclosing block end."
2450 (interactive "p")
2451 (idlwave-block-jump-out (- arg) 'nomark))
2453 (defun idlwave-beginning-of-block ()
2454 "Go to the beginning of the current block."
2455 (interactive)
2456 (idlwave-block-jump-out -1 'nomark)
2457 (forward-word 1))
2459 (defun idlwave-end-of-block ()
2460 "Go to the beginning of the current block."
2461 (interactive)
2462 (idlwave-block-jump-out 1 'nomark)
2463 (backward-word 1))
2465 (defun idlwave-forward-block (&optional arg)
2466 "Move across next nested block."
2467 (interactive)
2468 (let ((arg (or arg 1)))
2469 (if (idlwave-down-block arg)
2470 (idlwave-block-jump-out arg 'nomark))))
2472 (defun idlwave-backward-block ()
2473 "Move backward across previous nested block."
2474 (interactive)
2475 (if (idlwave-down-block -1)
2476 (idlwave-block-jump-out -1 'nomark)))
2478 (defun idlwave-down-block (&optional arg)
2479 "Go down a block.
2480 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2481 Returns non-nil if successfull."
2482 (interactive "p")
2483 (let (status)
2484 (if (< arg 0)
2485 ;; Backward
2486 (let ((eos (save-excursion
2487 (idlwave-block-jump-out -1 'nomark)
2488 (point))))
2489 (if (setq status (idlwave-find-key
2490 idlwave-end-block-reg -1 'nomark eos))
2491 (idlwave-beginning-of-statement)
2492 (message "No nested block before beginning of containing block.")))
2493 ;; Forward
2494 (let ((eos (save-excursion
2495 (idlwave-block-jump-out 1 'nomark)
2496 (point))))
2497 (if (setq status (idlwave-find-key
2498 idlwave-begin-block-reg 1 'nomark eos))
2499 (idlwave-end-of-statement)
2500 (message "No nested block before end of containing block."))))
2501 status))
2503 (defun idlwave-mark-doclib ()
2504 "Put point at beginning of doc library header, mark at end.
2505 The marks are pushed."
2506 (interactive)
2507 (let (beg
2508 (here (point)))
2509 (goto-char (point-max))
2510 (if (re-search-backward idlwave-doclib-start nil t)
2511 (progn
2512 (setq beg (progn (beginning-of-line) (point)))
2513 (if (re-search-forward idlwave-doclib-end nil t)
2514 (progn
2515 (forward-line 1)
2516 (push-mark beg nil t)
2517 (message "Could not find end of doc library header.")))
2518 (message "Could not find doc library header start.")
2519 (goto-char here)))))
2521 (defun idlwave-current-routine-fullname ()
2522 (let ((name (idlwave-current-routine)))
2523 (idlwave-make-full-name (nth 2 name) (car name))))
2525 (defun idlwave-current-routine ()
2526 "Return (NAME TYPE CLASS) of current routine."
2527 (idlwave-routines)
2528 (save-excursion
2529 (idlwave-beginning-of-subprogram 'nomark)
2530 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2531 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2532 'pro 'function))
2533 (class (idlwave-sintern-class (match-string 3)))
2534 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2535 (list name type class)))))
2537 (defvar idlwave-shell-prompt-pattern)
2538 (defun idlwave-beginning-of-statement ()
2539 "Move to beginning of the current statement.
2540 Skips back past statement continuations.
2541 Point is placed at the beginning of the line whether or not this is an
2542 actual statement."
2543 (interactive)
2544 (cond
2545 ((eq major-mode 'idlwave-shell-mode)
2546 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2547 (goto-char (match-end 0))))
2549 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2550 (idlwave-previous-statement)
2551 (beginning-of-line)))))
2553 (defun idlwave-previous-statement ()
2554 "Move point to beginning of the previous statement.
2555 Returns t if the current line before moving is the beginning of
2556 the first non-comment statement in the file, and nil otherwise."
2557 (interactive)
2558 (let (first-statement)
2559 (if (not (= (forward-line -1) 0))
2560 ;; first line in file
2562 ;; skip blank lines, label lines, include lines and line comments
2563 (while (and
2564 ;; The current statement is the first statement until we
2565 ;; reach another statement.
2566 (setq first-statement
2568 (looking-at idlwave-comment-line-start-skip)
2569 (looking-at "[ \t]*$")
2570 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2571 (looking-at "^@")))
2572 (= (forward-line -1) 0)))
2573 ;; skip continuation lines
2574 (while (and
2575 (save-excursion
2576 (forward-line -1)
2577 (idlwave-is-continuation-line))
2578 (= (forward-line -1) 0)))
2579 first-statement)))
2581 (defun idlwave-end-of-statement ()
2582 "Move point to the end of the current IDL statement.
2583 If not in a statement just moves to end of line. Returns position."
2584 (interactive)
2585 (while (and (idlwave-is-continuation-line)
2586 (= (forward-line 1) 0))
2587 (while (and (idlwave-is-comment-or-empty-line)
2588 (= (forward-line 1) 0))))
2589 (end-of-line)
2590 (point))
2592 (defun idlwave-end-of-statement0 ()
2593 "Move point to the end of the current IDL statement.
2594 If not in a statement just moves to end of line. Returns position."
2595 (interactive)
2596 (while (and (idlwave-is-continuation-line)
2597 (= (forward-line 1) 0)))
2598 (end-of-line)
2599 (point))
2601 (defun idlwave-next-statement ()
2602 "Move point to beginning of the next IDL statement.
2603 Returns t if that statement is the last non-comment IDL statement
2604 in the file, and nil otherwise."
2605 (interactive)
2606 (let (last-statement)
2607 (idlwave-end-of-statement)
2608 ;; skip blank lines, label lines, include lines and line comments
2609 (while (and (= (forward-line 1) 0)
2610 ;; The current statement is the last statement until
2611 ;; we reach a new statement.
2612 (setq last-statement
2614 (looking-at idlwave-comment-line-start-skip)
2615 (looking-at "[ \t]*$")
2616 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2617 (looking-at "^@")))))
2618 last-statement))
2620 (defun idlwave-skip-multi-commands (&optional lim)
2621 "Skip past multiple commands on a line (with `&')."
2622 (let ((save-point (point)))
2623 (when (re-search-forward ".*&" lim t)
2624 (goto-char (match-end 0))
2625 (if (idlwave-quoted)
2626 (goto-char save-point)
2627 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2628 (point)))
2630 (defun idlwave-skip-label-or-case ()
2631 "Skip label or case statement element.
2632 Returns position after label.
2633 If there is no label point is not moved and nil is returned."
2634 ;; Case expressions and labels are terminated by a colon.
2635 ;; So we find the first colon in the line and make sure
2636 ;; - no `?' is before it (might be a ? b : c)
2637 ;; - it is not in a comment
2638 ;; - not in a string constant
2639 ;; - not in parenthesis (like a[0:3])
2640 ;; - not followed by another ":" in explicit class, ala a->b::c
2641 ;; As many in this mode, this function is heuristic and not an exact
2642 ;; parser.
2643 (let* ((start (point))
2644 (eos (save-excursion (idlwave-end-of-statement) (point)))
2645 (end (idlwave-find-key ":" 1 'nomark eos)))
2646 (if (and end
2647 (= (nth 0 (parse-partial-sexp start end)) 0)
2648 (not (string-match "\\?" (buffer-substring start end)))
2649 (not (string-match "^::" (buffer-substring end eos))))
2650 (progn
2651 (forward-char)
2652 (point))
2653 (goto-char start)
2654 nil)))
2656 (defun idlwave-start-of-substatement (&optional pre)
2657 "Move to start of next IDL substatement after point.
2658 Uses the type of the current IDL statement to determine if the next
2659 statement is on a new line or is a subpart of the current statement.
2660 Returns point at start of substatement modulo whitespace.
2661 If optional argument is non-nil move to beginning of current
2662 substatement."
2663 (let ((orig (point))
2664 (eos (idlwave-end-of-statement))
2665 (ifnest 0)
2666 st nst last)
2667 (idlwave-beginning-of-statement)
2668 (idlwave-skip-label-or-case)
2669 (if (< (point) orig)
2670 (idlwave-skip-multi-commands orig))
2671 (setq last (point))
2672 ;; Continue looking for substatements until we are past orig
2673 (while (and (<= (point) orig) (not (eobp)))
2674 (setq last (point))
2675 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2676 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2677 (cond ((and nst
2678 (idlwave-find-key nst 1 'nomark eos))
2679 (goto-char (match-end 0)))
2680 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2681 (setq ifnest (1- ifnest))
2682 (goto-char (match-end 0)))
2683 (t (setq ifnest 0)
2684 (idlwave-next-statement))))
2685 (if pre (goto-char last))
2686 ;; If a continuation line starts here, move to next line
2687 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2688 (beginning-of-line 2))
2689 (point)))
2691 (defun idlwave-statement-type ()
2692 "Return the type of the current IDL statement.
2693 Uses `idlwave-statement-match' to return a cons of (type . point) with
2694 point the ending position where the type was determined. Type is the
2695 association from `idlwave-statement-match', i.e. the cons cell from the
2696 list not just the type symbol. Returns nil if not an identifiable
2697 statement."
2698 (save-excursion
2699 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2700 ;; and possibly comments
2701 (while (looking-at "[ \t]*\\$")
2702 (forward-line 1))
2703 (skip-chars-forward " \t")
2704 (let ((st idlwave-statement-match)
2705 (case-fold-search t))
2706 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2707 (setq st (cdr st))))
2708 (if st
2709 (append st (match-end 0))))))
2711 (defun idlwave-expand-equal (&optional before after is-action)
2712 "Pad '=' with spaces.
2713 Two cases: Assignment statement, and keyword assignment.
2714 Which case is determined using `idlwave-start-of-substatement' and
2715 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2716 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2717 is treated just like assignment statements. When nil, spaces are
2718 removed for keyword assignment. Any other value keeps the current space
2719 around the `='. Limits in for loops are treated as keyword assignment.
2721 Starting with IDL 6.0, a number of op= assignments are available.
2722 Since ambiguities of the form:
2724 r and= b
2725 rand= b
2727 can occur, alphanumeric operator assignment will never be pre-padded,
2728 only post-padded. You must use a space before these to disambiguate
2729 \(not just for padding, but for proper parsing by IDL too!). Other
2730 operators, such as ##=, ^=, etc., will be pre-padded.
2732 IS-ACTION is ignored.
2734 See `idlwave-surround'."
2735 (if idlwave-surround-by-blank
2736 (let
2737 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2738 (an-ops
2739 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2740 (len 1))
2742 (save-excursion
2743 (let ((case-fold-search t))
2744 (backward-char)
2745 (if (or
2746 (re-search-backward non-an-ops nil t)
2747 ;; Why doesn't ##? work for both?
2748 (re-search-backward "\\(#\\)\\=" nil t))
2749 (setq len (1+ (length (match-string 1))))
2750 (when (re-search-backward an-ops nil t)
2751 ;(setq begin nil) ; won't modify begin
2752 (setq len (1+ (length (match-string 1))))))))
2754 (if (eq t idlwave-pad-keyword)
2755 ;; Everything gets padded equally
2756 (idlwave-surround before after len)
2757 ;; Treating keywords/for variables specially...
2758 (let ((st (save-excursion ; To catch "for" variables
2759 (idlwave-start-of-substatement t)
2760 (idlwave-statement-type)))
2761 (what (save-excursion ; To catch keywords
2762 (skip-chars-backward "= \t")
2763 (nth 2 (idlwave-where)))))
2764 (cond ((or (memq what '(function-keyword procedure-keyword))
2765 (memq (caar st) '(for pdef)))
2766 (cond
2767 ((null idlwave-pad-keyword)
2768 (idlwave-surround 0 0)
2769 ) ; remove space
2770 (t))) ; leave any spaces alone
2771 (t (idlwave-surround before after len))))))))
2774 (defun idlwave-indent-and-action (&optional arg)
2775 "Call `idlwave-indent-line' and do expand actions.
2776 With prefix ARG non-nil, indent the entire sub-statement."
2777 (interactive "p")
2778 (save-excursion
2779 (if (and idlwave-expand-generic-end
2780 (re-search-backward "\\<\\(end\\)\\s-*\\="
2781 (max 0 (- (point) 10)) t)
2782 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2783 (progn (goto-char (match-end 1))
2784 ;;Expand the END abbreviation, just as RET or Space would have.
2785 (if abbrev-mode (expand-abbrev)
2786 (idlwave-show-begin)))))
2787 (when (and (not arg) current-prefix-arg)
2788 (setq arg current-prefix-arg)
2789 (setq current-prefix-arg nil))
2790 (if arg
2791 (idlwave-indent-statement)
2792 (idlwave-indent-line t)))
2794 (defun idlwave-indent-line (&optional expand)
2795 "Indent current IDL line as code or as a comment.
2796 The actions in `idlwave-indent-action-table' are performed.
2797 If the optional argument EXPAND is non-nil then the actions in
2798 `idlwave-indent-expand-table' are performed."
2799 (interactive)
2800 ;; Move point out of left margin.
2801 (if (save-excursion
2802 (skip-chars-backward " \t")
2803 (bolp))
2804 (skip-chars-forward " \t"))
2805 (let ((mloc (point-marker)))
2806 (save-excursion
2807 (beginning-of-line)
2808 (if (looking-at idlwave-comment-line-start-skip)
2809 ;; Indentation for a line comment
2810 (progn
2811 (skip-chars-forward " \t")
2812 (idlwave-indent-left-margin (idlwave-comment-hook)))
2814 ;; Code Line
2816 ;; Before indenting, run action routines.
2818 (if (and expand idlwave-do-actions)
2819 (mapc 'idlwave-do-action idlwave-indent-expand-table))
2821 (if idlwave-do-actions
2822 (mapc 'idlwave-do-action idlwave-indent-action-table))
2824 ;; No longer expand abbrevs on the line. The user can do this
2825 ;; manually using expand-region-abbrevs.
2827 ;; Indent for code line
2829 (beginning-of-line)
2830 (if (or
2831 ;; a label line
2832 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2833 ;; a batch command
2834 (looking-at "^[ \t]*@"))
2835 ;; leave flush left
2837 ;; indent the line
2838 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2839 ;; Adjust parallel comment
2840 (end-of-line)
2841 (if (idlwave-in-comment)
2842 ;; Emacs 21 is too smart with fill-column on comment indent
2843 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2844 (1- (frame-width))
2845 fill-column)))
2846 (indent-for-comment)))))
2847 (goto-char mloc)
2848 ;; Get rid of marker
2849 (set-marker mloc nil)))
2851 (defun idlwave-do-action (action)
2852 "Perform an action repeatedly on a line.
2853 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2854 either a function name to be called with `funcall' or a list to be
2855 evaluated with `eval'. The action performed by FUNC should leave
2856 point after the match for REG - otherwise an infinite loop may be
2857 entered. FUNC is always passed a final argument of 'is-action, so it
2858 can discriminate between being run as an action, or a key binding."
2859 (let ((action-key (car action))
2860 (action-routine (cdr action)))
2861 (beginning-of-line)
2862 (while (idlwave-look-at action-key)
2863 (if (listp action-routine)
2864 (eval (append action-routine '('is-action)))
2865 (funcall action-routine 'is-action)))))
2867 (defun idlwave-indent-to (col &optional min)
2868 "Indent from point with spaces until column COL.
2869 Inserts space before markers at point."
2870 (if (not min) (setq min 0))
2871 (insert-before-markers
2872 (make-string (max min (- col (current-column))) ?\ )))
2874 (defun idlwave-indent-left-margin (col)
2875 "Indent the current line to column COL.
2876 Indents such that first non-whitespace character is at column COL
2877 Inserts spaces before markers at point."
2878 (save-excursion
2879 (beginning-of-line)
2880 (delete-horizontal-space)
2881 (idlwave-indent-to col)))
2883 (defun idlwave-indent-subprogram ()
2884 "Indent program unit which contains point."
2885 (interactive)
2886 (save-excursion
2887 (idlwave-end-of-statement)
2888 (idlwave-beginning-of-subprogram)
2889 (let ((beg (point)))
2890 (idlwave-forward-block)
2891 (message "Indenting subprogram...")
2892 (indent-region beg (point) nil))
2893 (message "Indenting subprogram...done.")))
2895 (defun idlwave-indent-statement ()
2896 "Indent current statement, including all continuation lines."
2897 (interactive)
2898 (save-excursion
2899 (idlwave-beginning-of-statement)
2900 (let ((beg (point)))
2901 (idlwave-end-of-statement)
2902 (indent-region beg (point) nil))))
2904 (defun idlwave-calculate-indent ()
2905 "Return appropriate indentation for current line as IDL code."
2906 (save-excursion
2907 (beginning-of-line)
2908 (cond
2909 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2910 ;; function
2911 ((idlwave-look-at idlwave-begin-unit-reg)
2913 ;; Check for continuation line
2914 ((save-excursion
2915 (and (= (forward-line -1) 0)
2916 (idlwave-is-continuation-line)))
2917 (idlwave-calculate-cont-indent))
2918 ;; calculate indent based on previous and current statements
2919 (t (let* (beg-prev-pos
2920 (the-indent
2921 ;; calculate indent based on previous statement
2922 (save-excursion
2923 (cond
2924 ;; Beginning of file
2925 ((prog1
2926 (idlwave-previous-statement)
2927 (setq beg-prev-pos (point)))
2929 ;; Main block
2930 ((idlwave-look-at idlwave-begin-unit-reg t)
2931 (+ (idlwave-current-statement-indent)
2932 idlwave-main-block-indent))
2933 ;; Begin block
2934 ((idlwave-look-at idlwave-begin-block-reg t)
2935 (+ (idlwave-min-current-statement-indent)
2936 idlwave-block-indent))
2937 ;; End Block
2938 ((idlwave-look-at idlwave-end-block-reg t)
2939 (progn
2940 ;; Match to the *beginning* of the block opener
2941 (goto-char beg-prev-pos)
2942 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2943 (idlwave-min-current-statement-indent)))
2944 ;; idlwave-end-offset
2945 ;; idlwave-block-indent))
2947 ;; Default to current indent
2948 ((idlwave-current-statement-indent))))))
2949 ;; adjust the indentation based on the current statement
2950 (cond
2951 ;; End block
2952 ((idlwave-look-at idlwave-end-block-reg)
2953 (+ the-indent idlwave-end-offset))
2954 (the-indent)))))))
2957 ;; Parentheses indent
2960 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2961 "Calculate the continuation indent inside a paren group.
2962 Returns a cons-cell with (open . indent), where open is the
2963 location of the open paren."
2964 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2965 ;; Found an innermost open paren.
2966 (when open
2967 (goto-char open)
2968 ;; Line up with next word unless this is a closing paren.
2969 (cons open
2970 (cond
2971 ;; Plain Kernighan-style nested indent
2972 (idlwave-indent-parens-nested
2973 (+ idlwave-continuation-indent (idlwave-current-indent)))
2975 ;; This is a closed paren - line up under open paren.
2976 (close-exp
2977 (current-column))
2979 ;; Empty (or just comment) follows -- revert to basic indent
2980 ((progn
2981 ;; Skip paren
2982 (forward-char 1)
2983 (looking-at "[ \t$]*\\(;.*\\)?$"))
2984 nil)
2986 ;; Line up with first word after any blank space
2987 ((progn
2988 (skip-chars-forward " \t")
2989 (current-column))))))))
2991 (defun idlwave-calculate-cont-indent ()
2992 "Calculates the IDL continuation indent column from the previous statement.
2993 Note that here previous statement usually means the beginning of the
2994 current statement if this statement is a continuation of the previous
2995 line. Various special types of continuations, including assignments,
2996 routine definitions, and parenthetical groupings, are treated separately."
2997 (save-excursion
2998 (let* ((case-fold-search t)
2999 (end-reg (progn (beginning-of-line) (point)))
3000 (beg-last-statement (save-excursion (idlwave-previous-statement)
3001 (point)))
3002 (beg-reg (progn (idlwave-start-of-substatement 'pre)
3003 (if (eq (line-beginning-position) end-reg)
3004 (goto-char beg-last-statement)
3005 (point))))
3006 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
3007 idlwave-continuation-indent))
3008 fancy-nonparen-indent fancy-paren-indent)
3009 (cond
3010 ;; Align then with its matching if, etc.
3011 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
3012 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
3013 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
3014 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3015 "[ \t]*until")
3016 ("\\<case\\>" . "[ \t]*of")))
3017 match cont-re)
3018 (goto-char end-reg)
3019 (and
3020 (setq cont-re
3021 (catch 'exit
3022 (while (setq match (car matchers))
3023 (if (looking-at (cdr match))
3024 (throw 'exit (car match)))
3025 (setq matchers (cdr matchers)))))
3026 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3027 (if (looking-at "end") ;; that one's special
3028 (- (idlwave-current-indent)
3029 (+ idlwave-block-indent idlwave-end-offset))
3030 (idlwave-current-indent)))
3032 ;; Indent in from the previous line for continuing statements
3033 ((let ((matchers '("\\<then\\>"
3034 "\\<do\\>"
3035 "\\<repeat\\>"
3036 "\\<else\\>"))
3037 match)
3038 (catch 'exit
3039 (goto-char end-reg)
3040 (if (/= (forward-line -1) 0)
3041 (throw 'exit nil))
3042 (while (setq match (car matchers))
3043 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3044 "\\(;.*\\)?$"))
3045 (throw 'exit t))
3046 (setq matchers (cdr matchers)))))
3047 (+ idlwave-continuation-indent (idlwave-current-indent)))
3049 ;; Parenthetical indent, either traditional or Kernighan style
3050 ((setq fancy-paren-indent
3051 (let* ((end-reg end-reg)
3052 (close-exp (progn
3053 (goto-char end-reg)
3054 (skip-chars-forward " \t")
3055 (looking-at "\\s)")))
3056 indent-cons)
3057 (catch 'loop
3058 (while (setq indent-cons (idlwave-calculate-paren-indent
3059 beg-reg end-reg close-exp))
3060 ;; First permitted containing paren
3061 (if (or
3062 idlwave-indent-to-open-paren
3063 idlwave-indent-parens-nested
3064 (null (cdr indent-cons))
3065 (< (- (cdr indent-cons) basic-indent)
3066 idlwave-max-extra-continuation-indent))
3067 (throw 'loop (cdr indent-cons)))
3068 (setq end-reg (car indent-cons))))))
3069 fancy-paren-indent)
3071 ;; A continued assignment, or procedure call/definition
3072 ((and
3073 (> idlwave-max-extra-continuation-indent 0)
3074 (setq fancy-nonparen-indent
3075 (progn
3076 (goto-char beg-reg)
3077 (while (idlwave-look-at "&")) ; skip continued statements
3078 (cond
3079 ;; A continued Procedure call or definition
3080 ((progn
3081 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3082 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3083 (goto-char (match-end 0))
3084 ;; Comment only, or blank line with "$"? Basic indent.
3085 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3087 (current-column)))
3089 ;; Continued assignment (with =):
3090 ((catch 'assign ;
3091 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3092 (goto-char (match-end 0))
3093 (if (null (idlwave-what-function beg-reg))
3094 (throw 'assign t))))
3095 (unless (or
3096 (idlwave-in-quote)
3097 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3098 (save-excursion
3099 (goto-char beg-last-statement)
3100 (eq (caar (idlwave-statement-type)) 'for)))
3101 (current-column))))))
3102 (< (- fancy-nonparen-indent basic-indent)
3103 idlwave-max-extra-continuation-indent))
3104 (if fancy-paren-indent ;calculated but disallowed paren indent
3105 (+ fancy-nonparen-indent idlwave-continuation-indent)
3106 fancy-nonparen-indent))
3108 ;; Basic indent, by default
3109 (t basic-indent)))))
3113 (defun idlwave-find-key (key-re &optional dir nomark limit)
3114 "Move to next match of the regular expression KEY-RE.
3115 Matches inside comments or string constants will be ignored.
3116 If DIR is negative, the search will be backwards.
3117 At a successful match, the mark is pushed unless NOMARK is non-nil.
3118 Searches are limited to LIMIT.
3119 Searches are case-insensitive and use a special syntax table which
3120 treats `$' and `_' as word characters.
3121 Return value is the beginning of the match or (in case of failure) nil."
3122 (setq dir (or dir 0))
3123 (let ((case-fold-search t)
3124 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3125 found)
3126 (idlwave-with-special-syntax
3127 (save-excursion
3128 (catch 'exit
3129 (while (funcall search-func key-re limit t)
3130 (if (not (idlwave-quoted))
3131 (throw 'exit (setq found (match-beginning 0)))
3132 (if (or (and (> dir 0) (eobp))
3133 (and (< dir 0) (bobp)))
3134 (throw 'exit nil)))))))
3135 (if found
3136 (progn
3137 (if (not nomark) (push-mark))
3138 (goto-char found)
3139 found)
3140 nil)))
3142 (defun idlwave-block-jump-out (&optional dir nomark)
3143 "When optional argument DIR is non-negative, move forward to end of
3144 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3145 regular expressions. When DIR is negative, move backwards to block beginning.
3146 Recursively calls itself to skip over nested blocks. DIR defaults to
3147 forward. Calls `push-mark' unless the optional argument NOMARK is
3148 non-nil. Movement is limited by the start of program units because of
3149 possibility of unbalanced blocks."
3150 (interactive "P")
3151 (or dir (setq dir 0))
3152 (let* ((here (point))
3153 (case-fold-search t)
3154 (limit (if (>= dir 0) (point-max) (point-min)))
3155 (block-limit (if (>= dir 0)
3156 idlwave-begin-block-reg
3157 idlwave-end-block-reg))
3158 found
3159 (block-reg (concat idlwave-begin-block-reg "\\|"
3160 idlwave-end-block-reg))
3161 (unit-limit (or (save-excursion
3162 (if (< dir 0)
3163 (idlwave-find-key
3164 idlwave-begin-unit-reg dir t limit)
3165 (end-of-line)
3166 (idlwave-find-key
3167 idlwave-end-unit-reg dir t limit)))
3168 limit)))
3169 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3170 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3171 (while (and found (looking-at block-limit))
3172 (if (>= dir 0) (forward-word 1))
3173 (idlwave-block-jump-out dir t)
3174 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3175 (if (not nomark) (push-mark here))
3176 (if (not found) (goto-char unit-limit)
3177 (if (>= dir 0) (forward-word 1)))))
3179 (defun idlwave-min-current-statement-indent (&optional end-reg)
3180 "The minimum indent in the current statement."
3181 (idlwave-beginning-of-statement)
3182 (if (not (idlwave-is-continuation-line))
3183 (idlwave-current-indent)
3184 (let ((min (idlwave-current-indent)) comm-or-empty)
3185 (while (and (= (forward-line 1) 0)
3186 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3187 (idlwave-is-continuation-line))
3188 (or (null end-reg) (< (point) end-reg)))
3189 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3190 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3192 (min min (idlwave-current-indent))))))
3194 (defun idlwave-current-statement-indent (&optional last-line)
3195 "Return indentation of the current statement.
3196 If in a statement, moves to beginning of statement before finding indent."
3197 (if last-line
3198 (idlwave-end-of-statement)
3199 (idlwave-beginning-of-statement))
3200 (idlwave-current-indent))
3202 (defun idlwave-current-indent ()
3203 "Return the column of the indentation of the current line.
3204 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3205 (save-excursion
3206 (beginning-of-line)
3207 (skip-chars-forward " \t")
3208 ;; if we are at the end of blank line return 0
3209 (cond ((eolp) 0)
3210 ((current-column)))))
3212 (defun idlwave-is-continuation-line ()
3213 "Test if current line is continuation line.
3214 Blank or comment-only lines following regular continuation lines (with
3215 `$') count as continuations too."
3216 (let (p)
3217 (save-excursion
3219 (idlwave-look-at "\\<\\$")
3220 (catch 'loop
3221 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3222 (eq (forward-line -1) 0))
3223 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
3225 (defun idlwave-is-comment-line ()
3226 "Test if the current line is a comment line."
3227 (save-excursion
3228 (beginning-of-line 1)
3229 (looking-at "[ \t]*;")))
3231 (defun idlwave-is-comment-or-empty-line ()
3232 "Test if the current line is a comment line."
3233 (save-excursion
3234 (beginning-of-line 1)
3235 (looking-at "[ \t]*[;\n]")))
3237 (defun idlwave-look-at (regexp &optional cont beg)
3238 "Search current line from current point for REGEXP.
3239 If optional argument CONT is non-nil, searches to the end of
3240 the current statement.
3241 If optional arg BEG is non-nil, search starts from the beginning of the
3242 current statement.
3243 Ignores matches that end in a comment or inside a string expression.
3244 Returns point if successful, nil otherwise.
3245 This function produces unexpected results if REGEXP contains quotes or
3246 a comment delimiter. The search is case insensitive.
3247 If successful leaves point after the match, otherwise, does not move point."
3248 (let ((here (point))
3249 (case-fold-search t)
3250 (eos (save-excursion
3251 (if cont (idlwave-end-of-statement) (end-of-line))
3252 (point)))
3253 found)
3254 (idlwave-with-special-syntax
3255 (if beg (idlwave-beginning-of-statement))
3256 (while (and (setq found (re-search-forward regexp eos t))
3257 (idlwave-quoted))))
3258 (if (not found) (goto-char here))
3259 found))
3261 (defun idlwave-fill-paragraph (&optional nohang)
3262 "Fill paragraphs in comments.
3263 A paragraph is made up of all contiguous lines having the same comment
3264 leader (the leading whitespace before the comment delimiter and the
3265 comment delimiter). In addition, paragraphs are separated by blank
3266 line comments. The indentation is given by the hanging indent of the
3267 first line, otherwise by the minimum indentation of the lines after
3268 the first line. The indentation of the first line does not change.
3269 Does not effect code lines. Does not fill comments on the same line
3270 with code. The hanging indent is given by the end of the first match
3271 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3272 If the optional argument NOHANG is non-nil then the hanging indent is
3273 ignored."
3274 (interactive "P")
3275 ;; check if this is a line comment
3276 (if (save-excursion
3277 (beginning-of-line)
3278 (skip-chars-forward " \t")
3279 (looking-at comment-start))
3280 (let
3281 ((indent 999)
3282 pre here diff fill-prefix-reg bcl first-indent
3283 hang start end)
3284 ;; Change tabs to spaces in the surrounding paragraph.
3285 ;; The surrounding paragraph will be the largest containing block of
3286 ;; contiguous line comments. Thus, we may be changing tabs in
3287 ;; a much larger area than is needed, but this is the easiest
3288 ;; brute force way to do it.
3290 ;; This has the undesirable side effect of replacing the tabs
3291 ;; permanently without the user's request or knowledge.
3292 (save-excursion
3293 (backward-paragraph)
3294 (setq start (point)))
3295 (save-excursion
3296 (forward-paragraph)
3297 (setq end (point)))
3298 (untabify start end)
3300 (setq here (point))
3301 (beginning-of-line)
3302 (setq bcl (point))
3303 (re-search-forward
3304 (concat "^[ \t]*" comment-start "+")
3305 (save-excursion (end-of-line) (point))
3307 ;; Get the comment leader on the line and its length
3308 (setq pre (current-column))
3309 ;; the comment leader is the indentation plus exactly the
3310 ;; number of consecutive ";".
3311 (setq fill-prefix-reg
3312 (concat
3313 (setq fill-prefix
3314 (regexp-quote
3315 (buffer-substring (save-excursion
3316 (beginning-of-line) (point))
3317 (point))))
3318 "[^;]"))
3320 ;; Mark the beginning and end of the paragraph
3321 (goto-char bcl)
3322 (while (and (looking-at fill-prefix-reg)
3323 (not (looking-at paragraph-separate))
3324 (not (bobp)))
3325 (forward-line -1))
3326 ;; Move to first line of paragraph
3327 (if (/= (point) bcl)
3328 (forward-line 1))
3329 (setq start (point))
3330 (goto-char bcl)
3331 (while (and (looking-at fill-prefix-reg)
3332 (not (looking-at paragraph-separate))
3333 (not (eobp)))
3334 (forward-line 1))
3335 (beginning-of-line)
3336 (if (or (not (looking-at fill-prefix-reg))
3337 (looking-at paragraph-separate))
3338 (forward-line -1))
3339 (end-of-line)
3340 ;; if at end of buffer add a newline (need this because
3341 ;; fill-region needs END to be at the beginning of line after
3342 ;; the paragraph or it will add a line).
3343 (if (eobp)
3344 (progn (insert ?\n) (backward-char 1)))
3345 ;; Set END to the beginning of line after the paragraph
3346 ;; END is calculated as distance from end of buffer
3347 (setq end (- (point-max) (point) 1))
3349 ;; Calculate the indentation for the paragraph.
3351 ;; In the following while statements, after one iteration
3352 ;; point will be at the beginning of a line in which case
3353 ;; the while will not be executed for the
3354 ;; the first paragraph line and thus will not affect the
3355 ;; indentation.
3357 ;; First check to see if indentation is based on hanging indent.
3358 (if (and (not nohang) idlwave-hanging-indent
3359 (setq hang
3360 (save-excursion
3361 (goto-char start)
3362 (idlwave-calc-hanging-indent))))
3363 ;; Adjust lines of paragraph by inserting spaces so that
3364 ;; each line's indent is at least as great as the hanging
3365 ;; indent. This is needed for fill-paragraph to work with
3366 ;; a fill-prefix.
3367 (progn
3368 (setq indent hang)
3369 (beginning-of-line)
3370 (while (> (point) start)
3371 (re-search-forward comment-start-skip
3372 (save-excursion (end-of-line) (point))
3374 (if (> (setq diff (- indent (current-column))) 0)
3375 (progn
3376 (if (>= here (point))
3377 ;; adjust the original location for the
3378 ;; inserted text.
3379 (setq here (+ here diff)))
3380 (insert (make-string diff ?\ ))))
3381 (forward-line -1))
3384 ;; No hang. Instead find minimum indentation of paragraph
3385 ;; after first line.
3386 ;; For the following while statement, since START is at the
3387 ;; beginning of line and END is at the end of line
3388 ;; point is greater than START at least once (which would
3389 ;; be the case for a single line paragraph).
3390 (while (> (point) start)
3391 (beginning-of-line)
3392 (setq indent
3393 (min indent
3394 (progn
3395 (re-search-forward
3396 comment-start-skip
3397 (save-excursion (end-of-line) (point))
3399 (current-column))))
3400 (forward-line -1))
3402 (setq fill-prefix (concat fill-prefix
3403 (make-string (- indent pre)
3404 ?\ )))
3405 ;; first-line indent
3406 (setq first-indent
3407 (max
3408 (progn
3409 (re-search-forward
3410 comment-start-skip
3411 (save-excursion (end-of-line) (point))
3413 (current-column))
3414 indent))
3416 ;; try to keep point at its original place
3417 (goto-char here)
3419 ;; In place of the more modern fill-region-as-paragraph, a hack
3420 ;; to keep whitespace untouched on the first line within the
3421 ;; indent length and to preserve any indent on the first line
3422 ;; (first indent).
3423 (save-excursion
3424 (setq diff
3425 (buffer-substring start (+ start first-indent -1)))
3426 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3427 (fill-region-as-paragraph
3428 start
3429 (- (point-max) end)
3430 (current-justification)
3431 nil)
3432 (delete-region start (+ start first-indent -1))
3433 (goto-char start)
3434 (insert diff))
3435 ;; When we want the point at the beginning of the comment
3436 ;; body fill-region will put it at the beginning of the line.
3437 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3438 (setq fill-prefix nil))))
3440 (defun idlwave-calc-hanging-indent ()
3441 "Calculate the position of the hanging indent for the comment paragraph.
3442 The hanging indent position is given by the first match with the
3443 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3444 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3445 on the line.
3446 If not found returns nil."
3447 (if idlwave-use-last-hang-indent
3448 (save-excursion
3449 (end-of-line)
3450 (if (re-search-backward
3451 idlwave-hang-indent-regexp
3452 (save-excursion (beginning-of-line) (point))
3454 (+ (current-column) (length idlwave-hang-indent-regexp))))
3455 (save-excursion
3456 (beginning-of-line)
3457 (if (re-search-forward
3458 idlwave-hang-indent-regexp
3459 (save-excursion (end-of-line) (point))
3461 (current-column)))))
3463 (defun idlwave-auto-fill ()
3464 "Called to break lines in auto fill mode.
3465 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3466 non-nil. Places a continuation character at the end of the line if
3467 not in a comment. Splits strings with IDL concatenation operator `+'
3468 if `idlwave-auto-fill-split-string' is non-nil."
3469 (if (<= (current-column) fill-column)
3470 nil ; do not to fill
3471 (if (or (not idlwave-fill-comment-line-only)
3472 (save-excursion
3473 ;; Check for comment line
3474 (beginning-of-line)
3475 (looking-at idlwave-comment-line-start-skip)))
3476 (let (beg)
3477 (idlwave-indent-line)
3478 ;; Prevent actions do-auto-fill which calls indent-line-function.
3479 (let (idlwave-do-actions
3480 (paragraph-separate ".")
3481 (fill-nobreak-predicate
3482 (if (and (idlwave-in-quote)
3483 idlwave-auto-fill-split-string)
3484 (lambda () ;; We'll need 5 spaces for " ' + $"
3485 (<= (- fill-column (current-column)) 5)
3486 ))))
3487 (do-auto-fill))
3488 (save-excursion
3489 (end-of-line 0)
3490 ;; Indent the split line
3491 (idlwave-indent-line))
3492 (if (save-excursion
3493 (beginning-of-line)
3494 (looking-at idlwave-comment-line-start-skip))
3495 ;; A continued line comment
3496 ;; We treat continued line comments as part of a comment
3497 ;; paragraph. So we check for a hanging indent.
3498 (if idlwave-hanging-indent
3499 (let ((here (- (point-max) (point)))
3500 (indent
3501 (save-excursion
3502 (forward-line -1)
3503 (idlwave-calc-hanging-indent))))
3504 (if indent
3505 (progn
3506 ;; Remove whitespace between comment delimiter and
3507 ;; text, insert spaces for appropriate indentation.
3508 (beginning-of-line)
3509 (re-search-forward
3510 comment-start-skip
3511 (save-excursion (end-of-line) (point)) t)
3512 (delete-horizontal-space)
3513 (idlwave-indent-to indent)
3514 (goto-char (- (point-max) here)))
3516 ;; Split code or comment?
3517 (if (save-excursion
3518 (end-of-line 0)
3519 (idlwave-in-comment))
3520 ;; Splitting a non-full-line comment.
3521 ;; Insert the comment delimiter from split line
3522 (progn
3523 (save-excursion
3524 (beginning-of-line)
3525 (skip-chars-forward " \t")
3526 ;; Insert blank to keep off beginning of line
3527 (insert " "
3528 (save-excursion
3529 (forward-line -1)
3530 (buffer-substring (idlwave-goto-comment)
3531 (progn
3532 (skip-chars-forward "; ")
3533 (point))))))
3534 (idlwave-indent-line))
3535 ;; Split code line - add continuation character
3536 (save-excursion
3537 (end-of-line 0)
3538 ;; Check to see if we split a string
3539 (if (and (setq beg (idlwave-in-quote))
3540 idlwave-auto-fill-split-string)
3541 ;; Split the string and concatenate.
3542 ;; The first extra space is for the space
3543 ;; the line was split. That space was removed.
3544 (insert " " (char-after beg) " +"))
3545 (insert " $"))
3546 (if beg
3547 (if idlwave-auto-fill-split-string
3548 ;; Make the second part of continued string
3549 (save-excursion
3550 (beginning-of-line)
3551 (skip-chars-forward " \t")
3552 (insert (char-after beg)))
3553 ;; Warning
3554 (beep)
3555 (message "Warning: continuation inside a string.")))
3556 ;; Although do-auto-fill (via indent-new-comment-line) calls
3557 ;; idlwave-indent-line for the new line, re-indent again
3558 ;; because of the addition of the continuation character.
3559 (idlwave-indent-line))
3560 )))))
3562 (defun idlwave-auto-fill-mode (arg)
3563 "Toggle auto-fill mode for IDL mode.
3564 With arg, turn auto-fill mode on if arg is positive.
3565 In auto-fill mode, inserting a space at a column beyond `fill-column'
3566 automatically breaks the line at a previous space."
3567 (interactive "P")
3568 (prog1 (set idlwave-fill-function
3569 (if (if (null arg)
3570 (not (symbol-value idlwave-fill-function))
3571 (> (prefix-numeric-value arg) 0))
3572 'idlwave-auto-fill
3573 nil))
3574 ;; update mode-line
3575 (set-buffer-modified-p (buffer-modified-p))))
3577 ;(defun idlwave-fill-routine-call ()
3578 ; "Fill a routine definition or statement, indenting appropriately."
3579 ; (let ((where (idlwave-where)))))
3582 (defun idlwave-doc-header (&optional nomark)
3583 "Insert a documentation header at the beginning of the unit.
3584 Inserts the value of the variable `idlwave-file-header'. Sets mark
3585 before moving to do insertion unless the optional prefix argument
3586 NOMARK is non-nil."
3587 (interactive "P")
3588 (or nomark (push-mark))
3589 ;; make sure we catch the current line if it begins the unit
3590 (if idlwave-header-to-beginning-of-file
3591 (goto-char (point-min))
3592 (end-of-line)
3593 (idlwave-beginning-of-subprogram)
3594 (beginning-of-line)
3595 ;; skip function or procedure line
3596 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3597 (progn
3598 (idlwave-end-of-statement)
3599 (if (> (forward-line 1) 0) (insert "\n")))))
3600 (let ((pos (point)))
3601 (if idlwave-file-header
3602 (cond ((car idlwave-file-header)
3603 (insert-file-contents (car idlwave-file-header)))
3604 ((stringp (car (cdr idlwave-file-header)))
3605 (insert (car (cdr idlwave-file-header))))))
3606 (goto-char pos)))
3608 (defun idlwave-default-insert-timestamp ()
3609 "Default timestamp insertion function."
3610 (insert (current-time-string))
3611 (insert ", " (user-full-name))
3612 (if (boundp 'user-mail-address)
3613 (insert " <" user-mail-address ">")
3614 (insert " <" (user-login-name) "@" (system-name) ">"))
3615 ;; Remove extra spaces from line
3616 (idlwave-fill-paragraph)
3617 ;; Insert a blank line comment to separate from the date entry -
3618 ;; will keep the entry from flowing onto date line if re-filled.
3619 (insert "\n;\n;\t\t"))
3621 (defun idlwave-doc-modification ()
3622 "Insert a brief modification log at the beginning of the current program.
3623 Looks for an occurrence of the value of user variable
3624 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3625 name and places the point for the user to add a log. Before moving, saves
3626 location on mark ring so that the user can return to previous point."
3627 (interactive)
3628 (push-mark)
3629 (let* (beg end)
3630 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3631 (progn
3632 (goto-char (point-min))
3633 (re-search-forward idlwave-doclib-start nil t)))
3634 (setq beg (match-beginning 0))
3635 (re-search-forward idlwave-doclib-end nil t)
3636 (setq end (match-end 0)))
3637 (progn
3638 (goto-char beg)
3639 (if (re-search-forward
3640 (concat idlwave-doc-modifications-keyword ":")
3641 end t)
3642 (end-of-line)
3643 (goto-char end)
3644 (end-of-line -1)
3645 (insert "\n" comment-start "\n")
3646 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3647 (insert "\n;\n;\t")
3648 (run-hooks 'idlwave-timestamp-hook))
3649 (error "No valid DOCLIB header"))))
3652 ;; CJC 3/16/93
3653 ;; Interface to expand-region-abbrevs which did not work when the
3654 ;; abbrev hook associated with an abbrev moves point backwards
3655 ;; after abbrev expansion, e.g., as with the abbrev '.n'.
3656 ;; The original would enter an infinite loop in attempting to expand
3657 ;; .n (it would continually expand and unexpand the abbrev without expanding
3658 ;; because the point would keep going back to the beginning of the
3659 ;; abbrev instead of to the end of the abbrev). We now keep the
3660 ;; abbrev hook from moving backwards.
3662 (defun idlwave-expand-region-abbrevs (start end)
3663 "Expand each abbrev occurrence in the region.
3664 Calling from a program, arguments are START END."
3665 (interactive "r")
3666 (save-excursion
3667 (goto-char (min start end))
3668 (let ((idlwave-show-block nil) ;Do not blink
3669 (idlwave-abbrev-move nil)) ;Do not move
3670 (expand-region-abbrevs start end 'noquery))))
3672 (defun idlwave-quoted ()
3673 "Return t if point is in a comment or quoted string.
3674 Returns nil otherwise."
3675 (or (idlwave-in-comment) (idlwave-in-quote)))
3677 (defun idlwave-in-quote ()
3678 "Return location of the opening quote
3679 if point is in a IDL string constant, nil otherwise.
3680 Ignores comment delimiters on the current line.
3681 Properly handles nested quotation marks and octal
3682 constants - a double quote followed by an octal digit."
3683 ;; Treat an octal inside an apostrophe to be a normal string. Treat a
3684 ;; double quote followed by an octal digit to be an octal constant
3685 ;; rather than a string. Therefore, there is no terminating double
3686 ;; quote.
3687 (save-excursion
3688 ;; Because single and double quotes can quote each other we must
3689 ;; search for the string start from the beginning of line.
3690 (let* ((start (point))
3691 (eol (progn (end-of-line) (point)))
3692 (bq (progn (beginning-of-line) (point)))
3693 (endq (point))
3694 (data (match-data))
3695 delim
3696 found)
3697 (while (< endq start)
3698 ;; Find string start
3699 ;; Don't find an octal constant beginning with a double quote
3700 (if (re-search-forward "[\"']" eol 'lim)
3701 ;; Find the string end.
3702 ;; In IDL, two consecutive delimiters after the start of a
3703 ;; string act as an
3704 ;; escape for the delimiter in the string.
3705 ;; Two consecutive delimiters alone (i.e., not after the
3706 ;; start of a string) is the null string.
3707 (progn
3708 ;; Move to position after quote
3709 (goto-char (1+ (match-beginning 0)))
3710 (setq bq (1- (point)))
3711 ;; Get the string delimiter
3712 (setq delim (char-to-string (preceding-char)))
3713 ;; Check for null string
3714 (if (looking-at delim)
3715 (progn (setq endq (point)) (forward-char 1))
3716 ;; Look for next unpaired delimiter
3717 (setq found (search-forward delim eol 'lim))
3718 (while (looking-at delim)
3719 (forward-char 1)
3720 (setq found (search-forward delim eol 'lim)))
3721 (setq endq (if found (1- (point)) (point)))
3723 (progn (setq bq (point)) (setq endq (point)))))
3724 (store-match-data data)
3725 ;; return string beginning position or nil
3726 (if (> start bq) bq))))
3728 (defun idlwave-is-pointer-dereference (&optional limit)
3729 "Determine if the character after point is a pointer dereference *."
3730 (and
3731 (eq (char-after) ?\*)
3732 (not (idlwave-in-quote))
3733 (save-excursion
3734 (forward-char)
3735 (re-search-backward (concat "\\(" idlwave-idl-keywords
3736 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
3739 ;; Statement templates
3741 ;; Replace these with a general template function, something like
3742 ;; expand.el (I think there was also something with a name similar to
3743 ;; dmacro.el)
3745 (defun idlwave-template (s1 s2 &optional prompt noindent)
3746 "Build a template with optional prompt expression.
3748 Opens a line if point is not followed by a newline modulo intervening
3749 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3750 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3751 adjusted according to `idlwave-abbrev-change-case'. If optional
3752 argument PROMPT is a string then it is displayed as a message in the
3753 minibuffer. The PROMPT serves as a reminder to the user of an
3754 expression to enter.
3756 The lines containing S1 and S2 are reindented using `indent-region'
3757 unless the optional second argument NOINDENT is non-nil."
3758 (if (eq major-mode 'idlwave-shell-mode)
3759 ;; This is a gross hack to avoit template abbrev expansion
3760 ;; in the shell. FIXME: This is a dirty hack.
3761 (if (and (eq this-command 'self-insert-command)
3762 (equal last-abbrev-location (point)))
3763 (insert last-abbrev-text)
3764 (error "No templates in idlwave-shell"))
3765 (cond ((eq idlwave-abbrev-change-case 'down)
3766 (setq s1 (downcase s1) s2 (downcase s2)))
3767 (idlwave-abbrev-change-case
3768 (setq s1 (upcase s1) s2 (upcase s2))))
3769 (let ((beg (save-excursion (beginning-of-line) (point)))
3770 end)
3771 (if (not (looking-at "\\s-*\n"))
3772 (open-line 1))
3773 (insert s1)
3774 (save-excursion
3775 (insert s2)
3776 (setq end (point)))
3777 (if (not noindent)
3778 (indent-region beg end nil))
3779 (if (stringp prompt)
3780 (message "%s" prompt)))))
3782 (defun idlwave-rw-case (string)
3783 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3784 (if idlwave-reserved-word-upcase
3785 (upcase string)
3786 string))
3788 (defun idlwave-elif ()
3789 "Build skeleton IDL if-else block."
3790 (interactive)
3791 (idlwave-template
3792 (idlwave-rw-case "if")
3793 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3794 "Condition expression"))
3796 (defun idlwave-case ()
3797 "Build skeleton IDL case statement."
3798 (interactive)
3799 (idlwave-template
3800 (idlwave-rw-case "case")
3801 (idlwave-rw-case " of\n\nendcase")
3802 "Selector expression"))
3804 (defun idlwave-switch ()
3805 "Build skeleton IDL switch statement."
3806 (interactive)
3807 (idlwave-template
3808 (idlwave-rw-case "switch")
3809 (idlwave-rw-case " of\n\nendswitch")
3810 "Selector expression"))
3812 (defun idlwave-for ()
3813 "Build skeleton IDL loop statement."
3814 (interactive)
3815 (idlwave-template
3816 (idlwave-rw-case "for")
3817 (idlwave-rw-case " do begin\n\nendfor")
3818 "Loop expression"))
3820 (defun idlwave-if ()
3821 "Build skeleton IDL if statement."
3822 (interactive)
3823 (idlwave-template
3824 (idlwave-rw-case "if")
3825 (idlwave-rw-case " then begin\n\nendif")
3826 "Scalar logical expression"))
3828 (defun idlwave-procedure ()
3829 (interactive)
3830 (idlwave-template
3831 (idlwave-rw-case "pro")
3832 (idlwave-rw-case "\n\nreturn\nend")
3833 "Procedure name"))
3835 (defun idlwave-function ()
3836 (interactive)
3837 (idlwave-template
3838 (idlwave-rw-case "function")
3839 (idlwave-rw-case "\n\nreturn\nend")
3840 "Function name"))
3842 (defun idlwave-repeat ()
3843 (interactive)
3844 (idlwave-template
3845 (idlwave-rw-case "repeat begin\n\nendrep until")
3846 (idlwave-rw-case "")
3847 "Exit condition"))
3849 (defun idlwave-while ()
3850 (interactive)
3851 (idlwave-template
3852 (idlwave-rw-case "while")
3853 (idlwave-rw-case " do begin\n\nendwhile")
3854 "Entry condition"))
3856 (defun idlwave-split-string (string &optional pattern)
3857 "Return a list of substrings of STRING which are separated by PATTERN.
3858 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3859 (or pattern
3860 (setq pattern "[ \f\t\n\r\v]+"))
3861 (let (parts (start 0))
3862 (while (string-match pattern string start)
3863 (setq parts (cons (substring string start (match-beginning 0)) parts)
3864 start (match-end 0)))
3865 (nreverse (cons (substring string start) parts))))
3867 (defun idlwave-replace-string (string replace_string replace_with)
3868 (let* ((start 0)
3869 (last (length string))
3870 (ret_string "")
3871 end)
3872 (while (setq end (string-match replace_string string start))
3873 (setq ret_string
3874 (concat ret_string (substring string start end) replace_with))
3875 (setq start (match-end 0)))
3876 (setq ret_string (concat ret_string (substring string start last)))))
3878 (defun idlwave-get-buffer-visiting (file)
3879 ;; Return the buffer currently visiting FILE
3880 (cond
3881 ((boundp 'find-file-compare-truenames) ; XEmacs
3882 (let ((find-file-compare-truenames t))
3883 (get-file-buffer file)))
3884 ((fboundp 'find-buffer-visiting) ; Emacs
3885 (find-buffer-visiting file))
3886 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3888 (defvar idlwave-outlawed-buffers nil
3889 "List of buffers pulled up by IDLWAVE for special reasons.
3890 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3892 (defun idlwave-find-file-noselect (file &optional why)
3893 ;; Return a buffer visiting file.
3894 (or (idlwave-get-buffer-visiting file)
3895 (let ((buf (find-file-noselect file)))
3896 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3897 buf)))
3899 (defun idlwave-kill-autoloaded-buffers ()
3900 "Kill buffers created automatically by IDLWAVE.
3901 Function prompts for a letter to identify the buffers to kill.
3902 Possible letters are:
3904 f Buffers created by the command \\[idlwave-find-module] or mouse
3905 clicks in the routine info window.
3906 s Buffers created by the IDLWAVE Shell to display where execution
3907 stopped or an error was found.
3908 a Both of the above.
3910 Buffers containing unsaved changes require confirmation before they are killed."
3911 (interactive)
3912 (if (null idlwave-outlawed-buffers)
3913 (error "No IDLWAVE-created buffers available")
3914 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3915 (idlwave-count-outlawed-buffers 'find)
3916 (idlwave-count-outlawed-buffers 'shell)))
3917 (let ((c (read-char)))
3918 (cond
3919 ((member c '(?f ?\C-f))
3920 (idlwave-do-kill-autoloaded-buffers 'find))
3921 ((member c '(?s ?\C-s))
3922 (idlwave-do-kill-autoloaded-buffers 'shell))
3923 ((member c '(?a ?\C-a))
3924 (idlwave-do-kill-autoloaded-buffers t))
3925 (t (error "Abort"))))))
3927 (defun idlwave-count-outlawed-buffers (tag)
3928 "How many outlawed buffers have tag TAG?"
3929 (length (delq nil
3930 (mapcar
3931 (lambda (x) (eq (cdr x) tag))
3932 idlwave-outlawed-buffers))))
3934 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3935 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3936 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3937 (cnt 0)
3938 entry)
3939 (while (setq entry (pop list))
3940 (if (buffer-live-p (car entry))
3941 (and (or (memq t reasons)
3942 (memq (cdr entry) reasons))
3943 (kill-buffer (car entry))
3944 (incf cnt)
3945 (setq idlwave-outlawed-buffers
3946 (delq entry idlwave-outlawed-buffers)))
3947 (setq idlwave-outlawed-buffers
3948 (delq entry idlwave-outlawed-buffers))))
3949 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3951 (defun idlwave-revoke-license-to-kill ()
3952 "Remove BUFFER from the buffers which may be killed.
3953 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3954 Intended for `after-save-hook'."
3955 (let* ((buf (current-buffer))
3956 (entry (assq buf idlwave-outlawed-buffers)))
3957 ;; Revoke license
3958 (if entry
3959 (setq idlwave-outlawed-buffers
3960 (delq entry idlwave-outlawed-buffers)))
3961 ;; Remove this function from the hook.
3962 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3964 (defvar idlwave-path-alist)
3965 (defun idlwave-locate-lib-file (file)
3966 ;; Find FILE on the scanned lib path and return a buffer visiting it
3967 (let* ((dirs idlwave-path-alist)
3968 dir efile)
3969 (catch 'exit
3970 (while (setq dir (car (pop dirs)))
3971 (if (file-regular-p
3972 (setq efile (expand-file-name file dir)))
3973 (throw 'exit efile))))))
3975 (defun idlwave-expand-lib-file-name (file)
3976 ;; Find FILE on the scanned lib path and return a buffer visiting it
3977 ;; This is for, e.g., finding source with no user catalog
3978 (cond
3979 ((null file) nil)
3980 ((file-name-absolute-p file) file)
3981 (t (idlwave-locate-lib-file file))))
3983 (defun idlwave-make-tags ()
3984 "Create the IDL tags file IDLTAGS in the current directory from
3985 the list of directories specified in the minibuffer. Directories may be
3986 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3987 specified top directories are searched if the directory name is prefixed
3988 by @. Specify @ directories with care, it may take a long, long time if
3989 you specify /."
3990 (interactive)
3991 (let (directory directories cmd append status numdirs dir getsubdirs
3992 buffer save_buffer files numfiles item errbuf)
3995 ;; Read list of directories
3996 (setq directory (read-string "Tag Directories: " "."))
3997 (setq directories (idlwave-split-string directory "[ \t]+"))
3999 ;; Set etags command, vars
4000 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
4001 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4002 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4003 (setq append " ")
4004 (setq status 0)
4006 ;; For each directory
4007 (setq numdirs 0)
4008 (setq dir (nth numdirs directories))
4009 (while (and dir)
4011 ;; Find the subdirectories
4012 (if (string-match "^[@]\\(.+\\)$" dir)
4013 (setq getsubdirs t) (setq getsubdirs nil))
4014 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
4015 (setq dir (expand-file-name dir))
4016 (if (file-directory-p dir)
4017 (progn
4018 (if (and getsubdirs)
4019 (progn
4020 (setq buffer (get-buffer-create "*idltags*"))
4021 (call-process "sh" nil buffer nil "-c"
4022 (concat "find " dir " -type d -print"))
4023 (setq save_buffer (current-buffer))
4024 (set-buffer buffer)
4025 (setq files (idlwave-split-string
4026 (idlwave-replace-string
4027 (buffer-substring 1 (point-max))
4028 "\n" "/*.pro ")
4029 "[ \t]+"))
4030 (set-buffer save_buffer)
4031 (kill-buffer buffer))
4032 (setq files (list (concat dir "/*.pro"))))
4034 ;; For each subdirectory
4035 (setq numfiles 0)
4036 (setq item (nth numfiles files))
4037 (while (and item)
4039 ;; Call etags
4040 (if (not (string-match "^[ \\t]*$" item))
4041 (progn
4042 (message "%s" (concat "Tagging " item "..."))
4043 (setq errbuf (get-buffer-create "*idltags-error*"))
4044 (setq status (+ status
4045 (if (eq 0 (call-process
4046 "sh" nil errbuf nil "-c"
4047 (concat cmd append item)))
4049 1)))
4051 ;; Append additional tags
4052 (setq append " --append ")
4053 (setq numfiles (1+ numfiles))
4054 (setq item (nth numfiles files)))
4055 (progn
4056 (setq numfiles (1+ numfiles))
4057 (setq item (nth numfiles files))
4060 (setq numdirs (1+ numdirs))
4061 (setq dir (nth numdirs directories)))
4062 (progn
4063 (setq numdirs (1+ numdirs))
4064 (setq dir (nth numdirs directories)))))
4066 (setq errbuf (get-buffer-create "*idltags-error*"))
4067 (if (= status 0)
4068 (kill-buffer errbuf))
4069 (message "")
4072 (defun idlwave-toggle-comment-region (beg end &optional n)
4073 "Comment the lines in the region if the first non-blank line is
4074 commented, and conversely, uncomment region. If optional prefix arg
4075 N is non-nil, then for N positive, add N comment delimiters or for N
4076 negative, remove N comment delimiters.
4077 Uses `comment-region' which does not place comment delimiters on
4078 blank lines."
4079 (interactive "r\nP")
4080 (if n
4081 (comment-region beg end (prefix-numeric-value n))
4082 (save-excursion
4083 (goto-char beg)
4084 (beginning-of-line)
4085 ;; skip blank lines
4086 (skip-chars-forward " \t\n")
4087 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4088 (if (fboundp 'uncomment-region)
4089 (uncomment-region beg end)
4090 (comment-region beg end
4091 (- (length (buffer-substring
4092 (match-beginning 1)
4093 (match-end 1))))))
4094 (comment-region beg end)))))
4097 ;; ----------------------------------------------------------------------------
4098 ;; ----------------------------------------------------------------------------
4099 ;; ----------------------------------------------------------------------------
4100 ;; ----------------------------------------------------------------------------
4102 ;; Completion and Routine Info
4105 ;; String "intern" functions
4107 ;; For the completion and routine info function, we want to normalize
4108 ;; the case of procedure names etc. We do this by "interning" these
4109 ;; string is a hand-crafted way. Hashes are used to map the downcase
4110 ;; version of the strings to the cased versions. Most *-sint-*
4111 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4112 ;; system hash. The former is re-scanned, and the latter takes case
4113 ;; precedence.
4115 ;; Since these cased versions are really lisp objects, we can use `eq'
4116 ;; to search, which is a large performance boost. All new strings
4117 ;; need to be "sinterned". We do this as early as possible after
4118 ;; getting these strings from completion or buffer substrings. So
4119 ;; most of the code can simply assume to deal with "sinterned"
4120 ;; strings. The only exception is that the functions which scan whole
4121 ;; buffers for routine information do not intern the grabbed strings.
4122 ;; This is only done afterwards. Therefore in these functions it is
4123 ;; *not* safe to assume the strings can be compared with `eq' and be
4124 ;; fed into the routine assq functions.
4126 ;; Here we define the hashing functions.
4128 ;; The variables which hold the hashes.
4129 (defvar idlwave-sint-routines '(nil))
4130 (defvar idlwave-sint-keywords '(nil))
4131 (defvar idlwave-sint-methods '(nil))
4132 (defvar idlwave-sint-classes '(nil))
4133 (defvar idlwave-sint-dirs '(nil))
4134 (defvar idlwave-sint-libnames '(nil))
4136 (defun idlwave-reset-sintern (&optional what)
4137 "Reset all sintern hashes."
4138 ;; Make sure the hash functions are accessible.
4139 (unless (and (fboundp 'gethash)
4140 (fboundp 'puthash))
4141 (require 'cl)
4142 (or (fboundp 'puthash)
4143 (defalias 'puthash 'cl-puthash)))
4144 (let ((entries '((idlwave-sint-routines 1000 10)
4145 (idlwave-sint-keywords 1000 10)
4146 (idlwave-sint-methods 100 10)
4147 (idlwave-sint-classes 10 10))))
4149 ;; Make sure these are lists
4150 (loop for entry in entries
4151 for var = (car entry)
4152 do (if (not (consp (symbol-value var))) (set var (list nil))))
4154 ;; Reset the system & library hash
4155 (when (or (eq what t) (eq what 'syslib)
4156 (null (cdr idlwave-sint-routines)))
4157 (loop for entry in entries
4158 for var = (car entry) for size = (nth 1 entry)
4159 do (setcdr (symbol-value var)
4160 (make-hash-table ':size size ':test 'equal)))
4161 (setq idlwave-sint-dirs nil
4162 idlwave-sint-libnames nil))
4164 ;; Reset the buffer & shell hash
4165 (when (or (eq what t) (eq what 'bufsh)
4166 (null (car idlwave-sint-routines)))
4167 (loop for entry in entries
4168 for var = (car entry) for size = (nth 1 entry)
4169 do (setcar (symbol-value var)
4170 (make-hash-table ':size size ':test 'equal))))))
4172 (defun idlwave-sintern-routine-or-method (name &optional class set)
4173 (if class
4174 (idlwave-sintern-method name set)
4175 (idlwave-sintern-routine name set)))
4177 (defun idlwave-sintern (stype &rest args)
4178 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4180 ;;(defmacro idlwave-sintern (type var)
4181 ;; `(cond ((not (stringp name)) name)
4182 ;; ((gethash (downcase name) (cdr ,var)))
4183 ;; ((gethash (downcase name) (car ,var)))
4184 ;; (set (idlwave-sintern-set name ,type ,var set))
4185 ;; (name)))
4187 (defun idlwave-sintern-routine (name &optional set)
4188 (cond ((not (stringp name)) name)
4189 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4190 ((gethash (downcase name) (car idlwave-sint-routines)))
4191 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4192 (name)))
4193 (defun idlwave-sintern-keyword (name &optional set)
4194 (cond ((not (stringp name)) name)
4195 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4196 ((gethash (downcase name) (car idlwave-sint-keywords)))
4197 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4198 (name)))
4199 (defun idlwave-sintern-method (name &optional set)
4200 (cond ((not (stringp name)) name)
4201 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4202 ((gethash (downcase name) (car idlwave-sint-methods)))
4203 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4204 (name)))
4205 (defun idlwave-sintern-class (name &optional set)
4206 (cond ((not (stringp name)) name)
4207 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4208 ((gethash (downcase name) (car idlwave-sint-classes)))
4209 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4210 (name)))
4212 (defun idlwave-sintern-dir (dir &optional set)
4213 (car (or (member dir idlwave-sint-dirs)
4214 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4215 (defun idlwave-sintern-libname (name &optional set)
4216 (car (or (member name idlwave-sint-libnames)
4217 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4219 (defun idlwave-sintern-set (name type tables set)
4220 (let* ((func (or (cdr (assq type idlwave-completion-case))
4221 'identity))
4222 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4223 (table (if (eq set 'sys) (cdr tables) (car tables))))
4224 (puthash (downcase name) iname table)
4225 iname))
4227 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4228 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4229 (mapc (lambda(x)
4230 (setcar x (idlwave-sintern-keyword (car x) set)))
4231 (cdr kwd-list))
4232 kwd-list)
4234 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4235 "Sintern all strings in the rinfo LIST.
4236 With optional parameter SET: also set new patterns. Probably this
4237 will always have to be t. If DEFAULT-DIR is passed, it is used as
4238 the base of the directory."
4239 (let (entry name type class kwds res source call new)
4240 (while list
4241 (setq entry (car list)
4242 list (cdr list)
4243 name (car entry)
4244 type (nth 1 entry)
4245 class (nth 2 entry)
4246 source (nth 3 entry)
4247 call (nth 4 entry)
4248 kwds (nthcdr 5 entry))
4250 ;; The class and name
4251 (if class
4252 (progn
4253 (if (symbolp class) (setq class (symbol-name class)))
4254 (setq class (idlwave-sintern-class class set))
4255 (setq name (idlwave-sintern-method name set)))
4256 (setq name (idlwave-sintern-routine name set)))
4258 ;; The source
4259 (let ((source-type (car source))
4260 (source-file (nth 1 source))
4261 (source-dir (if default-dir
4262 (file-name-as-directory default-dir)
4263 (nth 2 source)))
4264 (source-lib (nth 3 source)))
4265 (if (stringp source-dir)
4266 (setq source-dir (idlwave-sintern-dir source-dir set)))
4267 (if (stringp source-lib)
4268 (setq source-lib (idlwave-sintern-libname source-lib set)))
4269 (setq source (list source-type source-file source-dir source-lib)))
4271 ;; The keywords
4272 (setq kwds (mapcar (lambda (x)
4273 (idlwave-sintern-keyword-list x set))
4274 kwds))
4276 ;; Build a canonicalized list
4277 (setq new (nconc (list name type class source call) kwds)
4278 res (cons new res)))
4279 (nreverse res)))
4281 ;; Creating new sintern tables
4283 (defun idlwave-new-sintern-type (tag)
4284 "Define a variable and a function to sintern the new type TAG.
4285 This defines the function `idlwave-sintern-TAG' and the variable
4286 `idlwave-sint-TAGs'."
4287 (let* ((name (symbol-name tag))
4288 (names (concat name "s"))
4289 (var (intern (concat "idlwave-sint-" names)))
4290 (func (intern (concat "idlwave-sintern-" name))))
4291 (set var nil) ; initial value of the association list
4292 (fset func ; set the function
4293 `(lambda (name &optional set)
4294 (cond ((not (stringp name)) name)
4295 ((cdr (assoc (downcase name) ,var)))
4296 (set
4297 (setq ,var (cons (cons (downcase name) name) ,var))
4298 name)
4299 (name))))))
4301 (defun idlwave-reset-sintern-type (tag)
4302 "Reset the sintern variable associated with TAG."
4303 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4305 ;;---------------------------------------------------------------------------
4308 ;; The variables which hold the information
4309 (defvar idlwave-system-routines nil
4310 "Holds the routine-info obtained by scanning buffers.")
4311 (defvar idlwave-buffer-routines nil
4312 "Holds the routine-info obtained by scanning buffers.")
4313 (defvar idlwave-compiled-routines nil
4314 "Holds the routine-info obtained by asking the shell.")
4315 (defvar idlwave-unresolved-routines nil
4316 "Holds the unresolved routine-info obtained by asking the shell.")
4317 (defvar idlwave-user-catalog-routines nil
4318 "Holds the procedure routine-info from the user scan.")
4319 (defvar idlwave-library-catalog-routines nil
4320 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4321 (defvar idlwave-library-catalog-libname nil
4322 "Name of library catalog loaded from .idlwave_catalog files.")
4323 (defvar idlwave-path-alist nil
4324 "Alist with !PATH directories and zero or more flags if the dir has
4325 been scanned in a user catalog ('user) or discovered in a library
4326 catalog \('lib).")
4327 (defvar idlwave-true-path-alist nil
4328 "Like `idlwave-path-alist', but with true filenames.")
4329 (defvar idlwave-routines nil
4330 "Holds the combined procedure/function/method routine-info.")
4331 (defvar idlwave-class-alist nil
4332 "Holds the class names known to IDLWAVE.")
4333 (defvar idlwave-class-history nil
4334 "The history of classes selected with the minibuffer.")
4335 (defvar idlwave-force-class-query nil)
4336 (defvar idlwave-before-completion-wconf nil
4337 "The window configuration just before the completion buffer was displayed.")
4338 (defvar idlwave-last-system-routine-info-cons-cell nil
4339 "The last cons cell in the system routine info.")
4342 ;; The code to get routine info from different sources.
4344 (defvar idlwave-system-routines)
4345 (defvar idlwave-catalog-process nil
4346 "The background process currently updating the catalog.")
4348 (defun idlwave-routines ()
4349 "Provide a list of IDL routines.
4350 This routine loads the builtin routines on the first call.
4351 Later it only returns the value of the variable."
4352 (if (and idlwave-catalog-process
4353 (processp idlwave-catalog-process))
4354 (progn
4355 (cond
4356 ((equal (process-status idlwave-catalog-process) 'exit)
4357 (message "updating........")
4358 (setq idlwave-catalog-process nil)
4359 (idlwave-update-routine-info '(4)))
4360 ((equal (process-status idlwave-catalog-process) 'run)
4361 ;; Keep it running...
4364 ;; Something is wrong, get rid of the process
4365 (message "Problem with catalog process") (beep)
4366 (condition-case nil
4367 (kill-process idlwave-catalog-process)
4368 (error nil))
4369 (setq idlwave-catalog-process nil)))))
4370 (or idlwave-routines
4371 (progn
4372 (idlwave-update-routine-info)
4373 ;; return the current value
4374 idlwave-routines)))
4376 (defvar idlwave-update-rinfo-hook nil
4377 "List of functions which should run after a global rinfo update.
4378 Does not run after automatic updates of buffer or the shell.")
4380 (defun idlwave-rescan-catalog-directories ()
4381 "Rescan the previously selected directories. For batch processing."
4382 (idlwave-update-routine-info '(16)))
4384 (defun idlwave-rescan-asynchronously ()
4385 "Dispatch another Emacs instance to update the idlwave catalog.
4386 After the process finishes normally, the first access to routine info
4387 will re-read the catalog."
4388 (interactive)
4389 (if (processp idlwave-catalog-process)
4390 (if (eq (process-status idlwave-catalog-process) 'run)
4391 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4392 (progn
4393 (condition-case nil
4394 (kill-process idlwave-catalog-process)
4395 (error nil))
4396 (error "Process killed, no new process started"))
4397 (error "Quit"))
4398 (condition-case nil
4399 (kill-process idlwave-catalog-process)
4400 (error nil))))
4401 (if (or (not idlwave-user-catalog-file)
4402 (not (stringp idlwave-user-catalog-file))
4403 (not (file-regular-p idlwave-user-catalog-file)))
4404 (error "No catalog has been produced yet"))
4405 (let* ((emacs (concat invocation-directory invocation-name))
4406 (args (list "-batch"
4407 "-l" (expand-file-name "~/.emacs")
4408 "-l" "idlwave"
4409 "-f" "idlwave-rescan-catalog-directories"))
4410 (process (apply 'start-process "idlcat"
4411 nil emacs args)))
4412 (setq idlwave-catalog-process process)
4413 (set-process-sentinel
4414 process
4415 (lambda (pro why)
4416 (when (string-match "finished" why)
4417 (setq idlwave-routines nil
4418 idlwave-system-routines nil
4419 idlwave-catalog-process nil)
4420 (or (idlwave-start-load-rinfo-timer)
4421 (idlwave-update-routine-info '(4))))))
4422 (message "Background job started to update catalog file")))
4425 ;; Format for all routine info user catalog, library catalogs, etc.:
4427 ;; ("ROUTINE" type class
4428 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4429 ;; (buffer pro_file dir) | (compiled pro_file dir)
4430 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4431 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4433 ;; DIR will be supplied dynamically while loading library catalogs,
4434 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4435 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4436 ;; be nil, as can LINK1, etc., if no HTML help is available.
4439 (defvar idlwave-load-rinfo-idle-timer)
4440 (defvar idlwave-shell-path-query)
4442 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4443 "Update the internal routine-info lists.
4444 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4445 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4446 about individual routines.
4448 The information can come from 4 sources:
4449 1. IDL programs in the current editing session
4450 2. Compiled modules in an IDL shell running as Emacs subprocess
4451 3. A list which covers the IDL system routines.
4452 4. A list which covers the prescanned library files.
4454 Scans all IDLWAVE-mode buffers of the current editing session (see
4455 `idlwave-scan-all-buffers-for-routine-info').
4456 When an IDL shell is running, this command also queries the IDL program
4457 for currently compiled routines.
4459 With prefix ARG, also reload the system and library lists.
4460 With two prefix ARG's, also rescans the chosen user catalog tree.
4461 With three prefix args, dispatch asynchronous process to do the update.
4463 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4464 lists, but instead wait for the shell query to complete and
4465 asynchronously finish updating routine info. This is set
4466 automatically when called interactively. When you need routine
4467 information updated immediately, leave NO-CONCATENATE nil."
4468 (interactive "P\np")
4469 ;; Stop any idle processing
4470 (if (or (and (fboundp 'itimerp)
4471 (itimerp idlwave-load-rinfo-idle-timer))
4472 (and (fboundp 'timerp)
4473 (timerp idlwave-load-rinfo-idle-timer)))
4474 (cancel-timer idlwave-load-rinfo-idle-timer))
4475 (cond
4476 ((equal arg '(64))
4477 ;; Start a background process which updates the catalog.
4478 (idlwave-rescan-asynchronously))
4479 ((equal arg '(16))
4480 ;; Update the user catalog now, and wait for them.
4481 (idlwave-create-user-catalog-file t))
4483 (let* ((load (or arg
4484 idlwave-buffer-case-takes-precedence
4485 (null idlwave-routines)))
4486 ;; The override-idle means, even if the idle timer has done some
4487 ;; preparing work, load and renormalize everything anyway.
4488 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4490 (setq idlwave-buffer-routines nil
4491 idlwave-compiled-routines nil
4492 idlwave-unresolved-routines nil)
4493 ;; Reset the appropriate hashes
4494 (if (get 'idlwave-reset-sintern 'done-by-idle)
4495 ;; reset was already done in idle time, so skip this step now once
4496 (put 'idlwave-reset-sintern 'done-by-idle nil)
4497 (idlwave-reset-sintern (cond (load t)
4498 ((null idlwave-system-routines) t)
4499 (t 'bufsh))))
4501 (if idlwave-buffer-case-takes-precedence
4502 ;; We can safely scan the buffer stuff first
4503 (progn
4504 (idlwave-update-buffer-routine-info)
4505 (and load (idlwave-load-all-rinfo override-idle)))
4506 ;; We first do the system info, and then the buffers
4507 (and load (idlwave-load-all-rinfo override-idle))
4508 (idlwave-update-buffer-routine-info))
4510 ;; Let's see if there is a shell
4511 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4512 (idlwave-shell-is-running)))
4513 (ask-shell (and shell-is-running
4514 idlwave-query-shell-for-routine-info)))
4516 ;; Load the library catalogs again, first re-scanning the path
4517 (when arg
4518 (if shell-is-running
4519 (idlwave-shell-send-command idlwave-shell-path-query
4520 '(progn
4521 (idlwave-shell-get-path-info)
4522 (idlwave-scan-library-catalogs))
4523 'hide)
4524 (idlwave-scan-library-catalogs)))
4526 (if (or (not ask-shell)
4527 (not no-concatenate))
4528 ;; 1. If we are not going to ask the shell, we need to do the
4529 ;; concatenation now.
4530 ;; 2. When this function is called non-interactively, it
4531 ;; means that someone needs routine info *now*. The
4532 ;; shell update causes the concatenation to be
4533 ;; *delayed*, so not in time for the current command.
4534 ;; Therefore, we do a concatenation now, even though
4535 ;; the shell might do it again.
4536 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4538 (when ask-shell
4539 ;; Ask the shell about the routines it knows of.
4540 (message "Querying the shell")
4541 (idlwave-shell-update-routine-info nil t)))))))
4544 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4545 (defvar idlwave-load-rinfo-idle-timer nil)
4546 (defun idlwave-start-load-rinfo-timer ()
4547 (if (or (and (fboundp 'itimerp)
4548 (itimerp idlwave-load-rinfo-idle-timer))
4549 (and (fboundp 'timerp)
4550 (timerp idlwave-load-rinfo-idle-timer)))
4551 (cancel-timer idlwave-load-rinfo-idle-timer))
4552 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4553 (setq idlwave-load-rinfo-idle-timer nil)
4554 (if (and idlwave-init-rinfo-when-idle-after
4555 (numberp idlwave-init-rinfo-when-idle-after)
4556 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4557 (not idlwave-routines))
4558 (condition-case nil
4559 (progn
4560 (setq idlwave-load-rinfo-idle-timer
4561 (run-with-idle-timer
4562 idlwave-init-rinfo-when-idle-after
4563 nil 'idlwave-load-rinfo-next-step)))
4564 (error nil))))
4566 (defvar idlwave-library-routines nil "Obsolete variable.")
4568 ;;------ XML Help routine info system
4569 (defun idlwave-load-system-routine-info ()
4570 ;; Load the system routine info from the cached routine info file,
4571 ;; which, if necessary, will be re-created from the XML file on
4572 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4573 ;; file distributed with older IDLWAVE versions (<6.0)
4574 (unless (and (load idlwave-xml-system-rinfo-converted-file
4575 'noerror 'nomessage)
4576 (idlwave-xml-system-routine-info-up-to-date))
4577 ;; See if we can create it from XML source
4578 (condition-case nil
4579 (idlwave-convert-xml-system-routine-info)
4580 (error
4581 (unless (load idlwave-xml-system-rinfo-converted-file
4582 'noerror 'nomessage)
4583 (if idlwave-system-routines
4584 (message
4585 "Failed to load converted routine info, using old conversion.")
4586 (message
4587 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4588 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4589 (message
4590 "Could not locate any system routine information."))))))))
4592 (defun idlwave-xml-system-routine-info-up-to-date()
4593 (let* ((dir (file-name-as-directory
4594 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4595 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4596 (file-newer-than-file-p ;converted file is newer than catalog
4597 idlwave-xml-system-rinfo-converted-file
4598 catalog-file)))
4600 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4601 (defvar idlwave-system-variables-alist nil
4602 "Alist of system variables and the associated structure tags.
4603 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4604 (defvar idlwave-executive-commands-alist nil
4605 "Alist of system variables and their help files.")
4606 (defvar idlwave-help-special-topic-words nil)
4609 (defun idlwave-shorten-syntax (syntax name &optional class)
4610 ;; From a list of syntax statements, shorten with %s and group with "or"
4611 (let ((case-fold-search t))
4612 (mapconcat
4613 (lambda (x)
4614 (while (string-match name x)
4615 (setq x (replace-match "%s" t t x)))
4616 (if class
4617 (while (string-match class x)
4618 (setq x (replace-match "%s" t t x))))
4620 (nreverse syntax)
4621 " or ")))
4623 (defun idlwave-xml-create-class-method-lists (xml-entry)
4624 ;; Create a class list entry from the xml parsed list., returning a
4625 ;; cons of form (class-entry method-entries).
4626 (let* ((nameblock (nth 1 xml-entry))
4627 (class (cdr (assq 'name nameblock)))
4628 (link (cdr (assq 'link nameblock)))
4629 (params (cddr xml-entry))
4630 (case-fold-search t)
4631 class-entry
4632 method methods-entry extra-kwds
4633 props get-props set-props init-props inherits
4634 pelem ptype)
4635 (while params
4636 (setq pelem (car params))
4637 (when (listp pelem)
4638 (setq ptype (car pelem)
4639 props (car (cdr pelem)))
4640 (cond
4641 ((eq ptype 'SUPERCLASS)
4642 (let ((pname (cdr (assq 'name props)))
4643 (plink (cdr (assq 'link props))))
4644 (unless (and (string= pname "None")
4645 (string= plink "None"))
4646 (push pname inherits))))
4648 ((eq ptype 'PROPERTY)
4649 (let ((pname (cdr (assq 'name props)))
4650 (plink (cdr (assq 'link props)))
4651 (get (string= (cdr (assq 'get props)) "Yes"))
4652 (set (string= (cdr (assq 'set props)) "Yes"))
4653 (init (string= (cdr (assq 'init props)) "Yes")))
4654 (if get (push (list pname plink) get-props))
4655 (if set (push (list pname plink) set-props))
4656 (if init (push (list pname plink) init-props))))
4658 ((eq ptype 'METHOD)
4659 (setq method (cdr (assq 'name props)))
4660 (setq extra-kwds ;;Assume all property keywords are gathered already
4661 (cond
4662 ((string-match (concat class "::Init") method)
4663 (put 'init-props 'matched t)
4664 init-props)
4665 ((string-match (concat class "::GetProperty") method)
4666 (put 'get-props 'matched t)
4667 get-props)
4668 ((string-match (concat class "::SetProperty") method)
4669 (put 'set-props 'matched t)
4670 set-props)
4671 (t nil)))
4672 (setq methods-entry
4673 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4674 methods-entry)))
4675 (t)))
4676 (setq params (cdr params)))
4677 ;;(unless (get 'init-props 'matched)
4678 ;; (message "Failed to match Init in class %s" class))
4679 ;;(unless (get 'get-props 'matched)
4680 ;; (message "Failed to match GetProperty in class %s" class))
4681 ;;(unless (get 'set-props 'matched)
4682 ;; (message "Failed to match SetProperty in class %s" class))
4683 (setq class-entry
4684 (if inherits
4685 (list class (append '(inherits) inherits) (list 'link link))
4686 (list class (list 'link link))))
4687 (cons class-entry methods-entry)))
4689 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4690 ;; Create correctly structured list elements from ROUTINE or METHOD
4691 ;; XML list structures. Return a list of list elements, with more
4692 ;; than one sub-list possible if a routine can serve as both
4693 ;; procedure and function (e.g. call_method).
4694 (let* ((nameblock (nth 1 xml-entry))
4695 (name (cdr (assq 'name nameblock)))
4696 (link (cdr (assq 'link nameblock)))
4697 (params (cddr xml-entry))
4698 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4699 (case-fold-search t)
4700 syntax kwd klink pref-list kwds pelem ptype props result type)
4701 (if class ;; strip out class name from class method name string
4702 (if (string-match (concat class "::") name)
4703 (setq name (substring name (match-end 0)))))
4704 (while params
4705 (setq pelem (car params))
4706 (when (listp pelem)
4707 (setq ptype (car pelem)
4708 props (car (cdr pelem)))
4709 (cond
4710 ((eq ptype 'SYNTAX)
4711 (setq syntax (cdr (assq 'name props)))
4712 (if (string-match "-&gt;" syntax)
4713 (setq syntax (replace-match "->" t nil syntax)))
4714 (setq type (cdr (assq 'type props)))
4715 (push syntax
4716 (aref syntax-vec (cond
4717 ((string-match "^pro" type) 0)
4718 ((string-match "^fun" type) 1)
4719 ((string-match "^exec" type) 2)))))
4720 ((eq ptype 'KEYWORD)
4721 (setq kwd (cdr (assq 'name props))
4722 klink (cdr (assq 'link props)))
4723 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4724 (progn
4725 (setq pref-list
4726 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4727 kwd (substring kwd (match-end 0)))
4728 (loop for x in pref-list do
4729 (push (list (concat x kwd) klink) kwds)))
4730 (push (list kwd klink) kwds)))
4732 (t))); Do nothing for the others
4733 (setq params (cdr params)))
4735 ;; Debug
4736 ;; (if (and (null (aref syntax-vec 0))
4737 ;; (null (aref syntax-vec 1))
4738 ;; (null (aref syntax-vec 2)))
4739 ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4740 ;; (if class
4741 ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4742 ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4744 ;; Executive commands are treated specially
4745 (if (aref syntax-vec 2)
4746 (cons (substring name 1) link)
4747 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4748 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4749 (loop for idx from 0 to 1 do
4750 (if (aref syntax-vec idx)
4751 (push (append (list name (if (eq idx 0) 'pro 'fun)
4752 class '(system)
4753 (idlwave-shorten-syntax
4754 (aref syntax-vec idx) name class))
4755 kwds) result)))
4756 result)))
4759 (defun idlwave-rinfo-group-keywords (kwds master-link)
4760 ;; Group keywords by link file, as a list with elements
4761 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4762 (let (kwd link anchor linkfiles block master-elt)
4763 (while kwds
4764 (setq kwd (car kwds)
4765 link (idlwave-split-link-target (nth 1 kwd))
4766 anchor (cdr link)
4767 link (car link)
4768 kwd (car kwd))
4769 (if (setq block (assoc link linkfiles))
4770 (push (cons kwd anchor) (cdr block))
4771 (push (list link (cons kwd anchor)) linkfiles))
4772 (setq kwds (cdr kwds)))
4773 ;; Ensure the master link is there
4774 (if (setq master-elt (assoc master-link linkfiles))
4775 (if (eq (car linkfiles) master-elt)
4776 linkfiles
4777 (cons master-elt (delq master-elt linkfiles)))
4778 (push (list master-link) linkfiles))))
4780 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4781 ;; Clean up the syntax of routines which are actually aliases by
4782 ;; removing the "OR" from the statements
4783 (let (syntax entry)
4784 (loop for x in aliases do
4785 (setq entry (assoc x idlwave-system-routines))
4786 (when entry
4787 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4788 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4790 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4791 ;; Duplicate and trim original routine aliases from rinfo list
4792 ;; This if for, e.g. OPENR/OPENW/OPENU
4793 (let (alias remove-list new parts all-parts)
4794 (loop for x in aliases do
4795 (when (setq parts (split-string (cdr x) "/"))
4796 (setq new (assoc (cdr x) all-parts))
4797 (unless new
4798 (setq new (cons (cdr x) parts))
4799 (push new all-parts))
4800 (setcdr new (delete (car x) (cdr new)))))
4802 ;; Add any missing aliases (separate by slashes)
4803 (loop for x in all-parts do
4804 (if (cdr x)
4805 (push (cons (nth 1 x) (car x)) aliases)))
4807 (loop for x in aliases do
4808 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4809 (unless (memq alias remove-list) (push alias remove-list))
4810 (setq alias (copy-sequence alias))
4811 (setcar alias (car x))
4812 (push alias idlwave-system-routines)))
4813 (loop for x in remove-list do
4814 (delq x idlwave-system-routines))))
4816 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4817 ;; Duplicate and trim original routine aliases from rinfo list
4818 ;; This if for, e.g. !X, !Y, !Z.
4819 (let (alias remove-list)
4820 (loop for x in aliases do
4821 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4822 (unless (memq alias remove-list) (push alias remove-list))
4823 (setq alias (copy-sequence alias))
4824 (setcar alias (car x))
4825 (push alias idlwave-system-variables-alist)))
4826 (loop for x in remove-list do
4827 (delq x idlwave-system-variables-alist))))
4830 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4831 ;; Create a sysvar list entry from the xml parsed list.
4832 (let* ((nameblock (nth 1 xml-entry))
4833 (name (cdr (assq 'name nameblock)))
4834 (sysvar (substring name (progn (string-match "^ *!" name)
4835 (match-end 0))))
4836 (link (cdr (assq 'link nameblock)))
4837 (params (cddr xml-entry))
4838 (case-fold-search t)
4839 pelem ptype props tags)
4840 (while params
4841 (setq pelem (car params))
4842 (when (listp pelem)
4843 (setq ptype (car pelem)
4844 props (car (cdr pelem)))
4845 (cond
4846 ((eq ptype 'FIELD)
4847 (push (cons (cdr (assq 'name props))
4848 (cdr
4849 (idlwave-split-link-target (cdr (assq 'link props)))))
4850 tags))))
4851 (setq params (cdr params)))
4852 (delq nil
4853 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4856 (defvar idlwave-xml-routine-info-file nil)
4858 (defun idlwave-save-routine-info ()
4859 (if idlwave-xml-routine-info-file
4860 (with-temp-file idlwave-xml-system-rinfo-converted-file
4861 (insert
4862 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4863 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4864 ;; Automatically generated from source file:
4865 ;; " idlwave-xml-routine-info-file "
4866 ;; on " (current-time-string) "
4867 ;; Do not edit."))
4868 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4869 idlwave-xml-routine-info-file))
4870 (insert "\n(setq idlwave-system-routines\n '")
4871 (prin1 idlwave-system-routines (current-buffer))
4872 (insert ")")
4873 (insert "\n(setq idlwave-system-variables-alist\n '")
4874 (prin1 idlwave-system-variables-alist (current-buffer))
4875 (insert ")")
4876 (insert "\n(setq idlwave-system-class-info\n '")
4877 (prin1 idlwave-system-class-info (current-buffer))
4878 (insert ")")
4879 (insert "\n(setq idlwave-executive-commands-alist\n '")
4880 (prin1 idlwave-executive-commands-alist (current-buffer))
4881 (insert ")")
4882 (insert "\n(setq idlwave-help-special-topic-words\n '")
4883 (prin1 idlwave-help-special-topic-words (current-buffer))
4884 (insert ")"))))
4886 (defun idlwave-convert-xml-system-routine-info ()
4887 "Convert XML supplied IDL routine info into internal form.
4888 Cache to disk for quick recovery."
4889 (interactive)
4890 (let* ((dir (file-name-as-directory
4891 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4892 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4893 (elem-cnt 0)
4894 props rinfo msg-cnt elem type nelem class-result alias
4895 routines routine-aliases statement-aliases sysvar-aliases)
4896 (if (not (file-exists-p catalog-file))
4897 (error "No such XML routine info file: %s" catalog-file)
4898 (if (not (file-readable-p catalog-file))
4899 (error "Cannot read XML routine info file: %s" catalog-file)))
4900 (message "Reading XML routine info...")
4901 (setq rinfo (xml-parse-file catalog-file))
4902 (message "Reading XML routine info...done")
4903 (setq rinfo (assq 'CATALOG rinfo))
4904 (unless rinfo (error "Failed to parse XML routine info"))
4905 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4907 (setq rinfo (cddr rinfo))
4909 (setq nelem (length rinfo)
4910 msg-cnt (/ nelem 20))
4912 (setq idlwave-xml-routine-info-file nil)
4913 (message "Converting XML routine info...")
4914 (setq idlwave-system-routines nil
4915 idlwave-system-variables-alist nil
4916 idlwave-system-class-info nil
4917 idlwave-executive-commands-alist nil
4918 idlwave-help-special-topic-words nil)
4920 (while rinfo
4921 (setq elem (car rinfo)
4922 rinfo (cdr rinfo))
4923 (incf elem-cnt)
4924 (when (listp elem)
4925 (setq type (car elem)
4926 props (car (cdr elem)))
4927 (if (= (mod elem-cnt msg-cnt) 0)
4928 (message "Converting XML routine info...%2d%%"
4929 (/ (* elem-cnt 100) nelem)))
4930 (cond
4931 ((eq type 'ROUTINE)
4932 (if (setq alias (assq 'alias_to props))
4933 (push (cons (cdr (assq 'name props)) (cdr alias))
4934 routine-aliases)
4935 (setq routines (idlwave-xml-create-rinfo-list elem))
4936 (if (listp (cdr routines))
4937 (setq idlwave-system-routines
4938 (nconc idlwave-system-routines routines))
4939 ;; a cons cell is an executive commands
4940 (push routines idlwave-executive-commands-alist))))
4942 ((eq type 'CLASS)
4943 (setq class-result (idlwave-xml-create-class-method-lists elem))
4944 (push (car class-result) idlwave-system-class-info)
4945 (setq idlwave-system-routines
4946 (nconc idlwave-system-routines (cdr class-result))))
4948 ((eq type 'STATEMENT)
4949 (push (cons (cdr (assq 'name props))
4950 (cdr (assq 'link props)))
4951 idlwave-help-special-topic-words)
4952 ;; Save the links to those which are statement aliases (not routines)
4953 (if (setq alias (assq 'alias_to props))
4954 (unless (member (cdr alias) statement-aliases)
4955 (push (cdr alias) statement-aliases))))
4957 ((eq type 'SYSVAR)
4958 (if (setq alias (cdr (assq 'alias_to props)))
4959 (push (cons (substring (cdr (assq 'name props)) 1)
4960 (substring alias 1))
4961 sysvar-aliases)
4962 (push (idlwave-xml-create-sysvar-alist elem)
4963 idlwave-system-variables-alist)))
4964 (t))))
4965 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4966 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4967 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4969 (setq idlwave-xml-routine-info-file catalog-file)
4970 (idlwave-save-routine-info)
4971 (message "Converting XML routine info...done")))
4974 ;; ("ROUTINE" type class
4975 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4976 ;; (buffer pro_file dir) | (compiled pro_file dir)
4977 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4978 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4981 (defun idlwave-load-rinfo-next-step ()
4982 (let ((inhibit-quit t)
4983 (arr idlwave-load-rinfo-steps-done))
4984 (if (catch 'exit
4985 (when (not (aref arr 0))
4986 (message "Loading system routine info in idle time...")
4987 (idlwave-load-system-routine-info)
4988 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4989 (message "Loading system routine info in idle time...done")
4990 (aset arr 0 t)
4991 (throw 'exit t))
4993 (when (not (aref arr 1))
4994 (message "Normalizing idlwave-system-routines in idle time...")
4995 (idlwave-reset-sintern t)
4996 (put 'idlwave-reset-sintern 'done-by-idle t)
4997 (setq idlwave-system-routines
4998 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4999 (message "Normalizing idlwave-system-routines in idle time...done")
5000 (aset arr 1 t)
5001 (throw 'exit t))
5003 (when (not (aref arr 2))
5004 (when (and (stringp idlwave-user-catalog-file)
5005 (file-regular-p idlwave-user-catalog-file))
5006 (message "Loading user catalog in idle time...")
5007 (condition-case nil
5008 (load-file idlwave-user-catalog-file)
5009 (error (throw 'exit nil)))
5010 ;; Check for the old style catalog and warn
5011 (if (and
5012 (boundp 'idlwave-library-routines)
5013 idlwave-library-routines)
5014 (progn
5015 (setq idlwave-library-routines nil)
5016 (ding)
5017 (message "Outdated user catalog: %s... recreate"
5018 idlwave-user-catalog-file))
5019 (message "Loading user catalog in idle time...done")))
5020 (aset arr 2 t)
5021 (throw 'exit t))
5023 (when (not (aref arr 3))
5024 (when idlwave-user-catalog-routines
5025 (message "Normalizing user catalog routines in idle time...")
5026 (setq idlwave-user-catalog-routines
5027 (idlwave-sintern-rinfo-list
5028 idlwave-user-catalog-routines 'sys))
5029 (message
5030 "Normalizing user catalog routines in idle time...done"))
5031 (aset arr 3 t)
5032 (throw 'exit t))
5034 (when (not (aref arr 4))
5035 (idlwave-scan-library-catalogs
5036 "Loading and normalizing library catalogs in idle time...")
5037 (aset arr 4 t)
5038 (throw 'exit t))
5039 (when (not (aref arr 5))
5040 (message "Finishing initialization in idle time...")
5041 (idlwave-routines)
5042 (message "Finishing initialization in idle time...done")
5043 (aset arr 5 t)
5044 (throw 'exit nil)))
5045 ;; restart the timer
5046 (if (sit-for 1)
5047 (idlwave-load-rinfo-next-step)
5048 (setq idlwave-load-rinfo-idle-timer
5049 (run-with-idle-timer
5050 idlwave-init-rinfo-when-idle-after
5051 nil 'idlwave-load-rinfo-next-step))))))
5053 (defvar idlwave-after-load-rinfo-hook nil)
5055 (defun idlwave-load-all-rinfo (&optional force)
5056 ;; Load and case-treat the system, user catalog, and library routine
5057 ;; info files.
5059 ;; System
5060 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
5061 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5062 (idlwave-load-system-routine-info))
5063 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5064 (message "Normalizing idlwave-system-routines...")
5065 (setq idlwave-system-routines
5066 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5067 (message "Normalizing idlwave-system-routines...done"))
5068 (when idlwave-system-routines
5069 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5070 (setq idlwave-last-system-routine-info-cons-cell
5071 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5073 ;; User catalog
5074 (when (and (stringp idlwave-user-catalog-file)
5075 (file-regular-p idlwave-user-catalog-file))
5076 (condition-case nil
5077 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5078 (load-file idlwave-user-catalog-file))
5079 (error nil))
5080 (when (and
5081 (boundp 'idlwave-library-routines)
5082 idlwave-library-routines)
5083 (setq idlwave-library-routines nil)
5084 (error "Outdated user catalog: %s... recreate"
5085 idlwave-user-catalog-file))
5086 (setq idlwave-true-path-alist nil)
5087 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5088 (message "Normalizing user catalog routines...")
5089 (setq idlwave-user-catalog-routines
5090 (idlwave-sintern-rinfo-list
5091 idlwave-user-catalog-routines 'sys))
5092 (message "Normalizing user catalog routines...done")))
5094 ;; Library catalog
5095 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5096 (idlwave-scan-library-catalogs
5097 "Loading and normalizing library catalogs..."))
5098 (run-hooks 'idlwave-after-load-rinfo-hook))
5101 (defun idlwave-update-buffer-routine-info ()
5102 (let (res)
5103 (cond
5104 ((eq idlwave-scan-all-buffers-for-routine-info t)
5105 ;; Scan all buffers, current buffer last
5106 (message "Scanning all buffers...")
5107 (setq res (idlwave-get-routine-info-from-buffers
5108 (reverse (buffer-list)))))
5109 ((null idlwave-scan-all-buffers-for-routine-info)
5110 ;; Don't scan any buffers
5111 (setq res nil))
5113 ;; Just scan this buffer
5114 (if (eq major-mode 'idlwave-mode)
5115 (progn
5116 (message "Scanning current buffer...")
5117 (setq res (idlwave-get-routine-info-from-buffers
5118 (list (current-buffer))))))))
5119 ;; Put the result into the correct variable
5120 (setq idlwave-buffer-routines
5121 (idlwave-sintern-rinfo-list res 'set))))
5123 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
5124 "Put the different sources for routine information together."
5125 ;; The sequence here is important because earlier definitions shadow
5126 ;; later ones. We assume that if things in the buffers are newer
5127 ;; then in the shell of the system, they are meant to be different.
5128 (setcdr idlwave-last-system-routine-info-cons-cell
5129 (append idlwave-buffer-routines
5130 idlwave-compiled-routines
5131 idlwave-library-catalog-routines
5132 idlwave-user-catalog-routines))
5133 (setq idlwave-class-alist nil)
5135 ;; Give a message with information about the number of routines we have.
5136 (unless quiet
5137 (message
5138 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5139 (length idlwave-buffer-routines)
5140 (length idlwave-compiled-routines)
5141 (length idlwave-library-catalog-routines)
5142 (length idlwave-user-catalog-routines)
5143 (length idlwave-system-routines)))
5144 (if run-hook
5145 (run-hooks 'idlwave-update-rinfo-hook)))
5147 (defun idlwave-class-alist ()
5148 "Return the class alist - make it if necessary."
5149 (or idlwave-class-alist
5150 (let (class)
5151 (loop for x in idlwave-routines do
5152 (when (and (setq class (nth 2 x))
5153 (not (assq class idlwave-class-alist)))
5154 (push (list class) idlwave-class-alist)))
5155 idlwave-class-alist)))
5157 ;; Three functions for the hooks
5158 (defun idlwave-save-buffer-update ()
5159 (idlwave-update-current-buffer-info 'save-buffer))
5160 (defun idlwave-kill-buffer-update ()
5161 (idlwave-update-current-buffer-info 'kill-buffer))
5162 (defun idlwave-new-buffer-update ()
5163 (idlwave-update-current-buffer-info 'find-file))
5165 (defun idlwave-update-current-buffer-info (why)
5166 "Update `idlwave-routines' for current buffer.
5167 Can run from `after-save-hook'."
5168 (when (and (eq major-mode 'idlwave-mode)
5169 (or (eq t idlwave-auto-routine-info-updates)
5170 (memq why idlwave-auto-routine-info-updates))
5171 idlwave-scan-all-buffers-for-routine-info
5172 idlwave-routines)
5173 (condition-case nil
5174 (let (routines)
5175 (idlwave-replace-buffer-routine-info
5176 (buffer-file-name)
5177 (if (eq why 'kill-buffer)
5179 (setq routines
5180 (idlwave-sintern-rinfo-list
5181 (idlwave-get-routine-info-from-buffers
5182 (list (current-buffer))) 'set))))
5183 (idlwave-concatenate-rinfo-lists 'quiet)
5184 routines)
5185 (error nil))))
5187 (defun idlwave-replace-buffer-routine-info (file new)
5188 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5189 (let ((list idlwave-buffer-routines)
5190 found)
5191 (while list
5192 ;; The following test uses eq to make sure it works correctly
5193 ;; when two buffers visit the same file. Then the file names
5194 ;; will be equal, but not eq.
5195 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
5196 (progn
5197 (setcar list nil)
5198 (setq found t))
5199 (if found
5200 ;; End of that section reached. Jump.
5201 (setq list nil)))
5202 (setq list (cdr list)))
5203 (setq idlwave-buffer-routines
5204 (append new (delq nil idlwave-buffer-routines)))))
5206 ;;----- Scanning buffers -------------------
5208 (defun idlwave-get-routine-info-from-buffers (buffers)
5209 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5210 (let (buf routine-lists res)
5211 (save-excursion
5212 (while (setq buf (pop buffers))
5213 (set-buffer buf)
5214 (if (and (eq major-mode 'idlwave-mode)
5215 buffer-file-name)
5216 ;; yes, this buffer has the right mode.
5217 (progn (setq res (condition-case nil
5218 (idlwave-get-buffer-routine-info)
5219 (error nil)))
5220 (push res routine-lists)))))
5221 ;; Concatenate the individual lists and return the result
5222 (apply 'nconc routine-lists)))
5224 (defun idlwave-get-buffer-routine-info ()
5225 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5226 (let* ((case-fold-search t)
5227 routine-list string entry)
5228 (save-excursion
5229 (save-restriction
5230 (widen)
5231 (goto-char (point-min))
5232 (while (re-search-forward
5233 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
5234 (setq string (buffer-substring-no-properties
5235 (match-beginning 0)
5236 (progn
5237 (idlwave-end-of-statement)
5238 (point))))
5239 (setq entry (idlwave-parse-definition string))
5240 (push entry routine-list))))
5241 routine-list))
5243 (defvar idlwave-scanning-lib-dir)
5244 (defvar idlwave-scanning-lib)
5245 (defun idlwave-parse-definition (string)
5246 "Parse a module definition."
5247 (let ((case-fold-search t)
5248 start name args type keywords class)
5249 ;; Remove comments
5250 (while (string-match ";.*" string)
5251 (setq string (replace-match "" t t string)))
5252 ;; Remove the continuation line stuff
5253 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5254 (setq string (replace-match "\\1 " t nil string)))
5255 (while (string-match "\n" string)
5256 (setq string (replace-match " " t nil string)))
5257 ;; Match the name and type.
5258 (when (string-match
5259 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5260 (setq start (match-end 0))
5261 (setq type (downcase (match-string 1 string)))
5262 (if (match-beginning 3)
5263 (setq class (match-string 3 string)))
5264 (setq name (match-string 4 string)))
5265 ;; Match normal args and keyword args
5266 (while (string-match
5267 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5268 string start)
5269 (setq start (match-end 0))
5270 (if (match-beginning 3)
5271 (push (match-string 1 string) keywords)
5272 (push (match-string 1 string) args)))
5273 ;; Normalize and sort.
5274 (setq args (nreverse args))
5275 (setq keywords (sort keywords (lambda (a b)
5276 (string< (downcase a) (downcase b)))))
5277 ;; Make and return the entry
5278 ;; We don't know which argument are optional, so this information
5279 ;; will not be contained in the calling sequence.
5280 (list name
5281 (if (equal type "pro") 'pro 'fun)
5282 class
5283 (cond ((not (boundp 'idlwave-scanning-lib))
5284 (list 'buffer (buffer-file-name)))
5285 ; ((string= (downcase
5286 ; (file-name-sans-extension
5287 ; (file-name-nondirectory (buffer-file-name))))
5288 ; (downcase name))
5289 ; (list 'lib))
5290 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5291 (t (list 'user (file-name-nondirectory (buffer-file-name))
5292 idlwave-scanning-lib-dir "UserLib")))
5293 (concat
5294 (if (string= type "function") "Result = " "")
5295 (if class "Obj ->[%s::]" "")
5296 "%s"
5297 (if args
5298 (concat
5299 (if (string= type "function") "(" ", ")
5300 (mapconcat 'identity args ", ")
5301 (if (string= type "function") ")" ""))))
5302 (if keywords
5303 (cons nil (mapcar 'list keywords)) ;No help file
5304 nil))))
5307 ;;----- Scanning the user catalog -------------------
5309 (defun idlwave-sys-dir ()
5310 "Return the syslib directory, or a dummy that never matches."
5311 (cond
5312 ((and idlwave-system-directory
5313 (not (string= idlwave-system-directory "")))
5314 idlwave-system-directory)
5315 ((getenv "IDL_DIR"))
5316 (t "@@@@@@@@")))
5319 (defun idlwave-create-user-catalog-file (&optional arg)
5320 "Scan all files on selected dirs of IDL search path for routine information.
5322 A widget checklist will allow you to choose the directories. Write
5323 the result as a file `idlwave-user-catalog-file'. When this file
5324 exists, it will be automatically loaded to give routine information
5325 about library routines. With ARG, just rescan the same directories
5326 as last time - so no widget will pop up."
5327 (interactive "P")
5328 ;; Make sure the file is loaded if it exists.
5329 (if (and (stringp idlwave-user-catalog-file)
5330 (file-regular-p idlwave-user-catalog-file))
5331 (condition-case nil
5332 (load-file idlwave-user-catalog-file)
5333 (error nil)))
5334 ;; Make sure the file name makes sense
5335 (unless (and (stringp idlwave-user-catalog-file)
5336 (> (length idlwave-user-catalog-file) 0)
5337 (file-accessible-directory-p
5338 (file-name-directory idlwave-user-catalog-file))
5339 (not (string= "" (file-name-nondirectory
5340 idlwave-user-catalog-file))))
5341 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5343 (cond
5344 ;; Rescan the known directories
5345 ((and arg idlwave-path-alist
5346 (consp (car idlwave-path-alist)))
5347 (idlwave-scan-user-lib-files idlwave-path-alist))
5349 ;; Expand the directories from library-path and run the widget
5350 (idlwave-library-path
5351 (idlwave-display-user-catalog-widget
5352 (if idlwave-true-path-alist
5353 ;; Propagate any flags on the existing path-alist
5354 (mapcar (lambda (x)
5355 (let ((path-entry (assoc (file-truename x)
5356 idlwave-true-path-alist)))
5357 (if path-entry
5358 (cons x (cdr path-entry))
5359 (list x))))
5360 (idlwave-expand-path idlwave-library-path))
5361 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5363 ;; Ask the shell for the path and then run the widget
5365 (message "Asking the shell for IDL path...")
5366 (require 'idlw-shell)
5367 (idlwave-shell-send-command idlwave-shell-path-query
5368 '(idlwave-user-catalog-command-hook nil)
5369 'hide))))
5372 ;; Parse shell path information and select among it.
5373 (defun idlwave-user-catalog-command-hook (&optional arg)
5374 ;; Command hook used by `idlwave-create-user-catalog-file'.
5375 (if arg
5376 ;; Scan immediately
5377 (idlwave-scan-user-lib-files idlwave-path-alist)
5378 ;; Set the path and display the widget
5379 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5380 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5381 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5383 (defconst idlwave-user-catalog-widget-help-string
5384 "This is the front-end to the creation of the IDLWAVE user catalog.
5385 Please select the directories on IDL's search path from which you
5386 would like to extract routine information, to be stored in the file:
5390 If this is not the correct file, first set variable
5391 `idlwave-user-catalog-file', and call this command again.
5393 N.B. Many libraries include pre-scanned catalog files
5394 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5395 not be scanned. You can scan your own libraries off-line using the
5396 perl script `idlwave_catalog'.
5398 After selecting the directories, choose [Scan & Save] to scan the library
5399 directories and save the routine info.
5400 \n")
5402 (defvar idlwave-widget)
5403 (defvar widget-keymap)
5404 (defun idlwave-display-user-catalog-widget (dirs-list)
5405 "Create the widget to select IDL search path directories for scanning."
5406 (interactive)
5407 (require 'widget)
5408 (require 'wid-edit)
5409 (unless dirs-list
5410 (error "Don't know IDL's search path"))
5412 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5413 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5414 (kill-all-local-variables)
5415 (make-local-variable 'idlwave-widget)
5416 (widget-insert (format idlwave-user-catalog-widget-help-string
5417 idlwave-user-catalog-file))
5419 (widget-create 'push-button
5420 :notify 'idlwave-widget-scan-user-lib-files
5421 "Scan & Save")
5422 (widget-insert " ")
5423 (widget-create 'push-button
5424 :notify 'idlwave-delete-user-catalog-file
5425 "Delete File")
5426 (widget-insert " ")
5427 (widget-create 'push-button
5428 :notify
5429 (lambda (&rest ignore)
5430 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5431 (dolist (x path-list)
5432 (unless (memq 'lib (cdr x))
5433 (idlwave-path-alist-add-flag x 'user)))
5434 (idlwave-display-user-catalog-widget path-list)))
5435 "Select All Non-Lib")
5436 (widget-insert " ")
5437 (widget-create 'push-button
5438 :notify
5439 (lambda (&rest ignore)
5440 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5441 (dolist (x path-list)
5442 (idlwave-path-alist-remove-flag x 'user))
5443 (idlwave-display-user-catalog-widget path-list)))
5444 "Deselect All")
5445 (widget-insert " ")
5446 (widget-create 'push-button
5447 :notify (lambda (&rest ignore)
5448 (kill-buffer (current-buffer)))
5449 "Quit")
5450 (widget-insert "\n\n")
5452 (widget-insert "Select Directories: \n")
5454 (setq idlwave-widget
5455 (apply 'widget-create
5456 'checklist
5457 :value (delq nil (mapcar (lambda (x)
5458 (if (memq 'user (cdr x))
5459 (car x)))
5460 dirs-list))
5461 :greedy t
5462 :tag "List of directories"
5463 (mapcar (lambda (x)
5464 (list 'item
5465 (if (memq 'lib (cdr x))
5466 (concat "[LIB] " (car x) )
5467 (car x)))) dirs-list)))
5468 (widget-put idlwave-widget :path-dirs dirs-list)
5469 (widget-insert "\n")
5470 (use-local-map widget-keymap)
5471 (widget-setup)
5472 (goto-char (point-min))
5473 (delete-other-windows))
5475 (defun idlwave-delete-user-catalog-file (&rest ignore)
5476 (if (yes-or-no-p
5477 (format "Delete file %s " idlwave-user-catalog-file))
5478 (progn
5479 (delete-file idlwave-user-catalog-file)
5480 (message "%s has been deleted" idlwave-user-catalog-file))))
5482 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5483 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5484 (let* ((widget idlwave-widget)
5485 (selected-dirs (widget-value widget))
5486 (path-alist (widget-get widget :path-dirs))
5487 (this-path-alist path-alist)
5488 dir-entry)
5489 (while (setq dir-entry (pop this-path-alist))
5490 (if (member
5491 (if (memq 'lib (cdr dir-entry))
5492 (concat "[LIB] " (car dir-entry))
5493 (car dir-entry))
5494 selected-dirs)
5495 (idlwave-path-alist-add-flag dir-entry 'user)
5496 (idlwave-path-alist-remove-flag dir-entry 'user)))
5497 (idlwave-scan-user-lib-files path-alist)))
5499 (defvar font-lock-mode)
5500 (defun idlwave-scan-user-lib-files (path-alist)
5501 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5502 (let* ((idlwave-scanning-lib t)
5503 (idlwave-scanning-lib-dir "")
5504 (idlwave-completion-case nil)
5505 dirs-alist dir files file)
5506 (setq idlwave-user-catalog-routines nil
5507 idlwave-path-alist path-alist ; for library-path instead
5508 idlwave-true-path-alist nil)
5509 (if idlwave-auto-write-paths (idlwave-write-paths))
5510 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5511 (idlwave-mode)
5512 (setq dirs-alist (reverse path-alist))
5513 (while (setq dir (pop dirs-alist))
5514 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5515 (setq dir (car dir))
5516 (setq idlwave-scanning-lib-dir dir)
5517 (when (file-directory-p dir)
5518 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5519 (while (setq file (pop files))
5520 (when (file-regular-p file)
5521 (if (not (file-readable-p file))
5522 (message "Skipping %s (no read permission)" file)
5523 (message "Scanning %s..." file)
5524 (erase-buffer)
5525 (insert-file-contents file 'visit)
5526 (setq idlwave-user-catalog-routines
5527 (append (idlwave-get-routine-info-from-buffers
5528 (list (current-buffer)))
5529 idlwave-user-catalog-routines)))))))))
5530 (message "Creating user catalog file...")
5531 (kill-buffer "*idlwave-scan.pro*")
5532 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5533 (let ((font-lock-maximum-size 0)
5534 (auto-mode-alist nil))
5535 (find-file idlwave-user-catalog-file))
5536 (if (and (boundp 'font-lock-mode)
5537 font-lock-mode)
5538 (font-lock-mode 0))
5539 (erase-buffer)
5540 (insert ";; IDLWAVE user catalog file\n")
5541 (insert (format ";; Created %s\n\n" (current-time-string)))
5543 ;; Define the routine info list
5544 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5545 (let ((standard-output (current-buffer)))
5546 (mapc (lambda (x)
5547 (insert "\n ")
5548 (prin1 x)
5549 (goto-char (point-max)))
5550 idlwave-user-catalog-routines))
5551 (insert (format "))\n\n;;; %s ends here\n"
5552 (file-name-nondirectory idlwave-user-catalog-file)))
5553 (goto-char (point-min))
5554 ;; Save the buffer
5555 (save-buffer 0)
5556 (kill-buffer (current-buffer)))
5557 (message "Creating user catalog file...done")
5558 (message "Info for %d routines saved in %s"
5559 (length idlwave-user-catalog-routines)
5560 idlwave-user-catalog-file)
5561 (sit-for 2)
5562 (idlwave-update-routine-info t))
5564 (defun idlwave-read-paths ()
5565 (if (and (stringp idlwave-path-file)
5566 (file-regular-p idlwave-path-file))
5567 (condition-case nil
5568 (load idlwave-path-file t t t)
5569 (error nil))))
5571 (defun idlwave-write-paths ()
5572 (interactive)
5573 (when (and idlwave-path-alist idlwave-system-directory)
5574 (let ((font-lock-maximum-size 0)
5575 (auto-mode-alist nil))
5576 (find-file idlwave-path-file))
5577 (if (and (boundp 'font-lock-mode)
5578 font-lock-mode)
5579 (font-lock-mode 0))
5580 (erase-buffer)
5581 (insert ";; IDLWAVE paths\n")
5582 (insert (format ";; Created %s\n\n" (current-time-string)))
5583 ;; Define the variable which knows the value of "!DIR"
5584 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5585 idlwave-system-directory))
5587 ;; Define the variable which contains a list of all scanned directories
5588 (insert "\n(setq idlwave-path-alist\n '(")
5589 (let ((standard-output (current-buffer)))
5590 (mapc (lambda (x)
5591 (insert "\n ")
5592 (prin1 x)
5593 (goto-char (point-max)))
5594 idlwave-path-alist))
5595 (insert "))\n")
5596 (save-buffer 0)
5597 (kill-buffer (current-buffer))))
5600 (defun idlwave-expand-path (path &optional default-dir)
5601 ;; Expand parts of path starting with '+' recursively into directory list.
5602 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5603 (message "Expanding path...")
5604 (let (path1 dir recursive)
5605 (while (setq dir (pop path))
5606 (if (setq recursive (string= (substring dir 0 1) "+"))
5607 (setq dir (substring dir 1)))
5608 (if (and recursive
5609 (not (file-name-absolute-p dir)))
5610 (setq dir (expand-file-name dir default-dir)))
5611 (if recursive
5612 ;; Expand recursively
5613 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5614 ;; Keep unchanged
5615 (push dir path1)))
5616 (message "Expanding path...done")
5617 (nreverse path1)))
5619 (defun idlwave-recursive-directory-list (dir)
5620 ;; Return a list of all directories below DIR, including DIR itself
5621 (let ((path (list dir)) path1 file files)
5622 (while (setq dir (pop path))
5623 (when (file-directory-p dir)
5624 (setq files (nreverse (directory-files dir t "[^.]")))
5625 (while (setq file (pop files))
5626 (if (file-directory-p file)
5627 (push (file-name-as-directory file) path)))
5628 (push dir path1)))
5629 path1))
5632 ;;----- Scanning the library catalogs ------------------
5637 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5638 "Scan for library catalog files (.idlwave_catalog) and ingest.
5640 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5641 instead, if present) are searched. Print MESSAGE-BASE along with the
5642 libraries being loaded, if passed, and skip loading/normalizing if
5643 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5644 be set to nil to disable library catalog scanning."
5645 (when idlwave-use-library-catalogs
5646 (let ((dirs
5647 (if idlwave-library-path
5648 (idlwave-expand-path idlwave-library-path)
5649 (mapcar 'car idlwave-path-alist)))
5650 (old-libname "")
5651 dir-entry dir catalog all-routines)
5652 (if message-base (message message-base))
5653 (while (setq dir (pop dirs))
5654 (catch 'continue
5655 (when (file-readable-p
5656 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5657 (unless no-load
5658 (setq idlwave-library-catalog-routines nil)
5659 ;; Load the catalog file
5660 (condition-case nil
5661 (load catalog t t t)
5662 (error (throw 'continue t)))
5663 (when (and
5664 message-base
5665 (not (string= idlwave-library-catalog-libname
5666 old-libname)))
5667 (message "%s" (concat message-base
5668 idlwave-library-catalog-libname))
5669 (setq old-libname idlwave-library-catalog-libname))
5670 (when idlwave-library-catalog-routines
5671 (setq all-routines
5672 (append
5673 (idlwave-sintern-rinfo-list
5674 idlwave-library-catalog-routines 'sys dir)
5675 all-routines))))
5677 ;; Add a 'lib flag if on path-alist
5678 (when (and idlwave-path-alist
5679 (setq dir-entry (assoc dir idlwave-path-alist)))
5680 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5681 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5682 (if message-base (message (concat message-base "done"))))))
5684 ;;----- Communicating with the Shell -------------------
5686 ;; First, here is the idl program which can be used to query IDL for
5687 ;; defined routines.
5688 (defconst idlwave-routine-info.pro
5690 ;; START OF IDLWAVE SUPPORT ROUTINES
5691 pro idlwave_print_safe,item,limit
5692 catch,err
5693 if err ne 0 then begin
5694 print,'Could not print item.'
5695 return
5696 endif
5697 if n_elements(item) gt limit then $
5698 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5699 else print,item
5702 pro idlwave_print_info_entry,name,func=func,separator=sep
5703 ;; See if it's an object method
5704 if name eq '' then return
5705 func = keyword_set(func)
5706 methsep = strpos(name,'::')
5707 meth = methsep ne -1
5709 ;; Get routine info
5710 pars = routine_info(name,/parameters,functions=func)
5711 source = routine_info(name,/source,functions=func)
5712 nargs = pars.num_args
5713 nkw = pars.num_kw_args
5714 if nargs gt 0 then args = pars.args
5715 if nkw gt 0 then kwargs = pars.kw_args
5717 ;; Trim the class, and make the name
5718 if meth then begin
5719 class = strmid(name,0,methsep)
5720 name = strmid(name,methsep+2,strlen(name)-1)
5721 if nargs gt 0 then begin
5722 ;; remove the self argument
5723 wh = where(args ne 'SELF',nargs)
5724 if nargs gt 0 then args = args[wh]
5725 endif
5726 endif else begin
5727 ;; No class, just a normal routine.
5728 class = \"\"
5729 endelse
5731 ;; Calling sequence
5732 cs = \"\"
5733 if func then cs = 'Result = '
5734 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5735 cs = cs + '%s'
5736 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5737 if nargs gt 0 then begin
5738 for j=0,nargs-1 do begin
5739 cs = cs + args[j]
5740 if j lt nargs-1 then cs = cs + ', '
5741 endfor
5743 if func then cs = cs + ')'
5744 ;; Keyword arguments
5745 kwstring = ''
5746 if nkw gt 0 then begin
5747 for j=0,nkw-1 do begin
5748 kwstring = kwstring + ' ' + kwargs[j]
5749 endfor
5750 endif
5752 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5754 print,ret + ': ' + name + sep + class + sep + source[0].path $
5755 + sep + cs + sep + kwstring
5758 pro idlwave_routine_info,file
5759 on_error,1
5760 sep = '<@>'
5761 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5762 all = routine_info()
5763 fileQ=n_elements(file) ne 0
5764 if fileQ then file=strtrim(file,2)
5765 for i=0L,n_elements(all)-1L do begin
5766 if fileQ then begin
5767 if (routine_info(all[i],/SOURCE)).path eq file then $
5768 idlwave_print_info_entry,all[i],separator=sep
5769 endif else idlwave_print_info_entry,all[i],separator=sep
5770 endfor
5771 all = routine_info(/functions)
5772 for i=0L,n_elements(all)-1L do begin
5773 if fileQ then begin
5774 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5775 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5776 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5777 endfor
5778 print,'>>>END OF IDLWAVE ROUTINE INFO'
5781 pro idlwave_get_sysvars
5782 on_error,1
5783 catch,error_status
5784 if error_status ne 0 then begin
5785 print, 'Cannot get info about system variables'
5786 endif else begin
5787 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5788 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5789 v = strsplit(s,' +',/regex,/extract) ; get variables
5790 for i=0L,n_elements(v)-1 do begin
5791 t = [''] ; get tag list
5792 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5793 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5794 endfor
5795 endelse
5798 pro idlwave_get_class_tags, class
5799 res = execute('tags=tag_names({'+class+'})')
5800 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5802 ;; END OF IDLWAVE SUPPORT ROUTINES
5804 "The IDL programs to get info from the shell.")
5806 (defvar idlwave-idlwave_routine_info-compiled nil
5807 "Remember if the routine info procedure is already compiled.")
5809 (defvar idlwave-shell-temp-pro-file)
5810 (defvar idlwave-shell-temp-rinfo-save-file)
5812 (defun idlwave-shell-compile-helper-routines (&optional wait)
5813 (unless (and idlwave-idlwave_routine_info-compiled
5814 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5815 (with-current-buffer (idlwave-find-file-noselect
5816 (idlwave-shell-temp-file 'pro))
5817 (erase-buffer)
5818 (insert idlwave-routine-info.pro)
5819 (save-buffer 0))
5820 (idlwave-shell-send-command
5821 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
5822 nil 'hide wait)
5823 (idlwave-shell-send-command
5824 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5825 (idlwave-shell-temp-file 'rinfo))
5826 nil 'hide)
5827 (setq idlwave-idlwave_routine_info-compiled t))
5829 ;; Restore if necessary. Must use execute to hide lame routine_info
5830 ;; errors on undefinded routine
5831 (idlwave-shell-send-command
5832 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5833 idlwave-shell-temp-rinfo-save-file
5834 idlwave-shell-temp-rinfo-save-file)
5835 nil 'hide))
5838 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5839 "Query the shell for routine_info of compiled modules and update the lists."
5840 ;; Save and compile the procedure. The compiled procedure is then
5841 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5842 ;; need to test for and possibly RESTORE the procedure each time we
5843 ;; use it, since the user may have killed or redefined it. In
5844 ;; particular, .RESET_SESSION will kill all user procedures. If
5845 ;; FILE is set, only update routine info for routines in that file.
5847 (idlwave-shell-compile-helper-routines wait)
5848 ; execute the routine_info procedure, and analyze the output
5849 (idlwave-shell-send-command
5850 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
5851 `(progn
5852 (idlwave-shell-routine-info-filter)
5853 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5854 'hide wait))
5856 ;; ---------------------------------------------------------------------------
5858 ;; Completion and displaying routine calling sequences
5860 (defvar idlwave-completion-help-info nil)
5861 (defvar idlwave-completion-help-links nil)
5862 (defvar idlwave-current-obj_new-class nil)
5863 (defvar idlwave-complete-special nil)
5864 (defvar method-selector)
5865 (defvar class-selector)
5866 (defvar type-selector)
5867 (defvar super-classes)
5869 (defun idlwave-complete (&optional arg module class)
5870 "Complete a function, procedure or keyword name at point.
5871 This function is smart and figures out what can be completed
5872 at this point.
5873 - At the beginning of a statement it completes procedure names.
5874 - In the middle of a statement it completes function names.
5875 - After a `(' or `,' in the argument list of a function or procedure,
5876 it completes a keyword of the relevant function or procedure.
5877 - In the first arg of `OBJ_NEW', it completes a class name.
5879 When several completions are possible, a list will be displayed in
5880 the *Completions* buffer. If this list is too long to fit into the
5881 window, scrolling can be achieved by repeatedly pressing
5882 \\[idlwave-complete].
5884 The function also knows about object methods. When it needs a class
5885 name, the action depends upon `idlwave-query-class', which see. You
5886 can force IDLWAVE to ask you for a class name with a
5887 \\[universal-argument] prefix argument to this command.
5889 See also the variables `idlwave-keyword-completion-adds-equal' and
5890 `idlwave-function-completion-adds-paren'.
5892 The optional ARG can be used to specify the completion type in order
5893 to override IDLWAVE's idea of what should be completed at point.
5894 Possible values are:
5896 0 <=> query for the completion type
5897 1 <=> 'procedure
5898 2 <=> 'procedure-keyword
5899 3 <=> 'function
5900 4 <=> 'function-keyword
5901 5 <=> 'procedure-method
5902 6 <=> 'procedure-method-keyword
5903 7 <=> 'function-method
5904 8 <=> 'function-method-keyword
5905 9 <=> 'class
5907 As a special case, the universal argument C-u forces completion of
5908 function names in places where the default would be a keyword.
5910 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5911 completion.
5913 For Lisp programmers only:
5914 When we force a keyword, optional argument MODULE can contain the module name.
5915 When we force a method or a method keyword, CLASS can specify the class."
5916 (interactive "P")
5917 (idlwave-routines)
5918 (let* ((where-list
5919 (if (and arg
5920 (or (and (integerp arg) (not (equal arg '(16))))
5921 (symbolp arg)))
5922 (idlwave-make-force-complete-where-list arg module class)
5923 (idlwave-where)))
5924 (what (nth 2 where-list))
5925 (idlwave-force-class-query (equal arg '(4)))
5926 (completion-regexp-list
5927 (if (equal arg '(16))
5928 (list (read-string (concat "Completion Regexp: "))))))
5930 (if (and module (string-match "::" module))
5931 (setq class (substring module 0 (match-beginning 0))
5932 module (substring module (match-end 0))))
5934 (cond
5936 ((and (null arg)
5937 (eq (car-safe last-command) 'idlwave-display-completion-list)
5938 (get-buffer-window "*Completions*"))
5939 (setq this-command last-command)
5940 (idlwave-scroll-completions))
5942 ;; Complete a filename in quotes
5943 ((and (idlwave-in-quote)
5944 (not (eq what 'class)))
5945 (idlwave-complete-filename))
5947 ;; Check for any special completion functions
5948 ((and idlwave-complete-special
5949 (idlwave-call-special idlwave-complete-special)))
5951 ((null what)
5952 (error "Nothing to complete here"))
5954 ;; Complete a class
5955 ((eq what 'class)
5956 (setq idlwave-completion-help-info '(class))
5957 (idlwave-complete-class))
5959 ((eq what 'procedure)
5960 ;; Complete a procedure name
5961 (let* ((cw-list (nth 3 where-list))
5962 (class-selector (idlwave-determine-class cw-list 'pro))
5963 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5964 (idlwave-all-class-inherits class-selector)))
5965 (isa (concat "procedure" (if class-selector "-method" "")))
5966 (type-selector 'pro))
5967 (setq idlwave-completion-help-info
5968 (list 'routine nil type-selector class-selector nil super-classes))
5969 (idlwave-complete-in-buffer
5970 'procedure (if class-selector 'method 'routine)
5971 (idlwave-routines) 'idlwave-selector
5972 (format "Select a %s name%s"
5974 (if class-selector
5975 (format " (class is %s)"
5976 (if (eq class-selector t)
5977 "unknown" class-selector))
5978 ""))
5980 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5982 ((eq what 'function)
5983 ;; Complete a function name
5984 (let* ((cw-list (nth 3 where-list))
5985 (class-selector (idlwave-determine-class cw-list 'fun))
5986 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5987 (idlwave-all-class-inherits class-selector)))
5988 (isa (concat "function" (if class-selector "-method" "")))
5989 (type-selector 'fun))
5990 (setq idlwave-completion-help-info
5991 (list 'routine nil type-selector class-selector nil super-classes))
5992 (idlwave-complete-in-buffer
5993 'function (if class-selector 'method 'routine)
5994 (idlwave-routines) 'idlwave-selector
5995 (format "Select a %s name%s"
5997 (if class-selector
5998 (format " (class is %s)"
5999 (if (eq class-selector t)
6000 "unknown" class-selector))
6001 ""))
6003 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
6005 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
6006 (equal arg '(4)))
6007 (idlwave-complete 3))
6009 ((eq what 'procedure-keyword)
6010 ;; Complete a procedure keyword
6011 (let* ((where (nth 3 where-list))
6012 (name (car where))
6013 (method-selector name)
6014 (type-selector 'pro)
6015 (class (idlwave-determine-class where 'pro))
6016 (class-selector class)
6017 (super-classes (idlwave-all-class-inherits class-selector))
6018 (isa (format "procedure%s-keyword" (if class "-method" "")))
6019 (entry (idlwave-best-rinfo-assq
6020 name 'pro class (idlwave-routines)))
6021 (system (if entry (eq (car (nth 3 entry)) 'system)))
6022 (list (idlwave-entry-keywords entry 'do-link)))
6023 (unless (or entry (eq class t))
6024 (error "Nothing known about procedure %s"
6025 (idlwave-make-full-name class name)))
6026 (setq list (idlwave-fix-keywords name 'pro class list
6027 super-classes system))
6028 (unless list (error "No keywords available for procedure %s"
6029 (idlwave-make-full-name class name)))
6030 (setq idlwave-completion-help-info
6031 (list 'keyword name type-selector class-selector entry super-classes))
6032 (idlwave-complete-in-buffer
6033 'keyword 'keyword list nil
6034 (format "Select keyword for procedure %s%s"
6035 (idlwave-make-full-name class name)
6036 (if (or (member '("_EXTRA") list)
6037 (member '("_REF_EXTRA") list))
6038 " (note _EXTRA)" ""))
6040 'idlwave-attach-keyword-classes)))
6042 ((eq what 'function-keyword)
6043 ;; Complete a function keyword
6044 (let* ((where (nth 3 where-list))
6045 (name (car where))
6046 (method-selector name)
6047 (type-selector 'fun)
6048 (class (idlwave-determine-class where 'fun))
6049 (class-selector class)
6050 (super-classes (idlwave-all-class-inherits class-selector))
6051 (isa (format "function%s-keyword" (if class "-method" "")))
6052 (entry (idlwave-best-rinfo-assq
6053 name 'fun class (idlwave-routines)))
6054 (system (if entry (eq (car (nth 3 entry)) 'system)))
6055 (list (idlwave-entry-keywords entry 'do-link))
6056 msg-name)
6057 (unless (or entry (eq class t))
6058 (error "Nothing known about function %s"
6059 (idlwave-make-full-name class name)))
6060 (setq list (idlwave-fix-keywords name 'fun class list
6061 super-classes system))
6062 ;; OBJ_NEW: Messages mention the proper Init method
6063 (setq msg-name (if (and (null class)
6064 (string= (upcase name) "OBJ_NEW"))
6065 (concat idlwave-current-obj_new-class
6066 "::Init (via OBJ_NEW)")
6067 (idlwave-make-full-name class name)))
6068 (unless list (error "No keywords available for function %s"
6069 msg-name))
6070 (setq idlwave-completion-help-info
6071 (list 'keyword name type-selector class-selector nil super-classes))
6072 (idlwave-complete-in-buffer
6073 'keyword 'keyword list nil
6074 (format "Select keyword for function %s%s" msg-name
6075 (if (or (member '("_EXTRA") list)
6076 (member '("_REF_EXTRA") list))
6077 " (note _EXTRA)" ""))
6079 'idlwave-attach-keyword-classes)))
6081 (t (error "This should not happen (idlwave-complete)")))))
6083 (defvar idlwave-complete-special nil
6084 "List of special completion functions.
6085 These functions are called for each completion. Each function must
6086 check if its own special completion context is present. If yes, it
6087 should use `idlwave-complete-in-buffer' to do some completion and
6088 return t. If such a function returns t, *no further* attempts to
6089 complete other contexts will be done. If the function returns nil,
6090 other completions will be tried.")
6092 (defun idlwave-call-special (functions &rest args)
6093 (let ((funcs functions)
6094 fun ret)
6095 (catch 'exit
6096 (while (setq fun (pop funcs))
6097 (if (setq ret (apply fun args))
6098 (throw 'exit ret)))
6099 nil)))
6101 (defun idlwave-make-force-complete-where-list (what &optional module class)
6102 ;; Return an artificial WHERE specification to force the completion
6103 ;; routine to complete a specific item independent of context.
6104 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6105 ;; MODULE and CLASS can be used to specify the routine name and class.
6106 ;; The class name will also be found in MODULE if that is like "class::mod".
6107 (let* ((what-list '(("procedure") ("procedure-keyword")
6108 ("function") ("function-keyword")
6109 ("procedure-method") ("procedure-method-keyword")
6110 ("function-method") ("function-method-keyword")
6111 ("class")))
6112 (module (idlwave-sintern-routine-or-method module class))
6113 (class (idlwave-sintern-class class))
6114 (what (cond
6115 ((equal what 0)
6116 (setq what
6117 (intern (completing-read
6118 "Complete what? " what-list nil t))))
6119 ((integerp what)
6120 (setq what (intern (car (nth (1- what) what-list)))))
6121 ((and what
6122 (symbolp what)
6123 (assoc (symbol-name what) what-list))
6124 what)
6125 (t (error "Invalid WHAT"))))
6126 (nil-list '(nil nil nil nil))
6127 (class-list (list nil nil (or class t) nil)))
6129 (cond
6131 ((eq what 'procedure)
6132 (list nil-list nil-list 'procedure nil-list nil))
6134 ((eq what 'procedure-keyword)
6135 (let* ((class-selector nil)
6136 (super-classes nil)
6137 (type-selector 'pro)
6138 (pro (or module
6139 (idlwave-completing-read
6140 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6141 (setq pro (idlwave-sintern-routine pro))
6142 (list nil-list nil-list 'procedure-keyword
6143 (list pro nil nil nil) nil)))
6145 ((eq what 'function)
6146 (list nil-list nil-list 'function nil-list nil))
6148 ((eq what 'function-keyword)
6149 (let* ((class-selector nil)
6150 (super-classes nil)
6151 (type-selector 'fun)
6152 (func (or module
6153 (idlwave-completing-read
6154 "Function: " (idlwave-routines) 'idlwave-selector))))
6155 (setq func (idlwave-sintern-routine func))
6156 (list nil-list nil-list 'function-keyword
6157 (list func nil nil nil) nil)))
6159 ((eq what 'procedure-method)
6160 (list nil-list nil-list 'procedure class-list nil))
6162 ((eq what 'procedure-method-keyword)
6163 (let* ((class (idlwave-determine-class class-list 'pro))
6164 (class-selector class)
6165 (super-classes (idlwave-all-class-inherits class-selector))
6166 (type-selector 'pro)
6167 (pro (or module
6168 (idlwave-completing-read
6169 (format "Procedure in %s class: " class-selector)
6170 (idlwave-routines) 'idlwave-selector))))
6171 (setq pro (idlwave-sintern-method pro))
6172 (list nil-list nil-list 'procedure-keyword
6173 (list pro nil class nil) nil)))
6175 ((eq what 'function-method)
6176 (list nil-list nil-list 'function class-list nil))
6178 ((eq what 'function-method-keyword)
6179 (let* ((class (idlwave-determine-class class-list 'fun))
6180 (class-selector class)
6181 (super-classes (idlwave-all-class-inherits class-selector))
6182 (type-selector 'fun)
6183 (func (or module
6184 (idlwave-completing-read
6185 (format "Function in %s class: " class-selector)
6186 (idlwave-routines) 'idlwave-selector))))
6187 (setq func (idlwave-sintern-method func))
6188 (list nil-list nil-list 'function-keyword
6189 (list func nil class nil) nil)))
6191 ((eq what 'class)
6192 (list nil-list nil-list 'class nil-list nil))
6194 (t (error "Invalid value for WHAT")))))
6196 (defun idlwave-completing-read (&rest args)
6197 ;; Completing read, case insensitive
6198 (let ((old-value (default-value 'completion-ignore-case)))
6199 (unwind-protect
6200 (progn
6201 (setq-default completion-ignore-case t)
6202 (apply 'completing-read args))
6203 (setq-default completion-ignore-case old-value))))
6205 (defvar idlwave-shell-default-directory)
6206 (defun idlwave-complete-filename ()
6207 "Use the comint stuff to complete a file name."
6208 (require 'comint)
6209 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6210 (comint-completion-addsuffix nil)
6211 (default-directory
6212 (if (and (boundp 'idlwave-shell-default-directory)
6213 (stringp idlwave-shell-default-directory)
6214 (file-directory-p idlwave-shell-default-directory))
6215 idlwave-shell-default-directory
6216 default-directory)))
6217 (comint-dynamic-complete-filename)))
6219 (defun idlwave-make-full-name (class name)
6220 ;; Make a fully qualified module name including the class name
6221 (concat (if class (format "%s::" class) "") name))
6223 (defun idlwave-rinfo-assoc (name type class list)
6224 "Like `idlwave-rinfo-assq', but sintern strings first."
6225 (idlwave-rinfo-assq
6226 (idlwave-sintern-routine-or-method name class)
6227 type (idlwave-sintern-class class) list))
6229 (defun idlwave-rinfo-assq (name type class list)
6230 ;; Works like assq, but also checks type and class
6231 (catch 'exit
6232 (let (match)
6233 (while (setq match (assq name list))
6234 (and (or (eq type t)
6235 (eq (nth 1 match) type))
6236 (eq (nth 2 match) class)
6237 (throw 'exit match))
6238 (setq list (cdr (memq match list)))))))
6240 (defun idlwave-rinfo-assq-any-class (name type class list)
6241 ;; Return the first matching method on the inheritance list
6242 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6243 class rtn)
6244 (while classes
6245 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6246 (setq classes nil)))
6247 rtn))
6249 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
6250 keep-system)
6251 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6252 If WITH-FILE is passed, find the best rinfo entry with a file
6253 included. If KEEP-SYSTEM is set, don't prune system for compiled
6254 syslib files."
6255 (let ((twins (idlwave-routine-twins
6256 (idlwave-rinfo-assq-any-class name type class list)
6257 list))
6258 syslibp)
6259 (when (> (length twins) 1)
6260 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
6261 (if (and (null keep-system)
6262 (eq 'system (car (nth 3 (car twins))))
6263 (setq syslibp (idlwave-any-syslib (cdr twins)))
6264 (not (equal 1 syslibp)))
6265 ;; Its a compiled syslib, so we need to remove the system entry
6266 (setq twins (cdr twins)))
6267 (if with-file
6268 (setq twins (delq nil
6269 (mapcar (lambda (x)
6270 (if (nth 1 (nth 3 x)) x))
6271 twins)))))
6272 (car twins)))
6274 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
6275 keep-system)
6276 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6277 (idlwave-best-rinfo-assq
6278 (idlwave-sintern-routine-or-method name class)
6279 type (idlwave-sintern-class class) list with-file keep-system))
6281 (defun idlwave-any-syslib (entries)
6282 "Does the entry list ENTRIES contain a syslib entry?
6283 If yes, return the index (>=1)."
6284 (let (file (cnt 0))
6285 (catch 'exit
6286 (while entries
6287 (incf cnt)
6288 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6289 (if (and file (idlwave-syslib-p file))
6290 (throw 'exit cnt)
6291 (setq entries (cdr entries))))
6292 nil)))
6294 (defun idlwave-all-assq (key list)
6295 "Return a list of all associations of Key in LIST."
6296 (let (rtn elt)
6297 (while (setq elt (assq key list))
6298 (push elt rtn)
6299 (setq list (cdr (memq elt list))))
6300 (nreverse rtn)))
6302 (defun idlwave-all-method-classes (method &optional type)
6303 "Return all classes which have a method METHOD.
6304 TYPE is 'fun or 'pro.
6305 When TYPE is not specified, both procedures and functions will be considered."
6306 (if (null method)
6307 (mapcar 'car (idlwave-class-alist))
6308 (let (rtn)
6309 (mapc (lambda (x)
6310 (and (nth 2 x)
6311 (or (not type)
6312 (eq type (nth 1 x)))
6313 (push (nth 2 x) rtn)))
6314 (idlwave-all-assq method (idlwave-routines)))
6315 (idlwave-uniquify rtn))))
6317 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
6318 "Return all classes which have a method METHOD with keyword KEYWORD.
6319 TYPE is 'fun or 'pro.
6320 When TYPE is not specified, both procedures and functions will be considered."
6321 (if (or (null method)
6322 (null keyword))
6324 (let (rtn)
6325 (mapc (lambda (x)
6326 (and (nth 2 x) ; non-nil class
6327 (or (not type) ; correct or unspecified type
6328 (eq type (nth 1 x)))
6329 (assoc keyword (idlwave-entry-keywords x))
6330 (push (nth 2 x) rtn)))
6331 (idlwave-all-assq method (idlwave-routines)))
6332 (idlwave-uniquify rtn))))
6334 (defun idlwave-members-only (list club)
6335 "Return list of all elements in LIST which are also in CLUB."
6336 (let (rtn)
6337 (while list
6338 (if (member (car list) club)
6339 (setq rtn (cons (car list) rtn)))
6340 (setq list (cdr list)))
6341 (nreverse rtn)))
6343 (defun idlwave-nonmembers-only (list club)
6344 "Return list of all elements in LIST which are not in CLUB."
6345 (let (rtn)
6346 (while list
6347 (if (member (car list) club)
6349 (setq rtn (cons (car list) rtn)))
6350 (setq list (cdr list)))
6351 (nreverse rtn)))
6353 (defun idlwave-explicit-class-listed (info)
6354 "Return whether or not the class is listed explicitly, ala a->b::c.
6355 INFO is as returned by `idlwave-what-function' or `-procedure'."
6356 (let ((apos (nth 3 info)))
6357 (if apos
6358 (save-excursion (goto-char apos)
6359 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6361 (defvar idlwave-determine-class-special nil
6362 "List of special functions for determining class.
6363 Must accept two arguments: `apos' and `info'.")
6365 (defun idlwave-determine-class (info type)
6366 ;; Determine the class of a routine call.
6367 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6368 ;; The second element in this structure is the class. When nil, we
6369 ;; return nil. When t, try to get the class from text properties at
6370 ;; the arrow. When the object is "self", we use the class of the
6371 ;; current routine. otherwise prompt the user for a class name.
6372 ;; Also stores the selected class as a text property at the arrow.
6373 ;; TYPE is 'fun or 'pro.
6374 (let* ((class (nth 2 info))
6375 (apos (nth 3 info))
6376 (nassoc (assoc (if (stringp (car info))
6377 (upcase (car info))
6378 (car info))
6379 idlwave-query-class))
6380 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6381 idlwave-query-class))
6382 (query (cond (nassoc (cdr nassoc))
6383 (dassoc (cdr dassoc))
6384 (t t)))
6385 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
6386 (is-self
6387 (and arrow
6388 (save-excursion (goto-char apos)
6389 (forward-word -1)
6390 (let ((case-fold-search t))
6391 (looking-at "self\\>")))))
6392 (force-query idlwave-force-class-query)
6393 store special-class class-alist)
6394 (cond
6395 ((null class) nil)
6396 ((eq t class)
6397 ;; There is an object which would like to know its class
6398 (if (and arrow (get-text-property apos 'idlwave-class)
6399 idlwave-store-inquired-class
6400 (not force-query))
6401 (setq class (get-text-property apos 'idlwave-class)
6402 class (idlwave-sintern-class class)))
6403 (if (and (eq t class) is-self)
6404 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6406 ;; Before prompting, try any special class determination routines
6407 (when (and (eq t class)
6408 idlwave-determine-class-special
6409 (not force-query))
6410 (setq special-class
6411 (idlwave-call-special idlwave-determine-class-special apos))
6412 (if special-class
6413 (setq class (idlwave-sintern-class special-class)
6414 store idlwave-store-inquired-class)))
6416 ;; Prompt for a class, if we need to
6417 (when (and (eq class t)
6418 (or force-query query))
6419 (setq class-alist
6420 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6421 (setq class
6422 (idlwave-sintern-class
6423 (cond
6424 ((and (= (length class-alist) 0) (not force-query))
6425 (error "No classes available with method %s" (car info)))
6426 ((and (= (length class-alist) 1) (not force-query))
6427 (car (car class-alist)))
6429 (setq store idlwave-store-inquired-class)
6430 (idlwave-completing-read
6431 (format "Class%s: " (if (stringp (car info))
6432 (format " for %s method %s"
6433 type (car info))
6434 ""))
6435 class-alist nil nil nil 'idlwave-class-history))))))
6437 ;; Store it, if requested
6438 (when (and class (not (eq t class)))
6439 ;; We have a real class here
6440 (when (and store arrow)
6441 (condition-case ()
6442 (add-text-properties
6443 apos (+ apos 2)
6444 `(idlwave-class ,class face ,idlwave-class-arrow-face
6445 rear-nonsticky t))
6446 (error nil)))
6447 (setf (nth 2 info) class))
6448 ;; Return the class
6449 class)
6450 ;; Default as fallback
6451 (t class))))
6453 (defun idlwave-selector (a)
6454 (and (eq (nth 1 a) type-selector)
6455 (or (and (nth 2 a) (eq class-selector t))
6456 (eq (nth 2 a) class-selector)
6457 (memq (nth 2 a) super-classes))))
6459 (defun idlwave-add-file-link-selector (a)
6460 ;; Record a file link, if any, for the tested names during selection.
6461 (let ((sel (idlwave-selector a)) file)
6462 (if (and sel (setq file (idlwave-entry-has-help a)))
6463 (push (cons (car a) file) idlwave-completion-help-links))
6464 sel))
6467 (defun idlwave-where ()
6468 "Find out where we are.
6469 The return value is a list with the following stuff:
6470 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6472 PRO-LIST (PRO POINT CLASS ARROW)
6473 FUNC-LIST (FUNC POINT CLASS ARROW)
6474 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6475 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6476 be completed here.
6477 LAST-CHAR last relevant character before point (non-white non-comment,
6478 not part of current identifier or leading slash).
6480 In the lists, we have these meanings:
6481 PRO: Procedure name
6482 FUNC: Function name
6483 POINT: Where is this
6484 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6485 ARROW: Location of the arrow"
6486 (idlwave-routines)
6487 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6488 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
6489 (func-entry (idlwave-what-function bos))
6490 (func (car func-entry))
6491 (func-class (nth 1 func-entry))
6492 (func-arrow (nth 2 func-entry))
6493 (func-point (or (nth 3 func-entry) 0))
6494 (func-level (or (nth 4 func-entry) 0))
6495 (pro-entry (idlwave-what-procedure bos))
6496 (pro (car pro-entry))
6497 (pro-class (nth 1 pro-entry))
6498 (pro-arrow (nth 2 pro-entry))
6499 (pro-point (or (nth 3 pro-entry) 0))
6500 (last-char (idlwave-last-valid-char))
6501 (case-fold-search t)
6502 (match-string (buffer-substring bos (point)))
6503 cw cw-mod cw-arrow cw-class cw-point)
6504 (if (< func-point pro-point) (setq func nil))
6505 (cond
6506 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6507 match-string)
6508 (setq cw 'class))
6509 ((string-match
6510 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6511 (if (> pro-point 0)
6512 (buffer-substring pro-point (point))
6513 match-string))
6514 (setq cw 'procedure cw-class pro-class cw-point pro-point
6515 cw-arrow pro-arrow))
6516 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6517 match-string)
6518 nil)
6519 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6520 match-string)
6521 (setq cw 'class))
6522 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6523 match-string)
6524 (setq cw 'class))
6525 ((and func
6526 (> func-point pro-point)
6527 (= func-level 1)
6528 (memq last-char '(?\( ?,)))
6529 (setq cw 'function-keyword cw-mod func cw-point func-point
6530 cw-class func-class cw-arrow func-arrow))
6531 ((and pro (eq last-char ?,))
6532 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6533 cw-class pro-class cw-arrow pro-arrow))
6534 ; ((member last-char '(?\' ?\) ?\] ?!))
6535 ; ;; after these chars, a function makes no sense
6536 ; ;; FIXME: I am sure there can be more in this list
6537 ; ;; FIXME: Do we want to do this at all?
6538 ; nil)
6539 ;; Everywhere else we try a function.
6541 (setq cw 'function)
6542 (save-excursion
6543 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6544 (setq cw-arrow (copy-marker (match-beginning 0))
6545 cw-class (if (match-end 4)
6546 (idlwave-sintern-class (match-string 4))
6547 t))))))
6548 (list (list pro pro-point pro-class pro-arrow)
6549 (list func func-point func-class func-arrow)
6551 (list cw-mod cw-point cw-class cw-arrow)
6552 last-char)))
6554 (defun idlwave-this-word (&optional class)
6555 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6556 (setq class (or class "a-zA-Z0-9$_."))
6557 (save-excursion
6558 (buffer-substring
6559 (progn (skip-chars-backward class) (point))
6560 (progn (skip-chars-forward class) (point)))))
6562 (defun idlwave-what-function (&optional bound)
6563 ;; Find out if point is within the argument list of a function.
6564 ;; The return value is ("function-name" class arrow-start (point) level).
6565 ;; Level is 1 on the top level parentheses, higher further down.
6567 ;; If the optional BOUND is an integer, bound backwards directed
6568 ;; searches to this point.
6570 (catch 'exit
6571 (let (pos
6572 func-point
6573 (cnt 0)
6574 func arrow-start class)
6575 (idlwave-with-special-syntax
6576 (save-restriction
6577 (save-excursion
6578 (narrow-to-region (max 1 (or bound 0)) (point-max))
6579 ;; move back out of the current parenthesis
6580 (while (condition-case nil
6581 (progn (up-list -1) t)
6582 (error nil))
6583 (setq pos (point))
6584 (incf cnt)
6585 (when (and (= (following-char) ?\()
6586 (re-search-backward
6587 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6588 bound t))
6589 (setq func (match-string 2)
6590 func-point (goto-char (match-beginning 2))
6591 pos func-point)
6592 (if (re-search-backward
6593 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6594 (setq arrow-start (copy-marker (match-beginning 0))
6595 class (or (match-string 2) t)))
6596 (throw
6597 'exit
6598 (list
6599 (idlwave-sintern-routine-or-method func class)
6600 (idlwave-sintern-class class)
6601 arrow-start func-point cnt)))
6602 (goto-char pos))
6603 (throw 'exit nil)))))))
6605 (defun idlwave-what-procedure (&optional bound)
6606 ;; Find out if point is within the argument list of a procedure.
6607 ;; The return value is ("procedure-name" class arrow-pos (point)).
6609 ;; If the optional BOUND is an integer, bound backwards directed
6610 ;; searches to this point.
6611 (let ((pos (point)) pro-point
6612 pro class arrow-start string)
6613 (save-excursion
6614 ;;(idlwave-beginning-of-statement)
6615 (idlwave-start-of-substatement 'pre)
6616 (setq string (buffer-substring (point) pos))
6617 (if (string-match
6618 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6619 (setq pro (match-string 1 string)
6620 pro-point (+ (point) (match-beginning 1)))
6621 (if (and (idlwave-skip-object)
6622 (setq string (buffer-substring (point) pos))
6623 (string-match
6624 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6625 string))
6626 (setq pro (if (match-beginning 4)
6627 (match-string 4 string))
6628 pro-point (if (match-beginning 4)
6629 (+ (point) (match-beginning 4))
6630 pos)
6631 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6632 class (or (match-string 3 string) t)))))
6633 (list (idlwave-sintern-routine-or-method pro class)
6634 (idlwave-sintern-class class)
6635 arrow-start
6636 pro-point)))
6638 (defun idlwave-skip-object ()
6639 ;; If there is an object at point, move over it and return t.
6640 (let ((pos (point)))
6641 (if (catch 'exit
6642 (save-excursion
6643 (skip-chars-forward " ") ; white space
6644 (skip-chars-forward "*") ; de-reference
6645 (cond
6646 ((looking-at idlwave-identifier)
6647 (goto-char (match-end 0)))
6648 ((eq (following-char) ?\()
6649 nil)
6650 (t (throw 'exit nil)))
6651 (catch 'endwhile
6652 (while t
6653 (cond ((eq (following-char) ?.)
6654 (forward-char 1)
6655 (if (not (looking-at idlwave-identifier))
6656 (throw 'exit nil))
6657 (goto-char (match-end 0)))
6658 ((memq (following-char) '(?\( ?\[))
6659 (condition-case nil
6660 (forward-list 1)
6661 (error (throw 'exit nil))))
6662 (t (throw 'endwhile t)))))
6663 (if (looking-at "[ \t]*->")
6664 (throw 'exit (setq pos (match-beginning 0)))
6665 (throw 'exit nil))))
6666 (goto-char pos)
6667 nil)))
6669 (defun idlwave-last-valid-char ()
6670 "Return the last character before point which is not white or a comment
6671 and also not part of the current identifier. Since we do this in
6672 order to identify places where keywords are, we consider the initial
6673 `/' of a keyword as part of the identifier.
6674 This function is not general, can only be used for completion stuff."
6675 (catch 'exit
6676 (save-excursion
6677 ;; skip the current identifier
6678 (skip-chars-backward "a-zA-Z0-9_$")
6679 ;; also skip a leading slash which might be belong to the keyword
6680 (if (eq (preceding-char) ?/)
6681 (backward-char 1))
6682 ;; FIXME: does not check if this is a valid identifier
6683 (while t
6684 (skip-chars-backward " \t")
6685 (cond
6686 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6687 ((eq (preceding-char) ?\n)
6688 (beginning-of-line 0)
6689 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6690 ;; continuation line
6691 (goto-char (match-end 1))
6692 (throw 'exit nil)))
6693 (t (throw 'exit (preceding-char))))))))
6695 (defvar idlwave-complete-after-success-form nil
6696 "A form to evaluate after successful completion.")
6697 (defvar idlwave-complete-after-success-form-force nil
6698 "A form to evaluate after completion selection in *Completions* buffer.")
6699 (defconst idlwave-completion-mark (make-marker)
6700 "A mark pointing to the beginning of the completion string.")
6701 (defvar completion-highlight-first-word-only) ;XEmacs.
6703 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6704 &optional prepare-display-function
6705 special-selector)
6706 "Perform TYPE completion of word before point against LIST.
6707 SELECTOR is the PREDICATE argument for the completion function. Show
6708 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6709 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
6710 used only once, for `all-completions', and can be used to, e.g.,
6711 accumulate information on matching completions."
6712 (let* ((completion-ignore-case t)
6713 beg (end (point)) slash part spart completion all-completions
6714 dpart dcompletion)
6716 (unless list
6717 (error (concat prompt ": No completions available")))
6719 ;; What is already in the buffer?
6720 (save-excursion
6721 (skip-chars-backward "a-zA-Z0-9_$")
6722 (setq slash (eq (preceding-char) ?/)
6723 beg (point)
6724 idlwave-complete-after-success-form
6725 (list 'idlwave-after-successful-completion
6726 (list 'quote type) slash beg)
6727 idlwave-complete-after-success-form-force
6728 (list 'idlwave-after-successful-completion
6729 (list 'quote type) slash (list 'quote 'force))))
6731 ;; Try a completion
6732 (setq part (buffer-substring beg end)
6733 dpart (downcase part)
6734 spart (idlwave-sintern stype part)
6735 completion (try-completion part list selector)
6736 dcompletion (if (stringp completion) (downcase completion))
6737 idlwave-completion-help-links nil)
6738 (cond
6739 ((null completion)
6740 ;; nothing available.
6741 (error (concat prompt ": no completion for \"%s\"") part))
6742 ((and (not (equal dpart dcompletion))
6743 (not (eq t completion)))
6744 ;; We can add something
6745 (delete-region beg end)
6746 (insert (if (and (string= part dpart)
6747 (or (not (string= part ""))
6748 idlwave-complete-empty-string-as-lower-case)
6749 (not idlwave-completion-force-default-case))
6750 dcompletion
6751 completion))
6752 (if (eq t (try-completion completion list selector))
6753 ;; Now this is a unique match
6754 (idlwave-after-successful-completion type slash beg))
6756 ((or (eq completion t)
6757 (and (= 1 (length (setq all-completions
6758 (idlwave-uniquify
6759 (all-completions part list
6760 (or special-selector
6761 selector))))))
6762 (equal dpart dcompletion)))
6763 ;; This is already complete
6764 (idlwave-after-successful-completion type slash beg)
6765 (message "%s is already the complete %s" part isa)
6766 nil)
6768 ;; We cannot add something - offer a list.
6769 (message "Making completion list...")
6771 (unless idlwave-completion-help-links ; already set somewhere?
6772 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6773 (let ((link (get-text-property 0 'link (car x))))
6774 (if link
6775 (push (cons (car x) link)
6776 idlwave-completion-help-links))))
6777 list))
6778 (let* ((list all-completions)
6779 ;; "complete" means, this is already a valid completion
6780 (complete (memq spart all-completions))
6781 (completion-highlight-first-word-only t)) ; XEmacs
6782 ;; (completion-fixup-function ; Emacs
6783 ;; (lambda () (and (eq (preceding-char) ?>)
6784 ;; (re-search-backward " <" beg t)))))
6786 (setq list (sort list (lambda (a b)
6787 (string< (downcase a) (downcase b)))))
6788 (if prepare-display-function
6789 (setq list (funcall prepare-display-function list)))
6790 (if (and (string= part dpart)
6791 (or (not (string= part ""))
6792 idlwave-complete-empty-string-as-lower-case)
6793 (not idlwave-completion-force-default-case))
6794 (setq list (mapcar (lambda (x)
6795 (if (listp x)
6796 (setcar x (downcase (car x)))
6797 (setq x (downcase x)))
6799 list)))
6800 (idlwave-display-completion-list list prompt beg complete))
6801 t))))
6803 (defun idlwave-complete-class ()
6804 "Complete a class at point."
6805 (interactive)
6806 ;; Call `idlwave-routines' to make sure the class list will be available
6807 (idlwave-routines)
6808 ;; Check for the special case of completing empty string after pro/function
6809 (if (let ((case-fold-search t))
6810 (save-excursion
6811 (and
6812 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6813 (- (point) 15) t)
6814 (goto-char (point-min))
6815 (re-search-forward
6816 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6817 ;; Yank the full class specification
6818 (insert (match-string 2))
6819 ;; Do the completion, using list gathered from `idlwave-routines'
6820 (idlwave-complete-in-buffer
6821 'class 'class (idlwave-class-alist) nil
6822 "Select a class" "class"
6823 (lambda (list) ;; Push it to help-links if system help available
6824 (mapcar (lambda (x)
6825 (let* ((entry (idlwave-class-info x))
6826 (link (nth 1 (assq 'link entry))))
6827 (if link (push (cons x link)
6828 idlwave-completion-help-links))
6830 list)))))
6832 (defun idlwave-attach-classes (list type show-classes)
6833 ;; Attach the proper class list to a LIST of completion items.
6834 ;; TYPE, when 'kwd, shows classes for method keywords, when
6835 ;; 'class-tag, for class tags, and otherwise for methods.
6836 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6837 (if (or (null show-classes) ; don't want to see classes
6838 (null class-selector) ; not a method call
6839 (and
6840 (stringp class-selector) ; the class is already known
6841 (not super-classes))) ; no possibilities for inheritance
6842 ;; In these cases, we do not have to do anything
6843 list
6844 (let* ((do-prop (and (>= show-classes 0)
6845 (>= emacs-major-version 21)))
6846 (do-buf (not (= show-classes 0)))
6847 ;; (do-dots (featurep 'xemacs))
6848 (do-dots t)
6849 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6850 (cons class-selector super-classes)))
6851 (max (abs show-classes))
6852 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6853 classes nclasses class-info space)
6854 (mapcar
6855 (lambda (x)
6856 ;; get the classes
6857 (if (eq type 'class-tag)
6858 ;; Just one class for tags
6859 (setq classes
6860 (list
6861 (idlwave-class-or-superclass-with-tag class-selector x)))
6862 ;; Multiple classes for method or method-keyword
6863 (setq classes
6864 (if (eq type 'kwd)
6865 (idlwave-all-method-keyword-classes
6866 method-selector x type-selector)
6867 (idlwave-all-method-classes x type-selector)))
6868 (if inherit
6869 (setq classes
6870 (delq nil
6871 (mapcar (lambda (x) (if (memq x inherit) x nil))
6872 classes)))))
6873 (setq nclasses (length classes))
6874 ;; Make the separator between item and class-info
6875 (if do-dots
6876 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6877 (setq space " "))
6878 (if do-buf
6879 ;; We do want info in the buffer
6880 (if (<= nclasses max)
6881 (setq class-info (concat
6882 space
6883 "<" (mapconcat 'identity classes ",") ">"))
6884 (setq class-info (format "%s<%d classes>" space nclasses)))
6885 (setq class-info nil))
6886 (when do-prop
6887 ;; We do want properties
6888 (setq x (copy-sequence x))
6889 (put-text-property 0 (length x)
6890 'help-echo (mapconcat 'identity classes " ")
6892 (if class-info
6893 (list x class-info)
6895 list))))
6897 (defun idlwave-attach-method-classes (list)
6898 ;; Call idlwave-attach-classes with method parameters
6899 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6900 (defun idlwave-attach-keyword-classes (list)
6901 ;; Call idlwave-attach-classes with keyword parameters
6902 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6903 (defun idlwave-attach-class-tag-classes (list)
6904 ;; Call idlwave-attach-classes with class structure tags
6905 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6908 ;;----------------------------------------------------------------------
6909 ;;----------------------------------------------------------------------
6910 ;;----------------------------------------------------------------------
6911 ;;----------------------------------------------------------------------
6912 ;;----------------------------------------------------------------------
6913 (defvar rtn)
6914 (defun idlwave-pset (item)
6915 (set 'rtn item))
6917 (defun idlwave-popup-select (ev list title &optional sort)
6918 "Select an item in LIST with a popup menu.
6919 TITLE is the title to put atop the popup. If SORT is non-nil,
6920 sort the list before displaying."
6921 (let ((maxpopup idlwave-max-popup-menu-items)
6922 rtn menu)
6923 (cond ((null list))
6924 ((= 1 (length list))
6925 (setq rtn (car list)))
6926 ((featurep 'xemacs)
6927 (if sort (setq list (sort list (lambda (a b)
6928 (string< (upcase a) (upcase b))))))
6929 (setq menu
6930 (append (list title)
6931 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6932 x)))
6933 list)))
6934 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6935 (let ((resp (get-popup-menu-response menu)))
6936 (funcall (event-function resp) (event-object resp))))
6938 (if sort (setq list (sort list (lambda (a b)
6939 (string< (upcase a) (upcase b))))))
6940 (setq menu (cons title
6941 (list
6942 (append (list "")
6943 (mapcar (lambda(x) (cons x x)) list)))))
6944 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6945 (setq rtn (x-popup-menu ev menu))))
6946 rtn))
6948 (defun idlwave-split-menu-xemacs (menu N)
6949 "Split the MENU into submenus of maximum length N."
6950 (if (<= (length menu) (1+ N))
6951 ;; No splitting needed
6952 menu
6953 (let* ((title (car menu))
6954 (entries (cdr menu))
6955 (menu (list title))
6956 (cnt 0)
6957 (nextmenu nil))
6958 (while entries
6959 (while (and entries (< cnt N))
6960 (setq cnt (1+ cnt)
6961 nextmenu (cons (car entries) nextmenu)
6962 entries (cdr entries)))
6963 (setq nextmenu (nreverse nextmenu))
6964 (setq nextmenu (cons (format "%s...%s"
6965 (aref (car nextmenu) 0)
6966 (aref (nth (1- cnt) nextmenu) 0))
6967 nextmenu))
6968 (setq menu (cons nextmenu menu)
6969 nextmenu nil
6970 cnt 0))
6971 (nreverse menu))))
6973 (defun idlwave-split-menu-emacs (menu N)
6974 "Split the MENU into submenus of maximum length N."
6975 (if (<= (length (nth 1 menu)) (1+ N))
6976 ;; No splitting needed
6977 menu
6978 (let* ((title (car menu))
6979 (entries (cdr (nth 1 menu)))
6980 (menu nil)
6981 (cnt 0)
6982 (nextmenu nil))
6983 (while entries
6984 (while (and entries (< cnt N))
6985 (setq cnt (1+ cnt)
6986 nextmenu (cons (car entries) nextmenu)
6987 entries (cdr entries)))
6988 (setq nextmenu (nreverse nextmenu))
6989 (prin1 nextmenu)
6990 (setq nextmenu (cons (format "%s...%s"
6991 (car (car nextmenu))
6992 (car (nth (1- cnt) nextmenu)))
6993 nextmenu))
6994 (setq menu (cons nextmenu menu)
6995 nextmenu nil
6996 cnt 0))
6997 (setq menu (nreverse menu))
6998 (setq menu (cons title menu))
6999 menu)))
7001 (defvar idlwave-completion-setup-hook nil)
7003 (defun idlwave-scroll-completions (&optional message)
7004 "Scroll the completion window on this frame."
7005 (let ((cwin (get-buffer-window "*Completions*" 'visible))
7006 (win (selected-window)))
7007 (unwind-protect
7008 (progn
7009 (select-window cwin)
7010 (condition-case nil
7011 (scroll-up)
7012 (error (if (and (listp last-command)
7013 (nth 2 last-command))
7014 (progn
7015 (select-window win)
7016 (eval idlwave-complete-after-success-form))
7017 (set-window-start cwin (point-min)))))
7018 (and message (message "%s" message)))
7019 (select-window win))))
7021 (defun idlwave-display-completion-list (list &optional message beg complete)
7022 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7023 (unless (and (get-buffer-window "*Completions*")
7024 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
7025 (move-marker idlwave-completion-mark beg)
7026 (setq idlwave-before-completion-wconf (current-window-configuration)))
7028 (if (featurep 'xemacs)
7029 (idlwave-display-completion-list-xemacs
7030 list)
7031 (idlwave-display-completion-list-emacs list))
7033 ;; Store a special value in `this-command'. When `idlwave-complete'
7034 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7035 (setq this-command (list 'idlwave-display-completion-list message complete))
7037 ;; Mark the completions buffer as created by cib
7038 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
7040 ;; Fontify the classes
7041 (if (and idlwave-completion-fontify-classes
7042 (consp (car list)))
7043 (idlwave-completion-fontify-classes))
7045 ;; Run the hook
7046 (run-hooks 'idlwave-completion-setup-hook)
7048 ;; Display the message
7049 (message "%s" (or message "Making completion list...done")))
7051 (defun idlwave-choose (function &rest args)
7052 "Call FUNCTION as a completion chooser and pass ARGS to it."
7053 (let ((completion-ignore-case t)) ; install correct value
7054 (apply function args))
7055 (if (and (eq major-mode 'idlwave-shell-mode)
7056 (boundp 'font-lock-mode)
7057 (not font-lock-mode))
7058 ;; For the shell, remove the fontification of the word before point
7059 (let ((beg (save-excursion
7060 (skip-chars-backward "a-zA-Z0-9_")
7061 (point))))
7062 (remove-text-properties beg (point) '(face nil))))
7063 (eval idlwave-complete-after-success-form-force))
7065 (defun idlwave-keyboard-quit ()
7066 (interactive)
7067 (unwind-protect
7068 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7069 (idlwave-restore-wconf-after-completion))
7070 (keyboard-quit)))
7072 (defun idlwave-restore-wconf-after-completion ()
7073 "Restore the old (before completion) window configuration."
7074 (and idlwave-completion-restore-window-configuration
7075 idlwave-before-completion-wconf
7076 (set-window-configuration idlwave-before-completion-wconf)))
7078 (defun idlwave-one-key-select (sym prompt delay)
7079 "Make the user select an element from the alist in the variable SYM.
7080 The keys of the alist are expected to be strings. The function returns the
7081 car of the selected association.
7082 To do this, PROMPT is displayed and the user must hit a letter key to
7083 select an entry. If the user does not reply within DELAY seconds, a help
7084 window with the options is displayed automatically.
7085 The key which is associated with each option is generated automatically.
7086 First, the strings are checked for preselected keys, like in \"[P]rint\".
7087 If these don't exist, a letter in the string is automatically selected."
7088 (let* ((alist (symbol-value sym))
7089 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7090 '(fit-window-to-buffer)))
7091 keys-alist char)
7092 ;; First check the cache
7093 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7094 (setq keys-alist (get sym :one-key-alist-cache))
7095 ;; Need to make new list
7096 (setq keys-alist (idlwave-make-one-key-alist alist))
7097 (put sym :one-key-alist-cache keys-alist)
7098 (put sym :one-key-alist-last alist))
7099 ;; Display prompt and wait for quick reply
7100 (message "%s[%s]" prompt
7101 (mapconcat (lambda(x) (char-to-string (car x)))
7102 keys-alist ""))
7103 (if (sit-for delay)
7104 ;; No quick reply: Show help
7105 (save-window-excursion
7106 (with-output-to-temp-buffer "*Completions*"
7107 (mapcar (lambda(x)
7108 (princ (nth 1 x))
7109 (princ "\n"))
7110 keys-alist))
7111 (setq char (read-char)))
7112 (setq char (read-char)))
7113 (message nil)
7114 ;; Return the selected result
7115 (nth 2 (assoc char keys-alist))))
7117 ;; Used for, e.g., electric debug super-examine.
7118 (defun idlwave-make-one-key-alist (alist)
7119 "Make an alist for single key selection."
7120 (let ((l alist) keys-alist name start char help
7121 (cnt 0)
7122 (case-fold-search nil))
7123 (while l
7124 (setq name (car (car l))
7125 l (cdr l))
7126 (catch 'exit
7127 ;; First check if the configuration predetermined a key
7128 (if (string-match "\\[\\(.\\)\\]" name)
7129 (progn
7130 (setq char (string-to-char (downcase (match-string 1 name)))
7131 help (format "%c: %s" char name)
7132 keys-alist (cons (list char help name) keys-alist))
7133 (throw 'exit t)))
7134 ;; Then check for capital letters
7135 (setq start 0)
7136 (while (string-match "[A-Z]" name start)
7137 (setq start (match-end 0)
7138 char (string-to-char (downcase (match-string 0 name))))
7139 (if (not (assoc char keys-alist))
7140 (progn
7141 (setq help (format "%c: %s" char
7142 (replace-match
7143 (concat "[" (match-string 0 name) "]")
7144 t t name))
7145 keys-alist (cons (list char help name) keys-alist))
7146 (throw 'exit t))))
7147 ;; Now check for lowercase letters
7148 (setq start 0)
7149 (while (string-match "[a-z]" name start)
7150 (setq start (match-end 0)
7151 char (string-to-char (match-string 0 name)))
7152 (if (not (assoc char keys-alist))
7153 (progn
7154 (setq help (format "%c: %s" char
7155 (replace-match
7156 (concat "[" (match-string 0 name) "]")
7157 t t name))
7158 keys-alist (cons (list char help name) keys-alist))
7159 (throw 'exit t))))
7160 ;; Bummer, nothing found! Use a stupid number
7161 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7162 help (format "%c: %s" char name)
7163 keys-alist (cons (list char help name) keys-alist))))
7164 (nreverse keys-alist)))
7166 (defun idlwave-set-local (var value &optional buffer)
7167 "Set the buffer-local value of VAR in BUFFER to VALUE."
7168 (with-current-buffer (or buffer (current-buffer))
7169 (set (make-local-variable var) value)))
7171 (defun idlwave-local-value (var &optional buffer)
7172 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7173 (with-current-buffer (or buffer (current-buffer))
7174 (and (local-variable-p var (current-buffer))
7175 (symbol-value var))))
7177 ;; In XEmacs, we can use :activate-callback directly to advice the
7178 ;; choose functions. We use the private keymap only for the online
7179 ;; help feature.
7181 (defvar idlwave-completion-map nil
7182 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7184 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
7185 (with-output-to-temp-buffer "*Completions*"
7186 (apply 'display-completion-list list
7187 ':activate-callback 'idlwave-default-choose-completion
7188 cl-args))
7189 (with-current-buffer "*Completions*"
7190 (use-local-map
7191 (or idlwave-completion-map
7192 (setq idlwave-completion-map
7193 (idlwave-make-modified-completion-map-xemacs
7194 (current-local-map)))))))
7196 (defun idlwave-default-choose-completion (&rest args)
7197 "Execute `default-choose-completion' and then restore the win-conf."
7198 (apply 'idlwave-choose 'default-choose-completion args))
7200 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7201 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7202 (let ((new-map (copy-keymap old-map)))
7203 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7204 (define-key new-map [button3] (lambda ()
7205 (interactive)
7206 (setq this-command last-command)))
7207 new-map))
7209 ;; In Emacs we also replace keybindings in the completion
7210 ;; map in order to install our wrappers.
7212 (defun idlwave-display-completion-list-emacs (list)
7213 "Display completion list and install the choose wrappers."
7214 (with-output-to-temp-buffer "*Completions*"
7215 (display-completion-list list))
7216 (with-current-buffer "*Completions*"
7217 (use-local-map
7218 (or idlwave-completion-map
7219 (setq idlwave-completion-map
7220 (idlwave-make-modified-completion-map-emacs
7221 (current-local-map)))))))
7223 (defun idlwave-make-modified-completion-map-emacs (old-map)
7224 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7225 (let ((new-map (copy-keymap old-map)))
7226 (substitute-key-definition
7227 'choose-completion 'idlwave-choose-completion new-map)
7228 (substitute-key-definition
7229 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7230 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7231 new-map))
7233 (defun idlwave-choose-completion (&rest args)
7234 "Choose the completion that point is in or next to."
7235 (interactive)
7236 (apply 'idlwave-choose 'choose-completion args))
7238 (defun idlwave-mouse-choose-completion (&rest args)
7239 "Click on an alternative in the `*Completions*' buffer to choose it."
7240 (interactive "e")
7241 (apply 'idlwave-choose 'mouse-choose-completion args))
7243 ;;----------------------------------------------------------------------
7244 ;;----------------------------------------------------------------------
7246 ;;; ------------------------------------------------------------------------
7247 ;;; Stucture parsing code, and code to manage class info
7250 ;; - Go again over the documentation how to write a completion
7251 ;; plugin. It is in self.el, but currently still very bad.
7252 ;; This could be in a separate file in the distribution, or
7253 ;; in an appendix for the manual.
7255 (defvar idlwave-struct-skip
7256 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7257 "Regexp for skipping continued blank or comment-only lines in structures.")
7259 (defvar idlwave-struct-tag-regexp
7260 (concat "[{,]" ;leading comma/brace
7261 idlwave-struct-skip ; 4 groups
7262 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7263 "[ \t]*:") ; the final colon
7264 "Regexp for structure tags.")
7266 (defun idlwave-struct-tags ()
7267 "Return a list of all tags in the structure defined at point.
7268 Point is expected just before the opening `{' of the struct definition."
7269 (save-excursion
7270 (let* ((borders (idlwave-struct-borders))
7271 (beg (car borders))
7272 (end (cdr borders))
7273 tags)
7274 (goto-char beg)
7275 (save-restriction
7276 (narrow-to-region beg end)
7277 (while (re-search-forward idlwave-struct-tag-regexp end t)
7278 ;; Check if we are still on the top level of the structure.
7279 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7280 (= (point) beg))
7281 (push (match-string-no-properties 5) tags))
7282 (goto-char (match-end 0))))
7283 (nreverse tags))))
7285 (defun idlwave-find-struct-tag (tag)
7286 "Find a given TAG in the structure defined at point."
7287 (let* ((borders (idlwave-struct-borders))
7288 (end (cdr borders))
7289 (case-fold-search t))
7290 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7291 end t)))
7293 (defun idlwave-struct-inherits ()
7294 "Return a list of all `inherits' names in the struct at point.
7295 Point is expected just before the opening `{' of the struct definition."
7296 (save-excursion
7297 (let* ((borders (idlwave-struct-borders))
7298 (beg (car borders))
7299 (end (cdr borders))
7300 (case-fold-search t)
7301 names)
7302 (goto-char beg)
7303 (save-restriction
7304 (narrow-to-region beg end)
7305 (while (re-search-forward
7306 (concat "[{,]" ;leading comma/brace
7307 idlwave-struct-skip ; 4 groups
7308 "inherits" ; The INHERITS tag
7309 idlwave-struct-skip ; 4 more
7310 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7311 end t)
7312 ;; Check if we are still on the top level of the structure.
7313 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7314 (= (point) beg))
7315 (push (match-string-no-properties 9) names))
7316 (goto-char (match-end 0))))
7317 (nreverse names))))
7319 (defun idlwave-in-structure ()
7320 "Return t if point is inside an IDL structure definition."
7321 (let ((beg (point)))
7322 (save-excursion
7323 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7324 (if (idlwave-find-structure-definition nil nil 'back)
7325 (let ((borders (idlwave-struct-borders)))
7326 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7327 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7329 (defun idlwave-struct-borders ()
7330 "Return the borders of the {...} after point as a cons cell."
7331 (let (beg)
7332 (save-excursion
7333 (skip-chars-forward "^{")
7334 (setq beg (point))
7335 (condition-case nil (forward-list 1)
7336 (error (goto-char beg)))
7337 (cons beg (point)))))
7339 (defun idlwave-find-structure-definition (&optional var name bound)
7340 "Search forward for a structure definition.
7341 If VAR is non-nil, search for a structure assigned to variable VAR.
7342 If NAME is non-nil, search for a named structure NAME, if a string,
7343 or a generic named structure otherwise. If BOUND is an integer, limit
7344 the search. If BOUND is the symbol `all', we search first back and
7345 then forward through the entire file. If BOUND is the symbol `back'
7346 we search only backward."
7347 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7348 (case-fold-search t)
7349 (lim (if (integerp bound) bound nil))
7350 (re (concat
7351 (if var
7352 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7353 "\\(\\)")
7354 "=" ws "\\({\\)"
7355 (if name
7356 (if (stringp name)
7357 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7358 ;; Just a generic name
7359 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7360 ""))))
7361 (if (or (and (or (eq bound 'all) (eq bound 'back))
7362 (re-search-backward re nil t))
7363 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7364 (progn
7365 (goto-char (match-beginning 3))
7366 (match-string-no-properties 5)))))
7368 (defvar idlwave-class-info nil)
7369 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7371 (add-hook 'idlwave-update-rinfo-hook
7372 (lambda () (setq idlwave-class-reset t)))
7373 (add-hook 'idlwave-after-load-rinfo-hook
7374 (lambda () (setq idlwave-class-info nil)))
7376 (defun idlwave-class-info (class)
7377 (let (list entry)
7378 (if idlwave-class-info
7379 (if idlwave-class-reset
7380 (setq
7381 idlwave-class-reset nil
7382 idlwave-class-info ; Remove any visited in a buffer
7383 (delq nil (mapcar
7384 (lambda (x)
7385 (let ((filebuf
7386 (idlwave-class-file-or-buffer
7387 (or (cdr (assq 'found-in x)) (car x)))))
7388 (if (cdr filebuf)
7390 x)))
7391 idlwave-class-info))))
7392 ;; Info is nil, put in the system stuff to start.
7393 (setq idlwave-class-info idlwave-system-class-info)
7394 (setq list idlwave-class-info)
7395 (while (setq entry (pop list))
7396 (idlwave-sintern-class-info entry)))
7397 (setq class (idlwave-sintern-class class))
7398 (or (assq class idlwave-class-info)
7399 (progn (idlwave-scan-class-info class)
7400 (assq class idlwave-class-info)))))
7402 (defun idlwave-sintern-class-info (entry)
7403 "Sintern the class names in a class-info entry."
7404 (let ((inherits (assq 'inherits entry)))
7405 (setcar entry (idlwave-sintern-class (car entry) 'set))
7406 (if inherits
7407 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7408 (cdr inherits))))))
7410 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7411 "Find class structure definition(s).
7412 If ALL-HOOK is set, find all named structure definitions in a given
7413 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7414 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7415 class/struct definition."
7416 (let ((case-fold-search t) end-lim name)
7417 (when (re-search-forward
7418 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7419 (if all-hook
7420 (progn
7421 ;; For everything there
7422 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7423 (while (setq name
7424 (idlwave-find-structure-definition nil t end-lim))
7425 (funcall all-hook name)))
7426 (idlwave-find-structure-definition nil (or alt-class class))))))
7429 (defun idlwave-class-file-or-buffer (class)
7430 "Find buffer visiting CLASS definition."
7431 (let* ((pro (concat (downcase class) "__define"))
7432 (file (idlwave-routine-source-file
7433 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7434 (idlwave-routines))))))
7435 (cons file (if file (idlwave-get-buffer-visiting file)))))
7438 (defun idlwave-scan-class-info (class)
7439 "Scan all class and named structure info in the class__define pro."
7440 (let* ((idlwave-auto-routine-info-updates nil)
7441 (filebuf (idlwave-class-file-or-buffer class))
7442 (file (car filebuf))
7443 (buf (cdr filebuf))
7444 (class (idlwave-sintern-class class)))
7445 (if (or
7446 (not file)
7447 (and ;; neither a regular file nor a visited buffer
7448 (not buf)
7449 (not (file-regular-p file))))
7450 nil ; Cannot find the file/buffer to get any info
7451 (save-excursion
7452 (if buf (set-buffer buf)
7453 ;; Read the file in temporarily
7454 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7455 (erase-buffer)
7456 (unless (eq major-mode 'idlwave-mode)
7457 (idlwave-mode))
7458 (insert-file-contents file))
7459 (save-excursion
7460 (goto-char 1)
7461 (idlwave-find-class-definition class
7462 ;; Scan all of the structures found there
7463 (lambda (name)
7464 (let* ((this-class (idlwave-sintern-class name))
7465 (entry
7466 (list this-class
7467 (cons 'tags (idlwave-struct-tags))
7468 (cons 'inherits (idlwave-struct-inherits)))))
7469 (if (not (eq this-class class))
7470 (setq entry (nconc entry (list (cons 'found-in class)))))
7471 (idlwave-sintern-class-info entry)
7472 (push entry idlwave-class-info)))))))))
7474 (defun idlwave-class-found-in (class)
7475 "Return the FOUND-IN property of the CLASS."
7476 (cdr (assq 'found-in (idlwave-class-info class))))
7477 (defun idlwave-class-tags (class)
7478 "Return the native tags in CLASS."
7479 (cdr (assq 'tags (idlwave-class-info class))))
7480 (defun idlwave-class-inherits (class)
7481 "Return the direct superclasses of CLASS."
7482 (cdr (assq 'inherits (idlwave-class-info class))))
7485 (defun idlwave-all-class-tags (class)
7486 "Return a list of native and inherited tags in CLASS."
7487 (condition-case err
7488 (apply 'append (mapcar 'idlwave-class-tags
7489 (cons class (idlwave-all-class-inherits class))))
7490 (error
7491 (idlwave-class-tag-reset)
7492 (error "%s" (error-message-string err)))))
7495 (defun idlwave-all-class-inherits (class)
7496 "Return a list of all superclasses of CLASS (recursively expanded).
7497 The list is cached in `idlwave-class-info' for faster access."
7498 (cond
7499 ((not idlwave-support-inheritance) nil)
7500 ((eq class nil) nil)
7501 ((eq class t) nil)
7503 (let ((info (idlwave-class-info class))
7504 entry)
7505 (if (setq entry (assq 'all-inherits info))
7506 (cdr entry)
7507 ;; Save the depth of inheritance scan to check for circular references
7508 (let ((inherits (mapcar (lambda (x) (cons x 0))
7509 (idlwave-class-inherits class)))
7510 rtn all-inherits cl)
7511 (while inherits
7512 (setq cl (pop inherits)
7513 rtn (cons (car cl) rtn)
7514 inherits (append (mapcar (lambda (x)
7515 (cons x (1+ (cdr cl))))
7516 (idlwave-class-inherits (car cl)))
7517 inherits))
7518 (if (> (cdr cl) 999)
7519 (error
7520 "Class scan: inheritance depth exceeded. Circular inheritance?")
7522 (setq all-inherits (nreverse rtn))
7523 (nconc info (list (cons 'all-inherits all-inherits)))
7524 all-inherits))))))
7526 (defun idlwave-entry-keywords (entry &optional record-link)
7527 "Return the flat entry keywords alist from routine-info entry.
7528 If RECORD-LINK is non-nil, the keyword text is copied and a text
7529 property indicating the link is added."
7530 (let (kwds)
7531 (mapc
7532 (lambda (key-list)
7533 (let ((file (car key-list)))
7534 (mapcar (lambda (key-cons)
7535 (let ((key (car key-cons))
7536 (link (cdr key-cons)))
7537 (when (and record-link file)
7538 (setq key (copy-sequence key))
7539 (put-text-property
7540 0 (length key)
7541 'link
7542 (concat
7543 file
7544 (if link
7545 (concat idlwave-html-link-sep
7546 (number-to-string link))))
7547 key))
7548 (push (list key) kwds)))
7549 (cdr key-list))))
7550 (nthcdr 5 entry))
7551 (nreverse kwds)))
7553 (defun idlwave-entry-find-keyword (entry keyword)
7554 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7555 (catch 'exit
7556 (mapc
7557 (lambda (key-list)
7558 (let ((file (car key-list))
7559 (kwd (assoc keyword (cdr key-list))))
7560 (when kwd
7561 (setq kwd (cons (car kwd)
7562 (if (and file (cdr kwd))
7563 (concat file
7564 idlwave-html-link-sep
7565 (number-to-string (cdr kwd)))
7566 (cdr kwd))))
7567 (throw 'exit kwd))))
7568 (nthcdr 5 entry))))
7570 ;;==========================================================================
7572 ;; Completing class structure tags. This is a completion plugin.
7573 ;; The necessary taglist is constructed dynamically
7575 (defvar idlwave-current-tags-class nil)
7576 (defvar idlwave-current-class-tags nil)
7577 (defvar idlwave-current-native-class-tags nil)
7578 (defvar idlwave-sint-class-tags nil)
7579 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7580 (idlwave-new-sintern-type 'class-tag)
7581 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7582 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7584 (defun idlwave-complete-class-structure-tag ()
7585 "Complete a structure tag on a `self' argument in an object method."
7586 (interactive)
7587 (let ((pos (point))
7588 (case-fold-search t))
7589 (if (save-excursion
7590 ;; Check if the context is right
7591 (skip-chars-backward "a-zA-Z0-9._$")
7592 (and (< (point) (- pos 4))
7593 (looking-at "self\\.")))
7594 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7595 (super-classes (idlwave-all-class-inherits class-selector)))
7596 ;; Check if we are in a class routine
7597 (unless class-selector
7598 (error "Not in a method procedure or function"))
7599 ;; Check if we need to update the "current" class
7600 (if (not (equal class-selector idlwave-current-tags-class))
7601 (idlwave-prepare-class-tag-completion class-selector))
7602 (setq idlwave-completion-help-info
7603 (list 'idlwave-complete-class-structure-tag-help
7604 (idlwave-sintern-routine
7605 (concat class-selector "__define"))
7606 nil))
7607 ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
7608 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7609 (idlwave-complete-in-buffer
7610 'class-tag 'class-tag
7611 idlwave-current-class-tags nil
7612 (format "Select a tag of class %s" class-selector)
7613 "class tag"
7614 'idlwave-attach-class-tag-classes))
7615 t) ; return t to skip other completions
7616 nil)))
7618 (defun idlwave-class-tag-reset ()
7619 (setq idlwave-current-tags-class nil))
7621 (defun idlwave-prepare-class-tag-completion (class)
7622 "Find and parse the necessary class definitions for class structure tags."
7623 (setq idlwave-sint-class-tags nil)
7624 (setq idlwave-current-tags-class class)
7625 (setq idlwave-current-class-tags
7626 (mapcar (lambda (x)
7627 (list (idlwave-sintern-class-tag x 'set)))
7628 (idlwave-all-class-tags class)))
7629 (setq idlwave-current-native-class-tags
7630 (mapcar 'downcase (idlwave-class-tags class))))
7632 ;===========================================================================
7634 ;; Completing system variables and their structure fields
7635 ;; This is also a plugin.
7637 (defvar idlwave-sint-sysvars nil)
7638 (defvar idlwave-sint-sysvartags nil)
7639 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7640 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7641 (idlwave-new-sintern-type 'sysvar)
7642 (idlwave-new-sintern-type 'sysvartag)
7643 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7644 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7645 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7648 (defun idlwave-complete-sysvar-or-tag ()
7649 "Complete a system variable."
7650 (interactive)
7651 (let ((pos (point))
7652 (case-fold-search t))
7653 (cond ((save-excursion
7654 ;; Check if the context is right for system variable
7655 (skip-chars-backward "[a-zA-Z0-9_$]")
7656 (equal (char-before) ?!))
7657 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7658 (idlwave-complete-in-buffer 'sysvar 'sysvar
7659 idlwave-system-variables-alist nil
7660 "Select a system variable"
7661 "system variable")
7662 t) ; return t to skip other completions
7663 ((save-excursion
7664 ;; Check if the context is right for sysvar tag
7665 (skip-chars-backward "a-zA-Z0-9_$.")
7666 (and (equal (char-before) ?!)
7667 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7668 (<= (match-end 0) pos)))
7669 ;; Complete a system variable tag
7670 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7671 (entry (assq var idlwave-system-variables-alist))
7672 (tags (cdr (assq 'tags entry))))
7673 (or entry (error "!%s is not a known system variable" var))
7674 (or tags (error "System variable !%s is not a structure" var))
7675 (setq idlwave-completion-help-info
7676 (list 'idlwave-complete-sysvar-tag-help var))
7677 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7678 tags nil
7679 "Select a system variable tag"
7680 "system variable tag")
7681 t)) ; return t to skip other completions
7682 (t nil))))
7684 (defvar link) ;dynamic variables set by help callback
7685 (defvar props)
7686 (defun idlwave-complete-sysvar-help (mode word)
7687 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7688 (entry (assoc word idlwave-system-variables-alist)))
7689 (cond
7690 ((eq mode 'test)
7691 (and (stringp word) entry (nth 1 (assq 'link entry))))
7692 ((eq mode 'set)
7693 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7694 (t (error "This should not happen")))))
7696 (defun idlwave-complete-sysvar-tag-help (mode word)
7697 (let* ((var (nth 1 idlwave-completion-help-info))
7698 (entry (assoc var idlwave-system-variables-alist))
7699 (tags (cdr (assq 'tags entry)))
7700 (main (nth 1 (assq 'link entry)))
7701 target)
7702 (cond
7703 ((eq mode 'test) ; we can at least link the main
7704 (and (stringp word) entry main))
7705 ((eq mode 'set)
7706 (if entry
7707 (setq link
7708 (if (setq target (cdr (assoc-string word tags t)))
7709 (idlwave-substitute-link-target main target)
7710 main)))) ;; setting dynamic!!!
7711 (t (error "This should not happen")))))
7713 (defun idlwave-split-link-target (link)
7714 "Split a given LINK into link file and anchor."
7715 (if (string-match idlwave-html-link-sep link)
7716 (cons (substring link 0 (match-beginning 0))
7717 (string-to-number (substring link (match-end 0))))))
7719 (defun idlwave-substitute-link-target (link target)
7720 "Substitute the TARGET anchor for the given LINK."
7721 (let (main-base)
7722 (setq main-base (if (string-match "#" link)
7723 (substring link 0 (match-beginning 0))
7724 link))
7725 (if target
7726 (concat main-base idlwave-html-link-sep (number-to-string target))
7727 link)))
7729 ;; Fake help in the source buffer for class structure tags.
7730 ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
7731 (defvar name)
7732 (defvar kwd)
7733 (defvar idlwave-help-do-class-struct-tag nil)
7734 (defun idlwave-complete-class-structure-tag-help (mode word)
7735 (cond
7736 ((eq mode 'test) ; nothing gets fontified for class tags
7737 nil)
7738 ((eq mode 'set)
7739 (let (class-with found-in)
7740 (when (setq class-with
7741 (idlwave-class-or-superclass-with-tag
7742 idlwave-current-tags-class
7743 word))
7744 (if (assq (idlwave-sintern-class class-with)
7745 idlwave-system-class-info)
7746 (error "No help available for system class tags"))
7747 (if (setq found-in (idlwave-class-found-in class-with))
7748 (setq name (cons (concat found-in "__define") class-with))
7749 (setq name (concat class-with "__define")))))
7750 (setq kwd word
7751 idlwave-help-do-class-struct-tag t))
7752 (t (error "This should not happen"))))
7754 (defun idlwave-class-or-superclass-with-tag (class tag)
7755 "Find and return the CLASS or one of its superclass with the
7756 associated TAG, if any."
7757 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7759 (catch 'exit
7760 (while sclasses
7761 (setq cl (pop sclasses))
7762 (let ((tags (idlwave-class-tags cl)))
7763 (while tags
7764 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7765 (throw 'exit cl))
7766 (setq tags (cdr tags))))))))
7769 (defun idlwave-sysvars-reset ()
7770 (if (and (fboundp 'idlwave-shell-is-running)
7771 (idlwave-shell-is-running)
7772 idlwave-idlwave_routine_info-compiled)
7773 (idlwave-shell-send-command "idlwave_get_sysvars"
7774 'idlwave-process-sysvars 'hide)))
7776 (defun idlwave-process-sysvars ()
7777 (idlwave-shell-filter-sysvars)
7778 (setq idlwave-sint-sysvars nil
7779 idlwave-sint-sysvartags nil)
7780 (idlwave-sintern-sysvar-alist))
7782 (defun idlwave-sintern-sysvar-alist ()
7783 (let ((list idlwave-system-variables-alist) entry tags)
7784 (while (setq entry (pop list))
7785 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7786 (setq tags (assq 'tags entry))
7787 (if tags
7788 (setcdr tags
7789 (mapcar (lambda (x)
7790 (cons (idlwave-sintern-sysvartag (car x) 'set)
7791 (cdr x)))
7792 (cdr tags)))))))
7794 (defvar idlwave-shell-command-output)
7795 (defun idlwave-shell-filter-sysvars ()
7796 "Get any new system variables and tags."
7797 (let ((text idlwave-shell-command-output)
7798 (start 0)
7799 (old idlwave-system-variables-alist)
7800 var tags type name class link old-entry)
7801 (setq idlwave-system-variables-alist nil)
7802 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7803 text start)
7804 (setq start (match-end 0)
7805 var (match-string 1 text)
7806 tags (if (match-end 3)
7807 (idlwave-split-string (match-string 3 text))))
7808 ;; Maintain old links, if present
7809 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7810 (setq link (assq 'link old-entry))
7811 (setq idlwave-system-variables-alist
7812 (cons (list var
7813 (cons
7814 'tags
7815 (mapcar (lambda (x)
7816 (cons x
7817 (cdr (assq
7818 (idlwave-sintern-sysvartag x)
7819 (cdr (assq 'tags old-entry))))))
7820 tags)) link)
7821 idlwave-system-variables-alist)))
7822 ;; Keep the old value if query was not successful
7823 (setq idlwave-system-variables-alist
7824 (or idlwave-system-variables-alist old))))
7826 (defun idlwave-completion-fontify-classes ()
7827 "Goto the *Completions* buffer and fontify the class info."
7828 (when (featurep 'font-lock)
7829 (with-current-buffer "*Completions*"
7830 (save-excursion
7831 (goto-char (point-min))
7832 (let ((buffer-read-only nil))
7833 (while (re-search-forward "\\.*<[^>]+>" nil t)
7834 (put-text-property (match-beginning 0) (match-end 0)
7835 'face 'font-lock-string-face)))))))
7837 (defun idlwave-uniquify (list)
7838 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7839 (delq nil
7840 (mapcar (lambda (x)
7841 (unless (gethash x ht)
7842 (puthash x t ht)
7844 list))))
7846 (defun idlwave-after-successful-completion (type slash &optional verify)
7847 "Add `=' or `(' after successful completion of keyword and function.
7848 Restore the pre-completion window configuration if possible."
7849 (cond
7850 ((eq type 'procedure)
7851 nil)
7852 ((eq type 'function)
7853 (cond
7854 ((equal idlwave-function-completion-adds-paren nil) nil)
7855 ((or (equal idlwave-function-completion-adds-paren t)
7856 (equal idlwave-function-completion-adds-paren 1))
7857 (insert "("))
7858 ((equal idlwave-function-completion-adds-paren 2)
7859 (insert "()")
7860 (backward-char 1))
7861 (t nil)))
7862 ((eq type 'keyword)
7863 (if (and idlwave-keyword-completion-adds-equal
7864 (not slash))
7865 (progn (insert "=") t)
7866 nil)))
7868 ;; Restore the pre-completion window configuration if this is safe.
7870 (if (or (eq verify 'force) ; force
7871 (and
7872 (get-buffer-window "*Completions*") ; visible
7873 (idlwave-local-value 'idlwave-completion-p
7874 "*Completions*") ; cib-buffer
7875 (eq (marker-buffer idlwave-completion-mark)
7876 (current-buffer)) ; buffer OK
7877 (equal (marker-position idlwave-completion-mark)
7878 verify))) ; pos OK
7879 (idlwave-restore-wconf-after-completion))
7880 (move-marker idlwave-completion-mark nil)
7881 (setq idlwave-before-completion-wconf nil))
7883 (defun idlwave-mouse-context-help (ev &optional arg)
7884 "Call `idlwave-context-help' on the clicked location."
7885 (interactive "eP")
7886 (mouse-set-point ev)
7887 (idlwave-context-help arg))
7889 (defvar idlwave-last-context-help-pos nil)
7890 (defun idlwave-context-help (&optional arg)
7891 "Display IDL Online Help on context.
7892 If point is on a keyword, help for that keyword will be shown. If
7893 point is on a routine name or in the argument list of a routine, help
7894 for that routine will be displayed. Works for system routines and
7895 keywords, it pulls up text help. For other routies and keywords,
7896 visits the source file, finding help in the header (if
7897 `idlwave-help-source-try-header' is non-nil) or the routine definition
7898 itself."
7899 (interactive "P")
7900 (idlwave-do-context-help arg))
7902 (defun idlwave-mouse-completion-help (ev)
7903 "Display online help about the completion at point."
7904 (interactive "eP")
7905 ;; Restore last-command for next command, to make
7906 ;; scrolling/cancelling of completions work.
7907 (setq this-command last-command)
7908 (idlwave-do-mouse-completion-help ev))
7910 (defun idlwave-routine-info (&optional arg external)
7911 "Display a routines calling sequence and list of keywords.
7912 When point is on the name a function or procedure, or in the argument
7913 list of a function or procedure, this command displays a help buffer with
7914 the information. When called with prefix arg, enforce class query.
7916 When point is on an object operator `->', display the class stored in
7917 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7918 arg, the class property is cleared out."
7920 (interactive "P")
7921 (idlwave-routines)
7922 (if (string-match "->" (buffer-substring
7923 (max (point-min) (1- (point)))
7924 (min (+ 2 (point)) (point-max))))
7925 ;; Cursor is on an arrow
7926 (if (get-text-property (point) 'idlwave-class)
7927 ;; arrow has class property
7928 (if arg
7929 ;; Remove property
7930 (save-excursion
7931 (backward-char 1)
7932 (when (looking-at ".?\\(->\\)")
7933 (remove-text-properties (match-beginning 1) (match-end 1)
7934 '(idlwave-class nil face nil))
7935 (message "Class property removed from arrow")))
7936 ;; Echo class property
7937 (message "Arrow has text property identifying object to be class %s"
7938 (get-text-property (point) 'idlwave-class)))
7939 ;; No property found
7940 (message "Arrow has no class text property"))
7942 ;; Not on an arrow...
7943 (let* ((idlwave-query-class nil)
7944 (idlwave-force-class-query (equal arg '(4)))
7945 (module (idlwave-what-module)))
7946 (if (car module)
7947 (apply 'idlwave-display-calling-sequence
7948 (idlwave-fix-module-if-obj_new module))
7949 (error "Don't know which calling sequence to show")))))
7951 (defun idlwave-resolve (&optional arg)
7952 "Call RESOLVE_ROUTINE on the module name at point.
7953 Like `idlwave-routine-info', this looks for a routine call at point.
7954 After confirmation in the minibuffer, it will use the shell to issue
7955 a RESOLVE call for this routine, to attempt to make it defined and its
7956 routine info available for IDLWAVE. If the routine is a method call,
7957 both `class__method' and `class__define' will be tried.
7958 With ARG, enforce query for the class of object methods."
7959 (interactive "P")
7960 (let* ((idlwave-query-class nil)
7961 (idlwave-force-class-query (equal arg '(4)))
7962 (module (idlwave-what-module))
7963 (name (idlwave-make-full-name (nth 2 module) (car module)))
7964 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7965 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7966 (kwd "")
7967 class)
7968 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7969 resolve)
7970 (setq type (match-string 1 resolve)
7971 class (if (match-beginning 2)
7972 (match-string 3 resolve)
7973 nil)
7974 name (match-string 4 resolve)))
7975 (if (string= (downcase type) "function")
7976 (setq kwd ",/is_function"))
7978 (cond
7979 ((null class)
7980 (idlwave-shell-send-command
7981 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7982 'idlwave-update-routine-info
7983 nil t))
7985 (idlwave-shell-send-command
7986 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7987 (list 'idlwave-shell-send-command
7988 (format "resolve_routine,'%s__%s'%s"
7989 (downcase class) (downcase name) kwd)
7990 '(idlwave-update-routine-info)
7991 nil t))))))
7993 (defun idlwave-find-module-this-file ()
7994 (interactive)
7995 (idlwave-find-module '(4)))
7997 (defun idlwave-find-module (&optional arg)
7998 "Find the source code of an IDL module.
7999 Works for modules for which IDLWAVE has routine info available.
8000 The function offers as default the module name `idlwave-routine-info'
8001 would use. With ARG limit to this buffer. With two prefix ARG's
8002 force class query for object methods."
8003 (interactive "P")
8004 (let* ((idlwave-query-class nil)
8005 (idlwave-force-class-query (equal arg '(16)))
8006 (this-buffer (equal arg '(4)))
8007 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
8008 (default (if module
8009 (concat (idlwave-make-full-name
8010 (nth 2 module) (car module))
8011 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8012 "none"))
8013 (list
8014 (idlwave-uniquify
8015 (delq nil
8016 (mapcar (lambda (x)
8017 (if (eq 'system (car-safe (nth 3 x)))
8018 ;; Take out system routines with no source.
8020 (list
8021 (concat (idlwave-make-full-name
8022 (nth 2 x) (car x))
8023 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8024 (if this-buffer
8025 (idlwave-save-buffer-update)
8026 (idlwave-routines))))))
8027 (name (idlwave-completing-read
8028 (if (or (not this-buffer)
8029 (assoc default list))
8030 (format "Module (Default %s): " default)
8031 (format "Module in this file: "))
8032 list))
8033 type class)
8034 (if (string-match "\\`\\s-*\\'" name)
8035 ;; Nothing, use the default.
8036 (setq name default))
8037 (if (string-match "<[fp]>" name)
8038 (setq type (substring name -2 -1)
8039 name (substring name 0 -3)))
8040 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8041 (setq class (match-string 1 name)
8042 name (match-string 2 name)))
8043 (setq name (idlwave-sintern-routine-or-method name class)
8044 class (idlwave-sintern-class class)
8045 type (cond ((equal type "f") 'fun)
8046 ((equal type "p") 'pro)
8047 (t t)))
8048 (idlwave-do-find-module name type class nil this-buffer)))
8050 (defun idlwave-do-find-module (name type class
8051 &optional force-source this-buffer)
8052 (let ((name1 (idlwave-make-full-name class name))
8053 source buf1 entry
8054 (buf (current-buffer))
8055 (pos (point))
8056 file name2)
8057 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8058 'WITH-FILE)
8059 source (or force-source (nth 3 entry))
8060 name2 (if (nth 2 entry)
8061 (idlwave-make-full-name (nth 2 entry) name)
8062 name1))
8063 (if source
8064 (setq file (idlwave-routine-source-file source)))
8065 (unless file ; Try to find it on the path.
8066 (setq file
8067 (idlwave-expand-lib-file-name
8068 (if class
8069 (format "%s__define.pro" (downcase class))
8070 (format "%s.pro" (downcase name))))))
8071 (cond
8072 ((or (null name) (equal name ""))
8073 (error "Abort"))
8074 ((eq (car source) 'system)
8075 (error "Source code for system routine %s is not available"
8076 name2))
8077 ((or (not file) (not (file-regular-p file)))
8078 (error "Source code for routine %s is not available"
8079 name2))
8081 (when (not this-buffer)
8082 (setq buf1
8083 (idlwave-find-file-noselect file 'find))
8084 (pop-to-buffer buf1 t))
8085 (goto-char (point-max))
8086 (let ((case-fold-search t))
8087 (if (re-search-backward
8088 (concat "^[ \t]*\\<"
8089 (cond ((eq type 'fun) "function")
8090 ((eq type 'pro) "pro")
8091 (t "\\(pro\\|function\\)"))
8092 "\\>[ \t]+"
8093 (regexp-quote (downcase name2))
8094 "[^a-zA-Z0-9_$]")
8095 nil t)
8096 (goto-char (match-beginning 0))
8097 (pop-to-buffer buf)
8098 (goto-char pos)
8099 (error "Could not find routine %s" name2)))))))
8101 (defun idlwave-what-module ()
8102 "Return a default module for stuff near point.
8103 Used by `idlwave-routine-info' and `idlwave-find-module'."
8104 (idlwave-routines)
8105 (if (let ((case-fold-search t))
8106 (save-excursion
8107 (idlwave-beginning-of-statement)
8108 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8109 ;; This is a function or procedure definition statement
8110 ;; We return the defined routine as module.
8111 (list
8112 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8113 (match-string-no-properties 2))
8114 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8115 (idlwave-sintern-class (match-string 3)))
8117 ;; Not a definition statement - analyze precise position.
8118 (let* ((where (idlwave-where))
8119 (cw (nth 2 where))
8120 (pro (car (nth 0 where)))
8121 (func (car (nth 1 where)))
8122 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8123 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8124 (following-char)))
8126 (cond
8127 ((and (eq cw 'procedure)
8128 (not (equal this-word "")))
8129 (setq this-word (idlwave-sintern-routine-or-method
8130 this-word (nth 2 (nth 3 where))))
8131 (list this-word 'pro
8132 (idlwave-determine-class
8133 (cons this-word (cdr (nth 3 where)))
8134 'pro)))
8135 ((and (eq cw 'function)
8136 (not (equal this-word ""))
8137 (or (eq next-char ?\() ; exclude arrays, vars.
8138 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8139 (setq this-word (idlwave-sintern-routine-or-method
8140 this-word (nth 2 (nth 3 where))))
8141 (list this-word 'fun
8142 (idlwave-determine-class
8143 (cons this-word (cdr (nth 3 where)))
8144 'fun)))
8145 ((and (memq cw '(function-keyword procedure-keyword))
8146 (not (equal this-word ""))
8147 (eq next-char ?\()) ; A function!
8148 (setq this-word (idlwave-sintern-routine this-word))
8149 (list this-word 'fun nil))
8150 (func
8151 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8152 (pro
8153 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8154 (t nil)))))
8156 (defun idlwave-what-module-find-class ()
8157 "Call `idlwave-what-module' and find the inherited class if necessary."
8158 (let* ((module (idlwave-what-module))
8159 (class (nth 2 module)))
8160 (if (and (= (length module) 3)
8161 (stringp class))
8162 (list (car module)
8163 (nth 1 module)
8164 (apply 'idlwave-find-inherited-class module))
8165 module)))
8167 (defun idlwave-find-inherited-class (name type class)
8168 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8169 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8170 (if entry
8171 (nth 2 entry)
8172 class)))
8174 (defun idlwave-fix-module-if-obj_new (module)
8175 "Check if MODULE points to obj_new.
8176 If yes, and if the cursor is in the keyword region, change to the
8177 appropriate Init method."
8178 (let* ((name (car module))
8179 (pos (point))
8180 (case-fold-search t)
8181 string)
8182 (if (and (stringp name)
8183 (equal (downcase name) "obj_new")
8184 (save-excursion
8185 (idlwave-beginning-of-statement)
8186 (setq string (buffer-substring (point) pos))
8187 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8188 string)))
8189 (let ((name "Init")
8190 (class (match-string 1 string)))
8191 (setq module (list (idlwave-sintern-method "Init")
8192 'fun
8193 (idlwave-sintern-class class)))))
8194 module))
8196 (defun idlwave-fix-keywords (name type class keywords
8197 &optional super-classes system)
8198 "Update a list of keywords.
8199 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8200 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8201 demand _EXTRA in the keyword list."
8202 (let ((case-fold-search t))
8204 ;; If this is the OBJ_NEW function, try to figure out the class and use
8205 ;; the keywords from the corresponding INIT method.
8206 (if (and (equal (upcase name) "OBJ_NEW")
8207 (or (eq major-mode 'idlwave-mode)
8208 (eq major-mode 'idlwave-shell-mode)))
8209 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8210 (string (buffer-substring bos (point)))
8211 (case-fold-search t)
8212 class)
8213 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8214 string)
8215 (setq class (idlwave-sintern-class (match-string 1 string)))
8216 (setq idlwave-current-obj_new-class class)
8217 (setq keywords
8218 (append keywords
8219 (idlwave-entry-keywords
8220 (idlwave-rinfo-assq
8221 (idlwave-sintern-method "INIT")
8222 'fun
8223 class
8224 (idlwave-routines)) 'do-link))))))
8226 ;; If the class is `t', combine all keywords of all methods NAME
8227 (when (eq class t)
8228 (mapc (lambda (entry)
8229 (and
8230 (nth 2 entry) ; non-nil class
8231 (eq (nth 1 entry) type) ; correct type
8232 (setq keywords
8233 (append keywords
8234 (idlwave-entry-keywords entry 'do-link)))))
8235 (idlwave-all-assq name (idlwave-routines)))
8236 (setq keywords (idlwave-uniquify keywords)))
8238 ;; If we have inheritance, add all keywords from superclasses, if
8239 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8240 (when (and
8241 super-classes
8242 idlwave-keyword-class-inheritance
8243 (stringp class)
8245 system
8246 (assq (idlwave-sintern-keyword "_extra") keywords)
8247 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8248 ;; Check if one of the keyword-class regexps matches the name
8249 (let ((regexps idlwave-keyword-class-inheritance) re)
8250 (catch 'exit
8251 (while (setq re (pop regexps))
8252 (if (string-match re name) (throw 'exit t))))))
8254 (loop for entry in (idlwave-routines) do
8255 (and (nth 2 entry) ; non-nil class
8256 (memq (nth 2 entry) super-classes) ; an inherited class
8257 (eq (nth 1 entry) type) ; correct type
8258 (eq (car entry) name) ; correct name
8259 (mapc (lambda (k) (add-to-list 'keywords k))
8260 (idlwave-entry-keywords entry 'do-link))))
8261 (setq keywords (idlwave-uniquify keywords)))
8263 ;; Return the final list
8264 keywords))
8266 (defun idlwave-expand-keyword (keyword module)
8267 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8268 KEYWORD may be an exact match or an abbreviation of a keyword.
8269 If the match is exact, KEYWORD itself is returned, even if there may be other
8270 keywords of which KEYWORD is an abbreviation. This is necessary because some
8271 system routines have keywords which are prefixes of other keywords.
8272 If KEYWORD is an abbreviation of several keywords, a list of all possible
8273 completions is returned.
8274 If the abbreviation was unique, the correct keyword is returned.
8275 If it cannot be a keyword, the function return nil.
8276 If we do not know about MODULE, just return KEYWORD literally."
8277 (let* ((name (car module))
8278 (type (nth 1 module))
8279 (class (nth 2 module))
8280 (kwd (idlwave-sintern-keyword keyword))
8281 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8282 (kwd-alist (idlwave-entry-keywords entry))
8283 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8284 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8285 (completion-ignore-case t)
8286 candidates)
8287 (cond ((assq kwd kwd-alist)
8288 kwd)
8289 ((setq candidates (all-completions kwd kwd-alist))
8290 (if (= (length candidates) 1)
8291 (car candidates)
8292 candidates))
8293 ((and entry extra)
8294 ;; Inheritance may cause this keyword to be correct
8295 keyword)
8296 (entry
8297 ;; We do know the function, which does not have the keyword.
8298 nil)
8300 ;; We do not know the function, so this just might be a correct
8301 ;; keyword - return it as it is.
8302 keyword))))
8304 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8305 (defvar idlwave-rinfo-map (make-sparse-keymap))
8306 (define-key idlwave-rinfo-mouse-map
8307 (if (featurep 'xemacs) [button2] [mouse-2])
8308 'idlwave-mouse-active-rinfo)
8309 (define-key idlwave-rinfo-mouse-map
8310 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8311 'idlwave-mouse-active-rinfo-shift)
8312 (define-key idlwave-rinfo-mouse-map
8313 (if (featurep 'xemacs) [button3] [mouse-3])
8314 'idlwave-mouse-active-rinfo-right)
8315 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8316 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8317 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8318 (defvar idlwave-popup-source nil)
8319 (defvar idlwave-rinfo-marker (make-marker))
8321 (defun idlwave-quit-help ()
8322 (interactive)
8323 (let ((ri-window (get-buffer-window "*Help*"))
8324 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8325 (when (and olh-window
8326 (fboundp 'idlwave-help-quit))
8327 (select-window olh-window)
8328 (idlwave-help-quit))
8329 (when (window-live-p ri-window)
8330 (delete-window ri-window))))
8332 (defun idlwave-display-calling-sequence (name type class
8333 &optional initial-class)
8334 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8335 (let* ((initial-class (or initial-class class))
8336 (entry (or (idlwave-best-rinfo-assq name type class
8337 (idlwave-routines))
8338 (idlwave-rinfo-assq name type class
8339 idlwave-unresolved-routines)))
8340 (name (or (car entry) name))
8341 (class (or (nth 2 entry) class))
8342 (superclasses (idlwave-all-class-inherits initial-class))
8343 (twins (idlwave-routine-twins entry))
8344 (dtwins (idlwave-study-twins twins))
8345 (all dtwins)
8346 (system (eq (car (nth 3 entry)) 'system))
8347 (calling-seq (nth 4 entry))
8348 (keywords (idlwave-entry-keywords entry 'do-link))
8349 (html-file (car (nth 5 entry)))
8350 (help-echo-kwd
8351 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8352 (help-echo-use
8353 "Button2/3: Online Help")
8354 (help-echo-src
8355 "Button2: Jump to source and back | Button3: Source in Help window.")
8356 (help-echo-class
8357 "Button2: Display info about same method in superclass")
8358 (col 0)
8359 (data (list name type class (current-buffer) nil initial-class))
8360 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8361 (face 'idlwave-help-link)
8362 beg props win cnt total)
8363 ;; Fix keywords, but don't add chained super-classes, since these
8364 ;; are shown separately for that super-class
8365 (setq keywords (idlwave-fix-keywords name type class keywords))
8366 (cond
8367 ((null entry)
8368 (error "No %s %s known %s" type name
8369 (if initial-class (concat "in class " initial-class) "")))
8370 ((or (null name) (equal name ""))
8371 (error "No function or procedure call at point"))
8372 ((null calling-seq)
8373 (error "Calling sequence of %s %s not available" type name))
8375 (move-marker idlwave-rinfo-marker (point))
8376 (with-current-buffer (get-buffer-create "*Help*")
8377 (use-local-map idlwave-rinfo-map)
8378 (setq buffer-read-only nil)
8379 (erase-buffer)
8380 (set (make-local-variable 'idlwave-popup-source) nil)
8381 (set (make-local-variable 'idlwave-current-obj_new-class)
8382 idlwave-current-obj_new-class)
8383 (when superclasses
8384 (setq props (list 'mouse-face 'highlight
8385 km-prop idlwave-rinfo-mouse-map
8386 'help-echo help-echo-class
8387 'data (cons 'class data)))
8388 (let ((classes (cons initial-class superclasses)) c)
8389 (insert "Classes: ")
8390 (while (setq c (pop classes))
8391 (insert " ")
8392 (setq beg (point))
8393 (insert c)
8394 (if (equal (downcase c) (downcase class))
8395 (add-text-properties beg (point) (list 'face 'bold))
8396 ;; If Method exists in a different class link it
8397 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8398 (add-text-properties beg (point) props))))
8399 (insert "\n")))
8400 (setq props (list 'mouse-face 'highlight
8401 km-prop idlwave-rinfo-mouse-map
8402 'help-echo help-echo-use
8403 'data (cons 'usage data)))
8404 (if html-file (setq props (append (list 'face face 'link html-file)
8405 props)))
8406 (insert "Usage: ")
8407 (setq beg (point))
8408 (insert (if class
8409 (format calling-seq class name class name class name)
8410 (format calling-seq name name name name))
8411 "\n")
8412 (add-text-properties beg (point) props)
8414 (insert "Keywords:")
8415 (if (null keywords)
8416 (insert " No keywords accepted.")
8417 (setq col 9)
8418 (mapc
8419 (lambda (x)
8420 (if (>= (+ col 1 (length (car x)))
8421 (window-width))
8422 (progn
8423 (insert "\n ")
8424 (setq col 9)))
8425 (insert " ")
8426 (setq beg (point)
8427 ;; Relevant keywords already have link property attached
8428 props (list 'mouse-face 'highlight
8429 km-prop idlwave-rinfo-mouse-map
8430 'data (cons 'keyword data)
8431 'help-echo help-echo-kwd
8432 'keyword (car x)))
8433 (if system (setq props (append (list 'face face) props)))
8434 (insert (car x))
8435 (add-text-properties beg (point) props)
8436 (setq col (+ col 1 (length (car x)))))
8437 keywords))
8439 (setq cnt 1 total (length all))
8440 ;; Here entry is (key file (list of type-conses))
8441 (while (setq entry (pop all))
8442 (setq props (list 'mouse-face 'highlight
8443 km-prop idlwave-rinfo-mouse-map
8444 'help-echo help-echo-src
8445 'source (list (car (car (nth 2 entry))) ;type
8446 (nth 1 entry)
8448 (cdr (car (nth 2 entry))))
8449 'data (cons 'source data)))
8450 (idlwave-insert-source-location
8451 (format "\n%-8s %s"
8452 (if (equal cnt 1)
8453 (if (> total 1) "Sources:" "Source:")
8455 (if (> total 1) "- " ""))
8456 entry props)
8457 (incf cnt)
8458 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8459 ;; No more source lines, please
8460 (insert (format
8461 "\n Source information truncated to %d entries."
8462 idlwave-rinfo-max-source-lines))
8463 (setq all nil)))
8464 (goto-char (point-min))
8465 (setq buffer-read-only t))
8466 (display-buffer "*Help*")
8467 (if (and (setq win (get-buffer-window "*Help*"))
8468 idlwave-resize-routine-help-window)
8469 (progn
8470 (let ((ww (selected-window)))
8471 (unwind-protect
8472 (progn
8473 (select-window win)
8474 (enlarge-window (- (/ (frame-height) 2)
8475 (window-height)))
8476 (shrink-window-if-larger-than-buffer))
8477 (select-window ww)))))))))
8479 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8480 "Insert a source location into the routine info buffer.
8481 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8482 to it."
8483 (let* ((key (car entry))
8484 (file (nth 1 entry))
8485 (types (nth 2 entry))
8486 (shell-flag (assq 'compiled types))
8487 (buffer-flag (assq 'buffer types))
8488 (user-flag (assq 'user types))
8489 (lib-flag (assq 'lib types))
8490 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8491 (and user-flag (idlwave-count-memq 'user types))
8492 (and lib-flag (idlwave-count-memq 'lib types))
8494 (doflags t)
8495 beg special)
8497 (insert prefix)
8499 (cond
8500 ((eq key 'system)
8501 (setq doflags nil)
8502 (insert "System "))
8504 ((eq key 'builtin)
8505 (setq doflags nil)
8506 (insert "Builtin "))
8508 ((and (not file) shell-flag)
8509 (insert "Unresolved"))
8511 ((null file)
8512 (insert "ERROR"))
8514 ((idlwave-syslib-p file)
8515 (if (string-match "obsolete" (file-name-directory file))
8516 (insert "Obsolete ")
8517 (insert "SystemLib ")))
8519 ;; New special syntax: taken directly from routine-info for
8520 ;; library catalog routines
8521 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8522 (insert (format "%-10s" special)))
8524 ;; Old special syntax: a matching regexp
8525 ((setq special (idlwave-special-lib-test file))
8526 (insert (format "%-10s" special)))
8528 ;; Catch-all with file
8529 ((idlwave-lib-p file) (insert "Library "))
8531 ;; Sanity catch all
8532 (t (insert "Other ")))
8534 (when doflags
8535 (insert (concat
8536 " ["
8537 (if lib-flag "L" "-")
8538 (if user-flag "C" "-")
8539 (if shell-flag "S" "-")
8540 (if buffer-flag "B" "-")
8541 "] ")))
8542 (when (> ndupl 1)
8543 (setq beg (point))
8544 (insert (format "(%dx) " ndupl))
8545 (add-text-properties beg (point) (list 'face 'bold)))
8546 (when (and file (not (equal file "")))
8547 (setq beg (point))
8548 (insert (apply 'abbreviate-file-name
8549 (if (featurep 'xemacs) (list file t) (list file))))
8550 (if file-props
8551 (add-text-properties beg (point) file-props)))))
8553 (defun idlwave-special-lib-test (file)
8554 "Check the path of FILE against the regexps which define special libs.
8555 Return the name of the special lib if there is a match."
8556 (let ((alist idlwave-special-lib-alist)
8557 entry rtn)
8558 (cond
8559 ((stringp file)
8560 (while (setq entry (pop alist))
8561 (if (string-match (car entry) file)
8562 (setq rtn (cdr entry)
8563 alist nil)))
8564 rtn)
8565 (t nil))))
8567 (defun idlwave-mouse-active-rinfo-right (ev)
8568 (interactive "e")
8569 (idlwave-mouse-active-rinfo ev 'right))
8571 (defun idlwave-mouse-active-rinfo-shift (ev)
8572 (interactive "e")
8573 (idlwave-mouse-active-rinfo ev nil 'shift))
8575 (defun idlwave-active-rinfo-space ()
8576 (interactive)
8577 (idlwave-mouse-active-rinfo nil 'right))
8579 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8580 "Do the mouse actions in the routine info buffer.
8581 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8582 was pressed."
8583 (interactive "e")
8584 (if ev (mouse-set-point ev))
8585 (let (data id name type class buf bufwin source link keyword
8586 word initial-class)
8587 (setq data (get-text-property (point) 'data)
8588 source (get-text-property (point) 'source)
8589 keyword (get-text-property (point) 'keyword)
8590 link (get-text-property (point) 'link)
8591 id (car data)
8592 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8593 buf (nth 4 data)
8594 initial-class (nth 6 data)
8595 word (idlwave-this-word)
8596 bufwin (get-buffer-window buf t))
8598 (cond ((eq id 'class) ; Switch class being displayed
8599 (if (window-live-p bufwin) (select-window bufwin))
8600 (idlwave-display-calling-sequence
8601 (idlwave-sintern-method name)
8602 type (idlwave-sintern-class word)
8603 initial-class))
8604 ((eq id 'usage) ; Online help on this routine
8605 (idlwave-online-help link name type class))
8606 ((eq id 'source) ; Source in help or buffer
8607 (if right ; In help
8608 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8609 (idlwave-help-source-try-header nil)
8610 ;; Fake idlwave-routines so help will find the right entry
8611 (idlwave-routines
8612 (list (list name type class source ""))))
8613 (idlwave-help-get-special-help name type class nil))
8614 ;; Otherwise just pop to the source
8615 (setq idlwave-popup-source (not idlwave-popup-source))
8616 (if idlwave-popup-source
8617 (condition-case err
8618 (idlwave-do-find-module name type class source)
8619 (error
8620 (setq idlwave-popup-source nil)
8621 (if (window-live-p bufwin) (select-window bufwin))
8622 (error (nth 1 err))))
8623 (if bufwin
8624 (select-window bufwin)
8625 (pop-to-buffer buf))
8626 (goto-char (marker-position idlwave-rinfo-marker)))))
8627 ((eq id 'keyword)
8628 (if right
8629 (idlwave-online-help link name type class keyword)
8630 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8632 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8633 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8634 (let ((bwin (get-buffer-window buffer)))
8635 (if idlwave-complete-empty-string-as-lower-case
8636 (setq keyword (downcase keyword)))
8637 (if bwin
8638 (select-window bwin)
8639 (pop-to-buffer buffer)
8640 (setq bwin (get-buffer-window buffer)))
8641 (if (eq (preceding-char) ?/)
8642 (insert keyword)
8643 (unless (save-excursion
8644 (re-search-backward
8645 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8646 (min (- (point) 100) (point-min)) t))
8647 (insert ", "))
8648 (if shift (insert "/"))
8649 (insert keyword)
8650 (if (and (not shift)
8651 idlwave-keyword-completion-adds-equal)
8652 (insert "=")))))
8654 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8655 "List the load path shadows of all routines defined in current buffer."
8656 (interactive "P")
8657 (idlwave-routines)
8658 (if (eq major-mode 'idlwave-mode)
8659 (idlwave-list-load-path-shadows
8660 nil (idlwave-update-current-buffer-info 'save-buffer)
8661 "in current buffer")
8662 (error "Current buffer is not in idlwave-mode")))
8664 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8665 "List the load path shadows of all routines compiled under the shell.
8666 This is very useful for checking an IDL application. Just compile the
8667 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8668 routines and update IDLWAVE internal info. Then check for shadowing
8669 with this command."
8670 (interactive "P")
8671 (cond
8672 ((or (not (fboundp 'idlwave-shell-is-running))
8673 (not (idlwave-shell-is-running)))
8674 (error "Shell is not running"))
8675 ((null idlwave-compiled-routines)
8676 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8678 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8679 "in the shell"))))
8681 (defun idlwave-list-all-load-path-shadows (&optional arg)
8682 "List the load path shadows of all routines known to IDLWAVE."
8683 (interactive "P")
8684 (idlwave-list-load-path-shadows nil nil "globally"))
8686 (defvar idlwave-sort-prefer-buffer-info t
8687 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8689 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8690 "List the routines which are defined multiple times.
8691 Search the information IDLWAVE has about IDL routines for multiple
8692 definitions.
8693 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8695 When IDL hits a routine call which is not defined, it will search on
8696 the load path in order to find a definition. The output of this command
8697 can be used to detect possible name clashes during this process."
8698 (idlwave-routines) ; Make sure everything is loaded.
8699 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8700 (or (y-or-n-p
8701 "You don't have any user or library catalogs. Continue anyway? ")
8702 (error "Abort")))
8703 (let* ((routines (append idlwave-system-routines
8704 idlwave-compiled-routines
8705 idlwave-library-catalog-routines
8706 idlwave-user-catalog-routines
8707 idlwave-buffer-routines
8708 nil))
8709 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8710 (keymap (make-sparse-keymap))
8711 (props (list 'mouse-face 'highlight
8712 km-prop keymap
8713 'help-echo "Mouse2: Find source"))
8714 (nroutines (length (or special-routines routines)))
8715 (step (/ nroutines 100))
8716 (n 0)
8717 (cnt 0)
8718 (idlwave-sort-prefer-buffer-info nil)
8719 routine twins dtwins twin done props1 lroutines)
8721 (if special-routines
8722 ;; Just looking for shadows of a few special routines
8723 (setq lroutines routines
8724 routines special-routines))
8726 (message "Sorting routines...")
8727 (setq routines (sort routines
8728 (lambda (a b)
8729 (string< (downcase (idlwave-make-full-name
8730 (nth 2 a) (car a)))
8731 (downcase (idlwave-make-full-name
8732 (nth 2 b) (car b)))))))
8733 (message "Sorting routines...done")
8735 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8736 (lambda (ev)
8737 (interactive "e")
8738 (mouse-set-point ev)
8739 (apply 'idlwave-do-find-module
8740 (get-text-property (point) 'find-args))))
8741 (define-key keymap [(return)]
8742 (lambda ()
8743 (interactive)
8744 (apply 'idlwave-do-find-module
8745 (get-text-property (point) 'find-args))))
8746 (message "Compiling list...( 0%%)")
8747 (with-current-buffer (get-buffer-create "*Shadows*")
8748 (setq buffer-read-only nil)
8749 (erase-buffer)
8750 (while (setq routine (pop routines))
8751 (if (= (mod (setq n (1+ n)) step) 0)
8752 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8754 ;; Get a list of all twins
8755 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8756 (if (memq routine done)
8757 (setq dtwins nil)
8758 (setq dtwins (idlwave-study-twins twins)))
8759 ;; Mark all twins as dealt with
8760 (setq done (append twins done))
8761 (when (or (> (length dtwins) 1)
8762 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8763 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8764 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8765 (incf cnt)
8766 (insert (format "\n%s%s"
8767 (idlwave-make-full-name (nth 2 routine)
8768 (car routine))
8769 (if (eq (nth 1 routine) 'fun) "()" "")))
8770 (while (setq twin (pop dtwins))
8771 (setq props1 (append (list 'find-args
8772 (list (nth 0 routine)
8773 (nth 1 routine)
8774 (nth 2 routine)))
8775 props))
8776 (idlwave-insert-source-location "\n - " twin props1))))
8777 (goto-char (point-min))
8778 (setq buffer-read-only t))
8779 (setq loc (or loc ""))
8780 (if (> cnt 0)
8781 (progn
8782 (display-buffer (get-buffer "*Shadows*"))
8783 (message "%d case%s of shadowing found %s"
8784 cnt (if (= cnt 1) "" "s") loc))
8785 (message "No shadowing conflicts found %s" loc))))
8787 (defun idlwave-print-source (routine)
8788 (let* ((source (nth 3 routine))
8789 (stype (car source))
8790 (sfile (idlwave-routine-source-file source)))
8791 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8792 (if (and (eq stype 'compiled)
8793 (or (not (stringp sfile))
8794 (not (string-match "\\S-" sfile))))
8795 (setq stype 'unresolved))
8796 (princ (format " %-10s %s\n"
8797 stype
8798 (if sfile sfile "No source code available")))))
8800 (defun idlwave-routine-twins (entry &optional list)
8801 "Return all twin entries of ENTRY in LIST.
8802 LIST defaults to `idlwave-routines'.
8803 Twin entries are those which have the same name, type, and class.
8804 ENTRY will also be returned, as the first item of this list."
8805 (let* ((name (car entry))
8806 (type (nth 1 entry))
8807 (class (nth 2 entry))
8808 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8809 twins candidate)
8810 (while (setq candidate (pop candidates))
8811 (if (and (not (eq candidate entry))
8812 (eq type (nth 1 candidate))
8813 (eq class (nth 2 candidate)))
8814 (push candidate twins)))
8815 (if (setq candidate (idlwave-rinfo-assq name type class
8816 idlwave-unresolved-routines))
8817 (push candidate twins))
8818 (cons entry (nreverse twins))))
8820 (defun idlwave-study-twins (entries)
8821 "Return dangerous twins of first entry in ENTRIES.
8822 Dangerous twins are routines with same name, but in different files on
8823 the load path. If a file is in the system library and has an entry in
8824 the `idlwave-system-routines' list, we omit the latter as
8825 non-dangerous because many IDL routines are implemented as library
8826 routines, and may have been scanned."
8827 (let* ((entry (car entries))
8828 (name (car entry)) ;
8829 (type (nth 1 entry)) ; Must be bound for
8830 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8831 (cnt 0)
8832 source type type-cons file alist syslibp key)
8833 (while (setq entry (pop entries))
8834 (incf cnt)
8835 (setq source (nth 3 entry)
8836 type (car source)
8837 type-cons (cons type (nth 3 source))
8838 file (idlwave-routine-source-file source))
8840 ;; Make KEY to index entry properly
8841 (setq key (cond ((eq type 'system) type)
8842 (file (file-truename file))
8843 (t 'unresolved)))
8845 ;; Check for an entry in the system library
8846 (if (and file
8847 (not syslibp)
8848 (idlwave-syslib-p file))
8849 (setq syslibp t))
8851 ;; If there's more than one matching entry for the same file, just
8852 ;; append the type-cons to the type list.
8853 (if (setq entry (assoc key alist))
8854 (push type-cons (nth 2 entry))
8855 (push (list key file (list type-cons)) alist)))
8857 (setq alist (nreverse alist))
8859 (when syslibp
8860 ;; File is in system *library* - remove any 'system entry
8861 (setq alist (delq (assq 'system alist) alist)))
8863 ;; If 'system remains and we've scanned the syslib, it's a builtin
8864 ;; (rather than a !DIR/lib/.pro file bundled as source).
8865 (when (and (idlwave-syslib-scanned-p)
8866 (setq entry (assoc 'system alist)))
8867 (setcar entry 'builtin))
8868 (sort alist 'idlwave-routine-twin-compare)))
8870 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8871 ;; (defvar type)
8872 ;; (defvar class)
8873 (defmacro idlwave-xor (a b)
8874 `(and (or ,a ,b)
8875 (not (and ,a ,b))))
8877 (defun idlwave-routine-entry-compare (a b)
8878 "Compare two routine info entries for sorting.
8879 This is the general case. It first compares class, names, and type.
8880 If it turns out that A and B are twins (same name, class, and type),
8881 calls another routine which compares twins on the basis of their file
8882 names and path locations."
8883 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8884 (cond
8885 ((not (equal (idlwave-downcase-safe class)
8886 (idlwave-downcase-safe (nth 2 b))))
8887 ;; Class decides
8888 (cond ((null (nth 2 b)) nil)
8889 ((null class) t)
8890 (t (string< (downcase class) (downcase (nth 2 b))))))
8891 ((not (equal (downcase name) (downcase (car b))))
8892 ;; Name decides
8893 (string< (downcase name) (downcase (car b))))
8894 ((not (eq type (nth 1 b)))
8895 ;; Type decides
8896 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8898 ;; A and B are twins - so the decision is more complicated.
8899 ;; Call twin-compare with the proper arguments.
8900 (idlwave-routine-entry-compare-twins a b)))))
8902 (defun idlwave-routine-entry-compare-twins (a b)
8903 "Compare two routine entries, under the assumption that they are twins.
8904 This basically calls `idlwave-routine-twin-compare' with the correct args."
8905 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8906 (asrc (nth 3 a))
8907 (atype (car asrc))
8908 (bsrc (nth 3 b))
8909 (btype (car bsrc))
8910 (afile (idlwave-routine-source-file asrc))
8911 (bfile (idlwave-routine-source-file bsrc)))
8912 (idlwave-routine-twin-compare
8913 (if (stringp afile)
8914 (list (file-truename afile) afile (list atype))
8915 (list atype afile (list atype)))
8916 (if (stringp bfile)
8917 (list (file-truename bfile) bfile (list btype))
8918 (list btype bfile (list btype))))
8921 ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
8922 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8923 (defvar class)
8925 (defun idlwave-routine-twin-compare (a b)
8926 "Compare two routine twin entries for sorting.
8927 In here, A and B are not normal routine info entries, but special
8928 lists (KEY FILENAME (TYPES...)).
8929 This expects NAME TYPE CLASS to be bound to the right values."
8930 (let* (;; Dis-assemble entries
8931 (akey (car a)) (bkey (car b))
8932 (afile (nth 1 a)) (bfile (nth 1 b))
8933 (atypes (nth 2 a)) (btypes (nth 2 b))
8934 ;; System routines?
8935 (asysp (memq akey '(builtin system)))
8936 (bsysp (memq bkey '(builtin system)))
8937 ;; Compiled routines?
8938 (acompp (memq 'compiled atypes))
8939 (bcompp (memq 'compiled btypes))
8940 ;; Unresolved?
8941 (aunresp (or (eq akey 'unresolved)
8942 (and acompp (not afile))))
8943 (bunresp (or (eq bkey 'unresolved)
8944 (and bcompp (not bfile))))
8945 ;; Buffer info available?
8946 (abufp (memq 'buffer atypes))
8947 (bbufp (memq 'buffer btypes))
8948 ;; On search path?
8949 (tpath-alist (idlwave-true-path-alist))
8950 (apathp (and (stringp akey)
8951 (assoc (file-name-directory akey) tpath-alist)))
8952 (bpathp (and (stringp bkey)
8953 (assoc (file-name-directory bkey) tpath-alist)))
8954 ;; How early on search path? High number means early since we
8955 ;; measure the tail of the path list
8956 (anpath (length (memq apathp tpath-alist)))
8957 (bnpath (length (memq bpathp tpath-alist)))
8958 ;; Look at file names
8959 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8960 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8961 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8962 (regexp-quote (downcase class))
8963 (regexp-quote (downcase name)))
8964 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8965 ;; Is file name derived from the routine name?
8966 ;; Method file or class definition file?
8967 (anamep (string-match fname-re aname))
8968 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8969 (bnamep (string-match fname-re bname))
8970 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8972 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8973 ;; doesn't it? The difficult stuff is hidden above...
8974 (cond
8975 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8976 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8977 ((and idlwave-sort-prefer-buffer-info
8978 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8979 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8980 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8981 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8982 ((and class anamep bnamep ; both file names match ->
8983 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8984 ((> anpath bnpath) t) ; Who is first on path?
8985 (t nil)))) ; Default
8987 (defun idlwave-routine-source-file (source)
8988 (if (nth 2 source)
8989 (expand-file-name (nth 1 source) (nth 2 source))
8990 (nth 1 source)))
8992 (defun idlwave-downcase-safe (string)
8993 "Donwcase if string, else return unchanged."
8994 (if (stringp string)
8995 (downcase string)
8996 string))
8998 (defun idlwave-count-eq (elt list)
8999 "How often is ELT in LIST?"
9000 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9002 (defun idlwave-count-memq (elt alist)
9003 "How often is ELT a key in ALIST?"
9004 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9006 (defun idlwave-syslib-p (file)
9007 "Non-nil if FILE is in the system library."
9008 (let* ((true-syslib (file-name-as-directory
9009 (file-truename
9010 (expand-file-name "lib" (idlwave-sys-dir)))))
9011 (true-file (file-truename file)))
9012 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9014 (defun idlwave-lib-p (file)
9015 "Non-nil if FILE is in the library."
9016 (let ((true-dir (file-name-directory (file-truename file))))
9017 (assoc true-dir (idlwave-true-path-alist))))
9019 (defun idlwave-path-alist-add-flag (list-entry flag)
9020 "Add a flag to the path list entry, if not set."
9021 (let ((flags (cdr list-entry)))
9022 (add-to-list 'flags flag)
9023 (setcdr list-entry flags)))
9025 (defun idlwave-path-alist-remove-flag (list-entry flag)
9026 "Remove a flag to the path list entry, if set."
9027 (let ((flags (delq flag (cdr list-entry))))
9028 (setcdr list-entry flags)))
9030 (defun idlwave-true-path-alist ()
9031 "Return `idlwave-path-alist' alist with true-names.
9032 Info is cached, but relies on the functions setting `idlwave-path-alist'
9033 to reset the variable `idlwave-true-path-alist' to nil."
9034 (or idlwave-true-path-alist
9035 (setq idlwave-true-path-alist
9036 (mapcar (lambda(x) (cons
9037 (file-name-as-directory
9038 (file-truename
9039 (directory-file-name
9040 (car x))))
9041 (cdr x)))
9042 idlwave-path-alist))))
9044 (defun idlwave-syslib-scanned-p ()
9045 "Non-nil if the system lib file !DIR/lib has been scanned."
9046 (let* ((true-syslib (file-name-as-directory
9047 (file-truename
9048 (expand-file-name "lib" (idlwave-sys-dir))))))
9049 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9051 ;; ----------------------------------------------------------------------------
9053 ;; Online Help display
9056 ;; ----------------------------------------------------------------------------
9058 ;; Additions for use with imenu.el and func-menu.el
9059 ;; (pop-up a list of IDL units in the current file).
9062 (defun idlwave-prev-index-position ()
9063 "Search for the previous procedure or function.
9064 Return nil if not found. For use with imenu.el."
9065 (save-match-data
9066 (cond
9067 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9068 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9069 (t nil))))
9071 (defun idlwave-unit-name ()
9072 "Return the unit name.
9073 Assumes that point is at the beginning of the unit as found by
9074 `idlwave-prev-index-position'."
9075 (forward-sexp 2)
9076 (forward-sexp -1)
9077 (let ((begin (point)))
9078 (re-search-forward
9079 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9080 (if (fboundp 'buffer-substring-no-properties)
9081 (buffer-substring-no-properties begin (point))
9082 (buffer-substring begin (point)))))
9084 (defalias 'idlwave-function-menu
9085 (condition-case nil
9086 (progn
9087 (require 'func-menu)
9088 'function-menu)
9089 (error (condition-case nil
9090 (progn
9091 (require 'imenu)
9092 'imenu)
9093 (error nil)))))
9095 ;; Here we hack func-menu.el in order to support this new mode.
9096 ;; The latest versions of func-menu.el already have this stuff in, so
9097 ;; we hack only if it is not already there.
9098 (when (fboundp 'eval-after-load)
9099 (eval-after-load "func-menu"
9100 '(progn
9101 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9102 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9103 (setq fume-function-name-regexp-alist
9104 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9105 fume-function-name-regexp-alist)))
9106 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9107 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9108 (setq fume-find-function-name-method-alist
9109 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9110 fume-find-function-name-method-alist))))))
9112 (defun idlwave-edit-in-idlde ()
9113 "Edit the current file in IDL Development environment."
9114 (interactive)
9115 (start-process "idldeclient" nil
9116 idlwave-shell-explicit-file-name "-c" "-e"
9117 (buffer-file-name)))
9119 (defvar idlwave-help-use-assistant)
9120 (defun idlwave-launch-idlhelp ()
9121 "Start the IDLhelp application."
9122 (interactive)
9123 (if idlwave-help-use-assistant
9124 (idlwave-help-assistant-raise)
9125 (start-process "idlhelp" nil idlwave-help-application)))
9127 ;; Menus - using easymenu.el
9128 (defvar idlwave-mode-menu-def
9129 `("IDLWAVE"
9130 ["PRO/FUNC menu" idlwave-function-menu t]
9131 ("Motion"
9132 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9133 ["Subprogram End" idlwave-end-of-subprogram t]
9134 ["Block Start" idlwave-beginning-of-block t]
9135 ["Block End" idlwave-end-of-block t]
9136 ["Up Block" idlwave-backward-up-block t]
9137 ["Down Block" idlwave-down-block t]
9138 ["Skip Block Backward" idlwave-backward-block t]
9139 ["Skip Block Forward" idlwave-forward-block t])
9140 ("Mark"
9141 ["Subprogram" idlwave-mark-subprogram t]
9142 ["Block" idlwave-mark-block t]
9143 ["Header" idlwave-mark-doclib t])
9144 ("Format"
9145 ["Indent Entire Statement" idlwave-indent-statement
9146 :active t :keys "C-u \\[indent-for-tab-command]" ]
9147 ["Indent Subprogram" idlwave-indent-subprogram t]
9148 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9149 ["Continue/Split line" idlwave-split-line t]
9150 "--"
9151 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9152 :selected (symbol-value idlwave-fill-function)])
9153 ("Templates"
9154 ["Procedure" idlwave-procedure t]
9155 ["Function" idlwave-function t]
9156 ["Doc Header" idlwave-doc-header t]
9157 ["Log" idlwave-doc-modification t]
9158 "--"
9159 ["Case" idlwave-case t]
9160 ["For" idlwave-for t]
9161 ["Repeat" idlwave-repeat t]
9162 ["While" idlwave-while t]
9163 "--"
9164 ["Close Block" idlwave-close-block t])
9165 ("Completion"
9166 ["Complete" idlwave-complete t]
9167 ("Complete Specific"
9168 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9169 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9170 "--"
9171 ["3 Function Name" (idlwave-complete 'function) t]
9172 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9173 "--"
9174 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9175 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9176 "--"
9177 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9178 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9179 "--"
9180 ["9 Class Name" idlwave-complete-class t]))
9181 ("Routine Info"
9182 ["Show Routine Info" idlwave-routine-info t]
9183 ["Online Context Help" idlwave-context-help t]
9184 "--"
9185 ["Find Routine Source" idlwave-find-module t]
9186 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9187 "--"
9188 ["Update Routine Info" idlwave-update-routine-info t]
9189 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9190 "--"
9191 "IDL User Catalog"
9192 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9193 ["Scan Directories" (idlwave-update-routine-info '(16))
9194 (and idlwave-path-alist (not idlwave-catalog-process))]
9195 ["Scan Directories &" (idlwave-update-routine-info '(64))
9196 (and idlwave-path-alist (not idlwave-catalog-process))]
9197 "--"
9198 "Routine Shadows"
9199 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9200 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9201 ["Check Everything" idlwave-list-all-load-path-shadows t])
9202 ("Misc"
9203 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9204 "--"
9205 ["Insert TAB character" idlwave-hard-tab t])
9206 "--"
9207 ("External"
9208 ["Start IDL shell" idlwave-shell t]
9209 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9210 ["Launch IDL Help" idlwave-launch-idlhelp t])
9211 "--"
9212 ("Customize"
9213 ["Browse IDLWAVE Group" idlwave-customize t]
9214 "--"
9215 ["Build Full Customize Menu" idlwave-create-customize-menu
9216 (fboundp 'customize-menu-create)])
9217 ("Documentation"
9218 ["Describe Mode" describe-mode t]
9219 ["Abbreviation List" idlwave-list-abbrevs t]
9220 "--"
9221 ["Commentary in idlwave.el" idlwave-show-commentary t]
9222 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9223 "--"
9224 ["Info" idlwave-info t]
9225 "--"
9226 ["Help with Topic" idlwave-help-assistant-help-with-topic
9227 idlwave-help-use-assistant]
9228 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9230 (defvar idlwave-mode-debug-menu-def
9231 '("Debug"
9232 ["Start IDL shell" idlwave-shell t]
9233 ["Save and .RUN buffer" idlwave-shell-save-and-run
9234 (and (boundp 'idlwave-shell-automatic-start)
9235 idlwave-shell-automatic-start)]))
9237 (if (or (featurep 'easymenu) (load "easymenu" t))
9238 (progn
9239 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9240 "IDL and WAVE CL editing menu"
9241 idlwave-mode-menu-def)
9242 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9243 "IDL and WAVE CL editing menu"
9244 idlwave-mode-debug-menu-def)))
9246 (defun idlwave-customize ()
9247 "Call the customize function with `idlwave' as argument."
9248 (interactive)
9249 ;; Try to load the code for the shell, so that we can customize it
9250 ;; as well.
9251 (or (featurep 'idlw-shell)
9252 (load "idlw-shell" t))
9253 (customize-browse 'idlwave))
9255 (defun idlwave-create-customize-menu ()
9256 "Create a full customization menu for IDLWAVE, insert it into the menu."
9257 (interactive)
9258 (if (fboundp 'customize-menu-create)
9259 (progn
9260 ;; Try to load the code for the shell, so that we can customize it
9261 ;; as well.
9262 (or (featurep 'idlw-shell)
9263 (load "idlw-shell" t))
9264 (easy-menu-change
9265 '("IDLWAVE") "Customize"
9266 `(["Browse IDLWAVE group" idlwave-customize t]
9267 "--"
9268 ,(customize-menu-create 'idlwave)
9269 ["Set" Custom-set t]
9270 ["Save" Custom-save t]
9271 ["Reset to Current" Custom-reset-current t]
9272 ["Reset to Saved" Custom-reset-saved t]
9273 ["Reset to Standard Settings" Custom-reset-standard t]))
9274 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9275 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9277 (defun idlwave-show-commentary ()
9278 "Use the finder to view the file documentation from `idlwave.el'."
9279 (interactive)
9280 (finder-commentary "idlwave.el"))
9282 (defun idlwave-shell-show-commentary ()
9283 "Use the finder to view the file documentation from `idlw-shell.el'."
9284 (interactive)
9285 (finder-commentary "idlw-shell.el"))
9287 (defun idlwave-info ()
9288 "Read documentation for IDLWAVE in the info system."
9289 (interactive)
9290 (info "idlwave"))
9292 (defun idlwave-list-abbrevs (arg)
9293 "Show the code abbreviations define in IDLWAVE mode.
9294 This lists all abbrevs where the replacement text differs from the input text.
9295 These are the ones the users want to learn to speed up their writing.
9297 The function does *not* list abbrevs which replace a word with itself
9298 to call a hook. These hooks are used to change the case of words or
9299 to blink the matching `begin', and the user does not need to know them.
9301 With arg, list all abbrevs with the corresponding hook.
9303 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9305 (interactive "P")
9306 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9307 abbrevs
9308 str rpl func fmt (len-str 0) (len-rpl 0))
9309 (mapatoms
9310 (lambda (sym)
9311 (if (symbol-value sym)
9312 (progn
9313 (setq str (symbol-name sym)
9314 rpl (symbol-value sym)
9315 func (symbol-function sym))
9316 (if arg
9317 (setq func (prin1-to-string func))
9318 (if (and (listp func) (stringp (nth 2 func)))
9319 (setq rpl (concat "EVAL: " (nth 2 func))
9320 func "")
9321 (setq func "")))
9322 (if (or arg (not (string= rpl str)))
9323 (progn
9324 (setq len-str (max len-str (length str)))
9325 (setq len-rpl (max len-rpl (length rpl)))
9326 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9327 table)
9328 ;; sort the list
9329 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9330 ;; Make the format
9331 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9332 (with-output-to-temp-buffer "*Help*"
9333 (if arg
9334 (progn
9335 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9336 (princ "=========================================\n\n")
9337 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9338 (princ (format fmt "---" "-------" "----")))
9339 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9340 (princ "================================================\n\n")
9341 (princ (format fmt "KEY" "ACTION" ""))
9342 (princ (format fmt "---" "------" "")))
9343 (mapcar
9344 (lambda (list)
9345 (setq str (car list)
9346 rpl (nth 1 list)
9347 func (nth 2 list))
9348 (princ (format fmt str rpl func)))
9349 abbrevs)))
9350 ;; Make sure each abbreviation uses only one display line
9351 (with-current-buffer "*Help*"
9352 (setq truncate-lines t)))
9354 ;; Add .pro files to speedbar for support, if it's loaded
9355 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9357 ;; Set an idle timer to load the routine info.
9358 ;; Will only work on systems which support this.
9359 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9361 ;; Run the hook
9362 (run-hooks 'idlwave-load-hook)
9364 (provide 'idlwave)
9366 ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
9367 ;;; idlwave.el ends here