Unify CNS11643-15
[emacs.git] / lisp / progmodes / idlwave.el
blobf070000c867387de9e08e1af35eecefd5b1c117d
1 ;; idlwave.el --- IDL editing mode for GNU Emacs
3 ;; Copyright (C) 1999-2017 Free Software Foundation, Inc.
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
9 ;; Version: 6.1.22
10 ;; Keywords: languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; IDLWAVE enables feature-rich development and interaction with IDL,
30 ;; the Interactive Data Language. It provides a compelling,
31 ;; full-featured alternative to the IDLDE development environment
32 ;; bundled with IDL.
34 ;; In the remotely distant past, based on pascal.el, though bears
35 ;; little resemblance to it now.
37 ;; Incorporates many ideas, such as abbrevs, action routines, and
38 ;; continuation line indenting, from wave.el.
39 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
41 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
42 ;; for features, key bindings, and info.
43 ;; Also, Info format documentation is available with `M-x idlwave-info'
45 ;; New versions of IDLWAVE, documentation, and more information
46 ;; available from:
47 ;; http://github.com/jdtsmith/idlwave
49 ;; INSTALLATION
50 ;; ============
52 ;; Follow the instructions in the INSTALL file of the distribution.
53 ;; In short, put this file on your load path and add the following
54 ;; lines to your init file:
56 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
57 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
58 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
61 ;; SOURCE
62 ;; ======
64 ;; The newest version of this file is available from the maintainer's
65 ;; Webpage:
67 ;; http://github.com/jdtsmith/idlwave
69 ;; DOCUMENTATION
70 ;; =============
72 ;; IDLWAVE is documented online in info format. A printable version
73 ;; of the documentation is available from the maintainers webpage (see
74 ;; SOURCE).
77 ;; ACKNOWLEDGMENTS
78 ;; ===============
80 ;; Thanks to the following people for their contributions and comments:
82 ;; Ulrik Dickow <dickow_at_nbi.dk>
83 ;; Eric E. Dors <edors_at_lanl.gov>
84 ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
85 ;; David Huenemoerder <dph_at_space.mit.edu>
86 ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
87 ;; Dick Jackson <dick_at_d-jackson.com>
88 ;; Xuyong Liu <liu_at_stsci.edu>
89 ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
90 ;; Laurent Mugnier <mugnier_at_onera.fr>
91 ;; Lubos Pochman <lubos_at_rsinc.com>
92 ;; Bob Portmann <portmann_at_al.noaa.gov>
93 ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
94 ;; Marty Ryba <ryba_at_ll.mit.edu>
95 ;; Paul Sorenson <aardvark62_at_msn.com>
96 ;; Phil Sterne <sterne_at_dublin.llnl.gov>
97 ;; Phil Williams <williams_at_irc.chmcc.org>
99 ;; CUSTOMIZATION:
100 ;; =============
102 ;; IDLWAVE has extensive customize support; to learn about the
103 ;; variables which control the mode's behavior, use `M-x
104 ;; idlwave-customize'.
106 ;; You can set your own preferred values with Customize, or with Lisp
107 ;; code in .emacs. For an example of what to put into .emacs, check
108 ;; the TexInfo documentation or see a complete .emacs available at the
109 ;; website.
111 ;; KNOWN PROBLEMS:
112 ;; ==============
114 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
115 ;; Numerics, Inc. is growing less and less complete as the two
116 ;; languages grow increasingly apart. The mode probably shouldn't
117 ;; even have "WAVE" in its title, but it's catchy, and was required
118 ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
120 ;; Moving the point backwards in conjunction with abbrev expansion
121 ;; does not work as I would like it, but this is a problem with
122 ;; emacs abbrev expansion done by the self-insert-command. It ends
123 ;; up inserting the character that expanded the abbrev after moving
124 ;; point backward, e.g., "\cl" expanded with a space becomes
125 ;; "LONG( )" with point before the close paren. This is solved by
126 ;; using a temporary function in `post-command-hook' - not pretty,
127 ;; but it works.
129 ;; Tabs and spaces are treated equally as whitespace when filling a
130 ;; comment paragraph. To accomplish this, tabs are permanently
131 ;; replaced by spaces in the text surrounding the paragraph, which
132 ;; may be an undesirable side-effect. Replacing tabs with spaces is
133 ;; limited to comments only and occurs only when a comment
134 ;; paragraph is filled via `idlwave-fill-paragraph'.
136 ;; Muti-statement lines (using "&") on block begin and end lines can
137 ;; ruin the formatting. For example, multiple end statements on a
138 ;; line: endif & endif. Using "&" outside of block begin/end lines
139 ;; should be okay.
141 ;; Determining the expression at point for printing and other
142 ;; examination commands is somewhat rough: currently only fairly
143 ;; simple entities are found. You can always drag-select or examine
144 ;; a pre-selected region.
146 ;; When forcing completion of method keywords, the initial
147 ;; query for a method has multiple entries for some methods. Would
148 ;; be too difficult to fix this hardly used case.
151 ;;; Code:
154 (eval-when-compile (require 'cl))
155 (require 'idlw-help)
157 ;; For XEmacs
158 (unless (fboundp 'line-beginning-position)
159 (defalias 'line-beginning-position 'point-at-bol))
160 (unless (fboundp 'line-end-position)
161 (defalias 'line-end-position 'point-at-eol))
162 (unless (fboundp 'char-valid-p)
163 (defalias 'char-valid-p 'characterp))
164 (unless (fboundp 'match-string-no-properties)
165 (defalias 'match-string-no-properties 'match-string))
167 (if (not (fboundp 'cancel-timer))
168 (condition-case nil
169 (require 'timer)
170 (error nil)))
172 (declare-function idlwave-shell-get-path-info "idlw-shell")
173 (declare-function idlwave-shell-temp-file "idlw-shell")
174 (declare-function idlwave-shell-is-running "idlw-shell")
175 (declare-function widget-value "wid-edit" (widget))
176 (declare-function comint-dynamic-complete-filename "comint" ())
178 (defgroup idlwave nil
179 "Major mode for editing IDL .pro files."
180 :tag "IDLWAVE"
181 :link '(url-link :tag "Home Page"
182 "http://github.com/jdtsmith/idlwave")
183 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
184 "idlw-shell.el")
185 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
186 :link '(custom-manual "(idlwave)Top")
187 :prefix "idlwave"
188 :group 'languages)
191 ;;; Variables for indentation behavior ---------------------------------------
193 (defgroup idlwave-code-formatting nil
194 "Indentation and formatting options for IDLWAVE mode."
195 :group 'idlwave)
197 (defcustom idlwave-main-block-indent 2
198 "Extra indentation for the main block of code.
199 That is the block between the FUNCTION/PRO statement and the END
200 statement for that program unit."
201 :group 'idlwave-code-formatting
202 :type 'integer)
204 (defcustom idlwave-block-indent 3
205 "Extra indentation applied to block lines.
206 If you change this, you probably also want to change `idlwave-end-offset'."
207 :group 'idlwave-code-formatting
208 :type 'integer)
210 (defcustom idlwave-end-offset -3
211 "Extra indentation applied to block END lines.
212 A value equal to negative `idlwave-block-indent' will make END lines
213 line up with the block BEGIN lines."
214 :group 'idlwave-code-formatting
215 :type 'integer)
217 (defcustom idlwave-continuation-indent 3
218 "Extra indentation applied to continuation lines.
219 This extra offset applies to the first of a set of continuation lines.
220 The following lines receive the same indentation as the first."
221 :group 'idlwave-code-formatting
222 :type 'integer)
224 (defcustom idlwave-max-extra-continuation-indent 40
225 "Maximum additional indentation for special continuation indent.
226 Several special indentations are tried to help line up continuation
227 lines in routine calls or definitions, other statements with
228 parentheses, or assignment statements. This variable specifies a
229 maximum amount by which this special indentation can exceed the
230 standard continuation indentation, otherwise defaulting to a fixed
231 offset. Set to 0 to effectively disable all special continuation
232 indentation, or to a large number (like 100) to enable it in all
233 cases. See also `idlwave-indent-to-open-paren', which can override
234 this variable."
235 :group 'idlwave-code-formatting
236 :type 'integer)
238 (defcustom idlwave-indent-to-open-paren t
239 "Non-nil means, indent continuation lines to innermost open parenthesis.
240 This indentation occurs even if otherwise disallowed by
241 `idlwave-max-extra-continuation-indent'. Matching parens and the
242 interleaving args are lined up. Example:
244 x = function_a(function_b(function_c( a, b, [1,2,3, $
245 4,5,6 $
246 ], $
247 c, d $
250 When this variable is nil, paren alignment may still occur, based on
251 the value of `idlwave-max-extra-continuation-indent', which, if zero,
252 would yield:
254 x = function_a(function_b(function_c( a, b, [1,2,3, $
255 4,5,6 $
256 ], $
257 c, d $
258 )))"
259 :group 'idlwave-code-formatting
260 :type 'boolean)
262 (defcustom idlwave-indent-parens-nested nil
263 "Non-nil means, indent continuation lines with parens by nesting
264 lines at consecutively deeper levels."
265 :group 'idlwave-code-formatting
266 :type 'boolean)
269 (defcustom idlwave-hanging-indent t
270 "If set non-nil then comment paragraphs are indented under the
271 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
272 of the paragraph."
273 :group 'idlwave-code-formatting
274 :type 'boolean)
276 (defcustom idlwave-hang-indent-regexp "- "
277 "Regular expression matching the position of the hanging indent
278 in the first line of a comment paragraph. The size of the indent
279 extends to the end of the match for the regular expression."
280 :group 'idlwave-code-formatting
281 :type 'regexp)
283 (defcustom idlwave-use-last-hang-indent nil
284 "If non-nil then use last match on line for `idlwave-indent-regexp'."
285 :group 'idlwave-code-formatting
286 :type 'boolean)
288 (defcustom idlwave-fill-comment-line-only t
289 "If non-nil then auto fill will only operate on comment lines."
290 :group 'idlwave-code-formatting
291 :type 'boolean)
293 (defcustom idlwave-auto-fill-split-string t
294 "If non-nil then auto fill will split strings with the IDL `+' operator.
295 When the line end falls within a string, string concatenation with the
296 `+' operator will be used to distribute a long string over lines.
297 If nil and a string is split then a terminal beep and warning are issued.
299 This variable is ignored when `idlwave-fill-comment-line-only' is
300 non-nil, since in this case code is not auto-filled."
301 :group 'idlwave-code-formatting
302 :type 'boolean)
304 (defcustom idlwave-split-line-string t
305 "If non-nil then `idlwave-split-line' will split strings with `+'.
306 When the splitting point of a line falls inside a string, split the string
307 using the `+' string concatenation operator. If nil and a string is
308 split then a terminal beep and warning are issued."
309 :group 'idlwave-code-formatting
310 :type 'boolean)
312 (defcustom idlwave-no-change-comment ";;;"
313 "The indentation of a comment that starts with this regular
314 expression will not be changed. Note that the indentation of a comment
315 at the beginning of a line is never changed."
316 :group 'idlwave-code-formatting
317 :type 'string)
319 (defcustom idlwave-begin-line-comment nil
320 "A comment anchored at the beginning of line.
321 A comment matching this regular expression will not have its
322 indentation changed. If nil the default is \"^;\", i.e., any line
323 beginning with a \";\". Expressions for comments at the beginning of
324 the line should begin with \"^\"."
325 :group 'idlwave-code-formatting
326 :type '(choice (const :tag "Any line beginning with `;'" nil)
327 'regexp))
329 (defcustom idlwave-code-comment ";;[^;]"
330 "A comment that starts with this regular expression on a line by
331 itself is indented as if it is a part of IDL code. As a result if
332 the comment is not preceded by whitespace it is unchanged."
333 :group 'idlwave-code-formatting
334 :type 'regexp)
336 ;; Comments not matching any of the above will be indented as a
337 ;; right-margin comment, i.e., to a minimum of `comment-column'.
339 ;;; Routine Info and Completion ---------------------------------------
341 (defgroup idlwave-routine-info nil
342 "Routine Info options for IDLWAVE mode."
343 :group 'idlwave)
345 (defcustom idlwave-use-library-catalogs t
346 "Non-nil means search the IDL path for library catalog files.
348 These files, named .idlwave_catalog, document routine information for
349 individual directories and libraries of IDL .pro files. Many popular
350 libraries come with catalog files by default, so leaving this on is
351 usually a good idea."
352 :group 'idlwave-routine-info
353 :type 'boolean)
355 (defcustom idlwave-init-rinfo-when-idle-after 10
356 "Seconds of idle time before routine info is automatically initialized.
357 Initializing the routine info can take a long time, in particular if a
358 large number of library catalogs are involved. When Emacs is idle for
359 more than the number of seconds specified by this variable, it starts
360 the initialization. The process is split into five steps, in order to
361 keep work interruption as short as possible. If one of the steps
362 finishes, and no user input has arrived in the mean time, initialization
363 proceeds immediately to the next step. A good value for this variable
364 is about 1/3 of the time initialization take in your setup. So if you
365 have a fast machine and no problems with a slow network connection,
366 don't hesitate to set this to 2 seconds. A value of 0 means, don't
367 initialize automatically, but instead wait until routine information is
368 needed, and initialize then."
369 :group 'idlwave-routine-info
370 :type 'number)
372 (defcustom idlwave-scan-all-buffers-for-routine-info t
373 "Non-nil means, scan buffers for IDL programs when updating info.
374 The scanning is done by the command `idlwave-update-routine-info'.
375 The following values are allowed:
377 nil Don't scan any buffers.
378 t Scan all `idlwave-mode' buffers in the current editing session.
379 `current' Scan only the current buffer, but no other buffers."
380 :group 'idlwave-routine-info
381 :type '(choice
382 (const :tag "No buffer" nil)
383 (const :tag "All buffers" t)
384 (const :tag "Current buffer only" current)))
386 (defcustom idlwave-query-shell-for-routine-info t
387 "Non-nil means query the shell for info about compiled routines.
388 Querying the shell is useful to get information about compiled modules,
389 and it is turned on by default. However, when you have a complete library
390 scan, this is not necessary."
391 :group 'idlwave-routine-info
392 :type 'boolean)
394 (defcustom idlwave-auto-routine-info-updates
395 '(find-file save-buffer kill-buffer compile-buffer)
396 "Controls under what circumstances routine info is updated automatically.
397 Possible values:
398 nil Never
399 t All available
400 \(...) A list of circumstances. Allowed members are:
401 find-file Add info for new IDLWAVE buffers.
402 save-buffer Update buffer info when buffer is saved
403 kill-buffer Remove buffer info when buffer gets killed
404 compile-buffer Update shell info after `idlwave-shell-save-and...'"
405 :group 'idlwave-routine-info
406 :type '(choice
407 (const :tag "Never" nil)
408 (const :tag "As often as possible" t)
409 (set :tag "Checklist" :greedy t
410 (const :tag "When visiting a file" find-file)
411 (const :tag "When saving a buffer" save-buffer)
412 (const :tag "After a buffer was killed" kill-buffer)
413 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
415 (defcustom idlwave-rinfo-max-source-lines 5
416 "Maximum number of source files displayed in the Routine Info window.
417 When an integer, it is the maximum number of source files displayed.
418 A value of t means to show all source files."
419 :group 'idlwave-routine-info
420 :type 'integer)
422 (defcustom idlwave-library-path nil
423 "Library path for Windows and Mac OS (OS9). Not needed under UNIX.
424 When selecting the directories to scan for IDL user catalog routine
425 info, IDLWAVE can, under UNIX, query the shell for the exact search
426 path (the value of !PATH). However, under MS-Windows, the
427 IDLWAVE shell does not work. In this case, this variable can be
428 set to specify the paths where IDLWAVE can find PRO files. The
429 shell will only be asked for a list of paths when this variable
430 is nil. The value is a list of directories. A directory
431 preceded by a `+' will be searched recursively. If you set this
432 variable on a UNIX system, the shell will not be queried. See
433 also `idlwave-system-directory'."
434 :group 'idlwave-routine-info
435 :type '(repeat (directory)))
437 (defcustom idlwave-system-directory ""
438 "The IDL system directory for Windows and Mac OS. Not needed under
439 UNIX. Set this to the value of the `!DIR' system variable in IDL.
440 IDLWAVE uses this to find out which of the library routines belong to
441 the official system library. All files inside the `lib' subdirectory
442 are considered system library files - so don't install private stuff
443 in this directory. On UNIX systems, IDLWAVE queries the shell for the
444 value of `!DIR'. See also `idlwave-library-path'."
445 :group 'idlwave-routine-info
446 :type 'directory)
448 ;; Configuration files
449 (defcustom idlwave-config-directory
450 (locate-user-emacs-file "idlwave" ".idlwave")
451 "Directory for configuration files and user-library catalog."
452 :version "24.4" ; added locate-user-emacs-file
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 (defcustom idlwave-special-lib-alist nil
461 "Alist of regular expressions matching special library directories.
462 When listing routine source locations, IDLWAVE gives a short hint where
463 the file defining the routine is located. By default it lists `SystemLib'
464 for routines in the system library `!DIR/lib' and `Library' for anything
465 else. This variable can define additional types. The car of each entry
466 is a regular expression matching the file name (they normally will match
467 on the path). The cdr is the string to be used as identifier. Max 10
468 chars are allowed."
469 :group 'idlwave-routine-info
470 :type '(repeat
471 (cons regexp string)))
473 (defcustom idlwave-auto-write-paths t
474 "Write out path (!PATH) and system directory (!DIR) info automatically.
475 Path info is needed to locate library catalog files. If non-nil,
476 whenever the path-list changes as a result of shell-query, etc., it is
477 written to file. Otherwise, the menu option \"Write Paths\" can be
478 used to force a write."
479 :group 'idlwave-routine-info
480 :type 'boolean)
482 (defgroup idlwave-completion nil
483 "Completion options for IDLWAVE mode."
484 :prefix "idlwave"
485 :group 'idlwave)
487 (eval-and-compile
488 (defconst idlwave-tmp
489 '(choice :tag "by applying the function"
490 (const upcase)
491 (const downcase)
492 (const capitalize)
493 (const preserve)
494 (symbol :tag "Other"))))
496 (defcustom idlwave-completion-case '((routine . upcase)
497 (keyword . upcase)
498 (class . preserve)
499 (method . preserve))
500 "Association list setting the case of completed words.
502 This variable determines the case (UPPER/lower/Capitalized...) of
503 words inserted into the buffer by completion. The preferred case can
504 be specified separately for routine names, keywords, classes and
505 methods.
506 This alist should therefore have entries for `routine' (normal
507 functions and procedures, i.e. non-methods), `keyword', `class', and
508 `method'. Plausible values are
510 upcase upcase whole word, like `BOX_CURSOR'
511 downcase downcase whole word, like `read_ppm'
512 capitalize capitalize each part, like `Widget_Control'
513 preserve preserve case as is, like `IDLgrView'
515 The value can also be any Emacs Lisp function which transforms the
516 case of characters in a string.
518 A value of `preserve' means that the case of the completed word is
519 identical to the way it was written in the definition statement of the
520 routine. This was implemented to allow for mixed-case completion, in
521 particular of object classes and methods.
522 If a completable word is defined in multiple locations, the meaning of
523 `preserve' is not unique since the different definitions might be
524 cased differently. Therefore IDLWAVE always takes the case of the
525 *first* definition it encounters during routine info collection and
526 uses the case derived from it consistently.
528 Note that a lowercase-only string in the buffer will always be completed in
529 lower case (but see the variable `idlwave-completion-force-default-case').
531 After changing this variable, you need to either restart Emacs or press
532 `C-u C-c C-i' to update the internal lists."
533 :group 'idlwave-completion
534 :type `(repeat
535 (cons (symbol :tag "Derive completion case for")
536 ,idlwave-tmp)))
538 (defcustom idlwave-completion-force-default-case nil
539 "Non-nil means, completion will always honor `idlwave-completion-case'.
540 When nil, only the completion of a mixed case or upper case string
541 will honor the default settings in `idlwave-completion-case', while
542 the completion of lower case strings will be completed entirely in
543 lower case."
544 :group 'idlwave-completion
545 :type 'boolean)
547 (defcustom idlwave-complete-empty-string-as-lower-case nil
548 "Non-nil means, the empty string is considered downcase for completion.
549 The case of what is already in the buffer determines the case of completions.
550 When this variable is non-nil, the empty string is considered to be downcase.
551 Completing on the empty string then offers downcase versions of the possible
552 completions."
553 :group 'idlwave-completion
554 :type 'boolean)
556 (defcustom idlwave-buffer-case-takes-precedence nil
557 "Non-nil means, the case of tokens in buffers dominates over system stuff.
558 To make this possible, we need to re-case everything each time we update
559 the routine info from the buffers. This is slow.
560 The default is to consider the case given in the system and library files
561 first which makes updating much faster."
562 :group 'idlwave-completion
563 :type 'boolean)
565 (defcustom idlwave-highlight-help-links-in-completion t
566 "Non-nil means, highlight completions for which system help is available.
567 Help can then be accessed with mouse-3.
568 This option is only effective when the online help system is installed."
569 :group 'idlwave-completion
570 :type 'boolean)
572 (defcustom idlwave-support-inheritance t
573 "Non-nil means, treat inheritance with completion, online help etc.
574 When nil, IDLWAVE only knows about the native methods and tags of a class,
575 not about inherited ones."
576 :group 'idlwave-routine-info
577 :type 'boolean)
579 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
580 "List of regular expressions for class-driven keyword inheritance.
581 Keyword inheritance is often tied to class inheritance by \"chaining\"
582 up the class tree. While it cannot be assumed that the presence of an
583 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
584 certain methods this assumption is almost always true. The methods
585 for which to assume this can be set here."
586 :group 'idlwave-routine-info
587 :type '(repeat (regexp :tag "Match method:")))
590 (defcustom idlwave-completion-show-classes 1
591 "Number of classes to show when completing object methods and keywords.
592 When completing methods or keywords for an object with unknown class,
593 the *Completions* buffer will show the valid classes for each completion
594 like this:
596 MyMethod <Class1,Class2,Class3>
598 The value of this variable may be nil to inhibit display, or an integer to
599 indicate the maximum number of classes to display.
601 On XEmacs, a full list of classes will also be placed into a `help-echo'
602 property on the completion items, so that the list of classes for the current
603 item is displayed in the echo area. If the value of this variable is a
604 negative integer, the `help-echo' property will be suppressed."
605 :group 'idlwave-completion
606 :type '(choice (const :tag "Don't show" nil)
607 (integer :tag "Number of classes shown" 1)))
609 (defcustom idlwave-completion-fontify-classes t
610 "Non-nil means, fontify the classes in completions buffer.
611 This makes it easier to distinguish the completion items from the extra
612 class info listed. See `idlwave-completion-show-classes'."
613 :group 'idlwave-completion
614 :type 'boolean)
616 (defcustom idlwave-query-class '((method-default . nil)
617 (keyword-default . nil))
618 "Association list governing specification of object classes for completion.
620 When IDLWAVE tries to complete object-oriented methods, it usually
621 cannot determine the class of a given object from context. In order
622 to provide the user with a correct list of methods or keywords, it
623 needs to determine the appropriate class. IDLWAVE has two ways of
624 doing this (well, three ways if you count the shell... see
625 `idlwave-shell-query-for-class'):
627 1. Combine the items of all available classes which contain this
628 method for the purpose of completion. So when completing a method,
629 all methods of all known classes are available, and when completing
630 a keyword, all keywords allowed for this method in any class are
631 shown. This behavior is very much like normal completion and is
632 therefore the default. It works much better than one might think -
633 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
634 become uncomfortably long. See also
635 `idlwave-completion-show-classes'.
637 2. The second possibility is to ask the user on each occasion. To
638 make this less interruptive, IDLWAVE can store the class as a text
639 property on the object operator `->'. For a given object in the
640 source code, class selection will then be needed only once
641 - for example to complete the method. Keywords to the method can
642 then be completed directly, because the class is already known.
643 You will have to turn on the storage of the selected class
644 explicitly with the variable `idlwave-store-inquired-class'.
646 This variable allows you to configure IDLWAVE's method and
647 method-keyword completion behavior. Its value is an alist, which
648 should contain at least two elements: (method-default . VALUE) and
649 \(keyword-default . VALUE), where VALUE is either t or nil. These
650 specify if the class should be found during method and keyword
651 completion, respectively.
653 The alist may have additional entries specifying exceptions from the
654 keyword completion rule for specific methods, like INIT or
655 GETPROPERTY. In order to turn on class specification for the INIT
656 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
657 :group 'idlwave-completion
658 :type '(list
659 (cons (const method-default)
660 (boolean :tag "Determine class when completing METHODS "))
661 (cons (const keyword-default)
662 (boolean :tag "Determine class when completing KEYWORDS "))
663 (repeat
664 :tag "Exceptions to defaults"
665 :inline t
666 (cons (string :tag "MODULE" :value "")
667 (boolean :tag "Determine class for this method")))))
669 (defcustom idlwave-store-inquired-class t
670 "Non-nil means, store class of a method call as text property on `->'.
671 IDLWAVE sometimes has to ask the user for the class associated with a
672 particular object method call. This happens during the commands
673 `idlwave-routine-info' and `idlwave-complete', depending upon the
674 value of the variable `idlwave-query-class'.
676 When you specify a class, this information can be stored as a text
677 property on the `->' arrow in the source code, so that during the same
678 editing session, IDLWAVE will not have to ask again. When this
679 variable is non-nil, IDLWAVE will store and reuse the class information.
680 The class stored can be checked and removed with `\\[idlwave-routine-info]'
681 on the arrow.
683 The default of this variable is nil, since the result of commands then
684 is more predictable. However, if you know what you are doing, it can
685 be nice to turn this on.
687 An arrow which knows the class will be highlighted with
688 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
689 displays (with prefix arg: deletes) the class stored on the arrow
690 at point."
691 :group 'idlwave-completion
692 :type 'boolean)
694 (defcustom idlwave-class-arrow-face 'bold
695 "Face to highlight object operator arrows `->' which carry a class property.
696 When IDLWAVE stores a class name as text property on an object arrow
697 \(see variable `idlwave-store-inquired-class', it highlights the arrow
698 with this font in order to remind the user that this arrow is special."
699 :group 'idlwave-completion
700 :type 'symbol)
702 (defcustom idlwave-resize-routine-help-window t
703 "Non-nil means, resize the Routine-info *Help* window to fit the content."
704 :group 'idlwave-completion
705 :type 'boolean)
707 (defcustom idlwave-keyword-completion-adds-equal t
708 "Non-nil means, completion automatically adds `=' after completed keywords."
709 :group 'idlwave-completion
710 :type 'boolean)
712 (defcustom idlwave-function-completion-adds-paren t
713 "Non-nil means, completion automatically adds `(' after completed function.
714 nil means, don't add anything.
715 A value of `2' means, also add the closing parenthesis and position cursor
716 between the two."
717 :group 'idlwave-completion
718 :type '(choice (const :tag "Nothing" nil)
719 (const :tag "(" t)
720 (const :tag "()" 2)))
722 (defcustom idlwave-completion-restore-window-configuration t
723 "Non-nil means, try to restore the window configuration after completion.
724 When completion is not unique, Emacs displays a list of completions.
725 This messes up your window configuration. With this variable set, IDLWAVE
726 restores the old configuration after successful completion."
727 :group 'idlwave-completion
728 :type 'boolean)
730 ;;; Variables for abbrev and action behavior -----------------------------
732 (defgroup idlwave-abbrev-and-indent-action nil
733 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
734 The variables in this group govern this."
735 :group 'idlwave)
737 (defcustom idlwave-do-actions nil
738 "Non-nil means performs actions when indenting.
739 The actions that can be performed are listed in `idlwave-indent-action-table'."
740 :group 'idlwave-abbrev-and-indent-action
741 :type 'boolean)
743 (defcustom idlwave-abbrev-start-char "\\"
744 "A single character string used to start abbreviations in abbrev mode.
745 Possible characters to choose from: ~\\=`%
746 or even `?'. `.' is not a good choice because it can make structure
747 field names act like abbrevs in certain circumstances.
749 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
750 must set it directly using `setq' in the init file before idlwave.el
751 is loaded."
752 :group 'idlwave-abbrev-and-indent-action
753 :type 'string)
755 (defcustom idlwave-surround-by-blank nil
756 "Non-nil means, enable `idlwave-surround'.
757 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
758 `idlwave-surround'.
759 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
761 Also see the default key bindings for keys using `idlwave-surround'.
762 Keys are bound and made into actions calling `idlwave-surround' with
763 `idlwave-action-and-binding'.
764 See help for `idlwave-action-and-binding' for examples.
766 Also see help for `idlwave-surround'."
767 :group 'idlwave-abbrev-and-indent-action
768 :type 'boolean)
770 (defcustom idlwave-pad-keyword t
771 "Non-nil means pad `=' in keywords (routine calls or defs) like assignment.
772 Whenever `idlwave-surround' is non-nil then this affects how `=' is
773 padded for keywords and for variables. If t, pad the same as for
774 assignments. If nil then spaces are removed. With any other value,
775 spaces are left unchanged."
776 :group 'idlwave-abbrev-and-indent-action
777 :type '(choice
778 (const :tag "Pad like assignments" t)
779 (const :tag "Remove space near `='" nil)
780 (other :tag "Keep space near `='" keep)))
782 (defcustom idlwave-show-block t
783 "Non-nil means point blinks to block beginning for `idlwave-show-begin'."
784 :group 'idlwave-abbrev-and-indent-action
785 :type 'boolean)
787 (defcustom idlwave-expand-generic-end nil
788 "Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
789 :group 'idlwave-abbrev-and-indent-action
790 :type 'boolean)
792 (defcustom idlwave-reindent-end t
793 "Non-nil means re-indent line after END was typed."
794 :group 'idlwave-abbrev-and-indent-action
795 :type 'boolean)
797 (defcustom idlwave-abbrev-move t
798 "Non-nil means the abbrev hook can move point.
799 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
800 definitions, use the command `list-abbrevs', for abbrevs that move
801 point. Moving point is useful, for example, to place point between
802 parentheses of expanded functions.
804 See `idlwave-check-abbrev'."
805 :group 'idlwave-abbrev-and-indent-action
806 :type 'boolean)
808 (defcustom idlwave-abbrev-change-case nil
809 "Non-nil means all abbrevs will be forced to either upper or lower case.
810 If the value t, all expanded abbrevs will be upper case.
811 If the value is `down' then abbrevs will be forced to lower case.
812 If nil, the case will not change.
813 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
814 upper case, regardless of this variable."
815 :group 'idlwave-abbrev-and-indent-action
816 :type 'boolean)
818 (defcustom idlwave-reserved-word-upcase nil
819 "Non-nil means, reserved words will be made upper case via abbrev expansion.
820 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
821 Has effect only if in abbrev-mode."
822 :group 'idlwave-abbrev-and-indent-action
823 :type 'boolean)
825 ;;; Action/Expand Tables.
827 ;; The average user may have difficulty modifying this directly. It
828 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
829 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
830 ;; examples of how to add an action.
832 ;; The action table is used by `idlwave-indent-line' whereas both the
833 ;; action and expand tables are used by `idlwave-indent-and-action'. In
834 ;; general, the expand table is only used when a line is explicitly
835 ;; indented. Whereas, in addition to being used when the expand table
836 ;; is used, the action table is used when a line is indirectly
837 ;; indented via line splitting, auto-filling or a new line creation.
839 ;; Example actions:
841 ;; Capitalize system vars
842 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
844 ;; Capitalize procedure name
845 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
846 ;; '(capitalize-word 1) t)
848 ;; Capitalize common block name
849 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
850 ;; '(capitalize-word 1) t)
851 ;; Capitalize label
852 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
853 ;; '(capitalize-word -1) t)
855 (defvar idlwave-indent-action-table nil
856 "Associated array containing action lists of search string (car),
857 and function as a cdr. This table is used by `idlwave-indent-line'.
858 See documentation for `idlwave-do-action' for a complete description of
859 the action lists.
861 Additions to the table are made with `idlwave-action-and-binding' when a
862 binding is not requested.
863 See help on `idlwave-action-and-binding' for examples.")
865 (defvar idlwave-indent-expand-table nil
866 "Associated array containing action lists of search string (car),
867 and function as a cdr. The table is used by the
868 `idlwave-indent-and-action' function. See documentation for
869 `idlwave-do-action' for a complete description of the action lists.
871 Additions to the table are made with `idlwave-action-and-binding' when a
872 binding is requested.
873 See help on `idlwave-action-and-binding' for examples.")
875 ;;; Documentation header and history keyword ---------------------------------
877 (defgroup idlwave-documentation nil
878 "Options for documenting IDLWAVE files."
879 :group 'idlwave)
881 ;; FIXME: make defcustom?
882 (defvar idlwave-file-header
883 (list nil
885 ; NAME:
889 ; PURPOSE:
893 ; CATEGORY:
897 ; CALLING SEQUENCE:
901 ; INPUTS:
905 ; OPTIONAL INPUTS:
909 ; KEYWORD PARAMETERS:
913 ; OUTPUTS:
917 ; OPTIONAL OUTPUTS:
921 ; COMMON BLOCKS:
925 ; SIDE EFFECTS:
929 ; RESTRICTIONS:
933 ; PROCEDURE:
937 ; EXAMPLE:
941 ; MODIFICATION HISTORY:
945 "A list (PATHNAME STRING) specifying the doc-header template to use for
946 summarizing a file. If PATHNAME is non-nil then this file will be included.
947 Otherwise STRING is used. If nil, the file summary will be omitted.
948 For example you might set PATHNAME to the path for the
949 lib_template.pro file included in the IDL distribution.")
951 (defcustom idlwave-header-to-beginning-of-file t
952 "Non-nil means, the documentation header will always be at start of file.
953 When nil, the header is positioned between the PRO/FUNCTION line of
954 the current routine and the code, allowing several routine headers in
955 a file."
956 :group 'idlwave-documentation
957 :type 'boolean)
959 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
960 "The hook function used to update the timestamp of a function."
961 :group 'idlwave-documentation
962 :type 'function)
964 (defcustom idlwave-doc-modifications-keyword "HISTORY"
965 "The modifications keyword to use with the log documentation commands.
966 A `:' is added to the keyword end.
967 Inserted by doc-header and used to position logs by doc-modification.
968 If nil it will not be inserted."
969 :group 'idlwave-documentation
970 :type 'string)
972 (defcustom idlwave-doclib-start "^;+\\+"
973 "Regexp matching the start of a document library header."
974 :group 'idlwave-documentation
975 :type 'regexp)
977 (defcustom idlwave-doclib-end "^;+-"
978 "Regexp matching the end of a document library header."
979 :group 'idlwave-documentation
980 :type 'regexp)
982 ;;; External Programs -------------------------------------------------------
984 (defgroup idlwave-external-programs nil
985 "Path locations of external commands used by IDLWAVE."
986 :group 'idlwave)
988 (defcustom idlwave-shell-explicit-file-name "idl"
989 "If non-nil, this is the command to run IDL.
990 Should be an absolute file path or path relative to the current environment
991 execution search path. If you want to specify command line switches
992 for the IDL program, use `idlwave-shell-command-line-options'.
994 I know the name of this variable is badly chosen, but I cannot change
995 it without compromising backwards-compatibility."
996 :group 'idlwave-external-programs
997 :type 'string)
999 (defcustom idlwave-shell-command-line-options nil
1000 "A list of command line options for calling the IDL program.
1001 Since IDL is executed directly without going through a shell like /bin/sh,
1002 this should be a list of strings like (\"-rt=file\" \"-nw\") with a separate
1003 string for each argument. But you may also give a single string which
1004 contains the options whitespace-separated. Emacs will be kind enough to
1005 split it for you."
1006 :type '(choice
1007 string
1008 (repeat (string :value "")))
1009 :group 'idlwave-external-programs)
1011 (defcustom idlwave-help-application "idlhelp"
1012 "The external application providing reference help for programming.
1013 Obsolete, if the IDL Assistant is being used for help."
1014 :group 'idlwave-external-programs
1015 :type 'string)
1017 ;;; Some Shell variables which must be defined here.-----------------------
1019 (defcustom idlwave-shell-debug-modifiers '()
1020 "List of modifiers to be used for the debugging commands.
1021 Will be used to bind debugging commands in the shell buffer and in all
1022 source buffers. These are additional convenience bindings, the debugging
1023 commands are always available with the `C-c C-d' prefix.
1024 If you set this to (control shift), this means setting a breakpoint will
1025 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1026 are `control', `meta', `super', `hyper', `alt', and `shift'."
1027 :group 'idlwave-shell-general-setup
1028 :type '(set :tag "Specify modifiers"
1029 (const control)
1030 (const meta)
1031 (const super)
1032 (const hyper)
1033 (const alt)
1034 (const shift)))
1036 (defcustom idlwave-shell-automatic-start nil
1037 "If non-nil attempt invoke `idlwave-shell' if not already running.
1038 This is checked when an attempt to send a command to an
1039 IDL process is made."
1040 :group 'idlwave-shell-general-setup
1041 :type 'boolean)
1043 ;;; Miscellaneous variables -------------------------------------------------
1045 (defgroup idlwave-misc nil
1046 "Miscellaneous options for IDLWAVE mode."
1047 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
1048 :group 'idlwave)
1050 (defcustom idlwave-startup-message t
1051 "Non-nil displays a startup message when `idlwave-mode' is first called."
1052 :group 'idlwave-misc
1053 :type 'boolean)
1055 (defcustom idlwave-default-font-lock-items
1056 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1057 common-blocks class-arrows)
1058 "Items which should be fontified on the default fontification level 2.
1059 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1060 is everything and level 2 is specified by this list.
1061 This variable must be set before IDLWAVE gets loaded.
1062 It is a list of symbols; the following symbols are allowed:
1064 pros-and-functions Procedure and Function definitions
1065 batch-files Batch Files
1066 idlwave-idl-keywords IDL Keywords
1067 label Statement Labels
1068 goto Goto Statements
1069 common-blocks Common Blocks
1070 keyword-parameters Keyword Parameters in routine definitions and calls
1071 system-variables System Variables
1072 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1073 class-arrows Object Arrows with class property"
1074 :group 'idlwave-misc
1075 :type '(set
1076 :inline t :greedy t
1077 (const :tag "Procedure and Function definitions" pros-and-functions)
1078 (const :tag "Batch Files" batch-files)
1079 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1080 (const :tag "Statement Labels" label)
1081 (const :tag "Goto Statements" goto)
1082 (const :tag "Tags in Structure Definition" structtag)
1083 (const :tag "Structure Name" structname)
1084 (const :tag "Common Blocks" common-blocks)
1085 (const :tag "Keyword Parameters" keyword-parameters)
1086 (const :tag "System Variables" system-variables)
1087 (const :tag "FIXME: Warning" fixme)
1088 (const :tag "Object Arrows with class property " class-arrows)))
1090 (defcustom idlwave-mode-hook nil
1091 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1092 :group 'idlwave-misc
1093 :type 'hook)
1095 (defcustom idlwave-load-hook nil
1096 "Normal hook. Executed when idlwave.el is loaded."
1097 :group 'idlwave-misc
1098 :type 'hook)
1100 (defvar idlwave-experimental nil
1101 "Non-nil means turn on a few experimental features.
1102 This variable is only for the maintainer, to test difficult stuff,
1103 while still distributing stable releases.
1104 As a user, you should not set this to t.")
1107 ;;; End customization variables section
1110 ;;; Non customization variables
1112 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1113 ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
1114 ;;; and Carsten Dominik...
1116 ;; The following are the reserved words in IDL. Maybe we should
1117 ;; highlight some more stuff as well?
1118 ;; Procedure declarations. Fontify keyword plus procedure name.
1119 (defvar idlwave-idl-keywords
1120 ;; To update this regexp, update the list of keywords and
1121 ;; evaluate the form.
1122 ;; (insert
1123 ;; (prin1-to-string
1124 ;; (concat
1125 ;; "\\<\\("
1126 ;; (regexp-opt
1127 ;; '("||" "&&" "and" "or" "xor" "not"
1128 ;; "eq" "ge" "gt" "le" "lt" "ne"
1129 ;; "for" "do" "endfor"
1130 ;; "if" "then" "endif" "else" "endelse"
1131 ;; "case" "of" "endcase"
1132 ;; "switch" "break" "continue" "endswitch"
1133 ;; "begin" "end"
1134 ;; "repeat" "until" "endrep"
1135 ;; "while" "endwhile"
1136 ;; "goto" "return"
1137 ;; "inherits" "mod"
1138 ;; "compile_opt" "forward_function"
1139 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1140 ;; "\\)\\>")))
1141 "\\<\\(&&\\|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\\|||\\)\\>")
1144 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1145 ;; Function declarations. Fontify keyword plus function name.
1146 (pros-and-functions
1147 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1148 (1 font-lock-keyword-face)
1149 (2 font-lock-function-name-face nil t)))
1151 ;; Common blocks
1152 (common-blocks
1153 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1154 (1 font-lock-keyword-face) ; "common"
1155 (2 font-lock-constant-face nil t) ; block name
1156 ("[ \t]*\\(\\sw+\\)[ ,]*"
1157 ;; Start with point after block name and comma
1158 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1160 (1 font-lock-variable-name-face) ; variable names
1163 ;; Batch files
1164 (batch-files
1165 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1167 ;; FIXME warning.
1168 (fixme
1169 '("\\<FIXME:" (0 font-lock-warning-face t)))
1171 ;; Labels
1172 (label
1173 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-constant-face)))
1175 ;; The goto statement and its label
1176 (goto
1177 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1178 (1 font-lock-keyword-face)
1179 (2 font-lock-constant-face)))
1181 ;; Tags in structure definitions. Note that this definition
1182 ;; actually collides with labels, so we have to use the same
1183 ;; face. It also matches named subscript ranges,
1184 ;; e.g. vec{bottom:top]. No good way around this.
1185 (structtag
1186 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-constant-face)))
1188 ;; Structure names
1189 (structname
1190 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1191 (2 font-lock-function-name-face)))
1193 ;; Keyword parameters, like /xlog or ,xrange=[]
1194 ;; This is anchored to the comma preceding the keyword.
1195 ;; Treats continuation lines, works only during whole buffer
1196 ;; fontification. Slow, use it only in fancy fontification.
1197 (keyword-parameters
1198 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1199 (6 font-lock-constant-face)))
1201 ;; System variables start with a bang.
1202 (system-variables
1203 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1204 (1 font-lock-variable-name-face)))
1206 ;; Special and unusual operators (not used because too noisy)
1207 ;; (special-operators
1208 ;; '("[<>#]" (0 font-lock-keyword-face)))
1210 ;; All operators (not used because too noisy)
1211 ;; (all-operators
1212 ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1214 ;; Arrows with text property `idlwave-class'
1215 (class-arrows
1216 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1218 (defconst idlwave-font-lock-keywords-1
1219 (list pros-and-functions batch-files)
1220 "Subdued level highlighting for IDLWAVE mode.")
1222 (defconst idlwave-font-lock-keywords-2
1223 (mapcar 'symbol-value idlwave-default-font-lock-items)
1224 "Medium level highlighting for IDLWAVE mode.")
1226 (defconst idlwave-font-lock-keywords-3
1227 (list pros-and-functions
1228 batch-files
1229 idlwave-idl-keywords
1230 label goto
1231 structtag
1232 structname
1233 common-blocks
1234 keyword-parameters
1235 system-variables
1236 class-arrows)
1237 "Gaudy level highlighting for IDLWAVE mode."))
1239 (defun idlwave-match-class-arrows (limit)
1240 ;; Match an object arrow with class property
1241 (and idlwave-store-inquired-class
1242 (re-search-forward "->" limit 'limit)
1243 (get-text-property (match-beginning 0) 'idlwave-class)))
1245 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1246 "Default expressions to highlight in IDLWAVE mode.")
1248 (defvar idlwave-font-lock-defaults
1249 '((idlwave-font-lock-keywords
1250 idlwave-font-lock-keywords-1
1251 idlwave-font-lock-keywords-2
1252 idlwave-font-lock-keywords-3)
1253 nil t
1254 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
1255 beginning-of-line))
1257 (put 'idlwave-mode 'font-lock-defaults
1258 idlwave-font-lock-defaults) ; XEmacs
1260 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1261 "Regexp to match the start of a full-line comment.
1262 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1263 only by whitespace.")
1265 (defconst idlwave-begin-block-reg
1266 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1267 "Regular expression to find the beginning of a block.
1268 The case does not matter. The search skips matches in comments.")
1270 (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
1271 "Regular expression to find the beginning of a unit.
1272 The case does not matter.")
1274 (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
1275 "Regular expression to find the line that indicates the end of unit.
1276 This line is the end of buffer or the start of another unit.
1277 The case does not matter. The search skips matches in comments.")
1279 (defconst idlwave-continue-line-reg "\\<\\$"
1280 "Regular expression to match a continued line.")
1282 (defconst idlwave-end-block-reg
1283 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1284 "Regular expression to find the end of a block.
1285 The case does not matter. The search skips matches in comments.")
1287 (defconst idlwave-block-matches
1288 '(("pro" . "end")
1289 ("function" . "end")
1290 ("case" . "endcase")
1291 ("else" . "endelse")
1292 ("for" . "endfor")
1293 ("then" . "endif")
1294 ("repeat" . "endrep")
1295 ("switch" . "endswitch")
1296 ("while" . "endwhile"))
1297 "Matches between statements and the corresponding END variant.
1298 The cars are the reserved words starting a block. If the block really
1299 begins with BEGIN, the cars are the reserved words before the begin
1300 which can be used to identify the block type.
1301 This is used to check for the correct END type, to close blocks and
1302 to expand generic end statements to their detailed form.")
1304 (defconst idlwave-block-match-regexp
1305 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1306 "Regular expression matching reserved words which can stand before
1307 blocks starting with a BEGIN statement. The matches must have associations
1308 `idlwave-block-matches'.")
1310 (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
1311 "Regular expression matching an IDL identifier.")
1313 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1314 "Regular expression matching IDL system variables.")
1316 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1317 "Regular expression matching IDL variable names.")
1319 (defconst idlwave-label (concat idlwave-identifier ":")
1320 "Regular expression matching IDL labels.")
1322 (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1323 "\\(\\s *" idlwave-identifier "::\\)?"
1326 (defconst idlwave-statement-match
1327 (list
1328 ;; "endif else" is the only possible "end" that can be
1329 ;; followed by a statement on the same line.
1330 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1331 ;; all other "end"s can not be followed by a statement.
1332 (cons 'end (list idlwave-end-block-reg nil))
1333 '(if . ("if\\>" "then"))
1334 '(for . ("for\\>" "do"))
1335 '(begin . ("begin\\>" nil))
1336 '(pdef . ("pro\\>\\|function\\>" nil))
1337 '(while . ("while\\>" "do"))
1338 '(repeat . ("repeat\\>" "repeat"))
1339 '(goto . ("goto\\>" nil))
1340 '(case . ("case\\>" nil))
1341 '(switch . ("switch\\>" nil))
1342 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
1343 "\\(" idlwave-method-call "\\s *\\)?"
1344 idlwave-identifier
1345 "\\s *(") nil))
1346 (cons 'call (list (concat
1347 "\\(" idlwave-method-call "\\s *\\)?"
1348 idlwave-identifier
1349 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
1350 (cons 'assign (list (concat
1351 "\\(" idlwave-variable "\\) *=") nil)))
1353 "Associated list of statement matching regular expressions.
1354 Each regular expression matches the start of an IDL statement.
1355 The first element of each association is a symbol giving the statement
1356 type. The associated value is a list. The first element of this list
1357 is a regular expression matching the start of an IDL statement for
1358 identifying the statement type. The second element of this list is a
1359 regular expression for finding a substatement for the type. The
1360 substatement starts after the end of the found match modulo
1361 whitespace. If it is nil then the statement has no substatement. The
1362 list order matters since matching an assignment statement exactly is
1363 not possible without parsing. Thus assignment statement become just
1364 the leftover unidentified statements containing an equal sign.")
1366 ;; FIXME: This var seems to only ever be set, but never actually used!
1367 (defvar idlwave-fill-function 'auto-fill-function
1368 "IDL mode auto fill function.")
1370 (defvar idlwave-comment-indent-function 'comment-indent-function
1371 "IDL mode comment indent function.")
1373 ;; Note that this is documented in the v18 manuals as being a string
1374 ;; of length one rather than a single character.
1375 ;; The code in this file accepts either format for compatibility.
1376 (defvar idlwave-comment-indent-char ?\
1377 "Character to be inserted for IDL comment indentation.
1378 Normally a space.")
1380 (defconst idlwave-continuation-char ?$
1381 "Character which is inserted as a last character on previous line by
1382 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1384 (defconst idlwave-mode-version "6.1_em22")
1386 (defmacro idlwave-keyword-abbrev (&rest args)
1387 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1388 `(quote (lambda ()
1389 ,(append '(idlwave-check-abbrev) args))))
1391 ;; If I take the time I can replace idlwave-keyword-abbrev with
1392 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1393 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1394 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1395 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1397 (defmacro idlwave-code-abbrev (&rest args)
1398 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1399 Specifically, if the abbrev is in a comment or string it is unexpanded.
1400 Otherwise ARGS forms a list that is evaluated."
1401 ;; FIXME: it would probably be better to rely on the new :enable-function
1402 ;; to enforce the "don't expand in comments or strings".
1403 `(lambda ()
1404 ,(prin1-to-string args) ;; Puts the code in the doc string
1405 (if (idlwave-quoted)
1406 (progn (unexpand-abbrev) nil)
1407 ,(append args))))
1409 (autoload 'idlwave-shell "idlw-shell"
1410 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1411 (autoload 'idlwave-shell-send-command "idlw-shell")
1412 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1413 "Run `idlwave-shell' and switch back to current window" t)
1414 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1415 "Save and run buffer under the shell." t)
1416 (autoload 'idlwave-shell-break-here "idlw-shell"
1417 "Set breakpoint in current line." t)
1418 (autoload 'idlwave-shell-run-region "idlw-shell"
1419 "Compile and run the region." t)
1421 (fset 'idlwave-debug-map (make-sparse-keymap))
1423 (defvar idlwave-mode-map
1424 (let ((map (make-sparse-keymap)))
1425 (define-key map "\C-c " 'idlwave-hard-tab)
1426 (define-key map [(control tab)] 'idlwave-hard-tab)
1427 ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
1428 (define-key map "'" 'idlwave-show-matching-quote)
1429 (define-key map "\"" 'idlwave-show-matching-quote)
1430 (define-key map "\C-g" 'idlwave-keyboard-quit)
1431 (define-key map "\C-c;" 'idlwave-toggle-comment-region)
1432 (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1433 (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
1434 (define-key map "\C-c{" 'idlwave-beginning-of-block)
1435 (define-key map "\C-c}" 'idlwave-end-of-block)
1436 (define-key map "\C-c]" 'idlwave-close-block)
1437 (define-key map [(meta control h)] 'idlwave-mark-subprogram)
1438 (define-key map "\M-\C-n" 'idlwave-forward-block)
1439 (define-key map "\M-\C-p" 'idlwave-backward-block)
1440 (define-key map "\M-\C-d" 'idlwave-down-block)
1441 (define-key map "\M-\C-u" 'idlwave-backward-up-block)
1442 (define-key map "\M-\r" 'idlwave-split-line)
1443 (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
1444 (define-key map "\C-c\C-p" 'idlwave-previous-statement)
1445 (define-key map "\C-c\C-n" 'idlwave-next-statement)
1446 ;; (define-key map "\r" 'idlwave-newline)
1447 ;; (define-key map "\t" 'idlwave-indent-line)
1448 (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
1449 (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
1450 (define-key map "\M-q" 'idlwave-fill-paragraph)
1451 (define-key map "\M-s" 'idlwave-edit-in-idlde)
1452 (define-key map "\C-c\C-h" 'idlwave-doc-header)
1453 (define-key map "\C-c\C-m" 'idlwave-doc-modification)
1454 (define-key map "\C-c\C-c" 'idlwave-case)
1455 (define-key map "\C-c\C-d" 'idlwave-debug-map)
1456 (when (and (listp idlwave-shell-debug-modifiers)
1457 (not (equal idlwave-shell-debug-modifiers '())))
1458 ;; Bind the debug commands also with the special modifiers.
1459 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1460 (mods-noshift
1461 (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
1462 (define-key map
1463 (vector (append mods-noshift (list (if shift ?C ?c))))
1464 'idlwave-shell-save-and-run)
1465 (define-key map
1466 (vector (append mods-noshift (list (if shift ?B ?b))))
1467 'idlwave-shell-break-here)
1468 (define-key map
1469 (vector (append mods-noshift (list (if shift ?E ?e))))
1470 'idlwave-shell-run-region)))
1471 (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1472 (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1473 (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
1474 (define-key map "\C-c\C-f" 'idlwave-for)
1475 ;; (define-key map "\C-c\C-f" 'idlwave-function)
1476 ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
1477 (define-key map "\C-c\C-r" 'idlwave-repeat)
1478 (define-key map "\C-c\C-w" 'idlwave-while)
1479 (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1480 (define-key map "\C-c\C-s" 'idlwave-shell)
1481 (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1482 (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1483 (define-key map "\C-c\C-v" 'idlwave-find-module)
1484 (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
1485 (define-key map "\C-c?" 'idlwave-routine-info)
1486 (define-key map "\M-?" 'idlwave-context-help)
1487 (define-key map [(control meta ?\?)]
1488 'idlwave-help-assistant-help-with-topic)
1489 ;; Pickup both forms of Esc/Meta binding
1490 (define-key map [(meta tab)] 'idlwave-complete)
1491 (define-key map [?\e?\t] 'idlwave-complete)
1492 (define-key map "\M-\C-i" 'idlwave-complete)
1493 (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
1494 (define-key map "\C-c=" 'idlwave-resolve)
1495 (define-key map
1496 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1497 'idlwave-mouse-context-help)
1498 map)
1499 "Keymap used in IDL mode.")
1501 (defvar idlwave-mode-syntax-table
1502 (let ((st (make-syntax-table)))
1503 (modify-syntax-entry ?+ "." st)
1504 (modify-syntax-entry ?- "." st)
1505 (modify-syntax-entry ?* "." st)
1506 (modify-syntax-entry ?/ "." st)
1507 (modify-syntax-entry ?^ "." st)
1508 (modify-syntax-entry ?# "." st)
1509 (modify-syntax-entry ?= "." st)
1510 (modify-syntax-entry ?% "." st)
1511 (modify-syntax-entry ?< "." st)
1512 (modify-syntax-entry ?> "." st)
1513 (modify-syntax-entry ?\' "\"" st)
1514 (modify-syntax-entry ?\" "\"" st)
1515 (modify-syntax-entry ?\\ "." st)
1516 (modify-syntax-entry ?_ "_" st)
1517 (modify-syntax-entry ?{ "(}" st)
1518 (modify-syntax-entry ?} "){" st)
1519 (modify-syntax-entry ?$ "_" st)
1520 (modify-syntax-entry ?. "." st)
1521 (modify-syntax-entry ?\; "<" st)
1522 (modify-syntax-entry ?\n ">" st)
1523 (modify-syntax-entry ?\f ">" st)
1525 "Syntax table in use in `idlwave-mode' buffers.")
1527 (defvar idlwave-find-symbol-syntax-table
1528 (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
1529 (modify-syntax-entry ?$ "w" st)
1530 (modify-syntax-entry ?_ "w" st)
1531 (modify-syntax-entry ?! "w" st)
1532 (modify-syntax-entry ?. "w" st)
1534 "Syntax table that treats symbol characters as word characters.")
1536 (defmacro idlwave-with-special-syntax (&rest body)
1537 "Execute BODY with a different syntax table."
1538 `(let ((saved-syntax (syntax-table)))
1539 (unwind-protect
1540 (progn
1541 (set-syntax-table idlwave-find-symbol-syntax-table)
1542 ,@body)
1543 (set-syntax-table saved-syntax))))
1545 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1546 ; "Execute BODY with a different syntax table."
1547 ; `(let ((saved-syntax (syntax-table)))
1548 ; (unwind-protect
1549 ; (progn
1550 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1551 ; ,@body)
1552 ; (set-syntax-table saved-syntax))))
1554 (defun idlwave-action-and-binding (key cmd &optional select)
1555 "KEY and CMD are made into a key binding and an indent action.
1556 KEY is a string - same as for the `define-key' function. CMD is a
1557 function of no arguments or a list to be evaluated. CMD is bound to
1558 KEY in `idlwave-mode-map' by defining an anonymous function calling
1559 `self-insert-command' followed by CMD. If KEY contains more than one
1560 character a binding will only be set if SELECT is `both'.
1562 \(KEY . CMD) is also placed in the `idlwave-indent-expand-table',
1563 replacing any previous value for KEY. If a binding is not set then it
1564 will instead be placed in `idlwave-indent-action-table'.
1566 If the optional argument SELECT is nil then an action and binding are
1567 created. If SELECT is `noaction', then a binding is always set and no
1568 action is created. If SELECT is `both' then an action and binding
1569 will both be created even if KEY contains more than one character.
1570 Otherwise, if SELECT is non-nil then only an action is created.
1572 Some examples:
1573 No spaces before and 1 after a comma
1574 (idlwave-action-and-binding \",\" \\='(idlwave-surround 0 1))
1575 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1576 (idlwave-action-and-binding \"=\" \\='(idlwave-expand-equal -1 -1))
1577 Capitalize system variables - action only
1578 (idlwave-action-and-binding idlwave-sysvar \\='(capitalize-word 1) t)"
1579 (if (not (equal select 'noaction))
1580 ;; Add action
1581 (let* ((table (if select 'idlwave-indent-action-table
1582 'idlwave-indent-expand-table))
1583 (table-key (regexp-quote key))
1584 (cell (assoc table-key (eval table))))
1585 (if cell
1586 ;; Replace action command
1587 (setcdr cell cmd)
1588 ;; New action
1589 (set table (append (eval table) (list (cons table-key cmd)))))))
1590 ;; Make key binding for action
1591 (if (or (and (null select) (= (length key) 1))
1592 (equal select 'noaction)
1593 (equal select 'both))
1594 (define-key idlwave-mode-map key
1595 `(lambda ()
1596 (interactive)
1597 (self-insert-command 1)
1598 ,(if (listp cmd) cmd (list cmd))))))
1600 ;; Set action and key bindings.
1601 ;; See description of the function `idlwave-action-and-binding'.
1602 ;; Automatically add spaces for the following characters
1604 ;; Actions for & are complicated by &&
1605 (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1607 ;; Automatically add spaces to equal sign if not keyword. This needs
1608 ;; to go ahead of > and <, so >= and <= will be treated correctly
1609 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1611 ;; Actions for > and < are complicated by >=, <=, and ->...
1612 (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1613 (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1615 (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1619 ;;; Abbrev Section
1621 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1622 ;;; space is inserted (this is the space typed by the user to expanded
1623 ;;; the abbrev).
1625 (defvar idlwave-mode-abbrev-table nil
1626 "Abbreviation table used for IDLWAVE mode.")
1627 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1629 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1630 "Define-abbrev with backward compatibility.
1632 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1633 `idlwave-mode-abbrev-table' unless TABLE is non-nil."
1634 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1635 (args (list (or table idlwave-mode-abbrev-table)
1636 (if noprefix name (concat idlwave-abbrev-start-char name))
1637 expansion
1638 hook)))
1639 (condition-case nil
1640 (apply 'define-abbrev (append args '(0 t)))
1641 (error (apply 'define-abbrev args)))))
1643 (condition-case nil
1644 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1645 "w" idlwave-mode-syntax-table)
1646 (error nil))
1649 ;; Templates
1651 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1652 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1653 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1654 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1655 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1656 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1657 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1658 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1659 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1661 ;; Keywords, system functions, conversion routines
1663 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1664 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1665 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1666 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1667 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1668 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1669 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1670 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1672 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1673 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1674 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1675 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1676 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1677 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1678 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1679 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1680 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1681 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1682 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1683 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1684 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1685 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1686 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1687 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1688 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1689 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1690 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1691 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1693 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1694 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1696 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1699 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1700 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1701 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1702 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1703 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1704 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1705 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1707 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1708 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1709 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1710 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1711 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1712 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1713 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1714 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1715 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1716 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1717 (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1718 (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
1720 ;; This section is reserved words only. (From IDL user manual)
1722 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1723 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1724 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1725 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1726 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1727 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1728 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1729 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1730 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1731 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1732 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1733 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1734 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1735 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1736 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1737 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1738 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1739 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1740 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1741 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1742 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1743 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1744 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1745 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1746 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1747 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1748 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1749 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1750 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1751 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1752 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1753 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1754 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1755 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1756 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1757 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1758 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1759 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1760 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1762 (defvar imenu-create-index-function)
1763 (defvar extract-index-name-function)
1764 (defvar prev-index-position-function)
1765 (defvar imenu-extract-index-name-function)
1766 (defvar imenu-prev-index-position-function)
1767 ;; defined later - so just make the compiler hush
1768 (defvar idlwave-mode-menu)
1769 (defvar idlwave-mode-debug-menu)
1771 ;;;###autoload
1772 (define-derived-mode idlwave-mode prog-mode "IDLWAVE"
1773 "Major mode for editing IDL source files (version 6.1_em22).
1775 The main features of this mode are
1777 1. Indentation and Formatting
1778 --------------------------
1779 Like other Emacs programming modes, C-j inserts a newline and indents.
1780 TAB is used for explicit indentation of the current line.
1782 To start a continuation line, use \\[idlwave-split-line]. This
1783 function can also be used in the middle of a line to split the line
1784 at that point. When used inside a long constant string, the string
1785 is split at that point with the `+' concatenation operator.
1787 Comments are indented as follows:
1789 `;;;' Indentation remains unchanged.
1790 `;;' Indent like the surrounding code
1791 `;' Indent to a minimum column.
1793 The indentation of comments starting in column 0 is never changed.
1795 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1796 comment. The indentation of the second line of the paragraph
1797 relative to the first will be retained. Use
1798 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1799 comments. When the variable `idlwave-fill-comment-line-only' is
1800 nil, code can also be auto-filled and auto-indented.
1802 To convert pre-existing IDL code to your formatting style, mark the
1803 entire buffer with \\[mark-whole-buffer] and execute
1804 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1805 again followed by \\[indent-region] (`indent-region').
1807 2. Routine Info
1808 ------------
1809 IDLWAVE displays information about the calling sequence and the
1810 accepted keyword parameters of a procedure or function with
1811 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1812 source file of a module. These commands know about system
1813 routines, all routines in idlwave-mode buffers and (when the
1814 idlwave-shell is active) about all modules currently compiled under
1815 this shell. It also makes use of pre-compiled or custom-scanned
1816 user and library catalogs many popular libraries ship with by
1817 default. Use \\[idlwave-update-routine-info] to update this
1818 information, which is also used for completion (see item 4).
1820 3. Online IDL Help
1821 ---------------
1823 \\[idlwave-context-help] displays the IDL documentation relevant
1824 for the system variable, keyword, or routines at point. A single
1825 key stroke gets you directly to the right place in the docs. See
1826 the manual to configure where and how the HTML help is displayed.
1828 4. Completion
1829 ----------
1830 \\[idlwave-complete] completes the names of procedures, functions
1831 class names, keyword parameters, system variables and tags, class
1832 tags, structure tags, filenames and much more. It is context
1833 sensitive and figures out what is expected at point. Lower case
1834 strings are completed in lower case, other strings in mixed or
1835 upper case.
1837 5. Code Templates and Abbreviations
1838 --------------------------------
1839 Many Abbreviations are predefined to expand to code fragments and templates.
1840 The abbreviations start generally with a `\\'. Some examples:
1842 \\pr PROCEDURE template
1843 \\fu FUNCTION template
1844 \\c CASE statement template
1845 \\sw SWITCH statement template
1846 \\f FOR loop template
1847 \\r REPEAT Loop template
1848 \\w WHILE loop template
1849 \\i IF statement template
1850 \\elif IF-ELSE statement template
1851 \\b BEGIN
1853 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1854 have direct keybindings - see the list of keybindings below.
1856 \\[idlwave-doc-header] inserts a documentation header at the
1857 beginning of the current program unit (pro, function or main).
1858 Change log entries can be added to the current program unit with
1859 \\[idlwave-doc-modification].
1861 6. Automatic Case Conversion
1862 -------------------------
1863 The case of reserved words and some abbrevs is controlled by
1864 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1866 7. Automatic END completion
1867 ------------------------
1868 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1869 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1871 8. Hooks
1872 -----
1873 Loading idlwave.el runs `idlwave-load-hook'.
1874 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1876 9. Documentation and Customization
1877 -------------------------------
1878 Info documentation for this package is available. Use
1879 \\[idlwave-info] to display (complain to your sysadmin if that does
1880 not work). For Postscript, PDF, and HTML versions of the
1881 documentation, check IDLWAVE's homepage at URL
1882 `http://github.com/jdtsmith/idlwave'.
1883 IDLWAVE has customize support - see the group `idlwave'.
1885 10.Keybindings
1886 -----------
1887 Here is a list of all keybindings of this mode.
1888 If some of the key bindings below show with ??, use \\[describe-key]
1889 followed by the key sequence to see what the key sequence does.
1891 \\{idlwave-mode-map}"
1892 :abbrev-table idlwave-mode-abbrev-table
1893 (if idlwave-startup-message
1894 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1895 (setq idlwave-startup-message nil)
1897 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1899 (set (make-local-variable idlwave-comment-indent-function)
1900 #'idlwave-comment-hook)
1902 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1903 (set (make-local-variable 'comment-start) ";")
1904 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
1905 (set (make-local-variable 'abbrev-all-caps) t)
1906 (set (make-local-variable 'indent-tabs-mode) nil)
1907 (set (make-local-variable 'completion-ignore-case) t)
1909 (when (featurep 'easymenu)
1910 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1911 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1913 (setq abbrev-mode t)
1915 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1916 (setq comment-end "")
1917 (set (make-local-variable 'comment-multi-line) nil)
1918 (set (make-local-variable 'paragraph-separate)
1919 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1920 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1921 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1922 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1924 ;; ChangeLog
1925 (set (make-local-variable 'add-log-current-defun-function)
1926 'idlwave-current-routine-fullname)
1928 ;; Set tag table list to use IDLTAGS as file name.
1929 (if (boundp 'tag-table-alist)
1930 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1932 ;; Font-lock additions
1933 ;; Following line is for Emacs - XEmacs uses the corresponding property
1934 ;; on the `idlwave-mode' symbol.
1935 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1936 (set (make-local-variable 'font-lock-mark-block-function)
1937 'idlwave-mark-subprogram)
1938 (set (make-local-variable 'font-lock-fontify-region-function)
1939 'idlwave-font-lock-fontify-region)
1941 ;; Imenu setup
1942 (set (make-local-variable 'imenu-create-index-function)
1943 'imenu-default-create-index-function)
1944 (set (make-local-variable 'imenu-extract-index-name-function)
1945 'idlwave-unit-name)
1946 (set (make-local-variable 'imenu-prev-index-position-function)
1947 'idlwave-prev-index-position)
1949 ;; HideShow setup
1950 (add-to-list 'hs-special-modes-alist
1951 (list 'idlwave-mode
1952 idlwave-begin-block-reg
1953 idlwave-end-block-reg
1955 'idlwave-forward-block nil))
1957 ;; Make a local post-command-hook and add our hook to it
1958 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1959 ;; (make-local-hook 'post-command-hook)
1960 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1962 ;; Make local hooks for buffer updates
1963 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1964 ;; (make-local-hook 'kill-buffer-hook)
1965 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1966 ;; (make-local-hook 'after-save-hook)
1967 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1968 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1970 ;; Setup directories and file, if necessary
1971 (idlwave-setup)
1973 ;; Update the routine info with info about current buffer?
1974 (idlwave-new-buffer-update)
1976 ;; Check help location
1977 (idlwave-help-check-locations))
1979 (defvar idlwave-setup-done nil)
1980 (defun idlwave-setup ()
1981 (unless idlwave-setup-done
1982 (if (not (file-directory-p idlwave-config-directory))
1983 (make-directory idlwave-config-directory))
1984 (setq
1985 idlwave-user-catalog-file (expand-file-name
1986 idlwave-user-catalog-file
1987 idlwave-config-directory)
1988 idlwave-xml-system-rinfo-converted-file
1989 (expand-file-name
1990 idlwave-xml-system-rinfo-converted-file
1991 idlwave-config-directory)
1992 idlwave-path-file (expand-file-name
1993 idlwave-path-file
1994 idlwave-config-directory))
1995 (idlwave-read-paths) ; we may need these early
1996 (setq idlwave-setup-done t)))
1998 (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
1999 "Fontify continuation lines correctly."
2000 (let (pos)
2001 (save-excursion
2002 (goto-char beg)
2003 (forward-line -1)
2004 (when (setq pos (idlwave-is-continuation-line))
2005 (goto-char pos)
2006 (idlwave-beginning-of-statement)
2007 (setq beg (point)))))
2008 (font-lock-default-fontify-region beg end verbose))
2011 ;; Code Formatting ----------------------------------------------------
2014 (defun idlwave-hard-tab ()
2015 "Insert TAB in buffer in current position."
2016 (interactive)
2017 (insert "\t"))
2019 ;;; This stuff is experimental
2021 (defvar idlwave-command-hook nil
2022 "If non-nil, a list that can be evaluated using `eval'.
2023 It is evaluated in the lisp function `idlwave-command-hook' which is
2024 placed in `post-command-hook'.")
2026 (defun idlwave-command-hook ()
2027 "Command run after every command.
2028 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2029 sets the variable to zero afterwards."
2030 (and idlwave-command-hook
2031 (listp idlwave-command-hook)
2032 (condition-case nil
2033 (eval idlwave-command-hook)
2034 (error nil)))
2035 (setq idlwave-command-hook nil))
2037 ;;; End experiment
2039 ;; It would be better to use expand.el for better abbrev handling and
2040 ;; versatility.
2042 (defun idlwave-check-abbrev (arg &optional reserved)
2043 "Reverse abbrev expansion if in comment or string.
2044 Argument ARG is the number of characters to move point
2045 backward if `idlwave-abbrev-move' is non-nil.
2046 If optional argument RESERVED is non-nil then the expansion
2047 consists of reserved words, which will be capitalized if
2048 `idlwave-reserved-word-upcase' is non-nil.
2049 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2050 is non-nil, unless its value is `down' in which case the abbrev will be
2051 made into all lowercase.
2052 Returns non-nil if abbrev is left expanded."
2053 (if (idlwave-quoted)
2054 (progn (unexpand-abbrev)
2055 nil)
2056 (if (and reserved idlwave-reserved-word-upcase)
2057 (upcase-region last-abbrev-location (point))
2058 (cond
2059 ((equal idlwave-abbrev-change-case 'down)
2060 (downcase-region last-abbrev-location (point)))
2061 (idlwave-abbrev-change-case
2062 (upcase-region last-abbrev-location (point)))))
2063 (if (and idlwave-abbrev-move (> arg 0))
2064 (if (boundp 'post-command-hook)
2065 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2066 (backward-char arg)))
2069 (defun idlwave-in-comment ()
2070 "Return t if point is inside a comment, nil otherwise."
2071 (save-excursion
2072 (let ((here (point)))
2073 (and (idlwave-goto-comment) (> here (point))))))
2075 (defun idlwave-goto-comment ()
2076 "Move to start of comment delimiter on current line.
2077 Moves to end of line if there is no comment delimiter.
2078 Ignores comment delimiters in strings.
2079 Returns point if comment found and nil otherwise."
2080 (let ((eos (point-at-eol))
2081 (data (match-data))
2082 found)
2083 ;; Look for first comment delimiter not in a string
2084 (beginning-of-line)
2085 (setq found (search-forward comment-start eos 'lim))
2086 (while (and found (idlwave-in-quote))
2087 (setq found (search-forward comment-start eos 'lim)))
2088 (store-match-data data)
2089 (and found (not (idlwave-in-quote))
2090 (progn
2091 (backward-char 1)
2092 (point)))))
2094 (defun idlwave-region-active-p ()
2095 "Should we operate on an active region?"
2096 (if (fboundp 'use-region-p)
2097 (use-region-p)
2098 (region-active-p)))
2100 (defun idlwave-show-matching-quote ()
2101 "Insert quote and show matching quote if this is end of a string."
2102 (interactive)
2103 (let ((bq (idlwave-in-quote))
2104 (inq last-command-event))
2105 (if (and bq (not (idlwave-in-comment)))
2106 (let ((delim (char-after bq)))
2107 (insert inq)
2108 (if (eq inq delim)
2109 (save-excursion
2110 (goto-char bq)
2111 (sit-for 1))))
2112 ;; Not the end of a string
2113 (insert inq))))
2115 (defun idlwave-show-begin-check ()
2116 "Ensure that the previous word was a token before `idlwave-show-begin'.
2117 An END token must be preceded by whitespace."
2118 (if (not (idlwave-quoted))
2120 (save-excursion
2121 (backward-word-strictly 1)
2122 (backward-char 1)
2123 (looking-at "[ \t\n\f]"))
2124 (idlwave-show-begin))))
2126 (defun idlwave-show-begin ()
2127 "Find the start of current block and blinks to it for a second.
2128 Also checks if the correct END statement has been used."
2129 ;; All end statements are reserved words
2130 ;; Re-indent end line
2131 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2132 ;;(backward-char 1)
2133 (let* ((pos (point-marker))
2134 (last-abbrev-marker (copy-marker last-abbrev-location))
2135 (eol-pos (point-at-eol))
2136 begin-pos end-pos end end1 )
2137 (if idlwave-reindent-end (idlwave-indent-line))
2138 (setq last-abbrev-location (marker-position last-abbrev-marker))
2139 (when (and (idlwave-check-abbrev 0 t)
2140 idlwave-show-block)
2141 (save-excursion
2142 ;; Move inside current block
2143 (goto-char last-abbrev-marker)
2144 (idlwave-block-jump-out -1 'nomark)
2145 (setq begin-pos (point))
2146 (idlwave-block-jump-out 1 'nomark)
2147 (setq end-pos (point))
2148 (if (> end-pos eol-pos)
2149 (setq end-pos pos))
2150 (goto-char end-pos)
2151 (setq end (buffer-substring
2152 (progn
2153 (skip-chars-backward "a-zA-Z")
2154 (point))
2155 end-pos))
2156 (goto-char begin-pos)
2157 (when (setq end1 (cdr (idlwave-block-master)))
2158 (cond
2159 ((null end1)) ; no-operation
2160 ((string= (downcase end) (downcase end1))
2161 (sit-for 1))
2162 ((string= (downcase end) "end")
2163 ;; A generic end
2164 (if idlwave-expand-generic-end
2165 (save-excursion
2166 (goto-char pos)
2167 (backward-char 3)
2168 (insert (if (string= end "END") (upcase end1) end1))
2169 (delete-char 3)))
2170 (sit-for 1))
2172 (beep)
2173 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2174 end1 end)
2175 (sit-for 1))))))))
2176 ;;(delete-char 1))
2178 (defun idlwave-block-master ()
2179 (let ((case-fold-search t))
2180 (save-excursion
2181 (cond
2182 ((looking-at "pro\\|case\\|switch\\|function\\>")
2183 (assoc (downcase (match-string 0)) idlwave-block-matches))
2184 ((looking-at "begin\\>")
2185 (let ((limit (save-excursion
2186 (idlwave-beginning-of-statement)
2187 (point))))
2188 (cond
2189 ((re-search-backward ":[ \t]*\\=" limit t)
2190 ;; seems to be a case thing
2191 '("begin" . "end"))
2192 ((re-search-backward idlwave-block-match-regexp limit t)
2193 (assoc (downcase (match-string 1))
2194 idlwave-block-matches))
2196 ;; Just a normal block
2197 '("begin" . "end")))))
2198 (t nil)))))
2200 (defun idlwave-close-block ()
2201 "Terminate the current block with the correct END statement."
2202 (interactive)
2203 ;; Start new line if we are not in a new line
2204 (unless (save-excursion
2205 (skip-chars-backward " \t")
2206 (bolp))
2207 (let ((idlwave-show-block nil))
2208 (newline-and-indent)))
2209 (let ((last-abbrev-location (point))) ; for upcasing
2210 (insert "end")
2211 (idlwave-show-begin)))
2213 (defun idlwave-custom-ampersand-surround (&optional is-action)
2214 "Surround &, leaving room for && (which surround as well)."
2215 (let* ((prev-char (char-after (- (point) 2)))
2216 (next-char (char-after (point)))
2217 (amp-left (eq prev-char ?&))
2218 (amp-right (eq next-char ?&))
2219 (len (if amp-left 2 1)))
2220 (unless amp-right ;no need to do it twice, amp-left will catch it.
2221 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2223 (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2224 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2225 (let* ((prev-char (char-after (- (point) 2)))
2226 (next-char (char-after (point)))
2227 (method-invoke (and gtr (eq prev-char ?-)))
2228 (len (if method-invoke 2 1)))
2229 (unless (eq next-char ?=)
2230 ;; Key binding: pad only on left, to save for possible >=/<=
2231 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2233 (defun idlwave-surround (&optional before after length is-action)
2234 "Surround the LENGTH characters before point with blanks.
2235 LENGTH defaults to 1.
2236 Optional arguments BEFORE and AFTER affect the behavior before and
2237 after the characters (see also description of `idlwave-make-space'):
2239 nil do nothing
2240 0 force no spaces
2241 integer > 0 force exactly n spaces
2242 integer < 0 at least |n| spaces
2244 The function does nothing if any of the following conditions is true:
2245 - `idlwave-surround-by-blank' is nil
2246 - the character before point is inside a string or comment"
2247 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2248 (let ((length (or length 1))) ; establish a default for LENGTH
2249 (backward-char length)
2250 (save-restriction
2251 (let ((here (point)))
2252 (skip-chars-backward " \t")
2253 (if (bolp)
2254 ;; avoid clobbering indent
2255 (progn
2256 (move-to-column (idlwave-calculate-indent))
2257 (if (<= (point) here)
2258 (narrow-to-region (point) here))
2259 (goto-char here)))
2260 (idlwave-make-space before))
2261 (skip-chars-forward " \t"))
2262 (forward-char length)
2263 (idlwave-make-space after)
2264 ;; Check to see if the line should auto wrap
2265 (if (and (equal (char-after (1- (point))) ?\ )
2266 (> (current-column) fill-column))
2267 (funcall auto-fill-function)))))
2269 (defun idlwave-make-space (n)
2270 "Make space at point.
2271 The space affected is all the spaces and tabs around point.
2272 If n is non-nil then point is left abs(n) spaces from the beginning of
2273 the contiguous space.
2274 The amount of space at point is determined by N.
2275 If the value of N is:
2276 nil - do nothing.
2277 > 0 - exactly N spaces.
2278 < 0 - a minimum of -N spaces, i.e., do not change if there are
2279 already -N spaces.
2280 0 - no spaces (i.e. remove any existing space)."
2281 (if (integerp n)
2282 (let
2283 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2284 (left (point))
2285 (end-col (progn (skip-chars-forward " \t") (current-column))))
2286 (delete-horizontal-space)
2287 (cond
2288 ((> n 0)
2289 (idlwave-indent-to (+ start-col n))
2290 (goto-char (+ left n)))
2291 ((< n 0)
2292 (idlwave-indent-to end-col (- n))
2293 (goto-char (- left n)))
2294 ;; n = 0, done
2295 ))))
2297 (defun idlwave-newline ()
2298 "Insert a newline and indent the current and previous line."
2299 (interactive)
2301 ;; Handle unterminated single and double quotes
2302 ;; If not in a comment and in a string then insertion of a newline
2303 ;; will mean unbalanced quotes.
2305 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2306 (progn (beep)
2307 (message "Warning: unbalanced quotes?")))
2308 (newline)
2310 ;; The current line is being split, the cursor should be at the
2311 ;; beginning of the new line skipping the leading indentation.
2313 ;; The reason we insert the new line before indenting is that the
2314 ;; indenting could be confused by keywords (e.g. END) on the line
2315 ;; after the split point. This prevents us from just using
2316 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2318 (beginning-of-line 0)
2319 (idlwave-indent-line)
2320 (forward-line)
2321 (idlwave-indent-line))
2324 ;; Use global variable 'comment-column' to set parallel comment
2326 ;; Modeled on lisp.el
2327 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2328 (defun idlwave-comment-hook ()
2329 "Compute indent for the beginning of the IDL comment delimiter."
2330 (if (or (looking-at idlwave-no-change-comment)
2331 (looking-at (or idlwave-begin-line-comment "^;")))
2332 (current-column)
2333 (if (looking-at idlwave-code-comment)
2334 (if (save-excursion (skip-chars-backward " \t") (bolp))
2335 ;; On line by itself, indent as code
2336 (let ((tem (idlwave-calculate-indent)))
2337 (if (listp tem) (car tem) tem))
2338 ;; after code - do not change
2339 (current-column))
2340 (skip-chars-backward " \t")
2341 (max (if (bolp) 0 (1+ (current-column)))
2342 comment-column))))
2344 (defun idlwave-split-line ()
2345 "Continue line by breaking line at point and indent the lines.
2346 For a code line insert continuation marker. If the line is a line comment
2347 then the new line will contain a comment with the same indentation.
2348 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2349 non-nil."
2350 (interactive)
2351 ;; Expand abbreviation, just like normal RET would.
2352 (and abbrev-mode (expand-abbrev))
2353 (let (beg)
2354 (if (not (idlwave-in-comment))
2355 ;; For code line add continuation.
2356 ;; Check if splitting a string.
2357 (progn
2358 (if (setq beg (idlwave-in-quote))
2359 (if idlwave-split-line-string
2360 ;; Split the string.
2361 (progn (insert (setq beg (char-after beg)) " + "
2362 idlwave-continuation-char beg)
2363 (backward-char 1)
2364 (newline-and-indent)
2365 (forward-char 1))
2366 ;; Do not split the string.
2367 (beep)
2368 (message "Warning: continuation inside string!!")
2369 (insert " " idlwave-continuation-char))
2370 ;; Not splitting a string.
2371 (if (not (member (char-before) '(?\ ?\t)))
2372 (insert " "))
2373 (insert idlwave-continuation-char)
2374 (newline-and-indent)))
2375 (indent-new-comment-line))
2376 ;; Indent previous line
2377 (setq beg (- (point-max) (point)))
2378 (forward-line -1)
2379 (idlwave-indent-line)
2380 (goto-char (- (point-max) beg))
2381 ;; Reindent new line
2382 (idlwave-indent-line)))
2384 (defun idlwave-beginning-of-subprogram (&optional nomark)
2385 "Move point to the beginning of the current program unit.
2386 If NOMARK is non-nil, do not push mark."
2387 (interactive)
2388 (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
2390 (defun idlwave-end-of-subprogram (&optional nomark)
2391 "Move point to the start of the next program unit.
2392 If NOMARK is non-nil, do not push mark."
2393 (interactive)
2394 (idlwave-end-of-statement)
2395 (idlwave-find-key idlwave-end-unit-reg 1 nomark))
2397 (defun idlwave-mark-statement ()
2398 "Mark current IDL statement."
2399 (interactive)
2400 (idlwave-end-of-statement)
2401 (let ((end (point)))
2402 (idlwave-beginning-of-statement)
2403 (push-mark end nil t)))
2405 (defun idlwave-mark-block ()
2406 "Mark containing block."
2407 (interactive)
2408 (idlwave-end-of-statement)
2409 (idlwave-backward-up-block -1)
2410 (idlwave-end-of-statement)
2411 (let ((end (point)))
2412 (idlwave-backward-block)
2413 (idlwave-beginning-of-statement)
2414 (push-mark end nil t)))
2417 (defun idlwave-mark-subprogram ()
2418 "Put mark at beginning of program, point at end.
2419 The marks are pushed."
2420 (interactive)
2421 (idlwave-end-of-statement)
2422 (idlwave-beginning-of-subprogram)
2423 (let ((beg (point)))
2424 (idlwave-forward-block)
2425 (push-mark beg nil t))
2426 (exchange-point-and-mark))
2428 (defun idlwave-backward-up-block (&optional arg)
2429 "Move to beginning of enclosing block if prefix ARG >= 0.
2430 If prefix ARG < 0 then move forward to enclosing block end."
2431 (interactive "p")
2432 (idlwave-block-jump-out (- arg) 'nomark))
2434 (defun idlwave-beginning-of-block ()
2435 "Go to the beginning of the current block."
2436 (interactive)
2437 (idlwave-block-jump-out -1 'nomark)
2438 (forward-word-strictly 1))
2440 (defun idlwave-end-of-block ()
2441 "Go to the beginning of the current block."
2442 (interactive)
2443 (idlwave-block-jump-out 1 'nomark)
2444 (backward-word-strictly 1))
2446 (defun idlwave-forward-block (&optional arg)
2447 "Move across next nested block."
2448 (interactive)
2449 (let ((arg (or arg 1)))
2450 (if (idlwave-down-block arg)
2451 (idlwave-block-jump-out arg 'nomark))))
2453 (defun idlwave-backward-block ()
2454 "Move backward across previous nested block."
2455 (interactive)
2456 (if (idlwave-down-block -1)
2457 (idlwave-block-jump-out -1 'nomark)))
2459 (defun idlwave-down-block (&optional arg)
2460 "Go down a block.
2461 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2462 Returns non-nil if successful."
2463 (interactive "p")
2464 (let (status)
2465 (if (< arg 0)
2466 ;; Backward
2467 (let ((eos (save-excursion
2468 (idlwave-block-jump-out -1 'nomark)
2469 (point))))
2470 (if (setq status (idlwave-find-key
2471 idlwave-end-block-reg -1 'nomark eos))
2472 (idlwave-beginning-of-statement)
2473 (message "No nested block before beginning of containing block.")))
2474 ;; Forward
2475 (let ((eos (save-excursion
2476 (idlwave-block-jump-out 1 'nomark)
2477 (point))))
2478 (if (setq status (idlwave-find-key
2479 idlwave-begin-block-reg 1 'nomark eos))
2480 (idlwave-end-of-statement)
2481 (message "No nested block before end of containing block."))))
2482 status))
2484 (defun idlwave-mark-doclib ()
2485 "Put point at beginning of doc library header, mark at end.
2486 The marks are pushed."
2487 (interactive)
2488 (let (beg
2489 (here (point)))
2490 (goto-char (point-max))
2491 (if (re-search-backward idlwave-doclib-start nil t)
2492 (progn
2493 (setq beg (progn (beginning-of-line) (point)))
2494 (if (re-search-forward idlwave-doclib-end nil t)
2495 (progn
2496 (forward-line 1)
2497 (push-mark beg nil t)
2498 (message "Could not find end of doc library header.")))
2499 (message "Could not find doc library header start.")
2500 (goto-char here)))))
2502 (defun idlwave-current-routine-fullname ()
2503 (let ((name (idlwave-current-routine)))
2504 (idlwave-make-full-name (nth 2 name) (car name))))
2506 (defun idlwave-current-routine ()
2507 "Return (NAME TYPE CLASS) of current routine."
2508 (idlwave-routines)
2509 (save-excursion
2510 (idlwave-beginning-of-subprogram 'nomark)
2511 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2512 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2513 'pro 'function))
2514 (class (idlwave-sintern-class (match-string 3)))
2515 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2516 (list name type class)))))
2518 (defvar idlwave-shell-prompt-pattern)
2519 (defun idlwave-beginning-of-statement ()
2520 "Move to beginning of the current statement.
2521 Skips back past statement continuations.
2522 Point is placed at the beginning of the line whether or not this is an
2523 actual statement."
2524 (interactive)
2525 (cond
2526 ((derived-mode-p 'idlwave-shell-mode)
2527 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2528 (goto-char (match-end 0))))
2530 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2531 (idlwave-previous-statement)
2532 (beginning-of-line)))))
2534 (defun idlwave-previous-statement ()
2535 "Move point to beginning of the previous statement.
2536 Returns t if the current line before moving is the beginning of
2537 the first non-comment statement in the file, and nil otherwise."
2538 (interactive)
2539 (let (first-statement)
2540 (if (not (= (forward-line -1) 0))
2541 ;; first line in file
2543 ;; skip blank lines, label lines, include lines and line comments
2544 (while (and
2545 ;; The current statement is the first statement until we
2546 ;; reach another statement.
2547 (setq first-statement
2549 (looking-at idlwave-comment-line-start-skip)
2550 (looking-at "[ \t]*$")
2551 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2552 (looking-at "^@")))
2553 (= (forward-line -1) 0)))
2554 ;; skip continuation lines
2555 (while (and
2556 (save-excursion
2557 (forward-line -1)
2558 (idlwave-is-continuation-line))
2559 (= (forward-line -1) 0)))
2560 first-statement)))
2562 (defun idlwave-end-of-statement ()
2563 "Move point to the end of the current IDL statement.
2564 If not in a statement just moves to end of line. Returns position."
2565 (interactive)
2566 (while (and (idlwave-is-continuation-line)
2567 (= (forward-line 1) 0))
2568 (while (and (idlwave-is-comment-or-empty-line)
2569 (= (forward-line 1) 0))))
2570 (end-of-line)
2571 (point))
2573 (defun idlwave-end-of-statement0 ()
2574 "Move point to the end of the current IDL statement.
2575 If not in a statement just moves to end of line. Returns position."
2576 (interactive)
2577 (while (and (idlwave-is-continuation-line)
2578 (= (forward-line 1) 0)))
2579 (end-of-line)
2580 (point))
2582 (defun idlwave-next-statement ()
2583 "Move point to beginning of the next IDL statement.
2584 Returns t if that statement is the last non-comment IDL statement
2585 in the file, and nil otherwise."
2586 (interactive)
2587 (let (last-statement)
2588 (idlwave-end-of-statement)
2589 ;; skip blank lines, label lines, include lines and line comments
2590 (while (and (= (forward-line 1) 0)
2591 ;; The current statement is the last statement until
2592 ;; we reach a new statement.
2593 (setq last-statement
2595 (looking-at idlwave-comment-line-start-skip)
2596 (looking-at "[ \t]*$")
2597 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2598 (looking-at "^@")))))
2599 last-statement))
2601 (defun idlwave-skip-multi-commands (&optional lim)
2602 "Skip past multiple commands on a line (with `&')."
2603 (let ((save-point (point)))
2604 (when (re-search-forward ".*&" lim t)
2605 (goto-char (match-end 0))
2606 (if (idlwave-quoted)
2607 (goto-char save-point)
2608 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
2609 (point)))
2611 (defun idlwave-skip-label-or-case ()
2612 "Skip label or case statement element.
2613 Returns position after label.
2614 If there is no label point is not moved and nil is returned."
2615 ;; Case expressions and labels are terminated by a colon.
2616 ;; So we find the first colon in the line and make sure
2617 ;; - no `?' is before it (might be a ? b : c)
2618 ;; - it is not in a comment
2619 ;; - not in a string constant
2620 ;; - not in parenthesis (like a[0:3])
2621 ;; - not followed by another ":" in explicit class, ala a->b::c
2622 ;; As many in this mode, this function is heuristic and not an exact
2623 ;; parser.
2624 (let* ((start (point))
2625 (eos (save-excursion (idlwave-end-of-statement) (point)))
2626 (end (idlwave-find-key ":" 1 'nomark eos)))
2627 (if (and end
2628 (= (nth 0 (parse-partial-sexp start end)) 0)
2629 (not (string-match "\\?" (buffer-substring start end)))
2630 (not (string-match "^::" (buffer-substring end eos))))
2631 (progn
2632 (forward-char)
2633 (point))
2634 (goto-char start)
2635 nil)))
2637 (defun idlwave-start-of-substatement (&optional pre)
2638 "Move to start of next IDL substatement after point.
2639 Uses the type of the current IDL statement to determine if the next
2640 statement is on a new line or is a subpart of the current statement.
2641 Returns point at start of substatement modulo whitespace.
2642 If optional argument is non-nil move to beginning of current
2643 substatement."
2644 (let ((orig (point))
2645 (eos (idlwave-end-of-statement))
2646 (ifnest 0)
2647 st nst last)
2648 (idlwave-beginning-of-statement)
2649 (idlwave-skip-label-or-case)
2650 (if (< (point) orig)
2651 (idlwave-skip-multi-commands orig))
2652 (setq last (point))
2653 ;; Continue looking for substatements until we are past orig
2654 (while (and (<= (point) orig) (not (eobp)))
2655 (setq last (point))
2656 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2657 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2658 (cond ((and nst
2659 (idlwave-find-key nst 1 'nomark eos))
2660 (goto-char (match-end 0)))
2661 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2662 (setq ifnest (1- ifnest))
2663 (goto-char (match-end 0)))
2664 (t (setq ifnest 0)
2665 (idlwave-next-statement))))
2666 (if pre (goto-char last))
2667 ;; If a continuation line starts here, move to next line
2668 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2669 (beginning-of-line 2))
2670 (point)))
2672 (defun idlwave-statement-type ()
2673 "Return the type of the current IDL statement.
2674 Uses `idlwave-statement-match' to return a cons of (type . point) with
2675 point the ending position where the type was determined. Type is the
2676 association from `idlwave-statement-match', i.e. the cons cell from the
2677 list not just the type symbol. Returns nil if not an identifiable
2678 statement."
2679 (save-excursion
2680 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2681 ;; and possibly comments
2682 (while (looking-at "[ \t]*\\$")
2683 (forward-line 1))
2684 (skip-chars-forward " \t")
2685 (let ((st idlwave-statement-match)
2686 (case-fold-search t))
2687 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2688 (setq st (cdr st))))
2689 (if st
2690 (append st (match-end 0))))))
2692 (defun idlwave-expand-equal (&optional before after is-action)
2693 "Pad `=' with spaces.
2694 Two cases: Assignment statement, and keyword assignment.
2695 Which case is determined using `idlwave-start-of-substatement' and
2696 `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
2697 and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
2698 is treated just like assignment statements. When nil, spaces are
2699 removed for keyword assignment. Any other value keeps the current space
2700 around the `='. Limits in for loops are treated as keyword assignment.
2702 Starting with IDL 6.0, a number of op= assignments are available.
2703 Since ambiguities of the form:
2705 r and= b
2706 rand= b
2708 can occur, alphanumeric operator assignment will never be pre-padded,
2709 only post-padded. You must use a space before these to disambiguate
2710 \(not just for padding, but for proper parsing by IDL too!). Other
2711 operators, such as ##=, ^=, etc., will be pre-padded.
2713 IS-ACTION is ignored.
2715 See `idlwave-surround'."
2716 (if idlwave-surround-by-blank
2717 (let
2718 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
2719 (an-ops
2720 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2721 (len 1))
2723 (save-excursion
2724 (let ((case-fold-search t))
2725 (backward-char)
2726 (if (or
2727 (re-search-backward non-an-ops nil t)
2728 ;; Why doesn't ##? work for both?
2729 (re-search-backward "\\(#\\)\\=" nil t))
2730 (setq len (1+ (length (match-string 1))))
2731 (when (re-search-backward an-ops nil t)
2732 ;(setq begin nil) ; won't modify begin
2733 (setq len (1+ (length (match-string 1))))))))
2735 (if (eq t idlwave-pad-keyword)
2736 ;; Everything gets padded equally
2737 (idlwave-surround before after len)
2738 ;; Treating keywords/for variables specially...
2739 (let ((st (save-excursion ; To catch "for" variables
2740 (idlwave-start-of-substatement t)
2741 (idlwave-statement-type)))
2742 (what (save-excursion ; To catch keywords
2743 (skip-chars-backward "= \t")
2744 (nth 2 (idlwave-where)))))
2745 (cond ((or (memq what '(function-keyword procedure-keyword))
2746 (memq (caar st) '(for pdef)))
2747 (cond
2748 ((null idlwave-pad-keyword)
2749 (idlwave-surround 0 0)
2750 ) ; remove space
2751 (t))) ; leave any spaces alone
2752 (t (idlwave-surround before after len))))))))
2755 (defun idlwave-indent-and-action (&optional arg)
2756 "Call `idlwave-indent-line' and do expand actions.
2757 With prefix ARG non-nil, indent the entire sub-statement."
2758 (interactive "p")
2759 (save-excursion
2760 (if (and idlwave-expand-generic-end
2761 (re-search-backward "\\<\\(end\\)\\s-*\\="
2762 (max 0 (- (point) 10)) t)
2763 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2764 (progn (goto-char (match-end 1))
2765 ;;Expand the END abbreviation, just as RET or Space would have.
2766 (if abbrev-mode (expand-abbrev)
2767 (idlwave-show-begin)))))
2768 (when (and (not arg) current-prefix-arg)
2769 (setq arg current-prefix-arg)
2770 (setq current-prefix-arg nil))
2771 (if arg
2772 (idlwave-indent-statement)
2773 (idlwave-indent-line t)))
2775 (defun idlwave-indent-line (&optional expand)
2776 "Indent current IDL line as code or as a comment.
2777 The actions in `idlwave-indent-action-table' are performed.
2778 If the optional argument EXPAND is non-nil then the actions in
2779 `idlwave-indent-expand-table' are performed."
2780 (interactive)
2781 ;; Move point out of left margin.
2782 (if (save-excursion
2783 (skip-chars-backward " \t")
2784 (bolp))
2785 (skip-chars-forward " \t"))
2786 (let ((mloc (point-marker)))
2787 (save-excursion
2788 (beginning-of-line)
2789 (if (looking-at idlwave-comment-line-start-skip)
2790 ;; Indentation for a line comment
2791 (progn
2792 (skip-chars-forward " \t")
2793 (idlwave-indent-left-margin (idlwave-comment-hook)))
2795 ;; Code Line
2797 ;; Before indenting, run action routines.
2799 (if (and expand idlwave-do-actions)
2800 (mapc 'idlwave-do-action idlwave-indent-expand-table))
2802 (if idlwave-do-actions
2803 (mapc 'idlwave-do-action idlwave-indent-action-table))
2805 ;; No longer expand abbrevs on the line. The user can do this
2806 ;; manually using expand-region-abbrevs.
2808 ;; Indent for code line
2810 (beginning-of-line)
2811 (if (or
2812 ;; a label line
2813 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2814 ;; a batch command
2815 (looking-at "^[ \t]*@"))
2816 ;; leave flush left
2818 ;; indent the line
2819 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2820 ;; Adjust parallel comment
2821 (end-of-line)
2822 (if (idlwave-in-comment)
2823 ;; Emacs 21 is too smart with fill-column on comment indent
2824 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2825 (1- (frame-width))
2826 fill-column)))
2827 (indent-for-comment)))))
2828 (goto-char mloc)
2829 ;; Get rid of marker
2830 (set-marker mloc nil)))
2832 (defun idlwave-do-action (action)
2833 "Perform an action repeatedly on a line.
2834 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2835 either a function name to be called with `funcall' or a list to be
2836 evaluated with `eval'. The action performed by FUNC should leave
2837 point after the match for REG - otherwise an infinite loop may be
2838 entered. FUNC is always passed a final argument of `is-action', so it
2839 can discriminate between being run as an action, or a key binding."
2840 (let ((action-key (car action))
2841 (action-routine (cdr action)))
2842 (beginning-of-line)
2843 (while (idlwave-look-at action-key)
2844 (if (listp action-routine)
2845 (eval (append action-routine '('is-action)))
2846 (funcall action-routine 'is-action)))))
2848 (defun idlwave-indent-to (col &optional min)
2849 "Indent from point with spaces until column COL.
2850 Inserts space before markers at point."
2851 (if (not min) (setq min 0))
2852 (insert-before-markers
2853 (make-string (max min (- col (current-column))) ?\ )))
2855 (defun idlwave-indent-left-margin (col)
2856 "Indent the current line to column COL.
2857 Indents such that first non-whitespace character is at column COL
2858 Inserts spaces before markers at point."
2859 (save-excursion
2860 (beginning-of-line)
2861 (delete-horizontal-space)
2862 (idlwave-indent-to col)))
2864 (defun idlwave-indent-subprogram ()
2865 "Indent program unit which contains point."
2866 (interactive)
2867 (save-excursion
2868 (idlwave-end-of-statement)
2869 (idlwave-beginning-of-subprogram)
2870 (let ((beg (point)))
2871 (idlwave-forward-block)
2872 (message "Indenting subprogram...")
2873 (indent-region beg (point) nil))
2874 (message "Indenting subprogram...done.")))
2876 (defun idlwave-indent-statement ()
2877 "Indent current statement, including all continuation lines."
2878 (interactive)
2879 (save-excursion
2880 (idlwave-beginning-of-statement)
2881 (let ((beg (point)))
2882 (idlwave-end-of-statement)
2883 (indent-region beg (point) nil))))
2885 (defun idlwave-calculate-indent ()
2886 "Return appropriate indentation for current line as IDL code."
2887 (save-excursion
2888 (beginning-of-line)
2889 (cond
2890 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2891 ;; function
2892 ((idlwave-look-at idlwave-begin-unit-reg)
2894 ;; Check for continuation line
2895 ((save-excursion
2896 (and (= (forward-line -1) 0)
2897 (idlwave-is-continuation-line)))
2898 (idlwave-calculate-cont-indent))
2899 ;; calculate indent based on previous and current statements
2900 (t (let* (beg-prev-pos
2901 (the-indent
2902 ;; calculate indent based on previous statement
2903 (save-excursion
2904 (cond
2905 ;; Beginning of file
2906 ((prog1
2907 (idlwave-previous-statement)
2908 (setq beg-prev-pos (point)))
2910 ;; Main block
2911 ((idlwave-look-at idlwave-begin-unit-reg t)
2912 (+ (idlwave-current-statement-indent)
2913 idlwave-main-block-indent))
2914 ;; Begin block
2915 ((idlwave-look-at idlwave-begin-block-reg t)
2916 (+ (idlwave-min-current-statement-indent)
2917 idlwave-block-indent))
2918 ;; End Block
2919 ((idlwave-look-at idlwave-end-block-reg t)
2920 (progn
2921 ;; Match to the *beginning* of the block opener
2922 (goto-char beg-prev-pos)
2923 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2924 (idlwave-min-current-statement-indent)))
2925 ;; idlwave-end-offset
2926 ;; idlwave-block-indent))
2928 ;; Default to current indent
2929 ((idlwave-current-statement-indent))))))
2930 ;; adjust the indentation based on the current statement
2931 (cond
2932 ;; End block
2933 ((idlwave-look-at idlwave-end-block-reg)
2934 (+ the-indent idlwave-end-offset))
2935 (the-indent)))))))
2938 ;; Parentheses indent
2941 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2942 "Calculate the continuation indent inside a paren group.
2943 Returns a cons-cell with (open . indent), where open is the
2944 location of the open paren."
2945 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2946 ;; Found an innermost open paren.
2947 (when open
2948 (goto-char open)
2949 ;; Line up with next word unless this is a closing paren.
2950 (cons open
2951 (cond
2952 ;; Plain Kernighan-style nested indent
2953 (idlwave-indent-parens-nested
2954 (+ idlwave-continuation-indent (idlwave-current-indent)))
2956 ;; This is a closed paren - line up under open paren.
2957 (close-exp
2958 (current-column))
2960 ;; Empty (or just comment) follows -- revert to basic indent
2961 ((progn
2962 ;; Skip paren
2963 (forward-char 1)
2964 (looking-at "[ \t$]*\\(;.*\\)?$"))
2965 nil)
2967 ;; Line up with first word after any blank space
2968 ((progn
2969 (skip-chars-forward " \t")
2970 (current-column))))))))
2972 (defun idlwave-calculate-cont-indent ()
2973 "Calculates the IDL continuation indent column from the previous statement.
2974 Note that here previous statement usually means the beginning of the
2975 current statement if this statement is a continuation of the previous
2976 line. Various special types of continuations, including assignments,
2977 routine definitions, and parenthetical groupings, are treated separately."
2978 (save-excursion
2979 (let* ((case-fold-search t)
2980 (end-reg (progn (beginning-of-line) (point)))
2981 (beg-last-statement (save-excursion (idlwave-previous-statement)
2982 (point)))
2983 (beg-reg (progn (idlwave-start-of-substatement 'pre)
2984 (if (eq (line-beginning-position) end-reg)
2985 (goto-char beg-last-statement)
2986 (point))))
2987 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
2988 idlwave-continuation-indent))
2989 fancy-nonparen-indent fancy-paren-indent)
2990 (cond
2991 ;; Align then with its matching if, etc.
2992 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
2993 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
2994 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
2995 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
2996 "[ \t]*until")
2997 ("\\<case\\>" . "[ \t]*of")))
2998 match cont-re)
2999 (goto-char end-reg)
3000 (and
3001 (setq cont-re
3002 (catch 'exit
3003 (while (setq match (car matchers))
3004 (if (looking-at (cdr match))
3005 (throw 'exit (car match)))
3006 (setq matchers (cdr matchers)))))
3007 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3008 (if (looking-at "end") ;; that one's special
3009 (- (idlwave-current-indent)
3010 (+ idlwave-block-indent idlwave-end-offset))
3011 (idlwave-current-indent)))
3013 ;; Indent in from the previous line for continuing statements
3014 ((let ((matchers '("\\<then\\>"
3015 "\\<do\\>"
3016 "\\<repeat\\>"
3017 "\\<else\\>"))
3018 match)
3019 (catch 'exit
3020 (goto-char end-reg)
3021 (if (/= (forward-line -1) 0)
3022 (throw 'exit nil))
3023 (while (setq match (car matchers))
3024 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3025 "\\(;.*\\)?$"))
3026 (throw 'exit t))
3027 (setq matchers (cdr matchers)))))
3028 (+ idlwave-continuation-indent (idlwave-current-indent)))
3030 ;; Parenthetical indent, either traditional or Kernighan style
3031 ((setq fancy-paren-indent
3032 (let* ((end-reg end-reg)
3033 (close-exp (progn
3034 (goto-char end-reg)
3035 (skip-chars-forward " \t")
3036 (looking-at "\\s)")))
3037 indent-cons)
3038 (catch 'loop
3039 (while (setq indent-cons (idlwave-calculate-paren-indent
3040 beg-reg end-reg close-exp))
3041 ;; First permitted containing paren
3042 (if (or
3043 idlwave-indent-to-open-paren
3044 idlwave-indent-parens-nested
3045 (null (cdr indent-cons))
3046 (< (- (cdr indent-cons) basic-indent)
3047 idlwave-max-extra-continuation-indent))
3048 (throw 'loop (cdr indent-cons)))
3049 (setq end-reg (car indent-cons))))))
3050 fancy-paren-indent)
3052 ;; A continued assignment, or procedure call/definition
3053 ((and
3054 (> idlwave-max-extra-continuation-indent 0)
3055 (setq fancy-nonparen-indent
3056 (progn
3057 (goto-char beg-reg)
3058 (while (idlwave-look-at "&")) ; skip continued statements
3059 (cond
3060 ;; A continued Procedure call or definition
3061 ((progn
3062 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3063 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3064 (goto-char (match-end 0))
3065 ;; Comment only, or blank line with "$"? Basic indent.
3066 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3068 (current-column)))
3070 ;; Continued assignment (with =):
3071 ((catch 'assign ;
3072 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3073 (goto-char (match-end 0))
3074 (if (null (idlwave-what-function beg-reg))
3075 (throw 'assign t))))
3076 (unless (or
3077 (idlwave-in-quote)
3078 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3079 (save-excursion
3080 (goto-char beg-last-statement)
3081 (eq (caar (idlwave-statement-type)) 'for)))
3082 (current-column))))))
3083 (< (- fancy-nonparen-indent basic-indent)
3084 idlwave-max-extra-continuation-indent))
3085 (if fancy-paren-indent ;calculated but disallowed paren indent
3086 (+ fancy-nonparen-indent idlwave-continuation-indent)
3087 fancy-nonparen-indent))
3089 ;; Basic indent, by default
3090 (t basic-indent)))))
3094 (defun idlwave-find-key (key-re &optional dir nomark limit)
3095 "Move to next match of the regular expression KEY-RE.
3096 Matches inside comments or string constants will be ignored.
3097 If DIR is negative, the search will be backwards.
3098 At a successful match, the mark is pushed unless NOMARK is non-nil.
3099 Searches are limited to LIMIT.
3100 Searches are case-insensitive and use a special syntax table which
3101 treats `$' and `_' as word characters.
3102 Return value is the beginning of the match or (in case of failure) nil."
3103 (setq dir (or dir 0))
3104 (let ((case-fold-search t)
3105 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3106 found)
3107 (idlwave-with-special-syntax
3108 (save-excursion
3109 (catch 'exit
3110 (while (funcall search-func key-re limit t)
3111 (if (not (idlwave-quoted))
3112 (throw 'exit (setq found (match-beginning 0)))
3113 (if (or (and (> dir 0) (eobp))
3114 (and (< dir 0) (bobp)))
3115 (throw 'exit nil)))))))
3116 (if found
3117 (progn
3118 (if (not nomark) (push-mark))
3119 (goto-char found)
3120 found)
3121 nil)))
3123 (defun idlwave-block-jump-out (&optional dir nomark)
3124 "When optional argument DIR is non-negative, move forward to end of
3125 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3126 regular expressions. When DIR is negative, move backwards to block beginning.
3127 Recursively calls itself to skip over nested blocks. DIR defaults to
3128 forward. Calls `push-mark' unless the optional argument NOMARK is
3129 non-nil. Movement is limited by the start of program units because of
3130 possibility of unbalanced blocks."
3131 (interactive "P")
3132 (or dir (setq dir 0))
3133 (let* ((here (point))
3134 (case-fold-search t)
3135 (limit (if (>= dir 0) (point-max) (point-min)))
3136 (block-limit (if (>= dir 0)
3137 idlwave-begin-block-reg
3138 idlwave-end-block-reg))
3139 found
3140 (block-reg (concat idlwave-begin-block-reg "\\|"
3141 idlwave-end-block-reg))
3142 (unit-limit (or (save-excursion
3143 (if (< dir 0)
3144 (idlwave-find-key
3145 idlwave-begin-unit-reg dir t limit)
3146 (end-of-line)
3147 (idlwave-find-key
3148 idlwave-end-unit-reg dir t limit)))
3149 limit)))
3150 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3151 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3152 (while (and found (looking-at block-limit))
3153 (if (>= dir 0) (forward-word-strictly 1))
3154 (idlwave-block-jump-out dir t)
3155 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3156 (if (not nomark) (push-mark here))
3157 (if (not found) (goto-char unit-limit)
3158 (if (>= dir 0) (forward-word-strictly 1)))))
3160 (defun idlwave-min-current-statement-indent (&optional end-reg)
3161 "The minimum indent in the current statement."
3162 (idlwave-beginning-of-statement)
3163 (if (not (idlwave-is-continuation-line))
3164 (idlwave-current-indent)
3165 (let ((min (idlwave-current-indent)) comm-or-empty)
3166 (while (and (= (forward-line 1) 0)
3167 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3168 (idlwave-is-continuation-line))
3169 (or (null end-reg) (< (point) end-reg)))
3170 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3171 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
3173 (min min (idlwave-current-indent))))))
3175 (defun idlwave-current-statement-indent (&optional last-line)
3176 "Return indentation of the current statement.
3177 If in a statement, moves to beginning of statement before finding indent."
3178 (if last-line
3179 (idlwave-end-of-statement)
3180 (idlwave-beginning-of-statement))
3181 (idlwave-current-indent))
3183 (defun idlwave-current-indent ()
3184 "Return the column of the indentation of the current line.
3185 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3186 (save-excursion
3187 (beginning-of-line)
3188 (skip-chars-forward " \t")
3189 ;; if we are at the end of blank line return 0
3190 (cond ((eolp) 0)
3191 ((current-column)))))
3193 (defun idlwave-is-continuation-line ()
3194 "Test if current line is continuation line.
3195 Blank or comment-only lines following regular continuation lines (with
3196 `$') count as continuations too."
3197 (let (p)
3198 (save-excursion
3200 (idlwave-look-at "\\<\\$")
3201 (catch 'loop
3202 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3203 (eq (forward-line -1) 0))
3204 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
3206 (defun idlwave-is-comment-line ()
3207 "Test if the current line is a comment line."
3208 (save-excursion
3209 (beginning-of-line 1)
3210 (looking-at "[ \t]*;")))
3212 (defun idlwave-is-comment-or-empty-line ()
3213 "Test if the current line is a comment line."
3214 (save-excursion
3215 (beginning-of-line 1)
3216 (looking-at "[ \t]*[;\n]")))
3218 (defun idlwave-look-at (regexp &optional cont beg)
3219 "Search current line from current point for REGEXP.
3220 If optional argument CONT is non-nil, searches to the end of
3221 the current statement.
3222 If optional arg BEG is non-nil, search starts from the beginning of the
3223 current statement.
3224 Ignores matches that end in a comment or inside a string expression.
3225 Returns point if successful, nil otherwise.
3226 This function produces unexpected results if REGEXP contains quotes or
3227 a comment delimiter. The search is case insensitive.
3228 If successful leaves point after the match, otherwise, does not move point."
3229 (let ((here (point))
3230 (case-fold-search t)
3231 (eos (save-excursion
3232 (if cont (idlwave-end-of-statement) (end-of-line))
3233 (point)))
3234 found)
3235 (idlwave-with-special-syntax
3236 (if beg (idlwave-beginning-of-statement))
3237 (while (and (setq found (re-search-forward regexp eos t))
3238 (idlwave-quoted))))
3239 (if (not found) (goto-char here))
3240 found))
3242 (defun idlwave-fill-paragraph (&optional nohang)
3243 "Fill paragraphs in comments.
3244 A paragraph is made up of all contiguous lines having the same comment
3245 leader (the leading whitespace before the comment delimiter and the
3246 comment delimiter). In addition, paragraphs are separated by blank
3247 line comments. The indentation is given by the hanging indent of the
3248 first line, otherwise by the minimum indentation of the lines after
3249 the first line. The indentation of the first line does not change.
3250 Does not effect code lines. Does not fill comments on the same line
3251 with code. The hanging indent is given by the end of the first match
3252 matching `idlwave-hang-indent-regexp' on the paragraph's first line.
3253 If the optional argument NOHANG is non-nil then the hanging indent is
3254 ignored."
3255 (interactive "P")
3256 ;; check if this is a line comment
3257 (if (save-excursion
3258 (beginning-of-line)
3259 (skip-chars-forward " \t")
3260 (looking-at comment-start))
3261 (let
3262 ((indent 999)
3263 pre here diff fill-prefix-reg bcl first-indent
3264 hang start end)
3265 ;; Change tabs to spaces in the surrounding paragraph.
3266 ;; The surrounding paragraph will be the largest containing block of
3267 ;; contiguous line comments. Thus, we may be changing tabs in
3268 ;; a much larger area than is needed, but this is the easiest
3269 ;; brute force way to do it.
3271 ;; This has the undesirable side effect of replacing the tabs
3272 ;; permanently without the user's request or knowledge.
3273 (save-excursion
3274 (backward-paragraph)
3275 (setq start (point)))
3276 (save-excursion
3277 (forward-paragraph)
3278 (setq end (point)))
3279 (untabify start end)
3281 (setq here (point))
3282 (beginning-of-line)
3283 (setq bcl (point))
3284 (re-search-forward (concat "^[ \t]*" comment-start "+")
3285 (point-at-eol) t)
3286 ;; Get the comment leader on the line and its length
3287 (setq pre (current-column))
3288 ;; the comment leader is the indentation plus exactly the
3289 ;; number of consecutive ";".
3290 (setq fill-prefix-reg
3291 (concat
3292 (setq fill-prefix
3293 (regexp-quote (buffer-substring (point-at-bol) (point))))
3294 "[^;]"))
3296 ;; Mark the beginning and end of the paragraph
3297 (goto-char bcl)
3298 (while (and (looking-at fill-prefix-reg)
3299 (not (looking-at paragraph-separate))
3300 (not (bobp)))
3301 (forward-line -1))
3302 ;; Move to first line of paragraph
3303 (if (/= (point) bcl)
3304 (forward-line 1))
3305 (setq start (point))
3306 (goto-char bcl)
3307 (while (and (looking-at fill-prefix-reg)
3308 (not (looking-at paragraph-separate))
3309 (not (eobp)))
3310 (forward-line 1))
3311 (beginning-of-line)
3312 (if (or (not (looking-at fill-prefix-reg))
3313 (looking-at paragraph-separate))
3314 (forward-line -1))
3315 (end-of-line)
3316 ;; if at end of buffer add a newline (need this because
3317 ;; fill-region needs END to be at the beginning of line after
3318 ;; the paragraph or it will add a line).
3319 (if (eobp)
3320 (progn (insert ?\n) (backward-char 1)))
3321 ;; Set END to the beginning of line after the paragraph
3322 ;; END is calculated as distance from end of buffer
3323 (setq end (- (point-max) (point) 1))
3325 ;; Calculate the indentation for the paragraph.
3327 ;; In the following while statements, after one iteration
3328 ;; point will be at the beginning of a line in which case
3329 ;; the while will not be executed for the
3330 ;; the first paragraph line and thus will not affect the
3331 ;; indentation.
3333 ;; First check to see if indentation is based on hanging indent.
3334 (if (and (not nohang) idlwave-hanging-indent
3335 (setq hang
3336 (save-excursion
3337 (goto-char start)
3338 (idlwave-calc-hanging-indent))))
3339 ;; Adjust lines of paragraph by inserting spaces so that
3340 ;; each line's indent is at least as great as the hanging
3341 ;; indent. This is needed for fill-paragraph to work with
3342 ;; a fill-prefix.
3343 (progn
3344 (setq indent hang)
3345 (beginning-of-line)
3346 (while (> (point) start)
3347 (re-search-forward comment-start-skip (point-at-eol) t)
3348 (if (> (setq diff (- indent (current-column))) 0)
3349 (progn
3350 (if (>= here (point))
3351 ;; adjust the original location for the
3352 ;; inserted text.
3353 (setq here (+ here diff)))
3354 (insert (make-string diff ?\ ))))
3355 (forward-line -1))
3358 ;; No hang. Instead find minimum indentation of paragraph
3359 ;; after first line.
3360 ;; For the following while statement, since START is at the
3361 ;; beginning of line and END is at the end of line
3362 ;; point is greater than START at least once (which would
3363 ;; be the case for a single line paragraph).
3364 (while (> (point) start)
3365 (beginning-of-line)
3366 (setq indent
3367 (min indent
3368 (progn
3369 (re-search-forward comment-start-skip (point-at-eol) t)
3370 (current-column))))
3371 (forward-line -1)))
3372 (setq fill-prefix (concat fill-prefix
3373 (make-string (- indent pre)
3374 ?\ )))
3375 ;; first-line indent
3376 (setq first-indent
3377 (max
3378 (progn
3379 (re-search-forward comment-start-skip (point-at-eol) t)
3380 (current-column))
3381 indent))
3383 ;; try to keep point at its original place
3384 (goto-char here)
3386 ;; In place of the more modern fill-region-as-paragraph, a hack
3387 ;; to keep whitespace untouched on the first line within the
3388 ;; indent length and to preserve any indent on the first line
3389 ;; (first indent).
3390 (save-excursion
3391 (setq diff
3392 (buffer-substring start (+ start first-indent -1)))
3393 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3394 (fill-region-as-paragraph
3395 start
3396 (- (point-max) end)
3397 (current-justification)
3398 nil)
3399 (delete-region start (+ start first-indent -1))
3400 (goto-char start)
3401 (insert diff))
3402 ;; When we want the point at the beginning of the comment
3403 ;; body fill-region will put it at the beginning of the line.
3404 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3405 (setq fill-prefix nil))))
3407 (defun idlwave-calc-hanging-indent ()
3408 "Calculate the position of the hanging indent for the comment paragraph.
3409 The hanging indent position is given by the first match with the
3410 `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3411 non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
3412 on the line.
3413 If not found returns nil."
3414 (if idlwave-use-last-hang-indent
3415 (save-excursion
3416 (end-of-line)
3417 (if (re-search-backward idlwave-hang-indent-regexp (point-at-bol) t)
3418 (+ (current-column) (length idlwave-hang-indent-regexp))))
3419 (save-excursion
3420 (beginning-of-line)
3421 (if (re-search-forward idlwave-hang-indent-regexp (point-at-eol) t)
3422 (current-column)))))
3424 (defun idlwave-auto-fill ()
3425 "Called to break lines in auto fill mode.
3426 Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3427 non-nil. Places a continuation character at the end of the line if
3428 not in a comment. Splits strings with IDL concatenation operator `+'
3429 if `idlwave-auto-fill-split-string' is non-nil."
3430 (if (<= (current-column) fill-column)
3431 nil ; do not to fill
3432 (if (or (not idlwave-fill-comment-line-only)
3433 (save-excursion
3434 ;; Check for comment line
3435 (beginning-of-line)
3436 (looking-at idlwave-comment-line-start-skip)))
3437 (let (beg)
3438 (idlwave-indent-line)
3439 ;; Prevent actions do-auto-fill which calls indent-line-function.
3440 (let (idlwave-do-actions
3441 (paragraph-separate ".")
3442 (fill-nobreak-predicate
3443 (if (and (idlwave-in-quote)
3444 idlwave-auto-fill-split-string)
3445 (lambda () ;; We'll need 5 spaces for " ' + $"
3446 (<= (- fill-column (current-column)) 5)
3447 ))))
3448 (do-auto-fill))
3449 (save-excursion
3450 (end-of-line 0)
3451 ;; Indent the split line
3452 (idlwave-indent-line))
3453 (if (save-excursion
3454 (beginning-of-line)
3455 (looking-at idlwave-comment-line-start-skip))
3456 ;; A continued line comment
3457 ;; We treat continued line comments as part of a comment
3458 ;; paragraph. So we check for a hanging indent.
3459 (if idlwave-hanging-indent
3460 (let ((here (- (point-max) (point)))
3461 (indent
3462 (save-excursion
3463 (forward-line -1)
3464 (idlwave-calc-hanging-indent))))
3465 (when indent
3466 ;; Remove whitespace between comment delimiter and
3467 ;; text, insert spaces for appropriate indentation.
3468 (beginning-of-line)
3469 (re-search-forward comment-start-skip (point-at-eol) t)
3470 (delete-horizontal-space)
3471 (idlwave-indent-to indent)
3472 (goto-char (- (point-max) here)))))
3473 ;; Split code or comment?
3474 (if (save-excursion
3475 (end-of-line 0)
3476 (idlwave-in-comment))
3477 ;; Splitting a non-full-line comment.
3478 ;; Insert the comment delimiter from split line
3479 (progn
3480 (save-excursion
3481 (beginning-of-line)
3482 (skip-chars-forward " \t")
3483 ;; Insert blank to keep off beginning of line
3484 (insert " "
3485 (save-excursion
3486 (forward-line -1)
3487 (buffer-substring (idlwave-goto-comment)
3488 (progn
3489 (skip-chars-forward "; ")
3490 (point))))))
3491 (idlwave-indent-line))
3492 ;; Split code line - add continuation character
3493 (save-excursion
3494 (end-of-line 0)
3495 ;; Check to see if we split a string
3496 (if (and (setq beg (idlwave-in-quote))
3497 idlwave-auto-fill-split-string)
3498 ;; Split the string and concatenate.
3499 ;; The first extra space is for the space
3500 ;; the line was split. That space was removed.
3501 (insert " " (char-after beg) " +"))
3502 (insert " $"))
3503 (if beg
3504 (if idlwave-auto-fill-split-string
3505 ;; Make the second part of continued string
3506 (save-excursion
3507 (beginning-of-line)
3508 (skip-chars-forward " \t")
3509 (insert (char-after beg)))
3510 ;; Warning
3511 (beep)
3512 (message "Warning: continuation inside a string.")))
3513 ;; Although do-auto-fill (via indent-new-comment-line) calls
3514 ;; idlwave-indent-line for the new line, re-indent again
3515 ;; because of the addition of the continuation character.
3516 (idlwave-indent-line))
3517 )))))
3519 (defun idlwave-auto-fill-mode (arg)
3520 "Toggle auto-fill mode for IDL mode.
3521 With arg, turn auto-fill mode on if arg is positive.
3522 In auto-fill mode, inserting a space at a column beyond `fill-column'
3523 automatically breaks the line at a previous space."
3524 (interactive "P")
3525 (prog1 (set idlwave-fill-function
3526 (if (if (null arg)
3527 (not (symbol-value idlwave-fill-function))
3528 (> (prefix-numeric-value arg) 0))
3529 'idlwave-auto-fill
3530 nil))
3531 ;; update mode-line
3532 (set-buffer-modified-p (buffer-modified-p))))
3534 ;(defun idlwave-fill-routine-call ()
3535 ; "Fill a routine definition or statement, indenting appropriately."
3536 ; (let ((where (idlwave-where)))))
3539 (defun idlwave-doc-header (&optional nomark)
3540 "Insert a documentation header at the beginning of the unit.
3541 Inserts the value of the variable `idlwave-file-header'. Sets mark
3542 before moving to do insertion unless the optional prefix argument
3543 NOMARK is non-nil."
3544 (interactive "P")
3545 (or nomark (push-mark))
3546 ;; make sure we catch the current line if it begins the unit
3547 (if idlwave-header-to-beginning-of-file
3548 (goto-char (point-min))
3549 (end-of-line)
3550 (idlwave-beginning-of-subprogram)
3551 (beginning-of-line)
3552 ;; skip function or procedure line
3553 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3554 (progn
3555 (idlwave-end-of-statement)
3556 (if (> (forward-line 1) 0) (insert "\n")))))
3557 (let ((pos (point)))
3558 (if idlwave-file-header
3559 (cond ((car idlwave-file-header)
3560 (insert-file-contents (car idlwave-file-header)))
3561 ((stringp (car (cdr idlwave-file-header)))
3562 (insert (car (cdr idlwave-file-header))))))
3563 (goto-char pos)))
3565 (defun idlwave-default-insert-timestamp ()
3566 "Default timestamp insertion function."
3567 (insert (current-time-string))
3568 (insert ", " (user-full-name))
3569 (if (boundp 'user-mail-address)
3570 (insert " <" user-mail-address ">")
3571 (insert " <" (user-login-name) "@" (system-name) ">"))
3572 ;; Remove extra spaces from line
3573 (idlwave-fill-paragraph)
3574 ;; Insert a blank line comment to separate from the date entry -
3575 ;; will keep the entry from flowing onto date line if re-filled.
3576 (insert "\n;\n;\t\t"))
3578 (defun idlwave-doc-modification ()
3579 "Insert a brief modification log at the beginning of the current program.
3580 Looks for an occurrence of the value of user variable
3581 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
3582 name and places the point for the user to add a log. Before moving, saves
3583 location on mark ring so that the user can return to previous point."
3584 (interactive)
3585 (push-mark)
3586 (let* (beg end)
3587 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3588 (progn
3589 (goto-char (point-min))
3590 (re-search-forward idlwave-doclib-start nil t)))
3591 (setq beg (match-beginning 0))
3592 (re-search-forward idlwave-doclib-end nil t)
3593 (setq end (match-end 0)))
3594 (progn
3595 (goto-char beg)
3596 (if (re-search-forward
3597 (concat idlwave-doc-modifications-keyword ":")
3598 end t)
3599 (end-of-line)
3600 (goto-char end)
3601 (end-of-line -1)
3602 (insert "\n" comment-start "\n")
3603 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3604 (insert "\n;\n;\t")
3605 (run-hooks 'idlwave-timestamp-hook))
3606 (error "No valid DOCLIB header"))))
3609 ;; CJC 3/16/93
3610 ;; Interface to expand-region-abbrevs which did not work when the
3611 ;; abbrev hook associated with an abbrev moves point backwards
3612 ;; after abbrev expansion, e.g., as with the abbrev '.n'.
3613 ;; The original would enter an infinite loop in attempting to expand
3614 ;; .n (it would continually expand and unexpand the abbrev without expanding
3615 ;; because the point would keep going back to the beginning of the
3616 ;; abbrev instead of to the end of the abbrev). We now keep the
3617 ;; abbrev hook from moving backwards.
3619 (defun idlwave-expand-region-abbrevs (start end)
3620 "Expand each abbrev occurrence in the region.
3621 Calling from a program, arguments are START END."
3622 (interactive "r")
3623 (save-excursion
3624 (goto-char (min start end))
3625 (let ((idlwave-show-block nil) ;Do not blink
3626 (idlwave-abbrev-move nil)) ;Do not move
3627 (expand-region-abbrevs start end 'noquery))))
3629 (defun idlwave-quoted ()
3630 "Return t if point is in a comment or quoted string.
3631 Returns nil otherwise."
3632 (or (idlwave-in-comment) (idlwave-in-quote)))
3634 (defun idlwave-in-quote ()
3635 "Return location of the opening quote
3636 if point is in a IDL string constant, nil otherwise.
3637 Ignores comment delimiters on the current line.
3638 Properly handles nested quotation marks and octal
3639 constants - a double quote followed by an octal digit."
3640 ;; Treat an octal inside an apostrophe to be a normal string. Treat a
3641 ;; double quote followed by an octal digit to be an octal constant
3642 ;; rather than a string. Therefore, there is no terminating double
3643 ;; quote.
3644 (save-excursion
3645 ;; Because single and double quotes can quote each other we must
3646 ;; search for the string start from the beginning of line.
3647 (let* ((start (point))
3648 (eol (point-at-eol))
3649 (bq (progn (beginning-of-line) (point)))
3650 (endq (point))
3651 (data (match-data))
3652 delim
3653 found)
3654 (while (< endq start)
3655 ;; Find string start
3656 ;; Don't find an octal constant beginning with a double quote
3657 (if (re-search-forward "[\"']" eol 'lim)
3658 ;; Find the string end.
3659 ;; In IDL, two consecutive delimiters after the start of a
3660 ;; string act as an
3661 ;; escape for the delimiter in the string.
3662 ;; Two consecutive delimiters alone (i.e., not after the
3663 ;; start of a string) is the null string.
3664 (progn
3665 ;; Move to position after quote
3666 (goto-char (1+ (match-beginning 0)))
3667 (setq bq (1- (point)))
3668 ;; Get the string delimiter
3669 (setq delim (char-to-string (preceding-char)))
3670 ;; Check for null string
3671 (if (looking-at delim)
3672 (progn (setq endq (point)) (forward-char 1))
3673 ;; Look for next unpaired delimiter
3674 (setq found (search-forward delim eol 'lim))
3675 (while (looking-at delim)
3676 (forward-char 1)
3677 (setq found (search-forward delim eol 'lim)))
3678 (setq endq (if found (1- (point)) (point)))
3680 (progn (setq bq (point)) (setq endq (point)))))
3681 (store-match-data data)
3682 ;; return string beginning position or nil
3683 (if (> start bq) bq))))
3685 (defun idlwave-is-pointer-dereference (&optional limit)
3686 "Determine if the character after point is a pointer dereference *."
3687 (and
3688 (eq (char-after) ?\*)
3689 (not (idlwave-in-quote))
3690 (save-excursion
3691 (forward-char)
3692 (re-search-backward (concat "\\(" idlwave-idl-keywords
3693 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
3696 ;; Statement templates
3698 ;; Replace these with a general template function, something like
3699 ;; expand.el (I think there was also something with a name similar to
3700 ;; dmacro.el)
3702 (defun idlwave-template (s1 s2 &optional prompt noindent)
3703 "Build a template with optional prompt expression.
3705 Opens a line if point is not followed by a newline modulo intervening
3706 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3707 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3708 adjusted according to `idlwave-abbrev-change-case'. If optional
3709 argument PROMPT is a string then it is displayed as a message in the
3710 minibuffer. The PROMPT serves as a reminder to the user of an
3711 expression to enter.
3713 The lines containing S1 and S2 are reindented using `indent-region'
3714 unless the optional second argument NOINDENT is non-nil."
3715 (if (derived-mode-p 'idlwave-shell-mode)
3716 ;; This is a gross hack to avoid template abbrev expansion
3717 ;; in the shell. FIXME: This is a dirty hack.
3718 (if (and (eq this-command 'self-insert-command)
3719 (equal last-abbrev-location (point)))
3720 (insert last-abbrev-text)
3721 (error "No templates in idlwave-shell"))
3722 (cond ((eq idlwave-abbrev-change-case 'down)
3723 (setq s1 (downcase s1) s2 (downcase s2)))
3724 (idlwave-abbrev-change-case
3725 (setq s1 (upcase s1) s2 (upcase s2))))
3726 (let ((beg (point-at-bol))
3727 end)
3728 (if (not (looking-at "\\s-*\n"))
3729 (open-line 1))
3730 (insert s1)
3731 (save-excursion
3732 (insert s2)
3733 (setq end (point)))
3734 (if (not noindent)
3735 (indent-region beg end nil))
3736 (if (stringp prompt)
3737 (message "%s" prompt)))))
3739 (defun idlwave-rw-case (string)
3740 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3741 (if idlwave-reserved-word-upcase
3742 (upcase string)
3743 string))
3745 (defun idlwave-elif ()
3746 "Build skeleton IDL if-else block."
3747 (interactive)
3748 (idlwave-template
3749 (idlwave-rw-case "if")
3750 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3751 "Condition expression"))
3753 (defun idlwave-case ()
3754 "Build skeleton IDL case statement."
3755 (interactive)
3756 (idlwave-template
3757 (idlwave-rw-case "case")
3758 (idlwave-rw-case " of\n\nendcase")
3759 "Selector expression"))
3761 (defun idlwave-switch ()
3762 "Build skeleton IDL switch statement."
3763 (interactive)
3764 (idlwave-template
3765 (idlwave-rw-case "switch")
3766 (idlwave-rw-case " of\n\nendswitch")
3767 "Selector expression"))
3769 (defun idlwave-for ()
3770 "Build skeleton IDL loop statement."
3771 (interactive)
3772 (idlwave-template
3773 (idlwave-rw-case "for")
3774 (idlwave-rw-case " do begin\n\nendfor")
3775 "Loop expression"))
3777 (defun idlwave-if ()
3778 "Build skeleton IDL if statement."
3779 (interactive)
3780 (idlwave-template
3781 (idlwave-rw-case "if")
3782 (idlwave-rw-case " then begin\n\nendif")
3783 "Scalar logical expression"))
3785 (defun idlwave-procedure ()
3786 (interactive)
3787 (idlwave-template
3788 (idlwave-rw-case "pro")
3789 (idlwave-rw-case "\n\nreturn\nend")
3790 "Procedure name"))
3792 (defun idlwave-function ()
3793 (interactive)
3794 (idlwave-template
3795 (idlwave-rw-case "function")
3796 (idlwave-rw-case "\n\nreturn\nend")
3797 "Function name"))
3799 (defun idlwave-repeat ()
3800 (interactive)
3801 (idlwave-template
3802 (idlwave-rw-case "repeat begin\n\nendrep until")
3803 (idlwave-rw-case "")
3804 "Exit condition"))
3806 (defun idlwave-while ()
3807 (interactive)
3808 (idlwave-template
3809 (idlwave-rw-case "while")
3810 (idlwave-rw-case " do begin\n\nendwhile")
3811 "Entry condition"))
3813 (defun idlwave-split-string (string &optional pattern)
3814 "Return a list of substrings of STRING which are separated by PATTERN.
3815 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3816 (or pattern
3817 (setq pattern "[ \f\t\n\r\v]+"))
3818 (let (parts (start 0))
3819 (while (string-match pattern string start)
3820 (setq parts (cons (substring string start (match-beginning 0)) parts)
3821 start (match-end 0)))
3822 (nreverse (cons (substring string start) parts))))
3824 (defun idlwave-replace-string (string replace_string replace_with)
3825 (let* ((start 0)
3826 (last (length string))
3827 (ret_string "")
3828 end)
3829 (while (setq end (string-match replace_string string start))
3830 (setq ret_string
3831 (concat ret_string (substring string start end) replace_with))
3832 (setq start (match-end 0)))
3833 (setq ret_string (concat ret_string (substring string start last)))))
3835 (defun idlwave-get-buffer-visiting (file)
3836 ;; Return the buffer currently visiting FILE
3837 (cond
3838 ((boundp 'find-file-compare-truenames) ; XEmacs
3839 (let ((find-file-compare-truenames t))
3840 (get-file-buffer file)))
3841 ((fboundp 'find-buffer-visiting) ; Emacs
3842 (find-buffer-visiting file))
3843 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3845 (defvar idlwave-outlawed-buffers nil
3846 "List of buffers pulled up by IDLWAVE for special reasons.
3847 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3849 (defun idlwave-find-file-noselect (file &optional why)
3850 ;; Return a buffer visiting file.
3851 (or (idlwave-get-buffer-visiting file)
3852 (let ((buf (find-file-noselect file)))
3853 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3854 buf)))
3856 (defun idlwave-kill-autoloaded-buffers ()
3857 "Kill buffers created automatically by IDLWAVE.
3858 Function prompts for a letter to identify the buffers to kill.
3859 Possible letters are:
3861 f Buffers created by the command \\[idlwave-find-module] or mouse
3862 clicks in the routine info window.
3863 s Buffers created by the IDLWAVE Shell to display where execution
3864 stopped or an error was found.
3865 a Both of the above.
3867 Buffers containing unsaved changes require confirmation before they are killed."
3868 (interactive)
3869 (if (null idlwave-outlawed-buffers)
3870 (error "No IDLWAVE-created buffers available")
3871 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3872 (idlwave-count-outlawed-buffers 'find)
3873 (idlwave-count-outlawed-buffers 'shell)))
3874 (let ((c (read-char)))
3875 (cond
3876 ((member c '(?f ?\C-f))
3877 (idlwave-do-kill-autoloaded-buffers 'find))
3878 ((member c '(?s ?\C-s))
3879 (idlwave-do-kill-autoloaded-buffers 'shell))
3880 ((member c '(?a ?\C-a))
3881 (idlwave-do-kill-autoloaded-buffers t))
3882 (t (error "Abort"))))))
3884 (defun idlwave-count-outlawed-buffers (tag)
3885 "How many outlawed buffers have tag TAG?"
3886 (length (delq nil
3887 (mapcar
3888 (lambda (x) (eq (cdr x) tag))
3889 idlwave-outlawed-buffers))))
3891 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3892 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3893 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3894 (cnt 0)
3895 entry)
3896 (while (setq entry (pop list))
3897 (if (buffer-live-p (car entry))
3898 (and (or (memq t reasons)
3899 (memq (cdr entry) reasons))
3900 (kill-buffer (car entry))
3901 (incf cnt)
3902 (setq idlwave-outlawed-buffers
3903 (delq entry idlwave-outlawed-buffers)))
3904 (setq idlwave-outlawed-buffers
3905 (delq entry idlwave-outlawed-buffers))))
3906 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3908 (defun idlwave-revoke-license-to-kill ()
3909 "Remove BUFFER from the buffers which may be killed.
3910 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3911 Intended for `after-save-hook'."
3912 (let* ((buf (current-buffer))
3913 (entry (assq buf idlwave-outlawed-buffers)))
3914 ;; Revoke license
3915 (if entry
3916 (setq idlwave-outlawed-buffers
3917 (delq entry idlwave-outlawed-buffers)))
3918 ;; Remove this function from the hook.
3919 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3921 (defvar idlwave-path-alist)
3922 (defun idlwave-locate-lib-file (file)
3923 ;; Find FILE on the scanned lib path and return a buffer visiting it
3924 (let* ((dirs idlwave-path-alist)
3925 dir efile)
3926 (catch 'exit
3927 (while (setq dir (car (pop dirs)))
3928 (if (file-regular-p
3929 (setq efile (expand-file-name file dir)))
3930 (throw 'exit efile))))))
3932 (defun idlwave-expand-lib-file-name (file)
3933 ;; Find FILE on the scanned lib path and return a buffer visiting it
3934 ;; This is for, e.g., finding source with no user catalog
3935 (cond
3936 ((null file) nil)
3937 ((file-name-absolute-p file) file)
3938 (t (idlwave-locate-lib-file file))))
3940 (defun idlwave-make-tags ()
3941 "Create the IDL tags file IDLTAGS in the current directory from
3942 the list of directories specified in the minibuffer. Directories may be
3943 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3944 specified top directories are searched if the directory name is prefixed
3945 by @. Specify @ directories with care, it may take a long, long time if
3946 you specify /."
3947 (interactive)
3948 (let (directory directories cmd append status numdirs dir getsubdirs
3949 buffer save_buffer files numfiles item errbuf)
3952 ;; Read list of directories
3953 (setq directory (read-string "Tag Directories: " "."))
3954 (setq directories (idlwave-split-string directory "[ \t]+"))
3956 ;; Set etags command, vars
3957 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3958 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3959 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3960 (setq append " ")
3961 (setq status 0)
3963 ;; For each directory
3964 (setq numdirs 0)
3965 (setq dir (nth numdirs directories))
3966 (while (and dir)
3968 ;; Find the subdirectories
3969 (if (string-match "^[@]\\(.+\\)$" dir)
3970 (setq getsubdirs t) (setq getsubdirs nil))
3971 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3972 (setq dir (expand-file-name dir))
3973 (if (file-directory-p dir)
3974 (progn
3975 (if (and getsubdirs)
3976 (progn
3977 (setq buffer (get-buffer-create "*idltags*"))
3978 (call-process "sh" nil buffer nil "-c"
3979 (concat "find " dir " -type d -print"))
3980 (setq save_buffer (current-buffer))
3981 (set-buffer buffer)
3982 (setq files (idlwave-split-string
3983 (idlwave-replace-string
3984 (buffer-substring 1 (point-max))
3985 "\n" "/*.pro ")
3986 "[ \t]+"))
3987 (set-buffer save_buffer)
3988 (kill-buffer buffer))
3989 (setq files (list (concat dir "/*.pro"))))
3991 ;; For each subdirectory
3992 (setq numfiles 0)
3993 (setq item (nth numfiles files))
3994 (while (and item)
3996 ;; Call etags
3997 (if (not (string-match "^[ \\t]*$" item))
3998 (progn
3999 (message "%s" (concat "Tagging " item "..."))
4000 (setq errbuf (get-buffer-create "*idltags-error*"))
4001 (setq status (+ status
4002 (if (eq 0 (call-process
4003 "sh" nil errbuf nil "-c"
4004 (concat cmd append item)))
4006 1)))
4008 ;; Append additional tags
4009 (setq append " --append ")
4010 (setq numfiles (1+ numfiles))
4011 (setq item (nth numfiles files)))
4012 (progn
4013 (setq numfiles (1+ numfiles))
4014 (setq item (nth numfiles files))
4017 (setq numdirs (1+ numdirs))
4018 (setq dir (nth numdirs directories)))
4019 (progn
4020 (setq numdirs (1+ numdirs))
4021 (setq dir (nth numdirs directories)))))
4023 (setq errbuf (get-buffer-create "*idltags-error*"))
4024 (if (= status 0)
4025 (kill-buffer errbuf))
4026 (message "")
4029 (defun idlwave-toggle-comment-region (beg end &optional n)
4030 "Comment the lines in the region if the first non-blank line is
4031 commented, and conversely, uncomment region. If optional prefix arg
4032 N is non-nil, then for N positive, add N comment delimiters or for N
4033 negative, remove N comment delimiters.
4034 Uses `comment-region' which does not place comment delimiters on
4035 blank lines."
4036 (interactive "r\nP")
4037 (if n
4038 (comment-region beg end (prefix-numeric-value n))
4039 (save-excursion
4040 (goto-char beg)
4041 (beginning-of-line)
4042 ;; skip blank lines
4043 (skip-chars-forward " \t\n")
4044 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
4045 (if (fboundp 'uncomment-region)
4046 (uncomment-region beg end)
4047 (comment-region beg end
4048 (- (length (buffer-substring
4049 (match-beginning 1)
4050 (match-end 1))))))
4051 (comment-region beg end)))))
4054 ;; ----------------------------------------------------------------------------
4055 ;; ----------------------------------------------------------------------------
4056 ;; ----------------------------------------------------------------------------
4057 ;; ----------------------------------------------------------------------------
4059 ;; Completion and Routine Info
4062 ;; String "intern" functions
4064 ;; For the completion and routine info function, we want to normalize
4065 ;; the case of procedure names etc. We do this by "interning" these
4066 ;; string is a hand-crafted way. Hashes are used to map the downcase
4067 ;; version of the strings to the cased versions. Most *-sint-*
4068 ;; variables consist of *two* hashes, a buffer+shell, followed by a
4069 ;; system hash. The former is re-scanned, and the latter takes case
4070 ;; precedence.
4072 ;; Since these cased versions are really lisp objects, we can use `eq'
4073 ;; to search, which is a large performance boost. All new strings
4074 ;; need to be "sinterned". We do this as early as possible after
4075 ;; getting these strings from completion or buffer substrings. So
4076 ;; most of the code can simply assume to deal with "sinterned"
4077 ;; strings. The only exception is that the functions which scan whole
4078 ;; buffers for routine information do not intern the grabbed strings.
4079 ;; This is only done afterwards. Therefore in these functions it is
4080 ;; *not* safe to assume the strings can be compared with `eq' and be
4081 ;; fed into the routine assq functions.
4083 ;; Here we define the hashing functions.
4085 ;; The variables which hold the hashes.
4086 (defvar idlwave-sint-routines '(nil))
4087 (defvar idlwave-sint-keywords '(nil))
4088 (defvar idlwave-sint-methods '(nil))
4089 (defvar idlwave-sint-classes '(nil))
4090 (defvar idlwave-sint-dirs '(nil))
4091 (defvar idlwave-sint-libnames '(nil))
4093 (defun idlwave-reset-sintern (&optional what)
4094 "Reset all sintern hashes."
4095 ;; Make sure the hash functions are accessible.
4096 (unless (and (fboundp 'gethash)
4097 (fboundp 'puthash))
4098 (require 'cl)
4099 (or (fboundp 'puthash)
4100 (defalias 'puthash 'cl-puthash)))
4101 (let ((entries '((idlwave-sint-routines 1000 10)
4102 (idlwave-sint-keywords 1000 10)
4103 (idlwave-sint-methods 100 10)
4104 (idlwave-sint-classes 10 10))))
4106 ;; Make sure these are lists
4107 (loop for entry in entries
4108 for var = (car entry)
4109 do (if (not (consp (symbol-value var))) (set var (list nil))))
4111 ;; Reset the system & library hash
4112 (when (or (eq what t) (eq what 'syslib)
4113 (null (cdr idlwave-sint-routines)))
4114 (loop for entry in entries
4115 for var = (car entry) for size = (nth 1 entry)
4116 do (setcdr (symbol-value var)
4117 (make-hash-table ':size size ':test 'equal)))
4118 (setq idlwave-sint-dirs nil
4119 idlwave-sint-libnames nil))
4121 ;; Reset the buffer & shell hash
4122 (when (or (eq what t) (eq what 'bufsh)
4123 (null (car idlwave-sint-routines)))
4124 (loop for entry in entries
4125 for var = (car entry) for size = (nth 1 entry)
4126 do (setcar (symbol-value var)
4127 (make-hash-table ':size size ':test 'equal))))))
4129 (defun idlwave-sintern-routine-or-method (name &optional class set)
4130 (if class
4131 (idlwave-sintern-method name set)
4132 (idlwave-sintern-routine name set)))
4134 (defun idlwave-sintern (stype &rest args)
4135 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4137 ;;(defmacro idlwave-sintern (type var)
4138 ;; `(cond ((not (stringp name)) name)
4139 ;; ((gethash (downcase name) (cdr ,var)))
4140 ;; ((gethash (downcase name) (car ,var)))
4141 ;; (set (idlwave-sintern-set name ,type ,var set))
4142 ;; (name)))
4144 (defun idlwave-sintern-routine (name &optional set)
4145 (cond ((not (stringp name)) name)
4146 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4147 ((gethash (downcase name) (car idlwave-sint-routines)))
4148 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4149 (name)))
4150 (defun idlwave-sintern-keyword (name &optional set)
4151 (cond ((not (stringp name)) name)
4152 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4153 ((gethash (downcase name) (car idlwave-sint-keywords)))
4154 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4155 (name)))
4156 (defun idlwave-sintern-method (name &optional set)
4157 (cond ((not (stringp name)) name)
4158 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4159 ((gethash (downcase name) (car idlwave-sint-methods)))
4160 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4161 (name)))
4162 (defun idlwave-sintern-class (name &optional set)
4163 (cond ((not (stringp name)) name)
4164 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4165 ((gethash (downcase name) (car idlwave-sint-classes)))
4166 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4167 (name)))
4169 (defun idlwave-sintern-dir (dir &optional set)
4170 (car (or (member dir idlwave-sint-dirs)
4171 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4172 (defun idlwave-sintern-libname (name &optional set)
4173 (car (or (member name idlwave-sint-libnames)
4174 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
4176 (defun idlwave-sintern-set (name type tables set)
4177 (let* ((func (or (cdr (assq type idlwave-completion-case))
4178 'identity))
4179 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4180 (table (if (eq set 'sys) (cdr tables) (car tables))))
4181 (puthash (downcase name) iname table)
4182 iname))
4184 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
4185 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4186 (mapc (lambda(x)
4187 (setcar x (idlwave-sintern-keyword (car x) set)))
4188 (cdr kwd-list))
4189 kwd-list)
4191 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4192 "Sintern all strings in the rinfo LIST.
4193 With optional parameter SET: also set new patterns. Probably this
4194 will always have to be t. If DEFAULT-DIR is passed, it is used as
4195 the base of the directory."
4196 (let (entry name type class kwds res source call new)
4197 (while list
4198 (setq entry (car list)
4199 list (cdr list)
4200 name (car entry)
4201 type (nth 1 entry)
4202 class (nth 2 entry)
4203 source (nth 3 entry)
4204 call (nth 4 entry)
4205 kwds (nthcdr 5 entry))
4207 ;; The class and name
4208 (if class
4209 (progn
4210 (if (symbolp class) (setq class (symbol-name class)))
4211 (setq class (idlwave-sintern-class class set))
4212 (setq name (idlwave-sintern-method name set)))
4213 (setq name (idlwave-sintern-routine name set)))
4215 ;; The source
4216 (let ((source-type (car source))
4217 (source-file (nth 1 source))
4218 (source-dir (if default-dir
4219 (file-name-as-directory default-dir)
4220 (nth 2 source)))
4221 (source-lib (nth 3 source)))
4222 (if (stringp source-dir)
4223 (setq source-dir (idlwave-sintern-dir source-dir set)))
4224 (if (stringp source-lib)
4225 (setq source-lib (idlwave-sintern-libname source-lib set)))
4226 (setq source (list source-type source-file source-dir source-lib)))
4228 ;; The keywords
4229 (setq kwds (mapcar (lambda (x)
4230 (idlwave-sintern-keyword-list x set))
4231 kwds))
4233 ;; Build a canonicalized list
4234 (setq new (nconc (list name type class source call) kwds)
4235 res (cons new res)))
4236 (nreverse res)))
4238 ;; Creating new sintern tables
4240 (defun idlwave-new-sintern-type (tag)
4241 "Define a variable and a function to sintern the new type TAG.
4242 This defines the function `idlwave-sintern-TAG' and the variable
4243 `idlwave-sint-TAGs'."
4244 (let* ((name (symbol-name tag))
4245 (names (concat name "s"))
4246 (var (intern (concat "idlwave-sint-" names)))
4247 (func (intern (concat "idlwave-sintern-" name))))
4248 (set var nil) ; initial value of the association list
4249 (fset func ; set the function
4250 `(lambda (name &optional set)
4251 (cond ((not (stringp name)) name)
4252 ((cdr (assoc (downcase name) ,var)))
4253 (set
4254 (setq ,var (cons (cons (downcase name) name) ,var))
4255 name)
4256 (name))))))
4258 (defun idlwave-reset-sintern-type (tag)
4259 "Reset the sintern variable associated with TAG."
4260 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4262 ;;---------------------------------------------------------------------------
4265 ;; The variables which hold the information
4266 (defvar idlwave-system-routines nil
4267 "Holds the routine-info obtained by scanning buffers.")
4268 (defvar idlwave-buffer-routines nil
4269 "Holds the routine-info obtained by scanning buffers.")
4270 (defvar idlwave-compiled-routines nil
4271 "Holds the routine-info obtained by asking the shell.")
4272 (defvar idlwave-unresolved-routines nil
4273 "Holds the unresolved routine-info obtained by asking the shell.")
4274 (defvar idlwave-user-catalog-routines nil
4275 "Holds the procedure routine-info from the user scan.")
4276 (defvar idlwave-library-catalog-routines nil
4277 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4278 (defvar idlwave-library-catalog-libname nil
4279 "Name of library catalog loaded from .idlwave_catalog files.")
4280 (defvar idlwave-path-alist nil
4281 "Alist with !PATH directories and zero or more flags if the dir has
4282 been scanned in a user catalog ('user) or discovered in a library
4283 catalog \('lib).")
4284 (defvar idlwave-true-path-alist nil
4285 "Like `idlwave-path-alist', but with true filenames.")
4286 (defvar idlwave-routines nil
4287 "Holds the combined procedure/function/method routine-info.")
4288 (defvar idlwave-class-alist nil
4289 "Holds the class names known to IDLWAVE.")
4290 (defvar idlwave-class-history nil
4291 "The history of classes selected with the minibuffer.")
4292 (defvar idlwave-force-class-query nil)
4293 (defvar idlwave-before-completion-wconf nil
4294 "The window configuration just before the completion buffer was displayed.")
4295 (defvar idlwave-last-system-routine-info-cons-cell nil
4296 "The last cons cell in the system routine info.")
4299 ;; The code to get routine info from different sources.
4301 (defvar idlwave-system-routines)
4302 (defvar idlwave-catalog-process nil
4303 "The background process currently updating the catalog.")
4305 (defun idlwave-routines ()
4306 "Provide a list of IDL routines.
4307 This routine loads the builtin routines on the first call.
4308 Later it only returns the value of the variable."
4309 (if (and idlwave-catalog-process
4310 (processp idlwave-catalog-process))
4311 (progn
4312 (cond
4313 ((equal (process-status idlwave-catalog-process) 'exit)
4314 (message "updating........")
4315 (setq idlwave-catalog-process nil)
4316 (idlwave-update-routine-info '(4)))
4317 ((equal (process-status idlwave-catalog-process) 'run)
4318 ;; Keep it running...
4321 ;; Something is wrong, get rid of the process
4322 (message "Problem with catalog process") (beep)
4323 (condition-case nil
4324 (kill-process idlwave-catalog-process)
4325 (error nil))
4326 (setq idlwave-catalog-process nil)))))
4327 (or idlwave-routines
4328 (progn
4329 (idlwave-update-routine-info)
4330 ;; return the current value
4331 idlwave-routines)))
4333 (defvar idlwave-update-rinfo-hook nil
4334 "List of functions which should run after a global rinfo update.
4335 Does not run after automatic updates of buffer or the shell.")
4337 (defun idlwave-rescan-catalog-directories ()
4338 "Rescan the previously selected directories. For batch processing."
4339 (idlwave-update-routine-info '(16)))
4341 (defun idlwave-rescan-asynchronously ()
4342 "Dispatch another Emacs instance to update the idlwave catalog.
4343 After the process finishes normally, the first access to routine info
4344 will re-read the catalog."
4345 (interactive)
4346 (if (processp idlwave-catalog-process)
4347 (if (eq (process-status idlwave-catalog-process) 'run)
4348 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4349 (progn
4350 (condition-case nil
4351 (kill-process idlwave-catalog-process)
4352 (error nil))
4353 (error "Process killed, no new process started"))
4354 (error "Quit"))
4355 (condition-case nil
4356 (kill-process idlwave-catalog-process)
4357 (error nil))))
4358 (if (or (not idlwave-user-catalog-file)
4359 (not (stringp idlwave-user-catalog-file))
4360 (not (file-regular-p idlwave-user-catalog-file)))
4361 (error "No catalog has been produced yet"))
4362 (let* ((emacs (concat invocation-directory invocation-name))
4363 (args (list "-batch"
4364 "-l" (expand-file-name "~/.emacs")
4365 "-l" "idlwave"
4366 "-f" "idlwave-rescan-catalog-directories"))
4367 (process (apply 'start-process "idlcat"
4368 nil emacs args)))
4369 (setq idlwave-catalog-process process)
4370 (set-process-sentinel
4371 process
4372 (lambda (pro why)
4373 (when (string-match "finished" why)
4374 (setq idlwave-routines nil
4375 idlwave-system-routines nil
4376 idlwave-catalog-process nil)
4377 (or (idlwave-start-load-rinfo-timer)
4378 (idlwave-update-routine-info '(4))))))
4379 (message "Background job started to update catalog file")))
4382 ;; Format for all routine info user catalog, library catalogs, etc.:
4384 ;; ("ROUTINE" type class
4385 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4386 ;; (buffer pro_file dir) | (compiled pro_file dir)
4387 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4388 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4390 ;; DIR will be supplied dynamically while loading library catalogs,
4391 ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4392 ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4393 ;; be nil, as can LINK1, etc., if no HTML help is available.
4396 (defvar idlwave-load-rinfo-idle-timer)
4397 (defvar idlwave-shell-path-query)
4399 (defun idlwave-update-routine-info (&optional arg no-concatenate)
4400 "Update the internal routine-info lists.
4401 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4402 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4403 about individual routines.
4405 The information can come from 4 sources:
4406 1. IDL programs in the current editing session
4407 2. Compiled modules in an IDL shell running as Emacs subprocess
4408 3. A list which covers the IDL system routines.
4409 4. A list which covers the prescanned library files.
4411 Scans all IDLWAVE-mode buffers of the current editing session (see
4412 `idlwave-scan-all-buffers-for-routine-info').
4413 When an IDL shell is running, this command also queries the IDL program
4414 for currently compiled routines.
4416 With prefix ARG, also reload the system and library lists.
4417 With two prefix ARG's, also rescans the chosen user catalog tree.
4418 With three prefix args, dispatch asynchronous process to do the update.
4420 If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4421 lists, but instead wait for the shell query to complete and
4422 asynchronously finish updating routine info. This is set
4423 automatically when called interactively. When you need routine
4424 information updated immediately, leave NO-CONCATENATE nil."
4425 (interactive "P\np")
4426 ;; Stop any idle processing
4427 (if (or (and (fboundp 'itimerp)
4428 (itimerp idlwave-load-rinfo-idle-timer))
4429 (and (fboundp 'timerp)
4430 (timerp idlwave-load-rinfo-idle-timer)))
4431 (cancel-timer idlwave-load-rinfo-idle-timer))
4432 (cond
4433 ((equal arg '(64))
4434 ;; Start a background process which updates the catalog.
4435 (idlwave-rescan-asynchronously))
4436 ((equal arg '(16))
4437 ;; Update the user catalog now, and wait for them.
4438 (idlwave-create-user-catalog-file t))
4440 (let* ((load (or arg
4441 idlwave-buffer-case-takes-precedence
4442 (null idlwave-routines)))
4443 ;; The override-idle means, even if the idle timer has done some
4444 ;; preparing work, load and renormalize everything anyway.
4445 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4447 (setq idlwave-buffer-routines nil
4448 idlwave-compiled-routines nil
4449 idlwave-unresolved-routines nil)
4450 ;; Reset the appropriate hashes
4451 (if (get 'idlwave-reset-sintern 'done-by-idle)
4452 ;; reset was already done in idle time, so skip this step now once
4453 (put 'idlwave-reset-sintern 'done-by-idle nil)
4454 (idlwave-reset-sintern (cond (load t)
4455 ((null idlwave-system-routines) t)
4456 (t 'bufsh))))
4458 (if idlwave-buffer-case-takes-precedence
4459 ;; We can safely scan the buffer stuff first
4460 (progn
4461 (idlwave-update-buffer-routine-info)
4462 (and load (idlwave-load-all-rinfo override-idle)))
4463 ;; We first do the system info, and then the buffers
4464 (and load (idlwave-load-all-rinfo override-idle))
4465 (idlwave-update-buffer-routine-info))
4467 ;; Let's see if there is a shell
4468 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4469 (idlwave-shell-is-running)))
4470 (ask-shell (and shell-is-running
4471 idlwave-query-shell-for-routine-info)))
4473 ;; Load the library catalogs again, first re-scanning the path
4474 (when arg
4475 (if shell-is-running
4476 (idlwave-shell-send-command idlwave-shell-path-query
4477 '(progn
4478 (idlwave-shell-get-path-info)
4479 (idlwave-scan-library-catalogs))
4480 'hide)
4481 (idlwave-scan-library-catalogs)))
4483 (if (or (not ask-shell)
4484 (not no-concatenate))
4485 ;; 1. If we are not going to ask the shell, we need to do the
4486 ;; concatenation now.
4487 ;; 2. When this function is called non-interactively, it
4488 ;; means that someone needs routine info *now*. The
4489 ;; shell update causes the concatenation to be
4490 ;; *delayed*, so not in time for the current command.
4491 ;; Therefore, we do a concatenation now, even though
4492 ;; the shell might do it again.
4493 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
4495 (when ask-shell
4496 ;; Ask the shell about the routines it knows of.
4497 (message "Querying the shell")
4498 (idlwave-shell-update-routine-info nil t)))))))
4501 (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
4502 (defvar idlwave-load-rinfo-idle-timer nil)
4503 (defun idlwave-start-load-rinfo-timer ()
4504 (if (or (and (fboundp 'itimerp)
4505 (itimerp idlwave-load-rinfo-idle-timer))
4506 (and (fboundp 'timerp)
4507 (timerp idlwave-load-rinfo-idle-timer)))
4508 (cancel-timer idlwave-load-rinfo-idle-timer))
4509 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
4510 (setq idlwave-load-rinfo-idle-timer nil)
4511 (if (and idlwave-init-rinfo-when-idle-after
4512 (numberp idlwave-init-rinfo-when-idle-after)
4513 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4514 (not idlwave-routines))
4515 (condition-case nil
4516 (progn
4517 (setq idlwave-load-rinfo-idle-timer
4518 (run-with-idle-timer
4519 idlwave-init-rinfo-when-idle-after
4520 nil 'idlwave-load-rinfo-next-step)))
4521 (error nil))))
4523 ;;------ XML Help routine info system
4524 (defun idlwave-load-system-routine-info ()
4525 ;; Load the system routine info from the cached routine info file,
4526 ;; which, if necessary, will be re-created from the XML file on
4527 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4528 ;; file distributed with older IDLWAVE versions (<6.0)
4529 (unless (and (load idlwave-xml-system-rinfo-converted-file
4530 'noerror 'nomessage)
4531 (idlwave-xml-system-routine-info-up-to-date))
4532 ;; See if we can create it from XML source
4533 (condition-case nil
4534 (idlwave-convert-xml-system-routine-info)
4535 (error
4536 (unless (load idlwave-xml-system-rinfo-converted-file
4537 'noerror 'nomessage)
4538 (if idlwave-system-routines
4539 (message
4540 "Failed to load converted routine info, using old conversion.")
4541 (message
4542 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4543 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4544 (message
4545 "Could not locate any system routine information."))))))))
4547 (defun idlwave-xml-system-routine-info-up-to-date()
4548 (let* ((dir (file-name-as-directory
4549 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4550 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4551 (file-newer-than-file-p ;converted file is newer than catalog
4552 idlwave-xml-system-rinfo-converted-file
4553 catalog-file)))
4555 (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4556 (defvar idlwave-system-variables-alist nil
4557 "Alist of system variables and the associated structure tags.
4558 Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4559 (defvar idlwave-executive-commands-alist nil
4560 "Alist of system variables and their help files.")
4561 (defvar idlwave-help-special-topic-words nil)
4564 (defun idlwave-shorten-syntax (syntax name &optional class)
4565 ;; From a list of syntax statements, shorten with %s and group with "or"
4566 (let ((case-fold-search t))
4567 (mapconcat
4568 (lambda (x)
4569 (while (string-match name x)
4570 (setq x (replace-match "%s" t t x)))
4571 (if class
4572 (while (string-match class x)
4573 (setq x (replace-match "%s" t t x))))
4575 (nreverse syntax)
4576 " or ")))
4578 (defun idlwave-xml-create-class-method-lists (xml-entry)
4579 ;; Create a class list entry from the xml parsed list., returning a
4580 ;; cons of form (class-entry method-entries).
4581 (let* ((nameblock (nth 1 xml-entry))
4582 (class (cdr (assq 'name nameblock)))
4583 (link (cdr (assq 'link nameblock)))
4584 (params (cddr xml-entry))
4585 (case-fold-search t)
4586 class-entry
4587 method methods-entry extra-kwds
4588 props get-props set-props init-props inherits
4589 pelem ptype)
4590 (while params
4591 (setq pelem (car params))
4592 (when (listp pelem)
4593 (setq ptype (car pelem)
4594 props (car (cdr pelem)))
4595 (cond
4596 ((eq ptype 'SUPERCLASS)
4597 (let ((pname (cdr (assq 'name props)))
4598 (plink (cdr (assq 'link props))))
4599 (unless (and (string= pname "None")
4600 (string= plink "None"))
4601 (push pname inherits))))
4603 ((eq ptype 'PROPERTY)
4604 (let ((pname (cdr (assq 'name props)))
4605 (plink (cdr (assq 'link props)))
4606 (get (string= (cdr (assq 'get props)) "Yes"))
4607 (set (string= (cdr (assq 'set props)) "Yes"))
4608 (init (string= (cdr (assq 'init props)) "Yes")))
4609 (if get (push (list pname plink) get-props))
4610 (if set (push (list pname plink) set-props))
4611 (if init (push (list pname plink) init-props))))
4613 ((eq ptype 'METHOD)
4614 (setq method (cdr (assq 'name props)))
4615 (setq extra-kwds ;;Assume all property keywords are gathered already
4616 (cond
4617 ((string-match (concat class "::Init") method)
4618 (put 'init-props 'matched t)
4619 init-props)
4620 ((string-match (concat class "::GetProperty") method)
4621 (put 'get-props 'matched t)
4622 get-props)
4623 ((string-match (concat class "::SetProperty") method)
4624 (put 'set-props 'matched t)
4625 set-props)
4626 (t nil)))
4627 (setq methods-entry
4628 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4629 methods-entry)))
4630 (t)))
4631 (setq params (cdr params)))
4632 ;;(unless (get 'init-props 'matched)
4633 ;; (message "Failed to match Init in class %s" class))
4634 ;;(unless (get 'get-props 'matched)
4635 ;; (message "Failed to match GetProperty in class %s" class))
4636 ;;(unless (get 'set-props 'matched)
4637 ;; (message "Failed to match SetProperty in class %s" class))
4638 (setq class-entry
4639 (if inherits
4640 (list class (append '(inherits) inherits) (list 'link link))
4641 (list class (list 'link link))))
4642 (cons class-entry methods-entry)))
4644 (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4645 ;; Create correctly structured list elements from ROUTINE or METHOD
4646 ;; XML list structures. Return a list of list elements, with more
4647 ;; than one sub-list possible if a routine can serve as both
4648 ;; procedure and function (e.g. call_method).
4649 (let* ((nameblock (nth 1 xml-entry))
4650 (name (cdr (assq 'name nameblock)))
4651 (link (cdr (assq 'link nameblock)))
4652 (params (cddr xml-entry))
4653 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4654 (case-fold-search t)
4655 syntax kwd klink pref-list kwds pelem ptype props result type)
4656 (if class ;; strip out class name from class method name string
4657 (if (string-match (concat class "::") name)
4658 (setq name (substring name (match-end 0)))))
4659 (while params
4660 (setq pelem (car params))
4661 (when (listp pelem)
4662 (setq ptype (car pelem)
4663 props (car (cdr pelem)))
4664 (cond
4665 ((eq ptype 'SYNTAX)
4666 (setq syntax (cdr (assq 'name props)))
4667 (if (string-match "-&gt;" syntax)
4668 (setq syntax (replace-match "->" t nil syntax)))
4669 (setq type (cdr (assq 'type props)))
4670 (push syntax
4671 (aref syntax-vec (cond
4672 ((string-match "^pro" type) 0)
4673 ((string-match "^fun" type) 1)
4674 ((string-match "^exec" type) 2)))))
4675 ((eq ptype 'KEYWORD)
4676 (setq kwd (cdr (assq 'name props))
4677 klink (cdr (assq 'link props)))
4678 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4679 (progn
4680 (setq pref-list
4681 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4682 kwd (substring kwd (match-end 0)))
4683 (loop for x in pref-list do
4684 (push (list (concat x kwd) klink) kwds)))
4685 (push (list kwd klink) kwds)))
4687 (t))); Do nothing for the others
4688 (setq params (cdr params)))
4690 ;; Debug
4691 ;; (if (and (null (aref syntax-vec 0))
4692 ;; (null (aref syntax-vec 1))
4693 ;; (null (aref syntax-vec 2)))
4694 ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4695 ;; (if class
4696 ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4697 ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4699 ;; Executive commands are treated specially
4700 (if (aref syntax-vec 2)
4701 (cons (substring name 1) link)
4702 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4703 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4704 (loop for idx from 0 to 1 do
4705 (if (aref syntax-vec idx)
4706 (push (append (list name (if (eq idx 0) 'pro 'fun)
4707 class '(system)
4708 (idlwave-shorten-syntax
4709 (aref syntax-vec idx) name class))
4710 kwds) result)))
4711 result)))
4714 (defun idlwave-rinfo-group-keywords (kwds master-link)
4715 ;; Group keywords by link file, as a list with elements
4716 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4717 (let (kwd link anchor linkfiles block master-elt)
4718 (while kwds
4719 (setq kwd (car kwds)
4720 link (idlwave-split-link-target (nth 1 kwd))
4721 anchor (cdr link)
4722 link (car link)
4723 kwd (car kwd))
4724 (if (setq block (assoc link linkfiles))
4725 (push (cons kwd anchor) (cdr block))
4726 (push (list link (cons kwd anchor)) linkfiles))
4727 (setq kwds (cdr kwds)))
4728 ;; Ensure the master link is there
4729 (if (setq master-elt (assoc master-link linkfiles))
4730 (if (eq (car linkfiles) master-elt)
4731 linkfiles
4732 (cons master-elt (delq master-elt linkfiles)))
4733 (push (list master-link) linkfiles))))
4735 (defun idlwave-convert-xml-clean-statement-aliases (aliases)
4736 ;; Clean up the syntax of routines which are actually aliases by
4737 ;; removing the "OR" from the statements
4738 (let (syntax entry)
4739 (loop for x in aliases do
4740 (setq entry (assoc x idlwave-system-routines))
4741 (when entry
4742 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4743 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4745 (defun idlwave-convert-xml-clean-routine-aliases (aliases)
4746 ;; Duplicate and trim original routine aliases from rinfo list
4747 ;; This if for, e.g. OPENR/OPENW/OPENU
4748 (let (alias remove-list new parts all-parts)
4749 (loop for x in aliases do
4750 (when (setq parts (split-string (cdr x) "/"))
4751 (setq new (assoc (cdr x) all-parts))
4752 (unless new
4753 (setq new (cons (cdr x) parts))
4754 (push new all-parts))
4755 (setcdr new (delete (car x) (cdr new)))))
4757 ;; Add any missing aliases (separate by slashes)
4758 (loop for x in all-parts do
4759 (if (cdr x)
4760 (push (cons (nth 1 x) (car x)) aliases)))
4762 (loop for x in aliases do
4763 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4764 (unless (memq alias remove-list) (push alias remove-list))
4765 (setq alias (copy-sequence alias))
4766 (setcar alias (car x))
4767 (push alias idlwave-system-routines)))
4768 (loop for x in remove-list do
4769 (delq x idlwave-system-routines))))
4771 (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4772 ;; Duplicate and trim original routine aliases from rinfo list
4773 ;; This if for, e.g. !X, !Y, !Z.
4774 (let (alias remove-list)
4775 (loop for x in aliases do
4776 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4777 (unless (memq alias remove-list) (push alias remove-list))
4778 (setq alias (copy-sequence alias))
4779 (setcar alias (car x))
4780 (push alias idlwave-system-variables-alist)))
4781 (loop for x in remove-list do
4782 (delq x idlwave-system-variables-alist))))
4785 (defun idlwave-xml-create-sysvar-alist (xml-entry)
4786 ;; Create a sysvar list entry from the xml parsed list.
4787 (let* ((nameblock (nth 1 xml-entry))
4788 (name (cdr (assq 'name nameblock)))
4789 (sysvar (substring name (progn (string-match "^ *!" name)
4790 (match-end 0))))
4791 (link (cdr (assq 'link nameblock)))
4792 (params (cddr xml-entry))
4793 (case-fold-search t)
4794 pelem ptype props tags)
4795 (while params
4796 (setq pelem (car params))
4797 (when (listp pelem)
4798 (setq ptype (car pelem)
4799 props (car (cdr pelem)))
4800 (cond
4801 ((eq ptype 'FIELD)
4802 (push (cons (cdr (assq 'name props))
4803 (cdr
4804 (idlwave-split-link-target (cdr (assq 'link props)))))
4805 tags))))
4806 (setq params (cdr params)))
4807 (delq nil
4808 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4811 (defvar idlwave-xml-routine-info-file nil)
4813 (defun idlwave-save-routine-info ()
4814 (if idlwave-xml-routine-info-file
4815 (with-temp-file idlwave-xml-system-rinfo-converted-file
4816 (insert
4817 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4818 ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4819 ;; Automatically generated from source file:
4820 ;; " idlwave-xml-routine-info-file "
4821 ;; on " (current-time-string) "
4822 ;; Do not edit."))
4823 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4824 idlwave-xml-routine-info-file))
4825 (insert "\n(setq idlwave-system-routines\n '")
4826 (prin1 idlwave-system-routines (current-buffer))
4827 (insert ")")
4828 (insert "\n(setq idlwave-system-variables-alist\n '")
4829 (prin1 idlwave-system-variables-alist (current-buffer))
4830 (insert ")")
4831 (insert "\n(setq idlwave-system-class-info\n '")
4832 (prin1 idlwave-system-class-info (current-buffer))
4833 (insert ")")
4834 (insert "\n(setq idlwave-executive-commands-alist\n '")
4835 (prin1 idlwave-executive-commands-alist (current-buffer))
4836 (insert ")")
4837 (insert "\n(setq idlwave-help-special-topic-words\n '")
4838 (prin1 idlwave-help-special-topic-words (current-buffer))
4839 (insert ")"))))
4841 (defun idlwave-convert-xml-system-routine-info ()
4842 "Convert XML supplied IDL routine info into internal form.
4843 Cache to disk for quick recovery."
4844 (interactive)
4845 (let* ((dir (file-name-as-directory
4846 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4847 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4848 (elem-cnt 0)
4849 props rinfo msg-cnt elem type nelem class-result alias
4850 routines routine-aliases statement-aliases sysvar-aliases)
4851 (if (not (file-exists-p catalog-file))
4852 (error "No such XML routine info file: %s" catalog-file)
4853 (if (not (file-readable-p catalog-file))
4854 (error "Cannot read XML routine info file: %s" catalog-file)))
4855 (message "Reading XML routine info...")
4856 (setq rinfo (xml-parse-file catalog-file))
4857 (message "Reading XML routine info...done")
4858 (setq rinfo (assq 'CATALOG rinfo))
4859 (unless rinfo (error "Failed to parse XML routine info"))
4860 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4862 (setq rinfo (cddr rinfo))
4864 (setq nelem (length rinfo)
4865 msg-cnt (/ nelem 20))
4867 (setq idlwave-xml-routine-info-file nil)
4868 (message "Converting XML routine info...")
4869 (setq idlwave-system-routines nil
4870 idlwave-system-variables-alist nil
4871 idlwave-system-class-info nil
4872 idlwave-executive-commands-alist nil
4873 idlwave-help-special-topic-words nil)
4875 (while rinfo
4876 (setq elem (car rinfo)
4877 rinfo (cdr rinfo))
4878 (incf elem-cnt)
4879 (when (listp elem)
4880 (setq type (car elem)
4881 props (car (cdr elem)))
4882 (if (= (mod elem-cnt msg-cnt) 0)
4883 (message "Converting XML routine info...%2d%%"
4884 (floor (* elem-cnt 100.0) nelem)))
4885 (cond
4886 ((eq type 'ROUTINE)
4887 (if (setq alias (assq 'alias_to props))
4888 (push (cons (cdr (assq 'name props)) (cdr alias))
4889 routine-aliases)
4890 (setq routines (idlwave-xml-create-rinfo-list elem))
4891 (if (listp (cdr routines))
4892 (setq idlwave-system-routines
4893 (nconc idlwave-system-routines routines))
4894 ;; a cons cell is an executive commands
4895 (push routines idlwave-executive-commands-alist))))
4897 ((eq type 'CLASS)
4898 (setq class-result (idlwave-xml-create-class-method-lists elem))
4899 (push (car class-result) idlwave-system-class-info)
4900 (setq idlwave-system-routines
4901 (nconc idlwave-system-routines (cdr class-result))))
4903 ((eq type 'STATEMENT)
4904 (push (cons (cdr (assq 'name props))
4905 (cdr (assq 'link props)))
4906 idlwave-help-special-topic-words)
4907 ;; Save the links to those which are statement aliases (not routines)
4908 (if (setq alias (assq 'alias_to props))
4909 (unless (member (cdr alias) statement-aliases)
4910 (push (cdr alias) statement-aliases))))
4912 ((eq type 'SYSVAR)
4913 (if (setq alias (cdr (assq 'alias_to props)))
4914 (push (cons (substring (cdr (assq 'name props)) 1)
4915 (substring alias 1))
4916 sysvar-aliases)
4917 (push (idlwave-xml-create-sysvar-alist elem)
4918 idlwave-system-variables-alist)))
4919 (t))))
4920 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4921 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4922 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4924 (setq idlwave-xml-routine-info-file catalog-file)
4925 (idlwave-save-routine-info)
4926 (message "Converting XML routine info...done")))
4929 ;; ("ROUTINE" type class
4930 ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4931 ;; (buffer pro_file dir) | (compiled pro_file dir)
4932 ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4933 ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4936 (defun idlwave-load-rinfo-next-step ()
4937 (let ((inhibit-quit t)
4938 (arr idlwave-load-rinfo-steps-done))
4939 (if (catch 'exit
4940 (when (not (aref arr 0))
4941 (message "Loading system routine info in idle time...")
4942 (idlwave-load-system-routine-info)
4943 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4944 (message "Loading system routine info in idle time...done")
4945 (aset arr 0 t)
4946 (throw 'exit t))
4948 (when (not (aref arr 1))
4949 (message "Normalizing idlwave-system-routines in idle time...")
4950 (idlwave-reset-sintern t)
4951 (put 'idlwave-reset-sintern 'done-by-idle t)
4952 (setq idlwave-system-routines
4953 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4954 (message "Normalizing idlwave-system-routines in idle time...done")
4955 (aset arr 1 t)
4956 (throw 'exit t))
4958 (when (not (aref arr 2))
4959 (when (and (stringp idlwave-user-catalog-file)
4960 (file-regular-p idlwave-user-catalog-file))
4961 (message "Loading user catalog in idle time...")
4962 (condition-case nil
4963 (load-file idlwave-user-catalog-file)
4964 (error (throw 'exit nil)))
4965 ;; Check for the old style catalog and warn
4966 (if (and
4967 (boundp 'idlwave-library-routines)
4968 idlwave-library-routines)
4969 (progn
4970 (setq idlwave-library-routines nil)
4971 (ding)
4972 (message "Outdated user catalog: %s... recreate"
4973 idlwave-user-catalog-file))
4974 (message "Loading user catalog in idle time...done")))
4975 (aset arr 2 t)
4976 (throw 'exit t))
4978 (when (not (aref arr 3))
4979 (when idlwave-user-catalog-routines
4980 (message "Normalizing user catalog routines in idle time...")
4981 (setq idlwave-user-catalog-routines
4982 (idlwave-sintern-rinfo-list
4983 idlwave-user-catalog-routines 'sys))
4984 (message
4985 "Normalizing user catalog routines in idle time...done"))
4986 (aset arr 3 t)
4987 (throw 'exit t))
4989 (when (not (aref arr 4))
4990 (idlwave-scan-library-catalogs
4991 "Loading and normalizing library catalogs in idle time...")
4992 (aset arr 4 t)
4993 (throw 'exit t))
4994 (when (not (aref arr 5))
4995 (message "Finishing initialization in idle time...")
4996 (idlwave-routines)
4997 (message "Finishing initialization in idle time...done")
4998 (aset arr 5 t)
4999 (throw 'exit nil)))
5000 ;; restart the timer
5001 (if (sit-for 1)
5002 (idlwave-load-rinfo-next-step)
5003 (setq idlwave-load-rinfo-idle-timer
5004 (run-with-idle-timer
5005 idlwave-init-rinfo-when-idle-after
5006 nil 'idlwave-load-rinfo-next-step))))))
5008 (defvar idlwave-after-load-rinfo-hook nil)
5010 (defun idlwave-load-all-rinfo (&optional force)
5011 ;; Load and case-treat the system, user catalog, and library routine
5012 ;; info files.
5014 ;; System
5015 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
5016 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5017 (idlwave-load-system-routine-info))
5018 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5019 (message "Normalizing idlwave-system-routines...")
5020 (setq idlwave-system-routines
5021 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5022 (message "Normalizing idlwave-system-routines...done"))
5023 (when idlwave-system-routines
5024 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5025 (setq idlwave-last-system-routine-info-cons-cell
5026 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5028 ;; User catalog
5029 (when (and (stringp idlwave-user-catalog-file)
5030 (file-regular-p idlwave-user-catalog-file))
5031 (condition-case nil
5032 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5033 (load-file idlwave-user-catalog-file))
5034 (error nil))
5035 (when (and
5036 (boundp 'idlwave-library-routines)
5037 idlwave-library-routines)
5038 (setq idlwave-library-routines nil)
5039 (error "Outdated user catalog: %s... recreate"
5040 idlwave-user-catalog-file))
5041 (setq idlwave-true-path-alist nil)
5042 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5043 (message "Normalizing user catalog routines...")
5044 (setq idlwave-user-catalog-routines
5045 (idlwave-sintern-rinfo-list
5046 idlwave-user-catalog-routines 'sys))
5047 (message "Normalizing user catalog routines...done")))
5049 ;; Library catalog
5050 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5051 (idlwave-scan-library-catalogs
5052 "Loading and normalizing library catalogs..."))
5053 (run-hooks 'idlwave-after-load-rinfo-hook))
5056 (defun idlwave-update-buffer-routine-info ()
5057 (let (res)
5058 (cond
5059 ((eq idlwave-scan-all-buffers-for-routine-info t)
5060 ;; Scan all buffers, current buffer last
5061 (message "Scanning all buffers...")
5062 (setq res (idlwave-get-routine-info-from-buffers
5063 (reverse (buffer-list)))))
5064 ((null idlwave-scan-all-buffers-for-routine-info)
5065 ;; Don't scan any buffers
5066 (setq res nil))
5068 ;; Just scan this buffer
5069 (if (derived-mode-p 'idlwave-mode)
5070 (progn
5071 (message "Scanning current buffer...")
5072 (setq res (idlwave-get-routine-info-from-buffers
5073 (list (current-buffer))))))))
5074 ;; Put the result into the correct variable
5075 (setq idlwave-buffer-routines
5076 (idlwave-sintern-rinfo-list res 'set))))
5078 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
5079 "Put the different sources for routine information together."
5080 ;; The sequence here is important because earlier definitions shadow
5081 ;; later ones. We assume that if things in the buffers are newer
5082 ;; then in the shell of the system, they are meant to be different.
5083 (let ((temp (append idlwave-buffer-routines
5084 idlwave-compiled-routines
5085 idlwave-library-catalog-routines
5086 idlwave-user-catalog-routines)))
5087 ;; Not actually used for anything?
5088 (if idlwave-last-system-routine-info-cons-cell
5089 (setcdr idlwave-last-system-routine-info-cons-cell temp)
5090 (setq idlwave-last-system-routine-info-cons-cell (cons temp nil))))
5091 (setq idlwave-class-alist nil)
5093 ;; Give a message with information about the number of routines we have.
5094 (unless quiet
5095 (message
5096 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
5097 (length idlwave-buffer-routines)
5098 (length idlwave-compiled-routines)
5099 (length idlwave-library-catalog-routines)
5100 (length idlwave-user-catalog-routines)
5101 (length idlwave-system-routines)))
5102 (if run-hook
5103 (run-hooks 'idlwave-update-rinfo-hook)))
5105 (defun idlwave-class-alist ()
5106 "Return the class alist - make it if necessary."
5107 (or idlwave-class-alist
5108 (let (class)
5109 (loop for x in idlwave-routines do
5110 (when (and (setq class (nth 2 x))
5111 (not (assq class idlwave-class-alist)))
5112 (push (list class) idlwave-class-alist)))
5113 idlwave-class-alist)))
5115 ;; Three functions for the hooks
5116 (defun idlwave-save-buffer-update ()
5117 (idlwave-update-current-buffer-info 'save-buffer))
5118 (defun idlwave-kill-buffer-update ()
5119 (idlwave-update-current-buffer-info 'kill-buffer))
5120 (defun idlwave-new-buffer-update ()
5121 (idlwave-update-current-buffer-info 'find-file))
5123 (defun idlwave-update-current-buffer-info (why)
5124 "Update `idlwave-routines' for current buffer.
5125 Can run from `after-save-hook'."
5126 (when (and (derived-mode-p 'idlwave-mode)
5127 (or (eq t idlwave-auto-routine-info-updates)
5128 (memq why idlwave-auto-routine-info-updates))
5129 idlwave-scan-all-buffers-for-routine-info
5130 idlwave-routines)
5131 (condition-case nil
5132 (let (routines)
5133 (idlwave-replace-buffer-routine-info
5134 (buffer-file-name)
5135 (if (eq why 'kill-buffer)
5137 (setq routines
5138 (idlwave-sintern-rinfo-list
5139 (idlwave-get-routine-info-from-buffers
5140 (list (current-buffer))) 'set))))
5141 (idlwave-concatenate-rinfo-lists 'quiet)
5142 routines)
5143 (error nil))))
5145 (defun idlwave-replace-buffer-routine-info (file new)
5146 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
5147 (let ((list idlwave-buffer-routines)
5148 found)
5149 (while list
5150 ;; The following test uses eq to make sure it works correctly
5151 ;; when two buffers visit the same file. Then the file names
5152 ;; will be equal, but not eq.
5153 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
5154 (progn
5155 (setcar list nil)
5156 (setq found t))
5157 (if found
5158 ;; End of that section reached. Jump.
5159 (setq list nil)))
5160 (setq list (cdr list)))
5161 (setq idlwave-buffer-routines
5162 (append new (delq nil idlwave-buffer-routines)))))
5164 ;;----- Scanning buffers -------------------
5166 (defun idlwave-get-routine-info-from-buffers (buffers)
5167 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5168 (let (buf routine-lists res)
5169 (save-excursion
5170 (while (setq buf (pop buffers))
5171 (set-buffer buf)
5172 (if (and (derived-mode-p 'idlwave-mode)
5173 buffer-file-name)
5174 ;; yes, this buffer has the right mode.
5175 (progn (setq res (condition-case nil
5176 (idlwave-get-buffer-routine-info)
5177 (error nil)))
5178 (push res routine-lists)))))
5179 ;; Concatenate the individual lists and return the result
5180 (apply 'nconc routine-lists)))
5182 (defun idlwave-get-buffer-routine-info ()
5183 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5184 (let* ((case-fold-search t)
5185 routine-list string entry)
5186 (save-excursion
5187 (save-restriction
5188 (widen)
5189 (goto-char (point-min))
5190 (while (re-search-forward
5191 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
5192 (setq string (buffer-substring-no-properties
5193 (match-beginning 0)
5194 (progn
5195 (idlwave-end-of-statement)
5196 (point))))
5197 (setq entry (idlwave-parse-definition string))
5198 (push entry routine-list))))
5199 routine-list))
5201 (defvar idlwave-scanning-lib-dir)
5202 (defvar idlwave-scanning-lib)
5203 (defun idlwave-parse-definition (string)
5204 "Parse a module definition."
5205 (let ((case-fold-search t)
5206 start name args type keywords class)
5207 ;; Remove comments
5208 (while (string-match ";.*" string)
5209 (setq string (replace-match "" t t string)))
5210 ;; Remove the continuation line stuff
5211 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5212 (setq string (replace-match "\\1 " t nil string)))
5213 (while (string-match "\n" string)
5214 (setq string (replace-match " " t nil string)))
5215 ;; Match the name and type.
5216 (when (string-match
5217 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5218 (setq start (match-end 0))
5219 (setq type (downcase (match-string 1 string)))
5220 (if (match-beginning 3)
5221 (setq class (match-string 3 string)))
5222 (setq name (match-string 4 string)))
5223 ;; Match normal args and keyword args
5224 (while (string-match
5225 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
5226 string start)
5227 (setq start (match-end 0))
5228 (if (match-beginning 3)
5229 (push (match-string 1 string) keywords)
5230 (push (match-string 1 string) args)))
5231 ;; Normalize and sort.
5232 (setq args (nreverse args))
5233 (setq keywords (sort keywords (lambda (a b)
5234 (string< (downcase a) (downcase b)))))
5235 ;; Make and return the entry
5236 ;; We don't know which argument are optional, so this information
5237 ;; will not be contained in the calling sequence.
5238 (list name
5239 (if (equal type "pro") 'pro 'fun)
5240 class
5241 (cond ((not (boundp 'idlwave-scanning-lib))
5242 (list 'buffer (buffer-file-name)))
5243 ; ((string= (downcase (file-name-base))
5244 ; (downcase name))
5245 ; (list 'lib))
5246 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
5247 (t (list 'user (file-name-nondirectory (buffer-file-name))
5248 idlwave-scanning-lib-dir "UserLib")))
5249 (concat
5250 (if (string= type "function") "Result = " "")
5251 (if class "Obj ->[%s::]" "")
5252 "%s"
5253 (if args
5254 (concat
5255 (if (string= type "function") "(" ", ")
5256 (mapconcat 'identity args ", ")
5257 (if (string= type "function") ")" ""))))
5258 (if keywords
5259 (cons nil (mapcar 'list keywords)) ;No help file
5260 nil))))
5263 ;;----- Scanning the user catalog -------------------
5265 (defun idlwave-sys-dir ()
5266 "Return the syslib directory, or a dummy that never matches."
5267 (cond
5268 ((and idlwave-system-directory
5269 (not (string= idlwave-system-directory "")))
5270 idlwave-system-directory)
5271 ((getenv "IDL_DIR"))
5272 (t "@@@@@@@@")))
5275 (defun idlwave-create-user-catalog-file (&optional arg)
5276 "Scan all files on selected dirs of IDL search path for routine information.
5278 A widget checklist will allow you to choose the directories. Write
5279 the result as a file `idlwave-user-catalog-file'. When this file
5280 exists, it will be automatically loaded to give routine information
5281 about library routines. With ARG, just rescan the same directories
5282 as last time - so no widget will pop up."
5283 (interactive "P")
5284 ;; Make sure the file is loaded if it exists.
5285 (if (and (stringp idlwave-user-catalog-file)
5286 (file-regular-p idlwave-user-catalog-file))
5287 (condition-case nil
5288 (load-file idlwave-user-catalog-file)
5289 (error nil)))
5290 ;; Make sure the file name makes sense
5291 (unless (and (stringp idlwave-user-catalog-file)
5292 (> (length idlwave-user-catalog-file) 0)
5293 (file-accessible-directory-p
5294 (file-name-directory idlwave-user-catalog-file))
5295 (not (string= "" (file-name-nondirectory
5296 idlwave-user-catalog-file))))
5297 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
5299 (cond
5300 ;; Rescan the known directories
5301 ((and arg idlwave-path-alist
5302 (consp (car idlwave-path-alist)))
5303 (idlwave-scan-user-lib-files idlwave-path-alist))
5305 ;; Expand the directories from library-path and run the widget
5306 (idlwave-library-path
5307 (idlwave-display-user-catalog-widget
5308 (if idlwave-true-path-alist
5309 ;; Propagate any flags on the existing path-alist
5310 (mapcar (lambda (x)
5311 (let ((path-entry (assoc (file-truename x)
5312 idlwave-true-path-alist)))
5313 (if path-entry
5314 (cons x (cdr path-entry))
5315 (list x))))
5316 (idlwave-expand-path idlwave-library-path))
5317 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5319 ;; Ask the shell for the path and then run the widget
5321 (message "Asking the shell for IDL path...")
5322 (require 'idlw-shell)
5323 (idlwave-shell-send-command idlwave-shell-path-query
5324 '(idlwave-user-catalog-command-hook nil)
5325 'hide))))
5328 ;; Parse shell path information and select among it.
5329 (defun idlwave-user-catalog-command-hook (&optional arg)
5330 ;; Command hook used by `idlwave-create-user-catalog-file'.
5331 (if arg
5332 ;; Scan immediately
5333 (idlwave-scan-user-lib-files idlwave-path-alist)
5334 ;; Set the path and display the widget
5335 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5336 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5337 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5339 (defconst idlwave-user-catalog-widget-help-string
5340 "This is the front-end to the creation of the IDLWAVE user catalog.
5341 Please select the directories on IDL's search path from which you
5342 would like to extract routine information, to be stored in the file:
5346 If this is not the correct file, first set variable
5347 `idlwave-user-catalog-file', and call this command again.
5349 N.B. Many libraries include pre-scanned catalog files
5350 \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5351 not be scanned. You can scan your own libraries off-line using the
5352 perl script `idlwave_catalog'.
5354 After selecting the directories, choose [Scan & Save] to scan the library
5355 directories and save the routine info.
5356 \n")
5358 (defvar idlwave-widget)
5359 (defvar widget-keymap)
5360 (defun idlwave-display-user-catalog-widget (dirs-list)
5361 "Create the widget to select IDL search path directories for scanning."
5362 (interactive)
5363 (require 'widget)
5364 (require 'wid-edit)
5365 (unless dirs-list
5366 (error "Don't know IDL's search path"))
5368 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5369 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5370 (kill-all-local-variables)
5371 (make-local-variable 'idlwave-widget)
5372 (widget-insert (format idlwave-user-catalog-widget-help-string
5373 idlwave-user-catalog-file))
5375 (widget-create 'push-button
5376 :notify 'idlwave-widget-scan-user-lib-files
5377 "Scan & Save")
5378 (widget-insert " ")
5379 (widget-create 'push-button
5380 :notify 'idlwave-delete-user-catalog-file
5381 "Delete File")
5382 (widget-insert " ")
5383 (widget-create 'push-button
5384 :notify
5385 (lambda (&rest ignore)
5386 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5387 (dolist (x path-list)
5388 (unless (memq 'lib (cdr x))
5389 (idlwave-path-alist-add-flag x 'user)))
5390 (idlwave-display-user-catalog-widget path-list)))
5391 "Select All Non-Lib")
5392 (widget-insert " ")
5393 (widget-create 'push-button
5394 :notify
5395 (lambda (&rest ignore)
5396 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5397 (dolist (x path-list)
5398 (idlwave-path-alist-remove-flag x 'user))
5399 (idlwave-display-user-catalog-widget path-list)))
5400 "Deselect All")
5401 (widget-insert " ")
5402 (widget-create 'push-button
5403 :notify (lambda (&rest ignore)
5404 (kill-buffer (current-buffer)))
5405 "Quit")
5406 (widget-insert "\n\n")
5408 (widget-insert "Select Directories: \n")
5410 (setq idlwave-widget
5411 (apply 'widget-create
5412 'checklist
5413 :value (delq nil (mapcar (lambda (x)
5414 (if (memq 'user (cdr x))
5415 (car x)))
5416 dirs-list))
5417 :greedy t
5418 :tag "List of directories"
5419 (mapcar (lambda (x)
5420 (list 'item
5421 (if (memq 'lib (cdr x))
5422 (concat "[LIB] " (car x) )
5423 (car x)))) dirs-list)))
5424 (widget-put idlwave-widget :path-dirs dirs-list)
5425 (widget-insert "\n")
5426 (use-local-map widget-keymap)
5427 (widget-setup)
5428 (goto-char (point-min))
5429 (delete-other-windows))
5431 (defun idlwave-delete-user-catalog-file (&rest ignore)
5432 (if (yes-or-no-p
5433 (format "Delete file %s " idlwave-user-catalog-file))
5434 (progn
5435 (delete-file idlwave-user-catalog-file)
5436 (message "%s has been deleted" idlwave-user-catalog-file))))
5438 (defun idlwave-widget-scan-user-lib-files (&rest ignore)
5439 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
5440 (let* ((widget idlwave-widget)
5441 (selected-dirs (widget-value widget))
5442 (path-alist (widget-get widget :path-dirs))
5443 (this-path-alist path-alist)
5444 dir-entry)
5445 (while (setq dir-entry (pop this-path-alist))
5446 (if (member
5447 (if (memq 'lib (cdr dir-entry))
5448 (concat "[LIB] " (car dir-entry))
5449 (car dir-entry))
5450 selected-dirs)
5451 (idlwave-path-alist-add-flag dir-entry 'user)
5452 (idlwave-path-alist-remove-flag dir-entry 'user)))
5453 (idlwave-scan-user-lib-files path-alist)))
5455 (defvar font-lock-mode)
5456 (defun idlwave-scan-user-lib-files (path-alist)
5457 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
5458 (let* ((idlwave-scanning-lib t)
5459 (idlwave-scanning-lib-dir "")
5460 (idlwave-completion-case nil)
5461 dirs-alist dir files file)
5462 (setq idlwave-user-catalog-routines nil
5463 idlwave-path-alist path-alist ; for library-path instead
5464 idlwave-true-path-alist nil)
5465 (if idlwave-auto-write-paths (idlwave-write-paths))
5466 (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
5467 (idlwave-mode)
5468 (setq dirs-alist (reverse path-alist))
5469 (while (setq dir (pop dirs-alist))
5470 (when (memq 'user (cdr dir)) ; Has it marked for scan?
5471 (setq dir (car dir))
5472 (setq idlwave-scanning-lib-dir dir)
5473 (when (file-directory-p dir)
5474 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5475 (while (setq file (pop files))
5476 (when (file-regular-p file)
5477 (if (not (file-readable-p file))
5478 (message "Skipping %s (no read permission)" file)
5479 (message "Scanning %s..." file)
5480 (erase-buffer)
5481 (insert-file-contents file 'visit)
5482 (setq idlwave-user-catalog-routines
5483 (append (idlwave-get-routine-info-from-buffers
5484 (list (current-buffer)))
5485 idlwave-user-catalog-routines)))))))))
5486 (message "Creating user catalog file...")
5487 (kill-buffer "*idlwave-scan.pro*")
5488 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5489 (with-temp-buffer
5490 (insert ";; IDLWAVE user catalog file\n")
5491 (insert (format ";; Created %s\n\n" (current-time-string)))
5493 ;; Define the routine info list
5494 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5495 (let ((standard-output (current-buffer)))
5496 (mapc (lambda (x)
5497 (insert "\n ")
5498 (prin1 x)
5499 (goto-char (point-max)))
5500 idlwave-user-catalog-routines))
5501 (insert (format "))\n\n;;; %s ends here\n"
5502 (file-name-nondirectory idlwave-user-catalog-file)))
5503 (write-region nil nil idlwave-user-catalog-file)))
5504 (message "Creating user catalog file...done")
5505 (message "Info for %d routines saved in %s"
5506 (length idlwave-user-catalog-routines)
5507 idlwave-user-catalog-file)
5508 (sit-for 2)
5509 (idlwave-update-routine-info t))
5511 (defun idlwave-read-paths ()
5512 (if (and (stringp idlwave-path-file)
5513 (file-regular-p idlwave-path-file))
5514 (condition-case nil
5515 (load idlwave-path-file t t t)
5516 (error nil))))
5518 (defun idlwave-write-paths ()
5519 (interactive)
5520 (when (and idlwave-path-alist idlwave-system-directory)
5521 (with-temp-buffer
5522 (insert ";; IDLWAVE paths\n")
5523 (insert (format ";; Created %s\n\n" (current-time-string)))
5524 ;; Define the variable which knows the value of "!DIR"
5525 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5526 idlwave-system-directory))
5528 ;; Define the variable which contains a list of all scanned directories
5529 (insert "\n(setq idlwave-path-alist\n '(")
5530 (let ((standard-output (current-buffer)))
5531 (mapc (lambda (x)
5532 (insert "\n ")
5533 (prin1 x)
5534 (goto-char (point-max)))
5535 idlwave-path-alist))
5536 (insert "))\n")
5537 (write-region nil nil idlwave-path-file))))
5539 (defun idlwave-expand-path (path &optional default-dir)
5540 ;; Expand parts of path starting with '+' recursively into directory list.
5541 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5542 (message "Expanding path...")
5543 (let (path1 dir recursive)
5544 (while (setq dir (pop path))
5545 (if (setq recursive (string= (substring dir 0 1) "+"))
5546 (setq dir (substring dir 1)))
5547 (if (and recursive
5548 (not (file-name-absolute-p dir)))
5549 (setq dir (expand-file-name dir default-dir)))
5550 (if recursive
5551 ;; Expand recursively
5552 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5553 ;; Keep unchanged
5554 (push dir path1)))
5555 (message "Expanding path...done")
5556 (nreverse path1)))
5558 (defun idlwave-recursive-directory-list (dir)
5559 ;; Return a list of all directories below DIR, including DIR itself
5560 (let ((path (list dir)) path1 file files)
5561 (while (setq dir (pop path))
5562 (when (file-directory-p dir)
5563 (setq files (nreverse (directory-files dir t "[^.]")))
5564 (while (setq file (pop files))
5565 (if (file-directory-p file)
5566 (push (file-name-as-directory file) path)))
5567 (push dir path1)))
5568 path1))
5571 ;;----- Scanning the library catalogs ------------------
5576 (defun idlwave-scan-library-catalogs (&optional message-base no-load)
5577 "Scan for library catalog files (.idlwave_catalog) and ingest.
5579 All directories on `idlwave-path-alist' (or `idlwave-library-path'
5580 instead, if present) are searched. Print MESSAGE-BASE along with the
5581 libraries being loaded, if passed, and skip loading/normalizing if
5582 NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5583 be set to nil to disable library catalog scanning."
5584 (when idlwave-use-library-catalogs
5585 (let ((dirs
5586 (if idlwave-library-path
5587 (idlwave-expand-path idlwave-library-path)
5588 (mapcar 'car idlwave-path-alist)))
5589 (old-libname "")
5590 dir-entry dir catalog all-routines)
5591 (if message-base (message message-base))
5592 (while (setq dir (pop dirs))
5593 (catch 'continue
5594 (when (file-readable-p
5595 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5596 (unless no-load
5597 (setq idlwave-library-catalog-routines nil)
5598 ;; Load the catalog file
5599 (condition-case nil
5600 (load catalog t t t)
5601 (error (throw 'continue t)))
5602 (when (and
5603 message-base
5604 (not (string= idlwave-library-catalog-libname
5605 old-libname)))
5606 (message "%s" (concat message-base
5607 idlwave-library-catalog-libname))
5608 (setq old-libname idlwave-library-catalog-libname))
5609 (when idlwave-library-catalog-routines
5610 (setq all-routines
5611 (append
5612 (idlwave-sintern-rinfo-list
5613 idlwave-library-catalog-routines 'sys dir)
5614 all-routines))))
5616 ;; Add a 'lib flag if on path-alist
5617 (when (and idlwave-path-alist
5618 (setq dir-entry (assoc dir idlwave-path-alist)))
5619 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5620 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5621 (if message-base (message (concat message-base "done"))))))
5623 ;;----- Communicating with the Shell -------------------
5625 ;; First, here is the idl program which can be used to query IDL for
5626 ;; defined routines.
5627 (defconst idlwave-routine-info.pro
5629 ;; START OF IDLWAVE SUPPORT ROUTINES
5630 pro idlwave_print_safe,item,limit
5631 catch,err
5632 if err ne 0 then begin
5633 print,'Could not print item.'
5634 return
5635 endif
5636 if n_elements(item) gt limit then $
5637 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5638 else print,item
5641 pro idlwave_print_info_entry,name,func=func,separator=sep
5642 ;; See if it's an object method
5643 if name eq '' then return
5644 func = keyword_set(func)
5645 methsep = strpos(name,'::')
5646 meth = methsep ne -1
5648 ;; Get routine info
5649 pars = routine_info(name,/parameters,functions=func)
5650 source = routine_info(name,/source,functions=func)
5651 nargs = pars.num_args
5652 nkw = pars.num_kw_args
5653 if nargs gt 0 then args = pars.args
5654 if nkw gt 0 then kwargs = pars.kw_args
5656 ;; Trim the class, and make the name
5657 if meth then begin
5658 class = strmid(name,0,methsep)
5659 name = strmid(name,methsep+2,strlen(name)-1)
5660 if nargs gt 0 then begin
5661 ;; remove the self argument
5662 wh = where(args ne 'SELF',nargs)
5663 if nargs gt 0 then args = args[wh]
5664 endif
5665 endif else begin
5666 ;; No class, just a normal routine.
5667 class = \"\"
5668 endelse
5670 ;; Calling sequence
5671 cs = \"\"
5672 if func then cs = 'Result = '
5673 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5674 cs = cs + '%s'
5675 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5676 if nargs gt 0 then begin
5677 for j=0,nargs-1 do begin
5678 cs = cs + args[j]
5679 if j lt nargs-1 then cs = cs + ', '
5680 endfor
5682 if func then cs = cs + ')'
5683 ;; Keyword arguments
5684 kwstring = ''
5685 if nkw gt 0 then begin
5686 for j=0,nkw-1 do begin
5687 kwstring = kwstring + ' ' + kwargs[j]
5688 endfor
5689 endif
5691 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
5693 print,ret + ': ' + name + sep + class + sep + source[0].path $
5694 + sep + cs + sep + kwstring
5697 pro idlwave_routine_info,file
5698 on_error,1
5699 sep = '<@>'
5700 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5701 all = routine_info()
5702 fileQ=n_elements(file) ne 0
5703 if fileQ then file=strtrim(file,2)
5704 for i=0L,n_elements(all)-1L do begin
5705 if fileQ then begin
5706 if (routine_info(all[i],/SOURCE)).path eq file then $
5707 idlwave_print_info_entry,all[i],separator=sep
5708 endif else idlwave_print_info_entry,all[i],separator=sep
5709 endfor
5710 all = routine_info(/functions)
5711 for i=0L,n_elements(all)-1L do begin
5712 if fileQ then begin
5713 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5714 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5715 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5716 endfor
5717 print,'>>>END OF IDLWAVE ROUTINE INFO'
5720 pro idlwave_get_sysvars
5721 on_error,1
5722 catch,error_status
5723 if error_status ne 0 then begin
5724 print, 'Cannot get info about system variables'
5725 endif else begin
5726 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5727 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5728 v = strsplit(s,' +',/regex,/extract) ; get variables
5729 for i=0L,n_elements(v)-1 do begin
5730 t = [''] ; get tag list
5731 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5732 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5733 endfor
5734 endelse
5737 pro idlwave_get_class_tags, class
5738 res = execute('tags=tag_names({'+class+'})')
5739 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5741 ;; END OF IDLWAVE SUPPORT ROUTINES
5743 "The IDL programs to get info from the shell.")
5745 (defvar idlwave-idlwave_routine_info-compiled nil
5746 "Remember if the routine info procedure is already compiled.")
5748 (defvar idlwave-shell-temp-pro-file)
5749 (defvar idlwave-shell-temp-rinfo-save-file)
5751 (defun idlwave-shell-compile-helper-routines (&optional wait)
5752 (unless (and idlwave-idlwave_routine_info-compiled
5753 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5754 (with-current-buffer (idlwave-find-file-noselect
5755 (idlwave-shell-temp-file 'pro))
5756 (erase-buffer)
5757 (insert idlwave-routine-info.pro)
5758 (save-buffer 0))
5759 (idlwave-shell-send-command
5760 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
5761 nil 'hide wait)
5762 (idlwave-shell-send-command
5763 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5764 (idlwave-shell-temp-file 'rinfo))
5765 nil 'hide)
5766 (setq idlwave-idlwave_routine_info-compiled t))
5768 ;; Restore if necessary. Must use execute to hide lame routine_info
5769 ;; errors on undefined routine
5770 (idlwave-shell-send-command
5771 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5772 idlwave-shell-temp-rinfo-save-file
5773 idlwave-shell-temp-rinfo-save-file)
5774 nil 'hide))
5777 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5778 "Query the shell for routine_info of compiled modules and update the lists."
5779 ;; Save and compile the procedure. The compiled procedure is then
5780 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5781 ;; need to test for and possibly RESTORE the procedure each time we
5782 ;; use it, since the user may have killed or redefined it. In
5783 ;; particular, .RESET_SESSION will kill all user procedures. If
5784 ;; FILE is set, only update routine info for routines in that file.
5786 (idlwave-shell-compile-helper-routines wait)
5787 ; execute the routine_info procedure, and analyze the output
5788 (idlwave-shell-send-command
5789 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
5790 `(progn
5791 (idlwave-shell-routine-info-filter)
5792 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5793 'hide wait))
5795 ;; ---------------------------------------------------------------------------
5797 ;; Completion and displaying routine calling sequences
5799 (defvar idlwave-completion-help-info nil)
5800 (defvar idlwave-completion-help-links nil)
5801 (defvar idlwave-current-obj_new-class nil)
5802 (defvar idlwave-complete-special nil)
5803 (defvar method-selector)
5804 (defvar class-selector)
5805 (defvar type-selector)
5806 (defvar super-classes)
5808 (defun idlwave-complete (&optional arg module class)
5809 "Complete a function, procedure or keyword name at point.
5810 This function is smart and figures out what can be completed
5811 at this point.
5812 - At the beginning of a statement it completes procedure names.
5813 - In the middle of a statement it completes function names.
5814 - After a `(' or `,' in the argument list of a function or procedure,
5815 it completes a keyword of the relevant function or procedure.
5816 - In the first arg of `OBJ_NEW', it completes a class name.
5818 When several completions are possible, a list will be displayed in
5819 the *Completions* buffer. If this list is too long to fit into the
5820 window, scrolling can be achieved by repeatedly pressing
5821 \\[idlwave-complete].
5823 The function also knows about object methods. When it needs a class
5824 name, the action depends upon `idlwave-query-class', which see. You
5825 can force IDLWAVE to ask you for a class name with a
5826 \\[universal-argument] prefix argument to this command.
5828 See also the variables `idlwave-keyword-completion-adds-equal' and
5829 `idlwave-function-completion-adds-paren'.
5831 The optional ARG can be used to specify the completion type in order
5832 to override IDLWAVE's idea of what should be completed at point.
5833 Possible values are:
5835 0 <=> query for the completion type
5836 1 <=> `procedure'
5837 2 <=> `procedure-keyword'
5838 3 <=> `function'
5839 4 <=> `function-keyword'
5840 5 <=> `procedure-method'
5841 6 <=> `procedure-method-keyword'
5842 7 <=> `function-method'
5843 8 <=> `function-method-keyword'
5844 9 <=> `class'
5846 As a special case, the universal argument C-u forces completion of
5847 function names in places where the default would be a keyword.
5849 Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5850 completion.
5852 For Lisp programmers only:
5853 When we force a keyword, optional argument MODULE can contain the module name.
5854 When we force a method or a method keyword, CLASS can specify the class."
5855 (interactive "P")
5856 (idlwave-routines)
5857 (let* ((where-list
5858 (if (and arg
5859 (or (and (integerp arg) (not (equal arg '(16))))
5860 (symbolp arg)))
5861 (idlwave-make-force-complete-where-list arg module class)
5862 (idlwave-where)))
5863 (what (nth 2 where-list))
5864 (idlwave-force-class-query (equal arg '(4)))
5865 (completion-regexp-list
5866 (if (equal arg '(16))
5867 (list (read-string (concat "Completion Regexp: "))))))
5869 (if (and module (string-match "::" module))
5870 (setq class (substring module 0 (match-beginning 0))
5871 module (substring module (match-end 0))))
5873 (cond
5875 ((and (null arg)
5876 (eq (car-safe last-command) 'idlwave-display-completion-list)
5877 (get-buffer-window "*Completions*"))
5878 (setq this-command last-command)
5879 (idlwave-scroll-completions))
5881 ;; Complete a filename in quotes
5882 ((and (idlwave-in-quote)
5883 (not (eq what 'class)))
5884 (idlwave-complete-filename))
5886 ;; Check for any special completion functions
5887 ((and idlwave-complete-special
5888 (idlwave-call-special idlwave-complete-special)))
5890 ((null what)
5891 (error "Nothing to complete here"))
5893 ;; Complete a class
5894 ((eq what 'class)
5895 (setq idlwave-completion-help-info '(class))
5896 (idlwave-complete-class))
5898 ((eq what 'procedure)
5899 ;; Complete a procedure name
5900 (let* ((cw-list (nth 3 where-list))
5901 (class-selector (idlwave-determine-class cw-list 'pro))
5902 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5903 (idlwave-all-class-inherits class-selector)))
5904 (isa (concat "procedure" (if class-selector "-method" "")))
5905 (type-selector 'pro))
5906 (setq idlwave-completion-help-info
5907 (list 'routine nil type-selector class-selector nil super-classes))
5908 (idlwave-complete-in-buffer
5909 'procedure (if class-selector 'method 'routine)
5910 (idlwave-routines) 'idlwave-selector
5911 (format "Select a %s name%s"
5913 (if class-selector
5914 (format " (class is %s)"
5915 (if (eq class-selector t)
5916 "unknown" class-selector))
5917 ""))
5919 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5921 ((eq what 'function)
5922 ;; Complete a function name
5923 (let* ((cw-list (nth 3 where-list))
5924 (class-selector (idlwave-determine-class cw-list 'fun))
5925 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5926 (idlwave-all-class-inherits class-selector)))
5927 (isa (concat "function" (if class-selector "-method" "")))
5928 (type-selector 'fun))
5929 (setq idlwave-completion-help-info
5930 (list 'routine nil type-selector class-selector nil super-classes))
5931 (idlwave-complete-in-buffer
5932 'function (if class-selector 'method 'routine)
5933 (idlwave-routines) 'idlwave-selector
5934 (format "Select a %s name%s"
5936 (if class-selector
5937 (format " (class is %s)"
5938 (if (eq class-selector t)
5939 "unknown" class-selector))
5940 ""))
5942 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
5944 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5945 (equal arg '(4)))
5946 (idlwave-complete 3))
5948 ((eq what 'procedure-keyword)
5949 ;; Complete a procedure keyword
5950 (let* ((where (nth 3 where-list))
5951 (name (car where))
5952 (method-selector name)
5953 (type-selector 'pro)
5954 (class (idlwave-determine-class where 'pro))
5955 (class-selector class)
5956 (super-classes (idlwave-all-class-inherits class-selector))
5957 (isa (format "procedure%s-keyword" (if class "-method" "")))
5958 (entry (idlwave-best-rinfo-assq
5959 name 'pro class (idlwave-routines)))
5960 (system (if entry (eq (car (nth 3 entry)) 'system)))
5961 (list (idlwave-entry-keywords entry 'do-link)))
5962 (unless (or entry (eq class t))
5963 (error "Nothing known about procedure %s"
5964 (idlwave-make-full-name class name)))
5965 (setq list (idlwave-fix-keywords name 'pro class list
5966 super-classes system))
5967 (unless list (error "No keywords available for procedure %s"
5968 (idlwave-make-full-name class name)))
5969 (setq idlwave-completion-help-info
5970 (list 'keyword name type-selector class-selector entry super-classes))
5971 (idlwave-complete-in-buffer
5972 'keyword 'keyword list nil
5973 (format "Select keyword for procedure %s%s"
5974 (idlwave-make-full-name class name)
5975 (if (or (member '("_EXTRA") list)
5976 (member '("_REF_EXTRA") list))
5977 " (note _EXTRA)" ""))
5979 'idlwave-attach-keyword-classes)))
5981 ((eq what 'function-keyword)
5982 ;; Complete a function keyword
5983 (let* ((where (nth 3 where-list))
5984 (name (car where))
5985 (method-selector name)
5986 (type-selector 'fun)
5987 (class (idlwave-determine-class where 'fun))
5988 (class-selector class)
5989 (super-classes (idlwave-all-class-inherits class-selector))
5990 (isa (format "function%s-keyword" (if class "-method" "")))
5991 (entry (idlwave-best-rinfo-assq
5992 name 'fun class (idlwave-routines)))
5993 (system (if entry (eq (car (nth 3 entry)) 'system)))
5994 (list (idlwave-entry-keywords entry 'do-link))
5995 msg-name)
5996 (unless (or entry (eq class t))
5997 (error "Nothing known about function %s"
5998 (idlwave-make-full-name class name)))
5999 (setq list (idlwave-fix-keywords name 'fun class list
6000 super-classes system))
6001 ;; OBJ_NEW: Messages mention the proper Init method
6002 (setq msg-name (if (and (null class)
6003 (string= (upcase name) "OBJ_NEW"))
6004 (concat idlwave-current-obj_new-class
6005 "::Init (via OBJ_NEW)")
6006 (idlwave-make-full-name class name)))
6007 (unless list (error "No keywords available for function %s"
6008 msg-name))
6009 (setq idlwave-completion-help-info
6010 (list 'keyword name type-selector class-selector nil super-classes))
6011 (idlwave-complete-in-buffer
6012 'keyword 'keyword list nil
6013 (format "Select keyword for function %s%s" msg-name
6014 (if (or (member '("_EXTRA") list)
6015 (member '("_REF_EXTRA") list))
6016 " (note _EXTRA)" ""))
6018 'idlwave-attach-keyword-classes)))
6020 (t (error "This should not happen (idlwave-complete)")))))
6022 (defvar idlwave-complete-special nil
6023 "List of special completion functions.
6024 These functions are called for each completion. Each function must
6025 check if its own special completion context is present. If yes, it
6026 should use `idlwave-complete-in-buffer' to do some completion and
6027 return t. If such a function returns t, *no further* attempts to
6028 complete other contexts will be done. If the function returns nil,
6029 other completions will be tried.")
6031 (defun idlwave-call-special (functions &rest args)
6032 (let ((funcs functions)
6033 fun ret)
6034 (catch 'exit
6035 (while (setq fun (pop funcs))
6036 (if (setq ret (apply fun args))
6037 (throw 'exit ret)))
6038 nil)))
6040 (defun idlwave-make-force-complete-where-list (what &optional module class)
6041 ;; Return an artificial WHERE specification to force the completion
6042 ;; routine to complete a specific item independent of context.
6043 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6044 ;; MODULE and CLASS can be used to specify the routine name and class.
6045 ;; The class name will also be found in MODULE if that is like "class::mod".
6046 (let* ((what-list '(("procedure") ("procedure-keyword")
6047 ("function") ("function-keyword")
6048 ("procedure-method") ("procedure-method-keyword")
6049 ("function-method") ("function-method-keyword")
6050 ("class")))
6051 (module (idlwave-sintern-routine-or-method module class))
6052 (class (idlwave-sintern-class class))
6053 (what (cond
6054 ((equal what 0)
6055 (setq what
6056 (intern (completing-read
6057 "Complete what? " what-list nil t))))
6058 ((integerp what)
6059 (setq what (intern (car (nth (1- what) what-list)))))
6060 ((and what
6061 (symbolp what)
6062 (assoc (symbol-name what) what-list))
6063 what)
6064 (t (error "Invalid WHAT"))))
6065 (nil-list '(nil nil nil nil))
6066 (class-list (list nil nil (or class t) nil)))
6068 (cond
6070 ((eq what 'procedure)
6071 (list nil-list nil-list 'procedure nil-list nil))
6073 ((eq what 'procedure-keyword)
6074 (let* ((class-selector nil)
6075 (super-classes nil)
6076 (type-selector 'pro)
6077 (pro (or module
6078 (idlwave-completing-read
6079 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6080 (setq pro (idlwave-sintern-routine pro))
6081 (list nil-list nil-list 'procedure-keyword
6082 (list pro nil nil nil) nil)))
6084 ((eq what 'function)
6085 (list nil-list nil-list 'function nil-list nil))
6087 ((eq what 'function-keyword)
6088 (let* ((class-selector nil)
6089 (super-classes nil)
6090 (type-selector 'fun)
6091 (func (or module
6092 (idlwave-completing-read
6093 "Function: " (idlwave-routines) 'idlwave-selector))))
6094 (setq func (idlwave-sintern-routine func))
6095 (list nil-list nil-list 'function-keyword
6096 (list func nil nil nil) nil)))
6098 ((eq what 'procedure-method)
6099 (list nil-list nil-list 'procedure class-list nil))
6101 ((eq what 'procedure-method-keyword)
6102 (let* ((class (idlwave-determine-class class-list 'pro))
6103 (class-selector class)
6104 (super-classes (idlwave-all-class-inherits class-selector))
6105 (type-selector 'pro)
6106 (pro (or module
6107 (idlwave-completing-read
6108 (format "Procedure in %s class: " class-selector)
6109 (idlwave-routines) 'idlwave-selector))))
6110 (setq pro (idlwave-sintern-method pro))
6111 (list nil-list nil-list 'procedure-keyword
6112 (list pro nil class nil) nil)))
6114 ((eq what 'function-method)
6115 (list nil-list nil-list 'function class-list nil))
6117 ((eq what 'function-method-keyword)
6118 (let* ((class (idlwave-determine-class class-list 'fun))
6119 (class-selector class)
6120 (super-classes (idlwave-all-class-inherits class-selector))
6121 (type-selector 'fun)
6122 (func (or module
6123 (idlwave-completing-read
6124 (format "Function in %s class: " class-selector)
6125 (idlwave-routines) 'idlwave-selector))))
6126 (setq func (idlwave-sintern-method func))
6127 (list nil-list nil-list 'function-keyword
6128 (list func nil class nil) nil)))
6130 ((eq what 'class)
6131 (list nil-list nil-list 'class nil-list nil))
6133 (t (error "Invalid value for WHAT")))))
6135 (defun idlwave-completing-read (&rest args)
6136 ;; Completing read, case insensitive
6137 (let ((old-value (default-value 'completion-ignore-case)))
6138 (unwind-protect
6139 (progn
6140 (setq-default completion-ignore-case t)
6141 (apply 'completing-read args))
6142 (setq-default completion-ignore-case old-value))))
6144 (defvar idlwave-shell-default-directory)
6145 (defun idlwave-complete-filename ()
6146 "Use the comint stuff to complete a file name."
6147 (require 'comint)
6148 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6149 (comint-completion-addsuffix nil)
6150 (default-directory
6151 (if (and (boundp 'idlwave-shell-default-directory)
6152 (stringp idlwave-shell-default-directory)
6153 (file-directory-p idlwave-shell-default-directory))
6154 idlwave-shell-default-directory
6155 default-directory)))
6156 (comint-dynamic-complete-filename)))
6158 (defun idlwave-make-full-name (class name)
6159 ;; Make a fully qualified module name including the class name
6160 (concat (if class (format "%s::" class) "") name))
6162 (defun idlwave-rinfo-assoc (name type class list)
6163 "Like `idlwave-rinfo-assq', but sintern strings first."
6164 (idlwave-rinfo-assq
6165 (idlwave-sintern-routine-or-method name class)
6166 type (idlwave-sintern-class class) list))
6168 (defun idlwave-rinfo-assq (name type class list)
6169 ;; Works like assq, but also checks type and class
6170 (catch 'exit
6171 (let (match)
6172 (while (setq match (assq name list))
6173 (and (or (eq type t)
6174 (eq (nth 1 match) type))
6175 (eq (nth 2 match) class)
6176 (throw 'exit match))
6177 (setq list (cdr (memq match list)))))))
6179 (defun idlwave-rinfo-assq-any-class (name type class list)
6180 ;; Return the first matching method on the inheritance list
6181 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6182 class rtn)
6183 (while classes
6184 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6185 (setq classes nil)))
6186 rtn))
6188 (defun idlwave-best-rinfo-assq (name type class list &optional with-file
6189 keep-system)
6190 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6191 If WITH-FILE is passed, find the best rinfo entry with a file
6192 included. If KEEP-SYSTEM is set, don't prune system for compiled
6193 syslib files."
6194 (let ((twins (idlwave-routine-twins
6195 (idlwave-rinfo-assq-any-class name type class list)
6196 list))
6197 syslibp)
6198 (when (> (length twins) 1)
6199 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
6200 (if (and (null keep-system)
6201 (eq 'system (car (nth 3 (car twins))))
6202 (setq syslibp (idlwave-any-syslib (cdr twins)))
6203 (not (equal 1 syslibp)))
6204 ;; Its a compiled syslib, so we need to remove the system entry
6205 (setq twins (cdr twins)))
6206 (if with-file
6207 (setq twins (delq nil
6208 (mapcar (lambda (x)
6209 (if (nth 1 (nth 3 x)) x))
6210 twins)))))
6211 (car twins)))
6213 (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
6214 keep-system)
6215 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6216 (idlwave-best-rinfo-assq
6217 (idlwave-sintern-routine-or-method name class)
6218 type (idlwave-sintern-class class) list with-file keep-system))
6220 (defun idlwave-any-syslib (entries)
6221 "Does the entry list ENTRIES contain a syslib entry?
6222 If yes, return the index (>=1)."
6223 (let (file (cnt 0))
6224 (catch 'exit
6225 (while entries
6226 (incf cnt)
6227 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6228 (if (and file (idlwave-syslib-p file))
6229 (throw 'exit cnt)
6230 (setq entries (cdr entries))))
6231 nil)))
6233 (defun idlwave-all-assq (key list)
6234 "Return a list of all associations of Key in LIST."
6235 (let (rtn elt)
6236 (while (setq elt (assq key list))
6237 (push elt rtn)
6238 (setq list (cdr (memq elt list))))
6239 (nreverse rtn)))
6241 (defun idlwave-all-method-classes (method &optional type)
6242 "Return all classes which have a method METHOD.
6243 TYPE is `fun' or `pro'.
6244 When TYPE is not specified, both procedures and functions will be considered."
6245 (if (null method)
6246 (mapcar 'car (idlwave-class-alist))
6247 (let (rtn)
6248 (mapc (lambda (x)
6249 (and (nth 2 x)
6250 (or (not type)
6251 (eq type (nth 1 x)))
6252 (push (nth 2 x) rtn)))
6253 (idlwave-all-assq method (idlwave-routines)))
6254 (idlwave-uniquify rtn))))
6256 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
6257 "Return all classes which have a method METHOD with keyword KEYWORD.
6258 TYPE is `fun' or `pro'.
6259 When TYPE is not specified, both procedures and functions will be considered."
6260 (if (or (null method)
6261 (null keyword))
6263 (let (rtn)
6264 (mapc (lambda (x)
6265 (and (nth 2 x) ; non-nil class
6266 (or (not type) ; correct or unspecified type
6267 (eq type (nth 1 x)))
6268 (assoc keyword (idlwave-entry-keywords x))
6269 (push (nth 2 x) rtn)))
6270 (idlwave-all-assq method (idlwave-routines)))
6271 (idlwave-uniquify rtn))))
6273 (defun idlwave-members-only (list club)
6274 "Return list of all elements in LIST which are also in CLUB."
6275 (let (rtn)
6276 (while list
6277 (if (member (car list) club)
6278 (setq rtn (cons (car list) rtn)))
6279 (setq list (cdr list)))
6280 (nreverse rtn)))
6282 (defun idlwave-nonmembers-only (list club)
6283 "Return list of all elements in LIST which are not in CLUB."
6284 (let (rtn)
6285 (while list
6286 (if (member (car list) club)
6288 (setq rtn (cons (car list) rtn)))
6289 (setq list (cdr list)))
6290 (nreverse rtn)))
6292 (defun idlwave-explicit-class-listed (info)
6293 "Return whether or not the class is listed explicitly, ala a->b::c.
6294 INFO is as returned by `idlwave-what-function' or `-procedure'."
6295 (let ((apos (nth 3 info)))
6296 (if apos
6297 (save-excursion (goto-char apos)
6298 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6300 (defvar idlwave-determine-class-special nil
6301 "List of special functions for determining class.
6302 Must accept two arguments: `apos' and `info'.")
6304 (defun idlwave-determine-class (info type)
6305 ;; Determine the class of a routine call.
6306 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6307 ;; The second element in this structure is the class. When nil, we
6308 ;; return nil. When t, try to get the class from text properties at
6309 ;; the arrow. When the object is "self", we use the class of the
6310 ;; current routine. otherwise prompt the user for a class name.
6311 ;; Also stores the selected class as a text property at the arrow.
6312 ;; TYPE is 'fun or 'pro.
6313 (let* ((class (nth 2 info))
6314 (apos (nth 3 info))
6315 (nassoc (assoc (if (stringp (car info))
6316 (upcase (car info))
6317 (car info))
6318 idlwave-query-class))
6319 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6320 idlwave-query-class))
6321 (query (cond (nassoc (cdr nassoc))
6322 (dassoc (cdr dassoc))
6323 (t t)))
6324 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
6325 (is-self
6326 (and arrow
6327 (save-excursion (goto-char apos)
6328 (forward-word-strictly -1)
6329 (let ((case-fold-search t))
6330 (looking-at "self\\>")))))
6331 (force-query idlwave-force-class-query)
6332 store special-class class-alist)
6333 (cond
6334 ((null class) nil)
6335 ((eq t class)
6336 ;; There is an object which would like to know its class
6337 (if (and arrow (get-text-property apos 'idlwave-class)
6338 idlwave-store-inquired-class
6339 (not force-query))
6340 (setq class (get-text-property apos 'idlwave-class)
6341 class (idlwave-sintern-class class)))
6342 (if (and (eq t class) is-self)
6343 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6345 ;; Before prompting, try any special class determination routines
6346 (when (and (eq t class)
6347 idlwave-determine-class-special
6348 (not force-query))
6349 (setq special-class
6350 (idlwave-call-special idlwave-determine-class-special apos))
6351 (if special-class
6352 (setq class (idlwave-sintern-class special-class)
6353 store idlwave-store-inquired-class)))
6355 ;; Prompt for a class, if we need to
6356 (when (and (eq class t)
6357 (or force-query query))
6358 (setq class-alist
6359 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6360 (setq class
6361 (idlwave-sintern-class
6362 (cond
6363 ((and (= (length class-alist) 0) (not force-query))
6364 (error "No classes available with method %s" (car info)))
6365 ((and (= (length class-alist) 1) (not force-query))
6366 (car (car class-alist)))
6368 (setq store idlwave-store-inquired-class)
6369 (idlwave-completing-read
6370 (format "Class%s: " (if (stringp (car info))
6371 (format " for %s method %s"
6372 type (car info))
6373 ""))
6374 class-alist nil nil nil 'idlwave-class-history))))))
6376 ;; Store it, if requested
6377 (when (and class (not (eq t class)))
6378 ;; We have a real class here
6379 (when (and store arrow)
6380 (condition-case ()
6381 (add-text-properties
6382 apos (+ apos 2)
6383 `(idlwave-class ,class face ,idlwave-class-arrow-face
6384 rear-nonsticky t))
6385 (error nil)))
6386 (setf (nth 2 info) class))
6387 ;; Return the class
6388 class)
6389 ;; Default as fallback
6390 (t class))))
6392 (defun idlwave-selector (a)
6393 (and (eq (nth 1 a) type-selector)
6394 (or (and (nth 2 a) (eq class-selector t))
6395 (eq (nth 2 a) class-selector)
6396 (memq (nth 2 a) super-classes))))
6398 (defun idlwave-add-file-link-selector (a)
6399 ;; Record a file link, if any, for the tested names during selection.
6400 (let ((sel (idlwave-selector a)) file)
6401 (if (and sel (setq file (idlwave-entry-has-help a)))
6402 (push (cons (car a) file) idlwave-completion-help-links))
6403 sel))
6406 (defun idlwave-where ()
6407 "Find out where we are.
6408 The return value is a list with the following stuff:
6409 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
6411 PRO-LIST (PRO POINT CLASS ARROW)
6412 FUNC-LIST (FUNC POINT CLASS ARROW)
6413 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
6414 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
6415 be completed here.
6416 LAST-CHAR last relevant character before point (non-white non-comment,
6417 not part of current identifier or leading slash).
6419 In the lists, we have these meanings:
6420 PRO: Procedure name
6421 FUNC: Function name
6422 POINT: Where is this
6423 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
6424 ARROW: Location of the arrow"
6425 (idlwave-routines)
6426 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
6427 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
6428 (func-entry (idlwave-what-function bos))
6429 (func (car func-entry))
6430 (func-class (nth 1 func-entry))
6431 (func-arrow (nth 2 func-entry))
6432 (func-point (or (nth 3 func-entry) 0))
6433 (func-level (or (nth 4 func-entry) 0))
6434 (pro-entry (idlwave-what-procedure bos))
6435 (pro (car pro-entry))
6436 (pro-class (nth 1 pro-entry))
6437 (pro-arrow (nth 2 pro-entry))
6438 (pro-point (or (nth 3 pro-entry) 0))
6439 (last-char (idlwave-last-valid-char))
6440 (case-fold-search t)
6441 (match-string (buffer-substring bos (point)))
6442 cw cw-mod cw-arrow cw-class cw-point)
6443 (if (< func-point pro-point) (setq func nil))
6444 (cond
6445 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
6446 match-string)
6447 (setq cw 'class))
6448 ((string-match
6449 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
6450 (if (> pro-point 0)
6451 (buffer-substring pro-point (point))
6452 match-string))
6453 (setq cw 'procedure cw-class pro-class cw-point pro-point
6454 cw-arrow pro-arrow))
6455 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
6456 match-string)
6457 nil)
6458 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
6459 match-string)
6460 (setq cw 'class))
6461 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
6462 match-string)
6463 (setq cw 'class))
6464 ((and func
6465 (> func-point pro-point)
6466 (= func-level 1)
6467 (memq last-char '(?\( ?,)))
6468 (setq cw 'function-keyword cw-mod func cw-point func-point
6469 cw-class func-class cw-arrow func-arrow))
6470 ((and pro (eq last-char ?,))
6471 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6472 cw-class pro-class cw-arrow pro-arrow))
6473 ; ((member last-char '(?\' ?\) ?\] ?!))
6474 ; ;; after these chars, a function makes no sense
6475 ; ;; FIXME: I am sure there can be more in this list
6476 ; ;; FIXME: Do we want to do this at all?
6477 ; nil)
6478 ;; Everywhere else we try a function.
6480 (setq cw 'function)
6481 (save-excursion
6482 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
6483 (setq cw-arrow (copy-marker (match-beginning 0))
6484 cw-class (if (match-end 4)
6485 (idlwave-sintern-class (match-string 4))
6486 t))))))
6487 (list (list pro pro-point pro-class pro-arrow)
6488 (list func func-point func-class func-arrow)
6490 (list cw-mod cw-point cw-class cw-arrow)
6491 last-char)))
6493 (defun idlwave-this-word (&optional class)
6494 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
6495 (setq class (or class "a-zA-Z0-9$_."))
6496 (save-excursion
6497 (buffer-substring
6498 (progn (skip-chars-backward class) (point))
6499 (progn (skip-chars-forward class) (point)))))
6501 (defun idlwave-what-function (&optional bound)
6502 ;; Find out if point is within the argument list of a function.
6503 ;; The return value is ("function-name" class arrow-start (point) level).
6504 ;; Level is 1 on the top level parentheses, higher further down.
6506 ;; If the optional BOUND is an integer, bound backwards directed
6507 ;; searches to this point.
6509 (catch 'exit
6510 (let (pos
6511 func-point
6512 (cnt 0)
6513 func arrow-start class)
6514 (idlwave-with-special-syntax
6515 (save-restriction
6516 (save-excursion
6517 (narrow-to-region (max 1 (or bound 0)) (point-max))
6518 ;; move back out of the current parenthesis
6519 (while (condition-case nil
6520 (progn (up-list -1) t)
6521 (error nil))
6522 (setq pos (point))
6523 (incf cnt)
6524 (when (and (= (following-char) ?\()
6525 (re-search-backward
6526 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6527 bound t))
6528 (setq func (match-string 2)
6529 func-point (goto-char (match-beginning 2))
6530 pos func-point)
6531 (if (re-search-backward
6532 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
6533 (setq arrow-start (copy-marker (match-beginning 0))
6534 class (or (match-string 2) t)))
6535 (throw
6536 'exit
6537 (list
6538 (idlwave-sintern-routine-or-method func class)
6539 (idlwave-sintern-class class)
6540 arrow-start func-point cnt)))
6541 (goto-char pos))
6542 (throw 'exit nil)))))))
6544 (defun idlwave-what-procedure (&optional bound)
6545 ;; Find out if point is within the argument list of a procedure.
6546 ;; The return value is ("procedure-name" class arrow-pos (point)).
6548 ;; If the optional BOUND is an integer, bound backwards directed
6549 ;; searches to this point.
6550 (let ((pos (point)) pro-point
6551 pro class arrow-start string)
6552 (save-excursion
6553 ;;(idlwave-beginning-of-statement)
6554 (idlwave-start-of-substatement 'pre)
6555 (setq string (buffer-substring (point) pos))
6556 (if (string-match
6557 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6558 (setq pro (match-string 1 string)
6559 pro-point (+ (point) (match-beginning 1)))
6560 (if (and (idlwave-skip-object)
6561 (setq string (buffer-substring (point) pos))
6562 (string-match
6563 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
6564 string))
6565 (setq pro (if (match-beginning 4)
6566 (match-string 4 string))
6567 pro-point (if (match-beginning 4)
6568 (+ (point) (match-beginning 4))
6569 pos)
6570 arrow-start (copy-marker (+ (point) (match-beginning 1)))
6571 class (or (match-string 3 string) t)))))
6572 (list (idlwave-sintern-routine-or-method pro class)
6573 (idlwave-sintern-class class)
6574 arrow-start
6575 pro-point)))
6577 (defun idlwave-skip-object ()
6578 ;; If there is an object at point, move over it and return t.
6579 (let ((pos (point)))
6580 (if (catch 'exit
6581 (save-excursion
6582 (skip-chars-forward " ") ; white space
6583 (skip-chars-forward "*") ; de-reference
6584 (cond
6585 ((looking-at idlwave-identifier)
6586 (goto-char (match-end 0)))
6587 ((eq (following-char) ?\()
6588 nil)
6589 (t (throw 'exit nil)))
6590 (catch 'endwhile
6591 (while t
6592 (cond ((eq (following-char) ?.)
6593 (forward-char 1)
6594 (if (not (looking-at idlwave-identifier))
6595 (throw 'exit nil))
6596 (goto-char (match-end 0)))
6597 ((memq (following-char) '(?\( ?\[))
6598 (condition-case nil
6599 (forward-list 1)
6600 (error (throw 'exit nil))))
6601 (t (throw 'endwhile t)))))
6602 (if (looking-at "[ \t]*->")
6603 (throw 'exit (setq pos (match-beginning 0)))
6604 (throw 'exit nil))))
6605 (goto-char pos)
6606 nil)))
6608 (defun idlwave-last-valid-char ()
6609 "Return the last character before point which is not white or a comment
6610 and also not part of the current identifier. Since we do this in
6611 order to identify places where keywords are, we consider the initial
6612 `/' of a keyword as part of the identifier.
6613 This function is not general, can only be used for completion stuff."
6614 (catch 'exit
6615 (save-excursion
6616 ;; skip the current identifier
6617 (skip-chars-backward "a-zA-Z0-9_$")
6618 ;; also skip a leading slash which might be belong to the keyword
6619 (if (eq (preceding-char) ?/)
6620 (backward-char 1))
6621 ;; FIXME: does not check if this is a valid identifier
6622 (while t
6623 (skip-chars-backward " \t")
6624 (cond
6625 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6626 ((eq (preceding-char) ?\n)
6627 (beginning-of-line 0)
6628 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
6629 ;; continuation line
6630 (goto-char (match-end 1))
6631 (throw 'exit nil)))
6632 (t (throw 'exit (preceding-char))))))))
6634 (defvar idlwave-complete-after-success-form nil
6635 "A form to evaluate after successful completion.")
6636 (defvar idlwave-complete-after-success-form-force nil
6637 "A form to evaluate after completion selection in *Completions* buffer.")
6638 (defconst idlwave-completion-mark (make-marker)
6639 "A mark pointing to the beginning of the completion string.")
6640 (defvar completion-highlight-first-word-only) ;XEmacs.
6642 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
6643 &optional prepare-display-function
6644 special-selector)
6645 "Perform TYPE completion of word before point against LIST.
6646 SELECTOR is the PREDICATE argument for the completion function. Show
6647 PROMPT in echo area. TYPE is one of the intern types, e.g., `function',
6648 `procedure', `class-tag', `keyword', `sysvar'. SPECIAL-SELECTOR is
6649 used only once, for `all-completions', and can be used to, e.g.,
6650 accumulate information on matching completions."
6651 (let* ((completion-ignore-case t)
6652 beg (end (point)) slash part spart completion all-completions
6653 dpart dcompletion)
6655 (unless list
6656 (error (concat prompt ": No completions available")))
6658 ;; What is already in the buffer?
6659 (save-excursion
6660 (skip-chars-backward "a-zA-Z0-9_$")
6661 (setq slash (eq (preceding-char) ?/)
6662 beg (point)
6663 idlwave-complete-after-success-form
6664 (list 'idlwave-after-successful-completion
6665 (list 'quote type) slash beg)
6666 idlwave-complete-after-success-form-force
6667 (list 'idlwave-after-successful-completion
6668 (list 'quote type) slash (list 'quote 'force))))
6670 ;; Try a completion
6671 (setq part (buffer-substring beg end)
6672 dpart (downcase part)
6673 spart (idlwave-sintern stype part)
6674 completion (try-completion part list selector)
6675 dcompletion (if (stringp completion) (downcase completion))
6676 idlwave-completion-help-links nil)
6677 (cond
6678 ((null completion)
6679 ;; nothing available.
6680 (error (concat prompt ": no completion for \"%s\"") part))
6681 ((and (not (equal dpart dcompletion))
6682 (not (eq t completion)))
6683 ;; We can add something
6684 (delete-region beg end)
6685 (insert (if (and (string= part dpart)
6686 (or (not (string= part ""))
6687 idlwave-complete-empty-string-as-lower-case)
6688 (not idlwave-completion-force-default-case))
6689 dcompletion
6690 completion))
6691 (if (eq t (try-completion completion list selector))
6692 ;; Now this is a unique match
6693 (idlwave-after-successful-completion type slash beg))
6695 ((or (eq completion t)
6696 (and (= 1 (length (setq all-completions
6697 (idlwave-uniquify
6698 (all-completions part list
6699 (or special-selector
6700 selector))))))
6701 (equal dpart dcompletion)))
6702 ;; This is already complete
6703 (idlwave-after-successful-completion type slash beg)
6704 (message "%s is already the complete %s" part isa)
6705 nil)
6707 ;; We cannot add something - offer a list.
6708 (message "Making completion list...")
6710 (unless idlwave-completion-help-links ; already set somewhere?
6711 (mapc (lambda (x) ; Pass link prop through to highlight-linked
6712 (let ((link (get-text-property 0 'link (car x))))
6713 (if link
6714 (push (cons (car x) link)
6715 idlwave-completion-help-links))))
6716 list))
6717 (let* ((list all-completions)
6718 ;; "complete" means, this is already a valid completion
6719 (complete (memq spart all-completions))
6720 (completion-highlight-first-word-only t)) ; XEmacs
6721 ;; (completion-fixup-function ; Emacs
6722 ;; (lambda () (and (eq (preceding-char) ?>)
6723 ;; (re-search-backward " <" beg t)))))
6725 (setq list (sort list (lambda (a b)
6726 (string< (downcase a) (downcase b)))))
6727 (if prepare-display-function
6728 (setq list (funcall prepare-display-function list)))
6729 (if (and (string= part dpart)
6730 (or (not (string= part ""))
6731 idlwave-complete-empty-string-as-lower-case)
6732 (not idlwave-completion-force-default-case))
6733 (setq list (mapcar (lambda (x)
6734 (if (listp x)
6735 (setcar x (downcase (car x)))
6736 (setq x (downcase x)))
6738 list)))
6739 (idlwave-display-completion-list list prompt beg complete))
6740 t))))
6742 (defun idlwave-complete-class ()
6743 "Complete a class at point."
6744 (interactive)
6745 ;; Call `idlwave-routines' to make sure the class list will be available
6746 (idlwave-routines)
6747 ;; Check for the special case of completing empty string after pro/function
6748 (if (let ((case-fold-search t))
6749 (save-excursion
6750 (and
6751 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6752 (- (point) 15) t)
6753 (goto-char (point-min))
6754 (re-search-forward
6755 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6756 ;; Yank the full class specification
6757 (insert (match-string 2))
6758 ;; Do the completion, using list gathered from `idlwave-routines'
6759 (idlwave-complete-in-buffer
6760 'class 'class (idlwave-class-alist) nil
6761 "Select a class" "class"
6762 (lambda (list) ;; Push it to help-links if system help available
6763 (mapcar (lambda (x)
6764 (let* ((entry (idlwave-class-info x))
6765 (link (nth 1 (assq 'link entry))))
6766 (if link (push (cons x link)
6767 idlwave-completion-help-links))
6769 list)))))
6771 (defun idlwave-attach-classes (list type show-classes)
6772 ;; Attach the proper class list to a LIST of completion items.
6773 ;; TYPE, when 'kwd, shows classes for method keywords, when
6774 ;; 'class-tag, for class tags, and otherwise for methods.
6775 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
6776 (if (or (null show-classes) ; don't want to see classes
6777 (null class-selector) ; not a method call
6778 (and
6779 (stringp class-selector) ; the class is already known
6780 (not super-classes))) ; no possibilities for inheritance
6781 ;; In these cases, we do not have to do anything
6782 list
6783 (let* ((do-prop (and (>= show-classes 0)
6784 (>= emacs-major-version 21)))
6785 (do-buf (not (= show-classes 0)))
6786 ;; (do-dots (featurep 'xemacs))
6787 (do-dots t)
6788 (inherit (if (and (not (eq type 'class-tag)) super-classes)
6789 (cons class-selector super-classes)))
6790 (max (abs show-classes))
6791 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6792 classes nclasses class-info space)
6793 (mapcar
6794 (lambda (x)
6795 ;; get the classes
6796 (if (eq type 'class-tag)
6797 ;; Just one class for tags
6798 (setq classes
6799 (list
6800 (idlwave-class-or-superclass-with-tag class-selector x)))
6801 ;; Multiple classes for method or method-keyword
6802 (setq classes
6803 (if (eq type 'kwd)
6804 (idlwave-all-method-keyword-classes
6805 method-selector x type-selector)
6806 (idlwave-all-method-classes x type-selector)))
6807 (if inherit
6808 (setq classes
6809 (delq nil
6810 (mapcar (lambda (x) (if (memq x inherit) x nil))
6811 classes)))))
6812 (setq nclasses (length classes))
6813 ;; Make the separator between item and class-info
6814 (if do-dots
6815 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6816 (setq space " "))
6817 (if do-buf
6818 ;; We do want info in the buffer
6819 (if (<= nclasses max)
6820 (setq class-info (concat
6821 space
6822 "<" (mapconcat 'identity classes ",") ">"))
6823 (setq class-info (format "%s<%d classes>" space nclasses)))
6824 (setq class-info nil))
6825 (when do-prop
6826 ;; We do want properties
6827 (setq x (copy-sequence x))
6828 (put-text-property 0 (length x)
6829 'help-echo (mapconcat 'identity classes " ")
6831 (if class-info
6832 (list x class-info)
6834 list))))
6836 (defun idlwave-attach-method-classes (list)
6837 ;; Call idlwave-attach-classes with method parameters
6838 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
6839 (defun idlwave-attach-keyword-classes (list)
6840 ;; Call idlwave-attach-classes with keyword parameters
6841 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6842 (defun idlwave-attach-class-tag-classes (list)
6843 ;; Call idlwave-attach-classes with class structure tags
6844 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
6847 ;;----------------------------------------------------------------------
6848 ;;----------------------------------------------------------------------
6849 ;;----------------------------------------------------------------------
6850 ;;----------------------------------------------------------------------
6851 ;;----------------------------------------------------------------------
6852 (when (featurep 'xemacs)
6853 (defvar rtn)
6854 (defun idlwave-pset (item)
6855 (set 'rtn item)))
6857 (defun idlwave-popup-select (ev list title &optional sort)
6858 "Select an item in LIST with a popup menu.
6859 TITLE is the title to put atop the popup. If SORT is non-nil,
6860 sort the list before displaying."
6861 (let ((maxpopup idlwave-max-popup-menu-items)
6862 rtn menu)
6863 (cond ((null list))
6864 ((= 1 (length list))
6865 (setq rtn (car list)))
6866 ((featurep 'xemacs)
6867 (if sort (setq list (sort list (lambda (a b)
6868 (string< (upcase a) (upcase b))))))
6869 (setq menu
6870 (append (list title)
6871 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6872 x)))
6873 list)))
6874 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6875 (let ((resp (get-popup-menu-response menu)))
6876 (funcall (event-function resp) (event-object resp))))
6878 (if sort (setq list (sort list (lambda (a b)
6879 (string< (upcase a) (upcase b))))))
6880 (setq menu (cons title
6881 (list
6882 (append (list "")
6883 (mapcar (lambda(x) (cons x x)) list)))))
6884 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6885 (setq rtn (x-popup-menu ev menu))))
6886 rtn))
6888 (defun idlwave-split-menu-xemacs (menu N)
6889 "Split the MENU into submenus of maximum length N."
6890 (if (<= (length menu) (1+ N))
6891 ;; No splitting needed
6892 menu
6893 (let* ((title (car menu))
6894 (entries (cdr menu))
6895 (menu (list title))
6896 (cnt 0)
6897 (nextmenu nil))
6898 (while entries
6899 (while (and entries (< cnt N))
6900 (setq cnt (1+ cnt)
6901 nextmenu (cons (car entries) nextmenu)
6902 entries (cdr entries)))
6903 (setq nextmenu (nreverse nextmenu))
6904 (setq nextmenu (cons (format "%s...%s"
6905 (aref (car nextmenu) 0)
6906 (aref (nth (1- cnt) nextmenu) 0))
6907 nextmenu))
6908 (setq menu (cons nextmenu menu)
6909 nextmenu nil
6910 cnt 0))
6911 (nreverse menu))))
6913 (defun idlwave-split-menu-emacs (menu N)
6914 "Split the MENU into submenus of maximum length N."
6915 (if (<= (length (nth 1 menu)) (1+ N))
6916 ;; No splitting needed
6917 menu
6918 (let* ((title (car menu))
6919 (entries (cdr (nth 1 menu)))
6920 (menu nil)
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 (prin1 nextmenu)
6930 (setq nextmenu (cons (format "%s...%s"
6931 (car (car nextmenu))
6932 (car (nth (1- cnt) nextmenu)))
6933 nextmenu))
6934 (setq menu (cons nextmenu menu)
6935 nextmenu nil
6936 cnt 0))
6937 (setq menu (nreverse menu))
6938 (setq menu (cons title menu))
6939 menu)))
6941 (defvar idlwave-completion-setup-hook nil)
6943 (defun idlwave-scroll-completions (&optional message)
6944 "Scroll the completion window on this frame."
6945 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6946 (win (selected-window)))
6947 (unwind-protect
6948 (progn
6949 (select-window cwin)
6950 (condition-case nil
6951 (scroll-up)
6952 (error (if (and (listp last-command)
6953 (nth 2 last-command))
6954 (progn
6955 (select-window win)
6956 (eval idlwave-complete-after-success-form))
6957 (set-window-start cwin (point-min)))))
6958 (and message (message "%s" message)))
6959 (select-window win))))
6961 (defun idlwave-display-completion-list (list &optional message beg complete)
6962 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6963 (unless (and (get-buffer-window "*Completions*")
6964 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6965 (move-marker idlwave-completion-mark beg)
6966 (setq idlwave-before-completion-wconf (current-window-configuration)))
6968 (if (featurep 'xemacs)
6969 (idlwave-display-completion-list-xemacs
6970 list)
6971 (idlwave-display-completion-list-emacs list))
6973 ;; Store a special value in `this-command'. When `idlwave-complete'
6974 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6975 (setq this-command (list 'idlwave-display-completion-list message complete))
6977 ;; Mark the completions buffer as created by cib
6978 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6980 ;; Fontify the classes
6981 (if (and idlwave-completion-fontify-classes
6982 (consp (car list)))
6983 (idlwave-completion-fontify-classes))
6985 ;; Run the hook
6986 (run-hooks 'idlwave-completion-setup-hook)
6988 ;; Display the message
6989 (message "%s" (or message "Making completion list...done")))
6991 (defun idlwave-choose (function &rest args)
6992 "Call FUNCTION as a completion chooser and pass ARGS to it."
6993 (let ((completion-ignore-case t)) ; install correct value
6994 (apply function args))
6995 (if (and (derived-mode-p 'idlwave-shell-mode)
6996 (boundp 'font-lock-mode)
6997 (not font-lock-mode))
6998 ;; For the shell, remove the fontification of the word before point
6999 (let ((beg (save-excursion
7000 (skip-chars-backward "a-zA-Z0-9_")
7001 (point))))
7002 (remove-text-properties beg (point) '(face nil))))
7003 (eval idlwave-complete-after-success-form-force))
7005 (defun idlwave-keyboard-quit ()
7006 (interactive)
7007 (unwind-protect
7008 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7009 (idlwave-restore-wconf-after-completion))
7010 (keyboard-quit)))
7012 (defun idlwave-restore-wconf-after-completion ()
7013 "Restore the old (before completion) window configuration."
7014 (and idlwave-completion-restore-window-configuration
7015 idlwave-before-completion-wconf
7016 (set-window-configuration idlwave-before-completion-wconf)))
7018 (defun idlwave-one-key-select (sym prompt delay)
7019 "Make the user select an element from the alist in the variable SYM.
7020 The keys of the alist are expected to be strings. The function returns the
7021 car of the selected association.
7022 To do this, PROMPT is displayed and the user must hit a letter key to
7023 select an entry. If the user does not reply within DELAY seconds, a help
7024 window with the options is displayed automatically.
7025 The key which is associated with each option is generated automatically.
7026 First, the strings are checked for preselected keys, like in \"[P]rint\".
7027 If these don't exist, a letter in the string is automatically selected."
7028 (let* ((alist (symbol-value sym))
7029 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7030 '(fit-window-to-buffer)))
7031 keys-alist char)
7032 ;; First check the cache
7033 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7034 (setq keys-alist (get sym :one-key-alist-cache))
7035 ;; Need to make new list
7036 (setq keys-alist (idlwave-make-one-key-alist alist))
7037 (put sym :one-key-alist-cache keys-alist)
7038 (put sym :one-key-alist-last alist))
7039 ;; Display prompt and wait for quick reply
7040 (message "%s[%s]" prompt
7041 (mapconcat (lambda(x) (char-to-string (car x)))
7042 keys-alist ""))
7043 (if (sit-for delay)
7044 ;; No quick reply: Show help
7045 (save-window-excursion
7046 (with-output-to-temp-buffer "*Completions*"
7047 (dolist (x keys-alist)
7048 (princ (nth 1 x))
7049 (princ "\n")))
7050 (setq char (read-char)))
7051 (setq char (read-char)))
7052 (message nil)
7053 ;; Return the selected result
7054 (nth 2 (assoc char keys-alist))))
7056 ;; Used for, e.g., electric debug super-examine.
7057 (defun idlwave-make-one-key-alist (alist)
7058 "Make an alist for single key selection."
7059 (let ((l alist) keys-alist name start char help
7060 (cnt 0)
7061 (case-fold-search nil))
7062 (while l
7063 (setq name (car (car l))
7064 l (cdr l))
7065 (catch 'exit
7066 ;; First check if the configuration predetermined a key
7067 (if (string-match "\\[\\(.\\)\\]" name)
7068 (progn
7069 (setq char (string-to-char (downcase (match-string 1 name)))
7070 help (format "%c: %s" char name)
7071 keys-alist (cons (list char help name) keys-alist))
7072 (throw 'exit t)))
7073 ;; Then check for capital letters
7074 (setq start 0)
7075 (while (string-match "[A-Z]" name start)
7076 (setq start (match-end 0)
7077 char (string-to-char (downcase (match-string 0 name))))
7078 (if (not (assoc char keys-alist))
7079 (progn
7080 (setq help (format "%c: %s" char
7081 (replace-match
7082 (concat "[" (match-string 0 name) "]")
7083 t t name))
7084 keys-alist (cons (list char help name) keys-alist))
7085 (throw 'exit t))))
7086 ;; Now check for lowercase letters
7087 (setq start 0)
7088 (while (string-match "[a-z]" name start)
7089 (setq start (match-end 0)
7090 char (string-to-char (match-string 0 name)))
7091 (if (not (assoc char keys-alist))
7092 (progn
7093 (setq help (format "%c: %s" char
7094 (replace-match
7095 (concat "[" (match-string 0 name) "]")
7096 t t name))
7097 keys-alist (cons (list char help name) keys-alist))
7098 (throw 'exit t))))
7099 ;; Bummer, nothing found! Use a stupid number
7100 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7101 help (format "%c: %s" char name)
7102 keys-alist (cons (list char help name) keys-alist))))
7103 (nreverse keys-alist)))
7105 (defun idlwave-set-local (var value &optional buffer)
7106 "Set the buffer-local value of VAR in BUFFER to VALUE."
7107 (with-current-buffer (or buffer (current-buffer))
7108 (set (make-local-variable var) value)))
7110 (defun idlwave-local-value (var &optional buffer)
7111 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7112 (with-current-buffer (or buffer (current-buffer))
7113 (and (local-variable-p var (current-buffer))
7114 (symbol-value var))))
7116 ;; In XEmacs, we can use :activate-callback directly to advice the
7117 ;; choose functions. We use the private keymap only for the online
7118 ;; help feature.
7120 (defvar idlwave-completion-map nil
7121 "Keymap for `completion-list-mode' with `idlwave-complete'.")
7123 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
7124 (with-output-to-temp-buffer "*Completions*"
7125 (apply 'display-completion-list list
7126 ':activate-callback 'idlwave-default-choose-completion
7127 cl-args))
7128 (with-current-buffer "*Completions*"
7129 (use-local-map
7130 (or idlwave-completion-map
7131 (setq idlwave-completion-map
7132 (idlwave-make-modified-completion-map-xemacs
7133 (current-local-map)))))))
7135 (defun idlwave-default-choose-completion (&rest args)
7136 "Execute `default-choose-completion' and then restore the win-conf."
7137 (apply 'idlwave-choose 'default-choose-completion args))
7139 (defun idlwave-make-modified-completion-map-xemacs (old-map)
7140 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7141 (let ((new-map (copy-keymap old-map)))
7142 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7143 (define-key new-map [button3] (lambda ()
7144 (interactive)
7145 (setq this-command last-command)))
7146 new-map))
7148 ;; In Emacs we also replace keybindings in the completion
7149 ;; map in order to install our wrappers.
7151 (defun idlwave-display-completion-list-emacs (list)
7152 "Display completion list and install the choose wrappers."
7153 (with-output-to-temp-buffer "*Completions*"
7154 (display-completion-list list))
7155 (with-current-buffer "*Completions*"
7156 (use-local-map
7157 (or idlwave-completion-map
7158 (setq idlwave-completion-map
7159 (idlwave-make-modified-completion-map-emacs
7160 (current-local-map)))))))
7162 (defun idlwave-make-modified-completion-map-emacs (old-map)
7163 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7164 (let ((new-map (copy-keymap old-map)))
7165 (substitute-key-definition
7166 'choose-completion 'idlwave-choose-completion new-map)
7167 (substitute-key-definition
7168 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
7169 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
7170 new-map))
7172 (defun idlwave-choose-completion (&rest args)
7173 "Choose the completion that point is in or next to."
7174 (interactive (list last-nonmenu-event))
7175 (apply 'idlwave-choose 'choose-completion args))
7177 (defun idlwave-mouse-choose-completion (&rest args)
7178 "Click on an alternative in the `*Completions*' buffer to choose it."
7179 (interactive "e")
7180 (apply 'idlwave-choose 'mouse-choose-completion args))
7182 ;;----------------------------------------------------------------------
7183 ;;----------------------------------------------------------------------
7185 ;;; ------------------------------------------------------------------------
7186 ;;; Structure parsing code, and code to manage class info
7189 ;; - Go again over the documentation how to write a completion
7190 ;; plugin. It is in self.el, but currently still very bad.
7191 ;; This could be in a separate file in the distribution, or
7192 ;; in an appendix for the manual.
7194 (defvar idlwave-struct-skip
7195 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7196 "Regexp for skipping continued blank or comment-only lines in structures.")
7198 (defvar idlwave-struct-tag-regexp
7199 (concat "[{,]" ;leading comma/brace
7200 idlwave-struct-skip ; 4 groups
7201 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7202 "[ \t]*:") ; the final colon
7203 "Regexp for structure tags.")
7205 (defun idlwave-struct-tags ()
7206 "Return a list of all tags in the structure defined at point.
7207 Point is expected just before the opening `{' of the struct definition."
7208 (save-excursion
7209 (let* ((borders (idlwave-struct-borders))
7210 (beg (car borders))
7211 (end (cdr borders))
7212 tags)
7213 (goto-char beg)
7214 (save-restriction
7215 (narrow-to-region beg end)
7216 (while (re-search-forward idlwave-struct-tag-regexp end t)
7217 ;; Check if we are still on the top level of the structure.
7218 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7219 (= (point) beg))
7220 (push (match-string-no-properties 5) tags))
7221 (goto-char (match-end 0))))
7222 (nreverse tags))))
7224 (defun idlwave-find-struct-tag (tag)
7225 "Find a given TAG in the structure defined at point."
7226 (let* ((borders (idlwave-struct-borders))
7227 (end (cdr borders))
7228 (case-fold-search t))
7229 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
7230 end t)))
7232 (defun idlwave-struct-inherits ()
7233 "Return a list of all `inherits' names in the struct at point.
7234 Point is expected just before the opening `{' of the struct definition."
7235 (save-excursion
7236 (let* ((borders (idlwave-struct-borders))
7237 (beg (car borders))
7238 (end (cdr borders))
7239 (case-fold-search t)
7240 names)
7241 (goto-char beg)
7242 (save-restriction
7243 (narrow-to-region beg end)
7244 (while (re-search-forward
7245 (concat "[{,]" ;leading comma/brace
7246 idlwave-struct-skip ; 4 groups
7247 "inherits" ; The INHERITS tag
7248 idlwave-struct-skip ; 4 more
7249 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7250 end t)
7251 ;; Check if we are still on the top level of the structure.
7252 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7253 (= (point) beg))
7254 (push (match-string-no-properties 9) names))
7255 (goto-char (match-end 0))))
7256 (nreverse names))))
7258 (defun idlwave-in-structure ()
7259 "Return t if point is inside an IDL structure definition."
7260 (let ((beg (point)))
7261 (save-excursion
7262 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7263 (if (idlwave-find-structure-definition nil nil 'back)
7264 (let ((borders (idlwave-struct-borders)))
7265 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7266 (and (> beg (car borders)) (< beg (cdr borders))))))))))
7268 (defun idlwave-struct-borders ()
7269 "Return the borders of the {...} after point as a cons cell."
7270 (let (beg)
7271 (save-excursion
7272 (skip-chars-forward "^{")
7273 (setq beg (point))
7274 (condition-case nil (forward-list 1)
7275 (error (goto-char beg)))
7276 (cons beg (point)))))
7278 (defun idlwave-find-structure-definition (&optional var name bound)
7279 "Search forward for a structure definition.
7280 If VAR is non-nil, search for a structure assigned to variable VAR.
7281 If NAME is non-nil, search for a named structure NAME, if a string,
7282 or a generic named structure otherwise. If BOUND is an integer, limit
7283 the search. If BOUND is the symbol `all', we search first back and
7284 then forward through the entire file. If BOUND is the symbol `back'
7285 we search only backward."
7286 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
7287 (case-fold-search t)
7288 (lim (if (integerp bound) bound nil))
7289 (re (concat
7290 (if var
7291 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7292 "\\(\\)")
7293 "=" ws "\\({\\)"
7294 (if name
7295 (if (stringp name)
7296 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
7297 ;; Just a generic name
7298 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7299 ""))))
7300 (if (or (and (or (eq bound 'all) (eq bound 'back))
7301 (re-search-backward re nil t))
7302 (and (not (eq bound 'back)) (re-search-forward re lim t)))
7303 (progn
7304 (goto-char (match-beginning 3))
7305 (match-string-no-properties 5)))))
7307 (defvar idlwave-class-info nil)
7308 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
7310 (add-hook 'idlwave-update-rinfo-hook
7311 (lambda () (setq idlwave-class-reset t)))
7312 (add-hook 'idlwave-after-load-rinfo-hook
7313 (lambda () (setq idlwave-class-info nil)))
7315 (defun idlwave-class-info (class)
7316 (let (list entry)
7317 (if idlwave-class-info
7318 (if idlwave-class-reset
7319 (setq
7320 idlwave-class-reset nil
7321 idlwave-class-info ; Remove any visited in a buffer
7322 (delq nil (mapcar
7323 (lambda (x)
7324 (let ((filebuf
7325 (idlwave-class-file-or-buffer
7326 (or (cdr (assq 'found-in x)) (car x)))))
7327 (if (cdr filebuf)
7329 x)))
7330 idlwave-class-info))))
7331 ;; Info is nil, put in the system stuff to start.
7332 (setq idlwave-class-info idlwave-system-class-info)
7333 (setq list idlwave-class-info)
7334 (while (setq entry (pop list))
7335 (idlwave-sintern-class-info entry)))
7336 (setq class (idlwave-sintern-class class))
7337 (or (assq class idlwave-class-info)
7338 (progn (idlwave-scan-class-info class)
7339 (assq class idlwave-class-info)))))
7341 (defun idlwave-sintern-class-info (entry)
7342 "Sintern the class names in a class-info entry."
7343 (let ((inherits (assq 'inherits entry)))
7344 (setcar entry (idlwave-sintern-class (car entry) 'set))
7345 (if inherits
7346 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7347 (cdr inherits))))))
7349 (defun idlwave-find-class-definition (class &optional all-hook alt-class)
7350 "Find class structure definition(s).
7351 If ALL-HOOK is set, find all named structure definitions in a given
7352 class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7353 set, look for the name__define pro, and inside of it, for the ALT-CLASS
7354 class/struct definition."
7355 (let ((case-fold-search t) end-lim name)
7356 (when (re-search-forward
7357 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7358 (if all-hook
7359 (progn
7360 ;; For everything there
7361 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
7362 (while (setq name
7363 (idlwave-find-structure-definition nil t end-lim))
7364 (funcall all-hook name)))
7365 (idlwave-find-structure-definition nil (or alt-class class))))))
7368 (defun idlwave-class-file-or-buffer (class)
7369 "Find buffer visiting CLASS definition."
7370 (let* ((pro (concat (downcase class) "__define"))
7371 (file (idlwave-routine-source-file
7372 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7373 (idlwave-routines))))))
7374 (cons file (if file (idlwave-get-buffer-visiting file)))))
7377 (defun idlwave-scan-class-info (class)
7378 "Scan all class and named structure info in the class__define pro."
7379 (let* ((idlwave-auto-routine-info-updates nil)
7380 (filebuf (idlwave-class-file-or-buffer class))
7381 (file (car filebuf))
7382 (buf (cdr filebuf))
7383 (class (idlwave-sintern-class class)))
7384 (if (or
7385 (not file)
7386 (and ;; neither a regular file nor a visited buffer
7387 (not buf)
7388 (not (file-regular-p file))))
7389 nil ; Cannot find the file/buffer to get any info
7390 (save-excursion
7391 (if buf (set-buffer buf)
7392 ;; Read the file in temporarily
7393 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7394 (erase-buffer)
7395 (unless (derived-mode-p 'idlwave-mode)
7396 (idlwave-mode))
7397 (insert-file-contents file))
7398 (save-excursion
7399 (goto-char 1)
7400 (idlwave-find-class-definition class
7401 ;; Scan all of the structures found there
7402 (lambda (name)
7403 (let* ((this-class (idlwave-sintern-class name))
7404 (entry
7405 (list this-class
7406 (cons 'tags (idlwave-struct-tags))
7407 (cons 'inherits (idlwave-struct-inherits)))))
7408 (if (not (eq this-class class))
7409 (setq entry (nconc entry (list (cons 'found-in class)))))
7410 (idlwave-sintern-class-info entry)
7411 (push entry idlwave-class-info)))))))))
7413 (defun idlwave-class-found-in (class)
7414 "Return the FOUND-IN property of the CLASS."
7415 (cdr (assq 'found-in (idlwave-class-info class))))
7416 (defun idlwave-class-tags (class)
7417 "Return the native tags in CLASS."
7418 (cdr (assq 'tags (idlwave-class-info class))))
7419 (defun idlwave-class-inherits (class)
7420 "Return the direct superclasses of CLASS."
7421 (cdr (assq 'inherits (idlwave-class-info class))))
7424 (defun idlwave-all-class-tags (class)
7425 "Return a list of native and inherited tags in CLASS."
7426 (condition-case err
7427 (apply 'append (mapcar 'idlwave-class-tags
7428 (cons class (idlwave-all-class-inherits class))))
7429 (error
7430 (idlwave-class-tag-reset)
7431 (error "%s" (error-message-string err)))))
7434 (defun idlwave-all-class-inherits (class)
7435 "Return a list of all superclasses of CLASS (recursively expanded).
7436 The list is cached in `idlwave-class-info' for faster access."
7437 (cond
7438 ((not idlwave-support-inheritance) nil)
7439 ((eq class nil) nil)
7440 ((eq class t) nil)
7442 (let ((info (idlwave-class-info class))
7443 entry)
7444 (if (setq entry (assq 'all-inherits info))
7445 (cdr entry)
7446 ;; Save the depth of inheritance scan to check for circular references
7447 (let ((inherits (mapcar (lambda (x) (cons x 0))
7448 (idlwave-class-inherits class)))
7449 rtn all-inherits cl)
7450 (while inherits
7451 (setq cl (pop inherits)
7452 rtn (cons (car cl) rtn)
7453 inherits (append (mapcar (lambda (x)
7454 (cons x (1+ (cdr cl))))
7455 (idlwave-class-inherits (car cl)))
7456 inherits))
7457 (if (> (cdr cl) 999)
7458 (error
7459 "Class scan: inheritance depth exceeded. Circular inheritance?")
7461 (setq all-inherits (nreverse rtn))
7462 (nconc info (list (cons 'all-inherits all-inherits)))
7463 all-inherits))))))
7465 (defun idlwave-entry-keywords (entry &optional record-link)
7466 "Return the flat entry keywords alist from routine-info entry.
7467 If RECORD-LINK is non-nil, the keyword text is copied and a text
7468 property indicating the link is added."
7469 (let (kwds)
7470 (mapc
7471 (lambda (key-list)
7472 (let ((file (car key-list)))
7473 (mapcar (lambda (key-cons)
7474 (let ((key (car key-cons))
7475 (link (cdr key-cons)))
7476 (when (and record-link file)
7477 (setq key (copy-sequence key))
7478 (put-text-property
7479 0 (length key)
7480 'link
7481 (concat
7482 file
7483 (if link
7484 (concat idlwave-html-link-sep
7485 (number-to-string link))))
7486 key))
7487 (push (list key) kwds)))
7488 (cdr key-list))))
7489 (nthcdr 5 entry))
7490 (nreverse kwds)))
7492 (defun idlwave-entry-find-keyword (entry keyword)
7493 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
7494 (catch 'exit
7495 (mapc
7496 (lambda (key-list)
7497 (let ((file (car key-list))
7498 (kwd (assoc keyword (cdr key-list))))
7499 (when kwd
7500 (setq kwd (cons (car kwd)
7501 (if (and file (cdr kwd))
7502 (concat file
7503 idlwave-html-link-sep
7504 (number-to-string (cdr kwd)))
7505 (cdr kwd))))
7506 (throw 'exit kwd))))
7507 (nthcdr 5 entry))))
7509 ;;==========================================================================
7511 ;; Completing class structure tags. This is a completion plugin.
7512 ;; The necessary taglist is constructed dynamically
7514 (defvar idlwave-current-tags-class nil)
7515 (defvar idlwave-current-class-tags nil)
7516 (defvar idlwave-current-native-class-tags nil)
7517 (defvar idlwave-sint-class-tags nil)
7518 (declare-function idlwave-sintern-class-tag "idlwave" t t)
7519 (idlwave-new-sintern-type 'class-tag)
7520 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
7521 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
7523 (defun idlwave-complete-class-structure-tag ()
7524 "Complete a structure tag on a `self' argument in an object method."
7525 (interactive)
7526 (let ((pos (point))
7527 (case-fold-search t))
7528 (if (save-excursion
7529 ;; Check if the context is right
7530 (skip-chars-backward "a-zA-Z0-9._$")
7531 (and (< (point) (- pos 4))
7532 (looking-at "self\\.")))
7533 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7534 (super-classes (idlwave-all-class-inherits class-selector)))
7535 ;; Check if we are in a class routine
7536 (unless class-selector
7537 (error "Not in a method procedure or function"))
7538 ;; Check if we need to update the "current" class
7539 (if (not (equal class-selector idlwave-current-tags-class))
7540 (idlwave-prepare-class-tag-completion class-selector))
7541 (setq idlwave-completion-help-info
7542 (list 'idlwave-complete-class-structure-tag-help
7543 (idlwave-sintern-routine
7544 (concat class-selector "__define"))
7545 nil))
7546 ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
7547 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7548 (idlwave-complete-in-buffer
7549 'class-tag 'class-tag
7550 idlwave-current-class-tags nil
7551 (format "Select a tag of class %s" class-selector)
7552 "class tag"
7553 'idlwave-attach-class-tag-classes))
7554 t) ; return t to skip other completions
7555 nil)))
7557 (defun idlwave-class-tag-reset ()
7558 (setq idlwave-current-tags-class nil))
7560 (defun idlwave-prepare-class-tag-completion (class)
7561 "Find and parse the necessary class definitions for class structure tags."
7562 (setq idlwave-sint-class-tags nil)
7563 (setq idlwave-current-tags-class class)
7564 (setq idlwave-current-class-tags
7565 (mapcar (lambda (x)
7566 (list (idlwave-sintern-class-tag x 'set)))
7567 (idlwave-all-class-tags class)))
7568 (setq idlwave-current-native-class-tags
7569 (mapcar 'downcase (idlwave-class-tags class))))
7571 ;===========================================================================
7573 ;; Completing system variables and their structure fields
7574 ;; This is also a plugin.
7576 (defvar idlwave-sint-sysvars nil)
7577 (defvar idlwave-sint-sysvartags nil)
7578 (declare-function idlwave-sintern-sysvar "idlwave" t t)
7579 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
7580 (idlwave-new-sintern-type 'sysvar)
7581 (idlwave-new-sintern-type 'sysvartag)
7582 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7583 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
7584 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7587 (defun idlwave-complete-sysvar-or-tag ()
7588 "Complete a system variable."
7589 (interactive)
7590 (let ((pos (point))
7591 (case-fold-search t))
7592 (cond ((save-excursion
7593 ;; Check if the context is right for system variable
7594 (skip-chars-backward "[a-zA-Z0-9_$]")
7595 (equal (char-before) ?!))
7596 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
7597 (idlwave-complete-in-buffer 'sysvar 'sysvar
7598 idlwave-system-variables-alist nil
7599 "Select a system variable"
7600 "system variable")
7601 t) ; return t to skip other completions
7602 ((save-excursion
7603 ;; Check if the context is right for sysvar tag
7604 (skip-chars-backward "a-zA-Z0-9_$.")
7605 (and (equal (char-before) ?!)
7606 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7607 (<= (match-end 0) pos)))
7608 ;; Complete a system variable tag
7609 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7610 (entry (assq var idlwave-system-variables-alist))
7611 (tags (cdr (assq 'tags entry))))
7612 (or entry (error "!%s is not a known system variable" var))
7613 (or tags (error "System variable !%s is not a structure" var))
7614 (setq idlwave-completion-help-info
7615 (list 'idlwave-complete-sysvar-tag-help var))
7616 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
7617 tags nil
7618 "Select a system variable tag"
7619 "system variable tag")
7620 t)) ; return t to skip other completions
7621 (t nil))))
7623 (defvar idlw-help-link) ;dynamic variables set by help callback
7624 (defun idlwave-complete-sysvar-help (mode word)
7625 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7626 (entry (assoc word idlwave-system-variables-alist)))
7627 (cond
7628 ((eq mode 'test)
7629 (and (stringp word) entry (nth 1 (assq 'link entry))))
7630 ((eq mode 'set)
7631 ;; Setting dynamic!!!
7632 (if entry (setq idlw-help-link (nth 1 (assq 'link entry)))))
7633 (t (error "This should not happen")))))
7635 (defun idlwave-complete-sysvar-tag-help (mode word)
7636 (let* ((var (nth 1 idlwave-completion-help-info))
7637 (entry (assoc var idlwave-system-variables-alist))
7638 (tags (cdr (assq 'tags entry)))
7639 (main (nth 1 (assq 'link entry)))
7640 target)
7641 (cond
7642 ((eq mode 'test) ; we can at least link the main
7643 (and (stringp word) entry main))
7644 ((eq mode 'set)
7645 (if entry
7646 (setq idlw-help-link
7647 (if (setq target (cdr (assoc-string word tags t)))
7648 (idlwave-substitute-link-target main target)
7649 main)))) ;; setting dynamic!!!
7650 (t (error "This should not happen")))))
7652 (defun idlwave-split-link-target (link)
7653 "Split a given LINK into link file and anchor."
7654 (if (string-match idlwave-html-link-sep link)
7655 (cons (substring link 0 (match-beginning 0))
7656 (string-to-number (substring link (match-end 0))))))
7658 (defun idlwave-substitute-link-target (link target)
7659 "Substitute the TARGET anchor for the given LINK."
7660 (let (main-base)
7661 (setq main-base (if (string-match "#" link)
7662 (substring link 0 (match-beginning 0))
7663 link))
7664 (if target
7665 (concat main-base idlwave-html-link-sep (number-to-string target))
7666 link)))
7668 ;; Fake help in the source buffer for class structure tags.
7669 ;; IDLW-HELP-LINK AND IDLW-HELP-NAME ARE GLOBAL-VARIABLES HERE.
7670 ;; (from idlwave-do-mouse-completion-help)
7671 (defvar idlw-help-name)
7672 (defvar idlw-help-link)
7673 (defvar idlwave-help-do-class-struct-tag nil)
7674 (defun idlwave-complete-class-structure-tag-help (mode word)
7675 (cond
7676 ((eq mode 'test) ; nothing gets fontified for class tags
7677 nil)
7678 ((eq mode 'set)
7679 (let (class-with found-in)
7680 (when (setq class-with
7681 (idlwave-class-or-superclass-with-tag
7682 idlwave-current-tags-class
7683 word))
7684 (if (assq (idlwave-sintern-class class-with)
7685 idlwave-system-class-info)
7686 (error "No help available for system class tags"))
7687 (if (setq found-in (idlwave-class-found-in class-with))
7688 (setq idlw-help-name (cons (concat found-in "__define") class-with))
7689 (setq idlw-help-name (concat class-with "__define")))))
7690 (setq idlw-help-link word
7691 idlwave-help-do-class-struct-tag t))
7692 (t (error "This should not happen"))))
7694 (defun idlwave-class-or-superclass-with-tag (class tag)
7695 "Find and return the CLASS or one of its superclass with the
7696 associated TAG, if any."
7697 (let ((sclasses (cons class (idlwave-all-class-inherits class)))
7699 (catch 'exit
7700 (while sclasses
7701 (setq cl (pop sclasses))
7702 (let ((tags (idlwave-class-tags cl)))
7703 (while tags
7704 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
7705 (throw 'exit cl))
7706 (setq tags (cdr tags))))))))
7709 (defun idlwave-sysvars-reset ()
7710 (if (and (fboundp 'idlwave-shell-is-running)
7711 (idlwave-shell-is-running)
7712 idlwave-idlwave_routine_info-compiled)
7713 (idlwave-shell-send-command "idlwave_get_sysvars"
7714 'idlwave-process-sysvars 'hide)))
7716 (defun idlwave-process-sysvars ()
7717 (idlwave-shell-filter-sysvars)
7718 (setq idlwave-sint-sysvars nil
7719 idlwave-sint-sysvartags nil)
7720 (idlwave-sintern-sysvar-alist))
7722 (defun idlwave-sintern-sysvar-alist ()
7723 (let ((list idlwave-system-variables-alist) entry tags)
7724 (while (setq entry (pop list))
7725 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
7726 (setq tags (assq 'tags entry))
7727 (if tags
7728 (setcdr tags
7729 (mapcar (lambda (x)
7730 (cons (idlwave-sintern-sysvartag (car x) 'set)
7731 (cdr x)))
7732 (cdr tags)))))))
7734 (defvar idlwave-shell-command-output)
7735 (defun idlwave-shell-filter-sysvars ()
7736 "Get any new system variables and tags."
7737 (let ((text idlwave-shell-command-output)
7738 (start 0)
7739 (old idlwave-system-variables-alist)
7740 var tags type name class link old-entry)
7741 (setq idlwave-system-variables-alist nil)
7742 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7743 text start)
7744 (setq start (match-end 0)
7745 var (match-string 1 text)
7746 tags (if (match-end 3)
7747 (idlwave-split-string (match-string 3 text))))
7748 ;; Maintain old links, if present
7749 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7750 (setq link (assq 'link old-entry))
7751 (setq idlwave-system-variables-alist
7752 (cons (list var
7753 (cons
7754 'tags
7755 (mapcar (lambda (x)
7756 (cons x
7757 (cdr (assq
7758 (idlwave-sintern-sysvartag x)
7759 (cdr (assq 'tags old-entry))))))
7760 tags)) link)
7761 idlwave-system-variables-alist)))
7762 ;; Keep the old value if query was not successful
7763 (setq idlwave-system-variables-alist
7764 (or idlwave-system-variables-alist old))))
7766 (defun idlwave-completion-fontify-classes ()
7767 "Goto the *Completions* buffer and fontify the class info."
7768 (when (featurep 'font-lock)
7769 (with-current-buffer "*Completions*"
7770 (save-excursion
7771 (goto-char (point-min))
7772 (let ((buffer-read-only nil))
7773 (while (re-search-forward "\\.*<[^>]+>" nil t)
7774 (put-text-property (match-beginning 0) (match-end 0)
7775 'face 'font-lock-string-face)))))))
7777 (defun idlwave-uniquify (list)
7778 (let ((ht (make-hash-table :size (length list) :test 'equal)))
7779 (delq nil
7780 (mapcar (lambda (x)
7781 (unless (gethash x ht)
7782 (puthash x t ht)
7784 list))))
7786 (defun idlwave-after-successful-completion (type slash &optional verify)
7787 "Add `=' or `(' after successful completion of keyword and function.
7788 Restore the pre-completion window configuration if possible."
7789 (cond
7790 ((eq type 'procedure)
7791 nil)
7792 ((eq type 'function)
7793 (cond
7794 ((equal idlwave-function-completion-adds-paren nil) nil)
7795 ((or (equal idlwave-function-completion-adds-paren t)
7796 (equal idlwave-function-completion-adds-paren 1))
7797 (insert "("))
7798 ((equal idlwave-function-completion-adds-paren 2)
7799 (insert "()")
7800 (backward-char 1))
7801 (t nil)))
7802 ((eq type 'keyword)
7803 (if (and idlwave-keyword-completion-adds-equal
7804 (not slash))
7805 (progn (insert "=") t)
7806 nil)))
7808 ;; Restore the pre-completion window configuration if this is safe.
7810 (if (or (eq verify 'force) ; force
7811 (and
7812 (get-buffer-window "*Completions*") ; visible
7813 (idlwave-local-value 'idlwave-completion-p
7814 "*Completions*") ; cib-buffer
7815 (eq (marker-buffer idlwave-completion-mark)
7816 (current-buffer)) ; buffer OK
7817 (equal (marker-position idlwave-completion-mark)
7818 verify))) ; pos OK
7819 (idlwave-restore-wconf-after-completion))
7820 (move-marker idlwave-completion-mark nil)
7821 (setq idlwave-before-completion-wconf nil))
7823 (defun idlwave-mouse-context-help (ev &optional arg)
7824 "Call `idlwave-context-help' on the clicked location."
7825 (interactive "eP")
7826 (mouse-set-point ev)
7827 (idlwave-context-help arg))
7829 (defvar idlwave-last-context-help-pos nil)
7830 (defun idlwave-context-help (&optional arg)
7831 "Display IDL Online Help on context.
7832 If point is on a keyword, help for that keyword will be shown. If
7833 point is on a routine name or in the argument list of a routine, help
7834 for that routine will be displayed. Works for system routines and
7835 keywords, it pulls up text help. For other routines and keywords,
7836 visits the source file, finding help in the header (if
7837 `idlwave-help-source-try-header' is non-nil) or the routine definition
7838 itself."
7839 (interactive "P")
7840 (idlwave-do-context-help arg))
7842 (defun idlwave-mouse-completion-help (ev)
7843 "Display online help about the completion at point."
7844 (interactive "eP")
7845 ;; Restore last-command for next command, to make
7846 ;; scrolling/canceling of completions work.
7847 (setq this-command last-command)
7848 (idlwave-do-mouse-completion-help ev))
7850 (defun idlwave-routine-info (&optional arg external)
7851 "Display a routines calling sequence and list of keywords.
7852 When point is on the name a function or procedure, or in the argument
7853 list of a function or procedure, this command displays a help buffer with
7854 the information. When called with prefix arg, enforce class query.
7856 When point is on an object operator `->', display the class stored in
7857 this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
7858 arg, the class property is cleared out."
7860 (interactive "P")
7861 (idlwave-routines)
7862 (if (string-match "->" (buffer-substring
7863 (max (point-min) (1- (point)))
7864 (min (+ 2 (point)) (point-max))))
7865 ;; Cursor is on an arrow
7866 (if (get-text-property (point) 'idlwave-class)
7867 ;; arrow has class property
7868 (if arg
7869 ;; Remove property
7870 (save-excursion
7871 (backward-char 1)
7872 (when (looking-at ".?\\(->\\)")
7873 (remove-text-properties (match-beginning 1) (match-end 1)
7874 '(idlwave-class nil face nil))
7875 (message "Class property removed from arrow")))
7876 ;; Echo class property
7877 (message "Arrow has text property identifying object to be class %s"
7878 (get-text-property (point) 'idlwave-class)))
7879 ;; No property found
7880 (message "Arrow has no class text property"))
7882 ;; Not on an arrow...
7883 (let* ((idlwave-query-class nil)
7884 (idlwave-force-class-query (equal arg '(4)))
7885 (module (idlwave-what-module)))
7886 (if (car module)
7887 (apply 'idlwave-display-calling-sequence
7888 (idlwave-fix-module-if-obj_new module))
7889 (error "Don't know which calling sequence to show")))))
7891 (defun idlwave-resolve (&optional arg)
7892 "Call RESOLVE_ROUTINE on the module name at point.
7893 Like `idlwave-routine-info', this looks for a routine call at point.
7894 After confirmation in the minibuffer, it will use the shell to issue
7895 a RESOLVE call for this routine, to attempt to make it defined and its
7896 routine info available for IDLWAVE. If the routine is a method call,
7897 both `class__method' and `class__define' will be tried.
7898 With ARG, enforce query for the class of object methods."
7899 (interactive "P")
7900 (let* ((idlwave-query-class nil)
7901 (idlwave-force-class-query (equal arg '(4)))
7902 (module (idlwave-what-module))
7903 (name (idlwave-make-full-name (nth 2 module) (car module)))
7904 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7905 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7906 (kwd "")
7907 class)
7908 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7909 resolve)
7910 (setq type (match-string 1 resolve)
7911 class (if (match-beginning 2)
7912 (match-string 3 resolve)
7913 nil)
7914 name (match-string 4 resolve)))
7915 (if (string= (downcase type) "function")
7916 (setq kwd ",/is_function"))
7918 (cond
7919 ((null class)
7920 (idlwave-shell-send-command
7921 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7922 'idlwave-update-routine-info
7923 nil t))
7925 (idlwave-shell-send-command
7926 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
7927 (list 'idlwave-shell-send-command
7928 (format "resolve_routine,'%s__%s'%s"
7929 (downcase class) (downcase name) kwd)
7930 '(idlwave-update-routine-info)
7931 nil t))))))
7933 (defun idlwave-find-module-this-file ()
7934 (interactive)
7935 (idlwave-find-module '(4)))
7937 (defun idlwave-find-module (&optional arg)
7938 "Find the source code of an IDL module.
7939 Works for modules for which IDLWAVE has routine info available.
7940 The function offers as default the module name `idlwave-routine-info'
7941 would use. With ARG limit to this buffer. With two prefix ARG's
7942 force class query for object methods."
7943 (interactive "P")
7944 (let* ((idlwave-query-class nil)
7945 (idlwave-force-class-query (equal arg '(16)))
7946 (this-buffer (equal arg '(4)))
7947 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
7948 (default (if module
7949 (concat (idlwave-make-full-name
7950 (nth 2 module) (car module))
7951 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7952 "none"))
7953 (list
7954 (idlwave-uniquify
7955 (delq nil
7956 (mapcar (lambda (x)
7957 (if (eq 'system (car-safe (nth 3 x)))
7958 ;; Take out system routines with no source.
7960 (list
7961 (concat (idlwave-make-full-name
7962 (nth 2 x) (car x))
7963 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7964 (if this-buffer
7965 (idlwave-save-buffer-update)
7966 (idlwave-routines))))))
7967 (name (idlwave-completing-read
7968 (if (or (not this-buffer)
7969 (assoc default list))
7970 (format "Module (Default %s): " default)
7971 (format "Module in this file: "))
7972 list))
7973 type class)
7974 (if (string-match "\\`\\s-*\\'" name)
7975 ;; Nothing, use the default.
7976 (setq name default))
7977 (if (string-match "<[fp]>" name)
7978 (setq type (substring name -2 -1)
7979 name (substring name 0 -3)))
7980 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7981 (setq class (match-string 1 name)
7982 name (match-string 2 name)))
7983 (setq name (idlwave-sintern-routine-or-method name class)
7984 class (idlwave-sintern-class class)
7985 type (cond ((equal type "f") 'fun)
7986 ((equal type "p") 'pro)
7987 (t t)))
7988 (idlwave-do-find-module name type class nil this-buffer)))
7990 (defun idlwave-do-find-module (name type class
7991 &optional force-source this-buffer)
7992 (let ((name1 (idlwave-make-full-name class name))
7993 source buf1 entry
7994 (buf (current-buffer))
7995 (pos (point))
7996 file name2)
7997 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7998 'WITH-FILE)
7999 source (or force-source (nth 3 entry))
8000 name2 (if (nth 2 entry)
8001 (idlwave-make-full-name (nth 2 entry) name)
8002 name1))
8003 (if source
8004 (setq file (idlwave-routine-source-file source)))
8005 (unless file ; Try to find it on the path.
8006 (setq file
8007 (idlwave-expand-lib-file-name
8008 (if class
8009 (format "%s__define.pro" (downcase class))
8010 (format "%s.pro" (downcase name))))))
8011 (cond
8012 ((or (null name) (equal name ""))
8013 (error "Abort"))
8014 ((eq (car source) 'system)
8015 (error "Source code for system routine %s is not available"
8016 name2))
8017 ((or (not file) (not (file-regular-p file)))
8018 (error "Source code for routine %s is not available"
8019 name2))
8021 (when (not this-buffer)
8022 (setq buf1
8023 (idlwave-find-file-noselect file 'find))
8024 (pop-to-buffer buf1 t))
8025 (goto-char (point-max))
8026 (let ((case-fold-search t))
8027 (if (re-search-backward
8028 (concat "^[ \t]*\\<"
8029 (cond ((eq type 'fun) "function")
8030 ((eq type 'pro) "pro")
8031 (t "\\(pro\\|function\\)"))
8032 "\\>[ \t]+"
8033 (regexp-quote (downcase name2))
8034 "[^a-zA-Z0-9_$]")
8035 nil t)
8036 (goto-char (match-beginning 0))
8037 (pop-to-buffer buf)
8038 (goto-char pos)
8039 (error "Could not find routine %s" name2)))))))
8041 (defun idlwave-what-module ()
8042 "Return a default module for stuff near point.
8043 Used by `idlwave-routine-info' and `idlwave-find-module'."
8044 (idlwave-routines)
8045 (if (let ((case-fold-search t))
8046 (save-excursion
8047 (idlwave-beginning-of-statement)
8048 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8049 ;; This is a function or procedure definition statement
8050 ;; We return the defined routine as module.
8051 (list
8052 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8053 (match-string-no-properties 2))
8054 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8055 (idlwave-sintern-class (match-string 3)))
8057 ;; Not a definition statement - analyze precise position.
8058 (let* ((where (idlwave-where))
8059 (cw (nth 2 where))
8060 (pro (car (nth 0 where)))
8061 (func (car (nth 1 where)))
8062 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8063 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8064 (following-char)))
8066 (cond
8067 ((and (eq cw 'procedure)
8068 (not (equal this-word "")))
8069 (setq this-word (idlwave-sintern-routine-or-method
8070 this-word (nth 2 (nth 3 where))))
8071 (list this-word 'pro
8072 (idlwave-determine-class
8073 (cons this-word (cdr (nth 3 where)))
8074 'pro)))
8075 ((and (eq cw 'function)
8076 (not (equal this-word ""))
8077 (or (eq next-char ?\() ; exclude arrays, vars.
8078 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
8079 (setq this-word (idlwave-sintern-routine-or-method
8080 this-word (nth 2 (nth 3 where))))
8081 (list this-word 'fun
8082 (idlwave-determine-class
8083 (cons this-word (cdr (nth 3 where)))
8084 'fun)))
8085 ((and (memq cw '(function-keyword procedure-keyword))
8086 (not (equal this-word ""))
8087 (eq next-char ?\()) ; A function!
8088 (setq this-word (idlwave-sintern-routine this-word))
8089 (list this-word 'fun nil))
8090 (func
8091 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8092 (pro
8093 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8094 (t nil)))))
8096 (defun idlwave-what-module-find-class ()
8097 "Call `idlwave-what-module' and find the inherited class if necessary."
8098 (let* ((module (idlwave-what-module))
8099 (class (nth 2 module)))
8100 (if (and (= (length module) 3)
8101 (stringp class))
8102 (list (car module)
8103 (nth 1 module)
8104 (apply 'idlwave-find-inherited-class module))
8105 module)))
8107 (defun idlwave-find-inherited-class (name type class)
8108 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8109 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8110 (if entry
8111 (nth 2 entry)
8112 class)))
8114 (defun idlwave-fix-module-if-obj_new (module)
8115 "Check if MODULE points to obj_new.
8116 If yes, and if the cursor is in the keyword region, change to the
8117 appropriate Init method."
8118 (let* ((name (car module))
8119 (pos (point))
8120 (case-fold-search t)
8121 string)
8122 (if (and (stringp name)
8123 (equal (downcase name) "obj_new")
8124 (save-excursion
8125 (idlwave-beginning-of-statement)
8126 (setq string (buffer-substring (point) pos))
8127 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8128 string)))
8129 (let ((name "Init")
8130 (class (match-string 1 string)))
8131 (setq module (list (idlwave-sintern-method "Init")
8132 'fun
8133 (idlwave-sintern-class class)))))
8134 module))
8136 (defun idlwave-fix-keywords (name type class keywords
8137 &optional super-classes system)
8138 "Update a list of keywords.
8139 Translate OBJ_NEW, adding all super-class keywords, or all keywords
8140 from all classes if CLASS equals t. If SYSTEM is non-nil, don't
8141 demand _EXTRA in the keyword list."
8142 (let ((case-fold-search t))
8144 ;; If this is the OBJ_NEW function, try to figure out the class and use
8145 ;; the keywords from the corresponding INIT method.
8146 (if (and (equal (upcase name) "OBJ_NEW")
8147 (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
8148 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8149 (string (buffer-substring bos (point)))
8150 (case-fold-search t)
8151 class)
8152 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8153 string)
8154 (setq class (idlwave-sintern-class (match-string 1 string)))
8155 (setq idlwave-current-obj_new-class class)
8156 (setq keywords
8157 (append keywords
8158 (idlwave-entry-keywords
8159 (idlwave-rinfo-assq
8160 (idlwave-sintern-method "INIT")
8161 'fun
8162 class
8163 (idlwave-routines)) 'do-link))))))
8165 ;; If the class is t, combine all keywords of all methods NAME
8166 (when (eq class t)
8167 (mapc (lambda (entry)
8168 (and
8169 (nth 2 entry) ; non-nil class
8170 (eq (nth 1 entry) type) ; correct type
8171 (setq keywords
8172 (append keywords
8173 (idlwave-entry-keywords entry 'do-link)))))
8174 (idlwave-all-assq name (idlwave-routines)))
8175 (setq keywords (idlwave-uniquify keywords)))
8177 ;; If we have inheritance, add all keywords from superclasses, if
8178 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
8179 (when (and
8180 super-classes
8181 idlwave-keyword-class-inheritance
8182 (stringp class)
8184 system
8185 (assq (idlwave-sintern-keyword "_extra") keywords)
8186 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
8187 ;; Check if one of the keyword-class regexps matches the name
8188 (let ((regexps idlwave-keyword-class-inheritance) re)
8189 (catch 'exit
8190 (while (setq re (pop regexps))
8191 (if (string-match re name) (throw 'exit t))))))
8193 (loop for entry in (idlwave-routines) do
8194 (and (nth 2 entry) ; non-nil class
8195 (memq (nth 2 entry) super-classes) ; an inherited class
8196 (eq (nth 1 entry) type) ; correct type
8197 (eq (car entry) name) ; correct name
8198 (mapc (lambda (k) (add-to-list 'keywords k))
8199 (idlwave-entry-keywords entry 'do-link))))
8200 (setq keywords (idlwave-uniquify keywords)))
8202 ;; Return the final list
8203 keywords))
8205 (defun idlwave-expand-keyword (keyword module)
8206 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
8207 KEYWORD may be an exact match or an abbreviation of a keyword.
8208 If the match is exact, KEYWORD itself is returned, even if there may be other
8209 keywords of which KEYWORD is an abbreviation. This is necessary because some
8210 system routines have keywords which are prefixes of other keywords.
8211 If KEYWORD is an abbreviation of several keywords, a list of all possible
8212 completions is returned.
8213 If the abbreviation was unique, the correct keyword is returned.
8214 If it cannot be a keyword, the function return nil.
8215 If we do not know about MODULE, just return KEYWORD literally."
8216 (let* ((name (car module))
8217 (type (nth 1 module))
8218 (class (nth 2 module))
8219 (kwd (idlwave-sintern-keyword keyword))
8220 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
8221 (kwd-alist (idlwave-entry-keywords entry))
8222 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8223 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8224 (completion-ignore-case t)
8225 candidates)
8226 (cond ((assq kwd kwd-alist)
8227 kwd)
8228 ((setq candidates (all-completions kwd kwd-alist))
8229 (if (= (length candidates) 1)
8230 (car candidates)
8231 candidates))
8232 ((and entry extra)
8233 ;; Inheritance may cause this keyword to be correct
8234 keyword)
8235 (entry
8236 ;; We do know the function, which does not have the keyword.
8237 nil)
8239 ;; We do not know the function, so this just might be a correct
8240 ;; keyword - return it as it is.
8241 keyword))))
8243 (defvar idlwave-rinfo-mouse-map
8244 (let ((map (make-sparse-keymap)))
8245 (define-key map
8246 (if (featurep 'xemacs) [button2] [mouse-2])
8247 'idlwave-mouse-active-rinfo)
8248 (define-key map
8249 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8250 'idlwave-mouse-active-rinfo-shift)
8251 (define-key map
8252 (if (featurep 'xemacs) [button3] [mouse-3])
8253 'idlwave-mouse-active-rinfo-right)
8254 (define-key map " " 'idlwave-active-rinfo-space)
8255 (define-key map "q" 'idlwave-quit-help)
8256 map))
8258 (defvar idlwave-rinfo-map
8259 (let ((map (make-sparse-keymap)))
8260 (define-key map "q" 'idlwave-quit-help)
8261 map))
8263 (defvar idlwave-popup-source nil)
8264 (defvar idlwave-rinfo-marker (make-marker))
8266 (defun idlwave-quit-help ()
8267 (interactive)
8268 (let ((ri-window (get-buffer-window "*Help*"))
8269 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8270 (when (and olh-window
8271 (fboundp 'idlwave-help-quit))
8272 (select-window olh-window)
8273 (idlwave-help-quit))
8274 (when (window-live-p ri-window)
8275 (delete-window ri-window))))
8277 (defun idlwave-display-calling-sequence (name type class
8278 &optional initial-class)
8279 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
8280 (let* ((initial-class (or initial-class class))
8281 (entry (or (idlwave-best-rinfo-assq name type class
8282 (idlwave-routines))
8283 (idlwave-rinfo-assq name type class
8284 idlwave-unresolved-routines)))
8285 (name (or (car entry) name))
8286 (class (or (nth 2 entry) class))
8287 (superclasses (idlwave-all-class-inherits initial-class))
8288 (twins (idlwave-routine-twins entry))
8289 (dtwins (idlwave-study-twins twins))
8290 (all dtwins)
8291 (system (eq (car (nth 3 entry)) 'system))
8292 (calling-seq (nth 4 entry))
8293 (keywords (idlwave-entry-keywords entry 'do-link))
8294 (html-file (car (nth 5 entry)))
8295 (help-echo-kwd
8296 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
8297 (help-echo-use
8298 "Button2/3: Online Help")
8299 (help-echo-src
8300 "Button2: Jump to source and back | Button3: Source in Help window.")
8301 (help-echo-class
8302 "Button2: Display info about same method in superclass")
8303 (col 0)
8304 (data (list name type class (current-buffer) nil initial-class))
8305 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8306 (face 'idlwave-help-link)
8307 beg props win cnt total)
8308 ;; Fix keywords, but don't add chained super-classes, since these
8309 ;; are shown separately for that super-class
8310 (setq keywords (idlwave-fix-keywords name type class keywords))
8311 (cond
8312 ((null entry)
8313 (error "No %s %s known %s" type name
8314 (if initial-class (concat "in class " initial-class) "")))
8315 ((or (null name) (equal name ""))
8316 (error "No function or procedure call at point"))
8317 ((null calling-seq)
8318 (error "Calling sequence of %s %s not available" type name))
8320 (move-marker idlwave-rinfo-marker (point))
8321 (with-current-buffer (get-buffer-create "*Help*")
8322 (use-local-map idlwave-rinfo-map)
8323 (setq buffer-read-only nil)
8324 (erase-buffer)
8325 (set (make-local-variable 'idlwave-popup-source) nil)
8326 (set (make-local-variable 'idlwave-current-obj_new-class)
8327 idlwave-current-obj_new-class)
8328 (when superclasses
8329 (setq props (list 'mouse-face 'highlight
8330 km-prop idlwave-rinfo-mouse-map
8331 'help-echo help-echo-class
8332 'data (cons 'class data)))
8333 (let ((classes (cons initial-class superclasses)) c)
8334 (insert "Classes: ")
8335 (while (setq c (pop classes))
8336 (insert " ")
8337 (setq beg (point))
8338 (insert c)
8339 (if (equal (downcase c) (downcase class))
8340 (add-text-properties beg (point) (list 'face 'bold))
8341 ;; If Method exists in a different class link it
8342 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8343 (add-text-properties beg (point) props))))
8344 (insert "\n")))
8345 (setq props (list 'mouse-face 'highlight
8346 km-prop idlwave-rinfo-mouse-map
8347 'help-echo help-echo-use
8348 'data (cons 'usage data)))
8349 (if html-file (setq props (append (list 'face face 'link html-file)
8350 props)))
8351 (insert "Usage: ")
8352 (setq beg (point))
8353 (insert (if class
8354 (format calling-seq class name class name class name)
8355 (format calling-seq name name name name))
8356 "\n")
8357 (add-text-properties beg (point) props)
8359 (insert "Keywords:")
8360 (if (null keywords)
8361 (insert " No keywords accepted.")
8362 (setq col 9)
8363 (mapc
8364 (lambda (x)
8365 (if (>= (+ col 1 (length (car x)))
8366 (window-width))
8367 (progn
8368 (insert "\n ")
8369 (setq col 9)))
8370 (insert " ")
8371 (setq beg (point)
8372 ;; Relevant keywords already have link property attached
8373 props (list 'mouse-face 'highlight
8374 km-prop idlwave-rinfo-mouse-map
8375 'data (cons 'keyword data)
8376 'help-echo help-echo-kwd
8377 'keyword (car x)))
8378 (if system (setq props (append (list 'face face) props)))
8379 (insert (car x))
8380 (add-text-properties beg (point) props)
8381 (setq col (+ col 1 (length (car x)))))
8382 keywords))
8384 (setq cnt 1 total (length all))
8385 ;; Here entry is (key file (list of type-conses))
8386 (while (setq entry (pop all))
8387 (setq props (list 'mouse-face 'highlight
8388 km-prop idlwave-rinfo-mouse-map
8389 'help-echo help-echo-src
8390 'source (list (car (car (nth 2 entry))) ;type
8391 (nth 1 entry)
8393 (cdr (car (nth 2 entry))))
8394 'data (cons 'source data)))
8395 (idlwave-insert-source-location
8396 (format "\n%-8s %s"
8397 (if (equal cnt 1)
8398 (if (> total 1) "Sources:" "Source:")
8400 (if (> total 1) "- " ""))
8401 entry props)
8402 (incf cnt)
8403 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8404 ;; No more source lines, please
8405 (insert (format
8406 "\n Source information truncated to %d entries."
8407 idlwave-rinfo-max-source-lines))
8408 (setq all nil)))
8409 (goto-char (point-min))
8410 (setq buffer-read-only t))
8411 (display-buffer "*Help*")
8412 (if (and (setq win (get-buffer-window "*Help*"))
8413 idlwave-resize-routine-help-window)
8414 (progn
8415 (let ((ww (selected-window)))
8416 (unwind-protect
8417 (progn
8418 (select-window win)
8419 (enlarge-window (- (/ (frame-height) 2)
8420 (window-height)))
8421 (shrink-window-if-larger-than-buffer))
8422 (select-window ww)))))))))
8424 (defun idlwave-insert-source-location (prefix entry &optional file-props)
8425 "Insert a source location into the routine info buffer.
8426 Start line with PREFIX. If a file name is inserted, add FILE-PROPS
8427 to it."
8428 (let* ((key (car entry))
8429 (file (nth 1 entry))
8430 (types (nth 2 entry))
8431 (shell-flag (assq 'compiled types))
8432 (buffer-flag (assq 'buffer types))
8433 (user-flag (assq 'user types))
8434 (lib-flag (assq 'lib types))
8435 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8436 (and user-flag (idlwave-count-memq 'user types))
8437 (and lib-flag (idlwave-count-memq 'lib types))
8439 (doflags t)
8440 beg special)
8442 (insert prefix)
8444 (cond
8445 ((eq key 'system)
8446 (setq doflags nil)
8447 (insert "System "))
8449 ((eq key 'builtin)
8450 (setq doflags nil)
8451 (insert "Builtin "))
8453 ((and (not file) shell-flag)
8454 (insert "Unresolved"))
8456 ((null file)
8457 (insert "ERROR"))
8459 ((idlwave-syslib-p file)
8460 (if (string-match "obsolete" (file-name-directory file))
8461 (insert "Obsolete ")
8462 (insert "SystemLib ")))
8464 ;; New special syntax: taken directly from routine-info for
8465 ;; library catalog routines
8466 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8467 (insert (format "%-10s" special)))
8469 ;; Old special syntax: a matching regexp
8470 ((setq special (idlwave-special-lib-test file))
8471 (insert (format "%-10s" special)))
8473 ;; Catch-all with file
8474 ((idlwave-lib-p file) (insert "Library "))
8476 ;; Sanity catch all
8477 (t (insert "Other ")))
8479 (when doflags
8480 (insert (concat
8481 " ["
8482 (if lib-flag "L" "-")
8483 (if user-flag "C" "-")
8484 (if shell-flag "S" "-")
8485 (if buffer-flag "B" "-")
8486 "] ")))
8487 (when (> ndupl 1)
8488 (setq beg (point))
8489 (insert (format "(%dx) " ndupl))
8490 (add-text-properties beg (point) (list 'face 'bold)))
8491 (when (and file (not (equal file "")))
8492 (setq beg (point))
8493 (insert (apply 'abbreviate-file-name
8494 (if (featurep 'xemacs) (list file t) (list file))))
8495 (if file-props
8496 (add-text-properties beg (point) file-props)))))
8498 (defun idlwave-special-lib-test (file)
8499 "Check the path of FILE against the regexps which define special libs.
8500 Return the name of the special lib if there is a match."
8501 (let ((alist idlwave-special-lib-alist)
8502 entry rtn)
8503 (cond
8504 ((stringp file)
8505 (while (setq entry (pop alist))
8506 (if (string-match (car entry) file)
8507 (setq rtn (cdr entry)
8508 alist nil)))
8509 rtn)
8510 (t nil))))
8512 (defun idlwave-mouse-active-rinfo-right (ev)
8513 (interactive "e")
8514 (idlwave-mouse-active-rinfo ev 'right))
8516 (defun idlwave-mouse-active-rinfo-shift (ev)
8517 (interactive "e")
8518 (idlwave-mouse-active-rinfo ev nil 'shift))
8520 (defun idlwave-active-rinfo-space ()
8521 (interactive)
8522 (idlwave-mouse-active-rinfo nil 'right))
8524 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
8525 "Do the mouse actions in the routine info buffer.
8526 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8527 was pressed."
8528 (interactive "e")
8529 (if ev (mouse-set-point ev))
8530 (let (data id name type class buf bufwin source link keyword
8531 word initial-class)
8532 (setq data (get-text-property (point) 'data)
8533 source (get-text-property (point) 'source)
8534 keyword (get-text-property (point) 'keyword)
8535 link (get-text-property (point) 'link)
8536 id (car data)
8537 name (nth 1 data) type (nth 2 data) class (nth 3 data)
8538 buf (nth 4 data)
8539 initial-class (nth 6 data)
8540 word (idlwave-this-word)
8541 bufwin (get-buffer-window buf t))
8543 (cond ((eq id 'class) ; Switch class being displayed
8544 (if (window-live-p bufwin) (select-window bufwin))
8545 (idlwave-display-calling-sequence
8546 (idlwave-sintern-method name)
8547 type (idlwave-sintern-class word)
8548 initial-class))
8549 ((eq id 'usage) ; Online help on this routine
8550 (idlwave-online-help link name type class))
8551 ((eq id 'source) ; Source in help or buffer
8552 (if right ; In help
8553 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8554 (idlwave-help-source-try-header nil)
8555 ;; Fake idlwave-routines so help will find the right entry
8556 (idlwave-routines
8557 (list (list name type class source ""))))
8558 (idlwave-help-get-special-help name type class nil))
8559 ;; Otherwise just pop to the source
8560 (setq idlwave-popup-source (not idlwave-popup-source))
8561 (if idlwave-popup-source
8562 (condition-case err
8563 (idlwave-do-find-module name type class source)
8564 (error
8565 (setq idlwave-popup-source nil)
8566 (if (window-live-p bufwin) (select-window bufwin))
8567 (error (nth 1 err))))
8568 (if bufwin
8569 (select-window bufwin)
8570 (pop-to-buffer buf))
8571 (goto-char (marker-position idlwave-rinfo-marker)))))
8572 ((eq id 'keyword)
8573 (if right
8574 (idlwave-online-help link name type class keyword)
8575 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8577 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8578 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8579 (let ((bwin (get-buffer-window buffer)))
8580 (if idlwave-complete-empty-string-as-lower-case
8581 (setq keyword (downcase keyword)))
8582 (if bwin
8583 (select-window bwin)
8584 (pop-to-buffer buffer)
8585 (setq bwin (get-buffer-window buffer)))
8586 (if (eq (preceding-char) ?/)
8587 (insert keyword)
8588 (unless (save-excursion
8589 (re-search-backward
8590 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
8591 (min (- (point) 100) (point-min)) t))
8592 (insert ", "))
8593 (if shift (insert "/"))
8594 (insert keyword)
8595 (if (and (not shift)
8596 idlwave-keyword-completion-adds-equal)
8597 (insert "=")))))
8599 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
8600 "List the load path shadows of all routines defined in current buffer."
8601 (interactive "P")
8602 (idlwave-routines)
8603 (if (derived-mode-p 'idlwave-mode)
8604 (idlwave-list-load-path-shadows
8605 nil (idlwave-update-current-buffer-info 'save-buffer)
8606 "in current buffer")
8607 (error "Current buffer is not in idlwave-mode")))
8609 (defun idlwave-list-shell-load-path-shadows (&optional arg)
8610 "List the load path shadows of all routines compiled under the shell.
8611 This is very useful for checking an IDL application. Just compile the
8612 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8613 routines and update IDLWAVE internal info. Then check for shadowing
8614 with this command."
8615 (interactive "P")
8616 (cond
8617 ((or (not (fboundp 'idlwave-shell-is-running))
8618 (not (idlwave-shell-is-running)))
8619 (error "Shell is not running"))
8620 ((null idlwave-compiled-routines)
8621 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
8623 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8624 "in the shell"))))
8626 (defun idlwave-list-all-load-path-shadows (&optional arg)
8627 "List the load path shadows of all routines known to IDLWAVE."
8628 (interactive "P")
8629 (idlwave-list-load-path-shadows nil nil "globally"))
8631 (defvar idlwave-sort-prefer-buffer-info t
8632 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8634 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8635 "List the routines which are defined multiple times.
8636 Search the information IDLWAVE has about IDL routines for multiple
8637 definitions.
8638 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8640 When IDL hits a routine call which is not defined, it will search on
8641 the load path in order to find a definition. The output of this command
8642 can be used to detect possible name clashes during this process."
8643 (idlwave-routines) ; Make sure everything is loaded.
8644 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
8645 (or (y-or-n-p
8646 "You don't have any user or library catalogs. Continue anyway? ")
8647 (error "Abort")))
8648 (let* ((routines (append idlwave-system-routines
8649 idlwave-compiled-routines
8650 idlwave-library-catalog-routines
8651 idlwave-user-catalog-routines
8652 idlwave-buffer-routines
8653 nil))
8654 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8655 (keymap (make-sparse-keymap))
8656 (props (list 'mouse-face 'highlight
8657 km-prop keymap
8658 'help-echo "Mouse2: Find source"))
8659 (nroutines (length (or special-routines routines)))
8660 (step (/ nroutines 100))
8661 (n 0)
8662 (cnt 0)
8663 (idlwave-sort-prefer-buffer-info nil)
8664 routine twins dtwins twin done props1 lroutines)
8666 (if special-routines
8667 ;; Just looking for shadows of a few special routines
8668 (setq lroutines routines
8669 routines special-routines))
8671 (message "Sorting routines...")
8672 (setq routines (sort routines
8673 (lambda (a b)
8674 (string< (downcase (idlwave-make-full-name
8675 (nth 2 a) (car a)))
8676 (downcase (idlwave-make-full-name
8677 (nth 2 b) (car b)))))))
8678 (message "Sorting routines...done")
8680 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
8681 (lambda (ev)
8682 (interactive "e")
8683 (mouse-set-point ev)
8684 (apply 'idlwave-do-find-module
8685 (get-text-property (point) 'find-args))))
8686 (define-key keymap [(return)]
8687 (lambda ()
8688 (interactive)
8689 (apply 'idlwave-do-find-module
8690 (get-text-property (point) 'find-args))))
8691 (message "Compiling list...( 0%%)")
8692 (with-current-buffer (get-buffer-create "*Shadows*")
8693 (setq buffer-read-only nil)
8694 (erase-buffer)
8695 (while (setq routine (pop routines))
8696 (if (= (mod (setq n (1+ n)) step) 0)
8697 (message "Compiling list...(%2d%%)" (floor (* n 100.0) nroutines)))
8699 ;; Get a list of all twins
8700 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8701 (if (memq routine done)
8702 (setq dtwins nil)
8703 (setq dtwins (idlwave-study-twins twins)))
8704 ;; Mark all twins as dealt with
8705 (setq done (append twins done))
8706 (when (or (> (length dtwins) 1)
8707 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8708 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8709 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
8710 (incf cnt)
8711 (insert (format "\n%s%s"
8712 (idlwave-make-full-name (nth 2 routine)
8713 (car routine))
8714 (if (eq (nth 1 routine) 'fun) "()" "")))
8715 (while (setq twin (pop dtwins))
8716 (setq props1 (append (list 'find-args
8717 (list (nth 0 routine)
8718 (nth 1 routine)
8719 (nth 2 routine)))
8720 props))
8721 (idlwave-insert-source-location "\n - " twin props1))))
8722 (goto-char (point-min))
8723 (setq buffer-read-only t))
8724 (setq loc (or loc ""))
8725 (if (> cnt 0)
8726 (progn
8727 (display-buffer (get-buffer "*Shadows*"))
8728 (message "%d case%s of shadowing found %s"
8729 cnt (if (= cnt 1) "" "s") loc))
8730 (message "No shadowing conflicts found %s" loc))))
8732 (defun idlwave-print-source (routine)
8733 (let* ((source (nth 3 routine))
8734 (stype (car source))
8735 (sfile (idlwave-routine-source-file source)))
8736 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
8737 (if (and (eq stype 'compiled)
8738 (or (not (stringp sfile))
8739 (not (string-match "\\S-" sfile))))
8740 (setq stype 'unresolved))
8741 (princ (format " %-10s %s\n"
8742 stype
8743 (if sfile sfile "No source code available")))))
8745 (defun idlwave-routine-twins (entry &optional list)
8746 "Return all twin entries of ENTRY in LIST.
8747 LIST defaults to `idlwave-routines'.
8748 Twin entries are those which have the same name, type, and class.
8749 ENTRY will also be returned, as the first item of this list."
8750 (let* ((name (car entry))
8751 (type (nth 1 entry))
8752 (class (nth 2 entry))
8753 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8754 twins candidate)
8755 (while (setq candidate (pop candidates))
8756 (if (and (not (eq candidate entry))
8757 (eq type (nth 1 candidate))
8758 (eq class (nth 2 candidate)))
8759 (push candidate twins)))
8760 (if (setq candidate (idlwave-rinfo-assq name type class
8761 idlwave-unresolved-routines))
8762 (push candidate twins))
8763 (cons entry (nreverse twins))))
8765 (defun idlwave-study-twins (entries)
8766 "Return dangerous twins of first entry in ENTRIES.
8767 Dangerous twins are routines with same name, but in different files on
8768 the load path. If a file is in the system library and has an entry in
8769 the `idlwave-system-routines' list, we omit the latter as
8770 non-dangerous because many IDL routines are implemented as library
8771 routines, and may have been scanned."
8772 (let* ((entry (car entries))
8773 (idlwave-twin-name (car entry)) ;
8774 (type (nth 1 entry)) ; Must be bound for
8775 (idlwave-twin-class (nth 2 entry)) ; idlwave-routine-twin-compare
8776 (cnt 0)
8777 source type type-cons file alist syslibp key)
8778 (while (setq entry (pop entries))
8779 (incf cnt)
8780 (setq source (nth 3 entry)
8781 type (car source)
8782 type-cons (cons type (nth 3 source))
8783 file (idlwave-routine-source-file source))
8785 ;; Make KEY to index entry properly
8786 (setq key (cond ((eq type 'system) type)
8787 (file (file-truename file))
8788 (t 'unresolved)))
8790 ;; Check for an entry in the system library
8791 (if (and file
8792 (not syslibp)
8793 (idlwave-syslib-p file))
8794 (setq syslibp t))
8796 ;; If there's more than one matching entry for the same file, just
8797 ;; append the type-cons to the type list.
8798 (if (setq entry (assoc key alist))
8799 (push type-cons (nth 2 entry))
8800 (push (list key file (list type-cons)) alist)))
8802 (setq alist (nreverse alist))
8804 (when syslibp
8805 ;; File is in system *library* - remove any 'system entry
8806 (setq alist (delq (assq 'system alist) alist)))
8808 ;; If 'system remains and we've scanned the syslib, it's a builtin
8809 ;; (rather than a !DIR/lib/.pro file bundled as source).
8810 (when (and (idlwave-syslib-scanned-p)
8811 (setq entry (assoc 'system alist)))
8812 (setcar entry 'builtin))
8813 (sort alist 'idlwave-routine-twin-compare)))
8815 ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
8816 ;; (defvar type)
8817 (defmacro idlwave-xor (a b)
8818 `(and (or ,a ,b)
8819 (not (and ,a ,b))))
8821 (defun idlwave-routine-entry-compare (a b)
8822 "Compare two routine info entries for sorting.
8823 This is the general case. It first compares class, names, and type.
8824 If it turns out that A and B are twins (same name, class, and type),
8825 calls another routine which compares twins on the basis of their file
8826 names and path locations."
8827 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8828 (cond
8829 ((not (equal (idlwave-downcase-safe class)
8830 (idlwave-downcase-safe (nth 2 b))))
8831 ;; Class decides
8832 (cond ((null (nth 2 b)) nil)
8833 ((null class) t)
8834 (t (string< (downcase class) (downcase (nth 2 b))))))
8835 ((not (equal (downcase name) (downcase (car b))))
8836 ;; Name decides
8837 (string< (downcase name) (downcase (car b))))
8838 ((not (eq type (nth 1 b)))
8839 ;; Type decides
8840 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
8842 ;; A and B are twins - so the decision is more complicated.
8843 ;; Call twin-compare with the proper arguments.
8844 (idlwave-routine-entry-compare-twins a b)))))
8846 (defun idlwave-routine-entry-compare-twins (a b)
8847 "Compare two routine entries, under the assumption that they are twins.
8848 This basically calls `idlwave-routine-twin-compare' with the correct args."
8849 (let* ((idlwave-twin-name (car a))
8850 (type (nth 1 a))
8851 (idlwave-twin-class (nth 2 a)) ; used in idlwave-routine-twin-compare
8852 (asrc (nth 3 a))
8853 (atype (car asrc))
8854 (bsrc (nth 3 b))
8855 (btype (car bsrc))
8856 (afile (idlwave-routine-source-file asrc))
8857 (bfile (idlwave-routine-source-file bsrc)))
8858 (idlwave-routine-twin-compare
8859 (if (stringp afile)
8860 (list (file-truename afile) afile (list atype))
8861 (list atype afile (list atype)))
8862 (if (stringp bfile)
8863 (list (file-truename bfile) bfile (list btype))
8864 (list btype bfile (list btype))))))
8866 ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
8867 (defvar idlwave-twin-class)
8868 (defvar idlwave-twin-name)
8870 (defun idlwave-routine-twin-compare (a b)
8871 "Compare two routine twin entries for sorting.
8872 In here, A and B are not normal routine info entries, but special
8873 lists (KEY FILENAME (TYPES...)).
8874 This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
8875 (let* (;; Dis-assemble entries
8876 (akey (car a)) (bkey (car b))
8877 (afile (nth 1 a)) (bfile (nth 1 b))
8878 (atypes (nth 2 a)) (btypes (nth 2 b))
8879 ;; System routines?
8880 (asysp (memq akey '(builtin system)))
8881 (bsysp (memq bkey '(builtin system)))
8882 ;; Compiled routines?
8883 (acompp (memq 'compiled atypes))
8884 (bcompp (memq 'compiled btypes))
8885 ;; Unresolved?
8886 (aunresp (or (eq akey 'unresolved)
8887 (and acompp (not afile))))
8888 (bunresp (or (eq bkey 'unresolved)
8889 (and bcompp (not bfile))))
8890 ;; Buffer info available?
8891 (abufp (memq 'buffer atypes))
8892 (bbufp (memq 'buffer btypes))
8893 ;; On search path?
8894 (tpath-alist (idlwave-true-path-alist))
8895 (apathp (and (stringp akey)
8896 (assoc (file-name-directory akey) tpath-alist)))
8897 (bpathp (and (stringp bkey)
8898 (assoc (file-name-directory bkey) tpath-alist)))
8899 ;; How early on search path? High number means early since we
8900 ;; measure the tail of the path list
8901 (anpath (length (memq apathp tpath-alist)))
8902 (bnpath (length (memq bpathp tpath-alist)))
8903 ;; Look at file names
8904 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8905 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8906 (fname-re (if idlwave-twin-class
8907 (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8908 (regexp-quote (downcase idlwave-twin-class))
8909 (regexp-quote (downcase idlwave-twin-name)))
8910 (format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
8911 ;; Is file name derived from the routine name?
8912 ;; Method file or class definition file?
8913 (anamep (string-match fname-re aname))
8914 (adefp (and idlwave-twin-class anamep
8915 (string= "define" (match-string 1 aname))))
8916 (bnamep (string-match fname-re bname))
8917 (bdefp (and idlwave-twin-class bnamep
8918 (string= "define" (match-string 1 bname)))))
8920 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8921 ;; doesn't it? The difficult stuff is hidden above...
8922 (cond
8923 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8924 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8925 ((and idlwave-sort-prefer-buffer-info
8926 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8927 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8928 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8929 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8930 ((and idlwave-twin-class anamep bnamep ; both file names match ->
8931 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8932 ((> anpath bnpath) t) ; Who is first on path?
8933 (t nil)))) ; Default
8935 (defun idlwave-routine-source-file (source)
8936 (if (nth 2 source)
8937 (expand-file-name (nth 1 source) (nth 2 source))
8938 (nth 1 source)))
8940 (defun idlwave-downcase-safe (string)
8941 "Downcase if string, else return unchanged."
8942 (if (stringp string)
8943 (downcase string)
8944 string))
8946 (defun idlwave-count-eq (elt list)
8947 "How often is ELT in LIST?"
8948 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8950 (defun idlwave-count-memq (elt alist)
8951 "How often is ELT a key in ALIST?"
8952 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8954 (defun idlwave-syslib-p (file)
8955 "Non-nil if FILE is in the system library."
8956 (let* ((true-syslib (file-name-as-directory
8957 (file-truename
8958 (expand-file-name "lib" (idlwave-sys-dir)))))
8959 (true-file (file-truename file)))
8960 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8962 (defun idlwave-lib-p (file)
8963 "Non-nil if FILE is in the library."
8964 (let ((true-dir (file-name-directory (file-truename file))))
8965 (assoc true-dir (idlwave-true-path-alist))))
8967 (defun idlwave-path-alist-add-flag (list-entry flag)
8968 "Add a flag to the path list entry, if not set."
8969 (let ((flags (cdr list-entry)))
8970 (add-to-list 'flags flag)
8971 (setcdr list-entry flags)))
8973 (defun idlwave-path-alist-remove-flag (list-entry flag)
8974 "Remove a flag to the path list entry, if set."
8975 (let ((flags (delq flag (cdr list-entry))))
8976 (setcdr list-entry flags)))
8978 (defun idlwave-true-path-alist ()
8979 "Return `idlwave-path-alist' alist with true-names.
8980 Info is cached, but relies on the functions setting `idlwave-path-alist'
8981 to reset the variable `idlwave-true-path-alist' to nil."
8982 (or idlwave-true-path-alist
8983 (setq idlwave-true-path-alist
8984 (mapcar (lambda(x) (cons
8985 (file-name-as-directory
8986 (file-truename
8987 (directory-file-name
8988 (car x))))
8989 (cdr x)))
8990 idlwave-path-alist))))
8992 (defun idlwave-syslib-scanned-p ()
8993 "Non-nil if the system lib file !DIR/lib has been scanned."
8994 (let* ((true-syslib (file-name-as-directory
8995 (file-truename
8996 (expand-file-name "lib" (idlwave-sys-dir))))))
8997 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8999 ;; ----------------------------------------------------------------------------
9001 ;; Online Help display
9004 ;; ----------------------------------------------------------------------------
9006 ;; Additions for use with imenu.el and func-menu.el
9007 ;; (pop-up a list of IDL units in the current file).
9010 (defun idlwave-prev-index-position ()
9011 "Search for the previous procedure or function.
9012 Return nil if not found. For use with imenu.el."
9013 (save-match-data
9014 (cond
9015 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9016 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9017 (t nil))))
9019 (defun idlwave-unit-name ()
9020 "Return the unit name.
9021 Assumes that point is at the beginning of the unit as found by
9022 `idlwave-prev-index-position'."
9023 (forward-sexp 2)
9024 (forward-sexp -1)
9025 (let ((begin (point)))
9026 (re-search-forward
9027 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
9028 (if (fboundp 'buffer-substring-no-properties)
9029 (buffer-substring-no-properties begin (point))
9030 (buffer-substring begin (point)))))
9032 (defalias 'idlwave-function-menu
9033 (condition-case nil
9034 (progn
9035 (require 'func-menu)
9036 'function-menu)
9037 (error (condition-case nil
9038 (progn
9039 (require 'imenu)
9040 'imenu)
9041 (error nil)))))
9043 ;; Here we hack func-menu.el in order to support this new mode.
9044 ;; The latest versions of func-menu.el already have this stuff in, so
9045 ;; we hack only if it is not already there.
9046 (when (featurep 'xemacs)
9047 (eval-after-load "func-menu"
9048 '(progn
9049 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9050 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9051 (setq fume-function-name-regexp-alist
9052 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9053 fume-function-name-regexp-alist)))
9054 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9055 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9056 (setq fume-find-function-name-method-alist
9057 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9058 fume-find-function-name-method-alist))))))
9060 (defun idlwave-edit-in-idlde ()
9061 "Edit the current file in IDL Development environment."
9062 (interactive)
9063 (start-process "idldeclient" nil
9064 idlwave-shell-explicit-file-name "-c" "-e"
9065 (buffer-file-name)))
9067 (defvar idlwave-help-use-assistant)
9068 (defun idlwave-launch-idlhelp ()
9069 "Start the IDLhelp application."
9070 (interactive)
9071 (if idlwave-help-use-assistant
9072 (idlwave-help-assistant-raise)
9073 (start-process "idlhelp" nil idlwave-help-application)))
9075 ;; Menus - using easymenu.el
9076 (defvar idlwave-mode-menu-def
9077 `("IDLWAVE"
9078 ["PRO/FUNC menu" idlwave-function-menu t]
9079 ("Motion"
9080 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9081 ["Subprogram End" idlwave-end-of-subprogram t]
9082 ["Block Start" idlwave-beginning-of-block t]
9083 ["Block End" idlwave-end-of-block t]
9084 ["Up Block" idlwave-backward-up-block t]
9085 ["Down Block" idlwave-down-block t]
9086 ["Skip Block Backward" idlwave-backward-block t]
9087 ["Skip Block Forward" idlwave-forward-block t])
9088 ("Mark"
9089 ["Subprogram" idlwave-mark-subprogram t]
9090 ["Block" idlwave-mark-block t]
9091 ["Header" idlwave-mark-doclib t])
9092 ("Format"
9093 ["Indent Entire Statement" idlwave-indent-statement
9094 :active t :keys "C-u \\[indent-for-tab-command]" ]
9095 ["Indent Subprogram" idlwave-indent-subprogram t]
9096 ["(Un)Comment Region" idlwave-toggle-comment-region t]
9097 ["Continue/Split line" idlwave-split-line t]
9098 "--"
9099 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9100 :selected (symbol-value idlwave-fill-function)])
9101 ("Templates"
9102 ["Procedure" idlwave-procedure t]
9103 ["Function" idlwave-function t]
9104 ["Doc Header" idlwave-doc-header t]
9105 ["Log" idlwave-doc-modification t]
9106 "--"
9107 ["Case" idlwave-case t]
9108 ["For" idlwave-for t]
9109 ["Repeat" idlwave-repeat t]
9110 ["While" idlwave-while t]
9111 "--"
9112 ["Close Block" idlwave-close-block t])
9113 ("Completion"
9114 ["Complete" idlwave-complete t]
9115 ("Complete Specific"
9116 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9117 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9118 "--"
9119 ["3 Function Name" (idlwave-complete 'function) t]
9120 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9121 "--"
9122 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9123 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9124 "--"
9125 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9126 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9127 "--"
9128 ["9 Class Name" idlwave-complete-class t]))
9129 ("Routine Info"
9130 ["Show Routine Info" idlwave-routine-info t]
9131 ["Online Context Help" idlwave-context-help t]
9132 "--"
9133 ["Find Routine Source" idlwave-find-module t]
9134 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
9135 "--"
9136 ["Update Routine Info" idlwave-update-routine-info t]
9137 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
9138 "--"
9139 "IDL User Catalog"
9140 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
9141 ["Scan Directories" (idlwave-update-routine-info '(16))
9142 (and idlwave-path-alist (not idlwave-catalog-process))]
9143 ["Scan Directories &" (idlwave-update-routine-info '(64))
9144 (and idlwave-path-alist (not idlwave-catalog-process))]
9145 "--"
9146 "Routine Shadows"
9147 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9148 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9149 ["Check Everything" idlwave-list-all-load-path-shadows t])
9150 ("Misc"
9151 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9152 "--"
9153 ["Insert TAB character" idlwave-hard-tab t])
9154 "--"
9155 ("External"
9156 ["Start IDL shell" idlwave-shell t]
9157 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9158 ["Launch IDL Help" idlwave-launch-idlhelp t])
9159 "--"
9160 ("Customize"
9161 ["Browse IDLWAVE Group" idlwave-customize t]
9162 "--"
9163 ["Build Full Customize Menu" idlwave-create-customize-menu
9164 (fboundp 'customize-menu-create)])
9165 ("Documentation"
9166 ["Describe Mode" describe-mode t]
9167 ["Abbreviation List" idlwave-list-abbrevs t]
9168 "--"
9169 ["Commentary in idlwave.el" idlwave-show-commentary t]
9170 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
9171 "--"
9172 ["Info" idlwave-info t]
9173 "--"
9174 ["Help with Topic" idlwave-help-assistant-help-with-topic
9175 idlwave-help-use-assistant]
9176 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9178 (defvar idlwave-mode-debug-menu-def
9179 '("Debug"
9180 ["Start IDL shell" idlwave-shell t]
9181 ["Save and .RUN buffer" idlwave-shell-save-and-run
9182 (and (boundp 'idlwave-shell-automatic-start)
9183 idlwave-shell-automatic-start)]))
9185 (if (or (featurep 'easymenu) (load "easymenu" t))
9186 (progn
9187 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9188 "IDL and WAVE CL editing menu"
9189 idlwave-mode-menu-def)
9190 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9191 "IDL and WAVE CL editing menu"
9192 idlwave-mode-debug-menu-def)))
9194 (defun idlwave-customize ()
9195 "Call the customize function with `idlwave' as argument."
9196 (interactive)
9197 ;; Try to load the code for the shell, so that we can customize it
9198 ;; as well.
9199 (or (featurep 'idlw-shell)
9200 (load "idlw-shell" t))
9201 (customize-browse 'idlwave))
9203 (defun idlwave-create-customize-menu ()
9204 "Create a full customization menu for IDLWAVE, insert it into the menu."
9205 (interactive)
9206 (if (fboundp 'customize-menu-create)
9207 (progn
9208 ;; Try to load the code for the shell, so that we can customize it
9209 ;; as well.
9210 (or (featurep 'idlw-shell)
9211 (load "idlw-shell" t))
9212 (easy-menu-change
9213 '("IDLWAVE") "Customize"
9214 `(["Browse IDLWAVE group" idlwave-customize t]
9215 "--"
9216 ,(customize-menu-create 'idlwave)
9217 ["Set" Custom-set t]
9218 ["Save" Custom-save t]
9219 ["Reset to Current" Custom-reset-current t]
9220 ["Reset to Saved" Custom-reset-saved t]
9221 ["Reset to Standard Settings" Custom-reset-standard t]))
9222 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9223 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9225 (defun idlwave-show-commentary ()
9226 "Use the finder to view the file documentation from `idlwave.el'."
9227 (interactive)
9228 (finder-commentary "idlwave.el"))
9230 (defun idlwave-shell-show-commentary ()
9231 "Use the finder to view the file documentation from `idlw-shell.el'."
9232 (interactive)
9233 (finder-commentary "idlw-shell.el"))
9235 (defun idlwave-info ()
9236 "Read documentation for IDLWAVE in the info system."
9237 (interactive)
9238 (info "idlwave"))
9240 (defun idlwave-list-abbrevs (arg)
9241 "Show the code abbreviations define in IDLWAVE mode.
9242 This lists all abbrevs where the replacement text differs from the input text.
9243 These are the ones the users want to learn to speed up their writing.
9245 The function does *not* list abbrevs which replace a word with itself
9246 to call a hook. These hooks are used to change the case of words or
9247 to blink the matching `begin', and the user does not need to know them.
9249 With arg, list all abbrevs with the corresponding hook.
9251 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9253 (interactive "P")
9254 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9255 abbrevs
9256 str rpl func fmt (len-str 0) (len-rpl 0))
9257 (mapatoms
9258 (lambda (sym)
9259 (if (symbol-value sym)
9260 (progn
9261 (setq str (symbol-name sym)
9262 rpl (symbol-value sym)
9263 func (symbol-function sym))
9264 (if arg
9265 (setq func (prin1-to-string func))
9266 (if (and (listp func) (stringp (nth 2 func)))
9267 (setq rpl (concat "EVAL: " (nth 2 func))
9268 func "")
9269 (setq func "")))
9270 (if (or arg (not (string= rpl str)))
9271 (progn
9272 (setq len-str (max len-str (length str)))
9273 (setq len-rpl (max len-rpl (length rpl)))
9274 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9275 table)
9276 ;; sort the list
9277 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9278 ;; Make the format
9279 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9280 (with-output-to-temp-buffer "*Help*"
9281 (if arg
9282 (progn
9283 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
9284 (princ "=========================================\n\n")
9285 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9286 (princ (format fmt "---" "-------" "----")))
9287 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9288 (princ "================================================\n\n")
9289 (princ (format fmt "KEY" "ACTION" ""))
9290 (princ (format fmt "---" "------" "")))
9291 (dolist (list abbrevs)
9292 (setq str (car list)
9293 rpl (nth 1 list)
9294 func (nth 2 list))
9295 (princ (format fmt str rpl func)))))
9296 ;; Make sure each abbreviation uses only one display line
9297 (with-current-buffer "*Help*"
9298 (setq truncate-lines t)))
9300 (declare-function speedbar-add-supported-extension "speedbar" (extension))
9302 ;; Add .pro files to speedbar for support, if it's loaded
9303 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9305 ;; Set an idle timer to load the routine info.
9306 ;; Will only work on systems which support this.
9307 (or idlwave-routines (idlwave-start-load-rinfo-timer))
9309 ;; Run the hook
9310 (run-hooks 'idlwave-load-hook)
9312 (provide 'idlwave)
9314 ;;; idlwave.el ends here