1 ;;; idlwave.el --- IDL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001,2002 Free Software Foundation
4 ;; Author: Carsten Dominik <dominik@astro.uva.nl>
5 ;; Chris Chase <chase@att.com>
6 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
8 ;; Date: $Date: 2002/10/18 08:12:35 $
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; In distant past, based on pascal.el. Though bears little
31 ;; resemblance to that now.
33 ;; Incorporates many ideas, such as abbrevs, action routines, and
34 ;; continuation line indenting, from wave.el.
35 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
37 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
38 ;; for features, key bindings, and info.
39 ;; Also, Info format documentation is available with `M-x idlwave-info'
41 ;; New versions of IDLWAVE, documentation, and more information
48 ;; Follow the instructions in the INSTALL file of the distribution.
49 ;; In short, put this file on your load path and add the following
50 ;; lines to your .emacs file:
52 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
53 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
54 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
60 ;; The newest version of this file is available from the maintainer's
68 ;; IDLWAVE is documented online in info format.
69 ;; A printable version of the documentation is available from the
70 ;; maintainers webpage (see under SOURCE)
76 ;; Thanks to the following people for their contributions and comments:
78 ;; Ulrik Dickow <dickow@nbi.dk>
79 ;; Eric E. Dors <edors@lanl.gov>
80 ;; Stein Vidar H. Haugan <s.v.h.haugan@astro.uio.no>
81 ;; David Huenemoerder <dph@space.mit.edu>
82 ;; Kevin Ivory <Kevin.Ivory@linmpi.mpg.de>
83 ;; Xuyong Liu <liu@stsci.edu>
84 ;; Simon Marshall <Simon.Marshall@esrin.esa.it>
85 ;; Laurent Mugnier <mugnier@onera.fr>
86 ;; Lubos Pochman <lubos@rsinc.com>
87 ;; Bob Portmann <portmann@al.noaa.gov>
88 ;; Patrick M. Ryan <pat@jaameri.gsfc.nasa.gov>
89 ;; Marty Ryba <ryba@ll.mit.edu>
90 ;; Phil Williams <williams@irc.chmcc.org>
91 ;; Phil Sterne <sterne@dublin.llnl.gov>
96 ;; IDLWAVE has extensive customize support - so if you want to learn
97 ;; about the variables which control the behavior of the mode, use
98 ;; `M-x idlwave-customize'.
100 ;; You can set your own preferred values with Customize, or with Lisp
101 ;; code in .emacs. For an example of what to put into .emacs, check
102 ;; the TexInfo documentation or see a complete .emacs at
103 ;; http://idlwave.org.
108 ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
109 ;; Numerics, Inc. is growing less and less complete as the two
110 ;; languages grow increasingly apart. The mode probably shouldn't
111 ;; even have "WAVE" in it's title, but it's catchy, and required to
112 ;; avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
114 ;; Moving the point backwards in conjunction with abbrev expansion
115 ;; does not work as I would like it, but this is a problem with
116 ;; emacs abbrev expansion done by the self-insert-command. It ends
117 ;; up inserting the character that expanded the abbrev after moving
118 ;; point backward, e.g., "\cl" expanded with a space becomes
119 ;; "LONG( )" with point before the close paren. This is solved by
120 ;; using a temporary function in `post-command-hook' - not pretty,
123 ;; Tabs and spaces are treated equally as whitespace when filling a
124 ;; comment paragraph. To accomplish this, tabs are permanently
125 ;; replaced by spaces in the text surrounding the paragraph, which
126 ;; may be an undesirable side-effect. Replacing tabs with spaces is
127 ;; limited to comments only and occurs only when a comment
128 ;; paragraph is filled via `idlwave-fill-paragraph'.
130 ;; Avoid muti-statement lines (using "&") on block begin and end
131 ;; lines. Multi-statement lines can mess up the formatting, for
132 ;; example, multiple end statements on a line: endif & endif.
133 ;; Using "&" outside of block begin/end lines should be okay.
135 ;; Determining the expression at point for printing and other
136 ;; examination commands is somewhat rough: currently only fairly
137 ;; simple entities are found. You can always drag-select or examine
140 ;; When forcing completion of method keywords, the initial
141 ;; query for a method has multiple entries for some methods. Would
142 ;; be too difficult to fix this hardly used case.
147 (eval-when-compile (require 'cl
))
150 ;; Kludge to allow `defcustom' for Emacs 19.
151 (condition-case () (require 'custom
) (error nil
))
152 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
153 nil
;; We've got what we needed
154 ;; We have the old or no custom-library, hack around it!
155 (defmacro defgroup
(&rest args
) nil
)
156 (defmacro defcustom
(var value doc
&rest args
)
157 `(defvar ,var
,value
,doc
))))
159 (defgroup idlwave nil
160 "Major mode for editing IDL .pro files"
162 :link
'(url-link :tag
"Home Page"
163 "http://idlwave.org")
164 :link
'(emacs-commentary-link :tag
"Commentary in idlw-shell.el"
166 :link
'(emacs-commentary-link :tag
"Commentary in idlwave.el" "idlwave.el")
167 :link
'(custom-manual "(idlwave)Top")
171 ;;; Variables for indentation behavior ---------------------------------------
173 (defgroup idlwave-code-formatting nil
174 "Indentation and formatting options for IDLWAVE mode."
177 (defcustom idlwave-main-block-indent
0
178 "*Extra indentation for the main block of code.
179 That is the block between the FUNCTION/PRO statement and the END
180 statement for that program unit."
181 :group
'idlwave-code-formatting
184 (defcustom idlwave-block-indent
4
185 "*Extra indentation applied to block lines.
186 If you change this, you probably also want to change `idlwave-end-offset'."
187 :group
'idlwave-code-formatting
190 (defcustom idlwave-end-offset -
4
191 "*Extra indentation applied to block END lines.
192 A value equal to negative `idlwave-block-indent' will make END lines
193 line up with the block BEGIN lines."
194 :group
'idlwave-code-formatting
197 (defcustom idlwave-continuation-indent
2
198 "*Extra indentation applied to continuation lines.
199 This extra offset applies to the first of a set of continuation lines.
200 The following lines receive the same indentation as the first."
201 :group
'idlwave-code-formatting
204 (defcustom idlwave-max-extra-continuation-indent
20
205 "*Maximum additional indentation for special continuation indent.
206 Several special indentations are tried to help line up continuation
207 lines in routine calls or definitions, other statements with
208 parentheses, or assignment statements. This variable specifies a
209 maximum amount by which this special indentation can exceed the
210 standard continuation indentation, otherwise defaulting to a fixed
211 offset. Set to 0 to effectively disable all special continuation
212 indentation, or to a large number (like 100) to enable it in all
213 cases. See also `idlwave-indent-top-open-paren', which can override
215 :group
'idlwave-code-formatting
218 (defcustom idlwave-indent-to-open-paren t
219 "*Non-nil means, indent continuation lines to innermost open
220 parenthesis. This indentation occurs even if otherwise disallowed by
221 `idlwave-max-extra-continuation-indent'. Matching parens and the
222 interleaving args are lined up. Example:
224 x = function_a(function_b(function_c( a, b, [1,2,3, $
230 When this variable is nil, paren alignment may still occur, based on
231 the value of `max-extra-continuation-indent', which, if zero, would
234 x = function_a(function_b(function_c( a, b, [1,2,3, $
239 :group
'idlwave-code-formatting
242 (defcustom idlwave-hanging-indent t
243 "*If set non-nil then comment paragraphs are indented under the
244 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
246 :group
'idlwave-code-formatting
249 (defcustom idlwave-hang-indent-regexp
"- "
250 "*Regular expression matching the position of the hanging indent
251 in the first line of a comment paragraph. The size of the indent
252 extends to the end of the match for the regular expression."
253 :group
'idlwave-code-formatting
256 (defcustom idlwave-use-last-hang-indent nil
257 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
258 :group
'idlwave-code-formatting
261 (defcustom idlwave-fill-comment-line-only t
262 "*If non-nil then auto fill will only operate on comment lines."
263 :group
'idlwave-code-formatting
266 (defcustom idlwave-auto-fill-split-string t
267 "*If non-nil then auto fill will split strings with the IDL `+' operator.
268 When the line end falls within a string, string concatenation with the
269 '+' operator will be used to distribute a long string over lines.
270 If nil and a string is split then a terminal beep and warning are issued.
272 This variable is ignored when `idlwave-fill-comment-line-only' is
273 non-nil, since in this case code is not auto-filled."
274 :group
'idlwave-code-formatting
277 (defcustom idlwave-split-line-string t
278 "*If non-nil then `idlwave-split-line' will split strings with `+'.
279 When the splitting point of a line falls inside a string, split the string
280 using the `+' string concatenation operator. If nil and a string is
281 split then a terminal beep and warning are issued."
282 :group
'idlwave-code-formatting
285 (defcustom idlwave-no-change-comment
";;;"
286 "*The indentation of a comment that starts with this regular
287 expression will not be changed. Note that the indentation of a comment
288 at the beginning of a line is never changed."
289 :group
'idlwave-code-formatting
292 (defcustom idlwave-begin-line-comment nil
293 "*A comment anchored at the beginning of line.
294 A comment matching this regular expression will not have its
295 indentation changed. If nil the default is \"^;\", i.e., any line
296 beginning with a \";\". Expressions for comments at the beginning of
297 the line should begin with \"^\"."
298 :group
'idlwave-code-formatting
299 :type
'(choice (const :tag
"Any line beginning with `;'" nil
)
302 (defcustom idlwave-code-comment
";;[^;]"
303 "*A comment that starts with this regular expression on a line by
304 itself is indented as if it is a part of IDL code. As a result if
305 the comment is not preceded by whitespace it is unchanged."
306 :group
'idlwave-code-formatting
309 ;; Comments not matching any of the above will be indented as a
310 ;; right-margin comment, i.e., to a minimum of `comment-column'.
313 ;;; Routine Info and Completion ---------------------------------------
315 (defgroup idlwave-routine-info nil
316 "Routine Info options for IDLWAVE mode."
320 (defcustom idlwave-init-rinfo-when-idle-after
10
321 "*Seconds of idle time before routine info is automatically initialized.
322 Initializing the routine info can take long, in particular if a large
323 library catalog is involved. When Emacs is idle for more than the number
324 of seconds specified by this variable, it starts the initialization.
325 The process is split into five steps, in order to keep possible work
326 interruption as short as possible. If one of the steps finishes, and no
327 user input has arrived in the mean time, initialization proceeds immediately
329 A good value for this variable is about 1/3 of the time initialization
330 take in you setup. So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
331 A Value of 0 means, don't initialize automatically."
332 :group
'idlwave-routine-info
335 (defcustom idlwave-scan-all-buffers-for-routine-info t
336 "*Non-nil means, scan buffers for IDL programs when updating info.
337 The scanning is done by the command `idlwave-update-routine-info'.
338 The following values are allowed:
340 nil Don't scan any buffers.
341 t Scan all idlwave-mode buffers in the current editing session.
342 current Scan only the current buffer, but no other buffers."
343 :group
'idlwave-routine-info
345 (const :tag
"No buffer" nil
)
346 (const :tag
"All buffers" t
)
347 (const :tag
"Current buffer only" 'current
)))
349 (defcustom idlwave-query-shell-for-routine-info t
350 "*Non-nil means query the shell for info about compiled routines.
351 Querying the shell is useful to get information about compiled modules,
352 and it is turned on by default. However, when you have a complete library
353 scan, this is not necessary."
354 :group
'idlwave-routine-info
357 (defcustom idlwave-auto-routine-info-updates
358 '(find-file save-buffer kill-buffer compile-buffer
)
359 "*Controls under what circumstances routine info is updated automatically.
363 \(...) A list of circumstances. Allowed members are:
364 find-file Add info for new IDLWAVE buffers.
365 save-buffer Update buffer info when buffer is saved
366 kill-buffer Remove buffer info when buffer gets killed
367 compile-buffer Update shell info after `idlwave-shell-save-and...'"
368 :group
'idlwave-routine-info
370 (const :tag
"Never" nil
)
371 (const :tag
"As often as possible" t
)
372 (set :tag
"Checklist" :greedy t
373 (const :tag
"When visiting a file" find-file
)
374 (const :tag
"When saving a buffer" save-buffer
)
375 (const :tag
"After a buffer was killed" kill-buffer
)
376 (const :tag
"After a buffer was compiled successfully, update shell info" compile-buffer
))))
378 (defcustom idlwave-rinfo-max-source-lines
5
379 "*Maximum number of source files displayed in the Routine Info window.
380 When an integer, it is the maximum number of source files displayed.
381 t means to show all source files."
382 :group
'idlwave-routine-info
385 (defcustom idlwave-library-path nil
386 "Library path for Windows and MacOS. Not needed under Unix.
387 When selecting the directories to scan for IDL library routine info,
388 IDLWAVE can under UNIX query the shell for the exact search path.
389 However, under Windows and MacOS, the IDLWAVE shell does not work. In this
390 case, this variable specifies the path where IDLWAVE can find library files.
391 The shell will only be asked when this variable is nil.
392 The value is a list of directories. A directory preceeded by a `+' will
393 be searched recursively. If you set this variable on a UNIX system, the shell
395 See also `idlwave-system-directory'."
396 :group
'idlwave-routine-info
397 :type
'(repeat (directory)))
399 (defcustom idlwave-system-directory
""
400 "The IDL system directory for Windows and MacOS. Not needed under UNIX.
401 Set this to the value of the `!DIR' system variable in IDL. IDLWAVE uses
402 this to find out which of the library routines belong to the official system
403 library. All files inside the `lib' subdirectory are considered system
404 library files - so don't install private stuff in this directory.
405 On UNIX systems, IDLWAVE queries the shell for the value of `!DIR'.
406 See also `idlwave-library-path'."
407 :group
'idlwave-routine-info
410 (defcustom idlwave-libinfo-file
"~/.idlcat.el"
411 "*File for routine information of the IDL library.
412 When this points to a file, the file will be loaded when IDLWAVE first
413 accesses routine info (or does completion).
414 When you scan the library with `idlwave-create-libinfo-file', this file
415 will be used to store the result."
416 :group
'idlwave-routine-info
419 (defcustom idlwave-special-lib-alist nil
420 "Alist of regular expressions matching special library directories.
421 When listing routine source locations, IDLWAVE gives a short hint where
422 the file defining the routine is located. By default it lists `SystemLib'
423 for routines in the system library `!DIR/lib' and `Library' for anything
424 else. This variable can define additional types. The car of each entry
425 is a regular expression matching the file name (they normally will match
426 on the path). The cdr is the string to be used as identifier. Max 10
428 :group
'idlwave-routine-info
430 (cons regexp string
)))
432 (defgroup idlwave-online-help nil
433 "Online Help options for IDLWAVE mode."
436 (defcustom idlwave-help-directory
""
437 "The directory where idlw-help.txt and idlw-help.el are stored."
438 :group
'idlwave-online-help
441 (defcustom idlwave-help-use-dedicated-frame t
442 "*Non-nil means, use a separate frame for Online Help if possible."
443 :group
'idlwave-online-help
446 (defcustom idlwave-help-frame-parameters
447 '((height .
20) (unsplittable . t
))
448 "The frame parameters for the special Online Help frame.
449 See also `idlwave-help-use-dedicated-frame'.
450 If you do not set the frame width here, the value specified in
451 `idlw-help.el' will be used."
452 :group
'idlwave-online-help
456 (defcustom idlwave-max-popup-menu-items
20
457 "Maximum number of items per pane in popup menus.
458 Currently only used for class selection during completion help."
459 :group
'idlwave-online-help
462 (defcustom idlwave-extra-help-function
'idlwave-help-with-source
463 "The function to call for online help if the normal help fails.
464 Online help works only for system routines which are described in the
465 IDL manuals. A function may be specified to access help from other sources.
467 The function must accept four arguments: NAME, TYPE, CLASS, KEYWORD.
468 The Help buffer is current when this function is called, and the help
469 text should be loaded into this buffer. If help is found, the function
470 should return the buffer position which should be used as `window-start'
471 in the help window. Also, the variable `idlwave-help-mode-line-indicator'
472 should be set to a useful string, which will be displayed in the mode line
473 of the help window. If should also set the variable `idlwave-min-frame-width'
474 to a positive integer. IDLWAVE will ensure that the help frame is at
475 least that many columns wide.
476 Failure to find help should be indicated by throwing an error.
478 When this variable is non-nil, IDLWAVE will allow the mouse-3 help click
479 for every routine and keyword, even though the item may not be highlighted
480 in blue (indicating the availability of system documentation).
482 The default value for this function is `idlwave-help-with-source' which
483 loads the routine source file into the help buffer. If you try to write
484 a different function which accesses a special help file or so, it is
485 probably a good idea to still call this function as a fallback."
486 :group
'idlwave-online-help
489 (defcustom idlwave-help-fontify-source-code nil
490 "*Non-nil means, fontify source code displayed as help like normal code."
491 :group
'idlwave-online-help
494 (defcustom idlwave-help-source-try-header t
495 "*Non-nil means, try to find help in routine header when displaying source.
496 Routines which are not documented in the system manual use their source as
497 help text. When this variable is non-nil, we try to find a description of
498 the help item in the first routine doclib header above the routine definition.
499 If the variable is nil, or if we cannot find/parse the header, the routine
500 definition is displayed instead."
501 :group
'idlwave-online-help
504 (defface idlwave-help-link-face
505 '((((class color
)) (:foreground
"Blue"))
507 "Face for highlighting links into IDLWAVE online help."
508 :group
'idlwave-online-help
)
510 (defcustom idlwave-help-activate-links-aggressively t
511 "*Non-nil means, make all possible links in help active.
512 This just activates all words which are also a help topic - some links may
514 :group
'idlwave-online-help
518 (defgroup idlwave-completion nil
519 "Completion options for IDLWAVE mode."
524 (defconst idlwave-tmp
525 '(choice :tag
"by applying the function"
530 (symbol :tag
"Other"))))
532 (defcustom idlwave-completion-case
'((routine . upcase
)
536 "Association list setting the case of completed words.
538 This variable determines the case (UPPER/lower/Capitalized...) of
539 words inserted into the buffer by completion. The preferred case can
540 be specified separately for routine names, keywords, classes and
542 This alist should therefore have entries for `routine' (normal
543 functions and procedures, i.e. non-methods), `keyword', `class', and
544 `method'. Plausible values are
546 upcase upcase whole word, like `BOX_CURSOR'
547 downcase downcase whole word, like `read_ppm'
548 capitalize capitalize each part, like `Widget_Control'
549 preserve preserve case as is, like `IDLgrView'
551 The value can also be any Emacs Lisp function which transforms the
552 case of characters in a string.
554 A value of `preserve' means that the case of the completed word is
555 identical to the way it was written in the definition statement of the
556 routine. This was implemented to allow for mixed-case completion, in
557 particular of object classes and methods.
558 If a completable word is defined in multiple locations, the meaning of
559 `preserve' is not unique since the different definitions might be
560 cased differently. Therefore IDLWAVE always takes the case of the
561 *first* definition it encounters during routine info collection and
562 uses the case derived from it consistently.
564 Note that a lowercase-only string in the buffer will always be completed in
565 lower case (but see the variable `idlwave-completion-force-default-case').
567 After changing this variable, you need to either restart Emacs or press
568 `C-u C-c C-i' to update the internal lists."
569 :group
'idlwave-completion
571 (cons (symbol :tag
"Derive completion case for")
574 (defcustom idlwave-completion-force-default-case nil
575 "*Non-nil means, completion will always honor `idlwave-completion-case'.
576 When nil, only the completion of a mixed case or upper case string
577 will honor the default settings in `idlwave-completion-case', while
578 the completion of lower case strings will be completed entirely in
580 :group
'idlwave-completion
583 (defcustom idlwave-complete-empty-string-as-lower-case nil
584 "*Non-nil means, the empty string is considered downcase for completion.
585 The case of what is already in the buffer determines the case of completions.
586 When this variable is non-nil, the empty string is considered to be downcase.
587 Completing on the empty string then offers downcase versions of the possible
589 :group
'idlwave-completion
592 (defvar idlwave-default-completion-case-is-down nil
593 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
594 `idlwave-completion-case'.")
596 (defcustom idlwave-buffer-case-takes-precedence nil
597 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
598 To make this possible, we need to re-case everything each time we update
599 the routine info from the buffers. This is slow.
600 The default is to consider the case given in the system and library files
601 first which makes updating much faster."
602 :group
'idlwave-completion
605 (defcustom idlwave-highlight-help-links-in-completion t
606 "*Non-nil means, highlight completions for which system help is available.
607 Help can then be accessed with mouse-3.
608 This option is only effective when the online help system is installed."
609 :group
'idlwave-completion
612 (defcustom idlwave-support-inheritance t
613 "Non-nil means, treat inheritance with completion, online help etc.
614 When nil, IDLWAVE only knows about the native methods and tags of a class,
615 not about inherited ones."
616 :group
'idlwave-routine-info
619 (defcustom idlwave-keyword-class-inheritance
'("^[gs]etproperty$" "^init$")
620 "List of regular expressions for class-driven keyword inheritance.
621 Keyword inheritance is often tied to class inheritance by \"chaining\"
622 up the class tree. While it cannot be assumed that the presence of an
623 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
624 certain methods this assumption is almost always true. The methods
625 for which to assume this can be set here."
626 :group
'idlwave-routine-info
627 :type
'(repeat (regexp :tag
"Match method:")))
630 (defcustom idlwave-completion-show-classes
1
631 "*Number of classes to show when completing object methods and keywords.
632 When completing methods or keywords for an object with unknown class,
633 the *Completions* buffer will show the legal classes for each completion
636 MyMethod <Class1,Class2,Class3>
638 The value of this variable may be nil to inhibit display, or an integer to
639 indicate the maximum number of classes to display.
641 On XEmacs, a full list of classes will also be placed into a `help-echo'
642 property on the competion items, so that the list of classes for the current
643 item is displayed in the echo area. If the value of this variable is a
644 negative integer, the `help-echo' property will be suppressed."
645 :group
'idlwave-completion
646 :type
'(choice (const :tag
"Don't show" nil
)
647 (integer :tag
"Number of classes shown" 1)))
649 (defcustom idlwave-completion-fontify-classes t
650 "*Non-nil means, fontify the classes in completions buffer.
651 This makes it easier to distinguish the completion items from the extra
652 class info listed. See `idlwave-completion-show-classes'."
653 :group
'idlwave-completion
656 (defcustom idlwave-query-class
'((method-default . nil
)
657 (keyword-default . nil
))
658 "Association list governing specification of object classes for completion.
660 When IDLWAVE tries to complete object-oriented methods, it usually
661 cannot determine the class of a given object from context. In order
662 to provide the user with a correct list of methods or keywords, it
663 needs to determine the appropriate class. IDLWAVE has two ways of
664 doing this (well, three ways if you count the shell... see
665 `idlwave-shell-query-for-class'):
667 1. Combine the items of all available classes which contain this
668 method for the purpose of completion. So when completing a method,
669 all methods of all known classes are available, and when completing
670 a keyword, all keywords allowed for this method in any class are
671 shown. This behavior is very much like normal completion and is
672 therefore the default. It works much better than one might think -
673 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
674 become uncomfortably long. See also
675 `idlwave-completion-show-classes'.
677 2. The second possibility is to ask the user on each occasion. To
678 make this less interruptive, IDLWAVE can store the class as a text
679 property on the object operator `->'. For a given object in the
680 source code, class selection will then be needed only once
681 - for example to complete the method. Keywords to the method can
682 then be completed directly, because the class is already known.
683 You will have to turn on the storage of the selected class
684 explicitly with the variable `idlwave-store-inquired-class'.
686 This variable allows you to configure IDLWAVE's method and
687 method-keyword completion behavior. Its value is an alist, which
688 should contain at least two elements: (method-default . VALUE) and
689 \(keyword-default . VALUE), where VALUE is either t or nil. These
690 specify if the class should be found during method and keyword
691 completion, respectively.
693 The alist may have additional entries specifying exceptions from the
694 keyword completion rule for specific methods, like INIT or
695 GETPROPERTY. In order to turn on class specification for the INIT
696 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
697 :group
'idlwave-completion
699 (cons (const method-default
)
700 (boolean :tag
"Determine class when completing METHODS "))
701 (cons (const keyword-default
)
702 (boolean :tag
"Determine class when completing KEYWORDS "))
704 :tag
"Exceptions to defaults"
706 (cons (string :tag
"MODULE" :value
"")
707 (boolean :tag
"Determine class for this method")))))
709 (defcustom idlwave-store-inquired-class nil
710 "*Non-nil means, store class of a method call as text property on `->'.
711 IDLWAVE sometimes has to ask the user for the class associated with a
712 particular object method call. This happens during the commands
713 `idlwave-routine-info' and `idlwave-complete', depending upon the
714 value of the variable `idlwave-query-class'.
716 When you specify a class, this information can be stored as a text
717 property on the `->' arrow in the source code, so that during the same
718 editing session, IDLWAVE will not have to ask again. When this
719 variable is non-nil, IDLWAVE will store and reuse the class information.
720 The class stored can be checked and removed with `\\[idlwave-routine-info]'
723 The default of this variable is nil, since the result of commands then
724 is more predictable. However, if you know what you are doing, it can
725 be nice to turn this on.
727 An arrow which knows the class will be highlighted with
728 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
729 displays (with prefix arg: deletes) the class stored on the arrow
731 :group
'idlwave-completion
734 (defcustom idlwave-class-arrow-face
'bold
735 "*Face to highlight object operator arrows `->' which carry a class property.
736 When IDLWAVE stores a class name as text property on an object arrow
737 \(see variable `idlwave-store-inquired-class', it highlights the arrow
738 with this font in order to remind the user that this arrow is special."
739 :group
'idlwave-completion
742 (defcustom idlwave-resize-routine-help-window t
743 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
744 :group
'idlwave-completion
747 (defcustom idlwave-keyword-completion-adds-equal t
748 "*Non-nil means, completion automatically adds `=' after completed keywords."
749 :group
'idlwave-completion
752 (defcustom idlwave-function-completion-adds-paren t
753 "*Non-nil means, completion automatically adds `(' after completed function.
754 nil means, don't add anything.
755 A value of `2' means, also add the closing parenthesis and position cursor
757 :group
'idlwave-completion
758 :type
'(choice (const :tag
"Nothing" nil
)
760 (const :tag
"()" 2)))
762 (defcustom idlwave-completion-restore-window-configuration t
763 "*Non-nil means, try to restore the window configuration after completion.
764 When completion is not unique, Emacs displays a list of completions.
765 This messes up your window configuration. With this variable set, IDLWAVE
766 restores the old configuration after successful completion."
767 :group
'idlwave-completion
770 ;;; Variables for abbrev and action behavior -----------------------------
772 (defgroup idlwave-abbrev-and-indent-action nil
773 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
774 The variables in this group govern this."
777 (defcustom idlwave-do-actions nil
778 "*Non-nil means performs actions when indenting.
779 The actions that can be performed are listed in `idlwave-indent-action-table'."
780 :group
'idlwave-abbrev-and-indent-action
783 (defcustom idlwave-abbrev-start-char
"\\"
784 "*A single character string used to start abbreviations in abbrev mode.
785 Possible characters to chose from: ~`\%
786 or even '?'. '.' is not a good choice because it can make structure
787 field names act like abbrevs in certain circumstances.
789 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
790 must set it directly using `setq' in the .emacs file before idlwave.el
792 :group
'idlwave-abbrev-and-indent-action
795 (defcustom idlwave-surround-by-blank nil
796 "*Non-nil means, enable `idlwave-surround'.
797 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
799 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
801 Also see the default key bindings for keys using `idlwave-surround'.
802 Keys are bound and made into actions calling `idlwave-surround' with
803 `idlwave-action-and-binding'.
804 See help for `idlwave-action-and-binding' for examples.
806 Also see help for `idlwave-surround'."
807 :group
'idlwave-abbrev-and-indent-action
810 (defcustom idlwave-pad-keyword t
811 "*Non-nil means pad '=' for keywords like assignments.
812 Whenever `idlwave-surround' is non-nil then this affects how '=' is padded
813 for keywords. If t, it is padded the same as for assignments.
814 If nil then spaces are removed. With any other value, spaces are left
816 :group
'idlwave-abbrev-and-indent-action
818 (const :tag
"Pad like assignments" t
)
819 (const :tag
"Remove space near `='" nil
)
820 (const :tag
"Keep space near `='" 'keep
)))
822 (defcustom idlwave-show-block t
823 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
824 :group
'idlwave-abbrev-and-indent-action
827 (defcustom idlwave-expand-generic-end nil
828 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
829 :group
'idlwave-abbrev-and-indent-action
832 (defcustom idlwave-reindent-end t
833 "*Non-nil means re-indent line after END was typed."
834 :group
'idlwave-abbrev-and-indent-action
837 (defcustom idlwave-abbrev-move t
838 "*Non-nil means the abbrev hook can move point.
839 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
840 definitions, use the command `list-abbrevs', for abbrevs that move
841 point. Moving point is useful, for example, to place point between
842 parentheses of expanded functions.
844 See `idlwave-check-abbrev'."
845 :group
'idlwave-abbrev-and-indent-action
848 (defcustom idlwave-abbrev-change-case nil
849 "*Non-nil means all abbrevs will be forced to either upper or lower case.
850 If the value t, all expanded abbrevs will be upper case.
851 If the value is 'down then abbrevs will be forced to lower case.
852 If nil, the case will not change.
853 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
854 upper case, regardless of this variable."
855 :group
'idlwave-abbrev-and-indent-action
858 (defcustom idlwave-reserved-word-upcase nil
859 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
860 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
861 Has effect only if in abbrev-mode."
862 :group
'idlwave-abbrev-and-indent-action
865 ;;; Action/Expand Tables.
867 ;; The average user may have difficulty modifying this directly. It
868 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
869 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
870 ;; examples of how to add an action.
872 ;; The action table is used by `idlwave-indent-line' whereas both the
873 ;; action and expand tables are used by `idlwave-indent-and-action'. In
874 ;; general, the expand table is only used when a line is explicitly
875 ;; indented. Whereas, in addition to being used when the expand table
876 ;; is used, the action table is used when a line is indirectly
877 ;; indented via line splitting, auto-filling or a new line creation.
881 ;; Capitalize system vars
882 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
884 ;; Capitalize procedure name
885 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
886 ;; '(capitalize-word 1) t)
888 ;; Capitalize common block name
889 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
890 ;; '(capitalize-word 1) t)
892 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
893 ;; '(capitalize-word -1) t)
895 (defvar idlwave-indent-action-table nil
896 "*Associated array containing action lists of search string (car),
897 and function as a cdr. This table is used by `idlwave-indent-line'.
898 See documentation for `idlwave-do-action' for a complete description of
901 Additions to the table are made with `idlwave-action-and-binding' when a
902 binding is not requested.
903 See help on `idlwave-action-and-binding' for examples.")
905 (defvar idlwave-indent-expand-table nil
906 "*Associated array containing action lists of search string (car),
907 and function as a cdr. The table is used by the
908 `idlwave-indent-and-action' function. See documentation for
909 `idlwave-do-action' for a complete description of the action lists.
911 Additions to the table are made with `idlwave-action-and-binding' when a
912 binding is requested.
913 See help on `idlwave-action-and-binding' for examples.")
915 ;;; Documentation header and history keyword ---------------------------------
917 (defgroup idlwave-documentation nil
918 "Options for documenting IDLWAVE files."
921 ;; FIXME: make defcustom?
922 (defvar idlwave-file-header
949 ; KEYWORD PARAMETERS:
981 ; MODIFICATION HISTORY:
985 "*A list (PATHNAME STRING) specifying the doc-header template to use for
986 summarizing a file. If PATHNAME is non-nil then this file will be included.
987 Otherwise STRING is used. If nil, the file summary will be omitted.
988 For example you might set PATHNAME to the path for the
989 lib_template.pro file included in the IDL distribution.")
991 (defcustom idlwave-header-to-beginning-of-file nil
992 "*Non-nil means, the documentation header will always be at start of file.
993 When nil, the header is positioned between the PRO/FUNCTION line of
994 the current routine and the code, allowing several routine headers in
996 :group
'idlwave-documentation
999 (defcustom idlwave-timestamp-hook
'idlwave-default-insert-timestamp
1000 "*The hook function used to update the timestamp of a function."
1001 :group
'idlwave-documentation
1004 (defcustom idlwave-doc-modifications-keyword
"HISTORY"
1005 "*The modifications keyword to use with the log documentation commands.
1006 A ':' is added to the keyword end.
1007 Inserted by doc-header and used to position logs by doc-modification.
1008 If nil it will not be inserted."
1009 :group
'idlwave-documentation
1012 (defcustom idlwave-doclib-start
"^;+\\+"
1013 "*Regexp matching the start of a document library header."
1014 :group
'idlwave-documentation
1017 (defcustom idlwave-doclib-end
"^;+-"
1018 "*Regexp matching the end of a document library header."
1019 :group
'idlwave-documentation
1022 ;;; External Programs -------------------------------------------------------
1024 (defgroup idlwave-external-programs nil
1025 "Path locations of external commands used by IDLWAVE."
1028 ;; WARNING: The following variable has recently been moved from
1029 ;; idlw-shell.el to this file. I hope this does not break
1032 (defcustom idlwave-shell-explicit-file-name
"idl"
1033 "*If non-nil, this is the command to run IDL.
1034 Should be an absolute file path or path relative to the current environment
1035 execution search path. If you want to specify command line switches
1036 for the idl program, use `idlwave-shell-command-line-options'.
1038 I know the name of this variable is badly chosen, but I cannot change
1039 it without compromizing backwards-compatibility."
1040 :group
'idlwave-external-programs
1043 (defcustom idlwave-shell-command-line-options nil
1044 "*A list of command line options for calling the IDL program.
1045 Since IDL is executed directly without going through a shell like /bin/sh,
1046 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1047 string for each argument. But you may also give a single string which
1048 contains the options whitespace-separated. Emacs will be kind enough to
1052 (repeat (string :value
"")))
1053 :group
'idlwave-external-programs
)
1055 (defcustom idlwave-help-application
"idlhelp"
1056 "*The external application providing reference help for programming."
1057 :group
'idlwave-external-programs
1060 ;;; Some Shell variables which must be defined here.-----------------------
1062 (defcustom idlwave-shell-debug-modifiers
'()
1063 "List of modifiers to be used for the debugging commands.
1064 Will be used to bind debugging commands in the shell buffer and in all
1065 source buffers. These are additional convenience bindings, the debugging
1066 commands are always available with the `C-c C-d' prefix.
1067 If you set this to '(control shift), this means setting a breakpoint will
1068 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1069 are `control', `meta', `super', `hyper', `alt', and `shift'."
1070 :group
'idlwave-shell-general-setup
1071 :type
'(set :tag
"Specify modifiers"
1079 (defcustom idlwave-shell-automatic-start nil
1080 "*If non-nil attempt invoke idlwave-shell if not already running.
1081 This is checked when an attempt to send a command to an
1082 IDL process is made."
1083 :group
'idlwave-shell-general-setup
1086 ;;; Miscellaneous variables -------------------------------------------------
1088 (defgroup idlwave-misc nil
1089 "Miscellaneous options for IDLWAVE mode."
1092 (defcustom idlwave-startup-message t
1093 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1094 :group
'idlwave-misc
1097 (defcustom idlwave-default-font-lock-items
1098 '(pros-and-functions batch-files idlwave-idl-keywords label goto
1099 common-blocks class-arrows
)
1100 "Items which should be fontified on the default fontification level 2.
1101 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1102 is everything and level 2 is specified by this list.
1103 This variable must be set before IDLWAVE gets loaded. It is
1104 a list of symbols, the following symbols are allowed.
1106 pros-and-functions Procedure and Function definitions
1107 batch-files Batch Files
1108 idlwave-idl-keywords IDL Keywords
1109 label Statement Labels
1110 goto Goto Statements
1111 common-blocks Common Blocks
1112 keyword-parameters Keyword Parameters in routine definitions and calls
1113 system-variables System Variables
1114 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1115 class-arrows Object Arrows with class property"
1116 :group
'idlwave-misc
1119 (const :tag
"Procedure and Function definitions" pros-and-functions
)
1120 (const :tag
"Batch Files" batch-files
)
1121 (const :tag
"IDL Keywords (reserved words)" idlwave-idl-keywords
)
1122 (const :tag
"Statement Labels" label
)
1123 (const :tag
"Goto Statements" goto
)
1124 (const :tag
"Tags in Structure Definition" structtag
)
1125 (const :tag
"Structure Name" structname
)
1126 (const :tag
"Common Blocks" common-blocks
)
1127 (const :tag
"Keyword Parameters" keyword-parameters
)
1128 (const :tag
"System Variables" system-variables
)
1129 (const :tag
"FIXME: Warning" fixme
)
1130 (const :tag
"Object Arrows with class property " class-arrows
)))
1132 (defcustom idlwave-mode-hook nil
1133 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1134 :group
'idlwave-misc
1137 (defcustom idlwave-load-hook nil
1138 "Normal hook. Executed when idlwave.el is loaded."
1139 :group
'idlwave-misc
1142 (defvar idlwave-experimental nil
1143 "Non-nil means turn on a few experimental features.
1144 This variable is only for the maintainer, to test difficult stuff,
1145 while still distributing stable releases.
1146 As a user, you should not set this to t.")
1149 ;;; End customization variables section
1152 ;;; Non customization variables
1154 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1155 ;;; Simon Marshall <simon@gnu.ai.mit.edu>
1156 ;;; and Carsten Dominik...
1158 ;; The following are the reserved words in IDL. Maybe we should
1159 ;; highlight some more stuff as well?
1160 ;; Procedure declarations. Fontify keyword plus procedure name.
1161 (defvar idlwave-idl-keywords
1162 ;; To update this regexp, update the list of keywords and
1163 ;; evaluate the form.
1169 ;; '("and" "or" "xor" "not"
1170 ;; "eq" "ge" "gt" "le" "lt" "ne"
1171 ;; "for" "do" "endfor"
1172 ;; "if" "then" "endif" "else" "endelse"
1173 ;; "case" "of" "endcase"
1174 ;; "switch" "break" "continue" "endswitch"
1176 ;; "repeat" "until" "endrep"
1177 ;; "while" "endwhile"
1180 ;; "compile_opt" "forward_function"
1181 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1183 "\\<\\(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\\)\\>")
1185 (let* (;; Procedure declarations. Fontify keyword plus procedure name.
1186 ;; Function declarations. Fontify keyword plus function name.
1188 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1189 (1 font-lock-keyword-face
)
1190 (2 font-lock-function-name-face nil t
)))
1194 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1195 (1 font-lock-keyword-face
) ; "common"
1196 (2 font-lock-reference-face nil t
) ; block name
1197 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1198 ;; Start with point after block name and comma
1199 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1201 (1 font-lock-variable-name-face
) ; variable names
1206 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face
)))
1210 '("\\<FIXME:" (0 font-lock-warning-face t
)))
1214 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face
)))
1216 ;; The goto statement and its label
1218 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1219 (1 font-lock-keyword-face
)
1220 (2 font-lock-reference-face
)))
1222 ;; Tags in structure definitions. Note that this definition actually
1223 ;; collides with labels, so we have to use the same face.
1225 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face
)))
1229 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1230 (2 font-lock-function-name-face
)))
1232 ;; Named parameters, like /xlog or ,xrange=[]
1233 ;; This is anchored to the comma preceeding the keyword.
1234 ;; Treats continuation lines, works only during whole buffer
1235 ;; fontification. Slow, use it only in fancy fontification.
1237 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1238 (5 font-lock-reference-face
)))
1240 ;; System variables start with a bang.
1242 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1243 (1 font-lock-variable-name-face
)))
1245 ;; Special and unusual operators (not used because too noisy)
1247 '("[<>#]" (0 font-lock-keyword-face
)))
1249 ;; All operators (not used because too noisy)
1251 '("[-*^#+<>/]" (0 font-lock-keyword-face
)))
1253 ;; Arrows with text property `idlwave-class'
1255 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face
))))
1257 (defconst idlwave-font-lock-keywords-1
1258 (list pros-and-functions batch-files
)
1259 "Subdued level highlighting for IDLWAVE mode.")
1261 (defconst idlwave-font-lock-keywords-2
1262 (mapcar 'symbol-value idlwave-default-font-lock-items
)
1263 "Medium level highlighting for IDLWAVE mode.")
1265 (defconst idlwave-font-lock-keywords-3
1266 (list pros-and-functions
1268 idlwave-idl-keywords
1276 "Gaudy level highlighting for IDLWAVE mode."))
1278 (defun idlwave-match-class-arrows (limit)
1279 ;; Match an object arrow with class property
1280 (and idlwave-store-inquired-class
1281 (re-search-forward "->" limit
'limit
)
1282 (get-text-property (match-beginning 0) 'idlwave-class
)))
1284 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1285 "Default expressions to highlight in IDLWAVE mode.")
1287 (defvar idlwave-font-lock-defaults
1288 '((idlwave-font-lock-keywords
1289 idlwave-font-lock-keywords-1
1290 idlwave-font-lock-keywords-2
1291 idlwave-font-lock-keywords-3
)
1293 ((?$ .
"w") (?_ .
"w") (?. .
"w"))
1296 (put 'idlwave-mode
'font-lock-defaults
1297 idlwave-font-lock-defaults
) ; XEmacs
1299 (defconst idlwave-comment-line-start-skip
"^[ \t]*;"
1300 "Regexp to match the start of a full-line comment.
1301 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1302 only by whitespace.")
1304 (defconst idlwave-begin-block-reg
1305 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1306 "Regular expression to find the beginning of a block. The case does
1307 not matter. The search skips matches in comments.")
1309 (defconst idlwave-begin-unit-reg
"\\<\\(pro\\|function\\)\\>\\|\\`"
1310 "Regular expression to find the beginning of a unit. The case does
1313 (defconst idlwave-end-unit-reg
"\\<\\(pro\\|function\\)\\>\\|\\'"
1314 "Regular expression to find the line that indicates the end of unit.
1315 This line is the end of buffer or the start of another unit. The case does
1316 not matter. The search skips matches in comments.")
1318 (defconst idlwave-continue-line-reg
"\\<\\$"
1319 "Regular expression to match a continued line.")
1321 (defconst idlwave-end-block-reg
1322 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1323 "Regular expression to find the end of a block. The case does
1324 not matter. The search skips matches found in comments.")
1326 (defconst idlwave-block-matches
1328 ("function" .
"end")
1329 ("case" .
"endcase")
1330 ("else" .
"endelse")
1333 ("repeat" .
"endrep")
1334 ("switch" .
"endswitch")
1335 ("while" .
"endwhile"))
1336 "Matches between statements and the corresponding END variant.
1337 The cars are the reserved words starting a block. If the block really
1338 begins with BEGIN, the cars are the reserved words before the begin
1339 which can be used to identify the block type.
1340 This is used to check for the correct END type, to close blocks and
1341 to expand generic end statements to their detailed form.")
1343 (defconst idlwave-block-match-regexp
1344 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1345 "Regular expression matching reserved words which can stand before
1346 blocks starting with a BEGIN statement. The matches must have associations
1347 `idlwave-block-matches'")
1349 (defconst idlwave-identifier
"[a-zA-Z][a-zA-Z0-9$_]*"
1350 "Regular expression matching an IDL identifier.")
1352 (defconst idlwave-sysvar
(concat "!" idlwave-identifier
)
1353 "Regular expression matching IDL system variables.")
1355 (defconst idlwave-variable
(concat idlwave-identifier
"\\|" idlwave-sysvar
)
1356 "Regular expression matching IDL variable names.")
1358 (defconst idlwave-label
(concat idlwave-identifier
":")
1359 "Regular expression matching IDL labels.")
1361 (defconst idlwave-statement-match
1363 ;; "endif else" is the only possible "end" that can be
1364 ;; followed by a statement on the same line.
1365 '(endelse .
("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1366 ;; all other "end"s can not be followed by a statement.
1367 (cons 'end
(list idlwave-end-block-reg nil
))
1368 '(if .
("if\\>" "then"))
1369 '(for .
("for\\>" "do"))
1370 '(begin .
("begin\\>" nil
))
1371 '(pdef .
("pro\\>\\|function\\>" nil
))
1372 '(while .
("while\\>" "do"))
1373 '(repeat .
("repeat\\>" "repeat"))
1374 '(goto .
("goto\\>" nil
))
1375 '(case .
("case\\>" nil
))
1376 '(switch .
("switch\\>" nil
))
1377 (cons 'call
(list (concat idlwave-identifier
"\\(\\s *$\\|\\s *,\\)") nil
))
1378 '(assign .
("[^=>\n]*=" nil
)))
1380 "Associated list of statement matching regular expressions.
1381 Each regular expression matches the start of an IDL statement. The
1382 first element of each association is a symbol giving the statement
1383 type. The associated value is a list. The first element of this list
1384 is a regular expression matching the start of an IDL statement for
1385 identifying the statement type. The second element of this list is a
1386 regular expression for finding a substatement for the type. The
1387 substatement starts after the end of the found match modulo
1388 whitespace. If it is nil then the statement has no substatement. The
1389 list order matters since matching an assignment statement exactly is
1390 not possible without parsing. Thus assignment statement become just
1391 the leftover unidentified statements containing an equal sign." )
1393 (defvar idlwave-fill-function
'auto-fill-function
1394 "IDL mode auto fill function.")
1396 (defvar idlwave-comment-indent-function
'comment-indent-function
1397 "IDL mode comment indent function.")
1399 ;; Note that this is documented in the v18 manuals as being a string
1400 ;; of length one rather than a single character.
1401 ;; The code in this file accepts either format for compatibility.
1402 (defvar idlwave-comment-indent-char ?\
1403 "Character to be inserted for IDL comment indentation.
1406 (defconst idlwave-continuation-char ?$
1407 "Character which is inserted as a last character on previous line by
1408 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1410 (defconst idlwave-mode-version
" 4.15")
1412 (defmacro idlwave-keyword-abbrev
(&rest args
)
1413 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1415 ,(append '(idlwave-check-abbrev) args
))))
1417 ;; If I take the time I can replace idlwave-keyword-abbrev with
1418 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1419 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1420 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1421 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1423 (defmacro idlwave-code-abbrev
(&rest args
)
1424 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1425 Specifically, if the abbrev is in a comment or string it is unexpanded.
1426 Otherwise ARGS forms a list that is evaluated."
1428 ,(prin1-to-string args
) ;; Puts the code in the doc string
1429 (if (idlwave-quoted)
1430 (progn (unexpand-abbrev) nil
)
1433 (defvar idlwave-mode-map
(make-sparse-keymap)
1434 "Keymap used in IDL mode.")
1436 (defvar idlwave-mode-syntax-table
(make-syntax-table)
1437 "Syntax table in use in `idlwave-mode' buffers.")
1439 (modify-syntax-entry ?
+ "." idlwave-mode-syntax-table
)
1440 (modify-syntax-entry ?-
"." idlwave-mode-syntax-table
)
1441 (modify-syntax-entry ?
* "." idlwave-mode-syntax-table
)
1442 (modify-syntax-entry ?
/ "." idlwave-mode-syntax-table
)
1443 (modify-syntax-entry ?^
"." idlwave-mode-syntax-table
)
1444 (modify-syntax-entry ?
# "." idlwave-mode-syntax-table
)
1445 (modify-syntax-entry ?
= "." idlwave-mode-syntax-table
)
1446 (modify-syntax-entry ?%
"." idlwave-mode-syntax-table
)
1447 (modify-syntax-entry ?
< "." idlwave-mode-syntax-table
)
1448 (modify-syntax-entry ?
> "." idlwave-mode-syntax-table
)
1449 (modify-syntax-entry ?
\' "\"" idlwave-mode-syntax-table
)
1450 (modify-syntax-entry ?
\" "\"" idlwave-mode-syntax-table
)
1451 (modify-syntax-entry ?
\\ "." idlwave-mode-syntax-table
)
1452 (modify-syntax-entry ?_
"_" idlwave-mode-syntax-table
)
1453 (modify-syntax-entry ?
{ "(}" idlwave-mode-syntax-table
)
1454 (modify-syntax-entry ?
} "){" idlwave-mode-syntax-table
)
1455 (modify-syntax-entry ?$
"_" idlwave-mode-syntax-table
)
1456 (modify-syntax-entry ?.
"." idlwave-mode-syntax-table
)
1457 (modify-syntax-entry ?\
; "<" idlwave-mode-syntax-table)
1458 (modify-syntax-entry ?
\n ">" idlwave-mode-syntax-table
)
1459 (modify-syntax-entry ?
\f ">" idlwave-mode-syntax-table
)
1461 (defvar idlwave-find-symbol-syntax-table
1462 (copy-syntax-table idlwave-mode-syntax-table
)
1463 "Syntax table that treats symbol characters as word characters.")
1465 (modify-syntax-entry ?$
"w" idlwave-find-symbol-syntax-table
)
1466 (modify-syntax-entry ?_
"w" idlwave-find-symbol-syntax-table
)
1467 (modify-syntax-entry ?
! "w" idlwave-find-symbol-syntax-table
)
1468 (modify-syntax-entry ?.
"w" idlwave-find-symbol-syntax-table
)
1470 (defmacro idlwave-with-special-syntax
(&rest body
)
1471 "Execute BODY with a different syntax table."
1472 `(let ((saved-syntax (syntax-table)))
1475 (set-syntax-table idlwave-find-symbol-syntax-table
)
1477 (set-syntax-table saved-syntax
))))
1479 ;(defmacro idlwave-with-special-syntax1 (&rest body)
1480 ; "Execute BODY with a different syntax table."
1481 ; `(let ((saved-syntax (syntax-table)))
1484 ; (set-syntax-table idlwave-find-symbol-syntax-table)
1486 ; (set-syntax-table saved-syntax))))
1488 (defun idlwave-action-and-binding (key cmd
&optional select
)
1489 "KEY and CMD are made into a key binding and an indent action.
1490 KEY is a string - same as for the `define-key' function. CMD is a
1491 function of no arguments or a list to be evaluated. CMD is bound to
1492 KEY in `idlwave-mode-map' by defining an anonymous function calling
1493 `self-insert-command' followed by CMD. If KEY contains more than one
1494 character a binding will only be set if SELECT is 'both.
1496 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1497 replacing any previous value for KEY. If a binding is not set then it
1498 will instead be placed in `idlwave-indent-action-table'.
1500 If the optional argument SELECT is nil then an action and binding are
1501 created. If SELECT is 'noaction, then a binding is always set and no
1502 action is created. If SELECT is 'both then an action and binding
1503 will both be created even if KEY contains more than one character.
1504 Otherwise, if SELECT is non-nil then only an action is created.
1507 No spaces before and 1 after a comma
1508 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1509 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1510 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1511 Capitalize system variables - action only
1512 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1513 (if (not (equal select
'noaction
))
1515 (let* ((table (if select
'idlwave-indent-action-table
1516 'idlwave-indent-expand-table
))
1517 (cell (assoc key
(eval table
))))
1519 ;; Replace action command
1522 (set table
(append (eval table
) (list (cons key cmd
)))))))
1523 ;; Make key binding for action
1524 (if (or (and (null select
) (= (length key
) 1))
1525 (equal select
'noaction
)
1526 (equal select
'both
))
1527 (define-key idlwave-mode-map key
1530 (self-insert-command 1))
1531 (list (if (listp cmd
)
1535 (fset 'idlwave-debug-map
(make-sparse-keymap))
1537 (define-key idlwave-mode-map
"\C-c " 'idlwave-hard-tab
)
1538 (define-key idlwave-mode-map
[(control tab
)] 'idlwave-hard-tab
)
1539 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1540 (define-key idlwave-mode-map
"'" 'idlwave-show-matching-quote
)
1541 (define-key idlwave-mode-map
"\"" 'idlwave-show-matching-quote
)
1542 (define-key idlwave-mode-map
"\C-g" 'idlwave-keyboard-quit
)
1543 (define-key idlwave-mode-map
"\C-c;" 'idlwave-toggle-comment-region
)
1544 (define-key idlwave-mode-map
"\C-\M-a" 'idlwave-beginning-of-subprogram
)
1545 (define-key idlwave-mode-map
"\C-\M-e" 'idlwave-end-of-subprogram
)
1546 (define-key idlwave-mode-map
"\C-c{" 'idlwave-beginning-of-block
)
1547 (define-key idlwave-mode-map
"\C-c}" 'idlwave-end-of-block
)
1548 (define-key idlwave-mode-map
"\C-c]" 'idlwave-close-block
)
1549 (define-key idlwave-mode-map
"\M-\C-h" 'idlwave-mark-subprogram
)
1550 (define-key idlwave-mode-map
"\M-\C-n" 'idlwave-forward-block
)
1551 (define-key idlwave-mode-map
"\M-\C-p" 'idlwave-backward-block
)
1552 (define-key idlwave-mode-map
"\M-\C-d" 'idlwave-down-block
)
1553 (define-key idlwave-mode-map
"\M-\C-u" 'idlwave-backward-up-block
)
1554 (define-key idlwave-mode-map
"\M-\r" 'idlwave-split-line
)
1555 (define-key idlwave-mode-map
"\M-\C-q" 'idlwave-indent-subprogram
)
1556 (define-key idlwave-mode-map
"\C-c\C-p" 'idlwave-previous-statement
)
1557 (define-key idlwave-mode-map
"\C-c\C-n" 'idlwave-next-statement
)
1558 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1559 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1560 (define-key idlwave-mode-map
[(shift tab
)] 'idlwave-indent-statement
)
1561 (define-key idlwave-mode-map
"\C-c\C-a" 'idlwave-auto-fill-mode
)
1562 (define-key idlwave-mode-map
"\M-q" 'idlwave-fill-paragraph
)
1563 (define-key idlwave-mode-map
"\M-s" 'idlwave-edit-in-idlde
)
1564 (define-key idlwave-mode-map
"\C-c\C-h" 'idlwave-doc-header
)
1565 (define-key idlwave-mode-map
"\C-c\C-m" 'idlwave-doc-modification
)
1566 (define-key idlwave-mode-map
"\C-c\C-c" 'idlwave-case
)
1567 (define-key idlwave-mode-map
"\C-c\C-d" 'idlwave-debug-map
)
1568 (define-key idlwave-mode-map
"\C-c\C-d\C-c" 'idlwave-shell-save-and-run
)
1569 (define-key idlwave-mode-map
"\C-c\C-d\C-b" 'idlwave-shell-break-here
)
1570 (when (and (boundp 'idlwave-shell-debug-modifiers
)
1571 (listp idlwave-shell-debug-modifiers
)
1572 (not (equal idlwave-shell-debug-modifiers
'())))
1573 ;; Bind the debug commands also with the special modifiers.
1574 (let ((shift (memq 'shift idlwave-shell-debug-modifiers
))
1575 (mods-noshift (delq 'shift
1576 (copy-sequence idlwave-shell-debug-modifiers
))))
1577 (define-key idlwave-mode-map
1578 (vector (append mods-noshift
(list (if shift ?C ?c
))))
1579 'idlwave-shell-save-and-run
)
1580 (define-key idlwave-mode-map
1581 (vector (append mods-noshift
(list (if shift ?B ?b
))))
1582 'idlwave-shell-break-here
)))
1583 (define-key idlwave-mode-map
"\C-c\C-f" 'idlwave-for
)
1584 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1585 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1586 (define-key idlwave-mode-map
"\C-c\C-r" 'idlwave-repeat
)
1587 (define-key idlwave-mode-map
"\C-c\C-w" 'idlwave-while
)
1588 (define-key idlwave-mode-map
"\C-c\C-k" 'idlwave-kill-autoloaded-buffers
)
1589 (define-key idlwave-mode-map
"\C-c\C-s" 'idlwave-shell
)
1590 (define-key idlwave-mode-map
"\C-c\C-l" 'idlwave-shell-recenter-shell-window
)
1591 (define-key idlwave-mode-map
"\C-c\C-b" 'idlwave-list-buffer-load-path-shadows
)
1592 (autoload 'idlwave-shell
"idlw-shell"
1593 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t
)
1594 (autoload 'idlwave-shell-send-command
"idlw-shell")
1595 (autoload 'idlwave-shell-recenter-shell-window
"idlw-shell"
1596 "Run `idlwave-shell' and switch back to current window" t
)
1597 (autoload 'idlwave-shell-save-and-run
"idlw-shell"
1598 "Save and run buffer under the shell." t
)
1599 (autoload 'idlwave-shell-break-here
"idlw-shell"
1600 "Set breakpoint in current line." t
)
1601 (define-key idlwave-mode-map
"\C-c\C-v" 'idlwave-find-module
)
1602 (define-key idlwave-mode-map
"\C-c?" 'idlwave-routine-info
)
1603 (define-key idlwave-mode-map
"\M-?" 'idlwave-context-help
)
1604 (define-key idlwave-mode-map
[(control meta ?
\?)] 'idlwave-online-help
)
1605 (define-key idlwave-mode-map
[(meta tab
)] 'idlwave-complete
)
1606 (define-key idlwave-mode-map
"\C-c\C-i" 'idlwave-update-routine-info
)
1607 (define-key idlwave-mode-map
"\C-c=" 'idlwave-resolve
)
1608 (define-key idlwave-mode-map
1609 (if (featurep 'xemacs
) [(shift button3
)] [(shift mouse-3
)])
1610 'idlwave-mouse-context-help
)
1612 ;; Set action and key bindings.
1613 ;; See description of the function `idlwave-action-and-binding'.
1614 ;; Automatically add spaces for the following characters
1615 (idlwave-action-and-binding "&" '(idlwave-surround -
1 -
1))
1616 (idlwave-action-and-binding "<" '(idlwave-surround -
1 -
1))
1617 ;; Binding works for both > and ->, by changing the length of the token.
1618 (idlwave-action-and-binding ">" '(idlwave-surround -
1 -
1 '(?-
) 1
1619 'idlwave-gtr-pad-hook
))
1620 (idlwave-action-and-binding "->" '(idlwave-surround -
1 -
1 nil
2) t
)
1621 (idlwave-action-and-binding "," '(idlwave-surround 0 -
1))
1622 ;; Automatically add spaces to equal sign if not keyword
1623 (idlwave-action-and-binding "=" '(idlwave-expand-equal -
1 -
1))
1628 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1629 ;;; space is inserted (this is the space typed by the user to expanded
1632 (defvar idlwave-mode-abbrev-table nil
1633 "Abbreviation table used for IDLWAVE mode")
1634 (define-abbrev-table 'idlwave-mode-abbrev-table
())
1636 (defun idlwave-define-abbrev (name expansion hook
&optional noprefix table
)
1637 "Define-abbrev with backward compatibility.
1639 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1640 idlwave-mode-abbrev-table unless TABLE is non-nil."
1641 (let ((abbrevs-changed nil
) ;; mask the current value to avoid save
1642 (args (list (or table idlwave-mode-abbrev-table
)
1643 (if noprefix name
(concat idlwave-abbrev-start-char name
))
1647 (apply 'define-abbrev
(append args
'(0 t
)))
1648 (error (apply 'define-abbrev args
)))))
1651 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char
)
1652 "w" idlwave-mode-syntax-table
)
1658 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case
))
1659 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch
))
1660 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for
))
1661 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function
))
1662 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure
))
1663 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat
))
1664 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while
))
1665 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if
))
1666 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif
))
1668 ;; Keywords, system functions, conversion routines
1670 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1671 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t
))
1672 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t
))
1673 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1674 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1675 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1676 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1677 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1678 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1679 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1680 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t
))
1681 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin
)
1682 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin
)
1683 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin
)
1684 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin
)
1685 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin
)
1686 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin
)
1687 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin
)
1688 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin
)
1689 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin
)
1690 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t
))
1691 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1692 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1693 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1694 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1695 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1696 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1697 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1698 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1699 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1700 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1701 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1702 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1703 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1704 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1705 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1707 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1708 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t
))
1714 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t
))
1715 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1716 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1717 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1718 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1719 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1720 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1721 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1722 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1723 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1725 ;; This section is reserved words only. (From IDL user manual)
1727 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t
) t
)
1728 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t
) t
)
1729 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t
) t
)
1730 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t
) t
)
1731 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t
) t
)
1732 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t
) t
)
1733 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t
) t
)
1734 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t
) t
)
1735 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t
)
1736 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t
)
1737 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t
)
1738 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t
)
1739 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t
)
1740 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t
)
1741 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t
)
1742 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t
)
1743 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t
)
1744 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t
) t
)
1745 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t
) t
)
1746 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t
) t
)
1747 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t
) t
)
1748 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t
) t
)
1749 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t
) t
)
1750 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t
) t
)
1751 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t
) t
)
1752 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t
) t
)
1753 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t
) t
)
1754 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t
) t
)
1755 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t
) t
)
1756 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t
) t
)
1757 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t
) t
)
1758 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t
) t
)
1759 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t
) t
)
1760 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t
) t
)
1761 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t
) t
)
1762 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t
) t
)
1763 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t
) t
)
1764 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t
) t
)
1765 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t
) t
)
1767 (defvar imenu-create-index-function
)
1768 (defvar extract-index-name-function
)
1769 (defvar prev-index-position-function
)
1770 (defvar imenu-extract-index-name-function
)
1771 (defvar imenu-prev-index-position-function
)
1772 ;; defined later - so just make the compiler hush
1773 (defvar idlwave-mode-menu
)
1774 (defvar idlwave-mode-debug-menu
)
1777 (defun idlwave-mode ()
1778 "Major mode for editing IDL and WAVE CL .pro files.
1780 The main features of this mode are
1782 1. Indentation and Formatting
1783 --------------------------
1784 Like other Emacs programming modes, C-j inserts a newline and indents.
1785 TAB is used for explicit indentation of the current line.
1787 To start a continuation line, use \\[idlwave-split-line]. This
1788 function can also be used in the middle of a line to split the line
1789 at that point. When used inside a long constant string, the string
1790 is split at that point with the `+' concatenation operator.
1792 Comments are indented as follows:
1794 `;;;' Indentation remains unchanged.
1795 `;;' Indent like the surrounding code
1796 `;' Indent to a minimum column.
1798 The indentation of comments starting in column 0 is never changed.
1800 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1801 comment. The indentation of the second line of the paragraph
1802 relative to the first will be retained. Use
1803 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1804 comments. When the variable `idlwave-fill-comment-line-only' is
1805 nil, code can also be auto-filled and auto-indented (not
1808 To convert pre-existing IDL code to your formatting style, mark the
1809 entire buffer with \\[mark-whole-buffer] and execute
1810 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1811 again followed by \\[indent-region] (`indent-region').
1815 IDLWAVE displays information about the calling sequence and the
1816 accepted keyword parameters of a procedure or function with
1817 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1818 source file of a module. These commands know about system
1819 routines, all routines in idlwave-mode buffers and (when the
1820 idlwave-shell is active) about all modules currently compiled under
1821 this shell. Use \\[idlwave-update-routine-info] to update this
1822 information, which is also used for completion (see item 4).
1826 \\[idlwave-context-help] displays the IDL documentation relevant
1827 for the system variable, keyword, or routine at point. A single key
1828 stroke gets you directly to the right place in the docs. Two additional
1829 files (an ASCII version of the IDL documentation and a topics file) must
1830 be installed for this - check the IDLWAVE webpage for these files.
1834 \\[idlwave-complete] completes the names of procedures, functions
1835 class names and keyword parameters. It is context sensitive and
1836 figures out what is expected at point (procedure/function/keyword).
1837 Lower case strings are completed in lower case, other strings in
1838 mixed or upper case.
1840 5. Code Templates and Abbreviations
1841 --------------------------------
1842 Many Abbreviations are predefined to expand to code fragments and templates.
1843 The abbreviations start generally with a `\\`. Some examples
1845 \\pr PROCEDURE template
1846 \\fu FUNCTION template
1847 \\c CASE statement template
1848 \\sw SWITCH statement template
1849 \\f FOR loop template
1850 \\r REPEAT Loop template
1851 \\w WHILE loop template
1852 \\i IF statement template
1853 \\elif IF-ELSE statement template
1856 For a full list, use \\[idlwave-list-abbrevs]. Some templates also have
1857 direct keybindings - see the list of keybindings below.
1859 \\[idlwave-doc-header] inserts a documentation header at the beginning of the
1860 current program unit (pro, function or main). Change log entries
1861 can be added to the current program unit with \\[idlwave-doc-modification].
1863 6. Automatic Case Conversion
1864 -------------------------
1865 The case of reserved words and some abbrevs is controlled by
1866 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1868 7. Automatic END completion
1869 ------------------------
1870 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1871 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1875 Loading idlwave.el runs `idlwave-load-hook'.
1876 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1878 9. Documentation and Customization
1879 -------------------------------
1880 Info documentation for this package is available. Use
1881 \\[idlwave-info] to display (complain to your sysadmin if that does
1882 not work). For Postscript, PDF, and HTML versions of the
1883 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1884 IDLWAVE has customize support - see the group `idlwave'.
1888 Here is a list of all keybindings of this mode.
1889 If some of the key bindings below show with ??, use \\[describe-key]
1890 followed by the key sequence to see what the key sequence does.
1892 \\{idlwave-mode-map}"
1895 (kill-all-local-variables)
1897 (if idlwave-startup-message
1898 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version
))
1899 (setq idlwave-startup-message nil
)
1901 (setq local-abbrev-table idlwave-mode-abbrev-table
)
1902 (set-syntax-table idlwave-mode-syntax-table
)
1904 (set (make-local-variable 'indent-line-function
) 'idlwave-indent-and-action
)
1906 (make-local-variable idlwave-comment-indent-function
)
1907 (set idlwave-comment-indent-function
'idlwave-comment-hook
)
1909 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
1910 (set (make-local-variable 'comment-start
) ";")
1911 (set (make-local-variable 'require-final-newline
) t
)
1912 (set (make-local-variable 'abbrev-all-caps
) t
)
1913 (set (make-local-variable 'indent-tabs-mode
) nil
)
1914 (set (make-local-variable 'completion-ignore-case
) t
)
1916 (use-local-map idlwave-mode-map
)
1918 (when (featurep 'easymenu
)
1919 (easy-menu-add idlwave-mode-menu idlwave-mode-map
)
1920 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map
))
1922 (setq mode-name
"IDLWAVE")
1923 (setq major-mode
'idlwave-mode
)
1924 (setq abbrev-mode t
)
1926 (set (make-local-variable idlwave-fill-function
) 'idlwave-auto-fill
)
1927 (setq comment-end
"")
1928 (set (make-local-variable 'comment-multi-line
) nil
)
1929 (set (make-local-variable 'paragraph-separate
)
1930 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1931 (set (make-local-variable 'paragraph-start
) "[ \t\f]\\|[ \t]*;+[ \t]")
1932 (set (make-local-variable 'paragraph-ignore-fill-prefix
) nil
)
1933 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
1935 ;; Set tag table list to use IDLTAGS as file name.
1936 (if (boundp 'tag-table-alist
)
1937 (add-to-list 'tag-table-alist
'("\\.pro$" .
"IDLTAGS")))
1939 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1940 ;; Following line is for Emacs - XEmacs uses the corresponding porperty
1941 ;; on the `idlwave-mode' symbol.
1942 (set (make-local-variable 'font-lock-defaults
) idlwave-font-lock-defaults
)
1945 (set (make-local-variable 'imenu-create-index-function
)
1946 'imenu-default-create-index-function
)
1947 (set (make-local-variable 'imenu-extract-index-name-function
)
1949 (set (make-local-variable 'imenu-prev-index-position-function
)
1950 'idlwave-prev-index-position
)
1952 ;; Make a local post-command-hook and add our hook to it
1953 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1954 (make-local-hook 'post-command-hook
)
1955 (add-hook 'post-command-hook
'idlwave-command-hook nil
'local
)
1957 ;; Make local hooks for buffer updates
1958 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1959 (make-local-hook 'kill-buffer-hook
)
1960 (add-hook 'kill-buffer-hook
'idlwave-kill-buffer-update nil
'local
)
1961 (make-local-hook 'after-save-hook
)
1962 (add-hook 'after-save-hook
'idlwave-save-buffer-update nil
'local
)
1963 (add-hook 'after-save-hook
'idlwave-revoke-license-to-kill nil
'local
)
1965 ;; Update the routine info with info about current buffer?
1966 (idlwave-new-buffer-update)
1968 ;; Run the mode hook
1969 (run-hooks 'idlwave-mode-hook
))
1972 ;; Done with start up and initialization code.
1973 ;; The remaining routines are the code formatting functions.
1976 (defun idlwave-push-mark (&rest rest
)
1977 "Push mark for compatibility with Emacs 18/19."
1978 (if (fboundp 'iconify-frame
)
1979 (apply 'push-mark rest
)
1982 (defun idlwave-hard-tab ()
1983 "Inserts TAB in buffer in current position."
1987 ;;; This stuff is experimental
1989 (defvar idlwave-command-hook nil
1990 "If non-nil, a list that can be evaluated using `eval'.
1991 It is evaluated in the lisp function `idlwave-command-hook' which is
1992 placed in `post-command-hook'.")
1994 (defun idlwave-command-hook ()
1995 "Command run after every command.
1996 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
1997 sets the variable to zero afterwards."
1998 (and idlwave-command-hook
1999 (listp idlwave-command-hook
)
2001 (eval idlwave-command-hook
)
2003 (setq idlwave-command-hook nil
))
2007 ;; It would be better to use expand.el for better abbrev handling and
2010 (defun idlwave-check-abbrev (arg &optional reserved
)
2011 "Reverses abbrev expansion if in comment or string.
2012 Argument ARG is the number of characters to move point
2013 backward if `idlwave-abbrev-move' is non-nil.
2014 If optional argument RESERVED is non-nil then the expansion
2015 consists of reserved words, which will be capitalized if
2016 `idlwave-reserved-word-upcase' is non-nil.
2017 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2018 is non-nil, unless its value is \`down in which case the abbrev will be
2019 made into all lowercase.
2020 Returns non-nil if abbrev is left expanded."
2021 (if (idlwave-quoted)
2022 (progn (unexpand-abbrev)
2024 (if (and reserved idlwave-reserved-word-upcase
)
2025 (upcase-region last-abbrev-location
(point))
2027 ((equal idlwave-abbrev-change-case
'down
)
2028 (downcase-region last-abbrev-location
(point)))
2029 (idlwave-abbrev-change-case
2030 (upcase-region last-abbrev-location
(point)))))
2031 (if (and idlwave-abbrev-move
(> arg
0))
2032 (if (boundp 'post-command-hook
)
2033 (setq idlwave-command-hook
(list 'backward-char
(1+ arg
)))
2034 (backward-char arg
)))
2037 (defun idlwave-in-comment ()
2038 "Returns t if point is inside a comment, nil otherwise."
2040 (let ((here (point)))
2041 (and (idlwave-goto-comment) (> here
(point))))))
2043 (defun idlwave-goto-comment ()
2044 "Move to start of comment delimiter on current line.
2045 Moves to end of line if there is no comment delimiter.
2046 Ignores comment delimiters in strings.
2047 Returns point if comment found and nil otherwise."
2048 (let ((eos (progn (end-of-line) (point)))
2051 ;; Look for first comment delimiter not in a string
2053 (setq found
(search-forward comment-start eos
'lim
))
2054 (while (and found
(idlwave-in-quote))
2055 (setq found
(search-forward comment-start eos
'lim
)))
2056 (store-match-data data
)
2057 (and found
(not (idlwave-in-quote))
2062 (defvar transient-mark-mode
)
2063 (defvar zmacs-regions
)
2064 (defvar mark-active
)
2065 (defun idlwave-region-active-p ()
2066 "Is transien-mark-mode on and the region active?
2067 Works on both Emacs and XEmacs."
2068 (if (featurep 'xemacs
)
2069 (and zmacs-regions
(region-active-p))
2070 (and transient-mark-mode mark-active
)))
2072 (defun idlwave-show-matching-quote ()
2073 "Insert quote and show matching quote if this is end of a string."
2075 (let ((bq (idlwave-in-quote))
2076 (inq last-command-char
))
2077 (if (and bq
(not (idlwave-in-comment)))
2078 (let ((delim (char-after bq
)))
2084 ;; Not the end of a string
2087 (defun idlwave-show-begin-check ()
2088 "Ensure that the previous word was a token before `idlwave-show-begin'.
2089 An END token must be preceded by whitespace."
2090 (if (not (idlwave-quoted))
2095 (looking-at "[ \t\n\f]"))
2096 (idlwave-show-begin))))
2098 (defun idlwave-show-begin ()
2099 "Finds the start of current block and blinks to it for a second.
2100 Also checks if the correct end statement has been used."
2101 ;; All end statements are reserved words
2102 ;; Re-indent end line
2103 (insert-char ?\
1) ;; So indent, etc. work well
2105 (let* ((pos (point-marker))
2106 (last-abbrev-marker (copy-marker last-abbrev-location
))
2107 (eol-pos (save-excursion (end-of-line) (point)))
2108 begin-pos end-pos end end1
)
2109 (if idlwave-reindent-end
(idlwave-indent-line))
2111 (when (and (idlwave-check-abbrev 0 t
)
2114 ;; Move inside current block
2115 (goto-char last-abbrev-marker
)
2116 (idlwave-block-jump-out -
1 'nomark
)
2117 (setq begin-pos
(point))
2118 (idlwave-block-jump-out 1 'nomark
)
2119 (setq end-pos
(point))
2120 (if (> end-pos eol-pos
)
2123 (setq end
(buffer-substring
2125 (skip-chars-backward "a-zA-Z")
2128 (goto-char begin-pos
)
2129 (when (setq end1
(cdr (idlwave-block-master)))
2131 ((null end1
)) ; no-operation
2132 ((string= (downcase end
) (downcase end1
))
2134 ((string= (downcase end
) "end")
2136 (if idlwave-expand-generic-end
2140 (insert (if (string= end
"END") (upcase end1
) end1
))
2145 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2150 (defun idlwave-block-master ()
2151 (let ((case-fold-search t
))
2154 ((looking-at "pro\\|case\\|switch\\|function\\>")
2155 (assoc (downcase (match-string 0)) idlwave-block-matches
))
2156 ((looking-at "begin\\>")
2157 (let ((limit (save-excursion
2158 (idlwave-beginning-of-statement)
2161 ((re-search-backward idlwave-block-match-regexp limit t
)
2162 (assoc (downcase (match-string 1))
2163 idlwave-block-matches
))
2164 ;;((re-search-backward ":[ \t]*\\=" limit t)
2165 ;; ;; seems to be a case thing
2166 ;; '("begin" . "end"))
2168 ;; Just a nromal block
2169 '("begin" .
"end")))))
2172 (defun idlwave-close-block ()
2173 "Terminate the current block with the correct END statement."
2176 ;; Start new line if we are not in a new line
2177 (unless (save-excursion
2178 (skip-chars-backward " \t")
2180 (let ((idlwave-show-block nil
))
2181 (newline-and-indent)))
2182 (let ((last-abbrev-location (point))) ; for upcasing
2184 (idlwave-show-begin)))
2186 (defun idlwave-gtr-pad-hook (char)
2187 "Let the > symbol expand around -> if present. The new token length
2191 (defun idlwave-surround (&optional before after escape-chars length ec-hook
)
2192 "Surround the LENGTH characters before point with blanks.
2193 LENGTH defaults to 1.
2194 Optional arguments BEFORE and AFTER affect the behavior before and
2195 after the characters (see also description of `idlwave-make-space'):
2199 integer > 0 force exactly n spaces
2200 integer < 0 at least |n| spaces
2202 The function does nothing if any of the following conditions is true:
2203 - `idlwave-surround-by-blank' is nil
2204 - the character before point is inside a string or comment
2205 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2206 This hack is used to avoid padding of `>' when it is part of
2207 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2209 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2210 the named function will be called with a single argument of the
2211 preceeding character. Then idlwave-surround will run as usual if
2212 EC-HOOK returns non-nil, and a new length will be taken from the
2214 (when (and idlwave-surround-by-blank
(not (idlwave-quoted)))
2215 (let* ((length (or length
1)) ; establish a default for LENGTH
2216 (prev-char (char-after (- (point) (1+ length
)))))
2217 (when (or (not (memq prev-char escape-chars
))
2218 (and (fboundp ec-hook
)
2220 (save-excursion (funcall ec-hook prev-char
)))))
2221 (backward-char length
)
2223 (let ((here (point)))
2224 (skip-chars-backward " \t")
2226 ;; avoid clobbering indent
2228 (move-to-column (idlwave-calculate-indent))
2229 (if (<= (point) here
)
2230 (narrow-to-region (point) here
))
2232 (idlwave-make-space before
))
2233 (skip-chars-forward " \t"))
2234 (forward-char length
)
2235 (idlwave-make-space after
)
2236 ;; Check to see if the line should auto wrap
2237 (if (and (equal (char-after (1- (point))) ?\
)
2238 (> (current-column) fill-column
))
2239 (funcall auto-fill-function
))))))
2241 (defun idlwave-make-space (n)
2242 "Make space at point.
2243 The space affected is all the spaces and tabs around point.
2244 If n is non-nil then point is left abs(n) spaces from the beginning of
2245 the contiguous space.
2246 The amount of space at point is determined by N.
2247 If the value of N is:
2249 > 0 - exactly N spaces.
2250 < 0 - a minimum of -N spaces, i.e., do not change if there are
2252 0 - no spaces (i.e. remove any existing space)."
2255 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2257 (end-col (progn (skip-chars-forward " \t") (current-column))))
2258 (delete-horizontal-space)
2261 (idlwave-indent-to (+ start-col n
))
2262 (goto-char (+ left n
)))
2264 (idlwave-indent-to end-col
(- n
))
2265 (goto-char (- left n
)))
2269 (defun idlwave-newline ()
2270 "Inserts a newline and indents the current and previous line."
2273 ;; Handle unterminated single and double quotes
2274 ;; If not in a comment and in a string then insertion of a newline
2275 ;; will mean unbalanced quotes.
2277 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2279 (message "Warning: unbalanced quotes?")))
2282 ;; The current line is being split, the cursor should be at the
2283 ;; beginning of the new line skipping the leading indentation.
2285 ;; The reason we insert the new line before indenting is that the
2286 ;; indenting could be confused by keywords (e.g. END) on the line
2287 ;; after the split point. This prevents us from just using
2288 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2290 (beginning-of-line 0)
2291 (idlwave-indent-line)
2293 (idlwave-indent-line))
2296 ;; Use global variable 'comment-column' to set parallel comment
2298 ;; Modeled on lisp.el
2299 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2300 (defun idlwave-comment-hook ()
2301 "Compute indent for the beginning of the IDL comment delimiter."
2302 (if (or (looking-at idlwave-no-change-comment
)
2303 (if idlwave-begin-line-comment
2304 (looking-at idlwave-begin-line-comment
)
2307 (if (looking-at idlwave-code-comment
)
2308 (if (save-excursion (skip-chars-backward " \t") (bolp))
2309 ;; On line by itself, indent as code
2310 (let ((tem (idlwave-calculate-indent)))
2311 (if (listp tem
) (car tem
) tem
))
2312 ;; after code - do not change
2314 (skip-chars-backward " \t")
2315 (max (if (bolp) 0 (1+ (current-column)))
2318 (defun idlwave-split-line ()
2319 "Continue line by breaking line at point and indent the lines.
2320 For a code line insert continuation marker. If the line is a line comment
2321 then the new line will contain a comment with the same indentation.
2322 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2325 ;; Expand abbreviation, just like normal RET would.
2326 (and abbrev-mode
(expand-abbrev))
2328 (if (not (idlwave-in-comment))
2329 ;; For code line add continuation.
2330 ;; Check if splitting a string.
2332 (if (setq beg
(idlwave-in-quote))
2333 (if idlwave-split-line-string
2334 ;; Split the string.
2335 (progn (insert (setq beg
(char-after beg
)) " + "
2336 idlwave-continuation-char beg
)
2338 (newline-and-indent)
2340 ;; Do not split the string.
2342 (message "Warning: continuation inside string!!")
2343 (insert " " idlwave-continuation-char
))
2344 ;; Not splitting a string.
2345 (if (not (member (char-before) '(?\ ?
\t)))
2347 (insert idlwave-continuation-char
)
2348 (newline-and-indent)))
2349 (indent-new-comment-line))
2350 ;; Indent previous line
2351 (setq beg
(- (point-max) (point)))
2353 (idlwave-indent-line)
2354 (goto-char (- (point-max) beg
))
2355 ;; Reindent new line
2356 (idlwave-indent-line)))
2358 (defun idlwave-beginning-of-subprogram ()
2359 "Moves point to the beginning of the current program unit."
2361 (idlwave-find-key idlwave-begin-unit-reg -
1))
2363 (defun idlwave-end-of-subprogram ()
2364 "Moves point to the start of the next program unit."
2366 (idlwave-end-of-statement)
2367 (idlwave-find-key idlwave-end-unit-reg
1))
2369 (defun idlwave-mark-statement ()
2370 "Mark current IDL statement."
2372 (idlwave-end-of-statement)
2373 (let ((end (point)))
2374 (idlwave-beginning-of-statement)
2375 (idlwave-push-mark end nil t
)))
2377 (defun idlwave-mark-block ()
2378 "Mark containing block."
2380 (idlwave-end-of-statement)
2381 (idlwave-backward-up-block -
1)
2382 (idlwave-end-of-statement)
2383 (let ((end (point)))
2384 (idlwave-backward-block)
2385 (idlwave-beginning-of-statement)
2386 (idlwave-push-mark end nil t
)))
2389 (defun idlwave-mark-subprogram ()
2390 "Put mark at beginning of program, point at end.
2391 The marks are pushed."
2393 (idlwave-end-of-statement)
2394 (idlwave-beginning-of-subprogram)
2395 (let ((beg (point)))
2396 (idlwave-forward-block)
2397 (idlwave-push-mark beg nil t
))
2398 (exchange-point-and-mark))
2400 (defun idlwave-backward-up-block (&optional arg
)
2401 "Move to beginning of enclosing block if prefix ARG >= 0.
2402 If prefix ARG < 0 then move forward to enclosing block end."
2404 (idlwave-block-jump-out (- arg
) 'nomark
))
2406 (defun idlwave-beginning-of-block ()
2407 "Go to the beginning of the current block."
2409 (idlwave-block-jump-out -
1 'nomark
)
2412 (defun idlwave-end-of-block ()
2413 "Go to the beginning of the current block."
2415 (idlwave-block-jump-out 1 'nomark
)
2418 (defun idlwave-forward-block ()
2419 "Move across next nested block."
2421 (if (idlwave-down-block 1)
2422 (idlwave-block-jump-out 1 'nomark
)))
2424 (defun idlwave-backward-block ()
2425 "Move backward across previous nested block."
2427 (if (idlwave-down-block -
1)
2428 (idlwave-block-jump-out -
1 'nomark
)))
2430 (defun idlwave-down-block (&optional arg
)
2432 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2433 Returns non-nil if successfull."
2438 (let ((eos (save-excursion
2439 (idlwave-block-jump-out -
1 'nomark
)
2441 (if (setq status
(idlwave-find-key
2442 idlwave-end-block-reg -
1 'nomark eos
))
2443 (idlwave-beginning-of-statement)
2444 (message "No nested block before beginning of containing block.")))
2446 (let ((eos (save-excursion
2447 (idlwave-block-jump-out 1 'nomark
)
2449 (if (setq status
(idlwave-find-key
2450 idlwave-begin-block-reg
1 'nomark eos
))
2451 (idlwave-end-of-statement)
2452 (message "No nested block before end of containing block."))))
2455 (defun idlwave-mark-doclib ()
2456 "Put point at beginning of doc library header, mark at end.
2457 The marks are pushed."
2461 (goto-char (point-max))
2462 (if (re-search-backward idlwave-doclib-start nil t
)
2464 (setq beg
(progn (beginning-of-line) (point)))
2465 (if (re-search-forward idlwave-doclib-end nil t
)
2468 (idlwave-push-mark beg nil t
)
2469 (message "Could not find end of doc library header.")))
2470 (message "Could not find doc library header start.")
2471 (goto-char here
)))))
2474 (defun idlwave-current-routine ()
2475 "Return (NAME TYPE CLASS) of current routine."
2478 (idlwave-beginning-of-subprogram)
2479 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2480 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2482 (class (idlwave-sintern-class (match-string 3)))
2483 (name (idlwave-sintern-routine-or-method (match-string 4) class
)))
2484 (list name type class
)))))
2486 (defvar idlwave-shell-prompt-pattern
)
2487 (defun idlwave-beginning-of-statement ()
2488 "Move to beginning of the current statement.
2489 Skips back past statement continuations.
2490 Point is placed at the beginning of the line whether or not this is an
2494 ((eq major-mode
'idlwave-shell-mode
)
2495 (if (re-search-backward idlwave-shell-prompt-pattern nil t
)
2496 (goto-char (match-end 0))))
2498 (if (save-excursion (forward-line -
1) (idlwave-is-continuation-line))
2499 (idlwave-previous-statement)
2500 (beginning-of-line)))))
2502 (defun idlwave-previous-statement ()
2503 "Moves point to beginning of the previous statement.
2504 Returns t if the current line before moving is the beginning of
2505 the first non-comment statement in the file, and nil otherwise."
2507 (let (first-statement)
2508 (if (not (= (forward-line -
1) 0))
2509 ;; first line in file
2511 ;; skip blank lines, label lines, include lines and line comments
2513 ;; The current statement is the first statement until we
2514 ;; reach another statement.
2515 (setq first-statement
2517 (looking-at idlwave-comment-line-start-skip
)
2518 (looking-at "[ \t]*$")
2519 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2521 (= (forward-line -
1) 0)))
2522 ;; skip continuation lines
2526 (idlwave-is-continuation-line))
2527 (= (forward-line -
1) 0)))
2530 (defun idlwave-end-of-statement ()
2531 "Moves point to the end of the current IDL statement.
2532 If not in a statement just moves to end of line. Returns position."
2534 (while (and (idlwave-is-continuation-line)
2535 (= (forward-line 1) 0))
2536 (while (and (idlwave-is-comment-or-empty-line)
2537 (= (forward-line 1) 0))))
2541 (defun idlwave-end-of-statement0 ()
2542 "Moves point to the end of the current IDL statement.
2543 If not in a statement just moves to end of line. Returns position."
2545 (while (and (idlwave-is-continuation-line)
2546 (= (forward-line 1) 0)))
2550 (defun idlwave-next-statement ()
2551 "Moves point to beginning of the next IDL statement.
2552 Returns t if that statement is the last
2553 non-comment IDL statement in the file, and nil otherwise."
2555 (let (last-statement)
2556 (idlwave-end-of-statement)
2557 ;; skip blank lines, label lines, include lines and line comments
2558 (while (and (= (forward-line 1) 0)
2559 ;; The current statement is the last statement until
2560 ;; we reach a new statement.
2561 (setq last-statement
2563 (looking-at idlwave-comment-line-start-skip
)
2564 (looking-at "[ \t]*$")
2565 (looking-at (concat "[ \t]*" idlwave-label
"[ \t]*$"))
2566 (looking-at "^@")))))
2569 (defun idlwave-skip-multi-commands (&optional lim
)
2570 "Skip past multiple commands on a line (with `&')."
2571 (let ((save-point (point)))
2572 (when (re-search-forward ".*&" lim t
)
2573 (goto-char (match-end 0))
2574 (if (idlwave-in-quote) (goto-char save-point
)))
2577 (defun idlwave-skip-label-or-case ()
2578 "Skip label or case statement element.
2579 Returns position after label.
2580 If there is no label point is not moved and nil is returned."
2581 ;; Case expressions and labels are terminated by a colon.
2582 ;; So we find the first colon in the line and make sure
2583 ;; - no `?' is before it (might be a ? b : c)
2584 ;; - it is not in a comment
2585 ;; - not in a string constant
2586 ;; - not in parenthesis (like a[0:3])
2587 ;; - not followed by another ":" in explicit class, ala a->b::c
2588 ;; As many in this mode, this function is heuristic and not an exact
2590 (let* ((start (point))
2591 (eos (save-excursion (idlwave-end-of-statement) (point)))
2592 (end (idlwave-find-key ":" 1 'nomark eos
)))
2594 (= (nth 0 (parse-partial-sexp start end
)) 0)
2595 (not (string-match "\\?" (buffer-substring start end
)))
2596 (not (string-match "^::" (buffer-substring end eos
))))
2603 (defun idlwave-start-of-substatement (&optional pre
)
2604 "Move to start of next IDL substatement after point.
2605 Uses the type of the current IDL statement to determine if the next
2606 statement is on a new line or is a subpart of the current statement.
2607 Returns point at start of substatement modulo whitespace.
2608 If optional argument is non-nil move to beginning of current
2610 (let ((orig (point))
2611 (eos (idlwave-end-of-statement))
2614 (idlwave-beginning-of-statement)
2615 (idlwave-skip-label-or-case)
2616 (idlwave-skip-multi-commands orig
)
2618 ;; Continue looking for substatements until we are past orig
2619 (while (and (<= (point) orig
) (not (eobp)))
2621 (setq nst
(nth 1 (cdr (setq st
(car (idlwave-statement-type))))))
2622 (if (equal (car st
) 'if
) (setq ifnest
(1+ ifnest
)))
2624 (idlwave-find-key nst
1 'nomark eos
))
2625 (goto-char (match-end 0)))
2626 ((and (> ifnest
0) (idlwave-find-key "\\<else\\>" 1 'nomark eos
))
2627 (setq ifnest
(1- ifnest
))
2628 (goto-char (match-end 0)))
2630 (idlwave-next-statement))))
2631 (if pre
(goto-char last
))
2632 ;; If a continuation line starts here, move to next line
2633 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2634 (beginning-of-line 2))
2637 (defun idlwave-statement-type ()
2638 "Return the type of the current IDL statement.
2639 Uses `idlwave-statement-match' to return a cons of (type . point) with
2640 point the ending position where the type was determined. Type is the
2641 association from `idlwave-statement-match', i.e. the cons cell from the
2642 list not just the type symbol. Returns nil if not an identifiable
2645 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2646 ;; and possibly comments
2647 (while (looking-at "[ \t]*\\$")
2649 (skip-chars-forward " \t")
2650 (let ((st idlwave-statement-match
)
2651 (case-fold-search t
))
2652 (while (and (not (looking-at (nth 0 (cdr (car st
)))))
2653 (setq st
(cdr st
))))
2655 (append st
(match-end 0))))))
2657 (defun idlwave-expand-equal (&optional before after
)
2658 "Pad '=' with spaces.
2659 Two cases: Assignment statement, and keyword assignment.
2660 The case is determined using `idlwave-start-of-substatement' and
2661 `idlwave-statement-type'.
2662 The equal sign will be surrounded by BEFORE and AFTER blanks.
2663 If `idlwave-pad-keyword' is t then keyword assignment is treated just
2664 like assignment statements. When nil, spaces are removed for keyword
2665 assignment. Any other value keeps the current space around the `='.
2666 Limits in for loops are treated as keyword assignment.
2667 See `idlwave-surround'. "
2668 ;; Even though idlwave-surround checks `idlwave-surround-by-blank' this
2669 ;; check saves the time of finding the statement type.
2670 (if idlwave-surround-by-blank
2671 (let ((st (save-excursion
2672 (idlwave-start-of-substatement t
)
2673 (idlwave-statement-type))))
2675 (cond ((or (and (equal (car (car st
)) 'assign
)
2676 (equal (cdr st
) (point)))
2677 (eq t idlwave-pad-keyword
))
2678 ;; An assignment statement or keywor and we need padding
2679 (idlwave-surround before after
))
2680 ((null idlwave-pad-keyword
)
2681 ;; Spaces should be removed at a keyword
2682 (idlwave-surround 0 0))
2685 (defun idlwave-indent-and-action (&optional arg
)
2686 "Call `idlwave-indent-line' and do expand actions.
2687 With prefix ARG non-nil, indent the entire sub-statement."
2690 (if (and idlwave-expand-generic-end
2691 (re-search-backward "\\<\\(end\\)\\s-*\\="
2692 (max 0 (- (point) 10)) t
)
2693 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2694 (progn (goto-char (match-end 1))
2695 ;;Expand the END abbreviation, just as RET or Space would have.
2696 (if abbrev-mode
(expand-abbrev)
2697 (idlwave-show-begin)))))
2699 (idlwave-indent-statement)
2700 (idlwave-indent-line t
)))
2702 (defun idlwave-indent-line (&optional expand
)
2703 "Indents current IDL line as code or as a comment.
2704 The actions in `idlwave-indent-action-table' are performed.
2705 If the optional argument EXPAND is non-nil then the actions in
2706 `idlwave-indent-expand-table' are performed."
2708 ;; Move point out of left margin.
2710 (skip-chars-backward " \t")
2712 (skip-chars-forward " \t"))
2713 (let ((mloc (point-marker)))
2716 (if (looking-at idlwave-comment-line-start-skip
)
2717 ;; Indentation for a line comment
2719 (skip-chars-forward " \t")
2720 (idlwave-indent-left-margin (idlwave-comment-hook)))
2724 ;; Before indenting, run action routines.
2726 (if (and expand idlwave-do-actions
)
2727 (mapcar 'idlwave-do-action idlwave-indent-expand-table
))
2729 (if idlwave-do-actions
2730 (mapcar 'idlwave-do-action idlwave-indent-action-table
))
2732 ;; No longer expand abbrevs on the line. The user can do this
2733 ;; manually using expand-region-abbrevs.
2735 ;; Indent for code line
2740 (looking-at (concat "^" idlwave-label
"[ \t]*$"))
2742 (looking-at "^[ \t]*@"))
2746 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2747 ;; Adjust parallel comment
2749 (if (idlwave-in-comment)
2750 ;; Emacs 21 is too smart with fill-column on comment indent
2751 (let ((fill-column (if (fboundp 'comment-indent-new-line
)
2754 (indent-for-comment)))))
2756 ;; Get rid of marker
2757 (set-marker mloc nil
)))
2759 (defun idlwave-do-action (action)
2760 "Perform an action repeatedly on a line.
2761 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2762 either a function name to be called with `funcall' or a list to be
2763 evaluated with `eval'. The action performed by FUNC should leave point
2764 after the match for REG - otherwise an infinite loop may be entered."
2765 (let ((action-key (car action
))
2766 (action-routine (cdr action
)))
2768 (while (idlwave-look-at action-key
)
2769 (if (listp action-routine
)
2770 (eval action-routine
)
2771 (funcall action-routine
)))))
2773 (defun idlwave-indent-to (col &optional min
)
2774 "Indent from point with spaces until column COL.
2775 Inserts space before markers at point."
2776 (if (not min
) (setq min
0))
2777 (insert-before-markers
2778 (make-string (max min
(- col
(current-column))) ?\
)))
2780 (defun idlwave-indent-left-margin (col)
2781 "Indent the current line to column COL.
2782 Indents such that first non-whitespace character is at column COL
2783 Inserts spaces before markers at point."
2786 (delete-horizontal-space)
2787 (idlwave-indent-to col
)))
2789 (defun idlwave-indent-subprogram ()
2790 "Indents program unit which contains point."
2793 (idlwave-end-of-statement)
2794 (idlwave-beginning-of-subprogram)
2795 (let ((beg (point)))
2796 (idlwave-forward-block)
2797 (message "Indenting subprogram...")
2798 (indent-region beg
(point) nil
))
2799 (message "Indenting subprogram...done.")))
2801 (defun idlwave-indent-statement ()
2802 "Indent current statement, including all continuation lines."
2805 (idlwave-beginning-of-statement)
2806 (let ((beg (point)))
2807 (idlwave-end-of-statement)
2808 (indent-region beg
(point) nil
))))
2810 (defun idlwave-calculate-indent ()
2811 "Return appropriate indentation for current line as IDL code."
2815 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2817 ((idlwave-look-at idlwave-begin-unit-reg
)
2819 ;; Check for continuation line
2821 (and (= (forward-line -
1) 0)
2822 (idlwave-is-continuation-line)))
2823 (idlwave-calculate-cont-indent))
2824 ;; calculate indent based on previous and current statements
2825 (t (let ((the-indent
2826 ;; calculate indent based on previous statement
2829 ((idlwave-previous-statement)
2832 ((idlwave-look-at idlwave-begin-unit-reg t
)
2833 (+ (idlwave-current-statement-indent)
2834 idlwave-main-block-indent
))
2836 ((idlwave-look-at idlwave-begin-block-reg t
)
2837 (+ (idlwave-current-statement-indent)
2838 idlwave-block-indent
))
2839 ((idlwave-look-at idlwave-end-block-reg t
)
2840 (- (idlwave-current-statement-indent)
2842 idlwave-block-indent
))
2843 ((idlwave-current-statement-indent))))))
2844 ;; adjust the indentation based on the current statement
2847 ((idlwave-look-at idlwave-end-block-reg
)
2848 (+ the-indent idlwave-end-offset
))
2852 ;; Parentheses balacing/indent
2855 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp
)
2856 "Calculate the continuation indent inside a paren group.
2857 Returns a cons-cell with (open . indent), where open is the
2858 location of the open paren"
2859 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg
))))
2860 ;; Found an innermost open paren.
2863 ;; Line up with next word unless this is a closing paren.
2866 ;; This is a closed paren - line up under open paren.
2869 ;; Empty (or just comment) - just line up next to paren
2873 (looking-at "[ \t$]*\\(;.*\\)?$"))
2875 ;; Line up with first word after blank space
2877 (skip-chars-forward " \t")
2878 (current-column))))))))
2880 (defun idlwave-calculate-cont-indent ()
2881 "Calculates the IDL continuation indent column from the previous statement.
2882 Note that here previous statement means the beginning of the current
2883 statement if this statement is a continuation of the previous line."
2886 (case-fold-search t
)
2887 (end-reg (progn (beginning-of-line) (point)))
2888 (close-exp (progn (skip-chars-forward " \t") (looking-at "\\s)")))
2889 ; (beg-reg (progn (idlwave-previous-statement) (point)))
2890 (beg-reg (progn ;; Use substatement indent unless it's this line
2891 (idlwave-start-of-substatement 'pre
)
2892 (if (eq (line-beginning-position) end-reg
)
2893 (idlwave-previous-statement))
2895 (cur-indent (idlwave-current-indent))
2896 (else-cont (and (goto-char end-reg
) (looking-at "[ \t]*else")))
2897 (basic-indent ;; The basic, non-fancy indent
2898 (+ cur-indent idlwave-continuation-indent
))
2899 (fancy-nonparen-indent ;; A smarter indent for routine/assignments
2900 ;; Try without parens first:
2903 (while (idlwave-look-at "&")) ; skip over continued statements
2905 ;; A continued Procedure call or definition
2907 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
2908 (looking-at "[ \t]*\\([a-zA-Z0-9$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
2909 (goto-char (match-end 0))
2910 ;; Comment only, or blank line with "$"? Align with ,
2911 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2912 (goto-char (match-end 2)))
2915 ;; Continued assignment (with =),
2916 ((looking-at "[ \t]*[][().a-zA-Z0-9$_]+[ \t]*\\(=\\)[ \t]*")
2917 (goto-char (match-end 0))
2918 ;; Comment only? Align with =
2919 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2921 (goto-char (match-end 1))
2922 (if idlwave-surround-by-blank
2923 (1+ (current-column))
2925 (current-column))))))
2926 (fancy-nonparen-indent-allowed
2927 (and fancy-nonparen-indent
2928 (< (- fancy-nonparen-indent basic-indent
)
2929 idlwave-max-extra-continuation-indent
)))
2930 (fancy-paren-indent-cons ;; A smarter indent for paren groups
2931 ;; Look for any enclosing parens
2932 (idlwave-calculate-paren-indent beg-reg end-reg close-exp
))
2933 (fancy-paren-open (car fancy-paren-indent-cons
))
2934 (fancy-paren-indent (cdr fancy-paren-indent-cons
))
2935 (fancy-paren-indent-allowed
2936 (and fancy-paren-indent
2937 (or idlwave-indent-to-open-paren
;; override
2938 (< (- fancy-paren-indent basic-indent
)
2939 idlwave-max-extra-continuation-indent
))))
2940 fancy-enclosing-paren-indent
)
2942 ;; else continuations are always standard
2946 ;; an allowed parenthesis-indent
2947 (fancy-paren-indent-allowed
2950 ;; a disallowed paren indent nested inside one or more other
2951 ;; parens: indent relative to the first allowed enclosing paren
2952 ;; set, if any... if it's actually a greater indent, just use
2953 ;; the fancy-paren-indent anyway.
2954 ((and fancy-paren-indent
2955 (not fancy-paren-indent-allowed
)
2956 (setq fancy-enclosing-paren-indent
2957 (let ((enclose-open fancy-paren-open
)
2961 (while (setq enclose-indent-cons
2962 (idlwave-calculate-paren-indent
2963 beg-reg
(max (1- enclose-open
) beg-reg
)
2965 enclose-open
(car enclose-indent-cons
)
2966 enclose-indent
(cdr enclose-indent-cons
))
2967 (if (< (- enclose-indent basic-indent
)
2968 idlwave-max-extra-continuation-indent
)
2969 (throw 'loop enclose-indent
)))))))
2970 (min fancy-paren-indent
2971 (+ fancy-enclosing-paren-indent idlwave-continuation-indent
)))
2973 ;; a disallowed paren indent inside another type: indent relative
2974 ((and fancy-paren-indent
2975 (not fancy-paren-indent-allowed
)
2976 fancy-nonparen-indent-allowed
)
2977 (+ fancy-nonparen-indent idlwave-continuation-indent
))
2979 ;; an allowed nonparen-only indent
2980 (fancy-nonparen-indent-allowed
2981 fancy-nonparen-indent
)
2987 (defun idlwave-find-key (key-re &optional dir nomark limit
)
2988 "Move to next match of the regular expression KEY-RE.
2989 Matches inside comments or string constants will be ignored.
2990 If DIR is negative, the search will be backwards.
2991 At a successful match, the mark is pushed unless NOMARK is non-nil.
2992 Searches are limited to LIMIT.
2993 Searches are case-insensitive and use a special syntax table which
2994 treats `$' and `_' as word characters.
2995 Return value is the beginning of the match or (in case of failure) nil."
2996 (setq dir
(or dir
0))
2997 (let ((case-fold-search t
)
2998 (search-func (if (> dir
0) 're-search-forward
're-search-backward
))
3000 (idlwave-with-special-syntax
3003 (while (funcall search-func key-re limit t
)
3004 (if (not (idlwave-quoted))
3005 (throw 'exit
(setq found
(match-beginning 0))))))))
3008 (if (not nomark
) (push-mark))
3013 (defun idlwave-block-jump-out (&optional dir nomark
)
3014 "When optional argument DIR is non-negative, move forward to end of
3015 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3016 regular expressions. When DIR is negative, move backwards to block beginning.
3017 Recursively calls itself to skip over nested blocks. DIR defaults to
3018 forward. Calls `push-mark' unless the optional argument NOMARK is
3019 non-nil. Movement is limited by the start of program units because of
3020 possibility of unbalanced blocks."
3022 (or dir
(setq dir
0))
3023 (let* ((here (point))
3024 (case-fold-search t
)
3025 (limit (if (>= dir
0) (point-max) (point-min)))
3026 (block-limit (if (>= dir
0)
3027 idlwave-begin-block-reg
3028 idlwave-end-block-reg
))
3030 (block-reg (concat idlwave-begin-block-reg
"\\|"
3031 idlwave-end-block-reg
))
3032 (unit-limit (or (save-excursion
3035 idlwave-begin-unit-reg dir t limit
)
3038 idlwave-end-unit-reg dir t limit
)))
3040 (if (>= dir
0) (end-of-line)) ;Make sure we are in current block
3041 (if (setq found
(idlwave-find-key block-reg dir t unit-limit
))
3042 (while (and found
(looking-at block-limit
))
3043 (if (>= dir
0) (forward-word 1))
3044 (idlwave-block-jump-out dir t
)
3045 (setq found
(idlwave-find-key block-reg dir t unit-limit
))))
3046 (if (not nomark
) (push-mark here
))
3047 (if (not found
) (goto-char unit-limit
)
3048 (if (>= dir
0) (forward-word 1)))))
3050 (defun idlwave-current-statement-indent ()
3051 "Return indentation of the current statement.
3052 If in a statement, moves to beginning of statement before finding indent."
3053 (idlwave-beginning-of-statement)
3054 (idlwave-current-indent))
3056 (defun idlwave-current-indent ()
3057 "Return the column of the indentation of the current line.
3058 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3061 (skip-chars-forward " \t")
3062 ;; if we are at the end of blank line return 0
3064 ((current-column)))))
3066 (defun idlwave-is-continuation-line ()
3067 "Tests if current line is continuation line.
3068 Blank or comment-only lines following regular continuation lines (with
3069 `$') count as continuations too."
3072 (idlwave-look-at "\\<\\$")
3074 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3075 (eq (forward-line -
1) 0))
3076 (if (idlwave-look-at "\\<\\$") (throw 'loop t
)))))))
3078 (defun idlwave-is-comment-line ()
3079 "Tests if the current line is a comment line."
3081 (beginning-of-line 1)
3082 (looking-at "[ \t]*;")))
3084 (defun idlwave-is-comment-or-empty-line ()
3085 "Tests if the current line is a comment line."
3087 (beginning-of-line 1)
3088 (looking-at "[ \t]*[;\n]")))
3090 (defun idlwave-look-at (regexp &optional cont beg
)
3091 "Searches current line from current point for REGEXP.
3092 If optional argument CONT is non-nil, searches to the end of
3093 the current statement.
3094 If optional arg BEG is non-nil, search starts from the beginning of the
3096 Ignores matches that end in a comment or inside a string expression.
3097 Returns point if successful, nil otherwise.
3098 This function produces unexpected results if REGEXP contains quotes or
3099 a comment delimiter. The search is case insensitive.
3100 If successful leaves point after the match, otherwise, does not move point."
3101 (let ((here (point))
3102 (case-fold-search t
)
3103 (eos (save-excursion
3104 (if cont
(idlwave-end-of-statement) (end-of-line))
3107 (idlwave-with-special-syntax
3108 (if beg
(idlwave-beginning-of-statement))
3109 (while (and (setq found
(re-search-forward regexp eos t
))
3111 (if (not found
) (goto-char here
))
3114 (defun idlwave-fill-paragraph (&optional nohang
)
3115 "Fills paragraphs in comments.
3116 A paragraph is made up of all contiguous lines having the same comment
3117 leader (the leading whitespace before the comment delimiter and the
3118 comment delimiter). In addition, paragraphs are separated by blank
3119 line comments. The indentation is given by the hanging indent of the
3120 first line, otherwise by the minimum indentation of the lines after
3121 the first line. The indentation of the first line does not change.
3122 Does not effect code lines. Does not fill comments on the same line
3123 with code. The hanging indent is given by the end of the first match
3124 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3125 optional argument NOHANG is non-nil then the hanging indent is
3128 ;; check if this is a line comment
3131 (skip-chars-forward " \t")
3132 (looking-at comment-start
))
3135 pre here diff fill-prefix-reg bcl first-indent
3137 ;; Change tabs to spaces in the surrounding paragraph.
3138 ;; The surrounding paragraph will be the largest containing block of
3139 ;; contiguous line comments. Thus, we may be changing tabs in
3140 ;; a much larger area than is needed, but this is the easiest
3141 ;; brute force way to do it.
3143 ;; This has the undesirable side effect of replacing the tabs
3144 ;; permanently without the user's request or knowledge.
3146 (backward-paragraph)
3147 (setq start
(point)))
3151 (untabify start end
)
3157 (concat "^[ \t]*" comment-start
"+")
3158 (save-excursion (end-of-line) (point))
3160 ;; Get the comment leader on the line and its length
3161 (setq pre
(current-column))
3162 ;; the comment leader is the indentation plus exactly the
3163 ;; number of consecutive ";".
3164 (setq fill-prefix-reg
3168 (buffer-substring (save-excursion
3169 (beginning-of-line) (point))
3173 ;; Mark the beginning and end of the paragraph
3175 (while (and (looking-at fill-prefix-reg
)
3176 (not (looking-at paragraph-separate
))
3179 ;; Move to first line of paragraph
3180 (if (/= (point) bcl
)
3182 (setq start
(point))
3184 (while (and (looking-at fill-prefix-reg
)
3185 (not (looking-at paragraph-separate
))
3189 (if (or (not (looking-at fill-prefix-reg
))
3190 (looking-at paragraph-separate
))
3193 ;; if at end of buffer add a newline (need this because
3194 ;; fill-region needs END to be at the beginning of line after
3195 ;; the paragraph or it will add a line).
3197 (progn (insert ?
\n) (backward-char 1)))
3198 ;; Set END to the beginning of line after the paragraph
3199 ;; END is calculated as distance from end of buffer
3200 (setq end
(- (point-max) (point) 1))
3202 ;; Calculate the indentation for the paragraph.
3204 ;; In the following while statements, after one iteration
3205 ;; point will be at the beginning of a line in which case
3206 ;; the while will not be executed for the
3207 ;; the first paragraph line and thus will not affect the
3210 ;; First check to see if indentation is based on hanging indent.
3211 (if (and (not nohang
) idlwave-hanging-indent
3215 (idlwave-calc-hanging-indent))))
3216 ;; Adjust lines of paragraph by inserting spaces so that
3217 ;; each line's indent is at least as great as the hanging
3218 ;; indent. This is needed for fill-paragraph to work with
3223 (while (> (point) start
)
3224 (re-search-forward comment-start-skip
3225 (save-excursion (end-of-line) (point))
3227 (if (> (setq diff
(- indent
(current-column))) 0)
3229 (if (>= here
(point))
3230 ;; adjust the original location for the
3232 (setq here
(+ here diff
)))
3233 (insert (make-string diff ?\
))))
3237 ;; No hang. Instead find minimum indentation of paragraph
3238 ;; after first line.
3239 ;; For the following while statement, since START is at the
3240 ;; beginning of line and END is at the end of line
3241 ;; point is greater than START at least once (which would
3242 ;; be the case for a single line paragraph).
3243 (while (> (point) start
)
3250 (save-excursion (end-of-line) (point))
3255 (setq fill-prefix
(concat fill-prefix
3256 (make-string (- indent pre
)
3258 ;; first-line indent
3264 (save-excursion (end-of-line) (point))
3269 ;; try to keep point at its original place
3272 ;; In place of the more modern fill-region-as-paragraph, a hack
3273 ;; to keep whitespace untouched on the first line within the
3274 ;; indent length and to preserve any indent on the first line
3278 (buffer-substring start
(+ start first-indent -
1)))
3279 (subst-char-in-region start
(+ start first-indent -
1) ?\ ?~ nil
)
3280 (fill-region-as-paragraph
3283 (current-justification)
3285 (delete-region start
(+ start first-indent -
1))
3288 ;; When we want the point at the beginning of the comment
3289 ;; body fill-region will put it at the beginning of the line.
3290 (if (bolp) (skip-chars-forward (concat " \t" comment-start
)))
3291 (setq fill-prefix nil
))))
3293 (defun idlwave-calc-hanging-indent ()
3294 "Calculate the position of the hanging indent for the comment
3295 paragraph. The hanging indent position is given by the first match
3296 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3297 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3299 If not found returns nil."
3300 (if idlwave-use-last-hang-indent
3303 (if (re-search-backward
3304 idlwave-hang-indent-regexp
3305 (save-excursion (beginning-of-line) (point))
3307 (+ (current-column) (length idlwave-hang-indent-regexp
))))
3310 (if (re-search-forward
3311 idlwave-hang-indent-regexp
3312 (save-excursion (end-of-line) (point))
3314 (current-column)))))
3316 (defun idlwave-auto-fill ()
3317 "Called to break lines in auto fill mode.
3318 Only fills comment lines if `idlwave-fill-comment-line-only' is non-nil.
3319 Places a continuation character at the end of the line
3320 if not in a comment. Splits strings with IDL concatenation operator
3321 `+' if `idlwave-auto-fill-split-string is non-nil."
3322 (if (<= (current-column) fill-column
)
3323 nil
; do not to fill
3324 (if (or (not idlwave-fill-comment-line-only
)
3326 ;; Check for comment line
3328 (looking-at idlwave-comment-line-start-skip
)))
3330 (idlwave-indent-line)
3331 ;; Prevent actions do-auto-fill which calls indent-line-function.
3332 (let (idlwave-do-actions
3333 (paragraph-start ".")
3334 (paragraph-separate "."))
3338 ;; Indent the split line
3339 (idlwave-indent-line)
3343 (looking-at idlwave-comment-line-start-skip
))
3344 ;; A continued line comment
3345 ;; We treat continued line comments as part of a comment
3346 ;; paragraph. So we check for a hanging indent.
3347 (if idlwave-hanging-indent
3348 (let ((here (- (point-max) (point)))
3352 (idlwave-calc-hanging-indent))))
3355 ;; Remove whitespace between comment delimiter and
3356 ;; text, insert spaces for appropriate indentation.
3360 (save-excursion (end-of-line) (point)) t
)
3361 (delete-horizontal-space)
3362 (idlwave-indent-to indent
)
3363 (goto-char (- (point-max) here
)))
3365 ;; Split code or comment?
3368 (idlwave-in-comment))
3369 ;; Splitting a non-line comment.
3370 ;; Insert the comment delimiter from split line
3374 (skip-chars-forward " \t")
3375 ;; Insert blank to keep off beginning of line
3379 (buffer-substring (idlwave-goto-comment)
3381 (skip-chars-forward "; ")
3383 (idlwave-indent-line))
3384 ;; Split code line - add continuation character
3387 ;; Check to see if we split a string
3388 (if (and (setq beg
(idlwave-in-quote))
3389 idlwave-auto-fill-split-string
)
3390 ;; Split the string and concatenate.
3391 ;; The first extra space is for the space
3392 ;; the line was split. That space was removed.
3393 (insert " " (char-after beg
) " +"))
3396 (if idlwave-auto-fill-split-string
3397 ;; Make the second part of continued string
3400 (skip-chars-forward " \t")
3401 (insert (char-after beg
)))
3404 (message "Warning: continuation inside a string.")))
3405 ;; Although do-auto-fill (via indent-new-comment-line) calls
3406 ;; idlwave-indent-line for the new line, re-indent again
3407 ;; because of the addition of the continuation character.
3408 (idlwave-indent-line))
3411 (defun idlwave-auto-fill-mode (arg)
3412 "Toggle auto-fill mode for IDL mode.
3413 With arg, turn auto-fill mode on if arg is positive.
3414 In auto-fill mode, inserting a space at a column beyond `fill-column'
3415 automatically breaks the line at a previous space."
3417 (prog1 (set idlwave-fill-function
3419 (not (symbol-value idlwave-fill-function
))
3420 (> (prefix-numeric-value arg
) 0))
3424 (set-buffer-modified-p (buffer-modified-p))))
3426 (defun idlwave-doc-header (&optional nomark
)
3427 "Insert a documentation header at the beginning of the unit.
3428 Inserts the value of the variable idlwave-file-header. Sets mark before
3429 moving to do insertion unless the optional prefix argument NOMARK
3432 (or nomark
(push-mark))
3433 ;; make sure we catch the current line if it begins the unit
3434 (if idlwave-header-to-beginning-of-file
3435 (goto-char (point-min))
3437 (idlwave-beginning-of-subprogram)
3439 ;; skip function or procedure line
3440 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3442 (idlwave-end-of-statement)
3443 (if (> (forward-line 1) 0) (insert "\n")))))
3444 (let ((pos (point)))
3445 (if idlwave-file-header
3446 (cond ((car idlwave-file-header
)
3447 (insert-file (car idlwave-file-header
)))
3448 ((stringp (car (cdr idlwave-file-header
)))
3449 (insert (car (cdr idlwave-file-header
))))))
3452 (defun idlwave-default-insert-timestamp ()
3453 "Default timestamp insertion function"
3454 (insert (current-time-string))
3455 (insert ", " (user-full-name))
3456 (if (boundp 'user-mail-address
)
3457 (insert " <" user-mail-address
">")
3458 (insert " <" (user-login-name) "@" (system-name) ">"))
3459 ;; Remove extra spaces from line
3460 (idlwave-fill-paragraph)
3461 ;; Insert a blank line comment to separate from the date entry -
3462 ;; will keep the entry from flowing onto date line if re-filled.
3463 (insert "\n;\n;\t\t"))
3465 (defun idlwave-doc-modification ()
3466 "Insert a brief modification log at the beginning of the current program.
3467 Looks for an occurrence of the value of user variable
3468 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3469 and places the point for the user to add a log. Before moving, saves
3470 location on mark ring so that the user can return to previous point."
3474 (if (and (or (re-search-backward idlwave-doclib-start nil t
)
3476 (goto-char (point-min))
3477 (re-search-forward idlwave-doclib-start nil t
)))
3478 (setq beg
(match-beginning 0))
3479 (re-search-forward idlwave-doclib-end nil t
)
3480 (setq end
(match-end 0)))
3483 (if (re-search-forward
3484 (concat idlwave-doc-modifications-keyword
":")
3489 (insert "\n" comment-start
"\n")
3490 (insert comment-start
" " idlwave-doc-modifications-keyword
":"))
3492 (run-hooks 'idlwave-timestamp-hook
))
3493 (error "No valid DOCLIB header"))))
3496 ;;; Interface to expand-region-abbrevs which did not work when the
3497 ;;; abbrev hook associated with an abbrev moves point backwards
3498 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3499 ;;; The original would enter an infinite loop in attempting to expand
3500 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3501 ;;; because the point would keep going back to the beginning of the
3502 ;;; abbrev instead of to the end of the abbrev). We now keep the
3503 ;;; abbrev hook from moving backwards.
3505 (defun idlwave-expand-region-abbrevs (start end
)
3506 "Expand each abbrev occurrence in the region.
3507 Calling from a program, arguments are START END."
3510 (goto-char (min start end
))
3511 (let ((idlwave-show-block nil
) ;Do not blink
3512 (idlwave-abbrev-move nil
)) ;Do not move
3513 (expand-region-abbrevs start end
'noquery
))))
3515 (defun idlwave-quoted ()
3516 "Returns t if point is in a comment or quoted string.
3518 (or (idlwave-in-comment) (idlwave-in-quote)))
3520 (defun idlwave-in-quote ()
3521 "Returns location of the opening quote
3522 if point is in a IDL string constant, nil otherwise.
3523 Ignores comment delimiters on the current line.
3524 Properly handles nested quotation marks and octal
3525 constants - a double quote followed by an octal digit."
3526 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3527 ;;; double quote followed by an octal digit to be an octal constant
3528 ;;; rather than a string. Therefore, there is no terminating double
3531 ;; Because single and double quotes can quote each other we must
3532 ;; search for the string start from the beginning of line.
3533 (let* ((start (point))
3534 (eol (progn (end-of-line) (point)))
3535 (bq (progn (beginning-of-line) (point)))
3540 (while (< endq start
)
3541 ;; Find string start
3542 ;; Don't find an octal constant beginning with a double quote
3543 (if (re-search-forward "\"[^0-7]\\|'\\|\"$" eol
'lim
)
3544 ;; Find the string end.
3545 ;; In IDL, two consecutive delimiters after the start of a
3547 ;; escape for the delimiter in the string.
3548 ;; Two consecutive delimiters alone (i.e., not after the
3549 ;; start of a string) is the null string.
3551 ;; Move to position after quote
3552 (goto-char (1+ (match-beginning 0)))
3553 (setq bq
(1- (point)))
3554 ;; Get the string delimiter
3555 (setq delim
(char-to-string (preceding-char)))
3556 ;; Check for null string
3557 (if (looking-at delim
)
3558 (progn (setq endq
(point)) (forward-char 1))
3559 ;; Look for next unpaired delimiter
3560 (setq found
(search-forward delim eol
'lim
))
3561 (while (looking-at delim
)
3563 (setq found
(search-forward delim eol
'lim
)))
3565 (setq endq
(- (point) 1))
3566 (setq endq
(point)))
3568 (progn (setq bq
(point)) (setq endq
(point)))))
3569 (store-match-data data
)
3570 ;; return string beginning position or nil
3571 (if (> start bq
) bq
))))
3573 (defun idlwave-is-pointer-dereference (&optional limit
)
3574 "Determines if the character after point is a pointer dereference *."
3575 (let ((pos (point)))
3577 (eq (char-after) ?\
*)
3578 (not (idlwave-in-quote))
3581 (re-search-backward (concat "\\(" idlwave-idl-keywords
3582 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t
)))))
3585 ;; Statement templates
3587 ;; Replace these with a general template function, something like
3588 ;; expand.el (I think there was also something with a name similar to
3591 (defun idlwave-template (s1 s2
&optional prompt noindent
)
3592 "Build a template with optional prompt expression.
3594 Opens a line if point is not followed by a newline modulo intervening
3595 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3596 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3597 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3598 PROMPT is a string then it is displayed as a message in the
3599 minibuffer. The PROMPT serves as a reminder to the user of an
3600 expression to enter.
3602 The lines containing S1 and S2 are reindented using `indent-region'
3603 unless the optional second argument NOINDENT is non-nil."
3604 (if (eq major-mode
'idlwave-shell-mode
)
3605 ;; This is a gross hack to avoit template abbrev expansion
3606 ;; in the shell. FIXME: This is a dirty hack.
3607 (if (and (eq this-command
'self-insert-command
)
3608 (equal last-abbrev-location
(point)))
3609 (insert last-abbrev-text
)
3610 (error "No templates in idlwave-shell"))
3611 (cond ((eq idlwave-abbrev-change-case
'down
)
3612 (setq s1
(downcase s1
) s2
(downcase s2
)))
3613 (idlwave-abbrev-change-case
3614 (setq s1
(upcase s1
) s2
(upcase s2
))))
3615 (let ((beg (save-excursion (beginning-of-line) (point)))
3617 (if (not (looking-at "\\s-*\n"))
3624 (indent-region beg end nil
))
3625 (if (stringp prompt
)
3626 (message prompt
)))))
3628 (defun idlwave-rw-case (string)
3629 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3630 (if idlwave-reserved-word-upcase
3634 (defun idlwave-elif ()
3635 "Build skeleton IDL if-else block."
3638 (idlwave-rw-case "if")
3639 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3640 "Condition expression"))
3642 (defun idlwave-case ()
3643 "Build skeleton IDL case statement."
3646 (idlwave-rw-case "case")
3647 (idlwave-rw-case " of\n\nendcase")
3648 "Selector expression"))
3650 (defun idlwave-switch ()
3651 "Build skeleton IDL switch statement."
3654 (idlwave-rw-case "switch")
3655 (idlwave-rw-case " of\n\nendswitch")
3656 "Selector expression"))
3658 (defun idlwave-for ()
3659 "Build skeleton for loop statment."
3662 (idlwave-rw-case "for")
3663 (idlwave-rw-case " do begin\n\nendfor")
3666 (defun idlwave-if ()
3667 "Build skeleton for loop statment."
3670 (idlwave-rw-case "if")
3671 (idlwave-rw-case " then begin\n\nendif")
3672 "Scalar logical expression"))
3674 (defun idlwave-procedure ()
3677 (idlwave-rw-case "pro")
3678 (idlwave-rw-case "\n\nreturn\nend")
3681 (defun idlwave-function ()
3684 (idlwave-rw-case "function")
3685 (idlwave-rw-case "\n\nreturn\nend")
3688 (defun idlwave-repeat ()
3691 (idlwave-rw-case "repeat begin\n\nendrep until")
3692 (idlwave-rw-case "")
3695 (defun idlwave-while ()
3698 (idlwave-rw-case "while")
3699 (idlwave-rw-case " do begin\n\nendwhile")
3702 (defun idlwave-split-string (string &optional pattern
)
3703 "Return a list of substrings of STRING which are separated by PATTERN.
3704 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3706 (setq pattern
"[ \f\t\n\r\v]+"))
3707 (let (parts (start 0))
3708 (while (string-match pattern string start
)
3709 (setq parts
(cons (substring string start
(match-beginning 0)) parts
)
3710 start
(match-end 0)))
3711 (nreverse (cons (substring string start
) parts
))))
3713 (defun idlwave-replace-string (string replace_string replace_with
)
3715 (last (length string
))
3718 (while (setq end
(string-match replace_string string start
))
3720 (concat ret_string
(substring string start end
) replace_with
))
3721 (setq start
(match-end 0)))
3722 (setq ret_string
(concat ret_string
(substring string start last
)))))
3724 (defun idlwave-get-buffer-visiting (file)
3725 ;; Return the buffer currently visiting FILE
3727 ((boundp 'find-file-compare-truenames
) ; XEmacs
3728 (let ((find-file-compare-truenames t
))
3729 (get-file-buffer file
)))
3730 ((fboundp 'find-buffer-visiting
) ; Emacs
3731 (find-buffer-visiting file
))
3732 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3734 (defvar idlwave-outlawed-buffers nil
3735 "List of buffer pulled up by idlwave for special reasons.
3736 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3738 (defun idlwave-find-file-noselect (file &optional why
)
3739 ;; Return a buffer visiting file.
3740 (or (idlwave-get-buffer-visiting file
)
3741 (let ((buf (find-file-noselect file
)))
3742 (if why
(add-to-list 'idlwave-outlawed-buffers
(cons buf why
)))
3745 (defun idlwave-kill-autoloaded-buffers ()
3746 "Cleanup by killing buffers created automatically by IDLWAVE.
3747 Function prompts for a letter to identify the buffers to kill.
3748 Possible letters are:
3750 f Buffers created by the command \\[idlwave-find-module] or mouse
3751 clicks in the routine info window.
3752 s Buffers created by the IDLWAVE Shell to display where execution
3753 stopped or an error was found.
3754 a Both of the above.
3756 Buffer containing unsaved changes require confirmation before they are killed."
3758 (if (null idlwave-outlawed-buffers
)
3759 (error "No IDLWAVE-created buffers available")
3760 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3761 (idlwave-count-outlawed-buffers 'find
)
3762 (idlwave-count-outlawed-buffers 'shell
)))
3763 (let ((c (read-char)))
3765 ((member c
'(?f ?\C-f
))
3766 (idlwave-do-kill-autoloaded-buffers 'find
))
3767 ((member c
'(?s ?\C-s
))
3768 (idlwave-do-kill-autoloaded-buffers 'shell
))
3769 ((member c
'(?a ?\C-a
))
3770 (idlwave-do-kill-autoloaded-buffers t
))
3771 (t (error "Abort"))))))
3773 (defun idlwave-count-outlawed-buffers (tag)
3774 "How many outlawed buffers have tag TAG?"
3777 (lambda (x) (eq (cdr x
) tag
))
3778 idlwave-outlawed-buffers
))))
3780 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons
)
3781 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3782 (let* ((list (copy-sequence idlwave-outlawed-buffers
))
3785 (while (setq entry
(pop list
))
3786 (if (buffer-live-p (car entry
))
3787 (and (or (memq t reasons
)
3788 (memq (cdr entry
) reasons
))
3789 (kill-buffer (car entry
))
3791 (setq idlwave-outlawed-buffers
3792 (delq entry idlwave-outlawed-buffers
)))
3793 (setq idlwave-outlawed-buffers
3794 (delq entry idlwave-outlawed-buffers
))))
3795 (message "%d buffer%s killed" cnt
(if (= cnt
1) "" "s"))))
3797 (defun idlwave-revoke-license-to-kill ()
3798 "Remove BUFFER from the buffers which may be killed.
3799 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3800 Intended for `after-save-hook'."
3801 (let* ((buf (current-buffer))
3802 (entry (assq buf idlwave-outlawed-buffers
)))
3805 (setq idlwave-outlawed-buffers
3806 (delq entry idlwave-outlawed-buffers
)))
3807 ;; Remove this function from the hook.
3808 (remove-hook 'after-save-hook
'idlwave-revoke-license-to-kill
'local
)))
3810 (defvar idlwave-path-alist
)
3811 (defun idlwave-locate-lib-file (file)
3812 ;; Find FILE on the scanned lib path and return a buffer visiting it
3813 (let* ((dirs idlwave-path-alist
)
3816 (while (setq dir
(car (pop dirs
)))
3818 (setq efile
(expand-file-name file dir
)))
3819 (throw 'exit efile
))))))
3820 (defun idlwave-expand-lib-file-name (file)
3821 ;; Find FILE on the scanned lib path and return a buffer visiting it
3824 ((string-match "\\`\\({\\([0-9]+\\)}/\\)\\(.*\\)" file
)
3825 (expand-file-name (match-string 3 file
)
3826 (car (nth (1- (string-to-int (match-string 2 file
)))
3827 idlwave-path-alist
))))
3828 ((file-name-absolute-p file
) file
)
3829 (t (idlwave-locate-lib-file file
))))
3831 (defun idlwave-make-tags ()
3832 "Creates the IDL tags file IDLTAGS in the current directory from
3833 the list of directories specified in the minibuffer. Directories may be
3834 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3835 specified top directories are searched if the directory name is prefixed
3836 by @. Specify @ directories with care, it may take a long, long time if
3839 (let (directory directories cmd append status numdirs dir getsubdirs
3840 buffer save_buffer files numfiles item errbuf
)
3843 ;; Read list of directories
3844 (setq directory
(read-string "Tag Directories: " "."))
3845 (setq directories
(idlwave-split-string directory
"[ \t]+"))
3847 ;; Set etags command, vars
3848 (setq cmd
"etags --output=IDLTAGS --language=none --regex='/[
3849 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3850 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3854 ;; For each directory
3856 (setq dir
(nth numdirs directories
))
3859 ;; Find the subdirectories
3860 (if (string-match "^[@]\\(.+\\)$" dir
)
3861 (setq getsubdirs t
) (setq getsubdirs nil
))
3862 (if (and getsubdirs
) (setq dir
(substring dir
1 (length dir
))))
3863 (setq dir
(expand-file-name dir
))
3864 (if (file-directory-p dir
)
3866 (if (and getsubdirs
)
3868 (setq buffer
(get-buffer-create "*idltags*"))
3869 (call-process "sh" nil buffer nil
"-c"
3870 (concat "find " dir
" -type d -print"))
3871 (setq save_buffer
(current-buffer))
3873 (setq files
(idlwave-split-string
3874 (idlwave-replace-string
3875 (buffer-substring 1 (point-max))
3878 (set-buffer save_buffer
)
3879 (kill-buffer buffer
))
3880 (setq files
(list (concat dir
"/*.pro"))))
3882 ;; For each subdirectory
3884 (setq item
(nth numfiles files
))
3888 (if (not (string-match "^[ \\t]*$" item
))
3890 (message (concat "Tagging " item
"..."))
3891 (setq errbuf
(get-buffer-create "*idltags-error*"))
3892 (setq status
(+ status
3893 (call-process "sh" nil errbuf nil
"-c"
3894 (concat cmd append item
))))
3896 ;; Append additional tags
3897 (setq append
" --append ")
3898 (setq numfiles
(1+ numfiles
))
3899 (setq item
(nth numfiles files
)))
3901 (setq numfiles
(1+ numfiles
))
3902 (setq item
(nth numfiles files
))
3905 (setq numdirs
(1+ numdirs
))
3906 (setq dir
(nth numdirs directories
)))
3908 (setq numdirs
(1+ numdirs
))
3909 (setq dir
(nth numdirs directories
)))))
3911 (setq errbuf
(get-buffer-create "*idltags-error*"))
3913 (kill-buffer errbuf
))
3917 (defun idlwave-toggle-comment-region (beg end
&optional n
)
3918 "Comment the lines in the region if the first non-blank line is
3919 commented, and conversely, uncomment region. If optional prefix arg
3920 N is non-nil, then for N positive, add N comment delimiters or for N
3921 negative, remove N comment delimiters.
3922 Uses `comment-region' which does not place comment delimiters on
3924 (interactive "r\nP")
3926 (comment-region beg end
(prefix-numeric-value n
))
3931 (skip-chars-forward " \t\n")
3932 (if (looking-at (concat "[ \t]*\\(" comment-start
"+\\)"))
3933 (comment-region beg end
3934 (- (length (buffer-substring
3937 (comment-region beg end
)))))
3940 ;; ----------------------------------------------------------------------------
3941 ;; ----------------------------------------------------------------------------
3942 ;; ----------------------------------------------------------------------------
3943 ;; ----------------------------------------------------------------------------
3945 ;; Completion and Routine Info
3948 ;; String "intern" functions
3950 ;; For the completion and routine info function, we want to normalize
3951 ;; the case of procedure names etc. We do this by "interning" these
3952 ;; string is a hand-crafted way. Hashes are used to map the downcase
3953 ;; version of the strings to the cased versions. Since these cased
3954 ;; versions are really lisp objects, we can use `eq' to search, which
3955 ;; is a large performance boost.
3956 ;; All new strings need to be "sinterned". We do this as early as
3957 ;; possible after getting these strings from completion or buffer
3958 ;; substrings. So most of the code can simply assume to deal with
3959 ;; "sinterned" strings. The only exception is that the functions
3960 ;; which scan whole buffers for routine information do not intern the
3961 ;; grabbed strings. This is only done afterwards. Therefore in these
3962 ;; functions it is *not* safe to assume the strings can be compared
3963 ;; with `eq' and be fed into the routine assq functions.
3965 ;; Here we define the hashing functions.
3967 ;; The variables which hold the hashes.
3968 (defvar idlwave-sint-routines
'(nil))
3969 (defvar idlwave-sint-keywords
'(nil))
3970 (defvar idlwave-sint-methods
'(nil))
3971 (defvar idlwave-sint-classes
'(nil))
3972 (defvar idlwave-sint-files
'(nil))
3974 (defun idlwave-reset-sintern (&optional what
)
3975 "Reset all sintern hashes."
3976 ;; Make sure the hash functions are accessible.
3977 (if (or (not (fboundp 'gethash
))
3978 (not (fboundp 'puthash
)))
3981 (or (fboundp 'puthash
)
3982 (defalias 'puthash
'cl-puthash
))))
3983 (let ((entries '((idlwave-sint-routines 1000 10)
3984 (idlwave-sint-keywords 1000 10)
3985 (idlwave-sint-methods 100 10)
3986 (idlwave-sint-classes 10 10))))
3988 ;; Make sure these are lists
3989 (loop for entry in entries
3990 for var
= (car entry
)
3991 do
(if (not (consp (symbol-value var
))) (set var
(list nil
))))
3993 (when (or (eq what t
) (eq what
'syslib
)
3994 (null (cdr idlwave-sint-routines
)))
3995 ;; Reset the system & library hash
3996 (loop for entry in entries
3997 for var
= (car entry
) for size
= (nth 1 entry
)
3998 do
(setcdr (symbol-value var
)
3999 (make-hash-table ':size size
':test
'equal
)))
4000 (setq idlwave-sint-files nil
))
4002 (when (or (eq what t
) (eq what
'bufsh
)
4003 (null (car idlwave-sint-routines
)))
4004 ;; Reset the buffer & shell hash
4005 (loop for entry in entries
4006 for var
= (car entry
) for size
= (nth 1 entry
)
4007 do
(setcar (symbol-value var
)
4008 (make-hash-table ':size size
':test
'equal
))))))
4010 (defun idlwave-sintern-routine-or-method (name &optional class set
)
4012 (idlwave-sintern-method name set
)
4013 (idlwave-sintern-routine name set
)))
4015 (defun idlwave-sintern (stype &rest args
)
4016 (apply (intern (concat "idlwave-sintern-" (symbol-name stype
))) args
))
4018 ;;(defmacro idlwave-sintern (type var)
4019 ;; `(cond ((not (stringp name)) name)
4020 ;; ((gethash (downcase name) (cdr ,var)))
4021 ;; ((gethash (downcase name) (car ,var)))
4022 ;; (set (idlwave-sintern-set name ,type ,var set))
4025 (defun idlwave-sintern-routine (name &optional set
)
4026 (cond ((not (stringp name
)) name
)
4027 ((gethash (downcase name
) (cdr idlwave-sint-routines
)))
4028 ((gethash (downcase name
) (car idlwave-sint-routines
)))
4029 (set (idlwave-sintern-set name
'routine idlwave-sint-routines set
))
4031 (defun idlwave-sintern-keyword (name &optional set
)
4032 (cond ((not (stringp name
)) name
)
4033 ((gethash (downcase name
) (cdr idlwave-sint-keywords
)))
4034 ((gethash (downcase name
) (car idlwave-sint-keywords
)))
4035 (set (idlwave-sintern-set name
'keyword idlwave-sint-keywords set
))
4037 (defun idlwave-sintern-method (name &optional set
)
4038 (cond ((not (stringp name
)) name
)
4039 ((gethash (downcase name
) (cdr idlwave-sint-methods
)))
4040 ((gethash (downcase name
) (car idlwave-sint-methods
)))
4041 (set (idlwave-sintern-set name
'method idlwave-sint-methods set
))
4043 (defun idlwave-sintern-class (name &optional set
)
4044 (cond ((not (stringp name
)) name
)
4045 ((gethash (downcase name
) (cdr idlwave-sint-classes
)))
4046 ((gethash (downcase name
) (car idlwave-sint-classes
)))
4047 (set (idlwave-sintern-set name
'class idlwave-sint-classes set
))
4050 (defun idlwave-sintern-file (name &optional set
)
4051 (car (or (member name idlwave-sint-files
)
4052 (setq idlwave-sint-files
(cons name idlwave-sint-files
)))))
4054 (defun idlwave-sintern-set (name type tables set
)
4055 (let* ((func (or (cdr (assq type idlwave-completion-case
))
4057 (iname (funcall (if (eq func
'preserve
) 'identity func
) name
))
4058 (table (if (eq set
'sys
) (cdr tables
) (car tables
))))
4059 (puthash (downcase name
) iname table
)
4062 (defun idlwave-sintern-rinfo-list (list &optional set
)
4063 "Sintern all strings in the rinfo LIST. With optional parameter SET:
4064 also set new patterns. Probably this will always have to be t."
4065 (let (entry name type class kwds res source call olh new
)
4067 (setq entry
(car list
)
4072 source
(nth 3 entry
)
4076 (setq kwds
(mapcar (lambda (x)
4077 (list (idlwave-sintern-keyword (car x
) set
)))
4081 (if (symbolp class
) (setq class
(symbol-name class
)))
4082 (setq class
(idlwave-sintern-class class set
))
4083 (setq name
(idlwave-sintern-method name set
)))
4084 (setq name
(idlwave-sintern-routine name set
)))
4085 (if (stringp (cdr source
))
4086 (setcdr source
(idlwave-sintern-file (cdr source
) t
)))
4088 (list name type class source call kwds olh
)
4089 (list name type class source call kwds
)))
4090 (setq res
(cons new res
)))
4093 ;; Creating new sintern tables
4095 (defun idlwave-new-sintern-type (tag)
4096 "Define a variable and a function to sintern the new type TAG.
4097 This defines the function `idlwave-sintern-TAG' and the variable
4098 `idlwave-sint-TAGs'."
4099 (let* ((name (symbol-name tag
))
4100 (names (concat name
"s"))
4101 (var (intern (concat "idlwave-sint-" names
)))
4102 (func (intern (concat "idlwave-sintern-" name
))))
4103 (set var nil
) ; initial value of the association list
4104 (fset func
; set the function
4105 `(lambda (name &optional set
)
4106 (cond ((not (stringp name
)) name
)
4107 ((cdr (assoc (downcase name
) ,var
)))
4109 (setq ,var
(cons (cons (downcase name
) name
) ,var
))
4113 (defun idlwave-reset-sintern-type (tag)
4114 "Reset the sintern variable associated with TAG."
4115 (set (intern (concat "idlwave-sint-" (symbol-name tag
) "s")) nil
))
4117 ;;---------------------------------------------------------------------------
4120 ;; The variables which hold the information
4121 (defvar idlwave-system-routines nil
4122 "Holds the routine-info obtained by scanning buffers.")
4123 (defvar idlwave-buffer-routines nil
4124 "Holds the routine-info obtained by scanning buffers.")
4125 (defvar idlwave-compiled-routines nil
4126 "Holds the routine-info obtained by asking the shell.")
4127 (defvar idlwave-unresolved-routines nil
4128 "Holds the unresolved routine-info obtained by asking the shell.")
4129 (defvar idlwave-library-routines nil
4130 "Holds the procedure routine-info from the library scan.")
4131 (defvar idlwave-path-alist nil
4132 "Alist with !PATH directories and a flag if the dir has been scanned.")
4133 (defvar idlwave-true-path-alist nil
4134 "Like `idlwave-path-alist', but with true filenames.")
4135 (defvar idlwave-routines nil
4136 "Holds the combinded procedure routine-info.")
4137 (defvar idlwave-class-alist nil
4138 "Holds the class names known to IDLWAVE.")
4139 (defvar idlwave-class-history nil
4140 "The history of classes selected with the minibuffer.")
4141 (defvar idlwave-force-class-query nil
)
4142 (defvar idlwave-before-completion-wconf nil
4143 "The window configuration just before the completion buffer was displayed.")
4144 (defvar idlwave-last-system-routine-info-cons-cell nil
4145 "The last cons cell in the system routine info.")
4148 ;; The code to get routine info from different sources.
4150 (defvar idlwave-system-routines
)
4151 (defvar idlwave-catalog-process nil
4152 "The background process currently updating the catalog.")
4154 (defun idlwave-routines ()
4155 "Provide a list of IDL routines.
4156 This routine loads the builtin routines on the first call. Later it
4157 only returns the value of the variable."
4158 (if (and idlwave-catalog-process
4159 (processp idlwave-catalog-process
))
4162 ((equal (process-status idlwave-catalog-process
) 'exit
)
4163 (message "updating........")
4164 (setq idlwave-catalog-process nil
)
4165 (idlwave-update-routine-info '(4)))
4166 ((equal (process-status idlwave-catalog-process
) 'run
)
4167 ;; Keep it running...
4170 ;; Something is wrong, get rid of the process
4171 (message "Problem with catalog process") (beep)
4173 (kill-process idlwave-catalog-process
)
4175 (setq idlwave-catalog-process nil
)))))
4176 (or idlwave-routines
4178 (idlwave-update-routine-info)
4179 ;; return the current value
4182 (defvar idlwave-update-rinfo-hook nil
4183 "List of functions which should run after a global rinfo update.
4184 Does not run after automatic updates of buffer or the shell.")
4186 (defun idlwave-rescan-catalog-directories ()
4187 "Rescan the previously selected directories. For batch processing."
4188 (idlwave-update-routine-info '(16)))
4190 (defun idlwave-rescan-asynchronously ()
4191 "Dispatch another emacs instance to update the idlwave catalog.
4192 After the process finishes normally, the first access to routine info
4193 will re-read the catalog."
4195 (if (processp idlwave-catalog-process
)
4196 (if (eq (process-status idlwave-catalog-process
) 'run
)
4197 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4200 (kill-process idlwave-catalog-process
)
4202 (error "Process killed, no new process started"))
4205 (kill-process idlwave-catalog-process
)
4207 (if (or (not idlwave-libinfo-file
)
4208 (not (stringp idlwave-libinfo-file
))
4209 (not (file-regular-p idlwave-libinfo-file
)))
4210 (error "No catalog has been produced yet"))
4211 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4212 (args (list "-batch"
4213 "-l" (expand-file-name "~/.emacs")
4215 "-f" "idlwave-rescan-catalog-directories"))
4216 (process (apply 'start-process
"idlcat"
4218 (setq idlwave-catalog-process process
)
4219 (set-process-sentinel
4222 (when (string-match "finished" why
)
4223 (setq idlwave-routines nil
4224 idlwave-system-routines nil
4225 idlwave-catalog-process nil
)
4226 (or (idlwave-start-load-rinfo-timer)
4227 (idlwave-update-routine-info '(4))))))
4228 (message "Background job started to update catalog file")))
4231 (defvar idlwave-load-rinfo-idle-timer
)
4232 (defun idlwave-update-routine-info (&optional arg
)
4233 "Update the internal routine-info lists.
4234 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4235 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4236 about individual routines.
4238 The information can come from 4 sources:
4239 1. IDL programs in the current editing session
4240 2. Compiled modules in an IDL shell running as Emacs subprocess
4241 3. A list which covers the IDL system routines.
4242 4. A list which covers the prescanned library files.
4244 Scans all IDLWAVE-mode buffers of the current editing session (see
4245 `idlwave-scan-all-buffers-for-routine-info').
4246 When an IDL shell is running, this command also queries the IDL program
4247 for currently compiled routines.
4249 With prefix ARG, also reload the system and library lists.
4250 With two prefix ARG's, also rescans the library tree.
4251 With three prefix args, dispatch asynchronous process to do the update."
4253 ;; Stop any idle processing
4254 (if (or (and (fboundp 'itimerp
)
4255 (itimerp idlwave-load-rinfo-idle-timer
))
4256 (and (fboundp 'timerp
)
4257 (timerp idlwave-load-rinfo-idle-timer
)))
4258 (cancel-timer idlwave-load-rinfo-idle-timer
))
4261 ;; Start a background process which updates the catalog.
4262 (idlwave-rescan-asynchronously))
4264 ;; Update the catalog now, and wait for it.
4265 (idlwave-create-libinfo-file t
))
4267 (let* ((load (or arg
4268 idlwave-buffer-case-takes-precedence
4269 (null idlwave-routines
)))
4270 ;; The override-idle means, even if the idle timer has done some
4271 ;; preparing work, load and renormalize everything anyway.
4272 (override-idle (or arg idlwave-buffer-case-takes-precedence
)))
4274 (setq idlwave-buffer-routines nil
4275 idlwave-compiled-routines nil
4276 idlwave-unresolved-routines nil
)
4277 ;; Reset the appropriate hashes
4278 (if (get 'idlwave-reset-sintern
'done-by-idle
)
4279 ;; reset was already done in idle time, so skip this step now once
4280 (put 'idlwave-reset-sintern
'done-by-idle nil
)
4281 (idlwave-reset-sintern (cond (load t
)
4282 ((null idlwave-system-routines
) t
)
4285 (if idlwave-buffer-case-takes-precedence
4286 ;; We can safely scan the buffer stuff first
4288 (idlwave-update-buffer-routine-info)
4289 (and load
(idlwave-load-system-rinfo override-idle
)))
4290 ;; We first do the system info, and then the buffers
4291 (and load
(idlwave-load-system-rinfo override-idle
))
4292 (idlwave-update-buffer-routine-info))
4294 ;; Let's see if there is a shell
4295 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running
)
4296 (idlwave-shell-is-running)))
4297 (ask-shell (and shell-is-running
4298 idlwave-query-shell-for-routine-info
)))
4300 (if (or (not ask-shell
)
4301 (not (interactive-p)))
4302 ;; 1. If we are not going to ask the shell, we need to do the
4303 ;; concatenation now.
4304 ;; 2. When this function is called non-interactively, it means
4305 ;; that someone needs routine info *now*. The shell update
4306 ;; causes the concatenation *delayed*, so not in time for
4307 ;; the current command. Therefore, we do a concatenation
4308 ;; now, even though the shell might do it again.
4309 (idlwave-concatenate-rinfo-lists nil t
))
4312 ;; Ask the shell about the routines it knows.
4313 (message "Querying the shell")
4314 (idlwave-shell-update-routine-info nil t
)))))))
4316 (defvar idlwave-load-rinfo-steps-done
(make-vector 5 nil
))
4317 (defvar idlwave-load-rinfo-idle-timer nil
)
4318 (defun idlwave-start-load-rinfo-timer ()
4319 (if (or (and (fboundp 'itimerp
)
4320 (itimerp idlwave-load-rinfo-idle-timer
))
4321 (and (fboundp 'timerp
)
4322 (timerp idlwave-load-rinfo-idle-timer
)))
4323 (cancel-timer idlwave-load-rinfo-idle-timer
))
4324 (setq idlwave-load-rinfo-steps-done
(make-vector 5 nil
))
4325 (setq idlwave-load-rinfo-idle-timer nil
)
4326 (if (and idlwave-init-rinfo-when-idle-after
4327 (numberp idlwave-init-rinfo-when-idle-after
)
4328 (not (equal 0 idlwave-init-rinfo-when-idle-after
))
4329 (not idlwave-routines
))
4332 (setq idlwave-load-rinfo-idle-timer
4333 (run-with-idle-timer
4334 idlwave-init-rinfo-when-idle-after
4335 nil
'idlwave-load-rinfo-next-step
)))
4340 (defun idlwave-load-rinfo-next-step ()
4341 (let ((inhibit-quit t
)
4342 (arr idlwave-load-rinfo-steps-done
))
4344 (when (not (aref arr
0))
4345 (message "Loading idlw-rinfo.el in idle time...")
4346 (load "idlw-rinfo" 'noerror
'nomessage
)
4347 (message "Loading idlw-rinfo.el in idle time...done")
4350 (when (not (aref arr
1))
4351 (message "Normalizing idlwave-system-routines in idle time...")
4352 (idlwave-reset-sintern t
)
4353 (put 'idlwave-reset-sintern
'done-by-idle t
)
4354 (setq idlwave-system-routines
4355 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4356 (message "Normalizing idlwave-system-routines in idle time...done")
4359 (when (not (aref arr
2))
4360 (when (and (stringp idlwave-libinfo-file
)
4361 (file-regular-p idlwave-libinfo-file
))
4364 (message "Loading library catalog in idle time...")
4365 (load-file idlwave-libinfo-file
)
4366 (message "Loading library catalog in idle time...done")
4369 (error (throw 'exit nil
)))))
4370 (when (not (aref arr
3))
4371 (when idlwave-library-routines
4372 (message "Normalizing idlwave-library-routines in idle time...")
4373 (setq idlwave-library-routines
(idlwave-sintern-rinfo-list
4374 idlwave-library-routines
'sys
))
4375 (message "Normalizing idlwave-library-routines in idle time...done"))
4378 (when (not (aref arr
4))
4379 (message "Finishing initialization in idle time...")
4381 (message "Finishing initialization in idle time...done")
4384 ;; restart the timer
4386 (idlwave-load-rinfo-next-step)
4387 (setq idlwave-load-rinfo-idle-timer
4388 (run-with-idle-timer
4389 idlwave-init-rinfo-when-idle-after
4390 nil
'idlwave-load-rinfo-next-step
)))
4393 (defun idlwave-load-system-rinfo (&optional force
)
4394 ;; Load and case-treat the system and lib info files.
4395 (when (or force
(not (aref idlwave-load-rinfo-steps-done
0)))
4396 (load "idlw-rinfo" 'noerror
'nomessage
))
4397 (when (or force
(not (aref idlwave-load-rinfo-steps-done
1)))
4398 (message "Normalizing idlwave-system-routines...")
4399 (setq idlwave-system-routines
4400 (idlwave-sintern-rinfo-list idlwave-system-routines
'sys
))
4401 (message "Normalizing idlwave-system-routines...done"))
4402 (setq idlwave-routines
(copy-sequence idlwave-system-routines
))
4403 (setq idlwave-last-system-routine-info-cons-cell
4404 (nthcdr (1- (length idlwave-routines
)) idlwave-routines
))
4405 (when (and (stringp idlwave-libinfo-file
)
4406 (file-regular-p idlwave-libinfo-file
))
4409 (when (or force
(not (aref idlwave-load-rinfo-steps-done
2)))
4410 (load-file idlwave-libinfo-file
))
4411 (setq idlwave-true-path-alist nil
)
4412 (when (or force
(not (aref idlwave-load-rinfo-steps-done
3)))
4413 (message "Normalizing idlwave-library-routines...")
4414 (setq idlwave-library-routines
(idlwave-sintern-rinfo-list
4415 idlwave-library-routines
'sys
))
4416 (message "Normalizing idlwave-library-routines...done")))
4419 (run-hooks 'idlwave-after-load-rinfo-hook
))
4422 (defun idlwave-update-buffer-routine-info ()
4425 ((eq idlwave-scan-all-buffers-for-routine-info t
)
4426 ;; Scan all buffers, current buffer last
4427 (message "Scanning all buffers...")
4428 (setq res
(idlwave-get-routine-info-from-buffers
4429 (reverse (buffer-list)))))
4430 ((null idlwave-scan-all-buffers-for-routine-info
)
4431 ;; Don't scan any buffers
4434 ;; Just scan this buffer
4435 (if (eq major-mode
'idlwave-mode
)
4437 (message "Scanning current buffer...")
4438 (setq res
(idlwave-get-routine-info-from-buffers
4439 (list (current-buffer))))))))
4440 ;; Put the result into the correct variable
4441 (setq idlwave-buffer-routines
4442 (idlwave-sintern-rinfo-list res t
))))
4444 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook
)
4445 "Put the different sources for routine information together."
4446 ;; The sequence here is important because earlier definitions shadow
4447 ;; later ones. We assume that if things in the buffers are newer
4448 ;; then in the shell of the system, it is meant to be different.
4450 (setcdr idlwave-last-system-routine-info-cons-cell
4451 (append idlwave-buffer-routines
4452 idlwave-compiled-routines
4453 idlwave-library-routines
))
4454 (setq idlwave-class-alist nil
)
4456 ;; Give a message with information about the number of routines we have.
4459 "Routine info updated: buffer(%d) compiled(%d) catalog(%d) system(%d)"
4460 (length idlwave-buffer-routines
)
4461 (length idlwave-compiled-routines
)
4462 (length idlwave-library-routines
)
4463 (length idlwave-system-routines
)))
4465 (run-hooks 'idlwave-update-rinfo-hook
)))
4467 (defun idlwave-class-alist ()
4468 "Return the class alist - make it if necessary."
4469 (or idlwave-class-alist
4471 (loop for x in idlwave-routines do
4472 (when (and (setq class
(nth 2 x
))
4473 (not (assq class idlwave-class-alist
)))
4474 (push (list class
) idlwave-class-alist
)))
4475 idlwave-class-alist
)))
4477 ;; Three functions for the hooks
4478 (defun idlwave-save-buffer-update ()
4479 (idlwave-update-current-buffer-info 'save-buffer
))
4480 (defun idlwave-kill-buffer-update ()
4481 (idlwave-update-current-buffer-info 'kill-buffer
))
4482 (defun idlwave-new-buffer-update ()
4483 (idlwave-update-current-buffer-info 'find-file
))
4485 (defun idlwave-update-current-buffer-info (why)
4486 "Undate idlwave-routines for current buffer. Can run from after-save-hook."
4487 (when (and (eq major-mode
'idlwave-mode
)
4488 (or (eq t idlwave-auto-routine-info-updates
)
4489 (memq why idlwave-auto-routine-info-updates
))
4490 idlwave-scan-all-buffers-for-routine-info
4494 (idlwave-replace-buffer-routine-info
4496 (if (eq why
'kill-buffer
)
4499 (idlwave-sintern-rinfo-list
4500 (idlwave-get-routine-info-from-buffers
4501 (list (current-buffer))) 'set
))))
4502 (idlwave-concatenate-rinfo-lists 'quiet
)
4506 (defun idlwave-replace-buffer-routine-info (file new
)
4507 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4508 (let ((list idlwave-buffer-routines
)
4511 ;; The following test uses eq to make sure it works correctly
4512 ;; when two buffers visit the same file. Then the file names
4513 ;; will be equal, but not eq.
4514 (if (eq (cdr (nth 3 (car list
))) file
)
4519 ;; End of that section reached. Jump.
4521 (setq list
(cdr list
)))
4522 (setq idlwave-buffer-routines
4523 (append new
(delq nil idlwave-buffer-routines
)))))
4525 ;;----- Scanning buffers -------------------
4527 (defun idlwave-get-routine-info-from-buffers (buffers)
4528 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4529 (let (buf routine-lists res
)
4531 (while (setq buf
(pop buffers
))
4533 (if (and (eq major-mode
'idlwave-mode
)
4535 ;; yes, this buffer has the right mode.
4536 (progn (setq res
(condition-case nil
4537 (idlwave-get-buffer-routine-info)
4539 (push res routine-lists
)))))
4540 ;; Concatenate the individual lists and return the result
4541 (apply 'nconc routine-lists
)))
4543 (defun idlwave-get-buffer-routine-info ()
4544 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4545 (let* ((case-fold-search t
)
4546 routine-list string entry
)
4550 (goto-char (point-min))
4551 (while (re-search-forward
4552 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t
)
4553 (setq string
(buffer-substring-no-properties
4556 (idlwave-end-of-statement)
4558 (setq entry
(idlwave-parse-definition string
))
4559 (push entry routine-list
))))
4562 (defvar idlwave-scanning-lib-dir
)
4563 (defun idlwave-parse-definition (string)
4564 "Parse a module definition."
4565 (let ((case-fold-search t
)
4566 start name args type keywords class
)
4568 (while (string-match ";.*" string
)
4569 (setq string
(replace-match "" t t string
)))
4570 ;; Remove the continuation line stuff
4571 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string
)
4572 (setq string
(replace-match "\\1 " t nil string
)))
4573 (while (string-match "\n" string
)
4574 (setq string
(replace-match " " t nil string
)))
4575 ;; Match the name and type.
4577 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string
)
4578 (setq start
(match-end 0))
4579 (setq type
(downcase (match-string 1 string
)))
4580 (if (match-beginning 3)
4581 (setq class
(match-string 3 string
)))
4582 (setq name
(match-string 4 string
)))
4583 ;; Match normal args and keyword args
4584 (while (string-match
4585 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4587 (setq start
(match-end 0))
4588 (if (match-beginning 3)
4589 (push (match-string 1 string
) keywords
)
4590 (push (match-string 1 string
) args
)))
4591 ;; Normalize and sort.
4592 (setq args
(nreverse args
))
4593 (setq keywords
(sort keywords
(lambda (a b
)
4594 (string< (downcase a
) (downcase b
)))))
4595 ;; Make and return the entry
4596 ;; We don't know which argument are optional, so this information
4597 ;; will not be contained in the calling sequence.
4599 (if (equal type
"pro") 'pro
'fun
)
4601 (cond ((not (boundp 'idlwave-scanning-lib
))
4602 (cons 'buffer
(buffer-file-name)))
4603 ; ((string= (downcase
4604 ; (file-name-sans-extension
4605 ; (file-name-nondirectory (buffer-file-name))))
4608 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4609 (t (cons 'lib
(concat idlwave-scanning-lib-dir
4610 (file-name-nondirectory (buffer-file-name))))))
4612 (if (string= type
"function") "Result = " "")
4613 (if class
"Obj ->[%s::]" "")
4617 (if (string= type
"function") "(" ", ")
4618 (mapconcat 'identity args
", ")
4619 (if (string= type
"function") ")" ""))))
4621 (mapcar 'list keywords
)
4624 ;;----- Scanning the library -------------------
4626 (defvar idlwave-sys-dir nil
4627 "Internal variable.")
4629 (defun idlwave-sys-dir ()
4630 "Return the syslib directory, or a dummy that never matches."
4634 (defvar idlwave-shell-path-query
)
4635 (defun idlwave-create-libinfo-file (&optional arg
)
4636 "Scan all files on selected dirs of IDL search path for routine information.
4637 A widget checklist will allow you to choose the directories.
4638 Write the result as a file `idlwave-libinfo-file'. When this file exists,
4639 will be automatically loaded to give routine information about library
4641 With ARG, just rescan the same directories as last time - so no widget
4644 ;; Make sure the file is loaded if it exists.
4645 (if (and (stringp idlwave-libinfo-file
)
4646 (file-regular-p idlwave-libinfo-file
))
4648 (load-file idlwave-libinfo-file
)
4650 ;; Make sure the file name makes sense
4651 (unless (and (stringp idlwave-libinfo-file
)
4652 (> (length idlwave-libinfo-file
) 0)
4653 (file-accessible-directory-p
4654 (file-name-directory idlwave-libinfo-file
))
4655 (not (string= "" (file-name-nondirectory
4656 idlwave-libinfo-file
))))
4657 (error "`idlwave-libinfo-file' does not point to file in accessible directory"))
4660 ((and arg idlwave-path-alist
4661 (consp (car idlwave-path-alist
))
4663 ;; Rescan the known directories
4664 (idlwave-scan-lib-files
4666 idlwave-path-alist
))
4667 (idlwave-library-path
4668 ;; Get the directories from that variable
4669 (idlwave-display-libinfo-widget
4670 idlwave-system-directory
4671 (idlwave-expand-path idlwave-library-path
)
4672 (delq nil
(mapcar (lambda (x) (if (consp x
) (if (cdr x
) (car x
) nil
) x
))
4673 idlwave-path-alist
))))
4675 ;; Ask the shell for the path and run the widget
4676 (message "Asking the shell for IDL path...")
4677 (require 'idlw-shell
)
4678 (idlwave-shell-send-command idlwave-shell-path-query
4679 '(idlwave-libinfo-command-hook nil
)
4682 (defun idlwave-libinfo-command-hook (&optional arg
)
4683 ;; Command hook used by `idlwave-create-libinfo-file'.
4686 (idlwave-scan-lib-files
4689 ;; Display the widget
4690 (let* ((rpl (idlwave-shell-path-filter))
4693 (idlwave-display-libinfo-widget
4695 (delq nil
(mapcar (lambda (x) (if (cdr x
) (car x
) nil
))
4696 idlwave-path-alist
))))))
4698 (defconst idlwave-libinfo-widget-help-string
4699 "This is the front-end to the creation of IDLWAVE library catalog.
4700 Please select below the directories on IDL's search path from which you
4701 would like to extract routine information, which will be stored in the file
4705 If this is not the correct file, first set variable `idlwave-libinfo-file'.
4706 Then call this command again.
4708 For writing code, you need to include the directories which contain the
4709 routines you use. If IDLWAVE should be able to analyse routine shadowing
4710 it is best to scan all directories.
4712 After selecting the directories, choose [Scan & Save] to scan the library
4713 directories and save the routine info.
4716 (defvar idlwave-widget
)
4717 (defvar widget-keymap
)
4718 (defun idlwave-display-libinfo-widget (sysdir dirs selected-dirs
)
4719 "Create the widget to select IDL search path directories for scanning."
4724 (error "Don't know IDL's search path"))
4726 ;; Allow only those directories to be selected which are in the path.
4727 (setq selected-dirs
(delq nil
(mapcar (lambda (x)
4728 (if (member x dirs
) x nil
))
4730 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4731 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4732 (kill-all-local-variables)
4733 (make-local-variable 'idlwave-widget
)
4734 (widget-insert (format idlwave-libinfo-widget-help-string
4735 idlwave-libinfo-file
))
4737 (widget-create 'push-button
4738 :notify
'idlwave-widget-scan-lib-files
4741 (widget-create 'push-button
4742 :notify
(lambda (&rest ignore
)
4743 (kill-buffer (current-buffer)))
4746 (widget-create 'push-button
4747 :notify
'idlwave-delete-libinfo-file
4750 (widget-create 'push-button
4751 :notify
'(lambda (&rest ignore
)
4752 (idlwave-display-libinfo-widget
4753 (widget-get idlwave-widget
:sysdir
)
4754 (widget-get idlwave-widget
:path-dirs
)
4755 (widget-get idlwave-widget
:path-dirs
)))
4758 (widget-create 'push-button
4759 :notify
'(lambda (&rest ignore
)
4760 (idlwave-display-libinfo-widget
4761 (widget-get idlwave-widget
:sysdir
)
4762 (widget-get idlwave-widget
:path-dirs
)
4765 (widget-insert "\n\n")
4767 (widget-insert "Select Directories\n")
4769 (setq idlwave-widget
4770 (apply 'widget-create
4772 :value selected-dirs
4774 :tag
"List of directories"
4775 (mapcar (lambda (x) (list 'item x
)) dirs
)))
4776 (widget-put idlwave-widget
:path-dirs dirs
)
4777 (widget-put idlwave-widget
:sysdir sysdir
)
4778 (widget-insert "\n")
4779 (use-local-map widget-keymap
)
4781 (goto-char (point-min))
4782 (delete-other-windows))
4784 (defun idlwave-delete-libinfo-file (&rest ignore
)
4786 (format "Delete file %s " idlwave-libinfo-file
))
4788 (delete-file idlwave-libinfo-file
)
4789 (message "%s has been deleted" idlwave-libinfo-file
))))
4791 (defun idlwave-widget-scan-lib-files (&rest ignore
)
4792 ;; Call `idlwave-scan-lib-files' with data taken from the widget.
4793 (let* ((widget idlwave-widget
)
4794 (selected-dirs (widget-value widget
))
4795 (sysdir (widget-get widget
:sysdir
))
4796 (path-dirs (widget-get widget
:path-dirs
))
4798 (mapcar (lambda (x) (cons x
(if (member x selected-dirs
) t nil
)))
4800 (idlwave-scan-lib-files sysdir path-dir-alist
)))
4802 (defvar font-lock-mode
)
4803 (defun idlwave-scan-lib-files (sysdir path-alist
)
4804 ;; Scan the files in PATH-ALIST and store the info in a file
4805 (let* ((idlwave-scanning-lib t
)
4806 (idlwave-scanning-lib-dir "")
4807 (dircnt (1+ (length path-alist
)))
4808 (idlwave-completion-case nil
)
4809 dirs-alist dir files file
)
4810 (setq idlwave-library-routines nil
)
4811 (setq idlwave-path-alist path-alist
)
4812 (setq idlwave-true-path-alist nil
)
4813 (setq idlwave-sys-dir sysdir
)
4815 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
4817 (setq dirs-alist
(reverse path-alist
))
4818 (while (setq dir
(pop dirs-alist
))
4821 ;; Has the flag of scanned directories
4822 (setq dir
(car dir
))
4823 (setq idlwave-scanning-lib-dir
(format "{%d}/" dircnt
))
4824 (when (file-directory-p dir
)
4825 (setq files
(directory-files dir
'full
"\\.[pP][rR][oO]\\'"))
4826 (while (setq file
(pop files
))
4827 (when (file-regular-p file
)
4828 (if (not (file-readable-p file
))
4829 (message "Skipping %s (no read permission)" file
)
4830 (message "Scanning %s..." file
)
4832 (insert-file-contents file
'visit
)
4833 (setq idlwave-library-routines
4834 (append (idlwave-get-routine-info-from-buffers
4835 (list (current-buffer)))
4836 idlwave-library-routines
)))
4838 ;; Sorting is not necessary since we sort each time before a routine
4839 ;; is used. So we don't do it here - the catalog file looks nicer
4840 ;; when it is unsorted.
4841 ;;(message "Sorting...")
4842 ;;(setq idlwave-library-routines
4843 ;;(sort idlwave-library-routines 'idlwave-routine-entry-compare))
4844 ;;(message "Sorting...done")
4845 (message "Creating libinfo file...")
4846 (kill-buffer "*idlwave-scan.pro*")
4847 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4848 (let ((font-lock-maximum-size 0)
4849 (auto-mode-alist nil
))
4850 (find-file idlwave-libinfo-file
))
4851 (if (and (boundp 'font-lock-mode
)
4855 (insert ";; IDLWAVE libinfo file\n")
4856 (insert (format ";; Created %s\n\n" (current-time-string)))
4858 ;; Define the variable which knows the value of "!DIR"
4859 (insert (format "\n(setq idlwave-sys-dir \"%s\")\n"
4862 ;; Define the variable which contains a list of all scanned directories
4863 (insert "\n(setq idlwave-path-alist\n '(")
4865 (insert (format "\n (\"%s\" . %s)" (car x
) (cdr x
))))
4869 ;; Define the routine info list
4870 (insert "\n(setq idlwave-library-routines\n '(")
4871 (let ((standard-output (current-buffer)))
4875 (goto-char (point-max)))
4876 ; (insert (with-output-to-string (prin1 x))))
4877 idlwave-library-routines
))
4878 (insert (format "))\n\n;;; %s ends here\n"
4879 (file-name-nondirectory idlwave-libinfo-file
)))
4880 (goto-char (point-min))
4883 (kill-buffer (current-buffer)))
4884 (message "Creating libinfo file...done")
4885 (message "Info for %d routines saved in %s"
4886 (length idlwave-library-routines
)
4887 idlwave-libinfo-file
)
4889 (idlwave-update-routine-info t
))
4891 (defun idlwave-expand-path (path &optional default-dir
)
4892 ;; Expand parts of path starting with '+' recursively into directory list.
4893 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
4894 (message "Expanding path...")
4895 (let (path1 dir recursive
)
4896 (while (setq dir
(pop path
))
4897 (if (setq recursive
(string= (substring dir
0 1) "+"))
4898 (setq dir
(substring dir
1)))
4900 (not (file-name-absolute-p dir
)))
4901 (setq dir
(expand-file-name dir default-dir
)))
4903 ;; Expand recursively
4904 (setq path1
(append (idlwave-recursive-directory-list dir
) path1
))
4907 (message "Expanding path...done")
4910 (defun idlwave-recursive-directory-list (dir)
4911 ;; Return a list of all directories below DIR, including DIR itself
4912 (let ((path (list dir
)) path1 file files
)
4913 (while (setq dir
(pop path
))
4914 (when (file-directory-p dir
)
4915 (setq files
(nreverse (directory-files dir t
"[^.]")))
4916 (while (setq file
(pop files
))
4917 (if (file-directory-p file
)
4918 (push (file-name-as-directory file
) path
)))
4922 ;;----- Asking the shell -------------------
4924 ;; First, here is the idl program which can be used to query IDL for
4925 ;; defined routines.
4926 (defconst idlwave-routine-info.pro
4928 ;; START OF IDLWAVE SUPPORT ROUTINES
4929 pro idlwave_print_info_entry,name,func=func,separator=sep
4930 ;; See if it's an object method
4931 if name eq '' then return
4932 func = keyword_set(func)
4933 methsep = strpos(name,'::')
4934 meth = methsep ne -1
4937 pars = routine_info(name,/parameters,functions=func)
4938 source = routine_info(name,/source,functions=func)
4939 nargs = pars.num_args
4940 nkw = pars.num_kw_args
4941 if nargs gt 0 then args = pars.args
4942 if nkw gt 0 then kwargs = pars.kw_args
4944 ;; Trim the class, and make the name
4946 class = strmid(name,0,methsep)
4947 name = strmid(name,methsep+2,strlen(name)-1)
4948 if nargs gt 0 then begin
4949 ;; remove the self argument
4950 wh = where(args ne 'SELF',nargs)
4951 if nargs gt 0 then args = args(wh)
4954 ;; No class, just a normal routine.
4960 if func then cs = 'Result = '
4961 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
4963 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
4964 if nargs gt 0 then begin
4965 for j=0,nargs-1 do begin
4967 if j lt nargs-1 then cs = cs + ', '
4970 if func then cs = cs + ')'
4971 ;; Keyword arguments
4973 if nkw gt 0 then begin
4974 for j=0,nkw-1 do begin
4975 kwstring = kwstring + ' ' + kwargs(j)
4979 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])(func)
4981 print,ret + ': ' + name + sep + class + sep + source(0).path $
4982 + sep + cs + sep + kwstring
4985 pro idlwave_routine_info
4987 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
4988 all = routine_info()
4989 for i=0,n_elements(all)-1 do $
4990 idlwave_print_info_entry,all(i),separator=sep
4991 all = routine_info(/functions)
4992 for i=0,n_elements(all)-1 do $
4993 idlwave_print_info_entry,all(i),/func,separator=sep
4994 print,'>>>END OF IDLWAVE ROUTINE INFO'
4997 pro idlwave_get_sysvars
4998 forward_function strjoin,strtrim,strsplit
5000 if error_status ne 0 then begin
5001 print, 'Cannot get info about system variables'
5003 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5004 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5005 v = strsplit(s,' +',/regex,/extract) ; get variables
5006 for i=0,n_elements(v)-1 do begin
5007 t = [''] ; get tag list
5008 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5009 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5014 pro idlwave_get_class_tags, class
5015 res = execute('tags=tag_names({'+class+'})')
5016 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5018 ;; END OF IDLWAVE SUPPORT ROUTINES
5020 "The idl programs to get info from the shell.")
5022 (defvar idlwave-idlwave_routine_info-compiled nil
5023 "Remembers if the routine info procedure is already compiled.")
5025 (defvar idlwave-shell-temp-pro-file
)
5026 (defvar idlwave-shell-temp-rinfo-save-file
)
5027 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks preempt
)
5028 "Query the shell for routine_info of compiled modules and update the lists."
5029 ;; Save and compile the procedure. The compiled procedure is then
5030 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5031 ;; We need to RESTORE the procedure each time we use it, since
5032 ;; the user may have killed or redefined it. In particular,
5033 ;; .RESET_SESSION will kill all user procedures.
5034 (unless (and idlwave-idlwave_routine_info-compiled
5035 (file-readable-p (idlwave-shell-temp-file 'rinfo
)))
5037 (set-buffer (idlwave-find-file-noselect
5038 (idlwave-shell-temp-file 'pro
)))
5040 (insert idlwave-routine-info.pro
)
5042 (idlwave-shell-send-command
5043 (concat ".run " idlwave-shell-temp-pro-file
)
5045 ; (message "SENDING SAVE") ; ????????????????????????
5046 (idlwave-shell-send-command
5047 (format "save,'idlwave_routine_info','idlwave_print_info_entry',FILE='%s',/ROUTINES"
5048 (idlwave-shell-temp-file 'rinfo
))
5051 ;; Restore and execute the procedure, analyze the output
5052 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5053 (idlwave-shell-send-command
5054 (format "RESTORE, '%s' & idlwave_routine_info"
5055 idlwave-shell-temp-rinfo-save-file
)
5057 (idlwave-shell-routine-info-filter)
5058 (idlwave-concatenate-rinfo-lists ,quiet
,run-hooks
))
5061 ;; ---------------------------------------------------------------------------
5063 ;; Completion and displaying routine calling sequences
5065 (defvar idlwave-completion-help-info nil
)
5066 (defvar idlwave-current-obj_new-class nil
)
5067 (defvar idlwave-complete-special nil
)
5069 (defun idlwave-complete (&optional arg module class
)
5070 "Complete a function, procedure or keyword name at point.
5071 This function is smart and figures out what can be legally completed
5073 - At the beginning of a statement it completes procedure names.
5074 - In the middle of a statement it completes function names.
5075 - after a `(' or `,' in the argument list of a function or procedure,
5076 it completes a keyword of the relevant function or procedure.
5077 - In the first arg of `OBJ_NEW', it completes a class name.
5079 When several completions are possible, a list will be displayed in the
5080 *Completions* buffer. If this list is too long to fit into the
5081 window, scrolling can be achieved by repeatedly pressing
5082 \\[idlwave-complete].
5084 The function also knows about object methods. When it needs a class
5085 name, the action depends upon `idlwave-query-class', which see. You
5086 can force IDLWAVE to ask you for a class name with a
5087 \\[universal-argument] prefix argument to this command.
5089 See also the variables `idlwave-keyword-completion-adds-equal' and
5090 `idlwave-function-completion-adds-paren'.
5092 The optional ARG can be used to specify the completion type in order
5093 to override IDLWAVE's idea of what should be completed at point.
5094 Possible values are:
5096 0 <=> query for the completion type
5098 2 <=> 'procedure-keyword
5100 4 <=> 'function-keyword
5101 5 <=> 'procedure-method
5102 6 <=> 'procedure-method-keyword
5103 7 <=> 'function-method
5104 8 <=> 'function-method-keyword
5107 As a special case, the universal argument C-u forces completion of
5108 function names in places where the default would be a keyword.
5110 For Lisp programmers only:
5111 When we force a keyword, optional argument MODULE can contain the module name.
5112 When we force a method or a method keyword, CLASS can specify the class."
5119 (idlwave-make-force-complete-where-list arg module class
)
5121 (what (nth 2 where-list
))
5122 (idlwave-force-class-query (equal arg
'(4))))
5124 (if (and module
(string-match "::" module
))
5125 (setq class
(substring module
0 (match-beginning 0))
5126 module
(substring module
(match-end 0))))
5131 (eq (car-safe last-command
) 'idlwave-display-completion-list
)
5132 (get-buffer-window "*Completions*"))
5133 (setq this-command last-command
)
5134 (idlwave-scroll-completions))
5136 ;; Check for any special completion functions
5137 ((and idlwave-complete-special
5138 (idlwave-call-special idlwave-complete-special
)))
5140 ((and (idlwave-in-quote)
5141 (not (eq what
'class
)))
5142 (idlwave-complete-filename))
5145 (error "Nothing to complete here"))
5148 (setq idlwave-completion-help-info
'(class))
5149 (idlwave-complete-class))
5151 ((eq what
'procedure
)
5152 ;; Complete a procedure name
5153 (let* ((cw-list (nth 3 where-list
))
5154 (class-selector (idlwave-determine-class cw-list
'pro
))
5155 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5156 (idlwave-all-class-inherits class-selector
)))
5157 (isa (concat "procedure" (if class-selector
"-method" "")))
5158 (type-selector 'pro
))
5159 (setq idlwave-completion-help-info
5160 (list 'routine nil type-selector class-selector nil super-classes
))
5161 (idlwave-complete-in-buffer
5162 'procedure
(if class-selector
'method
'routine
)
5163 (idlwave-routines) 'idlwave-selector
5164 (format "Select a %s name%s"
5167 (format " (class is %s)"
5168 (if (eq class-selector t
)
5169 "unknown" class-selector
))
5172 'idlwave-attach-method-classes
)))
5174 ((eq what
'function
)
5175 ;; Complete a function name
5176 (let* ((cw-list (nth 3 where-list
))
5177 (class-selector (idlwave-determine-class cw-list
'fun
))
5178 (super-classes (unless (idlwave-explicit-class-listed cw-list
)
5179 (idlwave-all-class-inherits class-selector
)))
5180 (isa (concat "function" (if class-selector
"-method" "")))
5181 (type-selector 'fun
))
5182 (setq idlwave-completion-help-info
5183 (list 'routine nil type-selector class-selector nil super-classes
))
5184 (idlwave-complete-in-buffer
5185 'function
(if class-selector
'method
'routine
)
5186 (idlwave-routines) 'idlwave-selector
5187 (format "Select a %s name%s"
5190 (format " (class is %s)"
5191 (if (eq class-selector t
)
5192 "unknown" class-selector
))
5195 'idlwave-attach-method-classes
)))
5197 ((and (memq what
'(procedure-keyword function-keyword
))
5199 (idlwave-complete 3))
5201 ((eq what
'procedure-keyword
)
5202 ;; Complete a procedure keyword
5203 (let* ((where (nth 3 where-list
))
5205 (method-selector name
)
5206 (type-selector 'pro
)
5207 (class (idlwave-determine-class where
'pro
))
5208 (class-selector class
)
5209 (super-classes (idlwave-all-class-inherits class-selector
))
5210 (isa (format "procedure%s-keyword" (if class
"-method" "")))
5211 (entry (idlwave-best-rinfo-assq
5212 name
'pro class
(idlwave-routines)))
5213 (list (nth 5 entry
)))
5214 (unless (or entry
(eq class t
))
5215 (error "Nothing known about procedure %s"
5216 (idlwave-make-full-name class name
)))
5217 (setq list
(idlwave-fix-keywords name
'pro class list
))
5218 (unless list
(error (format "No keywords available for procedure %s"
5219 (idlwave-make-full-name class name
))))
5220 (setq idlwave-completion-help-info
5221 (list 'keyword name type-selector class-selector nil super-classes
))
5222 (idlwave-complete-in-buffer
5223 'keyword
'keyword list nil
5224 (format "Select keyword for procedure %s%s"
5225 (idlwave-make-full-name class name
)
5226 (if (or (member '("_EXTRA") list
)
5227 (member '("_REF_EXTRA") list
))
5228 " (note _EXTRA)" ""))
5230 'idlwave-attach-keyword-classes
)))
5232 ((eq what
'function-keyword
)
5233 ;; Complete a function keyword
5234 (let* ((where (nth 3 where-list
))
5236 (method-selector name
)
5237 (type-selector 'fun
)
5238 (class (idlwave-determine-class where
'fun
))
5239 (class-selector class
)
5240 (super-classes (idlwave-all-class-inherits class-selector
))
5241 (isa (format "function%s-keyword" (if class
"-method" "")))
5242 (entry (idlwave-best-rinfo-assq
5243 name
'fun class
(idlwave-routines)))
5244 (list (nth 5 entry
))
5246 (unless (or entry
(eq class t
))
5247 (error "Nothing known about function %s"
5248 (idlwave-make-full-name class name
)))
5249 (setq list
(idlwave-fix-keywords name
'fun class list
))
5250 ;; OBJ_NEW: Messages mention the proper Init method
5251 (setq msg-name
(if (and (null class
)
5252 (string= (upcase name
) "OBJ_NEW"))
5253 (concat idlwave-current-obj_new-class
5254 "::Init (via OBJ_NEW)")
5255 (idlwave-make-full-name class name
)))
5256 (unless list
(error (format "No keywords available for function %s"
5258 (setq idlwave-completion-help-info
5259 (list 'keyword name type-selector class-selector nil super-classes
))
5260 (idlwave-complete-in-buffer
5261 'keyword
'keyword list nil
5262 (format "Select keyword for function %s%s" msg-name
5263 (if (or (member '("_EXTRA") list
)
5264 (member '("_REF_EXTRA") list
))
5265 " (note _EXTRA)" ""))
5267 'idlwave-attach-keyword-classes
)))
5269 (t (error "This should not happen (idlwave-complete)")))))
5271 (defvar idlwave-complete-special nil
5272 "List of special completion functions.
5273 These functions are called for each completion. Each function must check
5274 if its own special completion context is present. If yes, it should
5275 use `idlwave-complete-in-buffer' to do some completion and return `t'.
5276 If such a function returns `t', *no further* attempts to complete
5277 other contexts will be done. If the function returns `nil', other completions
5280 (defun idlwave-call-special (functions &rest args
)
5281 (let ((funcs functions
)
5284 (while (setq fun
(pop funcs
))
5285 (if (setq ret
(apply fun args
))
5289 (defun idlwave-make-force-complete-where-list (what &optional module class
)
5290 ;; Return an artificial WHERE specification to force the completion
5291 ;; routine to complete a specific item independent of context.
5292 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5293 ;; MODULE and CLASS can be used to specify the routine name and class.
5294 ;; The class name will also be found in MODULE if that is like "class::mod".
5295 (let* ((what-list '(("procedure") ("procedure-keyword")
5296 ("function") ("function-keyword")
5297 ("procedure-method") ("procedure-method-keyword")
5298 ("function-method") ("function-method-keyword")
5300 (module (idlwave-sintern-routine-or-method module class
))
5301 (class (idlwave-sintern-class class
))
5305 (intern (completing-read
5306 "Complete what? " what-list nil t
))))
5308 (setq what
(intern (car (nth (1- what
) what-list
)))))
5311 (assoc (symbol-name what
) what-list
))
5313 (t (error "Illegal WHAT"))))
5314 (nil-list '(nil nil nil nil
))
5315 (class-list (list nil nil
(or class t
) nil
)))
5319 ((eq what
'procedure
)
5320 (list nil-list nil-list
'procedure nil-list nil
))
5322 ((eq what
'procedure-keyword
)
5323 (let* ((class-selector nil
)
5325 (type-selector 'pro
)
5327 (idlwave-completing-read
5328 "Procedure: " (idlwave-routines) 'idlwave-selector
))))
5329 (setq pro
(idlwave-sintern-routine pro
))
5330 (list nil-list nil-list
'procedure-keyword
5331 (list pro nil nil nil
) nil
)))
5333 ((eq what
'function
)
5334 (list nil-list nil-list
'function nil-list nil
))
5336 ((eq what
'function-keyword
)
5337 (let* ((class-selector nil
)
5339 (type-selector 'fun
)
5341 (idlwave-completing-read
5342 "Function: " (idlwave-routines) 'idlwave-selector
))))
5343 (setq func
(idlwave-sintern-routine func
))
5344 (list nil-list nil-list
'function-keyword
5345 (list func nil nil nil
) nil
)))
5347 ((eq what
'procedure-method
)
5348 (list nil-list nil-list
'procedure class-list nil
))
5350 ((eq what
'procedure-method-keyword
)
5351 (let* ((class (idlwave-determine-class class-list
'pro
))
5352 (class-selector class
)
5353 (super-classes (idlwave-all-class-inherits class-selector
))
5354 (type-selector 'pro
)
5356 (idlwave-completing-read
5357 (format "Procedure in %s class: " class-selector
)
5358 (idlwave-routines) 'idlwave-selector
))))
5359 (setq pro
(idlwave-sintern-method pro
))
5360 (list nil-list nil-list
'procedure-keyword
5361 (list pro nil class nil
) nil
)))
5363 ((eq what
'function-method
)
5364 (list nil-list nil-list
'function class-list nil
))
5366 ((eq what
'function-method-keyword
)
5367 (let* ((class (idlwave-determine-class class-list
'fun
))
5368 (class-selector class
)
5369 (super-classes (idlwave-all-class-inherits class-selector
))
5370 (type-selector 'fun
)
5372 (idlwave-completing-read
5373 (format "Function in %s class: " class-selector
)
5374 (idlwave-routines) 'idlwave-selector
))))
5375 (setq func
(idlwave-sintern-method func
))
5376 (list nil-list nil-list
'function-keyword
5377 (list func nil class nil
) nil
)))
5380 (list nil-list nil-list
'class nil-list nil
))
5382 (t (error "Illegal value for WHAT")))))
5384 (defun idlwave-completing-read (&rest args
)
5385 ;; Completing read, case insensitive
5386 (let ((old-value (default-value 'completion-ignore-case
)))
5389 (setq-default completion-ignore-case t
)
5390 (apply 'completing-read args
))
5391 (setq-default completion-ignore-case old-value
))))
5393 (defvar idlwave-shell-default-directory
)
5394 (defun idlwave-complete-filename ()
5395 "Use the comint stuff to complete a file name."
5397 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5398 (comint-completion-addsuffix nil
)
5400 (if (and (boundp 'idlwave-shell-default-directory
)
5401 (stringp idlwave-shell-default-directory
)
5402 (file-directory-p idlwave-shell-default-directory
))
5403 idlwave-shell-default-directory
5404 default-directory
)))
5405 (comint-dynamic-complete-filename)))
5407 (defun idlwave-make-full-name (class name
)
5408 ;; Make a fully qualified module name including the class name
5409 (concat (if class
(format "%s::" class
) "") name
))
5411 (defun idlwave-rinfo-assoc (name type class list
)
5412 "Like `idlwave-rinfo-assq', but sintern strings first."
5414 (idlwave-sintern-routine-or-method name class
)
5415 type
(idlwave-sintern-class class
) list
))
5417 (defun idlwave-rinfo-assq (name type class list
)
5418 ;; Works like assq, but also checks type and class
5421 (while (setq match
(assq name list
))
5422 (and (or (eq type t
)
5423 (eq (nth 1 match
) type
))
5424 (eq (nth 2 match
) class
)
5425 (throw 'exit match
))
5426 (setq list
(cdr (memq match list
)))))))
5428 (defun idlwave-rinfo-assq-any-class (name type class list
)
5429 (let* ((classes (cons class
(idlwave-all-class-inherits class
)))
5432 (if (setq rtn
(idlwave-rinfo-assq name type
(pop classes
) list
))
5433 (setq classes nil
)))
5436 (defun idlwave-best-rinfo-assq (name type class list
)
5437 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first."
5438 (let ((twins (idlwave-routine-twins
5439 (idlwave-rinfo-assq-any-class name type class list
)
5442 (when (> (length twins
) 1)
5443 (setq twins
(sort twins
'idlwave-routine-entry-compare-twins
))
5444 (if (and (eq 'system
(car (nth 3 (car twins
))))
5445 (setq syslibp
(idlwave-any-syslib (cdr twins
)))
5446 (not (equal 1 syslibp
)))
5447 ;; Its a syslib, so we need to remove the system entry
5448 (setq twins
(cdr twins
))))
5451 (defun idlwave-best-rinfo-assoc (name type class list
)
5452 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5453 (idlwave-best-rinfo-assq
5454 (idlwave-sintern-routine-or-method name class
)
5455 type
(idlwave-sintern-class class
) list
))
5457 (defun idlwave-any-syslib (entries)
5458 "Does the entry list ENTRIES contain a syslib entry?
5459 If yes, return the index (>=1)."
5464 (setq file
(cdr (nth 3 (car entries
))))
5467 (idlwave-expand-lib-file-name file
)))
5469 (setq entries
(cdr entries
))))
5472 (defun idlwave-all-assq (key list
)
5473 "Return a list of all associations of Key in LIST."
5475 (while (setq elt
(assq key list
))
5477 (setq list
(cdr (memq elt list
))))
5480 (defun idlwave-all-method-classes (method &optional type
)
5481 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5482 When TYPE is not specified, both procedures and functions will be considered."
5484 (mapcar 'car
(idlwave-class-alist))
5489 (eq type
(nth 1 x
)))
5490 (push (nth 2 x
) rtn
)))
5491 (idlwave-all-assq method
(idlwave-routines)))
5492 (idlwave-uniquify rtn
))))
5494 (defun idlwave-all-method-keyword-classes (method keyword
&optional type
)
5495 "Return all classes which have a method METHOD with keyword KEYWORD.
5496 TYPE is 'fun or 'pro.
5497 When TYPE is not specified, both procedures and functions will be considered."
5498 (if (or (null method
)
5505 (eq type
(nth 1 x
)))
5506 (assoc keyword
(nth 5 x
))
5507 (push (nth 2 x
) rtn
)))
5508 (idlwave-all-assq method
(idlwave-routines)))
5509 (idlwave-uniquify rtn
))))
5511 (defun idlwave-members-only (list club
)
5512 "Return list of all elements in LIST which are also in CLUB."
5515 (if (member (car list
) club
)
5516 (setq rtn
(cons (car list
) rtn
)))
5517 (setq list
(cdr list
)))
5520 (defun idlwave-nonmembers-only (list club
)
5521 "Return list of all elements in LIST which are not in CLUB."
5524 (if (member (car list
) club
)
5526 (setq rtn
(cons (car list
) rtn
)))
5527 (setq list
(cdr list
)))
5530 (defun idlwave-explicit-class-listed (info)
5531 "Return whether or not the class is listed explicitly, ala a->b::c.
5532 INFO is as returned by idlwave-what-function or -procedure."
5533 (let ((apos (nth 3 info
)))
5535 (save-excursion (goto-char apos
)
5536 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5538 (defvar idlwave-determine-class-special nil
5539 "List of special functions for determining class.
5540 Must accept two arguments: `apos' and `info'")
5542 (defun idlwave-determine-class (info type
)
5543 ;; Determine the class of a routine call.
5544 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5545 ;; The second element in this structure is the class. When nil, we
5546 ;; return nil. When t, try to get the class from text properties at
5547 ;; the arrow. When the object is "self", we use the class of the
5548 ;; current routine. otherwise prompt the user for a class name.
5549 ;; Also stores the selected class as a text property at the arrow.
5550 ;; TYPE is 'fun or 'pro.
5551 (let* ((class (nth 2 info
))
5553 (nassoc (assoc (if (stringp (car info
))
5556 idlwave-query-class
))
5557 (dassoc (assq (if (car info
) 'keyword-default
'method-default
)
5558 idlwave-query-class
))
5559 (query (cond (nassoc (cdr nassoc
))
5560 (dassoc (cdr dassoc
))
5562 (arrow (and apos
(string= (buffer-substring apos
(+ 2 apos
)) "->")))
5565 (save-excursion (goto-char apos
)
5567 (let ((case-fold-search t
))
5568 (looking-at "self\\>")))))
5569 (force-query idlwave-force-class-query
)
5570 store special-class class-alist
)
5574 ;; There is an object which would like to know its class
5575 (if (and arrow
(get-text-property apos
'idlwave-class
)
5576 idlwave-store-inquired-class
5578 (setq class
(get-text-property apos
'idlwave-class
)
5579 class
(idlwave-sintern-class class
)))
5580 (if (and (eq t class
) is-self
)
5581 (setq class
(or (nth 2 (idlwave-current-routine)) class
)))
5583 ;; Before prompting, try any special class determination routines
5584 (when (and (eq t class
)
5585 idlwave-determine-class-special
5588 (idlwave-call-special idlwave-determine-class-special apos
))
5590 (setq class
(idlwave-sintern-class special-class
)
5591 store idlwave-store-inquired-class
)))
5593 ;; Prompt for a class, if we need to
5594 (when (and (eq class t
)
5595 (or force-query query
))
5597 (mapcar 'list
(idlwave-all-method-classes (car info
) type
)))
5599 (idlwave-sintern-class
5601 ((and (= (length class-alist
) 0) (not force-query
))
5602 (error "No classes available with method %s" (car info
)))
5603 ((and (= (length class-alist
) 1) (not force-query
))
5604 (car (car class-alist
)))
5606 (setq store idlwave-store-inquired-class
)
5607 (idlwave-completing-read
5608 (format "Class%s: " (if (stringp (car info
))
5609 (format " for %s method %s"
5612 class-alist nil nil nil
'idlwave-class-history
))))))
5614 ;; Store it, if requested
5615 (when (and class
(not (eq t class
)))
5616 ;; We have a real class here
5617 (when (and store arrow
)
5619 (add-text-properties
5621 `(idlwave-class ,class face
,idlwave-class-arrow-face
5624 (setf (nth 2 info
) class
))
5627 ;; Default as fallback
5630 (defvar type-selector
)
5631 (defvar class-selector
)
5632 (defvar method-selector
)
5633 (defvar super-classes
)
5634 (defun idlwave-selector (a)
5635 (and (eq (nth 1 a
) type-selector
)
5636 (or (and (nth 2 a
) (eq class-selector t
))
5637 (eq (nth 2 a
) class-selector
)
5638 (memq (nth 2 a
) super-classes
)
5641 (defun idlwave-where ()
5642 "Find out where we are.
5643 The return value is a list with the following stuff:
5644 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5646 PRO-LIST (PRO POINT CLASS ARROW)
5647 FUNC-LIST (FUNC POINT CLASS ARROW)
5648 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5649 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5651 LAST-CHAR last relevant character before point (non-white non-comment,
5652 not part of current identifier or leading slash).
5654 In the lists, we have these meanings:
5657 POINT: Where is this
5658 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5659 ARROW: Location of the arrow"
5661 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5662 (bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
5663 (func-entry (idlwave-what-function bos
))
5664 (func (car func-entry
))
5665 (func-class (nth 1 func-entry
))
5666 (func-arrow (nth 2 func-entry
))
5667 (func-point (or (nth 3 func-entry
) 0))
5668 (func-level (or (nth 4 func-entry
) 0))
5669 (pro-entry (idlwave-what-procedure bos
))
5670 (pro (car pro-entry
))
5671 (pro-class (nth 1 pro-entry
))
5672 (pro-arrow (nth 2 pro-entry
))
5673 (pro-point (or (nth 3 pro-entry
) 0))
5674 (last-char (idlwave-last-valid-char))
5675 (case-fold-search t
)
5676 cw cw-mod cw-arrow cw-class cw-point
)
5677 (if (< func-point pro-point
) (setq func nil
))
5679 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
5680 (buffer-substring bos
(point)))
5683 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
5684 (buffer-substring (if (> pro-point
0) pro-point bos
) (point)))
5685 (setq cw
'procedure cw-class pro-class cw-point pro-point
5686 cw-arrow pro-arrow
))
5687 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
5688 (buffer-substring bos
(point)))
5690 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
5691 (buffer-substring bos
(point)))
5693 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
5694 (buffer-substring bos
(point)))
5697 (> func-point pro-point
)
5699 (memq last-char
'(?\
( ?
,)))
5700 (setq cw
'function-keyword cw-mod func cw-point func-point
5701 cw-class func-class cw-arrow func-arrow
))
5702 ((and pro
(eq last-char ?
,))
5703 (setq cw
'procedure-keyword cw-mod pro cw-point pro-point
5704 cw-class pro-class cw-arrow pro-arrow
))
5705 ; ((member last-char '(?\' ?\) ?\] ?!))
5706 ; ;; after these chars, a function makes no sense
5707 ; ;; FIXME: I am sure there can be more in this list
5708 ; ;; FIXME: Do we want to do this at all?
5710 ;; Everywhere else we try a function.
5714 (if (re-search-backward "->[ \t]*\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t
)
5715 (setq cw-arrow
(copy-marker (match-beginning 0))
5716 cw-class
(if (match-end 2)
5717 (idlwave-sintern-class (match-string 2))
5719 (list (list pro pro-point pro-class pro-arrow
)
5720 (list func func-point func-class func-arrow
)
5722 (list cw-mod cw-point cw-class cw-arrow
)
5725 (defun idlwave-this-word (&optional class
)
5726 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
5727 (setq class
(or class
"a-zA-Z0-9$_"))
5729 (buffer-substring-no-properties
5730 (progn (skip-chars-backward class
) (point))
5731 (progn (skip-chars-forward class
) (point)))))
5733 (defun idlwave-what-function (&optional bound
)
5734 ;; Find out if point is within the argument list of a function.
5735 ;; The return value is ("function-name" class arrow-start (point) level).
5736 ;; Level is 1 on the top level parentheses, higher further down.
5738 ;; If the optional BOUND is an integer, bound backwards directed
5739 ;; searches to this point.
5745 func arrow-start class
)
5746 (idlwave-with-special-syntax
5749 (narrow-to-region (max 1 (or bound
0)) (point-max))
5750 ;; move back out of the current parenthesis
5751 (while (condition-case nil
5752 (progn (up-list -
1) t
)
5756 (when (and (= (following-char) ?\
()
5758 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
5760 (setq func
(match-string 2)
5761 func-point
(goto-char (match-beginning 2))
5763 (if (re-search-backward
5764 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t
)
5765 (setq arrow-start
(copy-marker (match-beginning 0))
5766 class
(or (match-string 2) t
)))
5770 (idlwave-sintern-routine-or-method func class
)
5771 (idlwave-sintern-class class
)
5772 arrow-start func-point cnt
)))
5774 (throw 'exit nil
)))))))
5776 (defun idlwave-what-procedure (&optional bound
)
5777 ;; Find out if point is within the argument list of a procedure.
5778 ;; The return value is ("procedure-name" class arrow-pos (point)).
5780 ;; If the optional BOUND is an integer, bound backwards directed
5781 ;; searches to this point.
5782 (let ((pos (point)) pro-point
5783 pro class arrow-start string
)
5785 ;;(idlwave-beginning-of-statement)
5786 (idlwave-start-of-substatement 'pre
)
5787 (setq string
(buffer-substring (point) pos
))
5789 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string
)
5790 (setq pro
(match-string 1 string
)
5791 pro-point
(+ (point) (match-beginning 1)))
5792 (if (and (idlwave-skip-object)
5793 (setq string
(buffer-substring (point) pos
))
5795 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\'\\)" string
))
5796 (setq pro
(if (match-beginning 4)
5797 (match-string 4 string
))
5798 pro-point
(if (match-beginning 4)
5799 (+ (point) (match-beginning 4))
5801 arrow-start
(copy-marker (+ (point) (match-beginning 1)))
5802 class
(or (match-string 3 string
) t
)))))
5803 (list (idlwave-sintern-routine-or-method pro class
)
5804 (idlwave-sintern-class class
)
5808 (defun idlwave-skip-object ()
5809 ;; If there is an object at point, move over it and return t.
5810 (let ((pos (point)))
5813 (skip-chars-forward " ") ; white space
5814 (skip-chars-forward "*") ; de-reference
5816 ((looking-at idlwave-identifier
)
5817 (goto-char (match-end 0)))
5818 ((eq (following-char) ?\
()
5820 (t (throw 'exit nil
)))
5823 (cond ((eq (following-char) ?.
)
5825 (if (not (looking-at idlwave-identifier
))
5827 (goto-char (match-end 0)))
5828 ((memq (following-char) '(?\
( ?\
[))
5831 (error (throw 'exit nil
))))
5832 (t (throw 'endwhile t
)))))
5833 (if (looking-at "[ \t]*->")
5834 (throw 'exit
(setq pos
(match-beginning 0)))
5835 (throw 'exit nil
))))
5839 (defun idlwave-last-valid-char ()
5840 "Return the last character before point which is not white or a comment
5841 and also not part of the current identifier. Since we do this in
5842 order to identify places where keywords are, we consider the initial
5843 `/' of a keyword as part of the identifier.
5844 This function is not general, can only be used for completion stuff."
5847 ;; skip the current identifier
5848 (skip-chars-backward "a-zA-Z0-9_$")
5849 ;; also skip a leading slash which might be belong to the keyword
5850 (if (eq (preceding-char) ?
/)
5852 ;; FIXME: does not check if this is a valid identifier
5854 (skip-chars-backward " \t")
5856 ((memq (preceding-char) '(?\
; ?\$)) (throw 'exit nil))
5857 ((eq (preceding-char) ?
\n)
5858 (beginning-of-line 0)
5859 (if (looking-at "\\([^;\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
5860 ;; continuation line
5861 (goto-char (match-end 1))
5863 (t (throw 'exit
(preceding-char))))))))
5865 (defvar idlwave-complete-after-success-form nil
5866 "A form to evaluate after successful completion.")
5867 (defvar idlwave-complete-after-success-form-force nil
5868 "A form to evaluate after completion selection in *Completions* buffer.")
5869 (defconst idlwave-completion-mark
(make-marker)
5870 "A mark pointing to the beginning of the completion string.")
5872 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
5873 &optional prepare-display-function
)
5874 "Perform TYPE completion of word before point against LIST.
5875 SELECTOR is the PREDICATE argument for the completion function. Show
5876 PROMPT in echo area. TYPE is one of 'function, 'procedure,
5877 'class-tag, or 'keyword."
5878 (let* ((completion-ignore-case t
)
5879 beg
(end (point)) slash part spart completion all-completions
5883 (error (concat prompt
": No completions available")))
5885 ;; What is already in the buffer?
5887 (skip-chars-backward "a-zA-Z0-9_$")
5888 (setq slash
(eq (preceding-char) ?
/)
5890 idlwave-complete-after-success-form
5891 (list 'idlwave-after-successful-completion
5892 (list 'quote type
) slash beg
)
5893 idlwave-complete-after-success-form-force
5894 (list 'idlwave-after-successful-completion
5895 (list 'quote type
) slash
(list 'quote
'force
))))
5898 (setq part
(buffer-substring beg end
)
5899 dpart
(downcase part
)
5900 spart
(idlwave-sintern stype part
)
5901 completion
(try-completion part list selector
)
5902 dcompletion
(if (stringp completion
) (downcase completion
)))
5905 ;; nothing available.
5906 (error (concat prompt
": no completion for \"%s\"") part
))
5907 ((and (not (equal dpart dcompletion
))
5908 (not (eq t completion
)))
5909 ;; We can add something
5910 (delete-region beg end
)
5911 (if (and (string= part dpart
)
5912 (or (not (string= part
""))
5913 idlwave-complete-empty-string-as-lower-case
)
5914 (not idlwave-completion-force-default-case
))
5915 (insert dcompletion
)
5916 (insert completion
))
5917 (if (eq t
(try-completion completion list selector
))
5918 ;; Now this is a unique match
5919 (idlwave-after-successful-completion type slash beg
))
5921 ((or (eq completion t
)
5922 (and (equal dpart dcompletion
)
5923 (= 1 (length (setq all-completions
5925 (all-completions part list selector
)))))))
5926 ;; This is already complete
5927 (idlwave-after-successful-completion type slash beg
)
5928 (message "%s is already the complete %s" part isa
)
5931 ;; We cannot add something - offer a list.
5932 (message "Making completion list...")
5933 (let* ((list all-completions
)
5934 ;; "complete" means, this is already a valid completion
5935 (complete (memq spart all-completions
))
5936 (completion-highlight-first-word-only t
) ; XEmacs
5937 (completion-fixup-function ; Emacs
5938 (lambda () (and (eq (preceding-char) ?
>)
5939 (re-search-backward " <" beg t
)))))
5940 (setq list
(sort list
(lambda (a b
)
5941 (string< (downcase a
) (downcase b
)))))
5942 (if prepare-display-function
5943 (setq list
(funcall prepare-display-function list
)))
5944 (if (and (string= part dpart
)
5945 (or (not (string= part
""))
5946 idlwave-complete-empty-string-as-lower-case
)
5947 (not idlwave-completion-force-default-case
))
5948 (setq list
(mapcar (lambda (x)
5950 (setcar x
(downcase (car x
)))
5951 (setq x
(downcase x
)))
5954 (idlwave-display-completion-list list prompt beg complete
))
5957 (defun idlwave-complete-class ()
5958 "Complete a class at point."
5960 ;; Call `idlwave-routines' to make sure the class list will be available
5962 ;; Check for the special case of completing empty string after pro/function
5963 (if (let ((case-fold-search t
))
5966 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
5968 (goto-char (point-min))
5970 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t
))))
5971 ;; Yank the full class specification
5972 (insert (match-string 2))
5973 ;; Do the completion
5974 (idlwave-complete-in-buffer 'class
'class
(idlwave-class-alist) nil
5975 "Select a class" "class")))
5977 (defun idlwave-attach-classes (list type show-classes
)
5978 ;; Attach the proper class list to a LIST of completion items.
5979 ;; TYPE, when 'kwd, shows classes for method keywords, when
5980 ;; 'class-tag, for class tags, and otherwise for methods.
5981 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
5982 (if (or (null show-classes
) ; don't want to see classes
5983 (null class-selector
) ; not a method call
5985 (stringp class-selector
) ; the class is already known
5986 (not super-classes
))) ; no possibilities for inheritance
5987 ;; In these cases, we do not have to do anything
5989 (let* ((do-prop (and (>= show-classes
0)
5990 (>= emacs-major-version
21)))
5991 (do-buf (not (= show-classes
0)))
5992 ;; (do-dots (featurep 'xemacs))
5994 (inherit (if (and (not (eq type
'class-tag
)) super-classes
)
5995 (cons class-selector super-classes
)))
5996 (max (abs show-classes
))
5997 (lmax (if do-dots
(apply 'max
(mapcar 'length list
))))
5998 classes nclasses class-info space
)
6002 (if (eq type
'class-tag
)
6003 ;; Just one class for tags
6006 (idlwave-class-or-superclass-with-tag class-selector x
)))
6007 ;; Multiple classes for method of method-keyword
6010 (idlwave-all-method-keyword-classes
6011 method-selector x type-selector
)
6012 (idlwave-all-method-classes x type-selector
)))
6016 (mapcar (lambda (x) (if (memq x inherit
) x nil
))
6018 (setq nclasses
(length classes
))
6019 ;; Make the separator between item and class-info
6021 (setq space
(concat " " (make-string (- lmax
(length x
)) ?.
)))
6024 ;; We do want info in the buffer
6025 (if (<= nclasses max
)
6026 (setq class-info
(concat
6028 "<" (mapconcat 'identity classes
",") ">"))
6029 (setq class-info
(format "%s<%d classes>" space nclasses
)))
6030 (setq class-info nil
))
6032 ;; We do want properties
6033 (setq x
(copy-sequence x
))
6034 (put-text-property 0 (length x
)
6035 'help-echo
(mapconcat 'identity classes
" ")
6042 (defun idlwave-attach-method-classes (list)
6043 ;; Call idlwave-attach-classes with method parameters
6044 (idlwave-attach-classes list
'method idlwave-completion-show-classes
))
6045 (defun idlwave-attach-keyword-classes (list)
6046 ;; Call idlwave-attach-classes with keyword parameters
6047 (idlwave-attach-classes list
'kwd idlwave-completion-show-classes
))
6048 (defun idlwave-attach-class-tag-classes (list)
6049 ;; Call idlwave-attach-classes with class structure tags
6050 (idlwave-attach-classes list
'class-tag idlwave-completion-show-classes
))
6053 ;;----------------------------------------------------------------------
6054 ;;----------------------------------------------------------------------
6055 ;;----------------------------------------------------------------------
6056 ;;----------------------------------------------------------------------
6057 ;;----------------------------------------------------------------------
6059 (defun idlwave-pset (item)
6062 (defun idlwave-popup-select (ev list title
&optional sort
)
6063 "Select an item in LIST with a popup menu.
6064 TITLE is the title to put atop the popup. If SORT is non-nil,
6065 sort the list before displaying"
6066 (let ((maxpopup idlwave-max-popup-menu-items
)
6069 ((= 1 (length list
))
6070 (setq rtn
(car list
)))
6072 (if sort
(setq list
(sort list
(lambda (a b
)
6073 (string< (upcase a
) (upcase b
))))))
6075 (append (list title
)
6076 (mapcar (lambda (x) (vector x
(list 'idlwave-pset
6079 (setq menu
(idlwave-split-menu-xemacs menu maxpopup
))
6080 (setq resp
(get-popup-menu-response menu
))
6081 (funcall (event-function resp
) (event-object resp
)))
6083 (if sort
(setq list
(sort list
(lambda (a b
)
6084 (string< (upcase a
) (upcase b
))))))
6085 (setq menu
(cons title
6088 (mapcar (lambda(x) (cons x x
)) list
)))))
6089 (setq menu
(idlwave-split-menu-emacs menu maxpopup
))
6090 (setq rtn
(x-popup-menu ev menu
))))
6093 (defun idlwave-split-menu-xemacs (menu N
)
6094 "Split the MENU into submenus of maximum length N."
6095 (if (<= (length menu
) (1+ N
))
6096 ;; No splitting needed
6098 (let* ((title (car menu
))
6099 (entries (cdr menu
))
6104 (while (and entries
(< cnt N
))
6106 nextmenu
(cons (car entries
) nextmenu
)
6107 entries
(cdr entries
)))
6108 (setq nextmenu
(nreverse nextmenu
))
6109 (setq nextmenu
(cons (format "%s...%s"
6110 (aref (car nextmenu
) 0)
6111 (aref (nth (1- cnt
) nextmenu
) 0))
6113 (setq menu
(cons nextmenu menu
)
6118 (defun idlwave-split-menu-emacs (menu N
)
6119 "Split the MENU into submenus of maximum length N."
6120 (if (<= (length (nth 1 menu
)) (1+ N
))
6121 ;; No splitting needed
6123 (let* ((title (car menu
))
6124 (entries (cdr (nth 1 menu
)))
6129 (while (and entries
(< cnt N
))
6131 nextmenu
(cons (car entries
) nextmenu
)
6132 entries
(cdr entries
)))
6133 (setq nextmenu
(nreverse nextmenu
))
6135 (setq nextmenu
(cons (format "%s...%s"
6136 (car (car nextmenu
))
6137 (car (nth (1- cnt
) nextmenu
)))
6139 (setq menu
(cons nextmenu menu
)
6142 (setq menu
(nreverse menu
))
6143 (setq menu
(cons title menu
))
6146 (defvar idlwave-completion-setup-hook nil
)
6148 (defun idlwave-scroll-completions (&optional message
)
6149 "Scroll the completion window on this frame."
6150 (let ((cwin (get-buffer-window "*Completions*" 'visible
))
6151 (win (selected-window)))
6154 (select-window cwin
)
6157 (error (if (and (listp last-command
)
6158 (nth 2 last-command
))
6161 (eval idlwave-complete-after-success-form
))
6162 (set-window-start cwin
(point-min)))))
6163 (and message
(message message
)))
6164 (select-window win
))))
6166 (defun idlwave-display-completion-list (list &optional message beg complete
)
6167 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6168 (unless (and (get-buffer-window "*Completions*")
6169 (idlwave-local-value 'idlwave-completion-p
"*Completions*"))
6170 (move-marker idlwave-completion-mark beg
)
6171 (setq idlwave-before-completion-wconf
(current-window-configuration)))
6173 (if (featurep 'xemacs
)
6174 (idlwave-display-completion-list-xemacs
6176 (idlwave-display-completion-list-emacs list
))
6178 ;; Store a special value in `this-command'. When `idlwave-complete'
6179 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6180 (setq this-command
(list 'idlwave-display-completion-list message complete
))
6182 ;; Mark the completions buffer as created by cib
6183 (idlwave-set-local 'idlwave-completion-p t
"*Completions*")
6185 ;; Fontify the classes
6186 (if (and idlwave-completion-fontify-classes
6188 (idlwave-completion-fontify-classes))
6191 (run-hooks 'idlwave-completion-setup-hook
)
6193 ;; Display the message
6194 (message (or message
"Making completion list...done")))
6196 (defun idlwave-choose (function &rest args
)
6197 "Call FUNCTION as a completion chooser and pass ARGS to it."
6198 (let ((completion-ignore-case t
)) ; install correct value
6199 (apply function args
))
6200 (if (and (eq major-mode
'idlwave-shell-mode
)
6201 (boundp 'font-lock-mode
)
6202 (not font-lock-mode
))
6203 ;; Remove the fontification of the word before point
6204 (let ((beg (save-excursion
6205 (skip-chars-backward "a-zA-Z0-9_")
6207 (remove-text-properties beg
(point) '(face nil
))))
6208 (eval idlwave-complete-after-success-form-force
))
6210 (defun idlwave-keyboard-quit ()
6213 (if (eq (car-safe last-command
) 'idlwave-display-completion-list
)
6214 (idlwave-restore-wconf-after-completion))
6217 (defun idlwave-restore-wconf-after-completion ()
6218 "Restore the old (before completion) window configuration."
6219 (and idlwave-completion-restore-window-configuration
6220 idlwave-before-completion-wconf
6221 (set-window-configuration idlwave-before-completion-wconf
)))
6223 (defun idlwave-set-local (var value
&optional buffer
)
6224 "Set the buffer-local value of VAR in BUFFER to VALUE."
6226 (set-buffer (or buffer
(current-buffer)))
6227 (set (make-local-variable var
) value
)))
6229 (defun idlwave-local-value (var &optional buffer
)
6230 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6232 (set-buffer (or buffer
(current-buffer)))
6233 (and (local-variable-p var
(current-buffer))
6234 (symbol-value var
))))
6236 ;; In XEmacs, we can use :activate-callback directly to advice the
6237 ;; choose functions. We use the private keymap only for the online
6240 (defvar idlwave-completion-map nil
6241 "Keymap for completion-list-mode with idlwave-complete.")
6243 (defun idlwave-display-completion-list-xemacs (list &rest cl-args
)
6244 (with-output-to-temp-buffer "*Completions*"
6245 (apply 'display-completion-list list
6246 ':activate-callback
'idlwave-default-choose-completion
6249 (set-buffer "*Completions*")
6251 (or idlwave-completion-map
6252 (setq idlwave-completion-map
6253 (idlwave-make-modified-completion-map-xemacs
6254 (current-local-map)))))))
6256 (defun idlwave-default-choose-completion (&rest args
)
6257 "Execute `default-choose-completion' and then restore the win-conf."
6258 (apply 'idlwave-choose
'default-choose-completion args
))
6260 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6261 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6262 (let ((new-map (copy-keymap old-map
)))
6263 (define-key new-map
[button3up] 'idlwave-mouse-completion-help)
6264 (define-key new-map [button3] (lambda ()
6266 (setq this-command last-command)))
6269 ;; In Emacs we also replace keybindings in the completion
6270 ;; map in order to install our wrappers.
6272 (defun idlwave-display-completion-list-emacs (list)
6273 "Display completion list and install the choose wrappers."
6274 (with-output-to-temp-buffer "*Completions*"
6275 (display-completion-list list))
6277 (set-buffer "*Completions*")
6279 (or idlwave-completion-map
6280 (setq idlwave-completion-map
6281 (idlwave-make-modified-completion-map-emacs
6282 (current-local-map)))))))
6284 (defun idlwave-make-modified-completion-map-emacs (old-map)
6285 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6286 (let ((new-map (copy-keymap old-map)))
6287 (substitute-key-definition
6288 'choose-completion 'idlwave-choose-completion new-map)
6289 (substitute-key-definition
6290 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6291 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6294 (defun idlwave-choose-completion (&rest args)
6295 "Choose the completion that point is in or next to."
6297 (apply 'idlwave-choose 'choose-completion args))
6299 (defun idlwave-mouse-choose-completion (&rest args)
6300 "Click on an alternative in the `*Completions*' buffer to choose it."
6302 (apply 'idlwave-choose 'mouse-choose-completion args))
6304 ;;----------------------------------------------------------------------
6305 ;;----------------------------------------------------------------------
6307 ;;; ------------------------------------------------------------------------
6308 ;;; Sturucture parsing code, and code to manage class info
6311 ;; - Go again over the documentation how to write a completion
6312 ;; plugin. It is in self.el, but currently still very bad.
6313 ;; This could be in a separate file in the distribution, or
6314 ;; in an appendix for the manual.
6316 (defun idlwave-struct-tags ()
6317 "Return a list of all tags in the structure defined at point.
6318 Point is expected just before the opening `{' of the struct definition."
6320 (let* ((borders (idlwave-struct-borders))
6325 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)[ \t]*:" end t)
6326 ;; Check if we are still on the top level of the structure.
6327 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6329 (push (match-string 5) tags))
6330 (goto-char (match-end 0)))
6333 (defun idlwave-find-struct-tag (tag)
6334 "Find a given TAG in the structure defined at point."
6335 (let* ((borders (idlwave-struct-borders))
6338 (case-fold-search t))
6339 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
6342 (defun idlwave-struct-inherits ()
6343 "Return a list of all `inherits' names in the struct at point.
6344 Point is expected just before the opening `{' of the struct definition."
6346 (let* ((borders (idlwave-struct-borders))
6349 (case-fold-search t)
6352 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n[ \t]*\\)?inherits[ \t]*\\(\\$.*\n[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)" end t)
6353 ;; Check if we are still on the top level of the structure.
6354 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6356 (push (match-string 3) names))
6357 (goto-char (match-end 0)))
6360 (defun idlwave-in-structure ()
6361 "Return t if point is inside an IDL structure."
6362 (let ((beg (point)))
6364 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6365 (if (idlwave-find-structure-definition nil nil 'back)
6366 (let ((borders (idlwave-struct-borders)))
6367 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6368 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6370 (defun idlwave-struct-borders ()
6371 "Return the borders of the {...} after point as a cons cell."
6374 (skip-chars-forward "^{")
6376 (condition-case nil (forward-list 1)
6377 (error (goto-char beg)))
6378 (cons beg (point)))))
6380 (defun idlwave-find-structure-definition (&optional var name bound)
6381 "Search forward for a structure definition.
6382 If VAR is non-nil, search for a structure assigned to variable VAR.
6383 If NAME is non-nil, search for a named structure NAME. If BOUND is an
6384 integer, limit the search. If BOUND is the symbol `all', we search
6385 first back and then forward through the entire file. If BOUND is the
6386 symbol `back' we search only backward."
6387 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
6388 (case-fold-search t)
6389 (lim (if (integerp bound) bound nil))
6392 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6395 (if name (concat ws "\\<" (downcase name) "[^a-zA-Z0-9_$]") ""))))
6396 (if (or (and (or (eq bound 'all) (eq bound 'back))
6397 (re-search-backward re nil t))
6398 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6399 (goto-char (match-beginning 3)))))
6401 (defvar idlwave-class-info nil)
6402 (defvar idlwave-system-class-info nil)
6403 (add-hook 'idlwave-update-rinfo-hook
6404 (lambda () (setq idlwave-class-info nil)))
6405 (add-hook 'idlwave-after-load-rinfo-hook
6406 (lambda () (setq idlwave-class-info nil)))
6408 (defun idlwave-class-info (class)
6410 (unless idlwave-class-info
6411 ;; Info is nil, put in the system stuff.
6412 (setq idlwave-class-info idlwave-system-class-info)
6413 (setq list idlwave-class-info)
6414 (while (setq entry (pop list))
6415 (idlwave-sintern-class-info entry)))
6416 (setq class (idlwave-sintern-class class))
6417 (setq entry (assq class idlwave-class-info))
6419 (setq entry (idlwave-find-class-info class))
6421 ;; Sintern and cache the info
6422 (idlwave-sintern-class-info entry)
6423 (push entry idlwave-class-info)))
6426 (defun idlwave-sintern-class-info (entry)
6427 "Sintern the class names in a class-info entry."
6428 (let ((taglist (assq 'tags entry))
6429 (inherits (assq 'inherits entry)))
6430 (setcar entry (idlwave-sintern-class (car entry) 'set))
6432 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6435 (defun idlwave-find-class-definition (class)
6436 (let ((case-fold-search t))
6437 (if (re-search-forward
6438 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6439 ;; FIXME: should we limit to end of pro here?
6440 (idlwave-find-structure-definition nil class))))
6442 (defun idlwave-find-class-info (class)
6443 "Find the __define procedure for a class structure and return info entry."
6444 (let* ((pro (concat (downcase class) "__define"))
6445 (class (idlwave-sintern-class class))
6446 (idlwave-auto-routine-info-updates nil)
6447 (file (cdr (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6448 (idlwave-routines)))))
6451 (not (file-regular-p
6452 (setq file (idlwave-expand-lib-file-name file)))))
6453 nil ; Cannot get info
6455 (if (setq buf (idlwave-get-buffer-visiting file))
6457 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6459 (unless (eq major-mode 'idlwave-mode)
6461 (insert-file-contents file))
6464 (if (idlwave-find-class-definition class)
6466 (cons 'tags (idlwave-struct-tags))
6467 (cons 'inherits (idlwave-struct-inherits)))))))))
6469 (defun idlwave-class-tags (class)
6470 "Return the native tags in CLASS."
6471 (cdr (assq 'tags (idlwave-class-info class))))
6472 (defun idlwave-class-inherits (class)
6473 "Return the direct superclasses of CLASS."
6474 (cdr (assq 'inherits (idlwave-class-info class))))
6476 (defun idlwave-all-class-tags (class)
6477 "Return a list of native and inherited tags in CLASS."
6479 (apply 'append (mapcar 'idlwave-class-tags
6480 (cons class (idlwave-all-class-inherits class))))
6482 (idlwave-class-tag-reset)
6483 (error "%s" (error-message-string err)))))
6486 (defun idlwave-all-class-inherits (class)
6487 "Return a list of all superclasses of CLASS (recursively expanded).
6488 The list is cached in `idlwave-class-info' for faster access."
6490 ((not idlwave-support-inheritance) nil)
6491 ((eq class nil) nil)
6494 (let ((info (idlwave-class-info class))
6496 (if (setq entry (assq 'all-inherits info))
6498 ;; Save the depth of inheritance scan to check for circular references
6499 (let ((inherits (mapcar (lambda (x) (cons x 0))
6500 (idlwave-class-inherits class)))
6501 rtn all-inherits cl)
6503 (setq cl (pop inherits)
6504 rtn (cons (car cl) rtn)
6505 inherits (append (mapcar (lambda (x)
6506 (cons x (1+ (cdr cl))))
6507 (idlwave-class-inherits (car cl)))
6509 (if (> (cdr cl) 999)
6511 "Class scan: inheritance depth exceeded. Circular inheritance?")
6513 (setq all-inherits (nreverse rtn))
6514 (nconc info (list (cons 'all-inherits all-inherits)))
6518 ;;==========================================================================
6520 ;; Completing class structure tags. This is a completion plugin.
6521 ;; The necessary taglist is constructed dynamically
6523 (defvar idlwave-current-tags-class nil)
6524 (defvar idlwave-current-class-tags nil)
6525 (defvar idlwave-current-native-class-tags nil)
6526 (defvar idlwave-sint-class-tags nil)
6527 (idlwave-new-sintern-type 'class-tag)
6528 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
6529 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
6531 (defun idlwave-complete-class-structure-tag ()
6532 "Complete a structure tag on a `self' argument in an object method."
6535 (case-fold-search t))
6537 ;; Check if the context is right
6538 (skip-chars-backward "[a-zA-Z0-9._$]")
6539 (and (< (point) (- pos 4))
6540 (looking-at "self\\.")))
6541 (let* ((class-selector (nth 2 (idlwave-current-routine)))
6542 (super-classes (idlwave-all-class-inherits class-selector)))
6543 ;; Check if we are in a class routine
6544 (unless class-selector
6545 (error "Not in a method procedure or function"))
6546 ;; Check if we need to update the "current" class
6547 (if (not (equal class-selector idlwave-current-tags-class))
6548 (idlwave-prepare-class-tag-completion class-selector))
6549 (setq idlwave-completion-help-info
6550 (list 'idlwave-complete-class-structure-tag-help
6551 (idlwave-sintern-routine
6552 (concat class-selector "__define"))
6554 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
6555 (idlwave-complete-in-buffer
6556 'class-tag 'class-tag
6557 idlwave-current-class-tags nil
6558 (format "Select a tag of class %s" class-selector)
6560 'idlwave-attach-class-tag-classes))
6561 t) ; return t to skip other completions
6564 (defun idlwave-class-tag-reset ()
6565 (setq idlwave-current-tags-class nil))
6567 (defun idlwave-prepare-class-tag-completion (class)
6568 "Find and parse the necessary class definitions for class structure tags."
6569 (setq idlwave-sint-class-tags nil)
6570 (setq idlwave-current-tags-class class)
6571 (setq idlwave-current-class-tags
6573 (list (idlwave-sintern-class-tag x 'set)))
6574 (idlwave-all-class-tags class)))
6575 (setq idlwave-current-native-class-tags
6576 (mapcar 'downcase (idlwave-class-tags class))))
6578 ;===========================================================================
6580 ;; Completing system variables and their structure fields
6581 ;; This is also a plugin. It is a bit bigger since we support loading
6582 ;; current system variables from the shell and highlighting in the
6583 ;; completions buffer.
6585 (defvar idlwave-sint-sysvars nil)
6586 (defvar idlwave-sint-sysvartags nil)
6587 (idlwave-new-sintern-type 'sysvar)
6588 (idlwave-new-sintern-type 'sysvartag)
6589 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
6590 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
6591 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-remember-builtin-sysvars)
6592 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
6594 (defvar idlwave-system-variables-alist nil
6595 "Alist of system variables and the associated structure tags.
6596 Gets set in `idlw-rinfo.el'.")
6597 (defvar idlwave-builtin-system-variables nil)
6599 (defun idlwave-complete-sysvar-or-tag ()
6600 "Complete a system variable."
6603 (case-fold-search t))
6604 (cond ((save-excursion
6605 ;; Check if the context is right for system variable
6606 (skip-chars-backward "[a-zA-Z0-9_$]")
6607 (equal (char-before) ?!))
6608 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
6609 (idlwave-complete-in-buffer 'sysvar 'sysvar
6610 idlwave-system-variables-alist nil
6611 "Select a system variable"
6613 t) ; return t to skip other completions
6615 ;; Check if the context is right for sysvar tag
6616 (skip-chars-backward "[a-zA-Z0-9_$.]")
6617 (and (equal (char-before) ?!)
6618 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
6619 (<= (match-end 0) pos)))
6620 ;; Complete a system variable tag
6621 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
6622 (entry (assq var idlwave-system-variables-alist))
6624 (or entry (error "!%s is not know to be a system variable" var))
6625 (or tags (error "System variable !%s is not a structure" var))
6626 (setq idlwave-completion-help-info
6627 (list 'idlwave-complete-sysvar-help var))
6628 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
6630 "Select a system variable tag"
6631 "system variable tag")
6632 t)) ; return t to skip other completions
6635 ;; Here we fake help using the routine "system variables" with keyword
6636 ;; set to the sysvar. Name and kwd are global variables here.
6639 (defun idlwave-complete-sysvar-help (mode word)
6642 (or (and (eq nil (nth 1 idlwave-completion-help-info))
6643 (member (downcase word) idlwave-builtin-system-variables))
6644 (and (stringp (nth 1 idlwave-completion-help-info))
6645 (member (downcase (nth 1 idlwave-completion-help-info))
6646 idlwave-builtin-system-variables))))
6648 (setq name "system variables"
6650 (if (stringp (nth 1 idlwave-completion-help-info))
6651 (nth 1 idlwave-completion-help-info)
6653 (t (error "This should not happen"))))
6655 ;; Fake help in the source buffer for class structure tags.
6656 ;; kwd and name are global-variables here.
6657 (defvar idlwave-help-do-class-struct-tag nil)
6658 (defun idlwave-complete-class-structure-tag-help (mode word)
6660 ((eq mode 'test) ; nothing gets fontified for class tags
6664 (when (setq class-with
6665 (idlwave-class-or-superclass-with-tag
6666 idlwave-current-tags-class
6668 (if (assq (idlwave-sintern-class class-with)
6669 idlwave-system-class-info)
6670 (error "No help available for system class tags."))
6671 (setq name (concat class-with "__define"))))
6673 idlwave-help-do-class-struct-tag t))
6674 (t (error "This should not happen"))))
6676 (defun idlwave-class-or-superclass-with-tag (class tag)
6677 "Find and return the CLASS or one of its superclass with the
6678 associated TAG, if any."
6679 (let ((sclasses (cons class (cdr (assq 'all-inherits
6680 (idlwave-class-info class)))))
6684 (setq cl (pop sclasses))
6685 (let ((tags (idlwave-class-tags cl)))
6687 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
6689 (setq tags (cdr tags))))))))
6692 (defun idlwave-sysvars-reset ()
6693 (if (and (fboundp 'idlwave-shell-is-running)
6694 (idlwave-shell-is-running))
6695 (idlwave-shell-send-command "idlwave_get_sysvars"
6696 'idlwave-process-sysvars 'hide)))
6698 (defun idlwave-process-sysvars ()
6699 (idlwave-shell-filter-sysvars)
6700 (setq idlwave-sint-sysvars nil
6701 idlwave-sint-sysvartags nil)
6702 (idlwave-sintern-sysvar-alist))
6704 (defun idlwave-remember-builtin-sysvars ()
6705 (setq idlwave-builtin-system-variables
6707 (mapcar 'car idlwave-system-variables-alist))))
6709 (defun idlwave-sintern-sysvar-alist ()
6710 (let ((list idlwave-system-variables-alist) entry)
6711 (while (setq entry (pop list))
6712 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
6713 (setcdr entry (mapcar (lambda (x)
6714 (list (idlwave-sintern-sysvartag (car x) 'set)))
6717 (defvar idlwave-shell-command-output)
6718 (defun idlwave-shell-filter-sysvars ()
6719 "Get the system variables and structure tags."
6720 (let ((text idlwave-shell-command-output)
6722 (old idlwave-system-variables-alist)
6723 var tags type name class)
6724 (setq idlwave-system-variables-alist nil)
6725 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
6727 (setq start (match-end 0)
6728 var (match-string 1 text)
6729 tags (if (match-end 3) (idlwave-split-string (match-string 3 text))))
6730 (setq idlwave-system-variables-alist
6731 (cons (cons var (mapcar 'list tags))
6732 idlwave-system-variables-alist)))
6733 ;; Keep the old value if query was not successful
6734 (setq idlwave-system-variables-alist
6735 (or idlwave-system-variables-alist old))))
6737 (defun idlwave-completion-fontify-classes ()
6738 "Goto the *Completions* buffer and fontify the class info."
6739 (when (featurep 'font-lock)
6741 (set-buffer "*Completions*")
6743 (goto-char (point-min))
6744 (let ((buffer-read-only nil))
6745 (while (re-search-forward "\\.*<[^>]+>" nil t)
6746 (put-text-property (match-beginning 0) (match-end 0)
6747 'face 'font-lock-string-face)))))))
6749 (defun idlwave-uniquify (list)
6751 (loop for x in list do
6752 (add-to-list 'nlist x))
6755 (defun idlwave-after-successful-completion (type slash &optional verify)
6756 "Add `=' or `(' after successful completion of keyword and function.
6757 Restore the pre-completion window configuration if possible."
6759 ((eq type 'procedure)
6761 ((eq type 'function)
6763 ((equal idlwave-function-completion-adds-paren nil) nil)
6764 ((or (equal idlwave-function-completion-adds-paren t)
6765 (equal idlwave-function-completion-adds-paren 1))
6767 ((equal idlwave-function-completion-adds-paren 2)
6772 (if (and idlwave-keyword-completion-adds-equal
6774 (progn (insert "=") t)
6777 ;; Restore the pre-completion window configuration if this is safe.
6779 (if (or (eq verify 'force) ; force
6781 (get-buffer-window "*Completions*") ; visible
6782 (idlwave-local-value 'idlwave-completion-p
6783 "*Completions*") ; cib-buffer
6784 (eq (marker-buffer idlwave-completion-mark)
6785 (current-buffer)) ; buffer OK
6786 (equal (marker-position idlwave-completion-mark)
6788 (idlwave-restore-wconf-after-completion))
6789 (move-marker idlwave-completion-mark nil)
6790 (setq idlwave-before-completion-wconf nil))
6792 (defun idlwave-mouse-context-help (ev &optional arg)
6793 "Call `idlwave-context-help' on the clicked location."
6795 (mouse-set-point ev)
6796 (idlwave-context-help arg))
6798 (defvar idlwave-last-context-help-pos nil)
6799 (defun idlwave-context-help (&optional arg)
6800 "Display IDL Online Help on context.
6801 If point is on a keyword, help for that keyword will be shown. If
6802 point is on a routine name or in the argument list of a routine, help
6803 for that routine will be displayed. Works for system routines and
6804 keywords, it pulls up text help. For other routies and keywords,
6805 visits the source file, finding help in the header (if
6806 `idlwave-help-source-try-header' is non-nil) or the routine definition
6809 (idlwave-require-online-help)
6810 (idlwave-do-context-help arg))
6812 (defun idlwave-mouse-completion-help (ev)
6813 "Display online help about the completion at point."
6815 (idlwave-require-online-help)
6816 ;; Restore last-command for next command, to make scrolling of completions
6818 (setq this-command last-command)
6819 (idlwave-do-mouse-completion-help ev))
6821 (defvar idlwave-help-is-loaded nil
6822 "Is online help avaiable?")
6823 ;; The following variables will be defined by `idlw-help.el'.
6824 (defvar idlwave-help-frame-width nil)
6825 (defvar idlwave-help-file nil)
6826 (defvar idlwave-help-topics nil)
6828 (defun idlwave-help-directory ()
6829 "Return the help directory, or nil if that is not known."
6830 (or (and (stringp idlwave-help-directory)
6831 (> (length idlwave-help-directory) 0)
6832 idlwave-help-directory)
6833 (getenv "IDLWAVE_HELP_DIRECTORY")))
6835 (defun idlwave-require-online-help ()
6836 (if idlwave-help-is-loaded
6837 t ;; everything is OK.
6838 (let* ((dir (or (idlwave-help-directory)
6839 (error "Online Help not installed (help directory unknown) - download at idlwave.org")))
6840 (lfile1 (expand-file-name "idlw-help.elc" dir))
6841 (lfile2 (expand-file-name "idlw-help.el" dir))
6842 (hfile (expand-file-name "idlw-help.txt" dir)))
6843 (if (or (and (file-regular-p lfile1) (load-file lfile1))
6844 (and (file-regular-p lfile2) (load-file lfile2)))
6846 (if (and idlwave-help-frame-parameters
6847 (not (assoc 'width idlwave-help-frame-parameters)))
6848 (push (cons 'width idlwave-help-frame-width)
6849 idlwave-help-frame-parameters))
6850 (or idlwave-help-topics
6851 (error "File `%s' in help dir `%s' does not define `idlwave-help-topics'"
6852 "idlw-help.el" dir)))
6853 (error "No such file `%s' in help dir `%s'" "idlw-help.el" dir))
6854 (if (file-regular-p hfile)
6855 (setq idlwave-help-is-loaded t
6856 idlwave-help-file hfile)
6857 (error "No such file `%s' in dir `%s'" "idlw-help.txt" dir)))))
6859 (defun idlwave-routine-info (&optional arg external)
6860 "Display a routines calling sequence and list of keywords.
6861 When point is on the name a function or procedure, or in the argument
6862 list of a function or procedure, this command displays a help buffer
6863 with the information. When called with prefix arg, enforce class
6866 When point is on an object operator `->', display the class stored in
6867 this arrow, if any (see `idlwave-store-inquired-class'). With a
6868 prefix arg, the class property is cleared out."
6872 (if (string-match "->" (buffer-substring
6873 (max (point-min) (1- (point)))
6874 (min (+ 2 (point)) (point-max))))
6875 ;; Cursor is on an arrow
6876 (if (get-text-property (point) 'idlwave-class)
6877 ;; arrow has class property
6882 (when (looking-at ".?\\(->\\)")
6883 (remove-text-properties (match-beginning 1) (match-end 1)
6884 '(idlwave-class nil face nil))
6885 (message "Class property removed from arrow")))
6886 ;; Echo class property
6887 (message "Arrow has text property identifying object to be class %s"
6888 (get-text-property (point) 'idlwave-class)))
6889 ;; No property found
6890 (message "Arrow has no class text property"))
6892 ;; Not on an arrow...
6893 (let* ((idlwave-query-class nil)
6894 (idlwave-force-class-query (equal arg '(4)))
6895 (module (idlwave-what-module)))
6897 (apply 'idlwave-display-calling-sequence
6898 (idlwave-fix-module-if-obj_new module))
6899 (error "Don't know which calling sequence to show")))))
6901 (defun idlwave-resolve (&optional arg)
6902 "Call RESOLVE on the module name at point.
6903 Like `idlwave-routine-info', this looks for a routine call at point.
6904 After confirmation in the minibuffer, it will use the shell to issue
6905 a RESOLVE call for this routine, to attempt to make it defined and its
6906 routine info available for IDLWAVE. If the routine is a method call,
6907 both `class__method' and `class__define' will be tried.
6908 With ARG, enforce query for the class of object methods."
6910 (let* ((idlwave-query-class nil)
6911 (idlwave-force-class-query (equal arg '(4)))
6912 (module (idlwave-what-module))
6913 (name (idlwave-make-full-name (nth 2 module) (car module)))
6914 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
6915 (resolve (read-string "Resolve: " (format "%s %s" type name)))
6918 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
6920 (setq type (match-string 1 resolve)
6921 class (if (match-beginning 2)
6922 (match-string 3 resolve)
6924 name (match-string 4 resolve)))
6925 (if (string= (downcase type) "function")
6926 (setq kwd ",/is_function"))
6930 (idlwave-shell-send-command
6931 (format "resolve_routine,'%s'%s" (downcase name) kwd)
6932 'idlwave-update-routine-info
6935 (idlwave-shell-send-command
6936 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
6937 (list 'idlwave-shell-send-command
6938 (format "resolve_routine,'%s__%s'%s"
6939 (downcase class) (downcase name) kwd)
6940 '(idlwave-update-routine-info)
6943 (defun idlwave-find-module (&optional arg)
6944 "Find the source code of an IDL module.
6945 Works for modules for which IDLWAVE has routine info available.
6946 The function offers as default the module name `idlwave-routine-info' would
6947 use. With ARG force class query for object methods."
6949 (let* ((idlwave-query-class nil)
6950 (idlwave-force-class-query (equal arg '(4)))
6951 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
6952 (default (concat (idlwave-make-full-name (nth 2 module) (car module))
6953 (if (eq (nth 1 module) 'pro) "<p>" "<f>")))
6957 (if (eq 'system (car-safe (nth 3 x)))
6958 ;; Take out system routines with no source.
6961 (concat (idlwave-make-full-name (nth 2 x) (car x))
6962 (if (eq (nth 1 x) 'pro) "<p>" "<f>"))
6964 (idlwave-routines))))
6965 (name (idlwave-completing-read
6966 (format "Module (Default %s): "
6967 (if default default "none"))
6970 (if (string-match "\\`\\s-*\\'" name)
6971 ;; Nothing, use the default.
6972 (setq name default))
6973 (if (string-match "<[fp]>" name)
6974 (setq type (substring name -2 -1)
6975 name (substring name 0 -3)))
6976 (if (string-match "\\(.*\\)::\\(.*\\)" name)
6977 (setq class (match-string 1 name)
6978 name (match-string 2 name)))
6979 (setq name (idlwave-sintern-routine-or-method name class)
6980 class (idlwave-sintern-class class)
6981 type (cond ((equal type "f") 'fun)
6982 ((equal type "p") 'pro)
6984 (idlwave-do-find-module name type class)))
6986 (defun idlwave-do-find-module (name type class &optional force-source)
6987 (let ((name1 (idlwave-make-full-name class name))
6989 (buf (current-buffer))
6992 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines))
6993 source (or force-source (nth 3 entry))
6994 name2 (if (nth 2 entry)
6995 (idlwave-make-full-name (nth 2 entry) name)
6998 ((or (null name) (equal name ""))
7001 (error "Nothing known about a module %s" name2))
7002 ((eq (car source) 'system)
7003 (error "Source code for system routine %s is not available"
7005 ((equal (cdr source) "")
7006 (error "Source code for routine %s is not available"
7008 ((memq (car source) '(buffer lib compiled))
7010 (if (eq (car source) 'lib)
7011 (idlwave-find-file-noselect
7012 (idlwave-expand-lib-file-name
7014 (format "%s.pro" (downcase name)))) 'find)
7015 (idlwave-find-file-noselect (cdr source) 'find)))
7016 (pop-to-buffer buf1 t)
7017 (goto-char (point-max))
7018 (let ((case-fold-search t))
7019 (if (re-search-backward
7020 (concat "^[ \t]*\\<"
7021 (cond ((equal type "f") "function")
7022 ((equal type "p") "pro")
7023 (t "\\(pro\\|function\\)"))
7025 (regexp-quote (downcase name2))
7028 (goto-char (match-beginning 0))
7031 (error "Could not find routine %s" name2)))))))
7033 (defun idlwave-what-module ()
7034 "Return a default module for stuff near point.
7035 Used by `idlwave-routine-info' and `idlwave-find-module'."
7037 (if (let ((case-fold-search t))
7039 (idlwave-beginning-of-statement)
7040 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7041 ;; This is a function or procedure definition statement
7042 ;; We return the defined routine as module.
7044 (idlwave-sintern-routine-or-method (match-string 4)
7046 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7047 (idlwave-sintern-class (match-string 3)))
7049 ;; Not a definition statement - analyze precise positon.
7050 (let* ((where (idlwave-where))
7052 (pro (car (nth 0 where)))
7053 (func (car (nth 1 where)))
7054 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7055 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7059 ((and (eq cw 'procedure)
7060 (not (equal this-word "")))
7061 (setq this-word (idlwave-sintern-routine-or-method
7062 this-word (nth 2 (nth 3 where))))
7063 (list this-word 'pro
7064 (idlwave-determine-class
7065 (cons this-word (cdr (nth 3 where)))
7067 ((and (eq cw 'function)
7068 (not (equal this-word ""))
7069 (or (eq next-char ?\() ; exclude arrays, vars.
7070 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
7071 (setq this-word (idlwave-sintern-routine-or-method
7072 this-word (nth 2 (nth 3 where))))
7073 (list this-word 'fun
7074 (idlwave-determine-class
7075 (cons this-word (cdr (nth 3 where)))
7077 ((and (memq cw '(function-keyword procedure-keyword))
7078 (not (equal this-word ""))
7079 (eq next-char ?\()) ; A function!
7080 (setq this-word (idlwave-sintern-routine this-word))
7081 (list this-word 'fun nil))
7083 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7085 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7088 (defun idlwave-what-module-find-class ()
7089 "Call idlwave-what-module and find the inherited class if necessary."
7090 (let* ((module (idlwave-what-module))
7091 (class (nth 2 module))
7093 (if (and (= (length module) 3)
7097 (apply 'idlwave-find-inherited-class module))
7100 (defun idlwave-find-inherited-class (name type class)
7101 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7102 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7107 (defun idlwave-fix-module-if-obj_new (module)
7108 "Check if MODULE points to obj_new. If yes, and if the cursor is in the
7109 keyword region, change to the appropriate Init method."
7110 (let* ((name (car module))
7112 (case-fold-search t)
7114 (if (and (stringp name)
7115 (equal (downcase name) "obj_new")
7117 (idlwave-beginning-of-statement)
7118 (setq string (buffer-substring (point) pos))
7119 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7122 (class (match-string 1 string)))
7123 (setq module (list (idlwave-sintern-method "Init")
7125 (idlwave-sintern-class class)))))
7129 (defun idlwave-fix-keywords (name type class keywords)
7130 ;; This fixes the list of keywords.
7131 (let ((case-fold-search t))
7133 ;; If this is the OBJ_NEW function, try to figure out the class and use
7134 ;; the keywords from the corresponding INIT method.
7135 (if (and (equal (upcase name) "OBJ_NEW")
7136 (or (eq major-mode 'idlwave-mode)
7137 (eq major-mode 'idlwave-shell-mode)))
7138 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7139 (string (buffer-substring bos (point)))
7140 (case-fold-search t)
7142 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7144 (setq class (idlwave-sintern-class (match-string 1 string)))
7145 (setq idlwave-current-obj_new-class class)
7148 (nth 5 (idlwave-rinfo-assq
7149 (idlwave-sintern-method "INIT")
7152 (idlwave-routines))))))))
7154 ;; If the class is `t', combine all keywords of all methods NAME
7156 (loop for x in (idlwave-routines) do
7157 (and (nth 2 x) ; non-nil class
7158 (eq (nth 1 x) type) ; correct type
7159 (eq (car x) name) ; correct name
7160 (mapcar (lambda (k) (add-to-list 'keywords k))
7162 (setq keywords (idlwave-uniquify keywords)))
7164 ;; If we have inheritance, add all keywords from superclasses, if
7165 ;; the user indicated that method in
7166 ;; `idlwave-keyword-class-inheritance'
7168 idlwave-keyword-class-inheritance
7170 (or (assq (idlwave-sintern-keyword "_extra") keywords)
7171 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7172 (boundp 'super-classes)
7173 ;; Check if one of the keyword-class regexps matches the name
7174 (let ((regexps idlwave-keyword-class-inheritance) re)
7176 (while (setq re (pop regexps))
7177 (if (string-match re name) (throw 'exit t))))))
7178 (loop for x in (idlwave-routines) do
7179 (and (nth 2 x) ; non-nil class
7180 (or (eq (nth 2 x) class) ; the right class
7181 (memq (nth 2 x) super-classes)) ; an inherited class
7182 (eq (nth 1 x) type) ; correct type
7183 (eq (car x) name) ; correct name
7184 (mapcar (lambda (k) (add-to-list 'keywords k))
7186 (setq keywords (idlwave-uniquify keywords)))
7188 ;; Return the final list
7191 (defun idlwave-expand-keyword (keyword module)
7192 "Expand KEYWORD to one of the legal keyword parameters of MODULE.
7193 KEYWORD may be an exact match or an abbreviation of a keyword.
7194 If the match is exact, KEYWORD itself is returned, even if there may be other
7195 keywords of which KEYWORD is an abbreviation. This is necessary because some
7196 system routines have keywords which are prefixes of other keywords.
7197 If KEYWORD is an abbreviation of several keywords, a list of all possible
7198 completions is returned.
7199 If the abbreviation was unique, the correct keyword is returned.
7200 If it cannot be a keyword, the function return nil.
7201 If we do not know about MODULE, just return KEYWORD literally."
7202 (let* ((name (car module))
7203 (type (nth 1 module))
7204 (class (nth 2 module))
7205 (kwd (idlwave-sintern-keyword keyword))
7206 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7207 (kwd-alist (nth 5 entry))
7208 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7209 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7210 (completion-ignore-case t)
7212 (cond ((assq kwd kwd-alist)
7214 ((setq candidates (all-completions kwd kwd-alist))
7215 (if (= (length candidates) 1)
7219 ;; Inheritance may cause this keyword to be correct
7222 ;; We do know the function, which does not have the keyword.
7225 ;; We do not know the function, so this just might be a correct
7226 ;; keyword - return it as it is.
7229 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7230 (defvar idlwave-rinfo-map (make-sparse-keymap))
7231 (define-key idlwave-rinfo-mouse-map
7232 (if (featurep 'xemacs) [button2] [mouse-2])
7233 'idlwave-mouse-active-rinfo)
7234 (define-key idlwave-rinfo-mouse-map
7235 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7236 'idlwave-mouse-active-rinfo-shift)
7237 (define-key idlwave-rinfo-mouse-map
7238 (if (featurep 'xemacs) [button3] [mouse-3])
7239 'idlwave-mouse-active-rinfo-right)
7240 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7241 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7242 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7243 (defvar idlwave-popup-source nil)
7244 (defvar idlwave-rinfo-marker (make-marker))
7246 (defun idlwave-quit-help ()
7248 (let ((ri-window (get-buffer-window "*Help*"))
7249 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7250 (when (and olh-window
7251 (fboundp 'idlwave-help-quit))
7252 (select-window olh-window)
7253 (idlwave-help-quit))
7254 (when (window-live-p ri-window)
7255 (delete-window ri-window))))
7257 (defun idlwave-display-calling-sequence (name type class
7258 &optional initial-class)
7259 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7260 (let* ((initial-class (or initial-class class))
7261 (entry (or (idlwave-best-rinfo-assq name type class
7263 (idlwave-rinfo-assq name type class
7264 idlwave-unresolved-routines)))
7265 (name (or (car entry) name))
7266 (class (or (nth 2 entry) class))
7267 (superclasses (idlwave-all-class-inherits initial-class))
7268 (twins (idlwave-routine-twins entry))
7269 (dtwins (idlwave-study-twins twins))
7271 (system (idlwave-rinfo-assq
7272 name type class idlwave-system-routines))
7273 (have-sysdoc (and system (idlwave-help-directory)))
7274 ;; (source (nth 3 entry))
7275 (have-olh (and (or system idlwave-extra-help-function)
7276 (idlwave-help-directory)))
7277 (calling-seq (nth 4 entry))
7278 (keywords (nth 5 entry))
7282 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') Button3: Online Help "
7283 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD')."))
7286 "Button2/3: Online Help"
7289 (if (idlwave-help-directory)
7290 "Button2: Pop to source and back. Button3: Source in Help window."
7291 "Button2: Pop to source and back."))
7293 "Button2: Display info about same method in superclass")
7295 (data (list name type class (current-buffer) olh initial-class))
7296 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7297 (face 'idlwave-help-link-face)
7298 beg props win cnt total)
7299 (setq keywords (idlwave-fix-keywords name type class keywords))
7302 (error "No %s %s known %s" type name
7303 (if initial-class (concat "in class " initial-class) "")))
7304 ((or (null name) (equal name ""))
7305 (error "No function or procedure call at point"))
7307 (error "Calling sequence of %s %s is not available" type name))
7310 (move-marker idlwave-rinfo-marker (point))
7311 (set-buffer (get-buffer-create "*Help*"))
7312 (use-local-map idlwave-rinfo-map)
7313 (setq buffer-read-only nil)
7315 (set (make-local-variable 'idlwave-popup-source) nil)
7316 (set (make-local-variable 'idlwave-current-obj_new-class)
7317 idlwave-current-obj_new-class)
7319 (setq props (list 'mouse-face 'highlight
7320 km-prop idlwave-rinfo-mouse-map
7321 'help-echo help-echo-class
7322 'data (cons 'class data)))
7323 (let ((classes (cons initial-class superclasses)) c)
7324 (insert "Classes: ")
7325 (while (setq c (pop classes))
7329 (if (equal (downcase c) (downcase class))
7330 (add-text-properties beg (point) (list 'face 'bold))
7331 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7332 (add-text-properties beg (point) props))))
7334 (setq props (if have-olh
7335 (list 'mouse-face 'highlight
7336 km-prop idlwave-rinfo-mouse-map
7337 'help-echo help-echo-use
7338 'data (cons 'usage data))))
7339 (if have-sysdoc (setq props (append (list 'face face) props)))
7343 (format calling-seq class name)
7344 (format calling-seq name))
7346 (add-text-properties beg (point) props)
7348 (insert "Keywords:")
7350 (insert " No keywords accepted.")
7354 (if (>= (+ col 1 (length (car x)))
7361 props (list 'mouse-face 'highlight
7362 km-prop idlwave-rinfo-mouse-map
7363 'data (cons 'keyword data)
7364 'help-echo help-echo-kwd
7366 (if have-sysdoc (setq props (append (list 'face face) props)))
7368 (add-text-properties beg (point) props)
7369 (setq col (+ col 1 (length (car x)))))
7372 (setq cnt 1 total (length all))
7373 (while (setq entry (pop all))
7374 (setq props (list 'mouse-face 'highlight
7375 km-prop idlwave-rinfo-mouse-map
7376 'help-echo help-echo-src
7377 'source (cons (car (nth 2 entry)) (nth 1 entry))
7378 'data (cons 'source data)))
7379 (idlwave-insert-source-location
7382 (if (> total 1) "Sources:" "Source:")
7384 (if (> total 1) "- " ""))
7387 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7388 ;; No more source lines, please
7390 "\n Source information truncated to %d entries."
7391 idlwave-rinfo-max-source-lines))
7394 (setq buffer-read-only t))
7395 (display-buffer "*Help*")
7396 (if (and (setq win (get-buffer-window "*Help*"))
7397 idlwave-resize-routine-help-window)
7399 (let ((ww (selected-window)))
7403 (enlarge-window (- (/ (frame-height) 2)
7405 (shrink-window-if-larger-than-buffer))
7406 (select-window ww)))))))))
7408 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7409 "Insert a source location into the routine info buffer.
7410 Start line with PREFIX.
7411 If a file name is inserted, add FILE-PROPS to it."
7413 (let* ((key (car entry))
7414 (file (nth 1 entry))
7415 (types (nth 2 entry))
7416 (shell-flag (member 'compiled types))
7417 (buffer-flag (member 'buffer types))
7418 (lib-flag (member 'lib types))
7419 (ndupl (or (and buffer-flag (idlwave-count-eq 'buffer types))
7420 (and lib-flag (idlwave-count-eq 'lib types))
7433 (insert "Builtin "))
7434 ((and (not file) shell-flag)
7435 (insert "Unresolved"))
7436 ((null file) (insert "ERROR"))
7437 ((setq special (idlwave-special-lib-test file))
7438 (insert (format "%-10s" special)))
7439 ((idlwave-syslib-p file)
7440 (if (string-match "obsolete" (file-name-directory file))
7441 (insert "Obsolete ")
7442 (insert "SystemLib ")))
7443 ((idlwave-lib-p file) (insert "Library "))
7444 (t (insert "Other ")))
7449 (if lib-flag "C" "-")
7450 (if shell-flag "S" "-")
7451 (if buffer-flag "B" "-")
7455 (insert (format "(%dx) " ndupl))
7456 (add-text-properties beg (point) (list 'face 'bold)))
7457 (when (and file (not (equal file "")))
7459 (insert (apply 'abbreviate-file-name
7460 (if (featurep 'xemacs) (list file t) (list file))))
7462 (add-text-properties beg (point) file-props)))))
7464 (defun idlwave-special-lib-test (file)
7465 "Check the path of FILE against the regexps which define special libs.
7466 Return the name of the special lib if there is a match."
7467 (let ((alist idlwave-special-lib-alist)
7471 (while (setq entry (pop alist))
7472 (if (string-match (car entry) file)
7473 (setq rtn (cdr entry)
7478 (defun idlwave-mouse-active-rinfo-right (ev)
7480 (idlwave-mouse-active-rinfo ev 'right))
7482 (defun idlwave-mouse-active-rinfo-shift (ev)
7484 (idlwave-mouse-active-rinfo ev nil 'shift))
7486 (defun idlwave-active-rinfo-space ()
7488 (idlwave-mouse-active-rinfo nil 'right))
7490 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
7491 "Does the mouse actions in the routine info buffer.
7492 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
7495 (if ev (mouse-set-point ev))
7496 (let (data id name type class buf keyword bufwin source word initial-class)
7497 (setq data (get-text-property (point) 'data)
7498 source (get-text-property (point) 'source)
7499 keyword (get-text-property (point) 'keyword)
7501 name (nth 1 data) type (nth 2 data) class (nth 3 data)
7503 initial-class (nth 6 data)
7504 word (idlwave-this-word)
7505 bufwin (get-buffer-window buf t))
7506 (cond ((eq id 'class)
7507 (if (window-live-p bufwin) (select-window bufwin))
7508 (idlwave-display-calling-sequence
7509 (idlwave-sintern-method name)
7510 type (idlwave-sintern-class word)
7513 (idlwave-require-online-help)
7514 (idlwave-online-help nil name type class))
7516 (if (and right (idlwave-help-directory))
7517 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
7518 (idlwave-help-source-try-header nil)
7519 ;; Fake idlwave-routines, to make help find the right entry
7521 (list (list (nth 1 data) (nth 2 data) (nth 3 data) source ""))))
7522 (idlwave-require-online-help)
7523 (idlwave-help-get-special-help name type class nil))
7524 (setq idlwave-popup-source (not idlwave-popup-source))
7525 (if idlwave-popup-source
7527 (idlwave-do-find-module name type class source)
7529 (setq idlwave-popup-source nil)
7530 (if (window-live-p bufwin) (select-window bufwin))
7531 (error (nth 1 err))))
7533 (select-window bufwin)
7534 (pop-to-buffer buf))
7535 (goto-char (marker-position idlwave-rinfo-marker)))))
7539 (idlwave-require-online-help)
7540 (idlwave-online-help nil name type class keyword))
7541 (idlwave-rinfo-insert-keyword keyword buf shift))))))
7543 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
7544 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
7545 (let ((bwin (get-buffer-window buffer)))
7546 (if idlwave-complete-empty-string-as-lower-case
7547 (setq keyword (downcase keyword)))
7549 (select-window bwin)
7550 (pop-to-buffer buffer)
7551 (setq bwin (get-buffer-window buffer)))
7552 (if (eq (preceding-char) ?/)
7554 (unless (save-excursion
7556 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
7557 (min (- (point) 100) (point-min)) t))
7559 (if shift (insert "/"))
7561 (if (and (not shift)
7562 idlwave-keyword-completion-adds-equal)
7565 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
7566 "List the load path shadows of all routines defined in current buffer."
7569 (if (eq major-mode 'idlwave-mode)
7570 (idlwave-list-load-path-shadows
7571 nil (idlwave-update-current-buffer-info 'save-buffer)
7572 "in current buffer")
7573 (error "Current buffer is not in idlwave-mode")))
7575 (defun idlwave-list-shell-load-path-shadows (&optional arg)
7576 "List the load path shadows of all routines compiled under the shell.
7577 This is very useful for checking an IDL application. Just compile the
7578 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
7579 routines and update IDLWAVE internal info. Then check for shadowing
7583 ((or (not (fboundp 'idlwave-shell-is-running))
7584 (not (idlwave-shell-is-running)))
7585 (error "Shell is not running"))
7586 ((null idlwave-compiled-routines)
7587 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
7589 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
7592 (defun idlwave-list-all-load-path-shadows (&optional arg)
7593 "List the load path shadows of all routines known to IDLWAVE."
7595 (idlwave-list-load-path-shadows nil nil "globally"))
7597 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
7598 "List the routines which are defined multiple times.
7599 Search the information IDLWAVE has about IDL routines for multiple
7601 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
7603 When IDL hits a routine call which is not defined, it will search on
7604 the load path in order to find a definition. The output of this
7605 command can be used to detect possible name clashes during this process."
7606 (idlwave-routines) ; Make sure everything is loaded.
7607 (unless idlwave-library-routines
7609 "You don't have a library catalog. Continue anyway? ")
7611 (let* ((routines (append idlwave-system-routines
7612 idlwave-compiled-routines
7613 idlwave-library-routines
7614 idlwave-buffer-routines
7616 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7617 (keymap (make-sparse-keymap))
7618 (props (list 'mouse-face 'highlight
7620 'help-echo "Mouse2: Find source"))
7621 (nroutines (length (or special-routines routines)))
7622 (step (/ nroutines 99))
7626 (idlwave-sort-prefer-buffer-info nil)
7627 routine twins dtwins twin done props1 lroutines)
7629 (if special-routines
7630 ;; Just looking for shadows of a few special routines
7631 (setq lroutines routines
7632 routines special-routines))
7634 (message "Sorting routines...")
7635 (setq routines (sort routines
7637 (string< (downcase (idlwave-make-full-name
7639 (downcase (idlwave-make-full-name
7640 (nth 2 b) (car b)))))))
7641 (message "Sorting routines...done")
7643 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
7646 (mouse-set-point ev)
7647 (apply 'idlwave-do-find-module
7648 (get-text-property (point) 'find-args))))
7649 (define-key keymap [(return)]
7652 (apply 'idlwave-do-find-module
7653 (get-text-property (point) 'find-args))))
7654 (message "Compiling list...( 0%%)")
7656 (set-buffer (get-buffer-create "*Shadows*"))
7657 (setq buffer-read-only nil)
7659 (while (setq routine (pop routines))
7661 (if (= (* next-perc step) n)
7663 (message "Compiling list...(%2d%%)" next-perc)
7664 (setq next-perc (1+ next-perc))))
7665 ;; Get a list of all twins
7666 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
7667 (if (memq routine done)
7669 (setq dtwins (idlwave-study-twins twins)))
7670 ;; Mark all twins as dealt with
7671 (setq done (append twins done))
7672 (when (or (> (length dtwins) 1)
7673 (> (idlwave-count-eq 'lib (nth 2 (car dtwins))) 1)
7674 (> (idlwave-count-eq 'buffer (nth 2 (car dtwins))) 1))
7676 (insert (format "\n%s%s"
7677 (idlwave-make-full-name (nth 2 routine) (car routine))
7678 (if (eq (nth 1 routine) 'fun) "()" "")))
7679 (while (setq twin (pop dtwins))
7680 (setq props1 (append (list 'find-args
7681 (list (nth 0 routine)
7684 (cons 'lib (nth 1 twin))))
7686 (idlwave-insert-source-location "\n - " twin props1))))
7687 (goto-char (point-min))
7688 (setq buffer-read-only t))
7689 (setq loc (or loc ""))
7692 (display-buffer (get-buffer "*Shadows*"))
7693 (message "%d case%s of shadowing found %s"
7694 cnt (if (= cnt 1) "" "s") loc))
7695 (message "No shadowing conflicts found %s" loc))))
7697 (defun idlwave-print-source (routine)
7698 (let* ((source (nth 3 routine))
7699 (stype (car source))
7700 (sfile (cdr source)))
7701 (if (and (eq stype 'lib) sfile)
7703 (setq sfile (idlwave-expand-lib-file-name sfile))
7704 (if (idlwave-syslib-p sfile) (setq stype 'syslib))))
7705 (if (and (eq stype 'compiled)
7706 (or (not (stringp sfile))
7707 (not (string-match "\\S-" sfile))))
7708 (setq stype 'unresolved))
7709 (princ (format " %-10s %s\n"
7711 (if sfile sfile "No source code available")))))
7713 (defun idlwave-routine-twins (entry &optional list)
7714 "Return all twin entries of ENTRY in LIST.
7715 LIST defaults to `idlwave-routines'.
7716 Twin entries are those which have the same name, type, and class.
7717 ENTRY will also be returned, as the first item of this list."
7718 (let* ((name (car entry))
7719 (type (nth 1 entry))
7720 (class (nth 2 entry))
7721 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
7723 (while (setq candidate (pop candidates))
7724 (if (and (not (eq candidate entry))
7725 (eq type (nth 1 candidate))
7726 (eq class (nth 2 candidate)))
7727 (push candidate twins)))
7728 (if (setq candidate (idlwave-rinfo-assq name type class
7729 idlwave-unresolved-routines))
7730 (push candidate twins))
7731 (cons entry (nreverse twins))))
7733 (defun idlwave-study-twins (entries)
7734 "Return dangerous twins of first entry in TWINS.
7735 Dangerous twins are routines with same name, but in different files
7737 If a file is in the system library and has an entry in the
7738 `idlwave-system-routines' list, we omit the latter because many IDL
7739 routines are implemented as library routines."
7740 (let* ((entry (car entries))
7741 (name (car entry)) ;
7742 (type (nth 1 entry)) ; Must be bound for
7743 (class (nth 2 entry)) ; idlwave-routine-twin-compare
7745 source type file thefile alist syslibp key)
7746 (while (setq entry (pop entries))
7748 (setq source (nth 3 entry)
7752 (setq file (idlwave-expand-lib-file-name file)))
7753 ;; Make KEY to index entry properly
7754 (setq key (cond ((eq type 'system) type)
7755 (file (file-truename file))
7759 (idlwave-syslib-p file))
7760 ;; We do have an entry in the system library
7763 (setq thefile (or thefile file))
7764 (if (setq entry (assoc key alist))
7765 (push type (nth 2 entry))
7766 (push (list key file (list type)) alist)))
7768 (setq alist (nreverse alist))
7771 ;; File is system *library* - remove any system entry
7772 (setq alist (delq (assoc 'system alist) alist)))
7774 (when (and (idlwave-syslib-scanned-p)
7775 (setq entry (assoc 'system alist)))
7776 (setcar entry 'builtin))
7777 (sort alist 'idlwave-routine-twin-compare)))
7782 (defvar idlwave-sort-prefer-buffer-info t
7783 "Internal variable used to influence `idlwave-routine-twin-compare'.")
7785 (defmacro idlwave-xor (a b)
7789 (defun idlwave-routine-entry-compare (a b)
7790 "Compare two routine info entries for sortiung. This is the general case.
7791 It first compates class, names, and type. If it turns out that A and B
7792 are twins (same name, class, and type), calls another routine which
7793 compares twins on the basis of their file names and path locations."
7794 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
7796 ((not (equal (idlwave-downcase-safe class)
7797 (idlwave-downcase-safe (nth 2 b))))
7799 (cond ((null (nth 2 b)) nil)
7801 (t (string< (downcase class) (downcase (nth 2 b))))))
7802 ((not (equal (downcase name) (downcase (car b))))
7804 (string< (downcase name) (downcase (car b))))
7805 ((not (eq type (nth 1 b)))
7807 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
7809 ;; A and B are twins - so the decision is more complicated.
7810 ;; Call twin-compare with the proper arguments.
7811 (idlwave-routine-entry-compare-twins a b)))))
7813 (defun idlwave-routine-entry-compare-twins (a b)
7814 "Compare two routine entries, under the assumption that they are twins.
7815 This basically calles `idlwave-routine-twin-compare' with the correct args."
7816 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
7817 (atype (car (nth 3 a)))
7818 (btype (car (nth 3 b)))
7819 (afile (cdr (nth 3 a)))
7820 (bfile (cdr (nth 3 b))))
7822 (setq afile (idlwave-expand-lib-file-name afile)))
7824 (setq bfile (idlwave-expand-lib-file-name bfile)))
7825 (idlwave-routine-twin-compare
7827 (list (file-truename afile) afile (list atype))
7828 (list atype afile (list atype)))
7830 (list (file-truename bfile) bfile (list btype))
7831 (list btype bfile (list btype))))
7834 (defun idlwave-routine-twin-compare (a b)
7835 "Compare two routine twin entries for sorting.
7836 In here, A and B are not normal routine info entries, but special
7837 lists (KEY FILENAME (TYPES...)).
7838 This expects NAME TYPE CLASS to be bound to the right values."
7839 (let* (;; Dis-assemble entries
7840 (akey (car a)) (bkey (car b))
7841 (afile (nth 1 a)) (bfile (nth 1 b))
7842 (atypes (nth 2 a)) (btypes (nth 2 b))
7844 (asysp (memq akey '(builtin system)))
7845 (bsysp (memq bkey '(builtin system)))
7846 ;; Compiled routines?
7847 (acompp (memq 'compiled atypes))
7848 (bcompp (memq 'compiled btypes))
7850 (aunresp (or (eq akey 'unresolved)
7851 (and acompp (not afile))))
7852 (bunresp (or (eq bkey 'unresolved)
7853 (and bcompp (not bfile))))
7854 ;; Buffer info available?
7855 (abufp (memq 'buffer atypes))
7856 (bbufp (memq 'buffer btypes))
7858 (tpath-alist (idlwave-true-path-alist))
7859 (apathp (assoc akey tpath-alist))
7860 (bpathp (assoc bkey tpath-alist))
7861 ;; How early on search path? High number means early since we
7862 ;; measure the tail of the path list
7863 (anpath (length (memq apathp tpath-alist)))
7864 (bnpath (length (memq bpathp tpath-alist)))
7865 ;; Look at file names
7866 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
7867 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
7868 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
7869 (regexp-quote (downcase class))
7870 (regexp-quote (downcase name)))
7871 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
7872 ;; Is file name derived from the routine name?
7873 ;; Method file or class definition file?
7874 (anamep (string-match fname-re aname))
7875 (adefp (and class anamep (string= "define" (match-string 1 aname))))
7876 (bnamep (string-match fname-re bname))
7877 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
7879 ;; Now: follow JD's ideas about sorting. Looks really simple now,
7880 ;; doesn't it? The difficult stuff is hidden above...
7882 ((idlwave-xor asysp bsysp) asysp) ; System entries first
7883 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
7884 ((and idlwave-sort-prefer-buffer-info
7885 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
7886 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
7887 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
7888 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
7889 ((and class anamep bnamep ; both file names match ->
7890 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
7891 ((> anpath bnpath) t) ; Who is first on path?
7892 (t nil)))) ; Default
7894 (defun idlwave-downcase-safe (string)
7895 "Donwcase if string, else return unchanged."
7896 (if (stringp string)
7900 (defun idlwave-count-eq (elt list)
7901 "How often is ELT in LIST?"
7902 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
7904 (defun idlwave-syslib-p (file)
7905 "Non-nil of FILE is in the system library."
7906 (let* ((true-syslib (file-name-as-directory
7908 (expand-file-name "lib" (idlwave-sys-dir)))))
7909 (true-file (file-truename file)))
7910 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
7912 (defun idlwave-lib-p (file)
7913 "Non-nil if file is in the library"
7914 (let ((true-dir (file-name-directory (file-truename file))))
7915 (assoc true-dir (idlwave-true-path-alist))))
7917 (defun idlwave-true-path-alist ()
7918 "Return `idlwave-path-alist' alist with true-names.
7919 Info is cached, but relies on the functons setting `idlwave-path-alist'
7920 to reset the variable `idlwave-true-path-alist' to nil."
7921 (or idlwave-true-path-alist
7922 (setq idlwave-true-path-alist
7923 (mapcar (lambda(x) (cons
7924 (file-name-as-directory
7926 (directory-file-name
7929 idlwave-path-alist))))
7931 (defun idlwave-syslib-scanned-p ()
7932 "Non-nil if the system lib file !DIR/lib has been scanned."
7933 (let* ((true-syslib (file-name-as-directory
7935 (expand-file-name "lib" (idlwave-sys-dir))))))
7936 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
7938 ;; ----------------------------------------------------------------------------
7940 ;; Online Help display
7943 ;; ----------------------------------------------------------------------------
7945 ;; Additions for use with imenu.el and func-menu.el
7946 ;; (pop-up a list of IDL units in the current file).
7949 (defun idlwave-prev-index-position ()
7950 "Search for the previous procedure or function.
7951 Return nil if not found. For use with imenu.el."
7954 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
7955 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
7958 (defun idlwave-unit-name ()
7959 "Return the unit name.
7960 Assumes that point is at the beginning of the unit as found by
7961 `idlwave-prev-index-position'."
7964 (let ((begin (point)))
7965 (re-search-forward "[a-zA-Z][a-zA-Z0-9$_]+\\(::[a-zA-Z][a-zA-Z0-9$_]+\\)?")
7966 (if (fboundp 'buffer-substring-no-properties)
7967 (buffer-substring-no-properties begin (point))
7968 (buffer-substring begin (point)))))
7970 (defalias 'idlwave-function-menu
7973 (require 'func-menu)
7975 (error (condition-case nil
7981 ;; Here we kack func-menu.el in order to support this new mode.
7982 ;; The latest versions of func-menu.el already have this stuff in, so
7983 ;; we hack only if it is not already there.
7984 (when (fboundp 'eval-after-load)
7985 (eval-after-load "func-menu"
7987 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
7988 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
7989 (setq fume-function-name-regexp-alist
7990 (cons '(idlwave-mode . fume-function-name-regexp-idl)
7991 fume-function-name-regexp-alist)))
7992 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
7993 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
7994 (setq fume-find-function-name-method-alist
7995 (cons '(idlwave-mode . fume-find-next-idl-function-name)
7996 fume-find-function-name-method-alist))))))
7998 (defun idlwave-edit-in-idlde ()
7999 "Edit the current file in IDL Development environment."
8001 (start-process "idldeclient" nil
8002 idlwave-shell-explicit-file-name "-c" "-e"
8003 (buffer-file-name) "&"))
8005 (defun idlwave-launch-idlhelp ()
8006 "Start the IDLhelp application."
8008 (start-process "idlhelp" nil idlwave-help-application))
8010 ;; Menus - using easymenu.el
8011 (defvar idlwave-mode-menu-def
8013 ["PRO/FUNC menu" idlwave-function-menu t]
8015 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8016 ["Subprogram End" idlwave-end-of-subprogram t]
8017 ["Block Start" idlwave-beginning-of-block t]
8018 ["Block End" idlwave-end-of-block t]
8019 ["Up Block" idlwave-backward-up-block t]
8020 ["Down Block" idlwave-down-block t]
8021 ["Skip Block Backward" idlwave-backward-block t]
8022 ["Skip Block Forward" idlwave-forward-block t])
8024 ["Subprogram" idlwave-mark-subprogram t]
8025 ["Block" idlwave-mark-block t]
8026 ["Header" idlwave-mark-doclib t])
8028 ["Indent Subprogram" idlwave-indent-subprogram t]
8029 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8030 ["Continue/Split line" idlwave-split-line t]
8032 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8033 :selected (symbol-value idlwave-fill-function)])
8035 ["Procedure" idlwave-procedure t]
8036 ["Function" idlwave-function t]
8037 ["Doc Header" idlwave-doc-header t]
8038 ["Log" idlwave-doc-modification t]
8040 ["Case" idlwave-case t]
8041 ["For" idlwave-for t]
8042 ["Repeat" idlwave-repeat t]
8043 ["While" idlwave-while t]
8045 ["Close Block" idlwave-close-block t])
8047 ["Complete" idlwave-complete t]
8049 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8050 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8052 ["3 Function Name" (idlwave-complete 'function) t]
8053 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8055 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8056 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8058 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8059 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8061 ["9 Class Name" idlwave-complete-class t]))
8063 ["Show Routine Info" idlwave-routine-info t]
8064 ["Online Context Help" idlwave-context-help (idlwave-help-directory)]
8066 ["Find Routine Source" idlwave-find-module t]
8067 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
8069 ["Update Routine Info" idlwave-update-routine-info t]
8071 "IDL Library Catalog"
8072 ["Select Catalog Directories" (idlwave-create-libinfo-file nil) t]
8073 ["Scan Directories" (idlwave-update-routine-info '(16))
8074 (and idlwave-path-alist (not idlwave-catalog-process))]
8075 ["Scan Directories &" (idlwave-update-routine-info '(64))
8076 (and idlwave-path-alist (not idlwave-catalog-process))]
8079 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8080 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8081 ["Check Everything" idlwave-list-all-load-path-shadows t])
8083 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8085 ["Insert TAB character" idlwave-hard-tab t])
8088 ["Generate IDL tags" idlwave-make-tags t]
8089 ["Start IDL shell" idlwave-shell t]
8090 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8091 ["Launch IDL Help" idlwave-launch-idlhelp t])
8094 ["Browse IDLWAVE Group" idlwave-customize t]
8096 ["Build Full Customize Menu" idlwave-create-customize-menu
8097 (fboundp 'customize-menu-create)])
8099 ["Describe Mode" describe-mode t]
8100 ["Abbreviation List" idlwave-list-abbrevs t]
8102 ["Commentary in idlwave.el" idlwave-show-commentary t]
8103 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
8105 ["Info" idlwave-info t]
8107 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8109 (defvar idlwave-mode-debug-menu-def
8111 ["Start IDL shell" idlwave-shell t]
8112 ["Save and .RUN buffer" idlwave-shell-save-and-run
8113 (and (boundp 'idlwave-shell-automatic-start)
8114 idlwave-shell-automatic-start)]))
8116 (if (or (featurep 'easymenu) (load "easymenu" t))
8118 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8119 "IDL and WAVE CL editing menu"
8120 idlwave-mode-menu-def)
8121 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8122 "IDL and WAVE CL editing menu"
8123 idlwave-mode-debug-menu-def)))
8125 (defun idlwave-customize ()
8126 "Call the customize function with idlwave as argument."
8128 ;; Try to load the code for the shell, so that we can customize it
8130 (or (featurep 'idlw-shell)
8131 (load "idlw-shell" t))
8132 (customize-browse 'idlwave))
8134 (defun idlwave-create-customize-menu ()
8135 "Create a full customization menu for IDLWAVE, insert it into the menu."
8137 (if (fboundp 'customize-menu-create)
8139 ;; Try to load the code for the shell, so that we can customize it
8141 (or (featurep 'idlw-shell)
8142 (load "idlw-shell" t))
8144 '("IDLWAVE") "Customize"
8145 `(["Browse IDLWAVE group" idlwave-customize t]
8147 ,(customize-menu-create 'idlwave)
8148 ["Set" Custom-set t]
8149 ["Save" Custom-save t]
8150 ["Reset to Current" Custom-reset-current t]
8151 ["Reset to Saved" Custom-reset-saved t]
8152 ["Reset to Standard Settings" Custom-reset-standard t]))
8153 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8154 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8156 (defun idlwave-show-commentary ()
8157 "Use the finder to view the file documentation from `idlwave.el'."
8160 (finder-commentary "idlwave.el"))
8162 (defun idlwave-shell-show-commentary ()
8163 "Use the finder to view the file documentation from `idlw-shell.el'."
8166 (finder-commentary "idlw-shell.el"))
8168 (defun idlwave-info ()
8169 "Read documentation for IDLWAVE in the info system."
8172 (Info-goto-node "(idlwave)"))
8174 (defun idlwave-list-abbrevs (arg)
8175 "Show the code abbreviations define in IDLWAVE mode.
8176 This lists all abbrevs where the replacement text differs from the input text.
8177 These are the ones the users want to learn to speed up their writing.
8179 The function does *not* list abbrevs which replace a word with itself
8180 to call a hook. These hooks are used to change the case of words or
8181 to blink the matching `begin', and the user does not need to know them.
8183 With arg, list all abbrevs with the corresponding hook.
8185 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8188 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8190 str rpl func fmt (len-str 0) (len-rpl 0))
8193 (if (symbol-value sym)
8195 (setq str (symbol-name sym)
8196 rpl (symbol-value sym)
8197 func (symbol-function sym))
8199 (setq func (prin1-to-string func))
8200 (if (and (listp func) (stringp (nth 2 func)))
8201 (setq rpl (concat "EVAL: " (nth 2 func))
8204 (if (or arg (not (string= rpl str)))
8206 (setq len-str (max len-str (length str)))
8207 (setq len-rpl (max len-rpl (length rpl)))
8208 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8211 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8213 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8214 (with-output-to-temp-buffer "*Help*"
8217 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8218 (princ "=========================================\n\n")
8219 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8220 (princ (format fmt "---" "-------" "----")))
8221 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8222 (princ "================================================\n\n")
8223 (princ (format fmt "KEY" "ACTION" ""))
8224 (princ (format fmt "---" "------" "")))
8227 (setq str (car list)
8230 (princ (format fmt str rpl func)))
8232 ;; Make sure each abbreviation uses only one display line
8234 (set-buffer "*Help*")
8235 (setq truncate-lines t)))
8237 ;; Add .pro files to speedbar for support, if it's loaded
8238 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8240 ;; Try to load online help, but catch any errors.
8242 (idlwave-require-online-help)
8245 ;; Set an idle timer to load the routine info.
8246 ;; Will only work on systems which support this.
8247 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8250 (run-hooks 'idlwave-load-hook)
8254 ;;; idlwave.el ends here