Derive from prog-mode, use derived-mode-p, and fix up various
[emacs.git] / lisp / progmodes / idlwave.el
blob4788cb307833ff01f323a186e182646103acd947
1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Carsten Dominik <dominik@science.uva.nl>
8 ;; Chris Chase <chase@att.com>
9 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
10 ;; Version: 6.1.22
11 ;; Keywords: languages
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;;; Commentary:
30 ;; IDLWAVE enables feature-rich development and interaction with IDL,
31 ;; the Interactive Data Language. It provides a compelling,
32 ;; full-featured alternative to the IDLDE development environment
33 ;; bundled with IDL.
35 ;; In the remotely distant past, based on pascal.el, though bears
36 ;; little resemblance to it now.
38 ;; Incorporates many ideas, such as abbrevs, action routines, and
39 ;; continuation line indenting, from wave.el.
40 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
42 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
43 ;; for features, key bindings, and info.
44 ;; Also, Info format documentation is available with `M-x idlwave-info'
46 ;; New versions of IDLWAVE, documentation, and more information
47 ;; available from:
48 ;; http://idlwave.org
50 ;; INSTALLATION
51 ;; ============
53 ;; Follow the instructions in the INSTALL file of the distribution.
54 ;; In short, put this file on your load path and add the following
55 ;; lines to your .emacs file:
57 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
58 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
59 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
62 ;; SOURCE
63 ;; ======
65 ;; The newest version of this file is available from the maintainer's
66 ;; Webpage:
68 ;; http://idlwave.org
70 ;; DOCUMENTATION
71 ;; =============
73 ;; IDLWAVE is documented online in info format. A printable version
74 ;; of the documentation is available from the maintainers webpage (see
75 ;; SOURCE).
78 ;; ACKNOWLEDGMENTS
79 ;; ===============
81 ;; Thanks to the following people for their contributions and comments:
83 ;; Ulrik Dickow <dickow_at_nbi.dk>
84 ;; Eric E. Dors <edors_at_lanl.gov>
85 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
86 ;; David Huenemoerder <dph_at_space.mit.edu>
87 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
88 ;; Dick Jackson <dick_at_d-jackson.com>
89 ;; Xuyong Liu <liu_at_stsci.edu>
90 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
91 ;; Laurent Mugnier <mugnier_at_onera.fr>
92 ;; Lubos Pochman <lubos_at_rsinc.com>
93 ;; Bob Portmann <portmann_at_al.noaa.gov>
94 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
95 ;; Marty Ryba <ryba_at_ll.mit.edu>
96 ;; Paul Sorenson <aardvark62_at_msn.com>
97 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
98 ;; Phil Williams <williams_at_irc.chmcc.org>
100 ;; CUSTOMIZATION:
101 ;; =============
103 ;; IDLWAVE has extensive customize support; to learn about the
104 ;; variables which control the mode's behavior, use `M-x
105 ;; idlwave-customize'.
107 ;; You can set your own preferred values with Customize, or with Lisp
108 ;; code in .emacs. For an example of what to put into .emacs, check
109 ;; the TexInfo documentation or see a complete .emacs available at the
110 ;; website.
112 ;; KNOWN PROBLEMS:
113 ;; ==============
115 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
116 ;; Numerics, Inc. is growing less and less complete as the two
117 ;; languages grow increasingly apart. The mode probably shouldn't
118 ;; even have "WAVE" in its title, but it's catchy, and was required
119 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
121 ;; Moving the point backwards in conjunction with abbrev expansion
122 ;; does not work as I would like it, but this is a problem with
123 ;; emacs abbrev expansion done by the self-insert-command. It ends
124 ;; up inserting the character that expanded the abbrev after moving
125 ;; point backward, e.g., "\cl" expanded with a space becomes
126 ;; "LONG( )" with point before the close paren. This is solved by
127 ;; using a temporary function in `post-command-hook' - not pretty,
128 ;; but it works.
130 ;; Tabs and spaces are treated equally as whitespace when filling a
131 ;; comment paragraph. To accomplish this, tabs are permanently
132 ;; replaced by spaces in the text surrounding the paragraph, which
133 ;; may be an undesirable side-effect. Replacing tabs with spaces is
134 ;; limited to comments only and occurs only when a comment
135 ;; paragraph is filled via `idlwave-fill-paragraph'.
137 ;; Muti-statement lines (using "&") on block begin and end lines can
138 ;; ruin the formatting. For example, multiple end statements on a
139 ;; line: endif & endif. Using "&" outside of block begin/end lines
140 ;; should be okay.
142 ;; Determining the expression at point for printing and other
143 ;; examination commands is somewhat rough: currently only fairly
144 ;; simple entities are found. You can always drag-select or examine
145 ;; a pre-selected region.
147 ;; When forcing completion of method keywords, the initial
148 ;; query for a method has multiple entries for some methods. Would
149 ;; be too difficult to fix this hardly used case.
152 ;;; Code:
155 (eval-when-compile (require 'cl))
156 (require 'idlw-help)
158 ;; For XEmacs
159 (unless (fboundp 'line-beginning-position)
160 (defalias 'line-beginning-position 'point-at-bol))
161 (unless (fboundp 'line-end-position)
162 (defalias 'line-end-position 'point-at-eol))
163 (unless (fboundp 'char-valid-p)
164 (defalias 'char-valid-p 'characterp))
165 (unless (fboundp 'match-string-no-properties)
166 (defalias 'match-string-no-properties 'match-string))
168 (if (not (fboundp 'cancel-timer))
169 (condition-case nil
170 (require 'timer)
171 (error nil)))
173 (declare-function idlwave-shell-get-path-info "idlw-shell")
174 (declare-function idlwave-shell-temp-file "idlw-shell")
175 (declare-function idlwave-shell-is-running "idlw-shell")
176 (declare-function widget-value "wid-edit" (widget))
177 (declare-function comint-dynamic-complete-filename "comint" ())
179 (defgroup idlwave nil
180 "Major mode for editing IDL .pro files."
181 :tag "IDLWAVE"
182 :link '(url-link :tag "Home Page"
183 "http://idlwave.org")
184 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
185 "idlw-shell.el")
186 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
187 :link '(custom-manual "(idlwave)Top")
188 :prefix "idlwave"
189 :group 'languages)
192 ;;; Variables for indentation behavior ---------------------------------------
194 (defgroup idlwave-code-formatting nil
195 "Indentation and formatting options for IDLWAVE mode."
196 :group 'idlwave)
198 (defcustom idlwave-main-block-indent 2
199 "*Extra indentation for the main block of code.
200 That is the block between the FUNCTION/PRO statement and the END
201 statement for that program unit."
202 :group 'idlwave-code-formatting
203 :type 'integer)
205 (defcustom idlwave-block-indent 3
206 "*Extra indentation applied to block lines.
207 If you change this, you probably also want to change `idlwave-end-offset'."
208 :group 'idlwave-code-formatting
209 :type 'integer)
211 (defcustom idlwave-end-offset -3
212 "*Extra indentation applied to block END lines.
213 A value equal to negative `idlwave-block-indent' will make END lines
214 line up with the block BEGIN lines."
215 :group 'idlwave-code-formatting
216 :type 'integer)
218 (defcustom idlwave-continuation-indent 3
219 "*Extra indentation applied to continuation lines.
220 This extra offset applies to the first of a set of continuation lines.
221 The following lines receive the same indentation as the first."
222 :group 'idlwave-code-formatting
223 :type 'integer)
225 (defcustom idlwave-max-extra-continuation-indent 40
226 "*Maximum additional indentation for special continuation indent.
227 Several special indentations are tried to help line up continuation
228 lines in routine calls or definitions, other statements with
229 parentheses, or assignment statements. This variable specifies a
230 maximum amount by which this special indentation can exceed the
231 standard continuation indentation, otherwise defaulting to a fixed
232 offset. Set to 0 to effectively disable all special continuation
233 indentation, or to a large number (like 100) to enable it in all
234 cases. See also `idlwave-indent-to-open-paren', which can override
235 this variable."
236 :group 'idlwave-code-formatting
237 :type 'integer)
239 (defcustom idlwave-indent-to-open-paren t
240 "*Non-nil means, indent continuation lines to innermost open parenthesis.
241 This indentation occurs even if otherwise disallowed by
242 `idlwave-max-extra-continuation-indent'. Matching parens and the
243 interleaving args are lined up. Example:
245 x = function_a(function_b(function_c( a, b, [1,2,3, $
246 4,5,6 $
247 ], $
248 c, d $
251 When this variable is nil, paren alignment may still occur, based on
252 the value of `idlwave-max-extra-continuation-indent', which, if zero,
253 would yield:
255 x = function_a(function_b(function_c( a, b, [1,2,3, $
256 4,5,6 $
257 ], $
258 c, d $
259 )))"
260 :group 'idlwave-code-formatting
261 :type 'boolean)
263 (defcustom idlwave-indent-parens-nested nil
264 "*Non-nil means, indent continuation lines with parens by nesting
265 lines at consecutively deeper levels."
266 :group 'idlwave-code-formatting
267 :type 'boolean)
270 (defcustom idlwave-hanging-indent t
271 "*If set non-nil then comment paragraphs are indented under the
272 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
273 of the paragraph."
274 :group 'idlwave-code-formatting
275 :type 'boolean)
277 (defcustom idlwave-hang-indent-regexp "- "
278 "*Regular expression matching the position of the hanging indent
279 in the first line of a comment paragraph. The size of the indent
280 extends to the end of the match for the regular expression."
281 :group 'idlwave-code-formatting
282 :type 'regexp)
284 (defcustom idlwave-use-last-hang-indent nil
285 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
286 :group 'idlwave-code-formatting
287 :type 'boolean)
289 (defcustom idlwave-fill-comment-line-only t
290 "*If non-nil then auto fill will only operate on comment lines."
291 :group 'idlwave-code-formatting
292 :type 'boolean)
294 (defcustom idlwave-auto-fill-split-string t
295 "*If non-nil then auto fill will split strings with the IDL `+' operator.
296 When the line end falls within a string, string concatenation with the
297 '+' operator will be used to distribute a long string over lines.
298 If nil and a string is split then a terminal beep and warning are issued.
300 This variable is ignored when `idlwave-fill-comment-line-only' is
301 non-nil, since in this case code is not auto-filled."
302 :group 'idlwave-code-formatting
303 :type 'boolean)
305 (defcustom idlwave-split-line-string t
306 "*If non-nil then `idlwave-split-line' will split strings with `+'.
307 When the splitting point of a line falls inside a string, split the string
308 using the `+' string concatenation operator. If nil and a string is
309 split then a terminal beep and warning are issued."
310 :group 'idlwave-code-formatting
311 :type 'boolean)
313 (defcustom idlwave-no-change-comment ";;;"
314 "*The indentation of a comment that starts with this regular
315 expression will not be changed. Note that the indentation of a comment
316 at the beginning of a line is never changed."
317 :group 'idlwave-code-formatting
318 :type 'string)
320 (defcustom idlwave-begin-line-comment nil
321 "*A comment anchored at the beginning of line.
322 A comment matching this regular expression will not have its
323 indentation changed. If nil the default is \"^;\", i.e., any line
324 beginning with a \";\". Expressions for comments at the beginning of
325 the line should begin with \"^\"."
326 :group 'idlwave-code-formatting
327 :type '(choice (const :tag "Any line beginning with `;'" nil)
328 'regexp))
330 (defcustom idlwave-code-comment ";;[^;]"
331 "*A comment that starts with this regular expression on a line by
332 itself is indented as if it is a part of IDL code. As a result if
333 the comment is not preceded by whitespace it is unchanged."
334 :group 'idlwave-code-formatting
335 :type 'regexp)
337 ;; Comments not matching any of the above will be indented as a
338 ;; right-margin comment, i.e., to a minimum of `comment-column'.
340 ;;; Routine Info and Completion ---------------------------------------
342 (defgroup idlwave-routine-info nil
343 "Routine Info options for IDLWAVE mode."
344 :group 'idlwave)
346 (defcustom idlwave-use-library-catalogs t
347 "*Non-nil means search the IDL path for library catalog files.
349 These files, named .idlwave_catalog, document routine information for
350 individual directories and libraries of IDL .pro files. Many popular
351 libraries come with catalog files by default, so leaving this on is
352 usually a good idea."
353 :group 'idlwave-routine-info
354 :type 'boolean)
356 (defcustom idlwave-init-rinfo-when-idle-after 10
357 "*Seconds of idle time before routine info is automatically initialized.
358 Initializing the routine info can take a long time, in particular if a
359 large number of library catalogs are involved. When Emacs is idle for
360 more than the number of seconds specified by this variable, it starts
361 the initialization. The process is split into five steps, in order to
362 keep work interruption as short as possible. If one of the steps
363 finishes, and no user input has arrived in the mean time, initialization
364 proceeds immediately to the next step. A good value for this variable
365 is about 1/3 of the time initialization take in your setup. So if you
366 have a fast machine and no problems with a slow network connection,
367 don't hesitate to set this to 2 seconds. A value of 0 means, don't
368 initialize automatically, but instead wait until routine information is
369 needed, and initialize then."
370 :group 'idlwave-routine-info
371 :type 'number)
373 (defcustom idlwave-scan-all-buffers-for-routine-info t
374 "*Non-nil means, scan buffers for IDL programs when updating info.
375 The scanning is done by the command `idlwave-update-routine-info'.
376 The following values are allowed:
378 nil Don't scan any buffers.
379 t Scan all `idlwave-mode' buffers in the current editing session.
380 current Scan only the current buffer, but no other buffers."
381 :group 'idlwave-routine-info
382 :type '(choice
383 (const :tag "No buffer" nil)
384 (const :tag "All buffers" t)
385 (const :tag "Current buffer only" 'current)))
387 (defcustom idlwave-query-shell-for-routine-info t
388 "*Non-nil means query the shell for info about compiled routines.
389 Querying the shell is useful to get information about compiled modules,
390 and it is turned on by default. However, when you have a complete library
391 scan, this is not necessary."
392 :group 'idlwave-routine-info
393 :type 'boolean)
395 (defcustom idlwave-auto-routine-info-updates
396 '(find-file save-buffer kill-buffer compile-buffer)
397 "*Controls under what circumstances routine info is updated automatically.
398 Possible values:
399 nil Never
400 t All available
401 \(...) A list of circumstances. Allowed members are:
402 find-file Add info for new IDLWAVE buffers.
403 save-buffer Update buffer info when buffer is saved
404 kill-buffer Remove buffer info when buffer gets killed
405 compile-buffer Update shell info after `idlwave-shell-save-and...'"
406 :group 'idlwave-routine-info
407 :type '(choice
408 (const :tag "Never" nil)
409 (const :tag "As often as possible" t)
410 (set :tag "Checklist" :greedy t
411 (const :tag "When visiting a file" find-file)
412 (const :tag "When saving a buffer" save-buffer)
413 (const :tag "After a buffer was killed" kill-buffer)
414 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
416 (defcustom idlwave-rinfo-max-source-lines 5
417 "*Maximum number of source files displayed in the Routine Info window.
418 When an integer, it is the maximum number of source files displayed.
419 A value of t means to show all source files."
420 :group 'idlwave-routine-info
421 :type 'integer)
423 (defcustom idlwave-library-path nil
424 "Library path for Windows and MacOS (OS9). Not needed under UNIX.
425 When selecting the directories to scan for IDL user catalog routine
426 info, IDLWAVE can, under UNIX, query the shell for the exact search
427 path \(the value of !PATH). However, under Windows and MacOS
428 \(pre-OSX), the IDLWAVE shell does not work. In this case, this
429 variable can be set to specify the paths where IDLWAVE can find PRO
430 files. The shell will only be asked for a list of paths when this
431 variable is nil. The value is a list of directories. A directory
432 preceeded by a `+' will be searched recursively. If you set this
433 variable on a UNIX system, the shell will not be queried. See also
434 `idlwave-system-directory'."
435 :group 'idlwave-routine-info
436 :type '(repeat (directory)))
438 (defcustom idlwave-system-directory ""
439 "The IDL system directory for Windows and MacOS. Not needed under
440 UNIX. Set this to the value of the `!DIR' system variable in IDL.
441 IDLWAVE uses this to find out which of the library routines belong to
442 the official system library. All files inside the `lib' subdirectory
443 are considered system library files - so don't install private stuff
444 in this directory. On UNIX systems, IDLWAVE queries the shell for the
445 value of `!DIR'. See also `idlwave-library-path'."
446 :group 'idlwave-routine-info
447 :type 'directory)
449 ;; Configuration files
450 (defcustom idlwave-config-directory
451 (convert-standard-filename "~/.idlwave")
452 "*Directory for configuration files and user-library catalog."
453 :group 'idlwave-routine-info
454 :type 'file)
456 (defvar idlwave-user-catalog-file "idlusercat.el")
457 (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
458 (defvar idlwave-path-file "idlpath.el")
460 (defvar idlwave-libinfo-file nil
461 "*Obsolete variable, no longer used.")
463 (defcustom idlwave-special-lib-alist nil
464 "Alist of regular expressions matching special library directories.
465 When listing routine source locations, IDLWAVE gives a short hint where
466 the file defining the routine is located. By default it lists `SystemLib'
467 for routines in the system library `!DIR/lib' and `Library' for anything
468 else. This variable can define additional types. The car of each entry
469 is a regular expression matching the file name (they normally will match
470 on the path). The cdr is the string to be used as identifier. Max 10
471 chars are allowed."
472 :group 'idlwave-routine-info
473 :type '(repeat
474 (cons regexp string)))
476 (defcustom idlwave-auto-write-paths t
477 "Write out path (!PATH) and system directory (!DIR) info automatically.
478 Path info is needed to locate library catalog files. If non-nil,
479 whenever the path-list changes as a result of shell-query, etc., it is
480 written to file. Otherwise, the menu option \"Write Paths\" can be
481 used to force a write."
482 :group 'idlwave-routine-info
483 :type 'boolean)
485 (defgroup idlwave-completion nil
486 "Completion options for IDLWAVE mode."
487 :prefix "idlwave"
488 :group 'idlwave)
490 (eval-and-compile
491 (defconst idlwave-tmp
492 '(choice :tag "by applying the function"
493 (const upcase)
494 (const downcase)
495 (const capitalize)
496 (const preserve)
497 (symbol :tag "Other"))))
499 (defcustom idlwave-completion-case '((routine . upcase)
500 (keyword . upcase)
501 (class . preserve)
502 (method . preserve))
503 "Association list setting the case of completed words.
505 This variable determines the case (UPPER/lower/Capitalized...) of
506 words inserted into the buffer by completion. The preferred case can
507 be specified separately for routine names, keywords, classes and
508 methods.
509 This alist should therefore have entries for `routine' (normal
510 functions and procedures, i.e. non-methods), `keyword', `class', and
511 `method'. Plausible values are
513 upcase upcase whole word, like `BOX_CURSOR'
514 downcase downcase whole word, like `read_ppm'
515 capitalize capitalize each part, like `Widget_Control'
516 preserve preserve case as is, like `IDLgrView'
518 The value can also be any Emacs Lisp function which transforms the
519 case of characters in a string.
521 A value of `preserve' means that the case of the completed word is
522 identical to the way it was written in the definition statement of the
523 routine. This was implemented to allow for mixed-case completion, in
524 particular of object classes and methods.
525 If a completable word is defined in multiple locations, the meaning of
526 `preserve' is not unique since the different definitions might be
527 cased differently. Therefore IDLWAVE always takes the case of the
528 *first* definition it encounters during routine info collection and
529 uses the case derived from it consistently.
531 Note that a lowercase-only string in the buffer will always be completed in
532 lower case (but see the variable `idlwave-completion-force-default-case').
534 After changing this variable, you need to either restart Emacs or press
535 `C-u C-c C-i' to update the internal lists."
536 :group 'idlwave-completion
537 :type `(repeat
538 (cons (symbol :tag "Derive completion case for")
539 ,idlwave-tmp)))
541 (defcustom idlwave-completion-force-default-case nil
542 "*Non-nil means, completion will always honor `idlwave-completion-case'.
543 When nil, only the completion of a mixed case or upper case string
544 will honor the default settings in `idlwave-completion-case', while
545 the completion of lower case strings will be completed entirely in
546 lower case."
547 :group 'idlwave-completion
548 :type 'boolean)
550 (defcustom idlwave-complete-empty-string-as-lower-case nil
551 "*Non-nil means, the empty string is considered downcase for completion.
552 The case of what is already in the buffer determines the case of completions.
553 When this variable is non-nil, the empty string is considered to be downcase.
554 Completing on the empty string then offers downcase versions of the possible
555 completions."
556 :group 'idlwave-completion
557 :type 'boolean)
559 (defvar idlwave-default-completion-case-is-down nil
560 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
561 `idlwave-completion-case'.")
563 (defcustom idlwave-buffer-case-takes-precedence nil
564 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
565 To make this possible, we need to re-case everything each time we update
566 the routine info from the buffers. This is slow.
567 The default is to consider the case given in the system and library files
568 first which makes updating much faster."
569 :group 'idlwave-completion
570 :type 'boolean)
572 (defcustom idlwave-highlight-help-links-in-completion t
573 "*Non-nil means, highlight completions for which system help is available.
574 Help can then be accessed with mouse-3.
575 This option is only effective when the online help system is installed."
576 :group 'idlwave-completion
577 :type 'boolean)
579 (defcustom idlwave-support-inheritance t
580 "Non-nil means, treat inheritance with completion, online help etc.
581 When nil, IDLWAVE only knows about the native methods and tags of a class,
582 not about inherited ones."
583 :group 'idlwave-routine-info
584 :type 'boolean)
586 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
587 "List of regular expressions for class-driven keyword inheritance.
588 Keyword inheritance is often tied to class inheritance by \"chaining\"
589 up the class tree. While it cannot be assumed that the presence of an
590 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
591 certain methods this assumption is almost always true. The methods
592 for which to assume this can be set here."
593 :group 'idlwave-routine-info
594 :type '(repeat (regexp :tag "Match method:")))
597 (defcustom idlwave-completion-show-classes 1
598 "*Number of classes to show when completing object methods and keywords.
599 When completing methods or keywords for an object with unknown class,
600 the *Completions* buffer will show the valid classes for each completion
601 like this:
603 MyMethod <Class1,Class2,Class3>
605 The value of this variable may be nil to inhibit display, or an integer to
606 indicate the maximum number of classes to display.
608 On XEmacs, a full list of classes will also be placed into a `help-echo'
609 property on the competion items, so that the list of classes for the current
610 item is displayed in the echo area. If the value of this variable is a
611 negative integer, the `help-echo' property will be suppressed."
612 :group 'idlwave-completion
613 :type '(choice (const :tag "Don't show" nil)
614 (integer :tag "Number of classes shown" 1)))
616 (defcustom idlwave-completion-fontify-classes t
617 "*Non-nil means, fontify the classes in completions buffer.
618 This makes it easier to distinguish the completion items from the extra
619 class info listed. See `idlwave-completion-show-classes'."
620 :group 'idlwave-completion
621 :type 'boolean)
623 (defcustom idlwave-query-class '((method-default . nil)
624 (keyword-default . nil))
625 "Association list governing specification of object classes for completion.
627 When IDLWAVE tries to complete object-oriented methods, it usually
628 cannot determine the class of a given object from context. In order
629 to provide the user with a correct list of methods or keywords, it
630 needs to determine the appropriate class. IDLWAVE has two ways of
631 doing this (well, three ways if you count the shell... see
632 `idlwave-shell-query-for-class'):
634 1. Combine the items of all available classes which contain this
635 method for the purpose of completion. So when completing a method,
636 all methods of all known classes are available, and when completing
637 a keyword, all keywords allowed for this method in any class are
638 shown. This behavior is very much like normal completion and is
639 therefore the default. It works much better than one might think -
640 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
641 become uncomfortably long. See also
642 `idlwave-completion-show-classes'.
644 2. The second possibility is to ask the user on each occasion. To
645 make this less interruptive, IDLWAVE can store the class as a text
646 property on the object operator `->'. For a given object in the
647 source code, class selection will then be needed only once
648 - for example to complete the method. Keywords to the method can
649 then be completed directly, because the class is already known.
650 You will have to turn on the storage of the selected class
651 explicitly with the variable `idlwave-store-inquired-class'.
653 This variable allows you to configure IDLWAVE's method and
654 method-keyword completion behavior. Its value is an alist, which
655 should contain at least two elements: (method-default . VALUE) and
656 \(keyword-default . VALUE), where VALUE is either t or nil. These
657 specify if the class should be found during method and keyword
658 completion, respectively.
660 The alist may have additional entries specifying exceptions from the
661 keyword completion rule for specific methods, like INIT or
662 GETPROPERTY. In order to turn on class specification for the INIT
663 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
664 :group 'idlwave-completion
665 :type '(list
666 (cons (const method-default)
667 (boolean :tag "Determine class when completing METHODS "))
668 (cons (const keyword-default)
669 (boolean :tag "Determine class when completing KEYWORDS "))
670 (repeat
671 :tag "Exceptions to defaults"
672 :inline t
673 (cons (string :tag "MODULE" :value "")
674 (boolean :tag "Determine class for this method")))))
676 (defcustom idlwave-store-inquired-class t
677 "*Non-nil means, store class of a method call as text property on `->'.
678 IDLWAVE sometimes has to ask the user for the class associated with a
679 particular object method call. This happens during the commands
680 `idlwave-routine-info' and `idlwave-complete', depending upon the
681 value of the variable `idlwave-query-class'.
683 When you specify a class, this information can be stored as a text
684 property on the `->' arrow in the source code, so that during the same
685 editing session, IDLWAVE will not have to ask again. When this
686 variable is non-nil, IDLWAVE will store and reuse the class information.
687 The class stored can be checked and removed with `\\[idlwave-routine-info]'
688 on the arrow.
690 The default of this variable is nil, since the result of commands then
691 is more predictable. However, if you know what you are doing, it can
692 be nice to turn this on.
694 An arrow which knows the class will be highlighted with
695 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
696 displays (with prefix arg: deletes) the class stored on the arrow
697 at point."
698 :group 'idlwave-completion
699 :type 'boolean)
701 (defcustom idlwave-class-arrow-face 'bold
702 "*Face to highlight object operator arrows `->' which carry a class property.
703 When IDLWAVE stores a class name as text property on an object arrow
704 \(see variable `idlwave-store-inquired-class', it highlights the arrow
705 with this font in order to remind the user that this arrow is special."
706 :group 'idlwave-completion
707 :type 'symbol)
709 (defcustom idlwave-resize-routine-help-window t
710 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
711 :group 'idlwave-completion
712 :type 'boolean)
714 (defcustom idlwave-keyword-completion-adds-equal t
715 "*Non-nil means, completion automatically adds `=' after completed keywords."
716 :group 'idlwave-completion
717 :type 'boolean)
719 (defcustom idlwave-function-completion-adds-paren t
720 "*Non-nil means, completion automatically adds `(' after completed function.
721 nil means, don't add anything.
722 A value of `2' means, also add the closing parenthesis and position cursor
723 between the two."
724 :group 'idlwave-completion
725 :type '(choice (const :tag "Nothing" nil)
726 (const :tag "(" t)
727 (const :tag "()" 2)))
729 (defcustom idlwave-completion-restore-window-configuration t
730 "*Non-nil means, try to restore the window configuration after completion.
731 When completion is not unique, Emacs displays a list of completions.
732 This messes up your window configuration. With this variable set, IDLWAVE
733 restores the old configuration after successful completion."
734 :group 'idlwave-completion
735 :type 'boolean)
737 ;;; Variables for abbrev and action behavior -----------------------------
739 (defgroup idlwave-abbrev-and-indent-action nil
740 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
741 The variables in this group govern this."
742 :group 'idlwave)
744 (defcustom idlwave-do-actions nil
745 "*Non-nil means performs actions when indenting.
746 The actions that can be performed are listed in `idlwave-indent-action-table'."
747 :group 'idlwave-abbrev-and-indent-action
748 :type 'boolean)
750 (defcustom idlwave-abbrev-start-char "\\"
751 "*A single character string used to start abbreviations in abbrev mode.
752 Possible characters to chose from: ~`\%
753 or even '?'. '.' is not a good choice because it can make structure
754 field names act like abbrevs in certain circumstances.
756 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
757 must set it directly using `setq' in the .emacs file before idlwave.el
758 is loaded."
759 :group 'idlwave-abbrev-and-indent-action
760 :type 'string)
762 (defcustom idlwave-surround-by-blank nil
763 "*Non-nil means, enable `idlwave-surround'.
764 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
765 `idlwave-surround'.
766 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
768 Also see the default key bindings for keys using `idlwave-surround'.
769 Keys are bound and made into actions calling `idlwave-surround' with
770 `idlwave-action-and-binding'.
771 See help for `idlwave-action-and-binding' for examples.
773 Also see help for `idlwave-surround'."
774 :group 'idlwave-abbrev-and-indent-action
775 :type 'boolean)
777 (defcustom idlwave-pad-keyword t
778 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
779 Whenever `idlwave-surround' is non-nil then this affects how '=' is
780 padded for keywords and for variables. If t, pad the same as for
781 assignments. If nil then spaces are removed. With any other value,
782 spaces are left unchanged."
783 :group 'idlwave-abbrev-and-indent-action
784 :type '(choice
785 (const :tag "Pad like assignments" t)
786 (const :tag "Remove space near `='" nil)
787 (const :tag "Keep space near `='" 'keep)))
789 (defcustom idlwave-show-block t
790 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
791 :group 'idlwave-abbrev-and-indent-action
792 :type 'boolean)
794 (defcustom idlwave-expand-generic-end nil
795 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
796 :group 'idlwave-abbrev-and-indent-action
797 :type 'boolean)
799 (defcustom idlwave-reindent-end t
800 "*Non-nil means re-indent line after END was typed."
801 :group 'idlwave-abbrev-and-indent-action
802 :type 'boolean)
804 (defcustom idlwave-abbrev-move t
805 "*Non-nil means the abbrev hook can move point.
806 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
807 definitions, use the command `list-abbrevs', for abbrevs that move
808 point. Moving point is useful, for example, to place point between
809 parentheses of expanded functions.
811 See `idlwave-check-abbrev'."
812 :group 'idlwave-abbrev-and-indent-action
813 :type 'boolean)
815 (defcustom idlwave-abbrev-change-case nil
816 "*Non-nil means all abbrevs will be forced to either upper or lower case.
817 If the value t, all expanded abbrevs will be upper case.
818 If the value is 'down then abbrevs will be forced to lower case.
819 If nil, the case will not change.
820 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
821 upper case, regardless of this variable."
822 :group 'idlwave-abbrev-and-indent-action
823 :type 'boolean)
825 (defcustom idlwave-reserved-word-upcase nil
826 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
827 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
828 Has effect only if in abbrev-mode."
829 :group 'idlwave-abbrev-and-indent-action
830 :type 'boolean)
832 ;;; Action/Expand Tables.
834 ;; The average user may have difficulty modifying this directly. It
835 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
836 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
837 ;; examples of how to add an action.
839 ;; The action table is used by `idlwave-indent-line' whereas both the
840 ;; action and expand tables are used by `idlwave-indent-and-action'. In
841 ;; general, the expand table is only used when a line is explicitly
842 ;; indented. Whereas, in addition to being used when the expand table
843 ;; is used, the action table is used when a line is indirectly
844 ;; indented via line splitting, auto-filling or a new line creation.
846 ;; Example actions:
848 ;; Capitalize system vars
849 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
851 ;; Capitalize procedure name
852 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
853 ;; '(capitalize-word 1) t)
855 ;; Capitalize common block name
856 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
857 ;; '(capitalize-word 1) t)
858 ;; Capitalize label
859 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
860 ;; '(capitalize-word -1) t)
862 (defvar idlwave-indent-action-table nil
863 "*Associated array containing action lists of search string (car),
864 and function as a cdr. This table is used by `idlwave-indent-line'.
865 See documentation for `idlwave-do-action' for a complete description of
866 the action lists.
868 Additions to the table are made with `idlwave-action-and-binding' when a
869 binding is not requested.
870 See help on `idlwave-action-and-binding' for examples.")
872 (defvar idlwave-indent-expand-table nil
873 "*Associated array containing action lists of search string (car),
874 and function as a cdr. The table is used by the
875 `idlwave-indent-and-action' function. See documentation for
876 `idlwave-do-action' for a complete description of the action lists.
878 Additions to the table are made with `idlwave-action-and-binding' when a
879 binding is requested.
880 See help on `idlwave-action-and-binding' for examples.")
882 ;;; Documentation header and history keyword ---------------------------------
884 (defgroup idlwave-documentation nil
885 "Options for documenting IDLWAVE files."
886 :group 'idlwave)
888 ;; FIXME: make defcustom?
889 (defvar idlwave-file-header
890 (list nil
892 ; NAME:
896 ; PURPOSE:
900 ; CATEGORY:
904 ; CALLING SEQUENCE:
908 ; INPUTS:
912 ; OPTIONAL INPUTS:
916 ; KEYWORD PARAMETERS:
920 ; OUTPUTS:
924 ; OPTIONAL OUTPUTS:
928 ; COMMON BLOCKS:
932 ; SIDE EFFECTS:
936 ; RESTRICTIONS:
940 ; PROCEDURE:
944 ; EXAMPLE:
948 ; MODIFICATION HISTORY:
952 "*A list (PATHNAME STRING) specifying the doc-header template to use for
953 summarizing a file. If PATHNAME is non-nil then this file will be included.
954 Otherwise STRING is used. If nil, the file summary will be omitted.
955 For example you might set PATHNAME to the path for the
956 lib_template.pro file included in the IDL distribution.")
958 (defcustom idlwave-header-to-beginning-of-file t
959 "*Non-nil means, the documentation header will always be at start of file.
960 When nil, the header is positioned between the PRO/FUNCTION line of
961 the current routine and the code, allowing several routine headers in
962 a file."
963 :group 'idlwave-documentation
964 :type 'boolean)
966 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
967 "*The hook function used to update the timestamp of a function."
968 :group 'idlwave-documentation
969 :type 'function)
971 (defcustom idlwave-doc-modifications-keyword "HISTORY"
972 "*The modifications keyword to use with the log documentation commands.
973 A ':' is added to the keyword end.
974 Inserted by doc-header and used to position logs by doc-modification.
975 If nil it will not be inserted."
976 :group 'idlwave-documentation
977 :type 'string)
979 (defcustom idlwave-doclib-start "^;+\\+"
980 "*Regexp matching the start of a document library header."
981 :group 'idlwave-documentation
982 :type 'regexp)
984 (defcustom idlwave-doclib-end "^;+-"
985 "*Regexp matching the end of a document library header."
986 :group 'idlwave-documentation
987 :type 'regexp)
989 ;;; External Programs -------------------------------------------------------
991 (defgroup idlwave-external-programs nil
992 "Path locations of external commands used by IDLWAVE."
993 :group 'idlwave)
995 (defcustom idlwave-shell-explicit-file-name "idl"
996 "*If non-nil, this is the command to run IDL.
997 Should be an absolute file path or path relative to the current environment
998 execution search path. If you want to specify command line switches
999 for the IDL program, use `idlwave-shell-command-line-options'.
1001 I know the name of this variable is badly chosen, but I cannot change
1002 it without compromising backwards-compatibility."
1003 :group 'idlwave-external-programs
1004 :type 'string)
1006 (defcustom idlwave-shell-command-line-options nil
1007 "*A list of command line options for calling the IDL program.
1008 Since IDL is executed directly without going through a shell like /bin/sh,
1009 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1010 string for each argument. But you may also give a single string which
1011 contains the options whitespace-separated. Emacs will be kind enough to
1012 split it for you."
1013 :type '(choice
1014 string
1015 (repeat (string :value "")))
1016 :group 'idlwave-external-programs)
1018 (defcustom idlwave-help-application "idlhelp"
1019 "*The external application providing reference help for programming.
1020 Obsolete, if the IDL Assistant is being used for help."
1021 :group 'idlwave-external-programs
1022 :type 'string)
1024 ;;; Some Shell variables which must be defined here.-----------------------
1026 (defcustom idlwave-shell-debug-modifiers '()
1027 "List of modifiers to be used for the debugging commands.
1028 Will be used to bind debugging commands in the shell buffer and in all
1029 source buffers. These are additional convenience bindings, the debugging
1030 commands are always available with the `C-c C-d' prefix.
1031 If you set this to '(control shift), this means setting a breakpoint will
1032 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1033 are `control', `meta', `super', `hyper', `alt', and `shift'."
1034 :group 'idlwave-shell-general-setup
1035 :type '(set :tag "Specify modifiers"
1036 (const control)
1037 (const meta)
1038 (const super)
1039 (const hyper)
1040 (const alt)
1041 (const shift)))
1043 (defcustom idlwave-shell-automatic-start nil
1044 "*If non-nil attempt invoke `idlwave-shell' if not already running.
1045 This is checked when an attempt to send a command to an
1046 IDL process is made."
1047 :group 'idlwave-shell-general-setup
1048 :type 'boolean)
1050 ;;; Miscellaneous variables -------------------------------------------------
1052 (defgroup idlwave-misc nil
1053 "Miscellaneous options for IDLWAVE mode."
1054 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
1055 :group 'idlwave)
1057 (defcustom idlwave-startup-message t
1058 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1059 :group 'idlwave-misc
1060 :type 'boolean)
1062 (defcustom idlwave-default-font-lock-items
1063 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1064 common-blocks class-arrows)
1065 "Items which should be fontified on the default fontification level 2.
1066 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1067 is everything and level 2 is specified by this list.
1068 This variable must be set before IDLWAVE gets loaded.
1069 It is a list of symbols; the following symbols are allowed:
1071 pros-and-functions Procedure and Function definitions
1072 batch-files Batch Files
1073 idlwave-idl-keywords IDL Keywords
1074 label Statement Labels
1075 goto Goto Statements
1076 common-blocks Common Blocks
1077 keyword-parameters Keyword Parameters in routine definitions and calls
1078 system-variables System Variables
1079 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1080 class-arrows Object Arrows with class property"
1081 :group 'idlwave-misc
1082 :type '(set
1083 :inline t :greedy t
1084 (const :tag "Procedure and Function definitions" pros-and-functions)
1085 (const :tag "Batch Files" batch-files)
1086 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1087 (const :tag "Statement Labels" label)
1088 (const :tag "Goto Statements" goto)
1089 (const :tag "Tags in Structure Definition" structtag)
1090 (const :tag "Structure Name" structname)
1091 (const :tag "Common Blocks" common-blocks)
1092 (const :tag "Keyword Parameters" keyword-parameters)
1093 (const :tag "System Variables" system-variables)
1094 (const :tag "FIXME: Warning" fixme)
1095 (const :tag "Object Arrows with class property " class-arrows)))
1097 (defcustom idlwave-mode-hook nil
1098 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1099 :group 'idlwave-misc
1100 :type 'hook)
1102 (defcustom idlwave-load-hook nil
1103 "Normal hook. Executed when idlwave.el is loaded."
1104 :group 'idlwave-misc
1105 :type 'hook)
1107 (defvar idlwave-experimental nil
1108 "Non-nil means turn on a few experimental features.
1109 This variable is only for the maintainer, to test difficult stuff,
1110 while still distributing stable releases.
1111 As a user, you should not set this to t.")
1114 ;;; End customization variables section
1117 ;;; Non customization variables
1119 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1120 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1121 ;;; and Carsten Dominik...
1123 ;; The following are the reserved words in IDL. Maybe we should
1124 ;; highlight some more stuff as well?
1125 ;; Procedure declarations. Fontify keyword plus procedure name.
1126 (defvar idlwave-idl-keywords
1127 ;; To update this regexp, update the list of keywords and
1128 ;; evaluate the form.
1129 ;; (insert
1130 ;; (prin1-to-string
1131 ;; (concat
1132 ;; "\\<\\("
1133 ;; (regexp-opt
1134 ;; '("||" "&&" "and" "or" "xor" "not"
1135 ;; "eq" "ge" "gt" "le" "lt" "ne"
1136 ;; "for" "do" "endfor"
1137 ;; "if" "then" "endif" "else" "endelse"
1138 ;; "case" "of" "endcase"
1139 ;; "switch" "break" "continue" "endswitch"
1140 ;; "begin" "end"
1141 ;; "repeat" "until" "endrep"
1142 ;; "while" "endwhile"
1143 ;; "goto" "return"
1144 ;; "inherits" "mod"
1145 ;; "compile_opt" "forward_function"
1146 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1147 ;; "\\)\\>")))
1148 "\\<\\(&&\\|and\\|b\\(egin\\|reak\\)\\|c\\(ase\\|o\\(mpile_opt\\|ntinue\\)\\)\\|do\\|e\\(lse\\|nd\\(case\\|else\\|for\\|if\\|rep\\|switch\\|while\\)?\\|q\\)\\|for\\(ward_function\\)?\\|g\\(oto\\|[et]\\)\\|i\\(f\\|nherits\\)\\|l[et]\\|mod\\|n\\(e\\|ot\\)\\|o\\(n_\\(error\\|ioerror\\)\\|[fr]\\)\\|re\\(peat\\|turn\\)\\|switch\\|then\\|until\\|while\\|xor\\|||\\)\\>")
1151 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1152 ;; Function declarations. Fontify keyword plus function name.
1153 (pros-and-functions
1154 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1155 (1 font-lock-keyword-face)
1156 (2 font-lock-function-name-face nil t)))
1158 ;; Common blocks
1159 (common-blocks
1160 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1161 (1 font-lock-keyword-face) ; "common"
1162 (2 font-lock-reference-face nil t) ; block name
1163 ("[ \t]*\\(\\sw+\\)[ ,]*"
1164 ;; Start with point after block name and comma
1165 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1167 (1 font-lock-variable-name-face) ; variable names
1170 ;; Batch files
1171 (batch-files
1172 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1174 ;; FIXME warning.
1175 (fixme
1176 '("\\<FIXME:" (0 font-lock-warning-face t)))
1178 ;; Labels
1179 (label
1180 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1182 ;; The goto statement and its label
1183 (goto
1184 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1185 (1 font-lock-keyword-face)
1186 (2 font-lock-reference-face)))
1188 ;; Tags in structure definitions. Note that this definition
1189 ;; actually collides with labels, so we have to use the same
1190 ;; face. It also matches named subscript ranges,
1191 ;; e.g. vec{bottom:top]. No good way around this.
1192 (structtag
1193 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1195 ;; Structure names
1196 (structname
1197 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1198 (2 font-lock-function-name-face)))
1200 ;; Keyword parameters, like /xlog or ,xrange=[]
1201 ;; This is anchored to the comma preceeding the keyword.
1202 ;; Treats continuation lines, works only during whole buffer
1203 ;; fontification. Slow, use it only in fancy fontification.
1204 (keyword-parameters
1205 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1206 (6 font-lock-reference-face)))
1208 ;; System variables start with a bang.
1209 (system-variables
1210 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1211 (1 font-lock-variable-name-face)))
1213 ;; Special and unusual operators (not used because too noisy)
1214 ;; (special-operators
1215 ;; '("[<>#]" (0 font-lock-keyword-face)))
1217 ;; All operators (not used because too noisy)
1218 ;; (all-operators
1219 ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1221 ;; Arrows with text property `idlwave-class'
1222 (class-arrows
1223 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1225 (defconst idlwave-font-lock-keywords-1
1226 (list pros-and-functions batch-files)
1227 "Subdued level highlighting for IDLWAVE mode.")
1229 (defconst idlwave-font-lock-keywords-2
1230 (mapcar 'symbol-value idlwave-default-font-lock-items)
1231 "Medium level highlighting for IDLWAVE mode.")
1233 (defconst idlwave-font-lock-keywords-3
1234 (list pros-and-functions
1235 batch-files
1236 idlwave-idl-keywords
1237 label goto
1238 structtag
1239 structname
1240 common-blocks
1241 keyword-parameters
1242 system-variables
1243 class-arrows)
1244 "Gaudy level highlighting for IDLWAVE mode."))
1246 (defun idlwave-match-class-arrows (limit)
1247 ;; Match an object arrow with class property
1248 (and idlwave-store-inquired-class
1249 (re-search-forward "->" limit 'limit)
1250 (get-text-property (match-beginning 0) 'idlwave-class)))
1252 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1253 "Default expressions to highlight in IDLWAVE mode.")
1255 (defvar idlwave-font-lock-defaults
1256 '((idlwave-font-lock-keywords
1257 idlwave-font-lock-keywords-1
1258 idlwave-font-lock-keywords-2
1259 idlwave-font-lock-keywords-3)
1260 nil t
1261 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
1262 beginning-of-line))
1264 (put 'idlwave-mode 'font-lock-defaults
1265 idlwave-font-lock-defaults) ; XEmacs
1267 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1268 "Regexp to match the start of a full-line comment.
1269 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1270 only by whitespace.")
1272 (defconst idlwave-begin-block-reg
1273 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1274 "Regular expression to find the beginning of a block.
1275 The case does not matter. The search skips matches in comments.")
1277 (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1278 "Regular expression to find the beginning of a unit.
1279 The case does not matter.")
1281 (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1282 "Regular expression to find the line that indicates the end of unit.
1283 This line is the end of buffer or the start of another unit.
1284 The case does not matter. The search skips matches in comments.")
1286 (defconst idlwave-continue-line-reg "\\<\\$"
1287 "Regular expression to match a continued line.")
1289 (defconst idlwave-end-block-reg
1290 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1291 "Regular expression to find the end of a block.
1292 The case does not matter. The search skips matches in comments.")
1294 (defconst idlwave-block-matches
1295 '(("pro" . "end")
1296 ("function" . "end")
1297 ("case" . "endcase")
1298 ("else" . "endelse")
1299 ("for" . "endfor")
1300 ("then" . "endif")
1301 ("repeat" . "endrep")
1302 ("switch" . "endswitch")
1303 ("while" . "endwhile"))
1304 "Matches between statements and the corresponding END variant.
1305 The cars are the reserved words starting a block. If the block really
1306 begins with BEGIN, the cars are the reserved words before the begin
1307 which can be used to identify the block type.
1308 This is used to check for the correct END type, to close blocks and
1309 to expand generic end statements to their detailed form.")
1311 (defconst idlwave-block-match-regexp
1312 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1313 "Regular expression matching reserved words which can stand before
1314 blocks starting with a BEGIN statement. The matches must have associations
1315 `idlwave-block-matches'.")
1317 (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
1318 "Regular expression matching an IDL identifier.")
1320 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1321 "Regular expression matching IDL system variables.")
1323 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1324 "Regular expression matching IDL variable names.")
1326 (defconst idlwave-label (concat idlwave-identifier ":")
1327 "Regular expression matching IDL labels.")
1329 (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1330 "\\(\\s *" idlwave-identifier "::\\)?"
1333 (defconst idlwave-statement-match
1334 (list
1335 ;; "endif else" is the only possible "end" that can be
1336 ;; followed by a statement on the same line.
1337 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1338 ;; all other "end"s can not be followed by a statement.
1339 (cons 'end (list idlwave-end-block-reg nil))
1340 '(if . ("if\\>" "then"))
1341 '(for . ("for\\>" "do"))
1342 '(begin . ("begin\\>" nil))
1343 '(pdef . ("pro\\>\\|function\\>" nil))
1344 '(while . ("while\\>" "do"))
1345 '(repeat . ("repeat\\>" "repeat"))
1346 '(goto . ("goto\\>" nil))
1347 '(case . ("case\\>" nil))
1348 '(switch . ("switch\\>" nil))
1349 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
1350 "\\(" idlwave-method-call "\\s *\\)?"
1351 idlwave-identifier
1352 "\\s *(") nil))
1353 (cons 'call (list (concat
1354 "\\(" idlwave-method-call "\\s *\\)?"
1355 idlwave-identifier
1356 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
1357 (cons 'assign (list (concat
1358 "\\(" idlwave-variable "\\) *=") nil)))
1360 "Associated list of statement matching regular expressions.
1361 Each regular expression matches the start of an IDL statement.
1362 The first element of each association is a symbol giving the statement
1363 type. The associated value is a list. The first element of this list
1364 is a regular expression matching the start of an IDL statement for
1365 identifying the statement type. The second element of this list is a
1366 regular expression for finding a substatement for the type. The
1367 substatement starts after the end of the found match modulo
1368 whitespace. If it is nil then the statement has no substatement. The
1369 list order matters since matching an assignment statement exactly is
1370 not possible without parsing. Thus assignment statement become just
1371 the leftover unidentified statements containing an equal sign.")
1373 ;; FIXME: This var seems to only ever be set, but never actually used!
1374 (defvar idlwave-fill-function 'auto-fill-function
1375 "IDL mode auto fill function.")
1377 (defvar idlwave-comment-indent-function 'comment-indent-function
1378 "IDL mode comment indent function.")
1380 ;; Note that this is documented in the v18 manuals as being a string
1381 ;; of length one rather than a single character.
1382 ;; The code in this file accepts either format for compatibility.
1383 (defvar idlwave-comment-indent-char ?\
1384 "Character to be inserted for IDL comment indentation.
1385 Normally a space.")
1387 (defconst idlwave-continuation-char ?$
1388 "Character which is inserted as a last character on previous line by
1389 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1391 (defconst idlwave-mode-version "6.1_em22")
1393 (defmacro idlwave-keyword-abbrev (&rest args)
1394 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1395 `(quote (lambda ()
1396 ,(append '(idlwave-check-abbrev) args))))
1398 ;; If I take the time I can replace idlwave-keyword-abbrev with
1399 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1400 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1401 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1402 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1404 (defmacro idlwave-code-abbrev (&rest args)
1405 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1406 Specifically, if the abbrev is in a comment or string it is unexpanded.
1407 Otherwise ARGS forms a list that is evaluated."
1408 ;; FIXME: it would probably be better to rely on the new :enable-function
1409 ;; to enforce the "don't expand in comments or strings".
1410 `(lambda ()
1411 ,(prin1-to-string args) ;; Puts the code in the doc string
1412 (if (idlwave-quoted)
1413 (progn (unexpand-abbrev) nil)
1414 ,(append args))))
1416 (autoload 'idlwave-shell "idlw-shell"
1417 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1418 (autoload 'idlwave-shell-send-command "idlw-shell")
1419 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1420 "Run `idlwave-shell' and switch back to current window" t)
1421 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1422 "Save and run buffer under the shell." t)
1423 (autoload 'idlwave-shell-break-here "idlw-shell"
1424 "Set breakpoint in current line." t)
1425 (autoload 'idlwave-shell-run-region "idlw-shell"
1426 "Compile and run the region." t)
1428 (fset 'idlwave-debug-map (make-sparse-keymap))
1430 (defvar idlwave-mode-map
1431 (let ((map (make-sparse-keymap)))
1432 (define-key map "\C-c " 'idlwave-hard-tab)
1433 (define-key map [(control tab)] 'idlwave-hard-tab)
1434 ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
1435 (define-key map "'" 'idlwave-show-matching-quote)
1436 (define-key map "\"" 'idlwave-show-matching-quote)
1437 (define-key map "\C-g" 'idlwave-keyboard-quit)
1438 (define-key map "\C-c;" 'idlwave-toggle-comment-region)
1439 (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1440 (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
1441 (define-key map "\C-c{" 'idlwave-beginning-of-block)
1442 (define-key map "\C-c}" 'idlwave-end-of-block)
1443 (define-key map "\C-c]" 'idlwave-close-block)
1444 (define-key map [(meta control h)] 'idlwave-mark-subprogram)
1445 (define-key map "\M-\C-n" 'idlwave-forward-block)
1446 (define-key map "\M-\C-p" 'idlwave-backward-block)
1447 (define-key map "\M-\C-d" 'idlwave-down-block)
1448 (define-key map "\M-\C-u" 'idlwave-backward-up-block)
1449 (define-key map "\M-\r" 'idlwave-split-line)
1450 (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
1451 (define-key map "\C-c\C-p" 'idlwave-previous-statement)
1452 (define-key map "\C-c\C-n" 'idlwave-next-statement)
1453 ;; (define-key map "\r" 'idlwave-newline)
1454 ;; (define-key map "\t" 'idlwave-indent-line)
1455 (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
1456 (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
1457 (define-key map "\M-q" 'idlwave-fill-paragraph)
1458 (define-key map "\M-s" 'idlwave-edit-in-idlde)
1459 (define-key map "\C-c\C-h" 'idlwave-doc-header)
1460 (define-key map "\C-c\C-m" 'idlwave-doc-modification)
1461 (define-key map "\C-c\C-c" 'idlwave-case)
1462 (define-key map "\C-c\C-d" 'idlwave-debug-map)
1463 (when (and (listp idlwave-shell-debug-modifiers)
1464 (not (equal idlwave-shell-debug-modifiers '())))
1465 ;; Bind the debug commands also with the special modifiers.
1466 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1467 (mods-noshift
1468 (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
1469 (define-key map
1470 (vector (append mods-noshift (list (if shift ?C ?c))))
1471 'idlwave-shell-save-and-run)
1472 (define-key map
1473 (vector (append mods-noshift (list (if shift ?B ?b))))
1474 'idlwave-shell-break-here)
1475 (define-key map
1476 (vector (append mods-noshift (list (if shift ?E ?e))))
1477 'idlwave-shell-run-region)))
1478 (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1479 (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1480 (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1481 (define-key map "\C-c\C-f" 'idlwave-for)
1482 ;; (define-key map "\C-c\C-f" 'idlwave-function)
1483 ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
1484 (define-key map "\C-c\C-r" 'idlwave-repeat)
1485 (define-key map "\C-c\C-w" 'idlwave-while)
1486 (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1487 (define-key map "\C-c\C-s" 'idlwave-shell)
1488 (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1489 (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1490 (define-key map "\C-c\C-v" 'idlwave-find-module)
1491 (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
1492 (define-key map "\C-c?" 'idlwave-routine-info)
1493 (define-key map "\M-?" 'idlwave-context-help)
1494 (define-key map [(control meta ?\?)]
1495 'idlwave-help-assistant-help-with-topic)
1496 ;; Pickup both forms of Esc/Meta binding
1497 (define-key map [(meta tab)] 'idlwave-complete)
1498 (define-key map [?\e?\t] 'idlwave-complete)
1499 (define-key map "\M-\C-i" 'idlwave-complete)
1500 (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
1501 (define-key map "\C-c=" 'idlwave-resolve)
1502 (define-key map
1503 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1504 'idlwave-mouse-context-help)
1505 map)
1506 "Keymap used in IDL mode.")
1508 (defvar idlwave-mode-syntax-table
1509 (let ((st (make-syntax-table)))
1510 (modify-syntax-entry ?+ "." st)
1511 (modify-syntax-entry ?- "." st)
1512 (modify-syntax-entry ?* "." st)
1513 (modify-syntax-entry ?/ "." st)
1514 (modify-syntax-entry ?^ "." st)
1515 (modify-syntax-entry ?# "." st)
1516 (modify-syntax-entry ?= "." st)
1517 (modify-syntax-entry ?% "." st)
1518 (modify-syntax-entry ?< "." st)
1519 (modify-syntax-entry ?> "." st)
1520 (modify-syntax-entry ?\' "\"" st)
1521 (modify-syntax-entry ?\" "\"" st)
1522 (modify-syntax-entry ?\\ "." st)
1523 (modify-syntax-entry ?_ "_" st)
1524 (modify-syntax-entry ?{ "(}" st)
1525 (modify-syntax-entry ?} "){" st)
1526 (modify-syntax-entry ?$ "_" st)
1527 (modify-syntax-entry ?. "." st)
1528 (modify-syntax-entry ?\; "<" st)
1529 (modify-syntax-entry ?\n ">" st)
1530 (modify-syntax-entry ?\f ">" st)
1532 "Syntax table in use in `idlwave-mode' buffers.")
1534 (defvar idlwave-find-symbol-syntax-table
1535 (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
1536 (modify-syntax-entry ?$ "w" st)
1537 (modify-syntax-entry ?_ "w" st)
1538 (modify-syntax-entry ?! "w" st)
1539 (modify-syntax-entry ?. "w" st)
1541 "Syntax table that treats symbol characters as word characters.")
1543 (defmacro idlwave-with-special-syntax (&rest body)
1544 "Execute BODY with a different syntax table."
1545 `(let ((saved-syntax (syntax-table)))
1546 (unwind-protect
1547 (progn
1548 (set-syntax-table idlwave-find-symbol-syntax-table)
1549 ,@body)
1550 (set-syntax-table saved-syntax))))
1552 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1553 ; "Execute BODY with a different syntax table."
1554 ; `(let ((saved-syntax (syntax-table)))
1555 ; (unwind-protect
1556 ; (progn
1557 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1558 ; ,@body)
1559 ; (set-syntax-table saved-syntax))))
1561 (defun idlwave-action-and-binding (key cmd &optional select)
1562 "KEY and CMD are made into a key binding and an indent action.
1563 KEY is a string - same as for the `define-key' function. CMD is a
1564 function of no arguments or a list to be evaluated. CMD is bound to
1565 KEY in `idlwave-mode-map' by defining an anonymous function calling
1566 `self-insert-command' followed by CMD. If KEY contains more than one
1567 character a binding will only be set if SELECT is 'both.
1569 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1570 replacing any previous value for KEY. If a binding is not set then it
1571 will instead be placed in `idlwave-indent-action-table'.
1573 If the optional argument SELECT is nil then an action and binding are
1574 created. If SELECT is 'noaction, then a binding is always set and no
1575 action is created. If SELECT is 'both then an action and binding
1576 will both be created even if KEY contains more than one character.
1577 Otherwise, if SELECT is non-nil then only an action is created.
1579 Some examples:
1580 No spaces before and 1 after a comma
1581 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1582 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1583 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1584 Capitalize system variables - action only
1585 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1586 (if (not (equal select 'noaction))
1587 ;; Add action
1588 (let* ((table (if select 'idlwave-indent-action-table
1589 'idlwave-indent-expand-table))
1590 (table-key (regexp-quote key))
1591 (cell (assoc table-key (eval table))))
1592 (if cell
1593 ;; Replace action command
1594 (setcdr cell cmd)
1595 ;; New action
1596 (set table (append (eval table) (list (cons table-key cmd)))))))
1597 ;; Make key binding for action
1598 (if (or (and (null select) (= (length key) 1))
1599 (equal select 'noaction)
1600 (equal select 'both))
1601 (define-key idlwave-mode-map key
1602 `(lambda ()
1603 (interactive)
1604 (self-insert-command 1)
1605 ,(if (listp cmd) cmd (list cmd))))))
1607 ;; Set action and key bindings.
1608 ;; See description of the function `idlwave-action-and-binding'.
1609 ;; Automatically add spaces for the following characters
1611 ;; Actions for & are complicated by &&
1612 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1614 ;; Automatically add spaces to equal sign if not keyword. This needs
1615 ;; to go ahead of > and <, so >= and <= will be treated correctly
1616 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1618 ;; Actions for > and < are complicated by >=, <=, and ->...
1619 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1620 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1622 (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1626 ;;; Abbrev Section
1628 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1629 ;;; space is inserted (this is the space typed by the user to expanded
1630 ;;; the abbrev).
1632 (defvar idlwave-mode-abbrev-table nil
1633 "Abbreviation table used for IDLWAVE mode.")
1634 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1636 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1637 "Define-abbrev with backward compatibility.
1639 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1640 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1641 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1642 (args (list (or table idlwave-mode-abbrev-table)
1643 (if noprefix name (concat idlwave-abbrev-start-char name))
1644 expansion
1645 hook)))
1646 (condition-case nil
1647 (apply 'define-abbrev (append args '(0 t)))
1648 (error (apply 'define-abbrev args)))))
1650 (condition-case nil
1651 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1652 "w" idlwave-mode-syntax-table)
1653 (error nil))
1656 ;; Templates
1658 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1659 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1660 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1661 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1662 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1663 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1664 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1665 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1666 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1668 ;; Keywords, system functions, conversion routines
1670 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1672 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1673 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1680 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1681 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1683 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1684 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1685 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1686 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1687 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1688 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1689 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1690 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1691 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1696 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1705 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1714 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1715 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1716 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1718 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1720 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1721 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1723 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1724 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1725 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1727 ;; This section is reserved words only. (From IDL user manual)
1729 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1730 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1731 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1732 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1733 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1734 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1735 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1736 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1737 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1739 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1740 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1741 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1742 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1743 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1744 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1745 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1746 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1760 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1761 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1762 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1763 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1764 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1765 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1766 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1767 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1769 (defvar imenu-create-index-function)
1770 (defvar extract-index-name-function)
1771 (defvar prev-index-position-function)
1772 (defvar imenu-extract-index-name-function)
1773 (defvar imenu-prev-index-position-function)
1774 ;; defined later - so just make the compiler hush
1775 (defvar idlwave-mode-menu)
1776 (defvar idlwave-mode-debug-menu)
1778 ;;;###autoload
1779 (define-derived-mode idlwave-mode prog-mode "IDLWAVE"
1780 "Major mode for editing IDL source files (version 6.1_em22).
1782 The main features of this mode are
1784 1. Indentation and Formatting
1785 --------------------------
1786 Like other Emacs programming modes, C-j inserts a newline and indents.
1787 TAB is used for explicit indentation of the current line.
1789 To start a continuation line, use \\[idlwave-split-line]. This
1790 function can also be used in the middle of a line to split the line
1791 at that point. When used inside a long constant string, the string
1792 is split at that point with the `+' concatenation operator.
1794 Comments are indented as follows:
1796 `;;;' Indentation remains unchanged.
1797 `;;' Indent like the surrounding code
1798 `;' Indent to a minimum column.
1800 The indentation of comments starting in column 0 is never changed.
1802 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1803 comment. The indentation of the second line of the paragraph
1804 relative to the first will be retained. Use
1805 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1806 comments. When the variable `idlwave-fill-comment-line-only' is
1807 nil, code can also be auto-filled and auto-indented.
1809 To convert pre-existing IDL code to your formatting style, mark the
1810 entire buffer with \\[mark-whole-buffer] and execute
1811 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1812 again followed by \\[indent-region] (`indent-region').
1814 2. Routine Info
1815 ------------
1816 IDLWAVE displays information about the calling sequence and the
1817 accepted keyword parameters of a procedure or function with
1818 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1819 source file of a module. These commands know about system
1820 routines, all routines in idlwave-mode buffers and (when the
1821 idlwave-shell is active) about all modules currently compiled under
1822 this shell. It also makes use of pre-compiled or custom-scanned
1823 user and library catalogs many popular libraries ship with by
1824 default. Use \\[idlwave-update-routine-info] to update this
1825 information, which is also used for completion (see item 4).
1827 3. Online IDL Help
1828 ---------------
1830 \\[idlwave-context-help] displays the IDL documentation relevant
1831 for the system variable, keyword, or routines at point. A single
1832 key stroke gets you directly to the right place in the docs. See
1833 the manual to configure where and how the HTML help is displayed.
1835 4. Completion
1836 ----------
1837 \\[idlwave-complete] completes the names of procedures, functions
1838 class names, keyword parameters, system variables and tags, class
1839 tags, structure tags, filenames and much more. It is context
1840 sensitive and figures out what is expected at point. Lower case
1841 strings are completed in lower case, other strings in mixed or
1842 upper case.
1844 5. Code Templates and Abbreviations
1845 --------------------------------
1846 Many Abbreviations are predefined to expand to code fragments and templates.
1847 The abbreviations start generally with a `\\`. Some examples:
1849 \\pr PROCEDURE template
1850 \\fu FUNCTION template
1851 \\c CASE statement template
1852 \\sw SWITCH statement template
1853 \\f FOR loop template
1854 \\r REPEAT Loop template
1855 \\w WHILE loop template
1856 \\i IF statement template
1857 \\elif IF-ELSE statement template
1858 \\b BEGIN
1860 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1861 have direct keybindings - see the list of keybindings below.
1863 \\[idlwave-doc-header] inserts a documentation header at the
1864 beginning of the current program unit (pro, function or main).
1865 Change log entries can be added to the current program unit with
1866 \\[idlwave-doc-modification].
1868 6. Automatic Case Conversion
1869 -------------------------
1870 The case of reserved words and some abbrevs is controlled by
1871 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1873 7. Automatic END completion
1874 ------------------------
1875 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1876 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1878 8. Hooks
1879 -----
1880 Loading idlwave.el runs `idlwave-load-hook'.
1881 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1883 9. Documentation and Customization
1884 -------------------------------
1885 Info documentation for this package is available. Use
1886 \\[idlwave-info] to display (complain to your sysadmin if that does
1887 not work). For Postscript, PDF, and HTML versions of the
1888 documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
1889 IDLWAVE has customize support - see the group `idlwave'.
1891 10.Keybindings
1892 -----------
1893 Here is a list of all keybindings of this mode.
1894 If some of the key bindings below show with ??, use \\[describe-key]
1895 followed by the key sequence to see what the key sequence does.
1897 \\{idlwave-mode-map}"
1898 :abbrev-table idlwave-mode-abbrev-table
1899 (if idlwave-startup-message
1900 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1901 (setq idlwave-startup-message nil)
1903 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1905 (set (make-local-variable idlwave-comment-indent-function)
1906 #'idlwave-comment-hook)
1908 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1909 (set (make-local-variable 'comment-start) ";")
1910 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
1911 (set (make-local-variable 'require-final-newline) t)
1912 (set (make-local-variable 'abbrev-all-caps) t)
1913 (set (make-local-variable 'indent-tabs-mode) nil)
1914 (set (make-local-variable 'completion-ignore-case) t)
1916 (when (featurep 'easymenu)
1917 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1918 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1920 (setq abbrev-mode t)
1922 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1923 (setq comment-end "")
1924 (set (make-local-variable 'comment-multi-line) nil)
1925 (set (make-local-variable 'paragraph-separate)
1926 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1927 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1928 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1929 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1931 ;; ChangeLog
1932 (set (make-local-variable 'add-log-current-defun-function)
1933 'idlwave-current-routine-fullname)
1935 ;; Set tag table list to use IDLTAGS as file name.
1936 (if (boundp 'tag-table-alist)
1937 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1939 ;; Font-lock additions
1940 ;; Following line is for Emacs - XEmacs uses the corresponding property
1941 ;; on the `idlwave-mode' symbol.
1942 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1943 (set (make-local-variable 'font-lock-mark-block-function)
1944 'idlwave-mark-subprogram)
1945 (set (make-local-variable 'font-lock-fontify-region-function)
1946 'idlwave-font-lock-fontify-region)
1948 ;; Imenu setup
1949 (set (make-local-variable 'imenu-create-index-function)
1950 'imenu-default-create-index-function)
1951 (set (make-local-variable 'imenu-extract-index-name-function)
1952 'idlwave-unit-name)
1953 (set (make-local-variable 'imenu-prev-index-position-function)
1954 'idlwave-prev-index-position)
1956 ;; HideShow setup
1957 (add-to-list 'hs-special-modes-alist
1958 (list 'idlwave-mode
1959 idlwave-begin-block-reg
1960 idlwave-end-block-reg
1962 'idlwave-forward-block nil))
1964 ;; Make a local post-command-hook and add our hook to it
1965 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1966 ;; (make-local-hook 'post-command-hook)
1967 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1969 ;; Make local hooks for buffer updates
1970 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1971 ;; (make-local-hook 'kill-buffer-hook)
1972 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1973 ;; (make-local-hook 'after-save-hook)
1974 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1975 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1977 ;; Setup directories and file, if necessary
1978 (idlwave-setup)
1980 ;; Update the routine info with info about current buffer?
1981 (idlwave-new-buffer-update)
1983 ;; Check help location
1984 (idlwave-help-check-locations))
1986 (defvar idlwave-setup-done nil)
1987 (defun idlwave-setup ()
1988 (unless idlwave-setup-done
1989 (if (not (file-directory-p idlwave-config-directory))
1990 (make-directory idlwave-config-directory))
1991 (setq
1992 idlwave-user-catalog-file (expand-file-name
1993 idlwave-user-catalog-file
1994 idlwave-config-directory)
1995 idlwave-xml-system-rinfo-converted-file
1996 (expand-file-name
1997 idlwave-xml-system-rinfo-converted-file
1998 idlwave-config-directory)
1999 idlwave-path-file (expand-file-name
2000 idlwave-path-file
2001 idlwave-config-directory))
2002 (idlwave-read-paths) ; we may need these early
2003 (setq idlwave-setup-done t)))
2005 (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
2006 "Fontify continuation lines correctly."
2007 (let (pos)
2008 (save-excursion
2009 (goto-char beg)
2010 (forward-line -1)
2011 (when (setq pos (idlwave-is-continuation-line))
2012 (goto-char pos)
2013 (idlwave-beginning-of-statement)
2014 (setq beg (point)))))
2015 (font-lock-default-fontify-region beg end verbose))
2018 ;; Code Formatting ----------------------------------------------------
2021 (defun idlwave-hard-tab ()
2022 "Insert TAB in buffer in current position."
2023 (interactive)
2024 (insert "\t"))
2026 ;;; This stuff is experimental
2028 (defvar idlwave-command-hook nil
2029 "If non-nil, a list that can be evaluated using `eval'.
2030 It is evaluated in the lisp function `idlwave-command-hook' which is
2031 placed in `post-command-hook'.")
2033 (defun idlwave-command-hook ()
2034 "Command run after every command.
2035 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2036 sets the variable to zero afterwards."
2037 (and idlwave-command-hook
2038 (listp idlwave-command-hook)
2039 (condition-case nil
2040 (eval idlwave-command-hook)
2041 (error nil)))
2042 (setq idlwave-command-hook nil))
2044 ;;; End experiment
2046 ;; It would be better to use expand.el for better abbrev handling and
2047 ;; versatility.
2049 (defun idlwave-check-abbrev (arg &optional reserved)
2050 "Reverse abbrev expansion if in comment or string.
2051 Argument ARG is the number of characters to move point
2052 backward if `idlwave-abbrev-move' is non-nil.
2053 If optional argument RESERVED is non-nil then the expansion
2054 consists of reserved words, which will be capitalized if
2055 `idlwave-reserved-word-upcase' is non-nil.
2056 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2057 is non-nil, unless its value is \`down in which case the abbrev will be
2058 made into all lowercase.
2059 Returns non-nil if abbrev is left expanded."
2060 (if (idlwave-quoted)
2061 (progn (unexpand-abbrev)
2062 nil)
2063 (if (and reserved idlwave-reserved-word-upcase)
2064 (upcase-region last-abbrev-location (point))
2065 (cond
2066 ((equal idlwave-abbrev-change-case 'down)
2067 (downcase-region last-abbrev-location (point)))
2068 (idlwave-abbrev-change-case
2069 (upcase-region last-abbrev-location (point)))))
2070 (if (and idlwave-abbrev-move (> arg 0))
2071 (if (boundp 'post-command-hook)
2072 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2073 (backward-char arg)))
2076 (defun idlwave-in-comment ()
2077 "Return t if point is inside a comment, nil otherwise."
2078 (save-excursion
2079 (let ((here (point)))
2080 (and (idlwave-goto-comment) (> here (point))))))
2082 (defun idlwave-goto-comment ()
2083 "Move to start of comment delimiter on current line.
2084 Moves to end of line if there is no comment delimiter.
2085 Ignores comment delimiters in strings.
2086 Returns point if comment found and nil otherwise."
2087 (let ((eos (point-at-eol))
2088 (data (match-data))
2089 found)
2090 ;; Look for first comment delimiter not in a string
2091 (beginning-of-line)
2092 (setq found (search-forward comment-start eos 'lim))
2093 (while (and found (idlwave-in-quote))
2094 (setq found (search-forward comment-start eos 'lim)))
2095 (store-match-data data)
2096 (and found (not (idlwave-in-quote))
2097 (progn
2098 (backward-char 1)
2099 (point)))))
2101 (defun idlwave-region-active-p ()
2102 "Should we operate on an active region?"
2103 (if (fboundp 'use-region-p)
2104 (use-region-p)
2105 (region-active-p)))
2107 (defun idlwave-show-matching-quote ()
2108 "Insert quote and show matching quote if this is end of a string."
2109 (interactive)
2110 (let ((bq (idlwave-in-quote))
2111 (inq last-command-event))
2112 (if (and bq (not (idlwave-in-comment)))
2113 (let ((delim (char-after bq)))
2114 (insert inq)
2115 (if (eq inq delim)
2116 (save-excursion
2117 (goto-char bq)
2118 (sit-for 1))))
2119 ;; Not the end of a string
2120 (insert inq))))
2122 (defun idlwave-show-begin-check ()
2123 "Ensure that the previous word was a token before `idlwave-show-begin'.
2124 An END token must be preceded by whitespace."
2125 (if (not (idlwave-quoted))
2127 (save-excursion
2128 (backward-word 1)
2129 (backward-char 1)
2130 (looking-at "[ \t\n\f]"))
2131 (idlwave-show-begin))))
2133 (defun idlwave-show-begin ()
2134 "Find the start of current block and blinks to it for a second.
2135 Also checks if the correct END statement has been used."
2136 ;; All end statements are reserved words
2137 ;; Re-indent end line
2138 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2139 ;;(backward-char 1)
2140 (let* ((pos (point-marker))
2141 (last-abbrev-marker (copy-marker last-abbrev-location))
2142 (eol-pos (point-at-eol))
2143 begin-pos end-pos end end1 )
2144 (if idlwave-reindent-end (idlwave-indent-line))
2145 (setq last-abbrev-location (marker-position last-abbrev-marker))
2146 (when (and (idlwave-check-abbrev 0 t)
2147 idlwave-show-block)
2148 (save-excursion
2149 ;; Move inside current block
2150 (goto-char last-abbrev-marker)
2151 (idlwave-block-jump-out -1 'nomark)
2152 (setq begin-pos (point))
2153 (idlwave-block-jump-out 1 'nomark)
2154 (setq end-pos (point))
2155 (if (> end-pos eol-pos)
2156 (setq end-pos pos))
2157 (goto-char end-pos)
2158 (setq end (buffer-substring
2159 (progn
2160 (skip-chars-backward "a-zA-Z")
2161 (point))
2162 end-pos))
2163 (goto-char begin-pos)
2164 (when (setq end1 (cdr (idlwave-block-master)))
2165 (cond
2166 ((null end1)) ; no-operation
2167 ((string= (downcase end) (downcase end1))
2168 (sit-for 1))
2169 ((string= (downcase end) "end")
2170 ;; A generic end
2171 (if idlwave-expand-generic-end
2172 (save-excursion
2173 (goto-char pos)
2174 (backward-char 3)
2175 (insert (if (string= end "END") (upcase end1) end1))
2176 (delete-char 3)))
2177 (sit-for 1))
2179 (beep)
2180 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2181 end1 end)
2182 (sit-for 1))))))))
2183 ;;(delete-char 1))
2185 (defun idlwave-block-master ()
2186 (let ((case-fold-search t))
2187 (save-excursion
2188 (cond
2189 ((looking-at "pro\\|case\\|switch\\|function\\>")
2190 (assoc (downcase (match-string 0)) idlwave-block-matches))
2191 ((looking-at "begin\\>")
2192 (let ((limit (save-excursion
2193 (idlwave-beginning-of-statement)
2194 (point))))
2195 (cond
2196 ((re-search-backward ":[ \t]*\\=" limit t)
2197 ;; seems to be a case thing
2198 '("begin" . "end"))
2199 ((re-search-backward idlwave-block-match-regexp limit t)
2200 (assoc (downcase (match-string 1))
2201 idlwave-block-matches))
2203 ;; Just a normal block
2204 '("begin" . "end")))))
2205 (t nil)))))
2207 (defun idlwave-close-block ()
2208 "Terminate the current block with the correct END statement."
2209 (interactive)
2210 ;; Start new line if we are not in a new line
2211 (unless (save-excursion
2212 (skip-chars-backward " \t")
2213 (bolp))
2214 (let ((idlwave-show-block nil))
2215 (newline-and-indent)))
2216 (let ((last-abbrev-location (point))) ; for upcasing
2217 (insert "end")
2218 (idlwave-show-begin)))
2220 (defun idlwave-custom-ampersand-surround (&optional is-action)
2221 "Surround &, leaving room for && (which surround as well)."
2222 (let* ((prev-char (char-after (- (point) 2)))
2223 (next-char (char-after (point)))
2224 (amp-left (eq prev-char ?&))
2225 (amp-right (eq next-char ?&))
2226 (len (if amp-left 2 1)))
2227 (unless amp-right ;no need to do it twice, amp-left will catch it.
2228 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2230 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2231 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2232 (let* ((prev-char (char-after (- (point) 2)))
2233 (next-char (char-after (point)))
2234 (method-invoke (and gtr (eq prev-char ?-)))
2235 (len (if method-invoke 2 1)))
2236 (unless (eq next-char ?=)
2237 ;; Key binding: pad only on left, to save for possible >=/<=
2238 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2240 (defun idlwave-surround (&optional before after length is-action)
2241 "Surround the LENGTH characters before point with blanks.
2242 LENGTH defaults to 1.
2243 Optional arguments BEFORE and AFTER affect the behavior before and
2244 after the characters (see also description of `idlwave-make-space'):
2246 nil do nothing
2247 0 force no spaces
2248 integer > 0 force exactly n spaces
2249 integer < 0 at least |n| spaces
2251 The function does nothing if any of the following conditions is true:
2252 - `idlwave-surround-by-blank' is nil
2253 - the character before point is inside a string or comment"
2254 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2255 (let ((length (or length 1))) ; establish a default for LENGTH
2256 (backward-char length)
2257 (save-restriction
2258 (let ((here (point)))
2259 (skip-chars-backward " \t")
2260 (if (bolp)
2261 ;; avoid clobbering indent
2262 (progn
2263 (move-to-column (idlwave-calculate-indent))
2264 (if (<= (point) here)
2265 (narrow-to-region (point) here))
2266 (goto-char here)))
2267 (idlwave-make-space before))
2268 (skip-chars-forward " \t"))
2269 (forward-char length)
2270 (idlwave-make-space after)
2271 ;; Check to see if the line should auto wrap
2272 (if (and (equal (char-after (1- (point))) ?\ )
2273 (> (current-column) fill-column))
2274 (funcall auto-fill-function)))))
2276 (defun idlwave-make-space (n)
2277 "Make space at point.
2278 The space affected is all the spaces and tabs around point.
2279 If n is non-nil then point is left abs(n) spaces from the beginning of
2280 the contiguous space.
2281 The amount of space at point is determined by N.
2282 If the value of N is:
2283 nil - do nothing.
2284 > 0 - exactly N spaces.
2285 < 0 - a minimum of -N spaces, i.e., do not change if there are
2286 already -N spaces.
2287 0 - no spaces (i.e. remove any existing space)."
2288 (if (integerp n)
2289 (let
2290 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2291 (left (point))
2292 (end-col (progn (skip-chars-forward " \t") (current-column))))
2293 (delete-horizontal-space)
2294 (cond
2295 ((> n 0)
2296 (idlwave-indent-to (+ start-col n))
2297 (goto-char (+ left n)))
2298 ((< n 0)
2299 (idlwave-indent-to end-col (- n))
2300 (goto-char (- left n)))
2301 ;; n = 0, done
2302 ))))
2304 (defun idlwave-newline ()
2305 "Insert a newline and indent the current and previous line."
2306 (interactive)
2308 ;; Handle unterminated single and double quotes
2309 ;; If not in a comment and in a string then insertion of a newline
2310 ;; will mean unbalanced quotes.
2312 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2313 (progn (beep)
2314 (message "Warning: unbalanced quotes?")))
2315 (newline)
2317 ;; The current line is being split, the cursor should be at the
2318 ;; beginning of the new line skipping the leading indentation.
2320 ;; The reason we insert the new line before indenting is that the
2321 ;; indenting could be confused by keywords (e.g. END) on the line
2322 ;; after the split point. This prevents us from just using
2323 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2325 (beginning-of-line 0)
2326 (idlwave-indent-line)
2327 (forward-line)
2328 (idlwave-indent-line))
2331 ;; Use global variable 'comment-column' to set parallel comment
2333 ;; Modeled on lisp.el
2334 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2335 (defun idlwave-comment-hook ()
2336 "Compute indent for the beginning of the IDL comment delimiter."
2337 (if (or (looking-at idlwave-no-change-comment)
2338 (looking-at (or idlwave-begin-line-comment "^;")))
2339 (current-column)
2340 (if (looking-at idlwave-code-comment)
2341 (if (save-excursion (skip-chars-backward " \t") (bolp))
2342 ;; On line by itself, indent as code
2343 (let ((tem (idlwave-calculate-indent)))
2344 (if (listp tem) (car tem) tem))
2345 ;; after code - do not change
2346 (current-column))
2347 (skip-chars-backward " \t")
2348 (max (if (bolp) 0 (1+ (current-column)))
2349 comment-column))))
2351 (defun idlwave-split-line ()
2352 "Continue line by breaking line at point and indent the lines.
2353 For a code line insert continuation marker. If the line is a line comment
2354 then the new line will contain a comment with the same indentation.
2355 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2356 non-nil."
2357 (interactive)
2358 ;; Expand abbreviation, just like normal RET would.
2359 (and abbrev-mode (expand-abbrev))
2360 (let (beg)
2361 (if (not (idlwave-in-comment))
2362 ;; For code line add continuation.
2363 ;; Check if splitting a string.
2364 (progn
2365 (if (setq beg (idlwave-in-quote))
2366 (if idlwave-split-line-string
2367 ;; Split the string.
2368 (progn (insert (setq beg (char-after beg)) " + "
2369 idlwave-continuation-char beg)
2370 (backward-char 1)
2371 (newline-and-indent)
2372 (forward-char 1))
2373 ;; Do not split the string.
2374 (beep)
2375 (message "Warning: continuation inside string!!")
2376 (insert " " idlwave-continuation-char))
2377 ;; Not splitting a string.
2378 (if (not (member (char-before) '(?\ ?\t)))
2379 (insert " "))
2380 (insert idlwave-continuation-char)
2381 (newline-and-indent)))
2382 (indent-new-comment-line))
2383 ;; Indent previous line
2384 (setq beg (- (point-max) (point)))
2385 (forward-line -1)
2386 (idlwave-indent-line)
2387 (goto-char (- (point-max) beg))
2388 ;; Reindent new line
2389 (idlwave-indent-line)))
2391 (defun idlwave-beginning-of-subprogram (&optional nomark)
2392 "Move point to the beginning of the current program unit.
2393 If NOMARK is non-nil, do not push mark."
2394 (interactive)
2395 (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
2397 (defun idlwave-end-of-subprogram (&optional nomark)
2398 "Move point to the start of the next program unit.
2399 If NOMARK is non-nil, do not push mark."
2400 (interactive)
2401 (idlwave-end-of-statement)
2402 (idlwave-find-key idlwave-end-unit-reg 1 nomark))
2404 (defun idlwave-mark-statement ()
2405 "Mark current IDL statement."
2406 (interactive)
2407 (idlwave-end-of-statement)
2408 (let ((end (point)))
2409 (idlwave-beginning-of-statement)
2410 (push-mark end nil t)))
2412 (defun idlwave-mark-block ()
2413 "Mark containing block."
2414 (interactive)
2415 (idlwave-end-of-statement)
2416 (idlwave-backward-up-block -1)
2417 (idlwave-end-of-statement)
2418 (let ((end (point)))
2419 (idlwave-backward-block)
2420 (idlwave-beginning-of-statement)
2421 (push-mark end nil t)))
2424 (defun idlwave-mark-subprogram ()
2425 "Put mark at beginning of program, point at end.
2426 The marks are pushed."
2427 (interactive)
2428 (idlwave-end-of-statement)
2429 (idlwave-beginning-of-subprogram)
2430 (let ((beg (point)))
2431 (idlwave-forward-block)
2432 (push-mark beg nil t))
2433 (exchange-point-and-mark))
2435 (defun idlwave-backward-up-block (&optional arg)
2436 "Move to beginning of enclosing block if prefix ARG >= 0.
2437 If prefix ARG < 0 then move forward to enclosing block end."
2438 (interactive "p")
2439 (idlwave-block-jump-out (- arg) 'nomark))
2441 (defun idlwave-beginning-of-block ()
2442 "Go to the beginning of the current block."
2443 (interactive)
2444 (idlwave-block-jump-out -1 'nomark)
2445 (forward-word 1))
2447 (defun idlwave-end-of-block ()
2448 "Go to the beginning of the current block."
2449 (interactive)
2450 (idlwave-block-jump-out 1 'nomark)
2451 (backward-word 1))
2453 (defun idlwave-forward-block (&optional arg)
2454 "Move across next nested block."
2455 (interactive)
2456 (let ((arg (or arg 1)))
2457 (if (idlwave-down-block arg)
2458 (idlwave-block-jump-out arg 'nomark))))
2460 (defun idlwave-backward-block ()
2461 "Move backward across previous nested block."
2462 (interactive)
2463 (if (idlwave-down-block -1)
2464 (idlwave-block-jump-out -1 'nomark)))
2466 (defun idlwave-down-block (&optional arg)
2467 "Go down a block.
2468 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2469 Returns non-nil if successfull."
2470 (interactive "p")
2471 (let (status)
2472 (if (< arg 0)
2473 ;; Backward
2474 (let ((eos (save-excursion
2475 (idlwave-block-jump-out -1 'nomark)
2476 (point))))
2477 (if (setq status (idlwave-find-key
2478 idlwave-end-block-reg -1 'nomark eos))
2479 (idlwave-beginning-of-statement)
2480 (message "No nested block before beginning of containing block.")))
2481 ;; Forward
2482 (let ((eos (save-excursion
2483 (idlwave-block-jump-out 1 'nomark)
2484 (point))))
2485 (if (setq status (idlwave-find-key
2486 idlwave-begin-block-reg 1 'nomark eos))
2487 (idlwave-end-of-statement)
2488 (message "No nested block before end of containing block."))))
2489 status))
2491 (defun idlwave-mark-doclib ()
2492 "Put point at beginning of doc library header, mark at end.
2493 The marks are pushed."
2494 (interactive)
2495 (let (beg
2496 (here (point)))
2497 (goto-char (point-max))
2498 (if (re-search-backward idlwave-doclib-start nil t)
2499 (progn
2500 (setq beg (progn (beginning-of-line) (point)))
2501 (if (re-search-forward idlwave-doclib-end nil t)
2502 (progn
2503 (forward-line 1)
2504 (push-mark beg nil t)
2505 (message "Could not find end of doc library header.")))
2506 (message "Could not find doc library header start.")
2507 (goto-char here)))))
2509 (defun idlwave-current-routine-fullname ()
2510 (let ((name (idlwave-current-routine)))
2511 (idlwave-make-full-name (nth 2 name) (car name))))
2513 (defun idlwave-current-routine ()
2514 "Return (NAME TYPE CLASS) of current routine."
2515 (idlwave-routines)
2516 (save-excursion
2517 (idlwave-beginning-of-subprogram 'nomark)
2518 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2519 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2520 'pro 'function))
2521 (class (idlwave-sintern-class (match-string 3)))
2522 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2523 (list name type class)))))
2525 (defvar idlwave-shell-prompt-pattern)
2526 (defun idlwave-beginning-of-statement ()
2527 "Move to beginning of the current statement.
2528 Skips back past statement continuations.
2529 Point is placed at the beginning of the line whether or not this is an
2530 actual statement."
2531 (interactive)
2532 (cond
2533 ((derived-mode-p 'idlwave-shell-mode)
2534 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2535 (goto-char (match-end 0))))
2537 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2538 (idlwave-previous-statement)
2539 (beginning-of-line)))))
2541 (defun idlwave-previous-statement ()
2542 "Move point to beginning of the previous statement.
2543 Returns t if the current line before moving is the beginning of
2544 the first non-comment statement in the file, and nil otherwise."
2545 (interactive)
2546 (let (first-statement)
2547 (if (not (= (forward-line -1) 0))
2548 ;; first line in file
2550 ;; skip blank lines, label lines, include lines and line comments
2551 (while (and
2552 ;; The current statement is the first statement until we
2553 ;; reach another statement.
2554 (setq first-statement
2556 (looking-at idlwave-comment-line-start-skip)
2557 (looking-at "[ \t]*$")
2558 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2559 (looking-at "^@")))
2560 (= (forward-line -1) 0)))
2561 ;; skip continuation lines
2562 (while (and
2563 (save-excursion
2564 (forward-line -1)
2565 (idlwave-is-continuation-line))
2566 (= (forward-line -1) 0)))
2567 first-statement)))
2569 (defun idlwave-end-of-statement ()
2570 "Move point to the end of the current IDL statement.
2571 If not in a statement just moves to end of line. Returns position."
2572 (interactive)
2573 (while (and (idlwave-is-continuation-line)
2574 (= (forward-line 1) 0))
2575 (while (and (idlwave-is-comment-or-empty-line)
2576 (= (forward-line 1) 0))))
2577 (end-of-line)
2578 (point))
2580 (defun idlwave-end-of-statement0 ()
2581 "Move point to the end of the current IDL statement.
2582 If not in a statement just moves to end of line. Returns position."
2583 (interactive)
2584 (while (and (idlwave-is-continuation-line)
2585 (= (forward-line 1) 0)))
2586 (end-of-line)
2587 (point))
2589 (defun idlwave-next-statement ()
2590 "Move point to beginning of the next IDL statement.
2591 Returns t if that statement is the last non-comment IDL statement
2592 in the file, and nil otherwise."
2593 (interactive)
2594 (let (last-statement)
2595 (idlwave-end-of-statement)
2596 ;; skip blank lines, label lines, include lines and line comments
2597 (while (and (= (forward-line 1) 0)
2598 ;; The current statement is the last statement until
2599 ;; we reach a new statement.
2600 (setq last-statement
2602 (looking-at idlwave-comment-line-start-skip)
2603 (looking-at "[ \t]*$")
2604 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2605 (looking-at "^@")))))
2606 last-statement))
2608 (defun idlwave-skip-multi-commands (&optional lim)
2609 "Skip past multiple commands on a line (with `&')."
2610 (let ((save-point (point)))
2611 (when (re-search-forward ".*&" lim t)
2612 (goto-char (match-end 0))
2613 (if (idlwave-quoted)
2614 (goto-char save-point)
2615 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2616 (point)))
2618 (defun idlwave-skip-label-or-case ()
2619 "Skip label or case statement element.
2620 Returns position after label.
2621 If there is no label point is not moved and nil is returned."
2622 ;; Case expressions and labels are terminated by a colon.
2623 ;; So we find the first colon in the line and make sure
2624 ;; - no `?' is before it (might be a ? b : c)
2625 ;; - it is not in a comment
2626 ;; - not in a string constant
2627 ;; - not in parenthesis (like a[0:3])
2628 ;; - not followed by another ":" in explicit class, ala a->b::c
2629 ;; As many in this mode, this function is heuristic and not an exact
2630 ;; parser.
2631 (let* ((start (point))
2632 (eos (save-excursion (idlwave-end-of-statement) (point)))
2633 (end (idlwave-find-key ":" 1 'nomark eos)))
2634 (if (and end
2635 (= (nth 0 (parse-partial-sexp start end)) 0)
2636 (not (string-match "\\?" (buffer-substring start end)))
2637 (not (string-match "^::" (buffer-substring end eos))))
2638 (progn
2639 (forward-char)
2640 (point))
2641 (goto-char start)
2642 nil)))
2644 (defun idlwave-start-of-substatement (&optional pre)
2645 "Move to start of next IDL substatement after point.
2646 Uses the type of the current IDL statement to determine if the next
2647 statement is on a new line or is a subpart of the current statement.
2648 Returns point at start of substatement modulo whitespace.
2649 If optional argument is non-nil move to beginning of current
2650 substatement."
2651 (let ((orig (point))
2652 (eos (idlwave-end-of-statement))
2653 (ifnest 0)
2654 st nst last)
2655 (idlwave-beginning-of-statement)
2656 (idlwave-skip-label-or-case)
2657 (if (< (point) orig)
2658 (idlwave-skip-multi-commands orig))
2659 (setq last (point))
2660 ;; Continue looking for substatements until we are past orig
2661 (while (and (<= (point) orig) (not (eobp)))
2662 (setq last (point))
2663 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2664 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2665 (cond ((and nst
2666 (idlwave-find-key nst 1 'nomark eos))
2667 (goto-char (match-end 0)))
2668 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2669 (setq ifnest (1- ifnest))
2670 (goto-char (match-end 0)))
2671 (t (setq ifnest 0)
2672 (idlwave-next-statement))))
2673 (if pre (goto-char last))
2674 ;; If a continuation line starts here, move to next line
2675 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2676 (beginning-of-line 2))
2677 (point)))
2679 (defun idlwave-statement-type ()
2680 "Return the type of the current IDL statement.
2681 Uses `idlwave-statement-match' to return a cons of (type . point) with
2682 point the ending position where the type was determined. Type is the
2683 association from `idlwave-statement-match', i.e. the cons cell from the
2684 list not just the type symbol. Returns nil if not an identifiable
2685 statement."
2686 (save-excursion
2687 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2688 ;; and possibly comments
2689 (while (looking-at "[ \t]*\\$")
2690 (forward-line 1))
2691 (skip-chars-forward " \t")
2692 (let ((st idlwave-statement-match)
2693 (case-fold-search t))
2694 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2695 (setq st (cdr st))))
2696 (if st
2697 (append st (match-end 0))))))
2699 (defun idlwave-expand-equal (&optional before after is-action)
2700 "Pad '=' with spaces.
2701 Two cases: Assignment statement, and keyword assignment.
2702 Which case is determined using `idlwave-start-of-substatement' and
2703 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2704 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2705 is treated just like assignment statements. When nil, spaces are
2706 removed for keyword assignment. Any other value keeps the current space
2707 around the `='. Limits in for loops are treated as keyword assignment.
2709 Starting with IDL 6.0, a number of op= assignments are available.
2710 Since ambiguities of the form:
2712 r and= b
2713 rand= b
2715 can occur, alphanumeric operator assignment will never be pre-padded,
2716 only post-padded. You must use a space before these to disambiguate
2717 \(not just for padding, but for proper parsing by IDL too!). Other
2718 operators, such as ##=, ^=, etc., will be pre-padded.
2720 IS-ACTION is ignored.
2722 See `idlwave-surround'."
2723 (if idlwave-surround-by-blank
2724 (let
2725 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2726 (an-ops
2727 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2728 (len 1))
2730 (save-excursion
2731 (let ((case-fold-search t))
2732 (backward-char)
2733 (if (or
2734 (re-search-backward non-an-ops nil t)
2735 ;; Why doesn't ##? work for both?
2736 (re-search-backward "\\(#\\)\\=" nil t))
2737 (setq len (1+ (length (match-string 1))))
2738 (when (re-search-backward an-ops nil t)
2739 ;(setq begin nil) ; won't modify begin
2740 (setq len (1+ (length (match-string 1))))))))
2742 (if (eq t idlwave-pad-keyword)
2743 ;; Everything gets padded equally
2744 (idlwave-surround before after len)
2745 ;; Treating keywords/for variables specially...
2746 (let ((st (save-excursion ; To catch "for" variables
2747 (idlwave-start-of-substatement t)
2748 (idlwave-statement-type)))
2749 (what (save-excursion ; To catch keywords
2750 (skip-chars-backward "= \t")
2751 (nth 2 (idlwave-where)))))
2752 (cond ((or (memq what '(function-keyword procedure-keyword))
2753 (memq (caar st) '(for pdef)))
2754 (cond
2755 ((null idlwave-pad-keyword)
2756 (idlwave-surround 0 0)
2757 ) ; remove space
2758 (t))) ; leave any spaces alone
2759 (t (idlwave-surround before after len))))))))
2762 (defun idlwave-indent-and-action (&optional arg)
2763 "Call `idlwave-indent-line' and do expand actions.
2764 With prefix ARG non-nil, indent the entire sub-statement."
2765 (interactive "p")
2766 (save-excursion
2767 (if (and idlwave-expand-generic-end
2768 (re-search-backward "\\<\\(end\\)\\s-*\\="
2769 (max 0 (- (point) 10)) t)
2770 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2771 (progn (goto-char (match-end 1))
2772 ;;Expand the END abbreviation, just as RET or Space would have.
2773 (if abbrev-mode (expand-abbrev)
2774 (idlwave-show-begin)))))
2775 (when (and (not arg) current-prefix-arg)
2776 (setq arg current-prefix-arg)
2777 (setq current-prefix-arg nil))
2778 (if arg
2779 (idlwave-indent-statement)
2780 (idlwave-indent-line t)))
2782 (defun idlwave-indent-line (&optional expand)
2783 "Indent current IDL line as code or as a comment.
2784 The actions in `idlwave-indent-action-table' are performed.
2785 If the optional argument EXPAND is non-nil then the actions in
2786 `idlwave-indent-expand-table' are performed."
2787 (interactive)
2788 ;; Move point out of left margin.
2789 (if (save-excursion
2790 (skip-chars-backward " \t")
2791 (bolp))
2792 (skip-chars-forward " \t"))
2793 (let ((mloc (point-marker)))
2794 (save-excursion
2795 (beginning-of-line)
2796 (if (looking-at idlwave-comment-line-start-skip)
2797 ;; Indentation for a line comment
2798 (progn
2799 (skip-chars-forward " \t")
2800 (idlwave-indent-left-margin (idlwave-comment-hook)))
2802 ;; Code Line
2804 ;; Before indenting, run action routines.
2806 (if (and expand idlwave-do-actions)
2807 (mapc 'idlwave-do-action idlwave-indent-expand-table))
2809 (if idlwave-do-actions
2810 (mapc 'idlwave-do-action idlwave-indent-action-table))
2812 ;; No longer expand abbrevs on the line. The user can do this
2813 ;; manually using expand-region-abbrevs.
2815 ;; Indent for code line
2817 (beginning-of-line)
2818 (if (or
2819 ;; a label line
2820 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2821 ;; a batch command
2822 (looking-at "^[ \t]*@"))
2823 ;; leave flush left
2825 ;; indent the line
2826 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2827 ;; Adjust parallel comment
2828 (end-of-line)
2829 (if (idlwave-in-comment)
2830 ;; Emacs 21 is too smart with fill-column on comment indent
2831 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2832 (1- (frame-width))
2833 fill-column)))
2834 (indent-for-comment)))))
2835 (goto-char mloc)
2836 ;; Get rid of marker
2837 (set-marker mloc nil)))
2839 (defun idlwave-do-action (action)
2840 "Perform an action repeatedly on a line.
2841 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2842 either a function name to be called with `funcall' or a list to be
2843 evaluated with `eval'. The action performed by FUNC should leave
2844 point after the match for REG - otherwise an infinite loop may be
2845 entered. FUNC is always passed a final argument of 'is-action, so it
2846 can discriminate between being run as an action, or a key binding."
2847 (let ((action-key (car action))
2848 (action-routine (cdr action)))
2849 (beginning-of-line)
2850 (while (idlwave-look-at action-key)
2851 (if (listp action-routine)
2852 (eval (append action-routine '('is-action)))
2853 (funcall action-routine 'is-action)))))
2855 (defun idlwave-indent-to (col &optional min)
2856 "Indent from point with spaces until column COL.
2857 Inserts space before markers at point."
2858 (if (not min) (setq min 0))
2859 (insert-before-markers
2860 (make-string (max min (- col (current-column))) ?\ )))
2862 (defun idlwave-indent-left-margin (col)
2863 "Indent the current line to column COL.
2864 Indents such that first non-whitespace character is at column COL
2865 Inserts spaces before markers at point."
2866 (save-excursion
2867 (beginning-of-line)
2868 (delete-horizontal-space)
2869 (idlwave-indent-to col)))
2871 (defun idlwave-indent-subprogram ()
2872 "Indent program unit which contains point."
2873 (interactive)
2874 (save-excursion
2875 (idlwave-end-of-statement)
2876 (idlwave-beginning-of-subprogram)
2877 (let ((beg (point)))
2878 (idlwave-forward-block)
2879 (message "Indenting subprogram...")
2880 (indent-region beg (point) nil))
2881 (message "Indenting subprogram...done.")))
2883 (defun idlwave-indent-statement ()
2884 "Indent current statement, including all continuation lines."
2885 (interactive)
2886 (save-excursion
2887 (idlwave-beginning-of-statement)
2888 (let ((beg (point)))
2889 (idlwave-end-of-statement)
2890 (indent-region beg (point) nil))))
2892 (defun idlwave-calculate-indent ()
2893 "Return appropriate indentation for current line as IDL code."
2894 (save-excursion
2895 (beginning-of-line)
2896 (cond
2897 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2898 ;; function
2899 ((idlwave-look-at idlwave-begin-unit-reg)
2901 ;; Check for continuation line
2902 ((save-excursion
2903 (and (= (forward-line -1) 0)
2904 (idlwave-is-continuation-line)))
2905 (idlwave-calculate-cont-indent))
2906 ;; calculate indent based on previous and current statements
2907 (t (let* (beg-prev-pos
2908 (the-indent
2909 ;; calculate indent based on previous statement
2910 (save-excursion
2911 (cond
2912 ;; Beginning of file
2913 ((prog1
2914 (idlwave-previous-statement)
2915 (setq beg-prev-pos (point)))
2917 ;; Main block
2918 ((idlwave-look-at idlwave-begin-unit-reg t)
2919 (+ (idlwave-current-statement-indent)
2920 idlwave-main-block-indent))
2921 ;; Begin block
2922 ((idlwave-look-at idlwave-begin-block-reg t)
2923 (+ (idlwave-min-current-statement-indent)
2924 idlwave-block-indent))
2925 ;; End Block
2926 ((idlwave-look-at idlwave-end-block-reg t)
2927 (progn
2928 ;; Match to the *beginning* of the block opener
2929 (goto-char beg-prev-pos)
2930 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2931 (idlwave-min-current-statement-indent)))
2932 ;; idlwave-end-offset
2933 ;; idlwave-block-indent))
2935 ;; Default to current indent
2936 ((idlwave-current-statement-indent))))))
2937 ;; adjust the indentation based on the current statement
2938 (cond
2939 ;; End block
2940 ((idlwave-look-at idlwave-end-block-reg)
2941 (+ the-indent idlwave-end-offset))
2942 (the-indent)))))))
2945 ;; Parentheses indent
2948 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2949 "Calculate the continuation indent inside a paren group.
2950 Returns a cons-cell with (open . indent), where open is the
2951 location of the open paren."
2952 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2953 ;; Found an innermost open paren.
2954 (when open
2955 (goto-char open)
2956 ;; Line up with next word unless this is a closing paren.
2957 (cons open
2958 (cond
2959 ;; Plain Kernighan-style nested indent
2960 (idlwave-indent-parens-nested
2961 (+ idlwave-continuation-indent (idlwave-current-indent)))
2963 ;; This is a closed paren - line up under open paren.
2964 (close-exp
2965 (current-column))
2967 ;; Empty (or just comment) follows -- revert to basic indent
2968 ((progn
2969 ;; Skip paren
2970 (forward-char 1)
2971 (looking-at "[ \t$]*\\(;.*\\)?$"))
2972 nil)
2974 ;; Line up with first word after any blank space
2975 ((progn
2976 (skip-chars-forward " \t")
2977 (current-column))))))))
2979 (defun idlwave-calculate-cont-indent ()
2980 "Calculates the IDL continuation indent column from the previous statement.
2981 Note that here previous statement usually means the beginning of the
2982 current statement if this statement is a continuation of the previous
2983 line. Various special types of continuations, including assignments,
2984 routine definitions, and parenthetical groupings, are treated separately."
2985 (save-excursion
2986 (let* ((case-fold-search t)
2987 (end-reg (progn (beginning-of-line) (point)))
2988 (beg-last-statement (save-excursion (idlwave-previous-statement)
2989 (point)))
2990 (beg-reg (progn (idlwave-start-of-substatement 'pre)
2991 (if (eq (line-beginning-position) end-reg)
2992 (goto-char beg-last-statement)
2993 (point))))
2994 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
2995 idlwave-continuation-indent))
2996 fancy-nonparen-indent fancy-paren-indent)
2997 (cond
2998 ;; Align then with its matching if, etc.
2999 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
3000 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
3001 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
3002 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
3003 "[ \t]*until")
3004 ("\\<case\\>" . "[ \t]*of")))
3005 match cont-re)
3006 (goto-char end-reg)
3007 (and
3008 (setq cont-re
3009 (catch 'exit
3010 (while (setq match (car matchers))
3011 (if (looking-at (cdr match))
3012 (throw 'exit (car match)))
3013 (setq matchers (cdr matchers)))))
3014 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3015 (if (looking-at "end") ;; that one's special
3016 (- (idlwave-current-indent)
3017 (+ idlwave-block-indent idlwave-end-offset))
3018 (idlwave-current-indent)))
3020 ;; Indent in from the previous line for continuing statements
3021 ((let ((matchers '("\\<then\\>"
3022 "\\<do\\>"
3023 "\\<repeat\\>"
3024 "\\<else\\>"))
3025 match)
3026 (catch 'exit
3027 (goto-char end-reg)
3028 (if (/= (forward-line -1) 0)
3029 (throw 'exit nil))
3030 (while (setq match (car matchers))
3031 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3032 "\\(;.*\\)?$"))
3033 (throw 'exit t))
3034 (setq matchers (cdr matchers)))))
3035 (+ idlwave-continuation-indent (idlwave-current-indent)))
3037 ;; Parenthetical indent, either traditional or Kernighan style
3038 ((setq fancy-paren-indent
3039 (let* ((end-reg end-reg)
3040 (close-exp (progn
3041 (goto-char end-reg)
3042 (skip-chars-forward " \t")
3043 (looking-at "\\s)")))
3044 indent-cons)
3045 (catch 'loop
3046 (while (setq indent-cons (idlwave-calculate-paren-indent
3047 beg-reg end-reg close-exp))
3048 ;; First permitted containing paren
3049 (if (or
3050 idlwave-indent-to-open-paren
3051 idlwave-indent-parens-nested
3052 (null (cdr indent-cons))
3053 (< (- (cdr indent-cons) basic-indent)
3054 idlwave-max-extra-continuation-indent))
3055 (throw 'loop (cdr indent-cons)))
3056 (setq end-reg (car indent-cons))))))
3057 fancy-paren-indent)
3059 ;; A continued assignment, or procedure call/definition
3060 ((and
3061 (> idlwave-max-extra-continuation-indent 0)
3062 (setq fancy-nonparen-indent
3063 (progn
3064 (goto-char beg-reg)
3065 (while (idlwave-look-at "&")) ; skip continued statements
3066 (cond
3067 ;; A continued Procedure call or definition
3068 ((progn
3069 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3070 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3071 (goto-char (match-end 0))
3072 ;; Comment only, or blank line with "$"? Basic indent.
3073 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3075 (current-column)))
3077 ;; Continued assignment (with =):
3078 ((catch 'assign ;
3079 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3080 (goto-char (match-end 0))
3081 (if (null (idlwave-what-function beg-reg))
3082 (throw 'assign t))))
3083 (unless (or
3084 (idlwave-in-quote)
3085 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3086 (save-excursion
3087 (goto-char beg-last-statement)
3088 (eq (caar (idlwave-statement-type)) 'for)))
3089 (current-column))))))
3090 (< (- fancy-nonparen-indent basic-indent)
3091 idlwave-max-extra-continuation-indent))
3092 (if fancy-paren-indent ;calculated but disallowed paren indent
3093 (+ fancy-nonparen-indent idlwave-continuation-indent)
3094 fancy-nonparen-indent))
3096 ;; Basic indent, by default
3097 (t basic-indent)))))
3101 (defun idlwave-find-key (key-re &optional dir nomark limit)
3102 "Move to next match of the regular expression KEY-RE.
3103 Matches inside comments or string constants will be ignored.
3104 If DIR is negative, the search will be backwards.
3105 At a successful match, the mark is pushed unless NOMARK is non-nil.
3106 Searches are limited to LIMIT.
3107 Searches are case-insensitive and use a special syntax table which
3108 treats `$' and `_' as word characters.
3109 Return value is the beginning of the match or (in case of failure) nil."
3110 (setq dir (or dir 0))
3111 (let ((case-fold-search t)
3112 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3113 found)
3114 (idlwave-with-special-syntax
3115 (save-excursion
3116 (catch 'exit
3117 (while (funcall search-func key-re limit t)
3118 (if (not (idlwave-quoted))
3119 (throw 'exit (setq found (match-beginning 0)))
3120 (if (or (and (> dir 0) (eobp))
3121 (and (< dir 0) (bobp)))
3122 (throw 'exit nil)))))))
3123 (if found
3124 (progn
3125 (if (not nomark) (push-mark))
3126 (goto-char found)
3127 found)
3128 nil)))
3130 (defun idlwave-block-jump-out (&optional dir nomark)
3131 "When optional argument DIR is non-negative, move forward to end of
3132 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3133 regular expressions. When DIR is negative, move backwards to block beginning.
3134 Recursively calls itself to skip over nested blocks. DIR defaults to
3135 forward. Calls `push-mark' unless the optional argument NOMARK is
3136 non-nil. Movement is limited by the start of program units because of
3137 possibility of unbalanced blocks."
3138 (interactive "P")
3139 (or dir (setq dir 0))
3140 (let* ((here (point))
3141 (case-fold-search t)
3142 (limit (if (>= dir 0) (point-max) (point-min)))
3143 (block-limit (if (>= dir 0)
3144 idlwave-begin-block-reg
3145 idlwave-end-block-reg))
3146 found
3147 (block-reg (concat idlwave-begin-block-reg "\\|"
3148 idlwave-end-block-reg))
3149 (unit-limit (or (save-excursion
3150 (if (< dir 0)
3151 (idlwave-find-key
3152 idlwave-begin-unit-reg dir t limit)
3153 (end-of-line)
3154 (idlwave-find-key
3155 idlwave-end-unit-reg dir t limit)))
3156 limit)))
3157 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3158 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3159 (while (and found (looking-at block-limit))
3160 (if (>= dir 0) (forward-word 1))
3161 (idlwave-block-jump-out dir t)
3162 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3163 (if (not nomark) (push-mark here))
3164 (if (not found) (goto-char unit-limit)
3165 (if (>= dir 0) (forward-word 1)))))
3167 (defun idlwave-min-current-statement-indent (&optional end-reg)
3168 "The minimum indent in the current statement."
3169 (idlwave-beginning-of-statement)
3170 (if (not (idlwave-is-continuation-line))
3171 (idlwave-current-indent)
3172 (let ((min (idlwave-current-indent)) comm-or-empty)
3173 (while (and (= (forward-line 1) 0)
3174 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3175 (idlwave-is-continuation-line))
3176 (or (null end-reg) (< (point) end-reg)))
3177 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3178 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3180 (min min (idlwave-current-indent))))))
3182 (defun idlwave-current-statement-indent (&optional last-line)
3183 "Return indentation of the current statement.
3184 If in a statement, moves to beginning of statement before finding indent."
3185 (if last-line
3186 (idlwave-end-of-statement)
3187 (idlwave-beginning-of-statement))
3188 (idlwave-current-indent))
3190 (defun idlwave-current-indent ()
3191 "Return the column of the indentation of the current line.
3192 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3193 (save-excursion
3194 (beginning-of-line)
3195 (skip-chars-forward " \t")
3196 ;; if we are at the end of blank line return 0
3197 (cond ((eolp) 0)
3198 ((current-column)))))
3200 (defun idlwave-is-continuation-line ()
3201 "Test if current line is continuation line.
3202 Blank or comment-only lines following regular continuation lines (with
3203 `$') count as continuations too."
3204 (let (p)
3205 (save-excursion
3207 (idlwave-look-at "\\<\\$")
3208 (catch 'loop
3209 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3210 (eq (forward-line -1) 0))
3211 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
3213 (defun idlwave-is-comment-line ()
3214 "Test if the current line is a comment line."
3215 (save-excursion
3216 (beginning-of-line 1)
3217 (looking-at "[ \t]*;")))
3219 (defun idlwave-is-comment-or-empty-line ()
3220 "Test if the current line is a comment line."
3221 (save-excursion
3222 (beginning-of-line 1)
3223 (looking-at "[ \t]*[;\n]")))
3225 (defun idlwave-look-at (regexp &optional cont beg)
3226 "Search current line from current point for REGEXP.
3227 If optional argument CONT is non-nil, searches to the end of
3228 the current statement.
3229 If optional arg BEG is non-nil, search starts from the beginning of the
3230 current statement.
3231 Ignores matches that end in a comment or inside a string expression.
3232 Returns point if successful, nil otherwise.
3233 This function produces unexpected results if REGEXP contains quotes or
3234 a comment delimiter. The search is case insensitive.
3235 If successful leaves point after the match, otherwise, does not move point."
3236 (let ((here (point))
3237 (case-fold-search t)
3238 (eos (save-excursion
3239 (if cont (idlwave-end-of-statement) (end-of-line))
3240 (point)))
3241 found)
3242 (idlwave-with-special-syntax
3243 (if beg (idlwave-beginning-of-statement))
3244 (while (and (setq found (re-search-forward regexp eos t))
3245 (idlwave-quoted))))
3246 (if (not found) (goto-char here))
3247 found))
3249 (defun idlwave-fill-paragraph (&optional nohang)
3250 "Fill paragraphs in comments.
3251 A paragraph is made up of all contiguous lines having the same comment
3252 leader (the leading whitespace before the comment delimiter and the
3253 comment delimiter). In addition, paragraphs are separated by blank
3254 line comments. The indentation is given by the hanging indent of the
3255 first line, otherwise by the minimum indentation of the lines after
3256 the first line. The indentation of the first line does not change.
3257 Does not effect code lines. Does not fill comments on the same line
3258 with code. The hanging indent is given by the end of the first match
3259 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3260 If the optional argument NOHANG is non-nil then the hanging indent is
3261 ignored."
3262 (interactive "P")
3263 ;; check if this is a line comment
3264 (if (save-excursion
3265 (beginning-of-line)
3266 (skip-chars-forward " \t")
3267 (looking-at comment-start))
3268 (let
3269 ((indent 999)
3270 pre here diff fill-prefix-reg bcl first-indent
3271 hang start end)
3272 ;; Change tabs to spaces in the surrounding paragraph.
3273 ;; The surrounding paragraph will be the largest containing block of
3274 ;; contiguous line comments. Thus, we may be changing tabs in
3275 ;; a much larger area than is needed, but this is the easiest
3276 ;; brute force way to do it.
3278 ;; This has the undesirable side effect of replacing the tabs
3279 ;; permanently without the user's request or knowledge.
3280 (save-excursion
3281 (backward-paragraph)
3282 (setq start (point)))
3283 (save-excursion
3284 (forward-paragraph)
3285 (setq end (point)))
3286 (untabify start end)
3288 (setq here (point))
3289 (beginning-of-line)
3290 (setq bcl (point))
3291 (re-search-forward (concat "^[ \t]*" comment-start "+")
3292 (point-at-eol) t)
3293 ;; Get the comment leader on the line and its length
3294 (setq pre (current-column))
3295 ;; the comment leader is the indentation plus exactly the
3296 ;; number of consecutive ";".
3297 (setq fill-prefix-reg
3298 (concat
3299 (setq fill-prefix
3300 (regexp-quote (buffer-substring (point-at-bol) (point))))
3301 "[^;]"))
3303 ;; Mark the beginning and end of the paragraph
3304 (goto-char bcl)
3305 (while (and (looking-at fill-prefix-reg)
3306 (not (looking-at paragraph-separate))
3307 (not (bobp)))
3308 (forward-line -1))
3309 ;; Move to first line of paragraph
3310 (if (/= (point) bcl)
3311 (forward-line 1))
3312 (setq start (point))
3313 (goto-char bcl)
3314 (while (and (looking-at fill-prefix-reg)
3315 (not (looking-at paragraph-separate))
3316 (not (eobp)))
3317 (forward-line 1))
3318 (beginning-of-line)
3319 (if (or (not (looking-at fill-prefix-reg))
3320 (looking-at paragraph-separate))
3321 (forward-line -1))
3322 (end-of-line)
3323 ;; if at end of buffer add a newline (need this because
3324 ;; fill-region needs END to be at the beginning of line after
3325 ;; the paragraph or it will add a line).
3326 (if (eobp)
3327 (progn (insert ?\n) (backward-char 1)))
3328 ;; Set END to the beginning of line after the paragraph
3329 ;; END is calculated as distance from end of buffer
3330 (setq end (- (point-max) (point) 1))
3332 ;; Calculate the indentation for the paragraph.
3334 ;; In the following while statements, after one iteration
3335 ;; point will be at the beginning of a line in which case
3336 ;; the while will not be executed for the
3337 ;; the first paragraph line and thus will not affect the
3338 ;; indentation.
3340 ;; First check to see if indentation is based on hanging indent.
3341 (if (and (not nohang) idlwave-hanging-indent
3342 (setq hang
3343 (save-excursion
3344 (goto-char start)
3345 (idlwave-calc-hanging-indent))))
3346 ;; Adjust lines of paragraph by inserting spaces so that
3347 ;; each line's indent is at least as great as the hanging
3348 ;; indent. This is needed for fill-paragraph to work with
3349 ;; a fill-prefix.
3350 (progn
3351 (setq indent hang)
3352 (beginning-of-line)
3353 (while (> (point) start)
3354 (re-search-forward comment-start-skip (point-at-eol) t)
3355 (if (> (setq diff (- indent (current-column))) 0)
3356 (progn
3357 (if (>= here (point))
3358 ;; adjust the original location for the
3359 ;; inserted text.
3360 (setq here (+ here diff)))
3361 (insert (make-string diff ?\ ))))
3362 (forward-line -1))
3365 ;; No hang. Instead find minimum indentation of paragraph
3366 ;; after first line.
3367 ;; For the following while statement, since START is at the
3368 ;; beginning of line and END is at the end of line
3369 ;; point is greater than START at least once (which would
3370 ;; be the case for a single line paragraph).
3371 (while (> (point) start)
3372 (beginning-of-line)
3373 (setq indent
3374 (min indent
3375 (progn
3376 (re-search-forward comment-start-skip (point-at-eol) t)
3377 (current-column))))
3378 (forward-line -1)))
3379 (setq fill-prefix (concat fill-prefix
3380 (make-string (- indent pre)
3381 ?\ )))
3382 ;; first-line indent
3383 (setq first-indent
3384 (max
3385 (progn
3386 (re-search-forward comment-start-skip (point-at-eol) t)
3387 (current-column))
3388 indent))
3390 ;; try to keep point at its original place
3391 (goto-char here)
3393 ;; In place of the more modern fill-region-as-paragraph, a hack
3394 ;; to keep whitespace untouched on the first line within the
3395 ;; indent length and to preserve any indent on the first line
3396 ;; (first indent).
3397 (save-excursion
3398 (setq diff
3399 (buffer-substring start (+ start first-indent -1)))
3400 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3401 (fill-region-as-paragraph
3402 start
3403 (- (point-max) end)
3404 (current-justification)
3405 nil)
3406 (delete-region start (+ start first-indent -1))
3407 (goto-char start)
3408 (insert diff))
3409 ;; When we want the point at the beginning of the comment
3410 ;; body fill-region will put it at the beginning of the line.
3411 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3412 (setq fill-prefix nil))))
3414 (defun idlwave-calc-hanging-indent ()
3415 "Calculate the position of the hanging indent for the comment paragraph.
3416 The hanging indent position is given by the first match with the
3417 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3418 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3419 on the line.
3420 If not found returns nil."
3421 (if idlwave-use-last-hang-indent
3422 (save-excursion
3423 (end-of-line)
3424 (if (re-search-backward idlwave-hang-indent-regexp (point-at-bol) t)
3425 (+ (current-column) (length idlwave-hang-indent-regexp))))
3426 (save-excursion
3427 (beginning-of-line)
3428 (if (re-search-forward idlwave-hang-indent-regexp (point-at-eol) t)
3429 (current-column)))))
3431 (defun idlwave-auto-fill ()
3432 "Called to break lines in auto fill mode.
3433 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3434 non-nil. Places a continuation character at the end of the line if
3435 not in a comment. Splits strings with IDL concatenation operator `+'
3436 if `idlwave-auto-fill-split-string' is non-nil."
3437 (if (<= (current-column) fill-column)
3438 nil ; do not to fill
3439 (if (or (not idlwave-fill-comment-line-only)
3440 (save-excursion
3441 ;; Check for comment line
3442 (beginning-of-line)
3443 (looking-at idlwave-comment-line-start-skip)))
3444 (let (beg)
3445 (idlwave-indent-line)
3446 ;; Prevent actions do-auto-fill which calls indent-line-function.
3447 (let (idlwave-do-actions
3448 (paragraph-separate ".")
3449 (fill-nobreak-predicate
3450 (if (and (idlwave-in-quote)
3451 idlwave-auto-fill-split-string)
3452 (lambda () ;; We'll need 5 spaces for " ' + $"
3453 (<= (- fill-column (current-column)) 5)
3454 ))))
3455 (do-auto-fill))
3456 (save-excursion
3457 (end-of-line 0)
3458 ;; Indent the split line
3459 (idlwave-indent-line))
3460 (if (save-excursion
3461 (beginning-of-line)
3462 (looking-at idlwave-comment-line-start-skip))
3463 ;; A continued line comment
3464 ;; We treat continued line comments as part of a comment
3465 ;; paragraph. So we check for a hanging indent.
3466 (if idlwave-hanging-indent
3467 (let ((here (- (point-max) (point)))
3468 (indent
3469 (save-excursion
3470 (forward-line -1)
3471 (idlwave-calc-hanging-indent))))
3472 (when indent
3473 ;; Remove whitespace between comment delimiter and
3474 ;; text, insert spaces for appropriate indentation.
3475 (beginning-of-line)
3476 (re-search-forward comment-start-skip (point-at-eol) t)
3477 (delete-horizontal-space)
3478 (idlwave-indent-to indent)
3479 (goto-char (- (point-max) here)))))
3480 ;; Split code or comment?
3481 (if (save-excursion
3482 (end-of-line 0)
3483 (idlwave-in-comment))
3484 ;; Splitting a non-full-line comment.
3485 ;; Insert the comment delimiter from split line
3486 (progn
3487 (save-excursion
3488 (beginning-of-line)
3489 (skip-chars-forward " \t")
3490 ;; Insert blank to keep off beginning of line
3491 (insert " "
3492 (save-excursion
3493 (forward-line -1)
3494 (buffer-substring (idlwave-goto-comment)
3495 (progn
3496 (skip-chars-forward "; ")
3497 (point))))))
3498 (idlwave-indent-line))
3499 ;; Split code line - add continuation character
3500 (save-excursion
3501 (end-of-line 0)
3502 ;; Check to see if we split a string
3503 (if (and (setq beg (idlwave-in-quote))
3504 idlwave-auto-fill-split-string)
3505 ;; Split the string and concatenate.
3506 ;; The first extra space is for the space
3507 ;; the line was split. That space was removed.
3508 (insert " " (char-after beg) " +"))
3509 (insert " $"))
3510 (if beg
3511 (if idlwave-auto-fill-split-string
3512 ;; Make the second part of continued string
3513 (save-excursion
3514 (beginning-of-line)
3515 (skip-chars-forward " \t")
3516 (insert (char-after beg)))
3517 ;; Warning
3518 (beep)
3519 (message "Warning: continuation inside a string.")))
3520 ;; Although do-auto-fill (via indent-new-comment-line) calls
3521 ;; idlwave-indent-line for the new line, re-indent again
3522 ;; because of the addition of the continuation character.
3523 (idlwave-indent-line))
3524 )))))
3526 (defun idlwave-auto-fill-mode (arg)
3527 "Toggle auto-fill mode for IDL mode.
3528 With arg, turn auto-fill mode on if arg is positive.
3529 In auto-fill mode, inserting a space at a column beyond `fill-column'
3530 automatically breaks the line at a previous space."
3531 (interactive "P")
3532 (prog1 (set idlwave-fill-function
3533 (if (if (null arg)
3534 (not (symbol-value idlwave-fill-function))
3535 (> (prefix-numeric-value arg) 0))
3536 'idlwave-auto-fill
3537 nil))
3538 ;; update mode-line
3539 (set-buffer-modified-p (buffer-modified-p))))
3541 ;(defun idlwave-fill-routine-call ()
3542 ; "Fill a routine definition or statement, indenting appropriately."
3543 ; (let ((where (idlwave-where)))))
3546 (defun idlwave-doc-header (&optional nomark)
3547 "Insert a documentation header at the beginning of the unit.
3548 Inserts the value of the variable `idlwave-file-header'. Sets mark
3549 before moving to do insertion unless the optional prefix argument
3550 NOMARK is non-nil."
3551 (interactive "P")
3552 (or nomark (push-mark))
3553 ;; make sure we catch the current line if it begins the unit
3554 (if idlwave-header-to-beginning-of-file
3555 (goto-char (point-min))
3556 (end-of-line)
3557 (idlwave-beginning-of-subprogram)
3558 (beginning-of-line)
3559 ;; skip function or procedure line
3560 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3561 (progn
3562 (idlwave-end-of-statement)
3563 (if (> (forward-line 1) 0) (insert "\n")))))
3564 (let ((pos (point)))
3565 (if idlwave-file-header
3566 (cond ((car idlwave-file-header)
3567 (insert-file-contents (car idlwave-file-header)))
3568 ((stringp (car (cdr idlwave-file-header)))
3569 (insert (car (cdr idlwave-file-header))))))
3570 (goto-char pos)))
3572 (defun idlwave-default-insert-timestamp ()
3573 "Default timestamp insertion function."
3574 (insert (current-time-string))
3575 (insert ", " (user-full-name))
3576 (if (boundp 'user-mail-address)
3577 (insert " <" user-mail-address ">")
3578 (insert " <" (user-login-name) "@" (system-name) ">"))
3579 ;; Remove extra spaces from line
3580 (idlwave-fill-paragraph)
3581 ;; Insert a blank line comment to separate from the date entry -
3582 ;; will keep the entry from flowing onto date line if re-filled.
3583 (insert "\n;\n;\t\t"))
3585 (defun idlwave-doc-modification ()
3586 "Insert a brief modification log at the beginning of the current program.
3587 Looks for an occurrence of the value of user variable
3588 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3589 name and places the point for the user to add a log. Before moving, saves
3590 location on mark ring so that the user can return to previous point."
3591 (interactive)
3592 (push-mark)
3593 (let* (beg end)
3594 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3595 (progn
3596 (goto-char (point-min))
3597 (re-search-forward idlwave-doclib-start nil t)))
3598 (setq beg (match-beginning 0))
3599 (re-search-forward idlwave-doclib-end nil t)
3600 (setq end (match-end 0)))
3601 (progn
3602 (goto-char beg)
3603 (if (re-search-forward
3604 (concat idlwave-doc-modifications-keyword ":")
3605 end t)
3606 (end-of-line)
3607 (goto-char end)
3608 (end-of-line -1)
3609 (insert "\n" comment-start "\n")
3610 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3611 (insert "\n;\n;\t")
3612 (run-hooks 'idlwave-timestamp-hook))
3613 (error "No valid DOCLIB header"))))
3616 ;; CJC 3/16/93
3617 ;; Interface to expand-region-abbrevs which did not work when the
3618 ;; abbrev hook associated with an abbrev moves point backwards
3619 ;; after abbrev expansion, e.g., as with the abbrev '.n'.
3620 ;; The original would enter an infinite loop in attempting to expand
3621 ;; .n (it would continually expand and unexpand the abbrev without expanding
3622 ;; because the point would keep going back to the beginning of the
3623 ;; abbrev instead of to the end of the abbrev). We now keep the
3624 ;; abbrev hook from moving backwards.
3626 (defun idlwave-expand-region-abbrevs (start end)
3627 "Expand each abbrev occurrence in the region.
3628 Calling from a program, arguments are START END."
3629 (interactive "r")
3630 (save-excursion
3631 (goto-char (min start end))
3632 (let ((idlwave-show-block nil) ;Do not blink
3633 (idlwave-abbrev-move nil)) ;Do not move
3634 (expand-region-abbrevs start end 'noquery))))
3636 (defun idlwave-quoted ()
3637 "Return t if point is in a comment or quoted string.
3638 Returns nil otherwise."
3639 (or (idlwave-in-comment) (idlwave-in-quote)))
3641 (defun idlwave-in-quote ()
3642 "Return location of the opening quote
3643 if point is in a IDL string constant, nil otherwise.
3644 Ignores comment delimiters on the current line.
3645 Properly handles nested quotation marks and octal
3646 constants - a double quote followed by an octal digit."
3647 ;; Treat an octal inside an apostrophe to be a normal string. Treat a
3648 ;; double quote followed by an octal digit to be an octal constant
3649 ;; rather than a string. Therefore, there is no terminating double
3650 ;; quote.
3651 (save-excursion
3652 ;; Because single and double quotes can quote each other we must
3653 ;; search for the string start from the beginning of line.
3654 (let* ((start (point))
3655 (eol (point-at-eol))
3656 (bq (progn (beginning-of-line) (point)))
3657 (endq (point))
3658 (data (match-data))
3659 delim
3660 found)
3661 (while (< endq start)
3662 ;; Find string start
3663 ;; Don't find an octal constant beginning with a double quote
3664 (if (re-search-forward "[\"']" eol 'lim)
3665 ;; Find the string end.
3666 ;; In IDL, two consecutive delimiters after the start of a
3667 ;; string act as an
3668 ;; escape for the delimiter in the string.
3669 ;; Two consecutive delimiters alone (i.e., not after the
3670 ;; start of a string) is the null string.
3671 (progn
3672 ;; Move to position after quote
3673 (goto-char (1+ (match-beginning 0)))
3674 (setq bq (1- (point)))
3675 ;; Get the string delimiter
3676 (setq delim (char-to-string (preceding-char)))
3677 ;; Check for null string
3678 (if (looking-at delim)
3679 (progn (setq endq (point)) (forward-char 1))
3680 ;; Look for next unpaired delimiter
3681 (setq found (search-forward delim eol 'lim))
3682 (while (looking-at delim)
3683 (forward-char 1)
3684 (setq found (search-forward delim eol 'lim)))
3685 (setq endq (if found (1- (point)) (point)))
3687 (progn (setq bq (point)) (setq endq (point)))))
3688 (store-match-data data)
3689 ;; return string beginning position or nil
3690 (if (> start bq) bq))))
3692 (defun idlwave-is-pointer-dereference (&optional limit)
3693 "Determine if the character after point is a pointer dereference *."
3694 (and
3695 (eq (char-after) ?\*)
3696 (not (idlwave-in-quote))
3697 (save-excursion
3698 (forward-char)
3699 (re-search-backward (concat "\\(" idlwave-idl-keywords
3700 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
3703 ;; Statement templates
3705 ;; Replace these with a general template function, something like
3706 ;; expand.el (I think there was also something with a name similar to
3707 ;; dmacro.el)
3709 (defun idlwave-template (s1 s2 &optional prompt noindent)
3710 "Build a template with optional prompt expression.
3712 Opens a line if point is not followed by a newline modulo intervening
3713 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3714 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3715 adjusted according to `idlwave-abbrev-change-case'. If optional
3716 argument PROMPT is a string then it is displayed as a message in the
3717 minibuffer. The PROMPT serves as a reminder to the user of an
3718 expression to enter.
3720 The lines containing S1 and S2 are reindented using `indent-region'
3721 unless the optional second argument NOINDENT is non-nil."
3722 (if (derived-mode-p 'idlwave-shell-mode)
3723 ;; This is a gross hack to avoit template abbrev expansion
3724 ;; in the shell. FIXME: This is a dirty hack.
3725 (if (and (eq this-command 'self-insert-command)
3726 (equal last-abbrev-location (point)))
3727 (insert last-abbrev-text)
3728 (error "No templates in idlwave-shell"))
3729 (cond ((eq idlwave-abbrev-change-case 'down)
3730 (setq s1 (downcase s1) s2 (downcase s2)))
3731 (idlwave-abbrev-change-case
3732 (setq s1 (upcase s1) s2 (upcase s2))))
3733 (let ((beg (point-at-bol))
3734 end)
3735 (if (not (looking-at "\\s-*\n"))
3736 (open-line 1))
3737 (insert s1)
3738 (save-excursion
3739 (insert s2)
3740 (setq end (point)))
3741 (if (not noindent)
3742 (indent-region beg end nil))
3743 (if (stringp prompt)
3744 (message "%s" prompt)))))
3746 (defun idlwave-rw-case (string)
3747 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3748 (if idlwave-reserved-word-upcase
3749 (upcase string)
3750 string))
3752 (defun idlwave-elif ()
3753 "Build skeleton IDL if-else block."
3754 (interactive)
3755 (idlwave-template
3756 (idlwave-rw-case "if")
3757 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3758 "Condition expression"))
3760 (defun idlwave-case ()
3761 "Build skeleton IDL case statement."
3762 (interactive)
3763 (idlwave-template
3764 (idlwave-rw-case "case")
3765 (idlwave-rw-case " of\n\nendcase")
3766 "Selector expression"))
3768 (defun idlwave-switch ()
3769 "Build skeleton IDL switch statement."
3770 (interactive)
3771 (idlwave-template
3772 (idlwave-rw-case "switch")
3773 (idlwave-rw-case " of\n\nendswitch")
3774 "Selector expression"))
3776 (defun idlwave-for ()
3777 "Build skeleton IDL loop statement."
3778 (interactive)
3779 (idlwave-template
3780 (idlwave-rw-case "for")
3781 (idlwave-rw-case " do begin\n\nendfor")
3782 "Loop expression"))
3784 (defun idlwave-if ()
3785 "Build skeleton IDL if statement."
3786 (interactive)
3787 (idlwave-template
3788 (idlwave-rw-case "if")
3789 (idlwave-rw-case " then begin\n\nendif")
3790 "Scalar logical expression"))
3792 (defun idlwave-procedure ()
3793 (interactive)
3794 (idlwave-template
3795 (idlwave-rw-case "pro")
3796 (idlwave-rw-case "\n\nreturn\nend")
3797 "Procedure name"))
3799 (defun idlwave-function ()
3800 (interactive)
3801 (idlwave-template
3802 (idlwave-rw-case "function")
3803 (idlwave-rw-case "\n\nreturn\nend")
3804 "Function name"))
3806 (defun idlwave-repeat ()
3807 (interactive)
3808 (idlwave-template
3809 (idlwave-rw-case "repeat begin\n\nendrep until")
3810 (idlwave-rw-case "")
3811 "Exit condition"))
3813 (defun idlwave-while ()
3814 (interactive)
3815 (idlwave-template
3816 (idlwave-rw-case "while")
3817 (idlwave-rw-case " do begin\n\nendwhile")
3818 "Entry condition"))
3820 (defun idlwave-split-string (string &optional pattern)
3821 "Return a list of substrings of STRING which are separated by PATTERN.
3822 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3823 (or pattern
3824 (setq pattern "[ \f\t\n\r\v]+"))
3825 (let (parts (start 0))
3826 (while (string-match pattern string start)
3827 (setq parts (cons (substring string start (match-beginning 0)) parts)
3828 start (match-end 0)))
3829 (nreverse (cons (substring string start) parts))))
3831 (defun idlwave-replace-string (string replace_string replace_with)
3832 (let* ((start 0)
3833 (last (length string))
3834 (ret_string "")
3835 end)
3836 (while (setq end (string-match replace_string string start))
3837 (setq ret_string
3838 (concat ret_string (substring string start end) replace_with))
3839 (setq start (match-end 0)))
3840 (setq ret_string (concat ret_string (substring string start last)))))
3842 (defun idlwave-get-buffer-visiting (file)
3843 ;; Return the buffer currently visiting FILE
3844 (cond
3845 ((boundp 'find-file-compare-truenames) ; XEmacs
3846 (let ((find-file-compare-truenames t))
3847 (get-file-buffer file)))
3848 ((fboundp 'find-buffer-visiting) ; Emacs
3849 (find-buffer-visiting file))
3850 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3852 (defvar idlwave-outlawed-buffers nil
3853 "List of buffers pulled up by IDLWAVE for special reasons.
3854 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3856 (defun idlwave-find-file-noselect (file &optional why)
3857 ;; Return a buffer visiting file.
3858 (or (idlwave-get-buffer-visiting file)
3859 (let ((buf (find-file-noselect file)))
3860 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3861 buf)))
3863 (defun idlwave-kill-autoloaded-buffers ()
3864 "Kill buffers created automatically by IDLWAVE.
3865 Function prompts for a letter to identify the buffers to kill.
3866 Possible letters are:
3868 f Buffers created by the command \\[idlwave-find-module] or mouse
3869 clicks in the routine info window.
3870 s Buffers created by the IDLWAVE Shell to display where execution
3871 stopped or an error was found.
3872 a Both of the above.
3874 Buffers containing unsaved changes require confirmation before they are killed."
3875 (interactive)
3876 (if (null idlwave-outlawed-buffers)
3877 (error "No IDLWAVE-created buffers available")
3878 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3879 (idlwave-count-outlawed-buffers 'find)
3880 (idlwave-count-outlawed-buffers 'shell)))
3881 (let ((c (read-char)))
3882 (cond
3883 ((member c '(?f ?\C-f))
3884 (idlwave-do-kill-autoloaded-buffers 'find))
3885 ((member c '(?s ?\C-s))
3886 (idlwave-do-kill-autoloaded-buffers 'shell))
3887 ((member c '(?a ?\C-a))
3888 (idlwave-do-kill-autoloaded-buffers t))
3889 (t (error "Abort"))))))
3891 (defun idlwave-count-outlawed-buffers (tag)
3892 "How many outlawed buffers have tag TAG?"
3893 (length (delq nil
3894 (mapcar
3895 (lambda (x) (eq (cdr x) tag))
3896 idlwave-outlawed-buffers))))
3898 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3899 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3900 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3901 (cnt 0)
3902 entry)
3903 (while (setq entry (pop list))
3904 (if (buffer-live-p (car entry))
3905 (and (or (memq t reasons)
3906 (memq (cdr entry) reasons))
3907 (kill-buffer (car entry))
3908 (incf cnt)
3909 (setq idlwave-outlawed-buffers
3910 (delq entry idlwave-outlawed-buffers)))
3911 (setq idlwave-outlawed-buffers
3912 (delq entry idlwave-outlawed-buffers))))
3913 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3915 (defun idlwave-revoke-license-to-kill ()
3916 "Remove BUFFER from the buffers which may be killed.
3917 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3918 Intended for `after-save-hook'."
3919 (let* ((buf (current-buffer))
3920 (entry (assq buf idlwave-outlawed-buffers)))
3921 ;; Revoke license
3922 (if entry
3923 (setq idlwave-outlawed-buffers
3924 (delq entry idlwave-outlawed-buffers)))
3925 ;; Remove this function from the hook.
3926 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3928 (defvar idlwave-path-alist)
3929 (defun idlwave-locate-lib-file (file)
3930 ;; Find FILE on the scanned lib path and return a buffer visiting it
3931 (let* ((dirs idlwave-path-alist)
3932 dir efile)
3933 (catch 'exit
3934 (while (setq dir (car (pop dirs)))
3935 (if (file-regular-p
3936 (setq efile (expand-file-name file dir)))
3937 (throw 'exit efile))))))
3939 (defun idlwave-expand-lib-file-name (file)
3940 ;; Find FILE on the scanned lib path and return a buffer visiting it
3941 ;; This is for, e.g., finding source with no user catalog
3942 (cond
3943 ((null file) nil)
3944 ((file-name-absolute-p file) file)
3945 (t (idlwave-locate-lib-file file))))
3947 (defun idlwave-make-tags ()
3948 "Create the IDL tags file IDLTAGS in the current directory from
3949 the list of directories specified in the minibuffer. Directories may be
3950 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3951 specified top directories are searched if the directory name is prefixed
3952 by @. Specify @ directories with care, it may take a long, long time if
3953 you specify /."
3954 (interactive)
3955 (let (directory directories cmd append status numdirs dir getsubdirs
3956 buffer save_buffer files numfiles item errbuf)
3959 ;; Read list of directories
3960 (setq directory (read-string "Tag Directories: " "."))
3961 (setq directories (idlwave-split-string directory "[ \t]+"))
3963 ;; Set etags command, vars
3964 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3965 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3966 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3967 (setq append " ")
3968 (setq status 0)
3970 ;; For each directory
3971 (setq numdirs 0)
3972 (setq dir (nth numdirs directories))
3973 (while (and dir)
3975 ;; Find the subdirectories
3976 (if (string-match "^[@]\\(.+\\)$" dir)
3977 (setq getsubdirs t) (setq getsubdirs nil))
3978 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3979 (setq dir (expand-file-name dir))
3980 (if (file-directory-p dir)
3981 (progn
3982 (if (and getsubdirs)
3983 (progn
3984 (setq buffer (get-buffer-create "*idltags*"))
3985 (call-process "sh" nil buffer nil "-c"
3986 (concat "find " dir " -type d -print"))
3987 (setq save_buffer (current-buffer))
3988 (set-buffer buffer)
3989 (setq files (idlwave-split-string
3990 (idlwave-replace-string
3991 (buffer-substring 1 (point-max))
3992 "\n" "/*.pro ")
3993 "[ \t]+"))
3994 (set-buffer save_buffer)
3995 (kill-buffer buffer))
3996 (setq files (list (concat dir "/*.pro"))))
3998 ;; For each subdirectory
3999 (setq numfiles 0)
4000 (setq item (nth numfiles files))
4001 (while (and item)
4003 ;; Call etags
4004 (if (not (string-match "^[ \\t]*$" item))
4005 (progn
4006 (message "%s" (concat "Tagging " item "..."))
4007 (setq errbuf (get-buffer-create "*idltags-error*"))
4008 (setq status (+ status
4009 (if (eq 0 (call-process
4010 "sh" nil errbuf nil "-c"
4011 (concat cmd append item)))
4013 1)))
4015 ;; Append additional tags
4016 (setq append " --append ")
4017 (setq numfiles (1+ numfiles))
4018 (setq item (nth numfiles files)))
4019 (progn
4020 (setq numfiles (1+ numfiles))
4021 (setq item (nth numfiles files))
4024 (setq numdirs (1+ numdirs))
4025 (setq dir (nth numdirs directories)))
4026 (progn
4027 (setq numdirs (1+ numdirs))
4028 (setq dir (nth numdirs directories)))))
4030 (setq errbuf (get-buffer-create "*idltags-error*"))
4031 (if (= status 0)
4032 (kill-buffer errbuf))
4033 (message "")
4036 (defun idlwave-toggle-comment-region (beg end &optional n)
4037 "Comment the lines in the region if the first non-blank line is
4038 commented, and conversely, uncomment region. If optional prefix arg
4039 N is non-nil, then for N positive, add N comment delimiters or for N
4040 negative, remove N comment delimiters.
4041 Uses `comment-region' which does not place comment delimiters on
4042 blank lines."
4043 (interactive "r\nP")
4044 (if n
4045 (comment-region beg end (prefix-numeric-value n))
4046 (save-excursion
4047 (goto-char beg)
4048 (beginning-of-line)
4049 ;; skip blank lines
4050 (skip-chars-forward " \t\n")
4051 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4052 (if (fboundp 'uncomment-region)
4053 (uncomment-region beg end)
4054 (comment-region beg end
4055 (- (length (buffer-substring
4056 (match-beginning 1)
4057 (match-end 1))))))
4058 (comment-region beg end)))))
4061 ;; ----------------------------------------------------------------------------
4062 ;; ----------------------------------------------------------------------------
4063 ;; ----------------------------------------------------------------------------
4064 ;; ----------------------------------------------------------------------------
4066 ;; Completion and Routine Info
4069 ;; String "intern" functions
4071 ;; For the completion and routine info function, we want to normalize
4072 ;; the case of procedure names etc. We do this by "interning" these
4073 ;; string is a hand-crafted way. Hashes are used to map the downcase
4074 ;; version of the strings to the cased versions. Most *-sint-*
4075 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4076 ;; system hash. The former is re-scanned, and the latter takes case
4077 ;; precedence.
4079 ;; Since these cased versions are really lisp objects, we can use `eq'
4080 ;; to search, which is a large performance boost. All new strings
4081 ;; need to be "sinterned". We do this as early as possible after
4082 ;; getting these strings from completion or buffer substrings. So
4083 ;; most of the code can simply assume to deal with "sinterned"
4084 ;; strings. The only exception is that the functions which scan whole
4085 ;; buffers for routine information do not intern the grabbed strings.
4086 ;; This is only done afterwards. Therefore in these functions it is
4087 ;; *not* safe to assume the strings can be compared with `eq' and be
4088 ;; fed into the routine assq functions.
4090 ;; Here we define the hashing functions.
4092 ;; The variables which hold the hashes.
4093 (defvar idlwave-sint-routines '(nil))
4094 (defvar idlwave-sint-keywords '(nil))
4095 (defvar idlwave-sint-methods '(nil))
4096 (defvar idlwave-sint-classes '(nil))
4097 (defvar idlwave-sint-dirs '(nil))
4098 (defvar idlwave-sint-libnames '(nil))
4100 (defun idlwave-reset-sintern (&optional what)
4101 "Reset all sintern hashes."
4102 ;; Make sure the hash functions are accessible.
4103 (unless (and (fboundp 'gethash)
4104 (fboundp 'puthash))
4105 (require 'cl)
4106 (or (fboundp 'puthash)
4107 (defalias 'puthash 'cl-puthash)))
4108 (let ((entries '((idlwave-sint-routines 1000 10)
4109 (idlwave-sint-keywords 1000 10)
4110 (idlwave-sint-methods 100 10)
4111 (idlwave-sint-classes 10 10))))
4113 ;; Make sure these are lists
4114 (loop for entry in entries
4115 for var = (car entry)
4116 do (if (not (consp (symbol-value var))) (set var (list nil))))
4118 ;; Reset the system & library hash
4119 (when (or (eq what t) (eq what 'syslib)
4120 (null (cdr idlwave-sint-routines)))
4121 (loop for entry in entries
4122 for var = (car entry) for size = (nth 1 entry)
4123 do (setcdr (symbol-value var)
4124 (make-hash-table ':size size ':test 'equal)))
4125 (setq idlwave-sint-dirs nil
4126 idlwave-sint-libnames nil))
4128 ;; Reset the buffer & shell hash
4129 (when (or (eq what t) (eq what 'bufsh)
4130 (null (car idlwave-sint-routines)))
4131 (loop for entry in entries
4132 for var = (car entry) for size = (nth 1 entry)
4133 do (setcar (symbol-value var)
4134 (make-hash-table ':size size ':test 'equal))))))
4136 (defun idlwave-sintern-routine-or-method (name &optional class set)
4137 (if class
4138 (idlwave-sintern-method name set)
4139 (idlwave-sintern-routine name set)))
4141 (defun idlwave-sintern (stype &rest args)
4142 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4144 ;;(defmacro idlwave-sintern (type var)
4145 ;; `(cond ((not (stringp name)) name)
4146 ;; ((gethash (downcase name) (cdr ,var)))
4147 ;; ((gethash (downcase name) (car ,var)))
4148 ;; (set (idlwave-sintern-set name ,type ,var set))
4149 ;; (name)))
4151 (defun idlwave-sintern-routine (name &optional set)
4152 (cond ((not (stringp name)) name)
4153 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4154 ((gethash (downcase name) (car idlwave-sint-routines)))
4155 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4156 (name)))
4157 (defun idlwave-sintern-keyword (name &optional set)
4158 (cond ((not (stringp name)) name)
4159 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4160 ((gethash (downcase name) (car idlwave-sint-keywords)))
4161 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4162 (name)))
4163 (defun idlwave-sintern-method (name &optional set)
4164 (cond ((not (stringp name)) name)
4165 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4166 ((gethash (downcase name) (car idlwave-sint-methods)))
4167 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4168 (name)))
4169 (defun idlwave-sintern-class (name &optional set)
4170 (cond ((not (stringp name)) name)
4171 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4172 ((gethash (downcase name) (car idlwave-sint-classes)))
4173 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4174 (name)))
4176 (defun idlwave-sintern-dir (dir &optional set)
4177 (car (or (member dir idlwave-sint-dirs)
4178 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4179 (defun idlwave-sintern-libname (name &optional set)
4180 (car (or (member name idlwave-sint-libnames)
4181 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4183 (defun idlwave-sintern-set (name type tables set)
4184 (let* ((func (or (cdr (assq type idlwave-completion-case))
4185 'identity))
4186 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4187 (table (if (eq set 'sys) (cdr tables) (car tables))))
4188 (puthash (downcase name) iname table)
4189 iname))
4191 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4192 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4193 (mapc (lambda(x)
4194 (setcar x (idlwave-sintern-keyword (car x) set)))
4195 (cdr kwd-list))
4196 kwd-list)
4198 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4199 "Sintern all strings in the rinfo LIST.
4200 With optional parameter SET: also set new patterns. Probably this
4201 will always have to be t. If DEFAULT-DIR is passed, it is used as
4202 the base of the directory."
4203 (let (entry name type class kwds res source call new)
4204 (while list
4205 (setq entry (car list)
4206 list (cdr list)
4207 name (car entry)
4208 type (nth 1 entry)
4209 class (nth 2 entry)
4210 source (nth 3 entry)
4211 call (nth 4 entry)
4212 kwds (nthcdr 5 entry))
4214 ;; The class and name
4215 (if class
4216 (progn
4217 (if (symbolp class) (setq class (symbol-name class)))
4218 (setq class (idlwave-sintern-class class set))
4219 (setq name (idlwave-sintern-method name set)))
4220 (setq name (idlwave-sintern-routine name set)))
4222 ;; The source
4223 (let ((source-type (car source))
4224 (source-file (nth 1 source))
4225 (source-dir (if default-dir
4226 (file-name-as-directory default-dir)
4227 (nth 2 source)))
4228 (source-lib (nth 3 source)))
4229 (if (stringp source-dir)
4230 (setq source-dir (idlwave-sintern-dir source-dir set)))
4231 (if (stringp source-lib)
4232 (setq source-lib (idlwave-sintern-libname source-lib set)))
4233 (setq source (list source-type source-file source-dir source-lib)))
4235 ;; The keywords
4236 (setq kwds (mapcar (lambda (x)
4237 (idlwave-sintern-keyword-list x set))
4238 kwds))
4240 ;; Build a canonicalized list
4241 (setq new (nconc (list name type class source call) kwds)
4242 res (cons new res)))
4243 (nreverse res)))
4245 ;; Creating new sintern tables
4247 (defun idlwave-new-sintern-type (tag)
4248 "Define a variable and a function to sintern the new type TAG.
4249 This defines the function `idlwave-sintern-TAG' and the variable
4250 `idlwave-sint-TAGs'."
4251 (let* ((name (symbol-name tag))
4252 (names (concat name "s"))
4253 (var (intern (concat "idlwave-sint-" names)))
4254 (func (intern (concat "idlwave-sintern-" name))))
4255 (set var nil) ; initial value of the association list
4256 (fset func ; set the function
4257 `(lambda (name &optional set)
4258 (cond ((not (stringp name)) name)
4259 ((cdr (assoc (downcase name) ,var)))
4260 (set
4261 (setq ,var (cons (cons (downcase name) name) ,var))
4262 name)
4263 (name))))))
4265 (defun idlwave-reset-sintern-type (tag)
4266 "Reset the sintern variable associated with TAG."
4267 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4269 ;;---------------------------------------------------------------------------
4272 ;; The variables which hold the information
4273 (defvar idlwave-system-routines nil
4274 "Holds the routine-info obtained by scanning buffers.")
4275 (defvar idlwave-buffer-routines nil
4276 "Holds the routine-info obtained by scanning buffers.")
4277 (defvar idlwave-compiled-routines nil
4278 "Holds the routine-info obtained by asking the shell.")
4279 (defvar idlwave-unresolved-routines nil
4280 "Holds the unresolved routine-info obtained by asking the shell.")
4281 (defvar idlwave-user-catalog-routines nil
4282 "Holds the procedure routine-info from the user scan.")
4283 (defvar idlwave-library-catalog-routines nil
4284 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4285 (defvar idlwave-library-catalog-libname nil
4286 "Name of library catalog loaded from .idlwave_catalog files.")
4287 (defvar idlwave-path-alist nil
4288 "Alist with !PATH directories and zero or more flags if the dir has
4289 been scanned in a user catalog ('user) or discovered in a library
4290 catalog \('lib).")
4291 (defvar idlwave-true-path-alist nil
4292 "Like `idlwave-path-alist', but with true filenames.")
4293 (defvar idlwave-routines nil
4294 "Holds the combined procedure/function/method routine-info.")
4295 (defvar idlwave-class-alist nil
4296 "Holds the class names known to IDLWAVE.")
4297 (defvar idlwave-class-history nil
4298 "The history of classes selected with the minibuffer.")
4299 (defvar idlwave-force-class-query nil)
4300 (defvar idlwave-before-completion-wconf nil
4301 "The window configuration just before the completion buffer was displayed.")
4302 (defvar idlwave-last-system-routine-info-cons-cell nil
4303 "The last cons cell in the system routine info.")
4306 ;; The code to get routine info from different sources.
4308 (defvar idlwave-system-routines)
4309 (defvar idlwave-catalog-process nil
4310 "The background process currently updating the catalog.")
4312 (defun idlwave-routines ()
4313 "Provide a list of IDL routines.
4314 This routine loads the builtin routines on the first call.
4315 Later it only returns the value of the variable."
4316 (if (and idlwave-catalog-process
4317 (processp idlwave-catalog-process))
4318 (progn
4319 (cond
4320 ((equal (process-status idlwave-catalog-process) 'exit)
4321 (message "updating........")
4322 (setq idlwave-catalog-process nil)
4323 (idlwave-update-routine-info '(4)))
4324 ((equal (process-status idlwave-catalog-process) 'run)
4325 ;; Keep it running...
4328 ;; Something is wrong, get rid of the process
4329 (message "Problem with catalog process") (beep)
4330 (condition-case nil
4331 (kill-process idlwave-catalog-process)
4332 (error nil))
4333 (setq idlwave-catalog-process nil)))))
4334 (or idlwave-routines
4335 (progn
4336 (idlwave-update-routine-info)
4337 ;; return the current value
4338 idlwave-routines)))
4340 (defvar idlwave-update-rinfo-hook nil
4341 "List of functions which should run after a global rinfo update.
4342 Does not run after automatic updates of buffer or the shell.")
4344 (defun idlwave-rescan-catalog-directories ()
4345 "Rescan the previously selected directories. For batch processing."
4346 (idlwave-update-routine-info '(16)))
4348 (defun idlwave-rescan-asynchronously ()
4349 "Dispatch another Emacs instance to update the idlwave catalog.
4350 After the process finishes normally, the first access to routine info
4351 will re-read the catalog."
4352 (interactive)
4353 (if (processp idlwave-catalog-process)
4354 (if (eq (process-status idlwave-catalog-process) 'run)
4355 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4356 (progn
4357 (condition-case nil
4358 (kill-process idlwave-catalog-process)
4359 (error nil))
4360 (error "Process killed, no new process started"))
4361 (error "Quit"))
4362 (condition-case nil
4363 (kill-process idlwave-catalog-process)
4364 (error nil))))
4365 (if (or (not idlwave-user-catalog-file)
4366 (not (stringp idlwave-user-catalog-file))
4367 (not (file-regular-p idlwave-user-catalog-file)))
4368 (error "No catalog has been produced yet"))
4369 (let* ((emacs (concat invocation-directory invocation-name))
4370 (args (list "-batch"
4371 "-l" (expand-file-name "~/.emacs")
4372 "-l" "idlwave"
4373 "-f" "idlwave-rescan-catalog-directories"))
4374 (process (apply 'start-process "idlcat"
4375 nil emacs args)))
4376 (setq idlwave-catalog-process process)
4377 (set-process-sentinel
4378 process
4379 (lambda (pro why)
4380 (when (string-match "finished" why)
4381 (setq idlwave-routines nil
4382 idlwave-system-routines nil
4383 idlwave-catalog-process nil)
4384 (or (idlwave-start-load-rinfo-timer)
4385 (idlwave-update-routine-info '(4))))))
4386 (message "Background job started to update catalog file")))
4389 ;; Format for all routine info user catalog, library catalogs, etc.:
4391 ;; ("ROUTINE" type class
4392 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4393 ;; (buffer pro_file dir) | (compiled pro_file dir)
4394 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4395 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4397 ;; DIR will be supplied dynamically while loading library catalogs,
4398 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4399 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4400 ;; be nil, as can LINK1, etc., if no HTML help is available.
4403 (defvar idlwave-load-rinfo-idle-timer)
4404 (defvar idlwave-shell-path-query)
4406 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4407 "Update the internal routine-info lists.
4408 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4409 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4410 about individual routines.
4412 The information can come from 4 sources:
4413 1. IDL programs in the current editing session
4414 2. Compiled modules in an IDL shell running as Emacs subprocess
4415 3. A list which covers the IDL system routines.
4416 4. A list which covers the prescanned library files.
4418 Scans all IDLWAVE-mode buffers of the current editing session (see
4419 `idlwave-scan-all-buffers-for-routine-info').
4420 When an IDL shell is running, this command also queries the IDL program
4421 for currently compiled routines.
4423 With prefix ARG, also reload the system and library lists.
4424 With two prefix ARG's, also rescans the chosen user catalog tree.
4425 With three prefix args, dispatch asynchronous process to do the update.
4427 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4428 lists, but instead wait for the shell query to complete and
4429 asynchronously finish updating routine info. This is set
4430 automatically when called interactively. When you need routine
4431 information updated immediately, leave NO-CONCATENATE nil."
4432 (interactive "P\np")
4433 ;; Stop any idle processing
4434 (if (or (and (fboundp 'itimerp)
4435 (itimerp idlwave-load-rinfo-idle-timer))
4436 (and (fboundp 'timerp)
4437 (timerp idlwave-load-rinfo-idle-timer)))
4438 (cancel-timer idlwave-load-rinfo-idle-timer))
4439 (cond
4440 ((equal arg '(64))
4441 ;; Start a background process which updates the catalog.
4442 (idlwave-rescan-asynchronously))
4443 ((equal arg '(16))
4444 ;; Update the user catalog now, and wait for them.
4445 (idlwave-create-user-catalog-file t))
4447 (let* ((load (or arg
4448 idlwave-buffer-case-takes-precedence
4449 (null idlwave-routines)))
4450 ;; The override-idle means, even if the idle timer has done some
4451 ;; preparing work, load and renormalize everything anyway.
4452 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4454 (setq idlwave-buffer-routines nil
4455 idlwave-compiled-routines nil
4456 idlwave-unresolved-routines nil)
4457 ;; Reset the appropriate hashes
4458 (if (get 'idlwave-reset-sintern 'done-by-idle)
4459 ;; reset was already done in idle time, so skip this step now once
4460 (put 'idlwave-reset-sintern 'done-by-idle nil)
4461 (idlwave-reset-sintern (cond (load t)
4462 ((null idlwave-system-routines) t)
4463 (t 'bufsh))))
4465 (if idlwave-buffer-case-takes-precedence
4466 ;; We can safely scan the buffer stuff first
4467 (progn
4468 (idlwave-update-buffer-routine-info)
4469 (and load (idlwave-load-all-rinfo override-idle)))
4470 ;; We first do the system info, and then the buffers
4471 (and load (idlwave-load-all-rinfo override-idle))
4472 (idlwave-update-buffer-routine-info))
4474 ;; Let's see if there is a shell
4475 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4476 (idlwave-shell-is-running)))
4477 (ask-shell (and shell-is-running
4478 idlwave-query-shell-for-routine-info)))
4480 ;; Load the library catalogs again, first re-scanning the path
4481 (when arg
4482 (if shell-is-running
4483 (idlwave-shell-send-command idlwave-shell-path-query
4484 '(progn
4485 (idlwave-shell-get-path-info)
4486 (idlwave-scan-library-catalogs))
4487 'hide)
4488 (idlwave-scan-library-catalogs)))
4490 (if (or (not ask-shell)
4491 (not no-concatenate))
4492 ;; 1. If we are not going to ask the shell, we need to do the
4493 ;; concatenation now.
4494 ;; 2. When this function is called non-interactively, it
4495 ;; means that someone needs routine info *now*. The
4496 ;; shell update causes the concatenation to be
4497 ;; *delayed*, so not in time for the current command.
4498 ;; Therefore, we do a concatenation now, even though
4499 ;; the shell might do it again.
4500 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4502 (when ask-shell
4503 ;; Ask the shell about the routines it knows of.
4504 (message "Querying the shell")
4505 (idlwave-shell-update-routine-info nil t)))))))
4508 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4509 (defvar idlwave-load-rinfo-idle-timer nil)
4510 (defun idlwave-start-load-rinfo-timer ()
4511 (if (or (and (fboundp 'itimerp)
4512 (itimerp idlwave-load-rinfo-idle-timer))
4513 (and (fboundp 'timerp)
4514 (timerp idlwave-load-rinfo-idle-timer)))
4515 (cancel-timer idlwave-load-rinfo-idle-timer))
4516 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4517 (setq idlwave-load-rinfo-idle-timer nil)
4518 (if (and idlwave-init-rinfo-when-idle-after
4519 (numberp idlwave-init-rinfo-when-idle-after)
4520 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4521 (not idlwave-routines))
4522 (condition-case nil
4523 (progn
4524 (setq idlwave-load-rinfo-idle-timer
4525 (run-with-idle-timer
4526 idlwave-init-rinfo-when-idle-after
4527 nil 'idlwave-load-rinfo-next-step)))
4528 (error nil))))
4530 (defvar idlwave-library-routines nil "Obsolete variable.")
4532 ;;------ XML Help routine info system
4533 (defun idlwave-load-system-routine-info ()
4534 ;; Load the system routine info from the cached routine info file,
4535 ;; which, if necessary, will be re-created from the XML file on
4536 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4537 ;; file distributed with older IDLWAVE versions (<6.0)
4538 (unless (and (load idlwave-xml-system-rinfo-converted-file
4539 'noerror 'nomessage)
4540 (idlwave-xml-system-routine-info-up-to-date))
4541 ;; See if we can create it from XML source
4542 (condition-case nil
4543 (idlwave-convert-xml-system-routine-info)
4544 (error
4545 (unless (load idlwave-xml-system-rinfo-converted-file
4546 'noerror 'nomessage)
4547 (if idlwave-system-routines
4548 (message
4549 "Failed to load converted routine info, using old conversion.")
4550 (message
4551 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4552 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4553 (message
4554 "Could not locate any system routine information."))))))))
4556 (defun idlwave-xml-system-routine-info-up-to-date()
4557 (let* ((dir (file-name-as-directory
4558 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4559 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4560 (file-newer-than-file-p ;converted file is newer than catalog
4561 idlwave-xml-system-rinfo-converted-file
4562 catalog-file)))
4564 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4565 (defvar idlwave-system-variables-alist nil
4566 "Alist of system variables and the associated structure tags.
4567 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4568 (defvar idlwave-executive-commands-alist nil
4569 "Alist of system variables and their help files.")
4570 (defvar idlwave-help-special-topic-words nil)
4573 (defun idlwave-shorten-syntax (syntax name &optional class)
4574 ;; From a list of syntax statements, shorten with %s and group with "or"
4575 (let ((case-fold-search t))
4576 (mapconcat
4577 (lambda (x)
4578 (while (string-match name x)
4579 (setq x (replace-match "%s" t t x)))
4580 (if class
4581 (while (string-match class x)
4582 (setq x (replace-match "%s" t t x))))
4584 (nreverse syntax)
4585 " or ")))
4587 (defun idlwave-xml-create-class-method-lists (xml-entry)
4588 ;; Create a class list entry from the xml parsed list., returning a
4589 ;; cons of form (class-entry method-entries).
4590 (let* ((nameblock (nth 1 xml-entry))
4591 (class (cdr (assq 'name nameblock)))
4592 (link (cdr (assq 'link nameblock)))
4593 (params (cddr xml-entry))
4594 (case-fold-search t)
4595 class-entry
4596 method methods-entry extra-kwds
4597 props get-props set-props init-props inherits
4598 pelem ptype)
4599 (while params
4600 (setq pelem (car params))
4601 (when (listp pelem)
4602 (setq ptype (car pelem)
4603 props (car (cdr pelem)))
4604 (cond
4605 ((eq ptype 'SUPERCLASS)
4606 (let ((pname (cdr (assq 'name props)))
4607 (plink (cdr (assq 'link props))))
4608 (unless (and (string= pname "None")
4609 (string= plink "None"))
4610 (push pname inherits))))
4612 ((eq ptype 'PROPERTY)
4613 (let ((pname (cdr (assq 'name props)))
4614 (plink (cdr (assq 'link props)))
4615 (get (string= (cdr (assq 'get props)) "Yes"))
4616 (set (string= (cdr (assq 'set props)) "Yes"))
4617 (init (string= (cdr (assq 'init props)) "Yes")))
4618 (if get (push (list pname plink) get-props))
4619 (if set (push (list pname plink) set-props))
4620 (if init (push (list pname plink) init-props))))
4622 ((eq ptype 'METHOD)
4623 (setq method (cdr (assq 'name props)))
4624 (setq extra-kwds ;;Assume all property keywords are gathered already
4625 (cond
4626 ((string-match (concat class "::Init") method)
4627 (put 'init-props 'matched t)
4628 init-props)
4629 ((string-match (concat class "::GetProperty") method)
4630 (put 'get-props 'matched t)
4631 get-props)
4632 ((string-match (concat class "::SetProperty") method)
4633 (put 'set-props 'matched t)
4634 set-props)
4635 (t nil)))
4636 (setq methods-entry
4637 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4638 methods-entry)))
4639 (t)))
4640 (setq params (cdr params)))
4641 ;;(unless (get 'init-props 'matched)
4642 ;; (message "Failed to match Init in class %s" class))
4643 ;;(unless (get 'get-props 'matched)
4644 ;; (message "Failed to match GetProperty in class %s" class))
4645 ;;(unless (get 'set-props 'matched)
4646 ;; (message "Failed to match SetProperty in class %s" class))
4647 (setq class-entry
4648 (if inherits
4649 (list class (append '(inherits) inherits) (list 'link link))
4650 (list class (list 'link link))))
4651 (cons class-entry methods-entry)))
4653 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4654 ;; Create correctly structured list elements from ROUTINE or METHOD
4655 ;; XML list structures. Return a list of list elements, with more
4656 ;; than one sub-list possible if a routine can serve as both
4657 ;; procedure and function (e.g. call_method).
4658 (let* ((nameblock (nth 1 xml-entry))
4659 (name (cdr (assq 'name nameblock)))
4660 (link (cdr (assq 'link nameblock)))
4661 (params (cddr xml-entry))
4662 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4663 (case-fold-search t)
4664 syntax kwd klink pref-list kwds pelem ptype props result type)
4665 (if class ;; strip out class name from class method name string
4666 (if (string-match (concat class "::") name)
4667 (setq name (substring name (match-end 0)))))
4668 (while params
4669 (setq pelem (car params))
4670 (when (listp pelem)
4671 (setq ptype (car pelem)
4672 props (car (cdr pelem)))
4673 (cond
4674 ((eq ptype 'SYNTAX)
4675 (setq syntax (cdr (assq 'name props)))
4676 (if (string-match "-&gt;" syntax)
4677 (setq syntax (replace-match "->" t nil syntax)))
4678 (setq type (cdr (assq 'type props)))
4679 (push syntax
4680 (aref syntax-vec (cond
4681 ((string-match "^pro" type) 0)
4682 ((string-match "^fun" type) 1)
4683 ((string-match "^exec" type) 2)))))
4684 ((eq ptype 'KEYWORD)
4685 (setq kwd (cdr (assq 'name props))
4686 klink (cdr (assq 'link props)))
4687 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4688 (progn
4689 (setq pref-list
4690 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4691 kwd (substring kwd (match-end 0)))
4692 (loop for x in pref-list do
4693 (push (list (concat x kwd) klink) kwds)))
4694 (push (list kwd klink) kwds)))
4696 (t))); Do nothing for the others
4697 (setq params (cdr params)))
4699 ;; Debug
4700 ;; (if (and (null (aref syntax-vec 0))
4701 ;; (null (aref syntax-vec 1))
4702 ;; (null (aref syntax-vec 2)))
4703 ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4704 ;; (if class
4705 ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4706 ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4708 ;; Executive commands are treated specially
4709 (if (aref syntax-vec 2)
4710 (cons (substring name 1) link)
4711 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4712 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4713 (loop for idx from 0 to 1 do
4714 (if (aref syntax-vec idx)
4715 (push (append (list name (if (eq idx 0) 'pro 'fun)
4716 class '(system)
4717 (idlwave-shorten-syntax
4718 (aref syntax-vec idx) name class))
4719 kwds) result)))
4720 result)))
4723 (defun idlwave-rinfo-group-keywords (kwds master-link)
4724 ;; Group keywords by link file, as a list with elements
4725 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4726 (let (kwd link anchor linkfiles block master-elt)
4727 (while kwds
4728 (setq kwd (car kwds)
4729 link (idlwave-split-link-target (nth 1 kwd))
4730 anchor (cdr link)
4731 link (car link)
4732 kwd (car kwd))
4733 (if (setq block (assoc link linkfiles))
4734 (push (cons kwd anchor) (cdr block))
4735 (push (list link (cons kwd anchor)) linkfiles))
4736 (setq kwds (cdr kwds)))
4737 ;; Ensure the master link is there
4738 (if (setq master-elt (assoc master-link linkfiles))
4739 (if (eq (car linkfiles) master-elt)
4740 linkfiles
4741 (cons master-elt (delq master-elt linkfiles)))
4742 (push (list master-link) linkfiles))))
4744 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4745 ;; Clean up the syntax of routines which are actually aliases by
4746 ;; removing the "OR" from the statements
4747 (let (syntax entry)
4748 (loop for x in aliases do
4749 (setq entry (assoc x idlwave-system-routines))
4750 (when entry
4751 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4752 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4754 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4755 ;; Duplicate and trim original routine aliases from rinfo list
4756 ;; This if for, e.g. OPENR/OPENW/OPENU
4757 (let (alias remove-list new parts all-parts)
4758 (loop for x in aliases do
4759 (when (setq parts (split-string (cdr x) "/"))
4760 (setq new (assoc (cdr x) all-parts))
4761 (unless new
4762 (setq new (cons (cdr x) parts))
4763 (push new all-parts))
4764 (setcdr new (delete (car x) (cdr new)))))
4766 ;; Add any missing aliases (separate by slashes)
4767 (loop for x in all-parts do
4768 (if (cdr x)
4769 (push (cons (nth 1 x) (car x)) aliases)))
4771 (loop for x in aliases do
4772 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4773 (unless (memq alias remove-list) (push alias remove-list))
4774 (setq alias (copy-sequence alias))
4775 (setcar alias (car x))
4776 (push alias idlwave-system-routines)))
4777 (loop for x in remove-list do
4778 (delq x idlwave-system-routines))))
4780 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4781 ;; Duplicate and trim original routine aliases from rinfo list
4782 ;; This if for, e.g. !X, !Y, !Z.
4783 (let (alias remove-list)
4784 (loop for x in aliases do
4785 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4786 (unless (memq alias remove-list) (push alias remove-list))
4787 (setq alias (copy-sequence alias))
4788 (setcar alias (car x))
4789 (push alias idlwave-system-variables-alist)))
4790 (loop for x in remove-list do
4791 (delq x idlwave-system-variables-alist))))
4794 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4795 ;; Create a sysvar list entry from the xml parsed list.
4796 (let* ((nameblock (nth 1 xml-entry))
4797 (name (cdr (assq 'name nameblock)))
4798 (sysvar (substring name (progn (string-match "^ *!" name)
4799 (match-end 0))))
4800 (link (cdr (assq 'link nameblock)))
4801 (params (cddr xml-entry))
4802 (case-fold-search t)
4803 pelem ptype props tags)
4804 (while params
4805 (setq pelem (car params))
4806 (when (listp pelem)
4807 (setq ptype (car pelem)
4808 props (car (cdr pelem)))
4809 (cond
4810 ((eq ptype 'FIELD)
4811 (push (cons (cdr (assq 'name props))
4812 (cdr
4813 (idlwave-split-link-target (cdr (assq 'link props)))))
4814 tags))))
4815 (setq params (cdr params)))
4816 (delq nil
4817 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4820 (defvar idlwave-xml-routine-info-file nil)
4822 (defun idlwave-save-routine-info ()
4823 (if idlwave-xml-routine-info-file
4824 (with-temp-file idlwave-xml-system-rinfo-converted-file
4825 (insert
4826 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4827 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4828 ;; Automatically generated from source file:
4829 ;; " idlwave-xml-routine-info-file "
4830 ;; on " (current-time-string) "
4831 ;; Do not edit."))
4832 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4833 idlwave-xml-routine-info-file))
4834 (insert "\n(setq idlwave-system-routines\n '")
4835 (prin1 idlwave-system-routines (current-buffer))
4836 (insert ")")
4837 (insert "\n(setq idlwave-system-variables-alist\n '")
4838 (prin1 idlwave-system-variables-alist (current-buffer))
4839 (insert ")")
4840 (insert "\n(setq idlwave-system-class-info\n '")
4841 (prin1 idlwave-system-class-info (current-buffer))
4842 (insert ")")
4843 (insert "\n(setq idlwave-executive-commands-alist\n '")
4844 (prin1 idlwave-executive-commands-alist (current-buffer))
4845 (insert ")")
4846 (insert "\n(setq idlwave-help-special-topic-words\n '")
4847 (prin1 idlwave-help-special-topic-words (current-buffer))
4848 (insert ")"))))
4850 (defun idlwave-convert-xml-system-routine-info ()
4851 "Convert XML supplied IDL routine info into internal form.
4852 Cache to disk for quick recovery."
4853 (interactive)
4854 (let* ((dir (file-name-as-directory
4855 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4856 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4857 (elem-cnt 0)
4858 props rinfo msg-cnt elem type nelem class-result alias
4859 routines routine-aliases statement-aliases sysvar-aliases)
4860 (if (not (file-exists-p catalog-file))
4861 (error "No such XML routine info file: %s" catalog-file)
4862 (if (not (file-readable-p catalog-file))
4863 (error "Cannot read XML routine info file: %s" catalog-file)))
4864 (message "Reading XML routine info...")
4865 (setq rinfo (xml-parse-file catalog-file))
4866 (message "Reading XML routine info...done")
4867 (setq rinfo (assq 'CATALOG rinfo))
4868 (unless rinfo (error "Failed to parse XML routine info"))
4869 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4871 (setq rinfo (cddr rinfo))
4873 (setq nelem (length rinfo)
4874 msg-cnt (/ nelem 20))
4876 (setq idlwave-xml-routine-info-file nil)
4877 (message "Converting XML routine info...")
4878 (setq idlwave-system-routines nil
4879 idlwave-system-variables-alist nil
4880 idlwave-system-class-info nil
4881 idlwave-executive-commands-alist nil
4882 idlwave-help-special-topic-words nil)
4884 (while rinfo
4885 (setq elem (car rinfo)
4886 rinfo (cdr rinfo))
4887 (incf elem-cnt)
4888 (when (listp elem)
4889 (setq type (car elem)
4890 props (car (cdr elem)))
4891 (if (= (mod elem-cnt msg-cnt) 0)
4892 (message "Converting XML routine info...%2d%%"
4893 (/ (* elem-cnt 100) nelem)))
4894 (cond
4895 ((eq type 'ROUTINE)
4896 (if (setq alias (assq 'alias_to props))
4897 (push (cons (cdr (assq 'name props)) (cdr alias))
4898 routine-aliases)
4899 (setq routines (idlwave-xml-create-rinfo-list elem))
4900 (if (listp (cdr routines))
4901 (setq idlwave-system-routines
4902 (nconc idlwave-system-routines routines))
4903 ;; a cons cell is an executive commands
4904 (push routines idlwave-executive-commands-alist))))
4906 ((eq type 'CLASS)
4907 (setq class-result (idlwave-xml-create-class-method-lists elem))
4908 (push (car class-result) idlwave-system-class-info)
4909 (setq idlwave-system-routines
4910 (nconc idlwave-system-routines (cdr class-result))))
4912 ((eq type 'STATEMENT)
4913 (push (cons (cdr (assq 'name props))
4914 (cdr (assq 'link props)))
4915 idlwave-help-special-topic-words)
4916 ;; Save the links to those which are statement aliases (not routines)
4917 (if (setq alias (assq 'alias_to props))
4918 (unless (member (cdr alias) statement-aliases)
4919 (push (cdr alias) statement-aliases))))
4921 ((eq type 'SYSVAR)
4922 (if (setq alias (cdr (assq 'alias_to props)))
4923 (push (cons (substring (cdr (assq 'name props)) 1)
4924 (substring alias 1))
4925 sysvar-aliases)
4926 (push (idlwave-xml-create-sysvar-alist elem)
4927 idlwave-system-variables-alist)))
4928 (t))))
4929 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4930 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4931 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4933 (setq idlwave-xml-routine-info-file catalog-file)
4934 (idlwave-save-routine-info)
4935 (message "Converting XML routine info...done")))
4938 ;; ("ROUTINE" type class
4939 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4940 ;; (buffer pro_file dir) | (compiled pro_file dir)
4941 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4942 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4945 (defun idlwave-load-rinfo-next-step ()
4946 (let ((inhibit-quit t)
4947 (arr idlwave-load-rinfo-steps-done))
4948 (if (catch 'exit
4949 (when (not (aref arr 0))
4950 (message "Loading system routine info in idle time...")
4951 (idlwave-load-system-routine-info)
4952 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4953 (message "Loading system routine info in idle time...done")
4954 (aset arr 0 t)
4955 (throw 'exit t))
4957 (when (not (aref arr 1))
4958 (message "Normalizing idlwave-system-routines in idle time...")
4959 (idlwave-reset-sintern t)
4960 (put 'idlwave-reset-sintern 'done-by-idle t)
4961 (setq idlwave-system-routines
4962 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4963 (message "Normalizing idlwave-system-routines in idle time...done")
4964 (aset arr 1 t)
4965 (throw 'exit t))
4967 (when (not (aref arr 2))
4968 (when (and (stringp idlwave-user-catalog-file)
4969 (file-regular-p idlwave-user-catalog-file))
4970 (message "Loading user catalog in idle time...")
4971 (condition-case nil
4972 (load-file idlwave-user-catalog-file)
4973 (error (throw 'exit nil)))
4974 ;; Check for the old style catalog and warn
4975 (if (and
4976 (boundp 'idlwave-library-routines)
4977 idlwave-library-routines)
4978 (progn
4979 (setq idlwave-library-routines nil)
4980 (ding)
4981 (message "Outdated user catalog: %s... recreate"
4982 idlwave-user-catalog-file))
4983 (message "Loading user catalog in idle time...done")))
4984 (aset arr 2 t)
4985 (throw 'exit t))
4987 (when (not (aref arr 3))
4988 (when idlwave-user-catalog-routines
4989 (message "Normalizing user catalog routines in idle time...")
4990 (setq idlwave-user-catalog-routines
4991 (idlwave-sintern-rinfo-list
4992 idlwave-user-catalog-routines 'sys))
4993 (message
4994 "Normalizing user catalog routines in idle time...done"))
4995 (aset arr 3 t)
4996 (throw 'exit t))
4998 (when (not (aref arr 4))
4999 (idlwave-scan-library-catalogs
5000 "Loading and normalizing library catalogs in idle time...")
5001 (aset arr 4 t)
5002 (throw 'exit t))
5003 (when (not (aref arr 5))
5004 (message "Finishing initialization in idle time...")
5005 (idlwave-routines)
5006 (message "Finishing initialization in idle time...done")
5007 (aset arr 5 t)
5008 (throw 'exit nil)))
5009 ;; restart the timer
5010 (if (sit-for 1)
5011 (idlwave-load-rinfo-next-step)
5012 (setq idlwave-load-rinfo-idle-timer
5013 (run-with-idle-timer
5014 idlwave-init-rinfo-when-idle-after
5015 nil 'idlwave-load-rinfo-next-step))))))
5017 (defvar idlwave-after-load-rinfo-hook nil)
5019 (defun idlwave-load-all-rinfo (&optional force)
5020 ;; Load and case-treat the system, user catalog, and library routine
5021 ;; info files.
5023 ;; System
5024 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
5025 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5026 (idlwave-load-system-routine-info))
5027 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5028 (message "Normalizing idlwave-system-routines...")
5029 (setq idlwave-system-routines
5030 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5031 (message "Normalizing idlwave-system-routines...done"))
5032 (when idlwave-system-routines
5033 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5034 (setq idlwave-last-system-routine-info-cons-cell
5035 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5037 ;; User catalog
5038 (when (and (stringp idlwave-user-catalog-file)
5039 (file-regular-p idlwave-user-catalog-file))
5040 (condition-case nil
5041 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5042 (load-file idlwave-user-catalog-file))
5043 (error nil))
5044 (when (and
5045 (boundp 'idlwave-library-routines)
5046 idlwave-library-routines)
5047 (setq idlwave-library-routines nil)
5048 (error "Outdated user catalog: %s... recreate"
5049 idlwave-user-catalog-file))
5050 (setq idlwave-true-path-alist nil)
5051 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5052 (message "Normalizing user catalog routines...")
5053 (setq idlwave-user-catalog-routines
5054 (idlwave-sintern-rinfo-list
5055 idlwave-user-catalog-routines 'sys))
5056 (message "Normalizing user catalog routines...done")))
5058 ;; Library catalog
5059 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5060 (idlwave-scan-library-catalogs
5061 "Loading and normalizing library catalogs..."))
5062 (run-hooks 'idlwave-after-load-rinfo-hook))
5065 (defun idlwave-update-buffer-routine-info ()
5066 (let (res)
5067 (cond
5068 ((eq idlwave-scan-all-buffers-for-routine-info t)
5069 ;; Scan all buffers, current buffer last
5070 (message "Scanning all buffers...")
5071 (setq res (idlwave-get-routine-info-from-buffers
5072 (reverse (buffer-list)))))
5073 ((null idlwave-scan-all-buffers-for-routine-info)
5074 ;; Don't scan any buffers
5075 (setq res nil))
5077 ;; Just scan this buffer
5078 (if (derived-mode-p 'idlwave-mode)
5079 (progn
5080 (message "Scanning current buffer...")
5081 (setq res (idlwave-get-routine-info-from-buffers
5082 (list (current-buffer))))))))
5083 ;; Put the result into the correct variable
5084 (setq idlwave-buffer-routines
5085 (idlwave-sintern-rinfo-list res 'set))))
5087 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
5088 "Put the different sources for routine information together."
5089 ;; The sequence here is important because earlier definitions shadow
5090 ;; later ones. We assume that if things in the buffers are newer
5091 ;; then in the shell of the system, they are meant to be different.
5092 (setcdr idlwave-last-system-routine-info-cons-cell
5093 (append idlwave-buffer-routines
5094 idlwave-compiled-routines
5095 idlwave-library-catalog-routines
5096 idlwave-user-catalog-routines))
5097 (setq idlwave-class-alist nil)
5099 ;; Give a message with information about the number of routines we have.
5100 (unless quiet
5101 (message
5102 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5103 (length idlwave-buffer-routines)
5104 (length idlwave-compiled-routines)
5105 (length idlwave-library-catalog-routines)
5106 (length idlwave-user-catalog-routines)
5107 (length idlwave-system-routines)))
5108 (if run-hook
5109 (run-hooks 'idlwave-update-rinfo-hook)))
5111 (defun idlwave-class-alist ()
5112 "Return the class alist - make it if necessary."
5113 (or idlwave-class-alist
5114 (let (class)
5115 (loop for x in idlwave-routines do
5116 (when (and (setq class (nth 2 x))
5117 (not (assq class idlwave-class-alist)))
5118 (push (list class) idlwave-class-alist)))
5119 idlwave-class-alist)))
5121 ;; Three functions for the hooks
5122 (defun idlwave-save-buffer-update ()
5123 (idlwave-update-current-buffer-info 'save-buffer))
5124 (defun idlwave-kill-buffer-update ()
5125 (idlwave-update-current-buffer-info 'kill-buffer))
5126 (defun idlwave-new-buffer-update ()
5127 (idlwave-update-current-buffer-info 'find-file))
5129 (defun idlwave-update-current-buffer-info (why)
5130 "Update `idlwave-routines' for current buffer.
5131 Can run from `after-save-hook'."
5132 (when (and (derived-mode-p 'idlwave-mode)
5133 (or (eq t idlwave-auto-routine-info-updates)
5134 (memq why idlwave-auto-routine-info-updates))
5135 idlwave-scan-all-buffers-for-routine-info
5136 idlwave-routines)
5137 (condition-case nil
5138 (let (routines)
5139 (idlwave-replace-buffer-routine-info
5140 (buffer-file-name)
5141 (if (eq why 'kill-buffer)
5143 (setq routines
5144 (idlwave-sintern-rinfo-list
5145 (idlwave-get-routine-info-from-buffers
5146 (list (current-buffer))) 'set))))
5147 (idlwave-concatenate-rinfo-lists 'quiet)
5148 routines)
5149 (error nil))))
5151 (defun idlwave-replace-buffer-routine-info (file new)
5152 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5153 (let ((list idlwave-buffer-routines)
5154 found)
5155 (while list
5156 ;; The following test uses eq to make sure it works correctly
5157 ;; when two buffers visit the same file. Then the file names
5158 ;; will be equal, but not eq.
5159 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
5160 (progn
5161 (setcar list nil)
5162 (setq found t))
5163 (if found
5164 ;; End of that section reached. Jump.
5165 (setq list nil)))
5166 (setq list (cdr list)))
5167 (setq idlwave-buffer-routines
5168 (append new (delq nil idlwave-buffer-routines)))))
5170 ;;----- Scanning buffers -------------------
5172 (defun idlwave-get-routine-info-from-buffers (buffers)
5173 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5174 (let (buf routine-lists res)
5175 (save-excursion
5176 (while (setq buf (pop buffers))
5177 (set-buffer buf)
5178 (if (and (derived-mode-p 'idlwave-mode)
5179 buffer-file-name)
5180 ;; yes, this buffer has the right mode.
5181 (progn (setq res (condition-case nil
5182 (idlwave-get-buffer-routine-info)
5183 (error nil)))
5184 (push res routine-lists)))))
5185 ;; Concatenate the individual lists and return the result
5186 (apply 'nconc routine-lists)))
5188 (defun idlwave-get-buffer-routine-info ()
5189 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5190 (let* ((case-fold-search t)
5191 routine-list string entry)
5192 (save-excursion
5193 (save-restriction
5194 (widen)
5195 (goto-char (point-min))
5196 (while (re-search-forward
5197 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
5198 (setq string (buffer-substring-no-properties
5199 (match-beginning 0)
5200 (progn
5201 (idlwave-end-of-statement)
5202 (point))))
5203 (setq entry (idlwave-parse-definition string))
5204 (push entry routine-list))))
5205 routine-list))
5207 (defvar idlwave-scanning-lib-dir)
5208 (defvar idlwave-scanning-lib)
5209 (defun idlwave-parse-definition (string)
5210 "Parse a module definition."
5211 (let ((case-fold-search t)
5212 start name args type keywords class)
5213 ;; Remove comments
5214 (while (string-match ";.*" string)
5215 (setq string (replace-match "" t t string)))
5216 ;; Remove the continuation line stuff
5217 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5218 (setq string (replace-match "\\1 " t nil string)))
5219 (while (string-match "\n" string)
5220 (setq string (replace-match " " t nil string)))
5221 ;; Match the name and type.
5222 (when (string-match
5223 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5224 (setq start (match-end 0))
5225 (setq type (downcase (match-string 1 string)))
5226 (if (match-beginning 3)
5227 (setq class (match-string 3 string)))
5228 (setq name (match-string 4 string)))
5229 ;; Match normal args and keyword args
5230 (while (string-match
5231 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5232 string start)
5233 (setq start (match-end 0))
5234 (if (match-beginning 3)
5235 (push (match-string 1 string) keywords)
5236 (push (match-string 1 string) args)))
5237 ;; Normalize and sort.
5238 (setq args (nreverse args))
5239 (setq keywords (sort keywords (lambda (a b)
5240 (string< (downcase a) (downcase b)))))
5241 ;; Make and return the entry
5242 ;; We don't know which argument are optional, so this information
5243 ;; will not be contained in the calling sequence.
5244 (list name
5245 (if (equal type "pro") 'pro 'fun)
5246 class
5247 (cond ((not (boundp 'idlwave-scanning-lib))
5248 (list 'buffer (buffer-file-name)))
5249 ; ((string= (downcase
5250 ; (file-name-sans-extension
5251 ; (file-name-nondirectory (buffer-file-name))))
5252 ; (downcase name))
5253 ; (list 'lib))
5254 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5255 (t (list 'user (file-name-nondirectory (buffer-file-name))
5256 idlwave-scanning-lib-dir "UserLib")))
5257 (concat
5258 (if (string= type "function") "Result = " "")
5259 (if class "Obj ->[%s::]" "")
5260 "%s"
5261 (if args
5262 (concat
5263 (if (string= type "function") "(" ", ")
5264 (mapconcat 'identity args ", ")
5265 (if (string= type "function") ")" ""))))
5266 (if keywords
5267 (cons nil (mapcar 'list keywords)) ;No help file
5268 nil))))
5271 ;;----- Scanning the user catalog -------------------
5273 (defun idlwave-sys-dir ()
5274 "Return the syslib directory, or a dummy that never matches."
5275 (cond
5276 ((and idlwave-system-directory
5277 (not (string= idlwave-system-directory "")))
5278 idlwave-system-directory)
5279 ((getenv "IDL_DIR"))
5280 (t "@@@@@@@@")))
5283 (defun idlwave-create-user-catalog-file (&optional arg)
5284 "Scan all files on selected dirs of IDL search path for routine information.
5286 A widget checklist will allow you to choose the directories. Write
5287 the result as a file `idlwave-user-catalog-file'. When this file
5288 exists, it will be automatically loaded to give routine information
5289 about library routines. With ARG, just rescan the same directories
5290 as last time - so no widget will pop up."
5291 (interactive "P")
5292 ;; Make sure the file is loaded if it exists.
5293 (if (and (stringp idlwave-user-catalog-file)
5294 (file-regular-p idlwave-user-catalog-file))
5295 (condition-case nil
5296 (load-file idlwave-user-catalog-file)
5297 (error nil)))
5298 ;; Make sure the file name makes sense
5299 (unless (and (stringp idlwave-user-catalog-file)
5300 (> (length idlwave-user-catalog-file) 0)
5301 (file-accessible-directory-p
5302 (file-name-directory idlwave-user-catalog-file))
5303 (not (string= "" (file-name-nondirectory
5304 idlwave-user-catalog-file))))
5305 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5307 (cond
5308 ;; Rescan the known directories
5309 ((and arg idlwave-path-alist
5310 (consp (car idlwave-path-alist)))
5311 (idlwave-scan-user-lib-files idlwave-path-alist))
5313 ;; Expand the directories from library-path and run the widget
5314 (idlwave-library-path
5315 (idlwave-display-user-catalog-widget
5316 (if idlwave-true-path-alist
5317 ;; Propagate any flags on the existing path-alist
5318 (mapcar (lambda (x)
5319 (let ((path-entry (assoc (file-truename x)
5320 idlwave-true-path-alist)))
5321 (if path-entry
5322 (cons x (cdr path-entry))
5323 (list x))))
5324 (idlwave-expand-path idlwave-library-path))
5325 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5327 ;; Ask the shell for the path and then run the widget
5329 (message "Asking the shell for IDL path...")
5330 (require 'idlw-shell)
5331 (idlwave-shell-send-command idlwave-shell-path-query
5332 '(idlwave-user-catalog-command-hook nil)
5333 'hide))))
5336 ;; Parse shell path information and select among it.
5337 (defun idlwave-user-catalog-command-hook (&optional arg)
5338 ;; Command hook used by `idlwave-create-user-catalog-file'.
5339 (if arg
5340 ;; Scan immediately
5341 (idlwave-scan-user-lib-files idlwave-path-alist)
5342 ;; Set the path and display the widget
5343 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5344 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5345 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5347 (defconst idlwave-user-catalog-widget-help-string
5348 "This is the front-end to the creation of the IDLWAVE user catalog.
5349 Please select the directories on IDL's search path from which you
5350 would like to extract routine information, to be stored in the file:
5354 If this is not the correct file, first set variable
5355 `idlwave-user-catalog-file', and call this command again.
5357 N.B. Many libraries include pre-scanned catalog files
5358 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5359 not be scanned. You can scan your own libraries off-line using the
5360 perl script `idlwave_catalog'.
5362 After selecting the directories, choose [Scan & Save] to scan the library
5363 directories and save the routine info.
5364 \n")
5366 (defvar idlwave-widget)
5367 (defvar widget-keymap)
5368 (defun idlwave-display-user-catalog-widget (dirs-list)
5369 "Create the widget to select IDL search path directories for scanning."
5370 (interactive)
5371 (require 'widget)
5372 (require 'wid-edit)
5373 (unless dirs-list
5374 (error "Don't know IDL's search path"))
5376 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5377 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5378 (kill-all-local-variables)
5379 (make-local-variable 'idlwave-widget)
5380 (widget-insert (format idlwave-user-catalog-widget-help-string
5381 idlwave-user-catalog-file))
5383 (widget-create 'push-button
5384 :notify 'idlwave-widget-scan-user-lib-files
5385 "Scan & Save")
5386 (widget-insert " ")
5387 (widget-create 'push-button
5388 :notify 'idlwave-delete-user-catalog-file
5389 "Delete File")
5390 (widget-insert " ")
5391 (widget-create 'push-button
5392 :notify
5393 (lambda (&rest ignore)
5394 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5395 (dolist (x path-list)
5396 (unless (memq 'lib (cdr x))
5397 (idlwave-path-alist-add-flag x 'user)))
5398 (idlwave-display-user-catalog-widget path-list)))
5399 "Select All Non-Lib")
5400 (widget-insert " ")
5401 (widget-create 'push-button
5402 :notify
5403 (lambda (&rest ignore)
5404 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5405 (dolist (x path-list)
5406 (idlwave-path-alist-remove-flag x 'user))
5407 (idlwave-display-user-catalog-widget path-list)))
5408 "Deselect All")
5409 (widget-insert " ")
5410 (widget-create 'push-button
5411 :notify (lambda (&rest ignore)
5412 (kill-buffer (current-buffer)))
5413 "Quit")
5414 (widget-insert "\n\n")
5416 (widget-insert "Select Directories: \n")
5418 (setq idlwave-widget
5419 (apply 'widget-create
5420 'checklist
5421 :value (delq nil (mapcar (lambda (x)
5422 (if (memq 'user (cdr x))
5423 (car x)))
5424 dirs-list))
5425 :greedy t
5426 :tag "List of directories"
5427 (mapcar (lambda (x)
5428 (list 'item
5429 (if (memq 'lib (cdr x))
5430 (concat "[LIB] " (car x) )
5431 (car x)))) dirs-list)))
5432 (widget-put idlwave-widget :path-dirs dirs-list)
5433 (widget-insert "\n")
5434 (use-local-map widget-keymap)
5435 (widget-setup)
5436 (goto-char (point-min))
5437 (delete-other-windows))
5439 (defun idlwave-delete-user-catalog-file (&rest ignore)
5440 (if (yes-or-no-p
5441 (format "Delete file %s " idlwave-user-catalog-file))
5442 (progn
5443 (delete-file idlwave-user-catalog-file)
5444 (message "%s has been deleted" idlwave-user-catalog-file))))
5446 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5447 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5448 (let* ((widget idlwave-widget)
5449 (selected-dirs (widget-value widget))
5450 (path-alist (widget-get widget :path-dirs))
5451 (this-path-alist path-alist)
5452 dir-entry)
5453 (while (setq dir-entry (pop this-path-alist))
5454 (if (member
5455 (if (memq 'lib (cdr dir-entry))
5456 (concat "[LIB] " (car dir-entry))
5457 (car dir-entry))
5458 selected-dirs)
5459 (idlwave-path-alist-add-flag dir-entry 'user)
5460 (idlwave-path-alist-remove-flag dir-entry 'user)))
5461 (idlwave-scan-user-lib-files path-alist)))
5463 (defvar font-lock-mode)
5464 (defun idlwave-scan-user-lib-files (path-alist)
5465 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5466 (let* ((idlwave-scanning-lib t)
5467 (idlwave-scanning-lib-dir "")
5468 (idlwave-completion-case nil)
5469 dirs-alist dir files file)
5470 (setq idlwave-user-catalog-routines nil
5471 idlwave-path-alist path-alist ; for library-path instead
5472 idlwave-true-path-alist nil)
5473 (if idlwave-auto-write-paths (idlwave-write-paths))
5474 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5475 (idlwave-mode)
5476 (setq dirs-alist (reverse path-alist))
5477 (while (setq dir (pop dirs-alist))
5478 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5479 (setq dir (car dir))
5480 (setq idlwave-scanning-lib-dir dir)
5481 (when (file-directory-p dir)
5482 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5483 (while (setq file (pop files))
5484 (when (file-regular-p file)
5485 (if (not (file-readable-p file))
5486 (message "Skipping %s (no read permission)" file)
5487 (message "Scanning %s..." file)
5488 (erase-buffer)
5489 (insert-file-contents file 'visit)
5490 (setq idlwave-user-catalog-routines
5491 (append (idlwave-get-routine-info-from-buffers
5492 (list (current-buffer)))
5493 idlwave-user-catalog-routines)))))))))
5494 (message "Creating user catalog file...")
5495 (kill-buffer "*idlwave-scan.pro*")
5496 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5497 (let ((font-lock-maximum-size 0)
5498 (auto-mode-alist nil))
5499 (find-file idlwave-user-catalog-file))
5500 (if (and (boundp 'font-lock-mode)
5501 font-lock-mode)
5502 (font-lock-mode 0))
5503 (erase-buffer)
5504 (insert ";; IDLWAVE user catalog file\n")
5505 (insert (format ";; Created %s\n\n" (current-time-string)))
5507 ;; Define the routine info list
5508 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5509 (let ((standard-output (current-buffer)))
5510 (mapc (lambda (x)
5511 (insert "\n ")
5512 (prin1 x)
5513 (goto-char (point-max)))
5514 idlwave-user-catalog-routines))
5515 (insert (format "))\n\n;;; %s ends here\n"
5516 (file-name-nondirectory idlwave-user-catalog-file)))
5517 (goto-char (point-min))
5518 ;; Save the buffer
5519 (save-buffer 0)
5520 (kill-buffer (current-buffer)))
5521 (message "Creating user catalog file...done")
5522 (message "Info for %d routines saved in %s"
5523 (length idlwave-user-catalog-routines)
5524 idlwave-user-catalog-file)
5525 (sit-for 2)
5526 (idlwave-update-routine-info t))
5528 (defun idlwave-read-paths ()
5529 (if (and (stringp idlwave-path-file)
5530 (file-regular-p idlwave-path-file))
5531 (condition-case nil
5532 (load idlwave-path-file t t t)
5533 (error nil))))
5535 (defun idlwave-write-paths ()
5536 (interactive)
5537 (when (and idlwave-path-alist idlwave-system-directory)
5538 (let ((font-lock-maximum-size 0)
5539 (auto-mode-alist nil))
5540 (find-file idlwave-path-file))
5541 (if (and (boundp 'font-lock-mode)
5542 font-lock-mode)
5543 (font-lock-mode 0))
5544 (erase-buffer)
5545 (insert ";; IDLWAVE paths\n")
5546 (insert (format ";; Created %s\n\n" (current-time-string)))
5547 ;; Define the variable which knows the value of "!DIR"
5548 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5549 idlwave-system-directory))
5551 ;; Define the variable which contains a list of all scanned directories
5552 (insert "\n(setq idlwave-path-alist\n '(")
5553 (let ((standard-output (current-buffer)))
5554 (mapc (lambda (x)
5555 (insert "\n ")
5556 (prin1 x)
5557 (goto-char (point-max)))
5558 idlwave-path-alist))
5559 (insert "))\n")
5560 (save-buffer 0)
5561 (kill-buffer (current-buffer))))
5564 (defun idlwave-expand-path (path &optional default-dir)
5565 ;; Expand parts of path starting with '+' recursively into directory list.
5566 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5567 (message "Expanding path...")
5568 (let (path1 dir recursive)
5569 (while (setq dir (pop path))
5570 (if (setq recursive (string= (substring dir 0 1) "+"))
5571 (setq dir (substring dir 1)))
5572 (if (and recursive
5573 (not (file-name-absolute-p dir)))
5574 (setq dir (expand-file-name dir default-dir)))
5575 (if recursive
5576 ;; Expand recursively
5577 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5578 ;; Keep unchanged
5579 (push dir path1)))
5580 (message "Expanding path...done")
5581 (nreverse path1)))
5583 (defun idlwave-recursive-directory-list (dir)
5584 ;; Return a list of all directories below DIR, including DIR itself
5585 (let ((path (list dir)) path1 file files)
5586 (while (setq dir (pop path))
5587 (when (file-directory-p dir)
5588 (setq files (nreverse (directory-files dir t "[^.]")))
5589 (while (setq file (pop files))
5590 (if (file-directory-p file)
5591 (push (file-name-as-directory file) path)))
5592 (push dir path1)))
5593 path1))
5596 ;;----- Scanning the library catalogs ------------------
5601 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5602 "Scan for library catalog files (.idlwave_catalog) and ingest.
5604 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5605 instead, if present) are searched. Print MESSAGE-BASE along with the
5606 libraries being loaded, if passed, and skip loading/normalizing if
5607 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5608 be set to nil to disable library catalog scanning."
5609 (when idlwave-use-library-catalogs
5610 (let ((dirs
5611 (if idlwave-library-path
5612 (idlwave-expand-path idlwave-library-path)
5613 (mapcar 'car idlwave-path-alist)))
5614 (old-libname "")
5615 dir-entry dir catalog all-routines)
5616 (if message-base (message message-base))
5617 (while (setq dir (pop dirs))
5618 (catch 'continue
5619 (when (file-readable-p
5620 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5621 (unless no-load
5622 (setq idlwave-library-catalog-routines nil)
5623 ;; Load the catalog file
5624 (condition-case nil
5625 (load catalog t t t)
5626 (error (throw 'continue t)))
5627 (when (and
5628 message-base
5629 (not (string= idlwave-library-catalog-libname
5630 old-libname)))
5631 (message "%s" (concat message-base
5632 idlwave-library-catalog-libname))
5633 (setq old-libname idlwave-library-catalog-libname))
5634 (when idlwave-library-catalog-routines
5635 (setq all-routines
5636 (append
5637 (idlwave-sintern-rinfo-list
5638 idlwave-library-catalog-routines 'sys dir)
5639 all-routines))))
5641 ;; Add a 'lib flag if on path-alist
5642 (when (and idlwave-path-alist
5643 (setq dir-entry (assoc dir idlwave-path-alist)))
5644 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5645 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5646 (if message-base (message (concat message-base "done"))))))
5648 ;;----- Communicating with the Shell -------------------
5650 ;; First, here is the idl program which can be used to query IDL for
5651 ;; defined routines.
5652 (defconst idlwave-routine-info.pro
5654 ;; START OF IDLWAVE SUPPORT ROUTINES
5655 pro idlwave_print_safe,item,limit
5656 catch,err
5657 if err ne 0 then begin
5658 print,'Could not print item.'
5659 return
5660 endif
5661 if n_elements(item) gt limit then $
5662 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5663 else print,item
5666 pro idlwave_print_info_entry,name,func=func,separator=sep
5667 ;; See if it's an object method
5668 if name eq '' then return
5669 func = keyword_set(func)
5670 methsep = strpos(name,'::')
5671 meth = methsep ne -1
5673 ;; Get routine info
5674 pars = routine_info(name,/parameters,functions=func)
5675 source = routine_info(name,/source,functions=func)
5676 nargs = pars.num_args
5677 nkw = pars.num_kw_args
5678 if nargs gt 0 then args = pars.args
5679 if nkw gt 0 then kwargs = pars.kw_args
5681 ;; Trim the class, and make the name
5682 if meth then begin
5683 class = strmid(name,0,methsep)
5684 name = strmid(name,methsep+2,strlen(name)-1)
5685 if nargs gt 0 then begin
5686 ;; remove the self argument
5687 wh = where(args ne 'SELF',nargs)
5688 if nargs gt 0 then args = args[wh]
5689 endif
5690 endif else begin
5691 ;; No class, just a normal routine.
5692 class = \"\"
5693 endelse
5695 ;; Calling sequence
5696 cs = \"\"
5697 if func then cs = 'Result = '
5698 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5699 cs = cs + '%s'
5700 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5701 if nargs gt 0 then begin
5702 for j=0,nargs-1 do begin
5703 cs = cs + args[j]
5704 if j lt nargs-1 then cs = cs + ', '
5705 endfor
5707 if func then cs = cs + ')'
5708 ;; Keyword arguments
5709 kwstring = ''
5710 if nkw gt 0 then begin
5711 for j=0,nkw-1 do begin
5712 kwstring = kwstring + ' ' + kwargs[j]
5713 endfor
5714 endif
5716 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5718 print,ret + ': ' + name + sep + class + sep + source[0].path $
5719 + sep + cs + sep + kwstring
5722 pro idlwave_routine_info,file
5723 on_error,1
5724 sep = '<@>'
5725 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5726 all = routine_info()
5727 fileQ=n_elements(file) ne 0
5728 if fileQ then file=strtrim(file,2)
5729 for i=0L,n_elements(all)-1L do begin
5730 if fileQ then begin
5731 if (routine_info(all[i],/SOURCE)).path eq file then $
5732 idlwave_print_info_entry,all[i],separator=sep
5733 endif else idlwave_print_info_entry,all[i],separator=sep
5734 endfor
5735 all = routine_info(/functions)
5736 for i=0L,n_elements(all)-1L do begin
5737 if fileQ then begin
5738 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5739 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5740 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5741 endfor
5742 print,'>>>END OF IDLWAVE ROUTINE INFO'
5745 pro idlwave_get_sysvars
5746 on_error,1
5747 catch,error_status
5748 if error_status ne 0 then begin
5749 print, 'Cannot get info about system variables'
5750 endif else begin
5751 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5752 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5753 v = strsplit(s,' +',/regex,/extract) ; get variables
5754 for i=0L,n_elements(v)-1 do begin
5755 t = [''] ; get tag list
5756 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5757 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5758 endfor
5759 endelse
5762 pro idlwave_get_class_tags, class
5763 res = execute('tags=tag_names({'+class+'})')
5764 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5766 ;; END OF IDLWAVE SUPPORT ROUTINES
5768 "The IDL programs to get info from the shell.")
5770 (defvar idlwave-idlwave_routine_info-compiled nil
5771 "Remember if the routine info procedure is already compiled.")
5773 (defvar idlwave-shell-temp-pro-file)
5774 (defvar idlwave-shell-temp-rinfo-save-file)
5776 (defun idlwave-shell-compile-helper-routines (&optional wait)
5777 (unless (and idlwave-idlwave_routine_info-compiled
5778 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5779 (with-current-buffer (idlwave-find-file-noselect
5780 (idlwave-shell-temp-file 'pro))
5781 (erase-buffer)
5782 (insert idlwave-routine-info.pro)
5783 (save-buffer 0))
5784 (idlwave-shell-send-command
5785 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
5786 nil 'hide wait)
5787 (idlwave-shell-send-command
5788 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5789 (idlwave-shell-temp-file 'rinfo))
5790 nil 'hide)
5791 (setq idlwave-idlwave_routine_info-compiled t))
5793 ;; Restore if necessary. Must use execute to hide lame routine_info
5794 ;; errors on undefinded routine
5795 (idlwave-shell-send-command
5796 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5797 idlwave-shell-temp-rinfo-save-file
5798 idlwave-shell-temp-rinfo-save-file)
5799 nil 'hide))
5802 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5803 "Query the shell for routine_info of compiled modules and update the lists."
5804 ;; Save and compile the procedure. The compiled procedure is then
5805 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5806 ;; need to test for and possibly RESTORE the procedure each time we
5807 ;; use it, since the user may have killed or redefined it. In
5808 ;; particular, .RESET_SESSION will kill all user procedures. If
5809 ;; FILE is set, only update routine info for routines in that file.
5811 (idlwave-shell-compile-helper-routines wait)
5812 ; execute the routine_info procedure, and analyze the output
5813 (idlwave-shell-send-command
5814 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
5815 `(progn
5816 (idlwave-shell-routine-info-filter)
5817 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5818 'hide wait))
5820 ;; ---------------------------------------------------------------------------
5822 ;; Completion and displaying routine calling sequences
5824 (defvar idlwave-completion-help-info nil)
5825 (defvar idlwave-completion-help-links nil)
5826 (defvar idlwave-current-obj_new-class nil)
5827 (defvar idlwave-complete-special nil)
5828 (defvar method-selector)
5829 (defvar class-selector)
5830 (defvar type-selector)
5831 (defvar super-classes)
5833 (defun idlwave-complete (&optional arg module class)
5834 "Complete a function, procedure or keyword name at point.
5835 This function is smart and figures out what can be completed
5836 at this point.
5837 - At the beginning of a statement it completes procedure names.
5838 - In the middle of a statement it completes function names.
5839 - After a `(' or `,' in the argument list of a function or procedure,
5840 it completes a keyword of the relevant function or procedure.
5841 - In the first arg of `OBJ_NEW', it completes a class name.
5843 When several completions are possible, a list will be displayed in
5844 the *Completions* buffer. If this list is too long to fit into the
5845 window, scrolling can be achieved by repeatedly pressing
5846 \\[idlwave-complete].
5848 The function also knows about object methods. When it needs a class
5849 name, the action depends upon `idlwave-query-class', which see. You
5850 can force IDLWAVE to ask you for a class name with a
5851 \\[universal-argument] prefix argument to this command.
5853 See also the variables `idlwave-keyword-completion-adds-equal' and
5854 `idlwave-function-completion-adds-paren'.
5856 The optional ARG can be used to specify the completion type in order
5857 to override IDLWAVE's idea of what should be completed at point.
5858 Possible values are:
5860 0 <=> query for the completion type
5861 1 <=> 'procedure
5862 2 <=> 'procedure-keyword
5863 3 <=> 'function
5864 4 <=> 'function-keyword
5865 5 <=> 'procedure-method
5866 6 <=> 'procedure-method-keyword
5867 7 <=> 'function-method
5868 8 <=> 'function-method-keyword
5869 9 <=> 'class
5871 As a special case, the universal argument C-u forces completion of
5872 function names in places where the default would be a keyword.
5874 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5875 completion.
5877 For Lisp programmers only:
5878 When we force a keyword, optional argument MODULE can contain the module name.
5879 When we force a method or a method keyword, CLASS can specify the class."
5880 (interactive "P")
5881 (idlwave-routines)
5882 (let* ((where-list
5883 (if (and arg
5884 (or (and (integerp arg) (not (equal arg '(16))))
5885 (symbolp arg)))
5886 (idlwave-make-force-complete-where-list arg module class)
5887 (idlwave-where)))
5888 (what (nth 2 where-list))
5889 (idlwave-force-class-query (equal arg '(4)))
5890 (completion-regexp-list
5891 (if (equal arg '(16))
5892 (list (read-string (concat "Completion Regexp: "))))))
5894 (if (and module (string-match "::" module))
5895 (setq class (substring module 0 (match-beginning 0))
5896 module (substring module (match-end 0))))
5898 (cond
5900 ((and (null arg)
5901 (eq (car-safe last-command) 'idlwave-display-completion-list)
5902 (get-buffer-window "*Completions*"))
5903 (setq this-command last-command)
5904 (idlwave-scroll-completions))
5906 ;; Complete a filename in quotes
5907 ((and (idlwave-in-quote)
5908 (not (eq what 'class)))
5909 (idlwave-complete-filename))
5911 ;; Check for any special completion functions
5912 ((and idlwave-complete-special
5913 (idlwave-call-special idlwave-complete-special)))
5915 ((null what)
5916 (error "Nothing to complete here"))
5918 ;; Complete a class
5919 ((eq what 'class)
5920 (setq idlwave-completion-help-info '(class))
5921 (idlwave-complete-class))
5923 ((eq what 'procedure)
5924 ;; Complete a procedure name
5925 (let* ((cw-list (nth 3 where-list))
5926 (class-selector (idlwave-determine-class cw-list 'pro))
5927 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5928 (idlwave-all-class-inherits class-selector)))
5929 (isa (concat "procedure" (if class-selector "-method" "")))
5930 (type-selector 'pro))
5931 (setq idlwave-completion-help-info
5932 (list 'routine nil type-selector class-selector nil super-classes))
5933 (idlwave-complete-in-buffer
5934 'procedure (if class-selector 'method 'routine)
5935 (idlwave-routines) 'idlwave-selector
5936 (format "Select a %s name%s"
5938 (if class-selector
5939 (format " (class is %s)"
5940 (if (eq class-selector t)
5941 "unknown" class-selector))
5942 ""))
5944 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5946 ((eq what 'function)
5947 ;; Complete a function name
5948 (let* ((cw-list (nth 3 where-list))
5949 (class-selector (idlwave-determine-class cw-list 'fun))
5950 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5951 (idlwave-all-class-inherits class-selector)))
5952 (isa (concat "function" (if class-selector "-method" "")))
5953 (type-selector 'fun))
5954 (setq idlwave-completion-help-info
5955 (list 'routine nil type-selector class-selector nil super-classes))
5956 (idlwave-complete-in-buffer
5957 'function (if class-selector 'method 'routine)
5958 (idlwave-routines) 'idlwave-selector
5959 (format "Select a %s name%s"
5961 (if class-selector
5962 (format " (class is %s)"
5963 (if (eq class-selector t)
5964 "unknown" class-selector))
5965 ""))
5967 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5969 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5970 (equal arg '(4)))
5971 (idlwave-complete 3))
5973 ((eq what 'procedure-keyword)
5974 ;; Complete a procedure keyword
5975 (let* ((where (nth 3 where-list))
5976 (name (car where))
5977 (method-selector name)
5978 (type-selector 'pro)
5979 (class (idlwave-determine-class where 'pro))
5980 (class-selector class)
5981 (super-classes (idlwave-all-class-inherits class-selector))
5982 (isa (format "procedure%s-keyword" (if class "-method" "")))
5983 (entry (idlwave-best-rinfo-assq
5984 name 'pro class (idlwave-routines)))
5985 (system (if entry (eq (car (nth 3 entry)) 'system)))
5986 (list (idlwave-entry-keywords entry 'do-link)))
5987 (unless (or entry (eq class t))
5988 (error "Nothing known about procedure %s"
5989 (idlwave-make-full-name class name)))
5990 (setq list (idlwave-fix-keywords name 'pro class list
5991 super-classes system))
5992 (unless list (error "No keywords available for procedure %s"
5993 (idlwave-make-full-name class name)))
5994 (setq idlwave-completion-help-info
5995 (list 'keyword name type-selector class-selector entry super-classes))
5996 (idlwave-complete-in-buffer
5997 'keyword 'keyword list nil
5998 (format "Select keyword for procedure %s%s"
5999 (idlwave-make-full-name class name)
6000 (if (or (member '("_EXTRA") list)
6001 (member '("_REF_EXTRA") list))
6002 " (note _EXTRA)" ""))
6004 'idlwave-attach-keyword-classes)))
6006 ((eq what 'function-keyword)
6007 ;; Complete a function keyword
6008 (let* ((where (nth 3 where-list))
6009 (name (car where))
6010 (method-selector name)
6011 (type-selector 'fun)
6012 (class (idlwave-determine-class where 'fun))
6013 (class-selector class)
6014 (super-classes (idlwave-all-class-inherits class-selector))
6015 (isa (format "function%s-keyword" (if class "-method" "")))
6016 (entry (idlwave-best-rinfo-assq
6017 name 'fun class (idlwave-routines)))
6018 (system (if entry (eq (car (nth 3 entry)) 'system)))
6019 (list (idlwave-entry-keywords entry 'do-link))
6020 msg-name)
6021 (unless (or entry (eq class t))
6022 (error "Nothing known about function %s"
6023 (idlwave-make-full-name class name)))
6024 (setq list (idlwave-fix-keywords name 'fun class list
6025 super-classes system))
6026 ;; OBJ_NEW: Messages mention the proper Init method
6027 (setq msg-name (if (and (null class)
6028 (string= (upcase name) "OBJ_NEW"))
6029 (concat idlwave-current-obj_new-class
6030 "::Init (via OBJ_NEW)")
6031 (idlwave-make-full-name class name)))
6032 (unless list (error "No keywords available for function %s"
6033 msg-name))
6034 (setq idlwave-completion-help-info
6035 (list 'keyword name type-selector class-selector nil super-classes))
6036 (idlwave-complete-in-buffer
6037 'keyword 'keyword list nil
6038 (format "Select keyword for function %s%s" msg-name
6039 (if (or (member '("_EXTRA") list)
6040 (member '("_REF_EXTRA") list))
6041 " (note _EXTRA)" ""))
6043 'idlwave-attach-keyword-classes)))
6045 (t (error "This should not happen (idlwave-complete)")))))
6047 (defvar idlwave-complete-special nil
6048 "List of special completion functions.
6049 These functions are called for each completion. Each function must
6050 check if its own special completion context is present. If yes, it
6051 should use `idlwave-complete-in-buffer' to do some completion and
6052 return t. If such a function returns t, *no further* attempts to
6053 complete other contexts will be done. If the function returns nil,
6054 other completions will be tried.")
6056 (defun idlwave-call-special (functions &rest args)
6057 (let ((funcs functions)
6058 fun ret)
6059 (catch 'exit
6060 (while (setq fun (pop funcs))
6061 (if (setq ret (apply fun args))
6062 (throw 'exit ret)))
6063 nil)))
6065 (defun idlwave-make-force-complete-where-list (what &optional module class)
6066 ;; Return an artificial WHERE specification to force the completion
6067 ;; routine to complete a specific item independent of context.
6068 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6069 ;; MODULE and CLASS can be used to specify the routine name and class.
6070 ;; The class name will also be found in MODULE if that is like "class::mod".
6071 (let* ((what-list '(("procedure") ("procedure-keyword")
6072 ("function") ("function-keyword")
6073 ("procedure-method") ("procedure-method-keyword")
6074 ("function-method") ("function-method-keyword")
6075 ("class")))
6076 (module (idlwave-sintern-routine-or-method module class))
6077 (class (idlwave-sintern-class class))
6078 (what (cond
6079 ((equal what 0)
6080 (setq what
6081 (intern (completing-read
6082 "Complete what? " what-list nil t))))
6083 ((integerp what)
6084 (setq what (intern (car (nth (1- what) what-list)))))
6085 ((and what
6086 (symbolp what)
6087 (assoc (symbol-name what) what-list))
6088 what)
6089 (t (error "Invalid WHAT"))))
6090 (nil-list '(nil nil nil nil))
6091 (class-list (list nil nil (or class t) nil)))
6093 (cond
6095 ((eq what 'procedure)
6096 (list nil-list nil-list 'procedure nil-list nil))
6098 ((eq what 'procedure-keyword)
6099 (let* ((class-selector nil)
6100 (super-classes nil)
6101 (type-selector 'pro)
6102 (pro (or module
6103 (idlwave-completing-read
6104 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6105 (setq pro (idlwave-sintern-routine pro))
6106 (list nil-list nil-list 'procedure-keyword
6107 (list pro nil nil nil) nil)))
6109 ((eq what 'function)
6110 (list nil-list nil-list 'function nil-list nil))
6112 ((eq what 'function-keyword)
6113 (let* ((class-selector nil)
6114 (super-classes nil)
6115 (type-selector 'fun)
6116 (func (or module
6117 (idlwave-completing-read
6118 "Function: " (idlwave-routines) 'idlwave-selector))))
6119 (setq func (idlwave-sintern-routine func))
6120 (list nil-list nil-list 'function-keyword
6121 (list func nil nil nil) nil)))
6123 ((eq what 'procedure-method)
6124 (list nil-list nil-list 'procedure class-list nil))
6126 ((eq what 'procedure-method-keyword)
6127 (let* ((class (idlwave-determine-class class-list 'pro))
6128 (class-selector class)
6129 (super-classes (idlwave-all-class-inherits class-selector))
6130 (type-selector 'pro)
6131 (pro (or module
6132 (idlwave-completing-read
6133 (format "Procedure in %s class: " class-selector)
6134 (idlwave-routines) 'idlwave-selector))))
6135 (setq pro (idlwave-sintern-method pro))
6136 (list nil-list nil-list 'procedure-keyword
6137 (list pro nil class nil) nil)))
6139 ((eq what 'function-method)
6140 (list nil-list nil-list 'function class-list nil))
6142 ((eq what 'function-method-keyword)
6143 (let* ((class (idlwave-determine-class class-list 'fun))
6144 (class-selector class)
6145 (super-classes (idlwave-all-class-inherits class-selector))
6146 (type-selector 'fun)
6147 (func (or module
6148 (idlwave-completing-read
6149 (format "Function in %s class: " class-selector)
6150 (idlwave-routines) 'idlwave-selector))))
6151 (setq func (idlwave-sintern-method func))
6152 (list nil-list nil-list 'function-keyword
6153 (list func nil class nil) nil)))
6155 ((eq what 'class)
6156 (list nil-list nil-list 'class nil-list nil))
6158 (t (error "Invalid value for WHAT")))))
6160 (defun idlwave-completing-read (&rest args)
6161 ;; Completing read, case insensitive
6162 (let ((old-value (default-value 'completion-ignore-case)))
6163 (unwind-protect
6164 (progn
6165 (setq-default completion-ignore-case t)
6166 (apply 'completing-read args))
6167 (setq-default completion-ignore-case old-value))))
6169 (defvar idlwave-shell-default-directory)
6170 (defun idlwave-complete-filename ()
6171 "Use the comint stuff to complete a file name."
6172 (require 'comint)
6173 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6174 (comint-completion-addsuffix nil)
6175 (default-directory
6176 (if (and (boundp 'idlwave-shell-default-directory)
6177 (stringp idlwave-shell-default-directory)
6178 (file-directory-p idlwave-shell-default-directory))
6179 idlwave-shell-default-directory
6180 default-directory)))
6181 (comint-dynamic-complete-filename)))
6183 (defun idlwave-make-full-name (class name)
6184 ;; Make a fully qualified module name including the class name
6185 (concat (if class (format "%s::" class) "") name))
6187 (defun idlwave-rinfo-assoc (name type class list)
6188 "Like `idlwave-rinfo-assq', but sintern strings first."
6189 (idlwave-rinfo-assq
6190 (idlwave-sintern-routine-or-method name class)
6191 type (idlwave-sintern-class class) list))
6193 (defun idlwave-rinfo-assq (name type class list)
6194 ;; Works like assq, but also checks type and class
6195 (catch 'exit
6196 (let (match)
6197 (while (setq match (assq name list))
6198 (and (or (eq type t)
6199 (eq (nth 1 match) type))
6200 (eq (nth 2 match) class)
6201 (throw 'exit match))
6202 (setq list (cdr (memq match list)))))))
6204 (defun idlwave-rinfo-assq-any-class (name type class list)
6205 ;; Return the first matching method on the inheritance list
6206 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6207 class rtn)
6208 (while classes
6209 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6210 (setq classes nil)))
6211 rtn))
6213 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
6214 keep-system)
6215 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6216 If WITH-FILE is passed, find the best rinfo entry with a file
6217 included. If KEEP-SYSTEM is set, don't prune system for compiled
6218 syslib files."
6219 (let ((twins (idlwave-routine-twins
6220 (idlwave-rinfo-assq-any-class name type class list)
6221 list))
6222 syslibp)
6223 (when (> (length twins) 1)
6224 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
6225 (if (and (null keep-system)
6226 (eq 'system (car (nth 3 (car twins))))
6227 (setq syslibp (idlwave-any-syslib (cdr twins)))
6228 (not (equal 1 syslibp)))
6229 ;; Its a compiled syslib, so we need to remove the system entry
6230 (setq twins (cdr twins)))
6231 (if with-file
6232 (setq twins (delq nil
6233 (mapcar (lambda (x)
6234 (if (nth 1 (nth 3 x)) x))
6235 twins)))))
6236 (car twins)))
6238 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
6239 keep-system)
6240 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6241 (idlwave-best-rinfo-assq
6242 (idlwave-sintern-routine-or-method name class)
6243 type (idlwave-sintern-class class) list with-file keep-system))
6245 (defun idlwave-any-syslib (entries)
6246 "Does the entry list ENTRIES contain a syslib entry?
6247 If yes, return the index (>=1)."
6248 (let (file (cnt 0))
6249 (catch 'exit
6250 (while entries
6251 (incf cnt)
6252 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6253 (if (and file (idlwave-syslib-p file))
6254 (throw 'exit cnt)
6255 (setq entries (cdr entries))))
6256 nil)))
6258 (defun idlwave-all-assq (key list)
6259 "Return a list of all associations of Key in LIST."
6260 (let (rtn elt)
6261 (while (setq elt (assq key list))
6262 (push elt rtn)
6263 (setq list (cdr (memq elt list))))
6264 (nreverse rtn)))
6266 (defun idlwave-all-method-classes (method &optional type)
6267 "Return all classes which have a method METHOD.
6268 TYPE is 'fun or 'pro.
6269 When TYPE is not specified, both procedures and functions will be considered."
6270 (if (null method)
6271 (mapcar 'car (idlwave-class-alist))
6272 (let (rtn)
6273 (mapc (lambda (x)
6274 (and (nth 2 x)
6275 (or (not type)
6276 (eq type (nth 1 x)))
6277 (push (nth 2 x) rtn)))
6278 (idlwave-all-assq method (idlwave-routines)))
6279 (idlwave-uniquify rtn))))
6281 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
6282 "Return all classes which have a method METHOD with keyword KEYWORD.
6283 TYPE is 'fun or 'pro.
6284 When TYPE is not specified, both procedures and functions will be considered."
6285 (if (or (null method)
6286 (null keyword))
6288 (let (rtn)
6289 (mapc (lambda (x)
6290 (and (nth 2 x) ; non-nil class
6291 (or (not type) ; correct or unspecified type
6292 (eq type (nth 1 x)))
6293 (assoc keyword (idlwave-entry-keywords x))
6294 (push (nth 2 x) rtn)))
6295 (idlwave-all-assq method (idlwave-routines)))
6296 (idlwave-uniquify rtn))))
6298 (defun idlwave-members-only (list club)
6299 "Return list of all elements in LIST which are also in CLUB."
6300 (let (rtn)
6301 (while list
6302 (if (member (car list) club)
6303 (setq rtn (cons (car list) rtn)))
6304 (setq list (cdr list)))
6305 (nreverse rtn)))
6307 (defun idlwave-nonmembers-only (list club)
6308 "Return list of all elements in LIST which are not in CLUB."
6309 (let (rtn)
6310 (while list
6311 (if (member (car list) club)
6313 (setq rtn (cons (car list) rtn)))
6314 (setq list (cdr list)))
6315 (nreverse rtn)))
6317 (defun idlwave-explicit-class-listed (info)
6318 "Return whether or not the class is listed explicitly, ala a->b::c.
6319 INFO is as returned by `idlwave-what-function' or `-procedure'."
6320 (let ((apos (nth 3 info)))
6321 (if apos
6322 (save-excursion (goto-char apos)
6323 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6325 (defvar idlwave-determine-class-special nil
6326 "List of special functions for determining class.
6327 Must accept two arguments: `apos' and `info'.")
6329 (defun idlwave-determine-class (info type)
6330 ;; Determine the class of a routine call.
6331 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6332 ;; The second element in this structure is the class. When nil, we
6333 ;; return nil. When t, try to get the class from text properties at
6334 ;; the arrow. When the object is "self", we use the class of the
6335 ;; current routine. otherwise prompt the user for a class name.
6336 ;; Also stores the selected class as a text property at the arrow.
6337 ;; TYPE is 'fun or 'pro.
6338 (let* ((class (nth 2 info))
6339 (apos (nth 3 info))
6340 (nassoc (assoc (if (stringp (car info))
6341 (upcase (car info))
6342 (car info))
6343 idlwave-query-class))
6344 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6345 idlwave-query-class))
6346 (query (cond (nassoc (cdr nassoc))
6347 (dassoc (cdr dassoc))
6348 (t t)))
6349 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
6350 (is-self
6351 (and arrow
6352 (save-excursion (goto-char apos)
6353 (forward-word -1)
6354 (let ((case-fold-search t))
6355 (looking-at "self\\>")))))
6356 (force-query idlwave-force-class-query)
6357 store special-class class-alist)
6358 (cond
6359 ((null class) nil)
6360 ((eq t class)
6361 ;; There is an object which would like to know its class
6362 (if (and arrow (get-text-property apos 'idlwave-class)
6363 idlwave-store-inquired-class
6364 (not force-query))
6365 (setq class (get-text-property apos 'idlwave-class)
6366 class (idlwave-sintern-class class)))
6367 (if (and (eq t class) is-self)
6368 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6370 ;; Before prompting, try any special class determination routines
6371 (when (and (eq t class)
6372 idlwave-determine-class-special
6373 (not force-query))
6374 (setq special-class
6375 (idlwave-call-special idlwave-determine-class-special apos))
6376 (if special-class
6377 (setq class (idlwave-sintern-class special-class)
6378 store idlwave-store-inquired-class)))
6380 ;; Prompt for a class, if we need to
6381 (when (and (eq class t)
6382 (or force-query query))
6383 (setq class-alist
6384 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6385 (setq class
6386 (idlwave-sintern-class
6387 (cond
6388 ((and (= (length class-alist) 0) (not force-query))
6389 (error "No classes available with method %s" (car info)))
6390 ((and (= (length class-alist) 1) (not force-query))
6391 (car (car class-alist)))
6393 (setq store idlwave-store-inquired-class)
6394 (idlwave-completing-read
6395 (format "Class%s: " (if (stringp (car info))
6396 (format " for %s method %s"
6397 type (car info))
6398 ""))
6399 class-alist nil nil nil 'idlwave-class-history))))))
6401 ;; Store it, if requested
6402 (when (and class (not (eq t class)))
6403 ;; We have a real class here
6404 (when (and store arrow)
6405 (condition-case ()
6406 (add-text-properties
6407 apos (+ apos 2)
6408 `(idlwave-class ,class face ,idlwave-class-arrow-face
6409 rear-nonsticky t))
6410 (error nil)))
6411 (setf (nth 2 info) class))
6412 ;; Return the class
6413 class)
6414 ;; Default as fallback
6415 (t class))))
6417 (defun idlwave-selector (a)
6418 (and (eq (nth 1 a) type-selector)
6419 (or (and (nth 2 a) (eq class-selector t))
6420 (eq (nth 2 a) class-selector)
6421 (memq (nth 2 a) super-classes))))
6423 (defun idlwave-add-file-link-selector (a)
6424 ;; Record a file link, if any, for the tested names during selection.
6425 (let ((sel (idlwave-selector a)) file)
6426 (if (and sel (setq file (idlwave-entry-has-help a)))
6427 (push (cons (car a) file) idlwave-completion-help-links))
6428 sel))
6431 (defun idlwave-where ()
6432 "Find out where we are.
6433 The return value is a list with the following stuff:
6434 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6436 PRO-LIST (PRO POINT CLASS ARROW)
6437 FUNC-LIST (FUNC POINT CLASS ARROW)
6438 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6439 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6440 be completed here.
6441 LAST-CHAR last relevant character before point (non-white non-comment,
6442 not part of current identifier or leading slash).
6444 In the lists, we have these meanings:
6445 PRO: Procedure name
6446 FUNC: Function name
6447 POINT: Where is this
6448 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6449 ARROW: Location of the arrow"
6450 (idlwave-routines)
6451 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6452 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
6453 (func-entry (idlwave-what-function bos))
6454 (func (car func-entry))
6455 (func-class (nth 1 func-entry))
6456 (func-arrow (nth 2 func-entry))
6457 (func-point (or (nth 3 func-entry) 0))
6458 (func-level (or (nth 4 func-entry) 0))
6459 (pro-entry (idlwave-what-procedure bos))
6460 (pro (car pro-entry))
6461 (pro-class (nth 1 pro-entry))
6462 (pro-arrow (nth 2 pro-entry))
6463 (pro-point (or (nth 3 pro-entry) 0))
6464 (last-char (idlwave-last-valid-char))
6465 (case-fold-search t)
6466 (match-string (buffer-substring bos (point)))
6467 cw cw-mod cw-arrow cw-class cw-point)
6468 (if (< func-point pro-point) (setq func nil))
6469 (cond
6470 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6471 match-string)
6472 (setq cw 'class))
6473 ((string-match
6474 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6475 (if (> pro-point 0)
6476 (buffer-substring pro-point (point))
6477 match-string))
6478 (setq cw 'procedure cw-class pro-class cw-point pro-point
6479 cw-arrow pro-arrow))
6480 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6481 match-string)
6482 nil)
6483 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6484 match-string)
6485 (setq cw 'class))
6486 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6487 match-string)
6488 (setq cw 'class))
6489 ((and func
6490 (> func-point pro-point)
6491 (= func-level 1)
6492 (memq last-char '(?\( ?,)))
6493 (setq cw 'function-keyword cw-mod func cw-point func-point
6494 cw-class func-class cw-arrow func-arrow))
6495 ((and pro (eq last-char ?,))
6496 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6497 cw-class pro-class cw-arrow pro-arrow))
6498 ; ((member last-char '(?\' ?\) ?\] ?!))
6499 ; ;; after these chars, a function makes no sense
6500 ; ;; FIXME: I am sure there can be more in this list
6501 ; ;; FIXME: Do we want to do this at all?
6502 ; nil)
6503 ;; Everywhere else we try a function.
6505 (setq cw 'function)
6506 (save-excursion
6507 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6508 (setq cw-arrow (copy-marker (match-beginning 0))
6509 cw-class (if (match-end 4)
6510 (idlwave-sintern-class (match-string 4))
6511 t))))))
6512 (list (list pro pro-point pro-class pro-arrow)
6513 (list func func-point func-class func-arrow)
6515 (list cw-mod cw-point cw-class cw-arrow)
6516 last-char)))
6518 (defun idlwave-this-word (&optional class)
6519 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6520 (setq class (or class "a-zA-Z0-9$_."))
6521 (save-excursion
6522 (buffer-substring
6523 (progn (skip-chars-backward class) (point))
6524 (progn (skip-chars-forward class) (point)))))
6526 (defun idlwave-what-function (&optional bound)
6527 ;; Find out if point is within the argument list of a function.
6528 ;; The return value is ("function-name" class arrow-start (point) level).
6529 ;; Level is 1 on the top level parentheses, higher further down.
6531 ;; If the optional BOUND is an integer, bound backwards directed
6532 ;; searches to this point.
6534 (catch 'exit
6535 (let (pos
6536 func-point
6537 (cnt 0)
6538 func arrow-start class)
6539 (idlwave-with-special-syntax
6540 (save-restriction
6541 (save-excursion
6542 (narrow-to-region (max 1 (or bound 0)) (point-max))
6543 ;; move back out of the current parenthesis
6544 (while (condition-case nil
6545 (progn (up-list -1) t)
6546 (error nil))
6547 (setq pos (point))
6548 (incf cnt)
6549 (when (and (= (following-char) ?\()
6550 (re-search-backward
6551 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6552 bound t))
6553 (setq func (match-string 2)
6554 func-point (goto-char (match-beginning 2))
6555 pos func-point)
6556 (if (re-search-backward
6557 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6558 (setq arrow-start (copy-marker (match-beginning 0))
6559 class (or (match-string 2) t)))
6560 (throw
6561 'exit
6562 (list
6563 (idlwave-sintern-routine-or-method func class)
6564 (idlwave-sintern-class class)
6565 arrow-start func-point cnt)))
6566 (goto-char pos))
6567 (throw 'exit nil)))))))
6569 (defun idlwave-what-procedure (&optional bound)
6570 ;; Find out if point is within the argument list of a procedure.
6571 ;; The return value is ("procedure-name" class arrow-pos (point)).
6573 ;; If the optional BOUND is an integer, bound backwards directed
6574 ;; searches to this point.
6575 (let ((pos (point)) pro-point
6576 pro class arrow-start string)
6577 (save-excursion
6578 ;;(idlwave-beginning-of-statement)
6579 (idlwave-start-of-substatement 'pre)
6580 (setq string (buffer-substring (point) pos))
6581 (if (string-match
6582 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6583 (setq pro (match-string 1 string)
6584 pro-point (+ (point) (match-beginning 1)))
6585 (if (and (idlwave-skip-object)
6586 (setq string (buffer-substring (point) pos))
6587 (string-match
6588 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6589 string))
6590 (setq pro (if (match-beginning 4)
6591 (match-string 4 string))
6592 pro-point (if (match-beginning 4)
6593 (+ (point) (match-beginning 4))
6594 pos)
6595 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6596 class (or (match-string 3 string) t)))))
6597 (list (idlwave-sintern-routine-or-method pro class)
6598 (idlwave-sintern-class class)
6599 arrow-start
6600 pro-point)))
6602 (defun idlwave-skip-object ()
6603 ;; If there is an object at point, move over it and return t.
6604 (let ((pos (point)))
6605 (if (catch 'exit
6606 (save-excursion
6607 (skip-chars-forward " ") ; white space
6608 (skip-chars-forward "*") ; de-reference
6609 (cond
6610 ((looking-at idlwave-identifier)
6611 (goto-char (match-end 0)))
6612 ((eq (following-char) ?\()
6613 nil)
6614 (t (throw 'exit nil)))
6615 (catch 'endwhile
6616 (while t
6617 (cond ((eq (following-char) ?.)
6618 (forward-char 1)
6619 (if (not (looking-at idlwave-identifier))
6620 (throw 'exit nil))
6621 (goto-char (match-end 0)))
6622 ((memq (following-char) '(?\( ?\[))
6623 (condition-case nil
6624 (forward-list 1)
6625 (error (throw 'exit nil))))
6626 (t (throw 'endwhile t)))))
6627 (if (looking-at "[ \t]*->")
6628 (throw 'exit (setq pos (match-beginning 0)))
6629 (throw 'exit nil))))
6630 (goto-char pos)
6631 nil)))
6633 (defun idlwave-last-valid-char ()
6634 "Return the last character before point which is not white or a comment
6635 and also not part of the current identifier. Since we do this in
6636 order to identify places where keywords are, we consider the initial
6637 `/' of a keyword as part of the identifier.
6638 This function is not general, can only be used for completion stuff."
6639 (catch 'exit
6640 (save-excursion
6641 ;; skip the current identifier
6642 (skip-chars-backward "a-zA-Z0-9_$")
6643 ;; also skip a leading slash which might be belong to the keyword
6644 (if (eq (preceding-char) ?/)
6645 (backward-char 1))
6646 ;; FIXME: does not check if this is a valid identifier
6647 (while t
6648 (skip-chars-backward " \t")
6649 (cond
6650 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6651 ((eq (preceding-char) ?\n)
6652 (beginning-of-line 0)
6653 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6654 ;; continuation line
6655 (goto-char (match-end 1))
6656 (throw 'exit nil)))
6657 (t (throw 'exit (preceding-char))))))))
6659 (defvar idlwave-complete-after-success-form nil
6660 "A form to evaluate after successful completion.")
6661 (defvar idlwave-complete-after-success-form-force nil
6662 "A form to evaluate after completion selection in *Completions* buffer.")
6663 (defconst idlwave-completion-mark (make-marker)
6664 "A mark pointing to the beginning of the completion string.")
6665 (defvar completion-highlight-first-word-only) ;XEmacs.
6667 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6668 &optional prepare-display-function
6669 special-selector)
6670 "Perform TYPE completion of word before point against LIST.
6671 SELECTOR is the PREDICATE argument for the completion function. Show
6672 PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6673 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
6674 used only once, for `all-completions', and can be used to, e.g.,
6675 accumulate information on matching completions."
6676 (let* ((completion-ignore-case t)
6677 beg (end (point)) slash part spart completion all-completions
6678 dpart dcompletion)
6680 (unless list
6681 (error (concat prompt ": No completions available")))
6683 ;; What is already in the buffer?
6684 (save-excursion
6685 (skip-chars-backward "a-zA-Z0-9_$")
6686 (setq slash (eq (preceding-char) ?/)
6687 beg (point)
6688 idlwave-complete-after-success-form
6689 (list 'idlwave-after-successful-completion
6690 (list 'quote type) slash beg)
6691 idlwave-complete-after-success-form-force
6692 (list 'idlwave-after-successful-completion
6693 (list 'quote type) slash (list 'quote 'force))))
6695 ;; Try a completion
6696 (setq part (buffer-substring beg end)
6697 dpart (downcase part)
6698 spart (idlwave-sintern stype part)
6699 completion (try-completion part list selector)
6700 dcompletion (if (stringp completion) (downcase completion))
6701 idlwave-completion-help-links nil)
6702 (cond
6703 ((null completion)
6704 ;; nothing available.
6705 (error (concat prompt ": no completion for \"%s\"") part))
6706 ((and (not (equal dpart dcompletion))
6707 (not (eq t completion)))
6708 ;; We can add something
6709 (delete-region beg end)
6710 (insert (if (and (string= part dpart)
6711 (or (not (string= part ""))
6712 idlwave-complete-empty-string-as-lower-case)
6713 (not idlwave-completion-force-default-case))
6714 dcompletion
6715 completion))
6716 (if (eq t (try-completion completion list selector))
6717 ;; Now this is a unique match
6718 (idlwave-after-successful-completion type slash beg))
6720 ((or (eq completion t)
6721 (and (= 1 (length (setq all-completions
6722 (idlwave-uniquify
6723 (all-completions part list
6724 (or special-selector
6725 selector))))))
6726 (equal dpart dcompletion)))
6727 ;; This is already complete
6728 (idlwave-after-successful-completion type slash beg)
6729 (message "%s is already the complete %s" part isa)
6730 nil)
6732 ;; We cannot add something - offer a list.
6733 (message "Making completion list...")
6735 (unless idlwave-completion-help-links ; already set somewhere?
6736 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6737 (let ((link (get-text-property 0 'link (car x))))
6738 (if link
6739 (push (cons (car x) link)
6740 idlwave-completion-help-links))))
6741 list))
6742 (let* ((list all-completions)
6743 ;; "complete" means, this is already a valid completion
6744 (complete (memq spart all-completions))
6745 (completion-highlight-first-word-only t)) ; XEmacs
6746 ;; (completion-fixup-function ; Emacs
6747 ;; (lambda () (and (eq (preceding-char) ?>)
6748 ;; (re-search-backward " <" beg t)))))
6750 (setq list (sort list (lambda (a b)
6751 (string< (downcase a) (downcase b)))))
6752 (if prepare-display-function
6753 (setq list (funcall prepare-display-function list)))
6754 (if (and (string= part dpart)
6755 (or (not (string= part ""))
6756 idlwave-complete-empty-string-as-lower-case)
6757 (not idlwave-completion-force-default-case))
6758 (setq list (mapcar (lambda (x)
6759 (if (listp x)
6760 (setcar x (downcase (car x)))
6761 (setq x (downcase x)))
6763 list)))
6764 (idlwave-display-completion-list list prompt beg complete))
6765 t))))
6767 (defun idlwave-complete-class ()
6768 "Complete a class at point."
6769 (interactive)
6770 ;; Call `idlwave-routines' to make sure the class list will be available
6771 (idlwave-routines)
6772 ;; Check for the special case of completing empty string after pro/function
6773 (if (let ((case-fold-search t))
6774 (save-excursion
6775 (and
6776 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6777 (- (point) 15) t)
6778 (goto-char (point-min))
6779 (re-search-forward
6780 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6781 ;; Yank the full class specification
6782 (insert (match-string 2))
6783 ;; Do the completion, using list gathered from `idlwave-routines'
6784 (idlwave-complete-in-buffer
6785 'class 'class (idlwave-class-alist) nil
6786 "Select a class" "class"
6787 (lambda (list) ;; Push it to help-links if system help available
6788 (mapcar (lambda (x)
6789 (let* ((entry (idlwave-class-info x))
6790 (link (nth 1 (assq 'link entry))))
6791 (if link (push (cons x link)
6792 idlwave-completion-help-links))
6794 list)))))
6796 (defun idlwave-attach-classes (list type show-classes)
6797 ;; Attach the proper class list to a LIST of completion items.
6798 ;; TYPE, when 'kwd, shows classes for method keywords, when
6799 ;; 'class-tag, for class tags, and otherwise for methods.
6800 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6801 (if (or (null show-classes) ; don't want to see classes
6802 (null class-selector) ; not a method call
6803 (and
6804 (stringp class-selector) ; the class is already known
6805 (not super-classes))) ; no possibilities for inheritance
6806 ;; In these cases, we do not have to do anything
6807 list
6808 (let* ((do-prop (and (>= show-classes 0)
6809 (>= emacs-major-version 21)))
6810 (do-buf (not (= show-classes 0)))
6811 ;; (do-dots (featurep 'xemacs))
6812 (do-dots t)
6813 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6814 (cons class-selector super-classes)))
6815 (max (abs show-classes))
6816 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6817 classes nclasses class-info space)
6818 (mapcar
6819 (lambda (x)
6820 ;; get the classes
6821 (if (eq type 'class-tag)
6822 ;; Just one class for tags
6823 (setq classes
6824 (list
6825 (idlwave-class-or-superclass-with-tag class-selector x)))
6826 ;; Multiple classes for method or method-keyword
6827 (setq classes
6828 (if (eq type 'kwd)
6829 (idlwave-all-method-keyword-classes
6830 method-selector x type-selector)
6831 (idlwave-all-method-classes x type-selector)))
6832 (if inherit
6833 (setq classes
6834 (delq nil
6835 (mapcar (lambda (x) (if (memq x inherit) x nil))
6836 classes)))))
6837 (setq nclasses (length classes))
6838 ;; Make the separator between item and class-info
6839 (if do-dots
6840 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6841 (setq space " "))
6842 (if do-buf
6843 ;; We do want info in the buffer
6844 (if (<= nclasses max)
6845 (setq class-info (concat
6846 space
6847 "<" (mapconcat 'identity classes ",") ">"))
6848 (setq class-info (format "%s<%d classes>" space nclasses)))
6849 (setq class-info nil))
6850 (when do-prop
6851 ;; We do want properties
6852 (setq x (copy-sequence x))
6853 (put-text-property 0 (length x)
6854 'help-echo (mapconcat 'identity classes " ")
6856 (if class-info
6857 (list x class-info)
6859 list))))
6861 (defun idlwave-attach-method-classes (list)
6862 ;; Call idlwave-attach-classes with method parameters
6863 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6864 (defun idlwave-attach-keyword-classes (list)
6865 ;; Call idlwave-attach-classes with keyword parameters
6866 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6867 (defun idlwave-attach-class-tag-classes (list)
6868 ;; Call idlwave-attach-classes with class structure tags
6869 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6872 ;;----------------------------------------------------------------------
6873 ;;----------------------------------------------------------------------
6874 ;;----------------------------------------------------------------------
6875 ;;----------------------------------------------------------------------
6876 ;;----------------------------------------------------------------------
6877 (when (featurep 'xemacs)
6878 (defvar rtn)
6879 (defun idlwave-pset (item)
6880 (set 'rtn item)))
6882 (defun idlwave-popup-select (ev list title &optional sort)
6883 "Select an item in LIST with a popup menu.
6884 TITLE is the title to put atop the popup. If SORT is non-nil,
6885 sort the list before displaying."
6886 (let ((maxpopup idlwave-max-popup-menu-items)
6887 rtn menu)
6888 (cond ((null list))
6889 ((= 1 (length list))
6890 (setq rtn (car list)))
6891 ((featurep 'xemacs)
6892 (if sort (setq list (sort list (lambda (a b)
6893 (string< (upcase a) (upcase b))))))
6894 (setq menu
6895 (append (list title)
6896 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6897 x)))
6898 list)))
6899 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6900 (let ((resp (get-popup-menu-response menu)))
6901 (funcall (event-function resp) (event-object resp))))
6903 (if sort (setq list (sort list (lambda (a b)
6904 (string< (upcase a) (upcase b))))))
6905 (setq menu (cons title
6906 (list
6907 (append (list "")
6908 (mapcar (lambda(x) (cons x x)) list)))))
6909 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6910 (setq rtn (x-popup-menu ev menu))))
6911 rtn))
6913 (defun idlwave-split-menu-xemacs (menu N)
6914 "Split the MENU into submenus of maximum length N."
6915 (if (<= (length menu) (1+ N))
6916 ;; No splitting needed
6917 menu
6918 (let* ((title (car menu))
6919 (entries (cdr menu))
6920 (menu (list title))
6921 (cnt 0)
6922 (nextmenu nil))
6923 (while entries
6924 (while (and entries (< cnt N))
6925 (setq cnt (1+ cnt)
6926 nextmenu (cons (car entries) nextmenu)
6927 entries (cdr entries)))
6928 (setq nextmenu (nreverse nextmenu))
6929 (setq nextmenu (cons (format "%s...%s"
6930 (aref (car nextmenu) 0)
6931 (aref (nth (1- cnt) nextmenu) 0))
6932 nextmenu))
6933 (setq menu (cons nextmenu menu)
6934 nextmenu nil
6935 cnt 0))
6936 (nreverse menu))))
6938 (defun idlwave-split-menu-emacs (menu N)
6939 "Split the MENU into submenus of maximum length N."
6940 (if (<= (length (nth 1 menu)) (1+ N))
6941 ;; No splitting needed
6942 menu
6943 (let* ((title (car menu))
6944 (entries (cdr (nth 1 menu)))
6945 (menu nil)
6946 (cnt 0)
6947 (nextmenu nil))
6948 (while entries
6949 (while (and entries (< cnt N))
6950 (setq cnt (1+ cnt)
6951 nextmenu (cons (car entries) nextmenu)
6952 entries (cdr entries)))
6953 (setq nextmenu (nreverse nextmenu))
6954 (prin1 nextmenu)
6955 (setq nextmenu (cons (format "%s...%s"
6956 (car (car nextmenu))
6957 (car (nth (1- cnt) nextmenu)))
6958 nextmenu))
6959 (setq menu (cons nextmenu menu)
6960 nextmenu nil
6961 cnt 0))
6962 (setq menu (nreverse menu))
6963 (setq menu (cons title menu))
6964 menu)))
6966 (defvar idlwave-completion-setup-hook nil)
6968 (defun idlwave-scroll-completions (&optional message)
6969 "Scroll the completion window on this frame."
6970 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6971 (win (selected-window)))
6972 (unwind-protect
6973 (progn
6974 (select-window cwin)
6975 (condition-case nil
6976 (scroll-up)
6977 (error (if (and (listp last-command)
6978 (nth 2 last-command))
6979 (progn
6980 (select-window win)
6981 (eval idlwave-complete-after-success-form))
6982 (set-window-start cwin (point-min)))))
6983 (and message (message "%s" message)))
6984 (select-window win))))
6986 (defun idlwave-display-completion-list (list &optional message beg complete)
6987 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6988 (unless (and (get-buffer-window "*Completions*")
6989 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6990 (move-marker idlwave-completion-mark beg)
6991 (setq idlwave-before-completion-wconf (current-window-configuration)))
6993 (if (featurep 'xemacs)
6994 (idlwave-display-completion-list-xemacs
6995 list)
6996 (idlwave-display-completion-list-emacs list))
6998 ;; Store a special value in `this-command'. When `idlwave-complete'
6999 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7000 (setq this-command (list 'idlwave-display-completion-list message complete))
7002 ;; Mark the completions buffer as created by cib
7003 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
7005 ;; Fontify the classes
7006 (if (and idlwave-completion-fontify-classes
7007 (consp (car list)))
7008 (idlwave-completion-fontify-classes))
7010 ;; Run the hook
7011 (run-hooks 'idlwave-completion-setup-hook)
7013 ;; Display the message
7014 (message "%s" (or message "Making completion list...done")))
7016 (defun idlwave-choose (function &rest args)
7017 "Call FUNCTION as a completion chooser and pass ARGS to it."
7018 (let ((completion-ignore-case t)) ; install correct value
7019 (apply function args))
7020 (if (and (derived-mode-p 'idlwave-shell-mode)
7021 (boundp 'font-lock-mode)
7022 (not font-lock-mode))
7023 ;; For the shell, remove the fontification of the word before point
7024 (let ((beg (save-excursion
7025 (skip-chars-backward "a-zA-Z0-9_")
7026 (point))))
7027 (remove-text-properties beg (point) '(face nil))))
7028 (eval idlwave-complete-after-success-form-force))
7030 (defun idlwave-keyboard-quit ()
7031 (interactive)
7032 (unwind-protect
7033 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7034 (idlwave-restore-wconf-after-completion))
7035 (keyboard-quit)))
7037 (defun idlwave-restore-wconf-after-completion ()
7038 "Restore the old (before completion) window configuration."
7039 (and idlwave-completion-restore-window-configuration
7040 idlwave-before-completion-wconf
7041 (set-window-configuration idlwave-before-completion-wconf)))
7043 (defun idlwave-one-key-select (sym prompt delay)
7044 "Make the user select an element from the alist in the variable SYM.
7045 The keys of the alist are expected to be strings. The function returns the
7046 car of the selected association.
7047 To do this, PROMPT is displayed and the user must hit a letter key to
7048 select an entry. If the user does not reply within DELAY seconds, a help
7049 window with the options is displayed automatically.
7050 The key which is associated with each option is generated automatically.
7051 First, the strings are checked for preselected keys, like in \"[P]rint\".
7052 If these don't exist, a letter in the string is automatically selected."
7053 (let* ((alist (symbol-value sym))
7054 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7055 '(fit-window-to-buffer)))
7056 keys-alist char)
7057 ;; First check the cache
7058 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7059 (setq keys-alist (get sym :one-key-alist-cache))
7060 ;; Need to make new list
7061 (setq keys-alist (idlwave-make-one-key-alist alist))
7062 (put sym :one-key-alist-cache keys-alist)
7063 (put sym :one-key-alist-last alist))
7064 ;; Display prompt and wait for quick reply
7065 (message "%s[%s]" prompt
7066 (mapconcat (lambda(x) (char-to-string (car x)))
7067 keys-alist ""))
7068 (if (sit-for delay)
7069 ;; No quick reply: Show help
7070 (save-window-excursion
7071 (with-output-to-temp-buffer "*Completions*"
7072 (mapcar (lambda(x)
7073 (princ (nth 1 x))
7074 (princ "\n"))
7075 keys-alist))
7076 (setq char (read-char)))
7077 (setq char (read-char)))
7078 (message nil)
7079 ;; Return the selected result
7080 (nth 2 (assoc char keys-alist))))
7082 ;; Used for, e.g., electric debug super-examine.
7083 (defun idlwave-make-one-key-alist (alist)
7084 "Make an alist for single key selection."
7085 (let ((l alist) keys-alist name start char help
7086 (cnt 0)
7087 (case-fold-search nil))
7088 (while l
7089 (setq name (car (car l))
7090 l (cdr l))
7091 (catch 'exit
7092 ;; First check if the configuration predetermined a key
7093 (if (string-match "\\[\\(.\\)\\]" name)
7094 (progn
7095 (setq char (string-to-char (downcase (match-string 1 name)))
7096 help (format "%c: %s" char name)
7097 keys-alist (cons (list char help name) keys-alist))
7098 (throw 'exit t)))
7099 ;; Then check for capital letters
7100 (setq start 0)
7101 (while (string-match "[A-Z]" name start)
7102 (setq start (match-end 0)
7103 char (string-to-char (downcase (match-string 0 name))))
7104 (if (not (assoc char keys-alist))
7105 (progn
7106 (setq help (format "%c: %s" char
7107 (replace-match
7108 (concat "[" (match-string 0 name) "]")
7109 t t name))
7110 keys-alist (cons (list char help name) keys-alist))
7111 (throw 'exit t))))
7112 ;; Now check for lowercase letters
7113 (setq start 0)
7114 (while (string-match "[a-z]" name start)
7115 (setq start (match-end 0)
7116 char (string-to-char (match-string 0 name)))
7117 (if (not (assoc char keys-alist))
7118 (progn
7119 (setq help (format "%c: %s" char
7120 (replace-match
7121 (concat "[" (match-string 0 name) "]")
7122 t t name))
7123 keys-alist (cons (list char help name) keys-alist))
7124 (throw 'exit t))))
7125 ;; Bummer, nothing found! Use a stupid number
7126 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7127 help (format "%c: %s" char name)
7128 keys-alist (cons (list char help name) keys-alist))))
7129 (nreverse keys-alist)))
7131 (defun idlwave-set-local (var value &optional buffer)
7132 "Set the buffer-local value of VAR in BUFFER to VALUE."
7133 (with-current-buffer (or buffer (current-buffer))
7134 (set (make-local-variable var) value)))
7136 (defun idlwave-local-value (var &optional buffer)
7137 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7138 (with-current-buffer (or buffer (current-buffer))
7139 (and (local-variable-p var (current-buffer))
7140 (symbol-value var))))
7142 ;; In XEmacs, we can use :activate-callback directly to advice the
7143 ;; choose functions. We use the private keymap only for the online
7144 ;; help feature.
7146 (defvar idlwave-completion-map nil
7147 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7149 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
7150 (with-output-to-temp-buffer "*Completions*"
7151 (apply 'display-completion-list list
7152 ':activate-callback 'idlwave-default-choose-completion
7153 cl-args))
7154 (with-current-buffer "*Completions*"
7155 (use-local-map
7156 (or idlwave-completion-map
7157 (setq idlwave-completion-map
7158 (idlwave-make-modified-completion-map-xemacs
7159 (current-local-map)))))))
7161 (defun idlwave-default-choose-completion (&rest args)
7162 "Execute `default-choose-completion' and then restore the win-conf."
7163 (apply 'idlwave-choose 'default-choose-completion args))
7165 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7166 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7167 (let ((new-map (copy-keymap old-map)))
7168 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7169 (define-key new-map [button3] (lambda ()
7170 (interactive)
7171 (setq this-command last-command)))
7172 new-map))
7174 ;; In Emacs we also replace keybindings in the completion
7175 ;; map in order to install our wrappers.
7177 (defun idlwave-display-completion-list-emacs (list)
7178 "Display completion list and install the choose wrappers."
7179 (with-output-to-temp-buffer "*Completions*"
7180 (display-completion-list list))
7181 (with-current-buffer "*Completions*"
7182 (use-local-map
7183 (or idlwave-completion-map
7184 (setq idlwave-completion-map
7185 (idlwave-make-modified-completion-map-emacs
7186 (current-local-map)))))))
7188 (defun idlwave-make-modified-completion-map-emacs (old-map)
7189 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7190 (let ((new-map (copy-keymap old-map)))
7191 (substitute-key-definition
7192 'choose-completion 'idlwave-choose-completion new-map)
7193 (substitute-key-definition
7194 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7195 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7196 new-map))
7198 (defun idlwave-choose-completion (&rest args)
7199 "Choose the completion that point is in or next to."
7200 (interactive)
7201 (apply 'idlwave-choose 'choose-completion args))
7203 (defun idlwave-mouse-choose-completion (&rest args)
7204 "Click on an alternative in the `*Completions*' buffer to choose it."
7205 (interactive "e")
7206 (apply 'idlwave-choose 'mouse-choose-completion args))
7208 ;;----------------------------------------------------------------------
7209 ;;----------------------------------------------------------------------
7211 ;;; ------------------------------------------------------------------------
7212 ;;; Stucture parsing code, and code to manage class info
7215 ;; - Go again over the documentation how to write a completion
7216 ;; plugin. It is in self.el, but currently still very bad.
7217 ;; This could be in a separate file in the distribution, or
7218 ;; in an appendix for the manual.
7220 (defvar idlwave-struct-skip
7221 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7222 "Regexp for skipping continued blank or comment-only lines in structures.")
7224 (defvar idlwave-struct-tag-regexp
7225 (concat "[{,]" ;leading comma/brace
7226 idlwave-struct-skip ; 4 groups
7227 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7228 "[ \t]*:") ; the final colon
7229 "Regexp for structure tags.")
7231 (defun idlwave-struct-tags ()
7232 "Return a list of all tags in the structure defined at point.
7233 Point is expected just before the opening `{' of the struct definition."
7234 (save-excursion
7235 (let* ((borders (idlwave-struct-borders))
7236 (beg (car borders))
7237 (end (cdr borders))
7238 tags)
7239 (goto-char beg)
7240 (save-restriction
7241 (narrow-to-region beg end)
7242 (while (re-search-forward idlwave-struct-tag-regexp end t)
7243 ;; Check if we are still on the top level of the structure.
7244 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7245 (= (point) beg))
7246 (push (match-string-no-properties 5) tags))
7247 (goto-char (match-end 0))))
7248 (nreverse tags))))
7250 (defun idlwave-find-struct-tag (tag)
7251 "Find a given TAG in the structure defined at point."
7252 (let* ((borders (idlwave-struct-borders))
7253 (end (cdr borders))
7254 (case-fold-search t))
7255 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7256 end t)))
7258 (defun idlwave-struct-inherits ()
7259 "Return a list of all `inherits' names in the struct at point.
7260 Point is expected just before the opening `{' of the struct definition."
7261 (save-excursion
7262 (let* ((borders (idlwave-struct-borders))
7263 (beg (car borders))
7264 (end (cdr borders))
7265 (case-fold-search t)
7266 names)
7267 (goto-char beg)
7268 (save-restriction
7269 (narrow-to-region beg end)
7270 (while (re-search-forward
7271 (concat "[{,]" ;leading comma/brace
7272 idlwave-struct-skip ; 4 groups
7273 "inherits" ; The INHERITS tag
7274 idlwave-struct-skip ; 4 more
7275 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7276 end t)
7277 ;; Check if we are still on the top level of the structure.
7278 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7279 (= (point) beg))
7280 (push (match-string-no-properties 9) names))
7281 (goto-char (match-end 0))))
7282 (nreverse names))))
7284 (defun idlwave-in-structure ()
7285 "Return t if point is inside an IDL structure definition."
7286 (let ((beg (point)))
7287 (save-excursion
7288 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7289 (if (idlwave-find-structure-definition nil nil 'back)
7290 (let ((borders (idlwave-struct-borders)))
7291 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7292 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7294 (defun idlwave-struct-borders ()
7295 "Return the borders of the {...} after point as a cons cell."
7296 (let (beg)
7297 (save-excursion
7298 (skip-chars-forward "^{")
7299 (setq beg (point))
7300 (condition-case nil (forward-list 1)
7301 (error (goto-char beg)))
7302 (cons beg (point)))))
7304 (defun idlwave-find-structure-definition (&optional var name bound)
7305 "Search forward for a structure definition.
7306 If VAR is non-nil, search for a structure assigned to variable VAR.
7307 If NAME is non-nil, search for a named structure NAME, if a string,
7308 or a generic named structure otherwise. If BOUND is an integer, limit
7309 the search. If BOUND is the symbol `all', we search first back and
7310 then forward through the entire file. If BOUND is the symbol `back'
7311 we search only backward."
7312 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7313 (case-fold-search t)
7314 (lim (if (integerp bound) bound nil))
7315 (re (concat
7316 (if var
7317 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7318 "\\(\\)")
7319 "=" ws "\\({\\)"
7320 (if name
7321 (if (stringp name)
7322 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7323 ;; Just a generic name
7324 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7325 ""))))
7326 (if (or (and (or (eq bound 'all) (eq bound 'back))
7327 (re-search-backward re nil t))
7328 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7329 (progn
7330 (goto-char (match-beginning 3))
7331 (match-string-no-properties 5)))))
7333 (defvar idlwave-class-info nil)
7334 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7336 (add-hook 'idlwave-update-rinfo-hook
7337 (lambda () (setq idlwave-class-reset t)))
7338 (add-hook 'idlwave-after-load-rinfo-hook
7339 (lambda () (setq idlwave-class-info nil)))
7341 (defun idlwave-class-info (class)
7342 (let (list entry)
7343 (if idlwave-class-info
7344 (if idlwave-class-reset
7345 (setq
7346 idlwave-class-reset nil
7347 idlwave-class-info ; Remove any visited in a buffer
7348 (delq nil (mapcar
7349 (lambda (x)
7350 (let ((filebuf
7351 (idlwave-class-file-or-buffer
7352 (or (cdr (assq 'found-in x)) (car x)))))
7353 (if (cdr filebuf)
7355 x)))
7356 idlwave-class-info))))
7357 ;; Info is nil, put in the system stuff to start.
7358 (setq idlwave-class-info idlwave-system-class-info)
7359 (setq list idlwave-class-info)
7360 (while (setq entry (pop list))
7361 (idlwave-sintern-class-info entry)))
7362 (setq class (idlwave-sintern-class class))
7363 (or (assq class idlwave-class-info)
7364 (progn (idlwave-scan-class-info class)
7365 (assq class idlwave-class-info)))))
7367 (defun idlwave-sintern-class-info (entry)
7368 "Sintern the class names in a class-info entry."
7369 (let ((inherits (assq 'inherits entry)))
7370 (setcar entry (idlwave-sintern-class (car entry) 'set))
7371 (if inherits
7372 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7373 (cdr inherits))))))
7375 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7376 "Find class structure definition(s).
7377 If ALL-HOOK is set, find all named structure definitions in a given
7378 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7379 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7380 class/struct definition."
7381 (let ((case-fold-search t) end-lim name)
7382 (when (re-search-forward
7383 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7384 (if all-hook
7385 (progn
7386 ;; For everything there
7387 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7388 (while (setq name
7389 (idlwave-find-structure-definition nil t end-lim))
7390 (funcall all-hook name)))
7391 (idlwave-find-structure-definition nil (or alt-class class))))))
7394 (defun idlwave-class-file-or-buffer (class)
7395 "Find buffer visiting CLASS definition."
7396 (let* ((pro (concat (downcase class) "__define"))
7397 (file (idlwave-routine-source-file
7398 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7399 (idlwave-routines))))))
7400 (cons file (if file (idlwave-get-buffer-visiting file)))))
7403 (defun idlwave-scan-class-info (class)
7404 "Scan all class and named structure info in the class__define pro."
7405 (let* ((idlwave-auto-routine-info-updates nil)
7406 (filebuf (idlwave-class-file-or-buffer class))
7407 (file (car filebuf))
7408 (buf (cdr filebuf))
7409 (class (idlwave-sintern-class class)))
7410 (if (or
7411 (not file)
7412 (and ;; neither a regular file nor a visited buffer
7413 (not buf)
7414 (not (file-regular-p file))))
7415 nil ; Cannot find the file/buffer to get any info
7416 (save-excursion
7417 (if buf (set-buffer buf)
7418 ;; Read the file in temporarily
7419 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7420 (erase-buffer)
7421 (unless (derived-mode-p 'idlwave-mode)
7422 (idlwave-mode))
7423 (insert-file-contents file))
7424 (save-excursion
7425 (goto-char 1)
7426 (idlwave-find-class-definition class
7427 ;; Scan all of the structures found there
7428 (lambda (name)
7429 (let* ((this-class (idlwave-sintern-class name))
7430 (entry
7431 (list this-class
7432 (cons 'tags (idlwave-struct-tags))
7433 (cons 'inherits (idlwave-struct-inherits)))))
7434 (if (not (eq this-class class))
7435 (setq entry (nconc entry (list (cons 'found-in class)))))
7436 (idlwave-sintern-class-info entry)
7437 (push entry idlwave-class-info)))))))))
7439 (defun idlwave-class-found-in (class)
7440 "Return the FOUND-IN property of the CLASS."
7441 (cdr (assq 'found-in (idlwave-class-info class))))
7442 (defun idlwave-class-tags (class)
7443 "Return the native tags in CLASS."
7444 (cdr (assq 'tags (idlwave-class-info class))))
7445 (defun idlwave-class-inherits (class)
7446 "Return the direct superclasses of CLASS."
7447 (cdr (assq 'inherits (idlwave-class-info class))))
7450 (defun idlwave-all-class-tags (class)
7451 "Return a list of native and inherited tags in CLASS."
7452 (condition-case err
7453 (apply 'append (mapcar 'idlwave-class-tags
7454 (cons class (idlwave-all-class-inherits class))))
7455 (error
7456 (idlwave-class-tag-reset)
7457 (error "%s" (error-message-string err)))))
7460 (defun idlwave-all-class-inherits (class)
7461 "Return a list of all superclasses of CLASS (recursively expanded).
7462 The list is cached in `idlwave-class-info' for faster access."
7463 (cond
7464 ((not idlwave-support-inheritance) nil)
7465 ((eq class nil) nil)
7466 ((eq class t) nil)
7468 (let ((info (idlwave-class-info class))
7469 entry)
7470 (if (setq entry (assq 'all-inherits info))
7471 (cdr entry)
7472 ;; Save the depth of inheritance scan to check for circular references
7473 (let ((inherits (mapcar (lambda (x) (cons x 0))
7474 (idlwave-class-inherits class)))
7475 rtn all-inherits cl)
7476 (while inherits
7477 (setq cl (pop inherits)
7478 rtn (cons (car cl) rtn)
7479 inherits (append (mapcar (lambda (x)
7480 (cons x (1+ (cdr cl))))
7481 (idlwave-class-inherits (car cl)))
7482 inherits))
7483 (if (> (cdr cl) 999)
7484 (error
7485 "Class scan: inheritance depth exceeded. Circular inheritance?")
7487 (setq all-inherits (nreverse rtn))
7488 (nconc info (list (cons 'all-inherits all-inherits)))
7489 all-inherits))))))
7491 (defun idlwave-entry-keywords (entry &optional record-link)
7492 "Return the flat entry keywords alist from routine-info entry.
7493 If RECORD-LINK is non-nil, the keyword text is copied and a text
7494 property indicating the link is added."
7495 (let (kwds)
7496 (mapc
7497 (lambda (key-list)
7498 (let ((file (car key-list)))
7499 (mapcar (lambda (key-cons)
7500 (let ((key (car key-cons))
7501 (link (cdr key-cons)))
7502 (when (and record-link file)
7503 (setq key (copy-sequence key))
7504 (put-text-property
7505 0 (length key)
7506 'link
7507 (concat
7508 file
7509 (if link
7510 (concat idlwave-html-link-sep
7511 (number-to-string link))))
7512 key))
7513 (push (list key) kwds)))
7514 (cdr key-list))))
7515 (nthcdr 5 entry))
7516 (nreverse kwds)))
7518 (defun idlwave-entry-find-keyword (entry keyword)
7519 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7520 (catch 'exit
7521 (mapc
7522 (lambda (key-list)
7523 (let ((file (car key-list))
7524 (kwd (assoc keyword (cdr key-list))))
7525 (when kwd
7526 (setq kwd (cons (car kwd)
7527 (if (and file (cdr kwd))
7528 (concat file
7529 idlwave-html-link-sep
7530 (number-to-string (cdr kwd)))
7531 (cdr kwd))))
7532 (throw 'exit kwd))))
7533 (nthcdr 5 entry))))
7535 ;;==========================================================================
7537 ;; Completing class structure tags. This is a completion plugin.
7538 ;; The necessary taglist is constructed dynamically
7540 (defvar idlwave-current-tags-class nil)
7541 (defvar idlwave-current-class-tags nil)
7542 (defvar idlwave-current-native-class-tags nil)
7543 (defvar idlwave-sint-class-tags nil)
7544 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7545 (idlwave-new-sintern-type 'class-tag)
7546 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7547 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7549 (defun idlwave-complete-class-structure-tag ()
7550 "Complete a structure tag on a `self' argument in an object method."
7551 (interactive)
7552 (let ((pos (point))
7553 (case-fold-search t))
7554 (if (save-excursion
7555 ;; Check if the context is right
7556 (skip-chars-backward "a-zA-Z0-9._$")
7557 (and (< (point) (- pos 4))
7558 (looking-at "self\\.")))
7559 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7560 (super-classes (idlwave-all-class-inherits class-selector)))
7561 ;; Check if we are in a class routine
7562 (unless class-selector
7563 (error "Not in a method procedure or function"))
7564 ;; Check if we need to update the "current" class
7565 (if (not (equal class-selector idlwave-current-tags-class))
7566 (idlwave-prepare-class-tag-completion class-selector))
7567 (setq idlwave-completion-help-info
7568 (list 'idlwave-complete-class-structure-tag-help
7569 (idlwave-sintern-routine
7570 (concat class-selector "__define"))
7571 nil))
7572 ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
7573 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7574 (idlwave-complete-in-buffer
7575 'class-tag 'class-tag
7576 idlwave-current-class-tags nil
7577 (format "Select a tag of class %s" class-selector)
7578 "class tag"
7579 'idlwave-attach-class-tag-classes))
7580 t) ; return t to skip other completions
7581 nil)))
7583 (defun idlwave-class-tag-reset ()
7584 (setq idlwave-current-tags-class nil))
7586 (defun idlwave-prepare-class-tag-completion (class)
7587 "Find and parse the necessary class definitions for class structure tags."
7588 (setq idlwave-sint-class-tags nil)
7589 (setq idlwave-current-tags-class class)
7590 (setq idlwave-current-class-tags
7591 (mapcar (lambda (x)
7592 (list (idlwave-sintern-class-tag x 'set)))
7593 (idlwave-all-class-tags class)))
7594 (setq idlwave-current-native-class-tags
7595 (mapcar 'downcase (idlwave-class-tags class))))
7597 ;===========================================================================
7599 ;; Completing system variables and their structure fields
7600 ;; This is also a plugin.
7602 (defvar idlwave-sint-sysvars nil)
7603 (defvar idlwave-sint-sysvartags nil)
7604 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7605 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7606 (idlwave-new-sintern-type 'sysvar)
7607 (idlwave-new-sintern-type 'sysvartag)
7608 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7609 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7610 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7613 (defun idlwave-complete-sysvar-or-tag ()
7614 "Complete a system variable."
7615 (interactive)
7616 (let ((pos (point))
7617 (case-fold-search t))
7618 (cond ((save-excursion
7619 ;; Check if the context is right for system variable
7620 (skip-chars-backward "[a-zA-Z0-9_$]")
7621 (equal (char-before) ?!))
7622 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7623 (idlwave-complete-in-buffer 'sysvar 'sysvar
7624 idlwave-system-variables-alist nil
7625 "Select a system variable"
7626 "system variable")
7627 t) ; return t to skip other completions
7628 ((save-excursion
7629 ;; Check if the context is right for sysvar tag
7630 (skip-chars-backward "a-zA-Z0-9_$.")
7631 (and (equal (char-before) ?!)
7632 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7633 (<= (match-end 0) pos)))
7634 ;; Complete a system variable tag
7635 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7636 (entry (assq var idlwave-system-variables-alist))
7637 (tags (cdr (assq 'tags entry))))
7638 (or entry (error "!%s is not a known system variable" var))
7639 (or tags (error "System variable !%s is not a structure" var))
7640 (setq idlwave-completion-help-info
7641 (list 'idlwave-complete-sysvar-tag-help var))
7642 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7643 tags nil
7644 "Select a system variable tag"
7645 "system variable tag")
7646 t)) ; return t to skip other completions
7647 (t nil))))
7649 (defvar idlw-help-link) ;dynamic variables set by help callback
7650 (defun idlwave-complete-sysvar-help (mode word)
7651 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7652 (entry (assoc word idlwave-system-variables-alist)))
7653 (cond
7654 ((eq mode 'test)
7655 (and (stringp word) entry (nth 1 (assq 'link entry))))
7656 ((eq mode 'set)
7657 ;; Setting dynamic!!!
7658 (if entry (setq idlw-help-link (nth 1 (assq 'link entry)))))
7659 (t (error "This should not happen")))))
7661 (defun idlwave-complete-sysvar-tag-help (mode word)
7662 (let* ((var (nth 1 idlwave-completion-help-info))
7663 (entry (assoc var idlwave-system-variables-alist))
7664 (tags (cdr (assq 'tags entry)))
7665 (main (nth 1 (assq 'link entry)))
7666 target)
7667 (cond
7668 ((eq mode 'test) ; we can at least link the main
7669 (and (stringp word) entry main))
7670 ((eq mode 'set)
7671 (if entry
7672 (setq idlw-help-link
7673 (if (setq target (cdr (assoc-string word tags t)))
7674 (idlwave-substitute-link-target main target)
7675 main)))) ;; setting dynamic!!!
7676 (t (error "This should not happen")))))
7678 (defun idlwave-split-link-target (link)
7679 "Split a given LINK into link file and anchor."
7680 (if (string-match idlwave-html-link-sep link)
7681 (cons (substring link 0 (match-beginning 0))
7682 (string-to-number (substring link (match-end 0))))))
7684 (defun idlwave-substitute-link-target (link target)
7685 "Substitute the TARGET anchor for the given LINK."
7686 (let (main-base)
7687 (setq main-base (if (string-match "#" link)
7688 (substring link 0 (match-beginning 0))
7689 link))
7690 (if target
7691 (concat main-base idlwave-html-link-sep (number-to-string target))
7692 link)))
7694 ;; Fake help in the source buffer for class structure tags.
7695 ;; IDLW-HELP-LINK AND IDLW-HELP-NAME ARE GLOBAL-VARIABLES HERE.
7696 ;; (from idlwave-do-mouse-completion-help)
7697 (defvar idlw-help-name)
7698 (defvar idlw-help-link)
7699 (defvar idlwave-help-do-class-struct-tag nil)
7700 (defun idlwave-complete-class-structure-tag-help (mode word)
7701 (cond
7702 ((eq mode 'test) ; nothing gets fontified for class tags
7703 nil)
7704 ((eq mode 'set)
7705 (let (class-with found-in)
7706 (when (setq class-with
7707 (idlwave-class-or-superclass-with-tag
7708 idlwave-current-tags-class
7709 word))
7710 (if (assq (idlwave-sintern-class class-with)
7711 idlwave-system-class-info)
7712 (error "No help available for system class tags"))
7713 (if (setq found-in (idlwave-class-found-in class-with))
7714 (setq idlw-help-name (cons (concat found-in "__define") class-with))
7715 (setq idlw-help-name (concat class-with "__define")))))
7716 (setq idlw-help-link word
7717 idlwave-help-do-class-struct-tag t))
7718 (t (error "This should not happen"))))
7720 (defun idlwave-class-or-superclass-with-tag (class tag)
7721 "Find and return the CLASS or one of its superclass with the
7722 associated TAG, if any."
7723 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7725 (catch 'exit
7726 (while sclasses
7727 (setq cl (pop sclasses))
7728 (let ((tags (idlwave-class-tags cl)))
7729 (while tags
7730 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7731 (throw 'exit cl))
7732 (setq tags (cdr tags))))))))
7735 (defun idlwave-sysvars-reset ()
7736 (if (and (fboundp 'idlwave-shell-is-running)
7737 (idlwave-shell-is-running)
7738 idlwave-idlwave_routine_info-compiled)
7739 (idlwave-shell-send-command "idlwave_get_sysvars"
7740 'idlwave-process-sysvars 'hide)))
7742 (defun idlwave-process-sysvars ()
7743 (idlwave-shell-filter-sysvars)
7744 (setq idlwave-sint-sysvars nil
7745 idlwave-sint-sysvartags nil)
7746 (idlwave-sintern-sysvar-alist))
7748 (defun idlwave-sintern-sysvar-alist ()
7749 (let ((list idlwave-system-variables-alist) entry tags)
7750 (while (setq entry (pop list))
7751 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7752 (setq tags (assq 'tags entry))
7753 (if tags
7754 (setcdr tags
7755 (mapcar (lambda (x)
7756 (cons (idlwave-sintern-sysvartag (car x) 'set)
7757 (cdr x)))
7758 (cdr tags)))))))
7760 (defvar idlwave-shell-command-output)
7761 (defun idlwave-shell-filter-sysvars ()
7762 "Get any new system variables and tags."
7763 (let ((text idlwave-shell-command-output)
7764 (start 0)
7765 (old idlwave-system-variables-alist)
7766 var tags type name class link old-entry)
7767 (setq idlwave-system-variables-alist nil)
7768 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7769 text start)
7770 (setq start (match-end 0)
7771 var (match-string 1 text)
7772 tags (if (match-end 3)
7773 (idlwave-split-string (match-string 3 text))))
7774 ;; Maintain old links, if present
7775 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7776 (setq link (assq 'link old-entry))
7777 (setq idlwave-system-variables-alist
7778 (cons (list var
7779 (cons
7780 'tags
7781 (mapcar (lambda (x)
7782 (cons x
7783 (cdr (assq
7784 (idlwave-sintern-sysvartag x)
7785 (cdr (assq 'tags old-entry))))))
7786 tags)) link)
7787 idlwave-system-variables-alist)))
7788 ;; Keep the old value if query was not successful
7789 (setq idlwave-system-variables-alist
7790 (or idlwave-system-variables-alist old))))
7792 (defun idlwave-completion-fontify-classes ()
7793 "Goto the *Completions* buffer and fontify the class info."
7794 (when (featurep 'font-lock)
7795 (with-current-buffer "*Completions*"
7796 (save-excursion
7797 (goto-char (point-min))
7798 (let ((buffer-read-only nil))
7799 (while (re-search-forward "\\.*<[^>]+>" nil t)
7800 (put-text-property (match-beginning 0) (match-end 0)
7801 'face 'font-lock-string-face)))))))
7803 (defun idlwave-uniquify (list)
7804 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7805 (delq nil
7806 (mapcar (lambda (x)
7807 (unless (gethash x ht)
7808 (puthash x t ht)
7810 list))))
7812 (defun idlwave-after-successful-completion (type slash &optional verify)
7813 "Add `=' or `(' after successful completion of keyword and function.
7814 Restore the pre-completion window configuration if possible."
7815 (cond
7816 ((eq type 'procedure)
7817 nil)
7818 ((eq type 'function)
7819 (cond
7820 ((equal idlwave-function-completion-adds-paren nil) nil)
7821 ((or (equal idlwave-function-completion-adds-paren t)
7822 (equal idlwave-function-completion-adds-paren 1))
7823 (insert "("))
7824 ((equal idlwave-function-completion-adds-paren 2)
7825 (insert "()")
7826 (backward-char 1))
7827 (t nil)))
7828 ((eq type 'keyword)
7829 (if (and idlwave-keyword-completion-adds-equal
7830 (not slash))
7831 (progn (insert "=") t)
7832 nil)))
7834 ;; Restore the pre-completion window configuration if this is safe.
7836 (if (or (eq verify 'force) ; force
7837 (and
7838 (get-buffer-window "*Completions*") ; visible
7839 (idlwave-local-value 'idlwave-completion-p
7840 "*Completions*") ; cib-buffer
7841 (eq (marker-buffer idlwave-completion-mark)
7842 (current-buffer)) ; buffer OK
7843 (equal (marker-position idlwave-completion-mark)
7844 verify))) ; pos OK
7845 (idlwave-restore-wconf-after-completion))
7846 (move-marker idlwave-completion-mark nil)
7847 (setq idlwave-before-completion-wconf nil))
7849 (defun idlwave-mouse-context-help (ev &optional arg)
7850 "Call `idlwave-context-help' on the clicked location."
7851 (interactive "eP")
7852 (mouse-set-point ev)
7853 (idlwave-context-help arg))
7855 (defvar idlwave-last-context-help-pos nil)
7856 (defun idlwave-context-help (&optional arg)
7857 "Display IDL Online Help on context.
7858 If point is on a keyword, help for that keyword will be shown. If
7859 point is on a routine name or in the argument list of a routine, help
7860 for that routine will be displayed. Works for system routines and
7861 keywords, it pulls up text help. For other routies and keywords,
7862 visits the source file, finding help in the header (if
7863 `idlwave-help-source-try-header' is non-nil) or the routine definition
7864 itself."
7865 (interactive "P")
7866 (idlwave-do-context-help arg))
7868 (defun idlwave-mouse-completion-help (ev)
7869 "Display online help about the completion at point."
7870 (interactive "eP")
7871 ;; Restore last-command for next command, to make
7872 ;; scrolling/cancelling of completions work.
7873 (setq this-command last-command)
7874 (idlwave-do-mouse-completion-help ev))
7876 (defun idlwave-routine-info (&optional arg external)
7877 "Display a routines calling sequence and list of keywords.
7878 When point is on the name a function or procedure, or in the argument
7879 list of a function or procedure, this command displays a help buffer with
7880 the information. When called with prefix arg, enforce class query.
7882 When point is on an object operator `->', display the class stored in
7883 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7884 arg, the class property is cleared out."
7886 (interactive "P")
7887 (idlwave-routines)
7888 (if (string-match "->" (buffer-substring
7889 (max (point-min) (1- (point)))
7890 (min (+ 2 (point)) (point-max))))
7891 ;; Cursor is on an arrow
7892 (if (get-text-property (point) 'idlwave-class)
7893 ;; arrow has class property
7894 (if arg
7895 ;; Remove property
7896 (save-excursion
7897 (backward-char 1)
7898 (when (looking-at ".?\\(->\\)")
7899 (remove-text-properties (match-beginning 1) (match-end 1)
7900 '(idlwave-class nil face nil))
7901 (message "Class property removed from arrow")))
7902 ;; Echo class property
7903 (message "Arrow has text property identifying object to be class %s"
7904 (get-text-property (point) 'idlwave-class)))
7905 ;; No property found
7906 (message "Arrow has no class text property"))
7908 ;; Not on an arrow...
7909 (let* ((idlwave-query-class nil)
7910 (idlwave-force-class-query (equal arg '(4)))
7911 (module (idlwave-what-module)))
7912 (if (car module)
7913 (apply 'idlwave-display-calling-sequence
7914 (idlwave-fix-module-if-obj_new module))
7915 (error "Don't know which calling sequence to show")))))
7917 (defun idlwave-resolve (&optional arg)
7918 "Call RESOLVE_ROUTINE on the module name at point.
7919 Like `idlwave-routine-info', this looks for a routine call at point.
7920 After confirmation in the minibuffer, it will use the shell to issue
7921 a RESOLVE call for this routine, to attempt to make it defined and its
7922 routine info available for IDLWAVE. If the routine is a method call,
7923 both `class__method' and `class__define' will be tried.
7924 With ARG, enforce query for the class of object methods."
7925 (interactive "P")
7926 (let* ((idlwave-query-class nil)
7927 (idlwave-force-class-query (equal arg '(4)))
7928 (module (idlwave-what-module))
7929 (name (idlwave-make-full-name (nth 2 module) (car module)))
7930 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7931 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7932 (kwd "")
7933 class)
7934 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7935 resolve)
7936 (setq type (match-string 1 resolve)
7937 class (if (match-beginning 2)
7938 (match-string 3 resolve)
7939 nil)
7940 name (match-string 4 resolve)))
7941 (if (string= (downcase type) "function")
7942 (setq kwd ",/is_function"))
7944 (cond
7945 ((null class)
7946 (idlwave-shell-send-command
7947 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7948 'idlwave-update-routine-info
7949 nil t))
7951 (idlwave-shell-send-command
7952 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7953 (list 'idlwave-shell-send-command
7954 (format "resolve_routine,'%s__%s'%s"
7955 (downcase class) (downcase name) kwd)
7956 '(idlwave-update-routine-info)
7957 nil t))))))
7959 (defun idlwave-find-module-this-file ()
7960 (interactive)
7961 (idlwave-find-module '(4)))
7963 (defun idlwave-find-module (&optional arg)
7964 "Find the source code of an IDL module.
7965 Works for modules for which IDLWAVE has routine info available.
7966 The function offers as default the module name `idlwave-routine-info'
7967 would use. With ARG limit to this buffer. With two prefix ARG's
7968 force class query for object methods."
7969 (interactive "P")
7970 (let* ((idlwave-query-class nil)
7971 (idlwave-force-class-query (equal arg '(16)))
7972 (this-buffer (equal arg '(4)))
7973 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7974 (default (if module
7975 (concat (idlwave-make-full-name
7976 (nth 2 module) (car module))
7977 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7978 "none"))
7979 (list
7980 (idlwave-uniquify
7981 (delq nil
7982 (mapcar (lambda (x)
7983 (if (eq 'system (car-safe (nth 3 x)))
7984 ;; Take out system routines with no source.
7986 (list
7987 (concat (idlwave-make-full-name
7988 (nth 2 x) (car x))
7989 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7990 (if this-buffer
7991 (idlwave-save-buffer-update)
7992 (idlwave-routines))))))
7993 (name (idlwave-completing-read
7994 (if (or (not this-buffer)
7995 (assoc default list))
7996 (format "Module (Default %s): " default)
7997 (format "Module in this file: "))
7998 list))
7999 type class)
8000 (if (string-match "\\`\\s-*\\'" name)
8001 ;; Nothing, use the default.
8002 (setq name default))
8003 (if (string-match "<[fp]>" name)
8004 (setq type (substring name -2 -1)
8005 name (substring name 0 -3)))
8006 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8007 (setq class (match-string 1 name)
8008 name (match-string 2 name)))
8009 (setq name (idlwave-sintern-routine-or-method name class)
8010 class (idlwave-sintern-class class)
8011 type (cond ((equal type "f") 'fun)
8012 ((equal type "p") 'pro)
8013 (t t)))
8014 (idlwave-do-find-module name type class nil this-buffer)))
8016 (defun idlwave-do-find-module (name type class
8017 &optional force-source this-buffer)
8018 (let ((name1 (idlwave-make-full-name class name))
8019 source buf1 entry
8020 (buf (current-buffer))
8021 (pos (point))
8022 file name2)
8023 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8024 'WITH-FILE)
8025 source (or force-source (nth 3 entry))
8026 name2 (if (nth 2 entry)
8027 (idlwave-make-full-name (nth 2 entry) name)
8028 name1))
8029 (if source
8030 (setq file (idlwave-routine-source-file source)))
8031 (unless file ; Try to find it on the path.
8032 (setq file
8033 (idlwave-expand-lib-file-name
8034 (if class
8035 (format "%s__define.pro" (downcase class))
8036 (format "%s.pro" (downcase name))))))
8037 (cond
8038 ((or (null name) (equal name ""))
8039 (error "Abort"))
8040 ((eq (car source) 'system)
8041 (error "Source code for system routine %s is not available"
8042 name2))
8043 ((or (not file) (not (file-regular-p file)))
8044 (error "Source code for routine %s is not available"
8045 name2))
8047 (when (not this-buffer)
8048 (setq buf1
8049 (idlwave-find-file-noselect file 'find))
8050 (pop-to-buffer buf1 t))
8051 (goto-char (point-max))
8052 (let ((case-fold-search t))
8053 (if (re-search-backward
8054 (concat "^[ \t]*\\<"
8055 (cond ((eq type 'fun) "function")
8056 ((eq type 'pro) "pro")
8057 (t "\\(pro\\|function\\)"))
8058 "\\>[ \t]+"
8059 (regexp-quote (downcase name2))
8060 "[^a-zA-Z0-9_$]")
8061 nil t)
8062 (goto-char (match-beginning 0))
8063 (pop-to-buffer buf)
8064 (goto-char pos)
8065 (error "Could not find routine %s" name2)))))))
8067 (defun idlwave-what-module ()
8068 "Return a default module for stuff near point.
8069 Used by `idlwave-routine-info' and `idlwave-find-module'."
8070 (idlwave-routines)
8071 (if (let ((case-fold-search t))
8072 (save-excursion
8073 (idlwave-beginning-of-statement)
8074 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8075 ;; This is a function or procedure definition statement
8076 ;; We return the defined routine as module.
8077 (list
8078 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8079 (match-string-no-properties 2))
8080 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8081 (idlwave-sintern-class (match-string 3)))
8083 ;; Not a definition statement - analyze precise position.
8084 (let* ((where (idlwave-where))
8085 (cw (nth 2 where))
8086 (pro (car (nth 0 where)))
8087 (func (car (nth 1 where)))
8088 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8089 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8090 (following-char)))
8092 (cond
8093 ((and (eq cw 'procedure)
8094 (not (equal this-word "")))
8095 (setq this-word (idlwave-sintern-routine-or-method
8096 this-word (nth 2 (nth 3 where))))
8097 (list this-word 'pro
8098 (idlwave-determine-class
8099 (cons this-word (cdr (nth 3 where)))
8100 'pro)))
8101 ((and (eq cw 'function)
8102 (not (equal this-word ""))
8103 (or (eq next-char ?\() ; exclude arrays, vars.
8104 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8105 (setq this-word (idlwave-sintern-routine-or-method
8106 this-word (nth 2 (nth 3 where))))
8107 (list this-word 'fun
8108 (idlwave-determine-class
8109 (cons this-word (cdr (nth 3 where)))
8110 'fun)))
8111 ((and (memq cw '(function-keyword procedure-keyword))
8112 (not (equal this-word ""))
8113 (eq next-char ?\()) ; A function!
8114 (setq this-word (idlwave-sintern-routine this-word))
8115 (list this-word 'fun nil))
8116 (func
8117 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8118 (pro
8119 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8120 (t nil)))))
8122 (defun idlwave-what-module-find-class ()
8123 "Call `idlwave-what-module' and find the inherited class if necessary."
8124 (let* ((module (idlwave-what-module))
8125 (class (nth 2 module)))
8126 (if (and (= (length module) 3)
8127 (stringp class))
8128 (list (car module)
8129 (nth 1 module)
8130 (apply 'idlwave-find-inherited-class module))
8131 module)))
8133 (defun idlwave-find-inherited-class (name type class)
8134 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8135 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8136 (if entry
8137 (nth 2 entry)
8138 class)))
8140 (defun idlwave-fix-module-if-obj_new (module)
8141 "Check if MODULE points to obj_new.
8142 If yes, and if the cursor is in the keyword region, change to the
8143 appropriate Init method."
8144 (let* ((name (car module))
8145 (pos (point))
8146 (case-fold-search t)
8147 string)
8148 (if (and (stringp name)
8149 (equal (downcase name) "obj_new")
8150 (save-excursion
8151 (idlwave-beginning-of-statement)
8152 (setq string (buffer-substring (point) pos))
8153 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8154 string)))
8155 (let ((name "Init")
8156 (class (match-string 1 string)))
8157 (setq module (list (idlwave-sintern-method "Init")
8158 'fun
8159 (idlwave-sintern-class class)))))
8160 module))
8162 (defun idlwave-fix-keywords (name type class keywords
8163 &optional super-classes system)
8164 "Update a list of keywords.
8165 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8166 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8167 demand _EXTRA in the keyword list."
8168 (let ((case-fold-search t))
8170 ;; If this is the OBJ_NEW function, try to figure out the class and use
8171 ;; the keywords from the corresponding INIT method.
8172 (if (and (equal (upcase name) "OBJ_NEW")
8173 (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
8174 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8175 (string (buffer-substring bos (point)))
8176 (case-fold-search t)
8177 class)
8178 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8179 string)
8180 (setq class (idlwave-sintern-class (match-string 1 string)))
8181 (setq idlwave-current-obj_new-class class)
8182 (setq keywords
8183 (append keywords
8184 (idlwave-entry-keywords
8185 (idlwave-rinfo-assq
8186 (idlwave-sintern-method "INIT")
8187 'fun
8188 class
8189 (idlwave-routines)) 'do-link))))))
8191 ;; If the class is `t', combine all keywords of all methods NAME
8192 (when (eq class t)
8193 (mapc (lambda (entry)
8194 (and
8195 (nth 2 entry) ; non-nil class
8196 (eq (nth 1 entry) type) ; correct type
8197 (setq keywords
8198 (append keywords
8199 (idlwave-entry-keywords entry 'do-link)))))
8200 (idlwave-all-assq name (idlwave-routines)))
8201 (setq keywords (idlwave-uniquify keywords)))
8203 ;; If we have inheritance, add all keywords from superclasses, if
8204 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8205 (when (and
8206 super-classes
8207 idlwave-keyword-class-inheritance
8208 (stringp class)
8210 system
8211 (assq (idlwave-sintern-keyword "_extra") keywords)
8212 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8213 ;; Check if one of the keyword-class regexps matches the name
8214 (let ((regexps idlwave-keyword-class-inheritance) re)
8215 (catch 'exit
8216 (while (setq re (pop regexps))
8217 (if (string-match re name) (throw 'exit t))))))
8219 (loop for entry in (idlwave-routines) do
8220 (and (nth 2 entry) ; non-nil class
8221 (memq (nth 2 entry) super-classes) ; an inherited class
8222 (eq (nth 1 entry) type) ; correct type
8223 (eq (car entry) name) ; correct name
8224 (mapc (lambda (k) (add-to-list 'keywords k))
8225 (idlwave-entry-keywords entry 'do-link))))
8226 (setq keywords (idlwave-uniquify keywords)))
8228 ;; Return the final list
8229 keywords))
8231 (defun idlwave-expand-keyword (keyword module)
8232 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8233 KEYWORD may be an exact match or an abbreviation of a keyword.
8234 If the match is exact, KEYWORD itself is returned, even if there may be other
8235 keywords of which KEYWORD is an abbreviation. This is necessary because some
8236 system routines have keywords which are prefixes of other keywords.
8237 If KEYWORD is an abbreviation of several keywords, a list of all possible
8238 completions is returned.
8239 If the abbreviation was unique, the correct keyword is returned.
8240 If it cannot be a keyword, the function return nil.
8241 If we do not know about MODULE, just return KEYWORD literally."
8242 (let* ((name (car module))
8243 (type (nth 1 module))
8244 (class (nth 2 module))
8245 (kwd (idlwave-sintern-keyword keyword))
8246 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8247 (kwd-alist (idlwave-entry-keywords entry))
8248 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8249 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8250 (completion-ignore-case t)
8251 candidates)
8252 (cond ((assq kwd kwd-alist)
8253 kwd)
8254 ((setq candidates (all-completions kwd kwd-alist))
8255 (if (= (length candidates) 1)
8256 (car candidates)
8257 candidates))
8258 ((and entry extra)
8259 ;; Inheritance may cause this keyword to be correct
8260 keyword)
8261 (entry
8262 ;; We do know the function, which does not have the keyword.
8263 nil)
8265 ;; We do not know the function, so this just might be a correct
8266 ;; keyword - return it as it is.
8267 keyword))))
8269 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
8270 (defvar idlwave-rinfo-map (make-sparse-keymap))
8271 (define-key idlwave-rinfo-mouse-map
8272 (if (featurep 'xemacs) [button2] [mouse-2])
8273 'idlwave-mouse-active-rinfo)
8274 (define-key idlwave-rinfo-mouse-map
8275 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8276 'idlwave-mouse-active-rinfo-shift)
8277 (define-key idlwave-rinfo-mouse-map
8278 (if (featurep 'xemacs) [button3] [mouse-3])
8279 'idlwave-mouse-active-rinfo-right)
8280 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8281 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8282 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8283 (defvar idlwave-popup-source nil)
8284 (defvar idlwave-rinfo-marker (make-marker))
8286 (defun idlwave-quit-help ()
8287 (interactive)
8288 (let ((ri-window (get-buffer-window "*Help*"))
8289 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8290 (when (and olh-window
8291 (fboundp 'idlwave-help-quit))
8292 (select-window olh-window)
8293 (idlwave-help-quit))
8294 (when (window-live-p ri-window)
8295 (delete-window ri-window))))
8297 (defun idlwave-display-calling-sequence (name type class
8298 &optional initial-class)
8299 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8300 (let* ((initial-class (or initial-class class))
8301 (entry (or (idlwave-best-rinfo-assq name type class
8302 (idlwave-routines))
8303 (idlwave-rinfo-assq name type class
8304 idlwave-unresolved-routines)))
8305 (name (or (car entry) name))
8306 (class (or (nth 2 entry) class))
8307 (superclasses (idlwave-all-class-inherits initial-class))
8308 (twins (idlwave-routine-twins entry))
8309 (dtwins (idlwave-study-twins twins))
8310 (all dtwins)
8311 (system (eq (car (nth 3 entry)) 'system))
8312 (calling-seq (nth 4 entry))
8313 (keywords (idlwave-entry-keywords entry 'do-link))
8314 (html-file (car (nth 5 entry)))
8315 (help-echo-kwd
8316 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8317 (help-echo-use
8318 "Button2/3: Online Help")
8319 (help-echo-src
8320 "Button2: Jump to source and back | Button3: Source in Help window.")
8321 (help-echo-class
8322 "Button2: Display info about same method in superclass")
8323 (col 0)
8324 (data (list name type class (current-buffer) nil initial-class))
8325 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8326 (face 'idlwave-help-link)
8327 beg props win cnt total)
8328 ;; Fix keywords, but don't add chained super-classes, since these
8329 ;; are shown separately for that super-class
8330 (setq keywords (idlwave-fix-keywords name type class keywords))
8331 (cond
8332 ((null entry)
8333 (error "No %s %s known %s" type name
8334 (if initial-class (concat "in class " initial-class) "")))
8335 ((or (null name) (equal name ""))
8336 (error "No function or procedure call at point"))
8337 ((null calling-seq)
8338 (error "Calling sequence of %s %s not available" type name))
8340 (move-marker idlwave-rinfo-marker (point))
8341 (with-current-buffer (get-buffer-create "*Help*")
8342 (use-local-map idlwave-rinfo-map)
8343 (setq buffer-read-only nil)
8344 (erase-buffer)
8345 (set (make-local-variable 'idlwave-popup-source) nil)
8346 (set (make-local-variable 'idlwave-current-obj_new-class)
8347 idlwave-current-obj_new-class)
8348 (when superclasses
8349 (setq props (list 'mouse-face 'highlight
8350 km-prop idlwave-rinfo-mouse-map
8351 'help-echo help-echo-class
8352 'data (cons 'class data)))
8353 (let ((classes (cons initial-class superclasses)) c)
8354 (insert "Classes: ")
8355 (while (setq c (pop classes))
8356 (insert " ")
8357 (setq beg (point))
8358 (insert c)
8359 (if (equal (downcase c) (downcase class))
8360 (add-text-properties beg (point) (list 'face 'bold))
8361 ;; If Method exists in a different class link it
8362 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8363 (add-text-properties beg (point) props))))
8364 (insert "\n")))
8365 (setq props (list 'mouse-face 'highlight
8366 km-prop idlwave-rinfo-mouse-map
8367 'help-echo help-echo-use
8368 'data (cons 'usage data)))
8369 (if html-file (setq props (append (list 'face face 'link html-file)
8370 props)))
8371 (insert "Usage: ")
8372 (setq beg (point))
8373 (insert (if class
8374 (format calling-seq class name class name class name)
8375 (format calling-seq name name name name))
8376 "\n")
8377 (add-text-properties beg (point) props)
8379 (insert "Keywords:")
8380 (if (null keywords)
8381 (insert " No keywords accepted.")
8382 (setq col 9)
8383 (mapc
8384 (lambda (x)
8385 (if (>= (+ col 1 (length (car x)))
8386 (window-width))
8387 (progn
8388 (insert "\n ")
8389 (setq col 9)))
8390 (insert " ")
8391 (setq beg (point)
8392 ;; Relevant keywords already have link property attached
8393 props (list 'mouse-face 'highlight
8394 km-prop idlwave-rinfo-mouse-map
8395 'data (cons 'keyword data)
8396 'help-echo help-echo-kwd
8397 'keyword (car x)))
8398 (if system (setq props (append (list 'face face) props)))
8399 (insert (car x))
8400 (add-text-properties beg (point) props)
8401 (setq col (+ col 1 (length (car x)))))
8402 keywords))
8404 (setq cnt 1 total (length all))
8405 ;; Here entry is (key file (list of type-conses))
8406 (while (setq entry (pop all))
8407 (setq props (list 'mouse-face 'highlight
8408 km-prop idlwave-rinfo-mouse-map
8409 'help-echo help-echo-src
8410 'source (list (car (car (nth 2 entry))) ;type
8411 (nth 1 entry)
8413 (cdr (car (nth 2 entry))))
8414 'data (cons 'source data)))
8415 (idlwave-insert-source-location
8416 (format "\n%-8s %s"
8417 (if (equal cnt 1)
8418 (if (> total 1) "Sources:" "Source:")
8420 (if (> total 1) "- " ""))
8421 entry props)
8422 (incf cnt)
8423 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8424 ;; No more source lines, please
8425 (insert (format
8426 "\n Source information truncated to %d entries."
8427 idlwave-rinfo-max-source-lines))
8428 (setq all nil)))
8429 (goto-char (point-min))
8430 (setq buffer-read-only t))
8431 (display-buffer "*Help*")
8432 (if (and (setq win (get-buffer-window "*Help*"))
8433 idlwave-resize-routine-help-window)
8434 (progn
8435 (let ((ww (selected-window)))
8436 (unwind-protect
8437 (progn
8438 (select-window win)
8439 (enlarge-window (- (/ (frame-height) 2)
8440 (window-height)))
8441 (shrink-window-if-larger-than-buffer))
8442 (select-window ww)))))))))
8444 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8445 "Insert a source location into the routine info buffer.
8446 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8447 to it."
8448 (let* ((key (car entry))
8449 (file (nth 1 entry))
8450 (types (nth 2 entry))
8451 (shell-flag (assq 'compiled types))
8452 (buffer-flag (assq 'buffer types))
8453 (user-flag (assq 'user types))
8454 (lib-flag (assq 'lib types))
8455 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8456 (and user-flag (idlwave-count-memq 'user types))
8457 (and lib-flag (idlwave-count-memq 'lib types))
8459 (doflags t)
8460 beg special)
8462 (insert prefix)
8464 (cond
8465 ((eq key 'system)
8466 (setq doflags nil)
8467 (insert "System "))
8469 ((eq key 'builtin)
8470 (setq doflags nil)
8471 (insert "Builtin "))
8473 ((and (not file) shell-flag)
8474 (insert "Unresolved"))
8476 ((null file)
8477 (insert "ERROR"))
8479 ((idlwave-syslib-p file)
8480 (if (string-match "obsolete" (file-name-directory file))
8481 (insert "Obsolete ")
8482 (insert "SystemLib ")))
8484 ;; New special syntax: taken directly from routine-info for
8485 ;; library catalog routines
8486 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8487 (insert (format "%-10s" special)))
8489 ;; Old special syntax: a matching regexp
8490 ((setq special (idlwave-special-lib-test file))
8491 (insert (format "%-10s" special)))
8493 ;; Catch-all with file
8494 ((idlwave-lib-p file) (insert "Library "))
8496 ;; Sanity catch all
8497 (t (insert "Other ")))
8499 (when doflags
8500 (insert (concat
8501 " ["
8502 (if lib-flag "L" "-")
8503 (if user-flag "C" "-")
8504 (if shell-flag "S" "-")
8505 (if buffer-flag "B" "-")
8506 "] ")))
8507 (when (> ndupl 1)
8508 (setq beg (point))
8509 (insert (format "(%dx) " ndupl))
8510 (add-text-properties beg (point) (list 'face 'bold)))
8511 (when (and file (not (equal file "")))
8512 (setq beg (point))
8513 (insert (apply 'abbreviate-file-name
8514 (if (featurep 'xemacs) (list file t) (list file))))
8515 (if file-props
8516 (add-text-properties beg (point) file-props)))))
8518 (defun idlwave-special-lib-test (file)
8519 "Check the path of FILE against the regexps which define special libs.
8520 Return the name of the special lib if there is a match."
8521 (let ((alist idlwave-special-lib-alist)
8522 entry rtn)
8523 (cond
8524 ((stringp file)
8525 (while (setq entry (pop alist))
8526 (if (string-match (car entry) file)
8527 (setq rtn (cdr entry)
8528 alist nil)))
8529 rtn)
8530 (t nil))))
8532 (defun idlwave-mouse-active-rinfo-right (ev)
8533 (interactive "e")
8534 (idlwave-mouse-active-rinfo ev 'right))
8536 (defun idlwave-mouse-active-rinfo-shift (ev)
8537 (interactive "e")
8538 (idlwave-mouse-active-rinfo ev nil 'shift))
8540 (defun idlwave-active-rinfo-space ()
8541 (interactive)
8542 (idlwave-mouse-active-rinfo nil 'right))
8544 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8545 "Do the mouse actions in the routine info buffer.
8546 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8547 was pressed."
8548 (interactive "e")
8549 (if ev (mouse-set-point ev))
8550 (let (data id name type class buf bufwin source link keyword
8551 word initial-class)
8552 (setq data (get-text-property (point) 'data)
8553 source (get-text-property (point) 'source)
8554 keyword (get-text-property (point) 'keyword)
8555 link (get-text-property (point) 'link)
8556 id (car data)
8557 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8558 buf (nth 4 data)
8559 initial-class (nth 6 data)
8560 word (idlwave-this-word)
8561 bufwin (get-buffer-window buf t))
8563 (cond ((eq id 'class) ; Switch class being displayed
8564 (if (window-live-p bufwin) (select-window bufwin))
8565 (idlwave-display-calling-sequence
8566 (idlwave-sintern-method name)
8567 type (idlwave-sintern-class word)
8568 initial-class))
8569 ((eq id 'usage) ; Online help on this routine
8570 (idlwave-online-help link name type class))
8571 ((eq id 'source) ; Source in help or buffer
8572 (if right ; In help
8573 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8574 (idlwave-help-source-try-header nil)
8575 ;; Fake idlwave-routines so help will find the right entry
8576 (idlwave-routines
8577 (list (list name type class source ""))))
8578 (idlwave-help-get-special-help name type class nil))
8579 ;; Otherwise just pop to the source
8580 (setq idlwave-popup-source (not idlwave-popup-source))
8581 (if idlwave-popup-source
8582 (condition-case err
8583 (idlwave-do-find-module name type class source)
8584 (error
8585 (setq idlwave-popup-source nil)
8586 (if (window-live-p bufwin) (select-window bufwin))
8587 (error (nth 1 err))))
8588 (if bufwin
8589 (select-window bufwin)
8590 (pop-to-buffer buf))
8591 (goto-char (marker-position idlwave-rinfo-marker)))))
8592 ((eq id 'keyword)
8593 (if right
8594 (idlwave-online-help link name type class keyword)
8595 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8597 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8598 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8599 (let ((bwin (get-buffer-window buffer)))
8600 (if idlwave-complete-empty-string-as-lower-case
8601 (setq keyword (downcase keyword)))
8602 (if bwin
8603 (select-window bwin)
8604 (pop-to-buffer buffer)
8605 (setq bwin (get-buffer-window buffer)))
8606 (if (eq (preceding-char) ?/)
8607 (insert keyword)
8608 (unless (save-excursion
8609 (re-search-backward
8610 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8611 (min (- (point) 100) (point-min)) t))
8612 (insert ", "))
8613 (if shift (insert "/"))
8614 (insert keyword)
8615 (if (and (not shift)
8616 idlwave-keyword-completion-adds-equal)
8617 (insert "=")))))
8619 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8620 "List the load path shadows of all routines defined in current buffer."
8621 (interactive "P")
8622 (idlwave-routines)
8623 (if (derived-mode-p 'idlwave-mode)
8624 (idlwave-list-load-path-shadows
8625 nil (idlwave-update-current-buffer-info 'save-buffer)
8626 "in current buffer")
8627 (error "Current buffer is not in idlwave-mode")))
8629 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8630 "List the load path shadows of all routines compiled under the shell.
8631 This is very useful for checking an IDL application. Just compile the
8632 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8633 routines and update IDLWAVE internal info. Then check for shadowing
8634 with this command."
8635 (interactive "P")
8636 (cond
8637 ((or (not (fboundp 'idlwave-shell-is-running))
8638 (not (idlwave-shell-is-running)))
8639 (error "Shell is not running"))
8640 ((null idlwave-compiled-routines)
8641 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8643 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8644 "in the shell"))))
8646 (defun idlwave-list-all-load-path-shadows (&optional arg)
8647 "List the load path shadows of all routines known to IDLWAVE."
8648 (interactive "P")
8649 (idlwave-list-load-path-shadows nil nil "globally"))
8651 (defvar idlwave-sort-prefer-buffer-info t
8652 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8654 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8655 "List the routines which are defined multiple times.
8656 Search the information IDLWAVE has about IDL routines for multiple
8657 definitions.
8658 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8660 When IDL hits a routine call which is not defined, it will search on
8661 the load path in order to find a definition. The output of this command
8662 can be used to detect possible name clashes during this process."
8663 (idlwave-routines) ; Make sure everything is loaded.
8664 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8665 (or (y-or-n-p
8666 "You don't have any user or library catalogs. Continue anyway? ")
8667 (error "Abort")))
8668 (let* ((routines (append idlwave-system-routines
8669 idlwave-compiled-routines
8670 idlwave-library-catalog-routines
8671 idlwave-user-catalog-routines
8672 idlwave-buffer-routines
8673 nil))
8674 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8675 (keymap (make-sparse-keymap))
8676 (props (list 'mouse-face 'highlight
8677 km-prop keymap
8678 'help-echo "Mouse2: Find source"))
8679 (nroutines (length (or special-routines routines)))
8680 (step (/ nroutines 100))
8681 (n 0)
8682 (cnt 0)
8683 (idlwave-sort-prefer-buffer-info nil)
8684 routine twins dtwins twin done props1 lroutines)
8686 (if special-routines
8687 ;; Just looking for shadows of a few special routines
8688 (setq lroutines routines
8689 routines special-routines))
8691 (message "Sorting routines...")
8692 (setq routines (sort routines
8693 (lambda (a b)
8694 (string< (downcase (idlwave-make-full-name
8695 (nth 2 a) (car a)))
8696 (downcase (idlwave-make-full-name
8697 (nth 2 b) (car b)))))))
8698 (message "Sorting routines...done")
8700 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8701 (lambda (ev)
8702 (interactive "e")
8703 (mouse-set-point ev)
8704 (apply 'idlwave-do-find-module
8705 (get-text-property (point) 'find-args))))
8706 (define-key keymap [(return)]
8707 (lambda ()
8708 (interactive)
8709 (apply 'idlwave-do-find-module
8710 (get-text-property (point) 'find-args))))
8711 (message "Compiling list...( 0%%)")
8712 (with-current-buffer (get-buffer-create "*Shadows*")
8713 (setq buffer-read-only nil)
8714 (erase-buffer)
8715 (while (setq routine (pop routines))
8716 (if (= (mod (setq n (1+ n)) step) 0)
8717 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8719 ;; Get a list of all twins
8720 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8721 (if (memq routine done)
8722 (setq dtwins nil)
8723 (setq dtwins (idlwave-study-twins twins)))
8724 ;; Mark all twins as dealt with
8725 (setq done (append twins done))
8726 (when (or (> (length dtwins) 1)
8727 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8728 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8729 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8730 (incf cnt)
8731 (insert (format "\n%s%s"
8732 (idlwave-make-full-name (nth 2 routine)
8733 (car routine))
8734 (if (eq (nth 1 routine) 'fun) "()" "")))
8735 (while (setq twin (pop dtwins))
8736 (setq props1 (append (list 'find-args
8737 (list (nth 0 routine)
8738 (nth 1 routine)
8739 (nth 2 routine)))
8740 props))
8741 (idlwave-insert-source-location "\n - " twin props1))))
8742 (goto-char (point-min))
8743 (setq buffer-read-only t))
8744 (setq loc (or loc ""))
8745 (if (> cnt 0)
8746 (progn
8747 (display-buffer (get-buffer "*Shadows*"))
8748 (message "%d case%s of shadowing found %s"
8749 cnt (if (= cnt 1) "" "s") loc))
8750 (message "No shadowing conflicts found %s" loc))))
8752 (defun idlwave-print-source (routine)
8753 (let* ((source (nth 3 routine))
8754 (stype (car source))
8755 (sfile (idlwave-routine-source-file source)))
8756 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8757 (if (and (eq stype 'compiled)
8758 (or (not (stringp sfile))
8759 (not (string-match "\\S-" sfile))))
8760 (setq stype 'unresolved))
8761 (princ (format " %-10s %s\n"
8762 stype
8763 (if sfile sfile "No source code available")))))
8765 (defun idlwave-routine-twins (entry &optional list)
8766 "Return all twin entries of ENTRY in LIST.
8767 LIST defaults to `idlwave-routines'.
8768 Twin entries are those which have the same name, type, and class.
8769 ENTRY will also be returned, as the first item of this list."
8770 (let* ((name (car entry))
8771 (type (nth 1 entry))
8772 (class (nth 2 entry))
8773 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8774 twins candidate)
8775 (while (setq candidate (pop candidates))
8776 (if (and (not (eq candidate entry))
8777 (eq type (nth 1 candidate))
8778 (eq class (nth 2 candidate)))
8779 (push candidate twins)))
8780 (if (setq candidate (idlwave-rinfo-assq name type class
8781 idlwave-unresolved-routines))
8782 (push candidate twins))
8783 (cons entry (nreverse twins))))
8785 (defun idlwave-study-twins (entries)
8786 "Return dangerous twins of first entry in ENTRIES.
8787 Dangerous twins are routines with same name, but in different files on
8788 the load path. If a file is in the system library and has an entry in
8789 the `idlwave-system-routines' list, we omit the latter as
8790 non-dangerous because many IDL routines are implemented as library
8791 routines, and may have been scanned."
8792 (let* ((entry (car entries))
8793 (idlwave-twin-name (car entry)) ;
8794 (type (nth 1 entry)) ; Must be bound for
8795 (idlwave-twin-class (nth 2 entry)) ; idlwave-routine-twin-compare
8796 (cnt 0)
8797 source type type-cons file alist syslibp key)
8798 (while (setq entry (pop entries))
8799 (incf cnt)
8800 (setq source (nth 3 entry)
8801 type (car source)
8802 type-cons (cons type (nth 3 source))
8803 file (idlwave-routine-source-file source))
8805 ;; Make KEY to index entry properly
8806 (setq key (cond ((eq type 'system) type)
8807 (file (file-truename file))
8808 (t 'unresolved)))
8810 ;; Check for an entry in the system library
8811 (if (and file
8812 (not syslibp)
8813 (idlwave-syslib-p file))
8814 (setq syslibp t))
8816 ;; If there's more than one matching entry for the same file, just
8817 ;; append the type-cons to the type list.
8818 (if (setq entry (assoc key alist))
8819 (push type-cons (nth 2 entry))
8820 (push (list key file (list type-cons)) alist)))
8822 (setq alist (nreverse alist))
8824 (when syslibp
8825 ;; File is in system *library* - remove any 'system entry
8826 (setq alist (delq (assq 'system alist) alist)))
8828 ;; If 'system remains and we've scanned the syslib, it's a builtin
8829 ;; (rather than a !DIR/lib/.pro file bundled as source).
8830 (when (and (idlwave-syslib-scanned-p)
8831 (setq entry (assoc 'system alist)))
8832 (setcar entry 'builtin))
8833 (sort alist 'idlwave-routine-twin-compare)))
8835 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8836 ;; (defvar type)
8837 (defmacro idlwave-xor (a b)
8838 `(and (or ,a ,b)
8839 (not (and ,a ,b))))
8841 (defun idlwave-routine-entry-compare (a b)
8842 "Compare two routine info entries for sorting.
8843 This is the general case. It first compares class, names, and type.
8844 If it turns out that A and B are twins (same name, class, and type),
8845 calls another routine which compares twins on the basis of their file
8846 names and path locations."
8847 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8848 (cond
8849 ((not (equal (idlwave-downcase-safe class)
8850 (idlwave-downcase-safe (nth 2 b))))
8851 ;; Class decides
8852 (cond ((null (nth 2 b)) nil)
8853 ((null class) t)
8854 (t (string< (downcase class) (downcase (nth 2 b))))))
8855 ((not (equal (downcase name) (downcase (car b))))
8856 ;; Name decides
8857 (string< (downcase name) (downcase (car b))))
8858 ((not (eq type (nth 1 b)))
8859 ;; Type decides
8860 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8862 ;; A and B are twins - so the decision is more complicated.
8863 ;; Call twin-compare with the proper arguments.
8864 (idlwave-routine-entry-compare-twins a b)))))
8866 (defun idlwave-routine-entry-compare-twins (a b)
8867 "Compare two routine entries, under the assumption that they are twins.
8868 This basically calls `idlwave-routine-twin-compare' with the correct args."
8869 (let* ((idlwave-twin-name (car a))
8870 (type (nth 1 a))
8871 (idlwave-twin-class (nth 2 a)) ; used in idlwave-routine-twin-compare
8872 (asrc (nth 3 a))
8873 (atype (car asrc))
8874 (bsrc (nth 3 b))
8875 (btype (car bsrc))
8876 (afile (idlwave-routine-source-file asrc))
8877 (bfile (idlwave-routine-source-file bsrc)))
8878 (idlwave-routine-twin-compare
8879 (if (stringp afile)
8880 (list (file-truename afile) afile (list atype))
8881 (list atype afile (list atype)))
8882 (if (stringp bfile)
8883 (list (file-truename bfile) bfile (list btype))
8884 (list btype bfile (list btype))))))
8886 ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
8887 (defvar idlwave-twin-class)
8888 (defvar idlwave-twin-name)
8890 (defun idlwave-routine-twin-compare (a b)
8891 "Compare two routine twin entries for sorting.
8892 In here, A and B are not normal routine info entries, but special
8893 lists (KEY FILENAME (TYPES...)).
8894 This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
8895 (let* (;; Dis-assemble entries
8896 (akey (car a)) (bkey (car b))
8897 (afile (nth 1 a)) (bfile (nth 1 b))
8898 (atypes (nth 2 a)) (btypes (nth 2 b))
8899 ;; System routines?
8900 (asysp (memq akey '(builtin system)))
8901 (bsysp (memq bkey '(builtin system)))
8902 ;; Compiled routines?
8903 (acompp (memq 'compiled atypes))
8904 (bcompp (memq 'compiled btypes))
8905 ;; Unresolved?
8906 (aunresp (or (eq akey 'unresolved)
8907 (and acompp (not afile))))
8908 (bunresp (or (eq bkey 'unresolved)
8909 (and bcompp (not bfile))))
8910 ;; Buffer info available?
8911 (abufp (memq 'buffer atypes))
8912 (bbufp (memq 'buffer btypes))
8913 ;; On search path?
8914 (tpath-alist (idlwave-true-path-alist))
8915 (apathp (and (stringp akey)
8916 (assoc (file-name-directory akey) tpath-alist)))
8917 (bpathp (and (stringp bkey)
8918 (assoc (file-name-directory bkey) tpath-alist)))
8919 ;; How early on search path? High number means early since we
8920 ;; measure the tail of the path list
8921 (anpath (length (memq apathp tpath-alist)))
8922 (bnpath (length (memq bpathp tpath-alist)))
8923 ;; Look at file names
8924 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8925 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8926 (fname-re (if idlwave-twin-class
8927 (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8928 (regexp-quote (downcase idlwave-twin-class))
8929 (regexp-quote (downcase idlwave-twin-name)))
8930 (format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
8931 ;; Is file name derived from the routine name?
8932 ;; Method file or class definition file?
8933 (anamep (string-match fname-re aname))
8934 (adefp (and idlwave-twin-class anamep
8935 (string= "define" (match-string 1 aname))))
8936 (bnamep (string-match fname-re bname))
8937 (bdefp (and idlwave-twin-class bnamep
8938 (string= "define" (match-string 1 bname)))))
8940 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8941 ;; doesn't it? The difficult stuff is hidden above...
8942 (cond
8943 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8944 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8945 ((and idlwave-sort-prefer-buffer-info
8946 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8947 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8948 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8949 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8950 ((and idlwave-twin-class anamep bnamep ; both file names match ->
8951 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8952 ((> anpath bnpath) t) ; Who is first on path?
8953 (t nil)))) ; Default
8955 (defun idlwave-routine-source-file (source)
8956 (if (nth 2 source)
8957 (expand-file-name (nth 1 source) (nth 2 source))
8958 (nth 1 source)))
8960 (defun idlwave-downcase-safe (string)
8961 "Donwcase if string, else return unchanged."
8962 (if (stringp string)
8963 (downcase string)
8964 string))
8966 (defun idlwave-count-eq (elt list)
8967 "How often is ELT in LIST?"
8968 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8970 (defun idlwave-count-memq (elt alist)
8971 "How often is ELT a key in ALIST?"
8972 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8974 (defun idlwave-syslib-p (file)
8975 "Non-nil if FILE is in the system library."
8976 (let* ((true-syslib (file-name-as-directory
8977 (file-truename
8978 (expand-file-name "lib" (idlwave-sys-dir)))))
8979 (true-file (file-truename file)))
8980 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8982 (defun idlwave-lib-p (file)
8983 "Non-nil if FILE is in the library."
8984 (let ((true-dir (file-name-directory (file-truename file))))
8985 (assoc true-dir (idlwave-true-path-alist))))
8987 (defun idlwave-path-alist-add-flag (list-entry flag)
8988 "Add a flag to the path list entry, if not set."
8989 (let ((flags (cdr list-entry)))
8990 (add-to-list 'flags flag)
8991 (setcdr list-entry flags)))
8993 (defun idlwave-path-alist-remove-flag (list-entry flag)
8994 "Remove a flag to the path list entry, if set."
8995 (let ((flags (delq flag (cdr list-entry))))
8996 (setcdr list-entry flags)))
8998 (defun idlwave-true-path-alist ()
8999 "Return `idlwave-path-alist' alist with true-names.
9000 Info is cached, but relies on the functions setting `idlwave-path-alist'
9001 to reset the variable `idlwave-true-path-alist' to nil."
9002 (or idlwave-true-path-alist
9003 (setq idlwave-true-path-alist
9004 (mapcar (lambda(x) (cons
9005 (file-name-as-directory
9006 (file-truename
9007 (directory-file-name
9008 (car x))))
9009 (cdr x)))
9010 idlwave-path-alist))))
9012 (defun idlwave-syslib-scanned-p ()
9013 "Non-nil if the system lib file !DIR/lib has been scanned."
9014 (let* ((true-syslib (file-name-as-directory
9015 (file-truename
9016 (expand-file-name "lib" (idlwave-sys-dir))))))
9017 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9019 ;; ----------------------------------------------------------------------------
9021 ;; Online Help display
9024 ;; ----------------------------------------------------------------------------
9026 ;; Additions for use with imenu.el and func-menu.el
9027 ;; (pop-up a list of IDL units in the current file).
9030 (defun idlwave-prev-index-position ()
9031 "Search for the previous procedure or function.
9032 Return nil if not found. For use with imenu.el."
9033 (save-match-data
9034 (cond
9035 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9036 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9037 (t nil))))
9039 (defun idlwave-unit-name ()
9040 "Return the unit name.
9041 Assumes that point is at the beginning of the unit as found by
9042 `idlwave-prev-index-position'."
9043 (forward-sexp 2)
9044 (forward-sexp -1)
9045 (let ((begin (point)))
9046 (re-search-forward
9047 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9048 (if (fboundp 'buffer-substring-no-properties)
9049 (buffer-substring-no-properties begin (point))
9050 (buffer-substring begin (point)))))
9052 (defalias 'idlwave-function-menu
9053 (condition-case nil
9054 (progn
9055 (require 'func-menu)
9056 'function-menu)
9057 (error (condition-case nil
9058 (progn
9059 (require 'imenu)
9060 'imenu)
9061 (error nil)))))
9063 ;; Here we hack func-menu.el in order to support this new mode.
9064 ;; The latest versions of func-menu.el already have this stuff in, so
9065 ;; we hack only if it is not already there.
9066 (when (fboundp 'eval-after-load)
9067 (eval-after-load "func-menu"
9068 '(progn
9069 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9070 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9071 (setq fume-function-name-regexp-alist
9072 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9073 fume-function-name-regexp-alist)))
9074 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9075 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9076 (setq fume-find-function-name-method-alist
9077 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9078 fume-find-function-name-method-alist))))))
9080 (defun idlwave-edit-in-idlde ()
9081 "Edit the current file in IDL Development environment."
9082 (interactive)
9083 (start-process "idldeclient" nil
9084 idlwave-shell-explicit-file-name "-c" "-e"
9085 (buffer-file-name)))
9087 (defvar idlwave-help-use-assistant)
9088 (defun idlwave-launch-idlhelp ()
9089 "Start the IDLhelp application."
9090 (interactive)
9091 (if idlwave-help-use-assistant
9092 (idlwave-help-assistant-raise)
9093 (start-process "idlhelp" nil idlwave-help-application)))
9095 ;; Menus - using easymenu.el
9096 (defvar idlwave-mode-menu-def
9097 `("IDLWAVE"
9098 ["PRO/FUNC menu" idlwave-function-menu t]
9099 ("Motion"
9100 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9101 ["Subprogram End" idlwave-end-of-subprogram t]
9102 ["Block Start" idlwave-beginning-of-block t]
9103 ["Block End" idlwave-end-of-block t]
9104 ["Up Block" idlwave-backward-up-block t]
9105 ["Down Block" idlwave-down-block t]
9106 ["Skip Block Backward" idlwave-backward-block t]
9107 ["Skip Block Forward" idlwave-forward-block t])
9108 ("Mark"
9109 ["Subprogram" idlwave-mark-subprogram t]
9110 ["Block" idlwave-mark-block t]
9111 ["Header" idlwave-mark-doclib t])
9112 ("Format"
9113 ["Indent Entire Statement" idlwave-indent-statement
9114 :active t :keys "C-u \\[indent-for-tab-command]" ]
9115 ["Indent Subprogram" idlwave-indent-subprogram t]
9116 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9117 ["Continue/Split line" idlwave-split-line t]
9118 "--"
9119 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9120 :selected (symbol-value idlwave-fill-function)])
9121 ("Templates"
9122 ["Procedure" idlwave-procedure t]
9123 ["Function" idlwave-function t]
9124 ["Doc Header" idlwave-doc-header t]
9125 ["Log" idlwave-doc-modification t]
9126 "--"
9127 ["Case" idlwave-case t]
9128 ["For" idlwave-for t]
9129 ["Repeat" idlwave-repeat t]
9130 ["While" idlwave-while t]
9131 "--"
9132 ["Close Block" idlwave-close-block t])
9133 ("Completion"
9134 ["Complete" idlwave-complete t]
9135 ("Complete Specific"
9136 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9137 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9138 "--"
9139 ["3 Function Name" (idlwave-complete 'function) t]
9140 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9141 "--"
9142 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9143 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9144 "--"
9145 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9146 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9147 "--"
9148 ["9 Class Name" idlwave-complete-class t]))
9149 ("Routine Info"
9150 ["Show Routine Info" idlwave-routine-info t]
9151 ["Online Context Help" idlwave-context-help t]
9152 "--"
9153 ["Find Routine Source" idlwave-find-module t]
9154 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9155 "--"
9156 ["Update Routine Info" idlwave-update-routine-info t]
9157 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9158 "--"
9159 "IDL User Catalog"
9160 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9161 ["Scan Directories" (idlwave-update-routine-info '(16))
9162 (and idlwave-path-alist (not idlwave-catalog-process))]
9163 ["Scan Directories &" (idlwave-update-routine-info '(64))
9164 (and idlwave-path-alist (not idlwave-catalog-process))]
9165 "--"
9166 "Routine Shadows"
9167 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9168 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9169 ["Check Everything" idlwave-list-all-load-path-shadows t])
9170 ("Misc"
9171 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9172 "--"
9173 ["Insert TAB character" idlwave-hard-tab t])
9174 "--"
9175 ("External"
9176 ["Start IDL shell" idlwave-shell t]
9177 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9178 ["Launch IDL Help" idlwave-launch-idlhelp t])
9179 "--"
9180 ("Customize"
9181 ["Browse IDLWAVE Group" idlwave-customize t]
9182 "--"
9183 ["Build Full Customize Menu" idlwave-create-customize-menu
9184 (fboundp 'customize-menu-create)])
9185 ("Documentation"
9186 ["Describe Mode" describe-mode t]
9187 ["Abbreviation List" idlwave-list-abbrevs t]
9188 "--"
9189 ["Commentary in idlwave.el" idlwave-show-commentary t]
9190 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9191 "--"
9192 ["Info" idlwave-info t]
9193 "--"
9194 ["Help with Topic" idlwave-help-assistant-help-with-topic
9195 idlwave-help-use-assistant]
9196 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9198 (defvar idlwave-mode-debug-menu-def
9199 '("Debug"
9200 ["Start IDL shell" idlwave-shell t]
9201 ["Save and .RUN buffer" idlwave-shell-save-and-run
9202 (and (boundp 'idlwave-shell-automatic-start)
9203 idlwave-shell-automatic-start)]))
9205 (if (or (featurep 'easymenu) (load "easymenu" t))
9206 (progn
9207 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9208 "IDL and WAVE CL editing menu"
9209 idlwave-mode-menu-def)
9210 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9211 "IDL and WAVE CL editing menu"
9212 idlwave-mode-debug-menu-def)))
9214 (defun idlwave-customize ()
9215 "Call the customize function with `idlwave' as argument."
9216 (interactive)
9217 ;; Try to load the code for the shell, so that we can customize it
9218 ;; as well.
9219 (or (featurep 'idlw-shell)
9220 (load "idlw-shell" t))
9221 (customize-browse 'idlwave))
9223 (defun idlwave-create-customize-menu ()
9224 "Create a full customization menu for IDLWAVE, insert it into the menu."
9225 (interactive)
9226 (if (fboundp 'customize-menu-create)
9227 (progn
9228 ;; Try to load the code for the shell, so that we can customize it
9229 ;; as well.
9230 (or (featurep 'idlw-shell)
9231 (load "idlw-shell" t))
9232 (easy-menu-change
9233 '("IDLWAVE") "Customize"
9234 `(["Browse IDLWAVE group" idlwave-customize t]
9235 "--"
9236 ,(customize-menu-create 'idlwave)
9237 ["Set" Custom-set t]
9238 ["Save" Custom-save t]
9239 ["Reset to Current" Custom-reset-current t]
9240 ["Reset to Saved" Custom-reset-saved t]
9241 ["Reset to Standard Settings" Custom-reset-standard t]))
9242 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9243 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9245 (defun idlwave-show-commentary ()
9246 "Use the finder to view the file documentation from `idlwave.el'."
9247 (interactive)
9248 (finder-commentary "idlwave.el"))
9250 (defun idlwave-shell-show-commentary ()
9251 "Use the finder to view the file documentation from `idlw-shell.el'."
9252 (interactive)
9253 (finder-commentary "idlw-shell.el"))
9255 (defun idlwave-info ()
9256 "Read documentation for IDLWAVE in the info system."
9257 (interactive)
9258 (info "idlwave"))
9260 (defun idlwave-list-abbrevs (arg)
9261 "Show the code abbreviations define in IDLWAVE mode.
9262 This lists all abbrevs where the replacement text differs from the input text.
9263 These are the ones the users want to learn to speed up their writing.
9265 The function does *not* list abbrevs which replace a word with itself
9266 to call a hook. These hooks are used to change the case of words or
9267 to blink the matching `begin', and the user does not need to know them.
9269 With arg, list all abbrevs with the corresponding hook.
9271 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9273 (interactive "P")
9274 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9275 abbrevs
9276 str rpl func fmt (len-str 0) (len-rpl 0))
9277 (mapatoms
9278 (lambda (sym)
9279 (if (symbol-value sym)
9280 (progn
9281 (setq str (symbol-name sym)
9282 rpl (symbol-value sym)
9283 func (symbol-function sym))
9284 (if arg
9285 (setq func (prin1-to-string func))
9286 (if (and (listp func) (stringp (nth 2 func)))
9287 (setq rpl (concat "EVAL: " (nth 2 func))
9288 func "")
9289 (setq func "")))
9290 (if (or arg (not (string= rpl str)))
9291 (progn
9292 (setq len-str (max len-str (length str)))
9293 (setq len-rpl (max len-rpl (length rpl)))
9294 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9295 table)
9296 ;; sort the list
9297 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9298 ;; Make the format
9299 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9300 (with-output-to-temp-buffer "*Help*"
9301 (if arg
9302 (progn
9303 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9304 (princ "=========================================\n\n")
9305 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9306 (princ (format fmt "---" "-------" "----")))
9307 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9308 (princ "================================================\n\n")
9309 (princ (format fmt "KEY" "ACTION" ""))
9310 (princ (format fmt "---" "------" "")))
9311 (mapcar
9312 (lambda (list)
9313 (setq str (car list)
9314 rpl (nth 1 list)
9315 func (nth 2 list))
9316 (princ (format fmt str rpl func)))
9317 abbrevs)))
9318 ;; Make sure each abbreviation uses only one display line
9319 (with-current-buffer "*Help*"
9320 (setq truncate-lines t)))
9322 ;; Add .pro files to speedbar for support, if it's loaded
9323 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9325 ;; Set an idle timer to load the routine info.
9326 ;; Will only work on systems which support this.
9327 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9329 ;; Run the hook
9330 (run-hooks 'idlwave-load-hook)
9332 (provide 'idlwave)
9334 ;;; idlwave.el ends here