Add :link (custom-group-link font-lock-faces) to defgroup.
[bpt/emacs.git] / lisp / progmodes / idlwave.el
CommitLineData
52a244eb 1;; idlwave.el --- IDL editing mode for GNU Emacs
31b58798 2;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3938cb82 3;; Free Software Foundation
f32b3b91 4
52a244eb 5;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
65363a4e 6;; Carsten Dominik <dominik@science.uva.nl>
52a244eb 7;; Chris Chase <chase@att.com>
5e72c6b2 8;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
3938cb82 9;; Version: 5.7_22
f32b3b91
CD
10;; Keywords: languages
11
e8af40ee 12;; This file is part of GNU Emacs.
f32b3b91
CD
13
14;; GNU Emacs is free software; you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
16;; the Free Software Foundation; either version 2, or (at your option)
17;; any later version.
18
19;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
25;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
26;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27;; Boston, MA 02110-1301, USA.
f32b3b91
CD
28
29;;; Commentary:
30
3938cb82
S
31;; IDLWAVE enables feature-rich development and interaction with IDL.
32
52a244eb
S
33;; In the remotely distant past, based on pascal.el, though bears
34;; little resemblance to it now.
f32b3b91
CD
35;;
36;; Incorporates many ideas, such as abbrevs, action routines, and
37;; continuation line indenting, from wave.el.
38;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
39;;
40;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
41;; for features, key bindings, and info.
42;; Also, Info format documentation is available with `M-x idlwave-info'
43;;
5e72c6b2
S
44;; New versions of IDLWAVE, documentation, and more information
45;; available from:
46;; http://idlwave.org
f32b3b91
CD
47;;
48;; INSTALLATION
49;; ============
50;;
51;; Follow the instructions in the INSTALL file of the distribution.
52;; In short, put this file on your load path and add the following
53;; lines to your .emacs file:
54;;
55;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
8c7b4ec8 56;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
f32b3b91
CD
57;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
58;;
59;;
60;; SOURCE
61;; ======
62;;
76959b77 63;; The newest version of this file is available from the maintainer's
52a244eb 64;; Webpage:
f32b3b91 65;;
5e72c6b2 66;; http://idlwave.org
f32b3b91
CD
67;;
68;; DOCUMENTATION
69;; =============
70;;
52a244eb
S
71;; IDLWAVE is documented online in info format. A printable version
72;; of the documentation is available from the maintainers webpage (see
73;; SOURCE).
775591f7 74;;
31b58798 75;;
f32b3b91
CD
76;; ACKNOWLEDGMENTS
77;; ===============
78;;
79;; Thanks to the following people for their contributions and comments:
80;;
52a244eb
S
81;; Ulrik Dickow <dickow_at_nbi.dk>
82;; Eric E. Dors <edors_at_lanl.gov>
83;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
84;; David Huenemoerder <dph_at_space.mit.edu>
85;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
86;; Dick Jackson <dick_at_d-jackson.com>
87;; Xuyong Liu <liu_at_stsci.edu>
88;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
89;; Laurent Mugnier <mugnier_at_onera.fr>
90;; Lubos Pochman <lubos_at_rsinc.com>
91;; Bob Portmann <portmann_at_al.noaa.gov>
92;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
93;; Marty Ryba <ryba_at_ll.mit.edu>
94;; Paul Sorenson <aardvark62_at_msn.com>
95;; Phil Sterne <sterne_at_dublin.llnl.gov>
96;; Phil Williams <williams_at_irc.chmcc.org>
f32b3b91
CD
97;;
98;; CUSTOMIZATION:
99;; =============
100;;
52a244eb
S
101;; IDLWAVE has extensive customize support; to learn about the
102;; variables which control the mode's behavior, use `M-x
103;; idlwave-customize'.
f32b3b91
CD
104;;
105;; You can set your own preferred values with Customize, or with Lisp
106;; code in .emacs. For an example of what to put into .emacs, check
52a244eb
S
107;; the TexInfo documentation or see a complete .emacs available at the
108;; website.
f32b3b91
CD
109;;
110;; KNOWN PROBLEMS:
111;; ==============
112;;
76959b77
S
113;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
114;; Numerics, Inc. is growing less and less complete as the two
115;; languages grow increasingly apart. The mode probably shouldn't
3938cb82 116;; even have "WAVE" in its title, but it's catchy, and was required
52a244eb 117;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
76959b77 118;;
f32b3b91
CD
119;; Moving the point backwards in conjunction with abbrev expansion
120;; does not work as I would like it, but this is a problem with
121;; emacs abbrev expansion done by the self-insert-command. It ends
122;; up inserting the character that expanded the abbrev after moving
123;; point backward, e.g., "\cl" expanded with a space becomes
124;; "LONG( )" with point before the close paren. This is solved by
31b58798 125;; using a temporary function in `post-command-hook' - not pretty,
595ab50b 126;; but it works.
f32b3b91
CD
127;;
128;; Tabs and spaces are treated equally as whitespace when filling a
129;; comment paragraph. To accomplish this, tabs are permanently
130;; replaced by spaces in the text surrounding the paragraph, which
131;; may be an undesirable side-effect. Replacing tabs with spaces is
132;; limited to comments only and occurs only when a comment
133;; paragraph is filled via `idlwave-fill-paragraph'.
134;;
52a244eb
S
135;; Muti-statement lines (using "&") on block begin and end lines can
136;; ruin the formatting. For example, multiple end statements on a
137;; line: endif & endif. Using "&" outside of block begin/end lines
138;; should be okay.
f32b3b91 139;;
76959b77
S
140;; Determining the expression at point for printing and other
141;; examination commands is somewhat rough: currently only fairly
142;; simple entities are found. You can always drag-select or examine
52a244eb 143;; a pre-selected region.
f32b3b91 144;;
f32b3b91
CD
145;; When forcing completion of method keywords, the initial
146;; query for a method has multiple entries for some methods. Would
595ab50b 147;; be too difficult to fix this hardly used case.
f32b3b91
CD
148;;
149\f
150;;; Code:
151
52a244eb 152
f32b3b91 153(eval-when-compile (require 'cl))
52a244eb
S
154(require 'idlw-help)
155
156;; For XEmacs
157(unless (fboundp 'line-beginning-position)
158 (defalias 'line-beginning-position 'point-at-bol))
159(unless (fboundp 'line-end-position)
160 (defalias 'line-end-position 'point-at-eol))
161(unless (fboundp 'char-valid-p)
162 (defalias 'char-valid-p 'characterp))
f32b3b91 163
3938cb82
S
164(if (not (fboundp 'cancel-timer))
165 (condition-case nil
166 (require 'timer)
167 (error nil)))
168
f32b3b91 169(eval-and-compile
5e72c6b2
S
170 ;; Kludge to allow `defcustom' for Emacs 19.
171 (condition-case () (require 'custom) (error nil))
172 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
173 nil ;; We've got what we needed
174 ;; We have the old or no custom-library, hack around it!
175 (defmacro defgroup (&rest args) nil)
31b58798 176 (defmacro defcustom (var value doc &rest args)
5e72c6b2 177 `(defvar ,var ,value ,doc))))
f32b3b91
CD
178
179(defgroup idlwave nil
31b58798 180 "Major mode for editing IDL .pro files."
f32b3b91 181 :tag "IDLWAVE"
31b58798 182 :link '(url-link :tag "Home Page"
5e72c6b2 183 "http://idlwave.org")
595ab50b
CD
184 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
185 "idlw-shell.el")
f32b3b91
CD
186 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
187 :link '(custom-manual "(idlwave)Top")
188 :prefix "idlwave"
189 :group 'languages)
190
52a244eb 191
f32b3b91
CD
192;;; Variables for indentation behavior ---------------------------------------
193
194(defgroup idlwave-code-formatting nil
195 "Indentation and formatting options for IDLWAVE mode."
196 :group 'idlwave)
197
198(defcustom idlwave-main-block-indent 0
199 "*Extra indentation for the main block of code.
200That is the block between the FUNCTION/PRO statement and the END
201statement for that program unit."
202 :group 'idlwave-code-formatting
203 :type 'integer)
204
205(defcustom idlwave-block-indent 4
206 "*Extra indentation applied to block lines.
207If you change this, you probably also want to change `idlwave-end-offset'."
208 :group 'idlwave-code-formatting
209 :type 'integer)
210
211(defcustom idlwave-end-offset -4
212 "*Extra indentation applied to block END lines.
213A value equal to negative `idlwave-block-indent' will make END lines
214line up with the block BEGIN lines."
215 :group 'idlwave-code-formatting
216 :type 'integer)
217
218(defcustom idlwave-continuation-indent 2
219 "*Extra indentation applied to continuation lines.
220This extra offset applies to the first of a set of continuation lines.
5e72c6b2
S
221The following lines receive the same indentation as the first."
222 :group 'idlwave-code-formatting
223 :type 'integer)
224
225(defcustom idlwave-max-extra-continuation-indent 20
226 "*Maximum additional indentation for special continuation indent.
227Several special indentations are tried to help line up continuation
228lines in routine calls or definitions, other statements with
134b6671 229parentheses, or assignment statements. This variable specifies a
5e72c6b2
S
230maximum amount by which this special indentation can exceed the
231standard continuation indentation, otherwise defaulting to a fixed
232offset. Set to 0 to effectively disable all special continuation
233indentation, or to a large number (like 100) to enable it in all
52a244eb 234cases. See also `idlwave-indent-to-open-paren', which can override
5e72c6b2 235this variable."
f32b3b91
CD
236 :group 'idlwave-code-formatting
237 :type 'integer)
238
5e72c6b2
S
239(defcustom idlwave-indent-to-open-paren t
240 "*Non-nil means, indent continuation lines to innermost open
241parenthesis. This indentation occurs even if otherwise disallowed by
242`idlwave-max-extra-continuation-indent'. Matching parens and the
243interleaving args are lined up. Example:
244
245 x = function_a(function_b(function_c( a, b, [1,2,3, $
246 4,5,6 $
247 ], $
248 c, d $
249 )))
250
251When this variable is nil, paren alignment may still occur, based on
252the value of `max-extra-continuation-indent', which, if zero, would
253yield:
254
255 x = function_a(function_b(function_c( a, b, [1,2,3, $
256 4,5,6 $
257 ], $
258 c, d $
259 )))"
260 :group 'idlwave-code-formatting
261 :type 'boolean)
262
52a244eb
S
263(defcustom idlwave-indent-parens-nested nil
264 "*Non-nil means, indent continuation lines with parens by nesting
265lines at consecutively deeper levels."
266 :group 'idlwave-code-formatting
267 :type 'boolean)
268
269
f32b3b91
CD
270(defcustom idlwave-hanging-indent t
271 "*If set non-nil then comment paragraphs are indented under the
272hanging indent given by `idlwave-hang-indent-regexp' match in the first line
273of the paragraph."
274 :group 'idlwave-code-formatting
275 :type 'boolean)
276
277(defcustom idlwave-hang-indent-regexp "- "
278 "*Regular expression matching the position of the hanging indent
279in the first line of a comment paragraph. The size of the indent
280extends to the end of the match for the regular expression."
281 :group 'idlwave-code-formatting
282 :type 'regexp)
283
284(defcustom idlwave-use-last-hang-indent nil
285 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
286 :group 'idlwave-code-formatting
287 :type 'boolean)
288
289(defcustom idlwave-fill-comment-line-only t
290 "*If non-nil then auto fill will only operate on comment lines."
291 :group 'idlwave-code-formatting
292 :type 'boolean)
293
294(defcustom idlwave-auto-fill-split-string t
295 "*If non-nil then auto fill will split strings with the IDL `+' operator.
31b58798
JB
296When the line end falls within a string, string concatenation with the
297'+' operator will be used to distribute a long string over lines.
f32b3b91
CD
298If nil and a string is split then a terminal beep and warning are issued.
299
300This variable is ignored when `idlwave-fill-comment-line-only' is
301non-nil, since in this case code is not auto-filled."
302 :group 'idlwave-code-formatting
303 :type 'boolean)
304
305(defcustom idlwave-split-line-string t
306 "*If non-nil then `idlwave-split-line' will split strings with `+'.
307When the splitting point of a line falls inside a string, split the string
308using the `+' string concatenation operator. If nil and a string is
309split then a terminal beep and warning are issued."
310 :group 'idlwave-code-formatting
311 :type 'boolean)
312
313(defcustom idlwave-no-change-comment ";;;"
314 "*The indentation of a comment that starts with this regular
315expression will not be changed. Note that the indentation of a comment
316at the beginning of a line is never changed."
317 :group 'idlwave-code-formatting
318 :type 'string)
319
320(defcustom idlwave-begin-line-comment nil
321 "*A comment anchored at the beginning of line.
322A comment matching this regular expression will not have its
323indentation changed. If nil the default is \"^;\", i.e., any line
324beginning with a \";\". Expressions for comments at the beginning of
325the line should begin with \"^\"."
326 :group 'idlwave-code-formatting
327 :type '(choice (const :tag "Any line beginning with `;'" nil)
328 'regexp))
329
330(defcustom idlwave-code-comment ";;[^;]"
331 "*A comment that starts with this regular expression on a line by
332itself is indented as if it is a part of IDL code. As a result if
333the comment is not preceded by whitespace it is unchanged."
334 :group 'idlwave-code-formatting
335 :type 'regexp)
336
337;; Comments not matching any of the above will be indented as a
338;; right-margin comment, i.e., to a minimum of `comment-column'.
339
f32b3b91
CD
340;;; Routine Info and Completion ---------------------------------------
341
15e42531
CD
342(defgroup idlwave-routine-info nil
343 "Routine Info options for IDLWAVE mode."
f32b3b91
CD
344 :group 'idlwave)
345
52a244eb
S
346(defcustom idlwave-use-library-catalogs t
347 "*Non-nil means search the IDL path for library catalog files.
348
349These files, named .idlwave_catalog, document routine information for
350individual directories and libraries of IDL .pro files. Many popular
351libraries come with catalog files by default, so leaving this on is a
352usually a good idea.."
353 :group 'idlwave-routine-info
354 :type 'boolean)
5e72c6b2
S
355
356(defcustom idlwave-init-rinfo-when-idle-after 10
357 "*Seconds of idle time before routine info is automatically initialized.
358Initializing the routine info can take long, in particular if a large
359library catalog is involved. When Emacs is idle for more than the number
360of seconds specified by this variable, it starts the initialization.
31b58798 361The process is split into five steps, in order to keep possible work
5e72c6b2
S
362interruption as short as possible. If one of the steps finishes, and no
363user input has arrived in the mean time, initialization proceeds immediately
364to the next step.
365A good value for this variable is about 1/3 of the time initialization
366take 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.
367A Value of 0 means, don't initialize automatically."
368 :group 'idlwave-routine-info
369 :type 'number)
370
f32b3b91 371(defcustom idlwave-scan-all-buffers-for-routine-info t
15e42531
CD
372 "*Non-nil means, scan buffers for IDL programs when updating info.
373The scanning is done by the command `idlwave-update-routine-info'.
374The following values are allowed:
375
376nil Don't scan any buffers.
377t Scan all idlwave-mode buffers in the current editing session.
378current Scan only the current buffer, but no other buffers."
379 :group 'idlwave-routine-info
380 :type '(choice
381 (const :tag "No buffer" nil)
382 (const :tag "All buffers" t)
383 (const :tag "Current buffer only" 'current)))
f32b3b91
CD
384
385(defcustom idlwave-query-shell-for-routine-info t
386 "*Non-nil means query the shell for info about compiled routines.
387Querying the shell is useful to get information about compiled modules,
388and it is turned on by default. However, when you have a complete library
389scan, this is not necessary."
15e42531 390 :group 'idlwave-routine-info
f32b3b91
CD
391 :type 'boolean)
392
15e42531
CD
393(defcustom idlwave-auto-routine-info-updates
394 '(find-file save-buffer kill-buffer compile-buffer)
395 "*Controls under what circumstances routine info is updated automatically.
396Possible values:
397nil Never
398t All available
facebc7b 399\(...) A list of circumstances. Allowed members are:
15e42531
CD
400 find-file Add info for new IDLWAVE buffers.
401 save-buffer Update buffer info when buffer is saved
402 kill-buffer Remove buffer info when buffer gets killed
403 compile-buffer Update shell info after `idlwave-shell-save-and...'"
404 :group 'idlwave-routine-info
405 :type '(choice
406 (const :tag "Never" nil)
407 (const :tag "As often as possible" t)
408 (set :tag "Checklist" :greedy t
409 (const :tag "When visiting a file" find-file)
410 (const :tag "When saving a buffer" save-buffer)
411 (const :tag "After a buffer was killed" kill-buffer)
412 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
31b58798 413
15e42531
CD
414(defcustom idlwave-rinfo-max-source-lines 5
415 "*Maximum number of source files displayed in the Routine Info window.
416When an integer, it is the maximum number of source files displayed.
417t means to show all source files."
418 :group 'idlwave-routine-info
419 :type 'integer)
420
f32b3b91 421(defcustom idlwave-library-path nil
52a244eb
S
422 "Library path for Windows and MacOS. Not needed under Unix. When
423selecting the directories to scan for IDL user catalog routine info,
424IDLWAVE can, under UNIX, query the shell for the exact search path
425\(the value of !PATH). However, under Windows and MacOS (pre-OSX),
426the IDLWAVE shell does not work. In this case, this variable can be
427set to specify the paths where IDLWAVE can find PRO files. The shell
428will only be asked for a list of paths when this variable is nil. The
429value is a list of directories. A directory preceeded by a `+' will
430be searched recursively. If you set this variable on a UNIX system,
431the shell will not be queried. See also `idlwave-system-directory'."
15e42531 432 :group 'idlwave-routine-info
f32b3b91
CD
433 :type '(repeat (directory)))
434
15e42531 435(defcustom idlwave-system-directory ""
52a244eb
S
436 "The IDL system directory for Windows and MacOS. Not needed under
437UNIX. Set this to the value of the `!DIR' system variable in IDL.
438IDLWAVE uses this to find out which of the library routines belong to
439the official system library. All files inside the `lib' subdirectory
440are considered system library files - so don't install private stuff
441in this directory. On UNIX systems, IDLWAVE queries the shell for the
442value of `!DIR'. See also `idlwave-library-path'."
15e42531
CD
443 :group 'idlwave-routine-info
444 :type 'directory)
445
31b58798 446(defcustom idlwave-config-directory
52a244eb
S
447 (convert-standard-filename "~/.idlwave")
448 "*Directory for configuration files and user-library catalog."
15e42531 449 :group 'idlwave-routine-info
f32b3b91
CD
450 :type 'file)
451
52a244eb
S
452(defvar idlwave-user-catalog-file "idlusercat.el")
453(defvar idlwave-path-file "idlpath.el")
454
455(defvar idlwave-libinfo-file nil
456 "*Obsolete variable, no longer used.")
457
15e42531
CD
458(defcustom idlwave-special-lib-alist nil
459 "Alist of regular expressions matching special library directories.
460When listing routine source locations, IDLWAVE gives a short hint where
31b58798 461the file defining the routine is located. By default it lists `SystemLib'
15e42531
CD
462for routines in the system library `!DIR/lib' and `Library' for anything
463else. This variable can define additional types. The car of each entry
464is a regular expression matching the file name (they normally will match
465on the path). The cdr is the string to be used as identifier. Max 10
466chars are allowed."
467 :group 'idlwave-routine-info
468 :type '(repeat
469 (cons regexp string)))
470
52a244eb 471(defcustom idlwave-auto-write-paths t
31b58798 472 "Write out path (!PATH) and system directory (!DIR) info automatically.
52a244eb
S
473Path info is needed to locate library catalog files. If non-nil,
474whenever the path-list changes as a result of shell-query, etc., it is
475written to file. Otherwise, the menu option \"Write Paths\" can be
476used to force a write."
477 :group 'idlwave-routine-info
05a1abfc 478 :type 'boolean)
775591f7 479
15e42531
CD
480(defgroup idlwave-completion nil
481 "Completion options for IDLWAVE mode."
482 :prefix "idlwave"
483 :group 'idlwave)
484
f32b3b91
CD
485(eval-and-compile
486 (defconst idlwave-tmp
487 '(choice :tag "by applying the function"
488 (const upcase)
489 (const downcase)
490 (const capitalize)
491 (const preserve)
492 (symbol :tag "Other"))))
493
f32b3b91
CD
494(defcustom idlwave-completion-case '((routine . upcase)
495 (keyword . upcase)
496 (class . preserve)
497 (method . preserve))
498 "Association list setting the case of completed words.
499
500This variable determines the case (UPPER/lower/Capitalized...) of
501words inserted into the buffer by completion. The preferred case can
502be specified separately for routine names, keywords, classes and
31b58798 503methods.
f32b3b91
CD
504This alist should therefore have entries for `routine' (normal
505functions and procedures, i.e. non-methods), `keyword', `class', and
506`method'. Plausible values are
507
508upcase upcase whole word, like `BOX_CURSOR'
509downcase downcase whole word, like `read_ppm'
510capitalize capitalize each part, like `Widget_Control'
511preserve preserve case as is, like `IDLgrView'
512
513The value can also be any Emacs Lisp function which transforms the
514case of characters in a string.
515
516A value of `preserve' means that the case of the completed word is
517identical to the way it was written in the definition statement of the
518routine. This was implemented to allow for mixed-case completion, in
519particular of object classes and methods.
520If a completable word is defined in multiple locations, the meaning of
521`preserve' is not unique since the different definitions might be
522cased differently. Therefore IDLWAVE always takes the case of the
523*first* definition it encounters during routine info collection and
524uses the case derived from it consistently.
525
526Note that a lowercase-only string in the buffer will always be completed in
527lower case (but see the variable `idlwave-completion-force-default-case').
528
529After changing this variable, you need to either restart Emacs or press
530`C-u C-c C-i' to update the internal lists."
15e42531 531 :group 'idlwave-completion
f32b3b91
CD
532 :type `(repeat
533 (cons (symbol :tag "Derive completion case for")
534 ,idlwave-tmp)))
535
536(defcustom idlwave-completion-force-default-case nil
537 "*Non-nil means, completion will always honor `idlwave-completion-case'.
538When nil, only the completion of a mixed case or upper case string
539will honor the default settings in `idlwave-completion-case', while
540the completion of lower case strings will be completed entirely in
541lower case."
15e42531 542 :group 'idlwave-completion
f32b3b91
CD
543 :type 'boolean)
544
545(defcustom idlwave-complete-empty-string-as-lower-case nil
546 "*Non-nil means, the empty string is considered downcase for completion.
547The case of what is already in the buffer determines the case of completions.
548When this variable is non-nil, the empty string is considered to be downcase.
549Completing on the empty string then offers downcase versions of the possible
550completions."
15e42531 551 :group 'idlwave-completion
f32b3b91
CD
552 :type 'boolean)
553
554(defvar idlwave-default-completion-case-is-down nil
555 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
556`idlwave-completion-case'.")
557
558(defcustom idlwave-buffer-case-takes-precedence nil
559 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
560To make this possible, we need to re-case everything each time we update
561the routine info from the buffers. This is slow.
562The default is to consider the case given in the system and library files
563first which makes updating much faster."
15e42531
CD
564 :group 'idlwave-completion
565 :type 'boolean)
566
567(defcustom idlwave-highlight-help-links-in-completion t
568 "*Non-nil means, highlight completions for which system help is available.
569Help can then be accessed with mouse-3.
570This option is only effective when the online help system is installed."
571 :group 'idlwave-completion
f32b3b91
CD
572 :type 'boolean)
573
05a1abfc
CD
574(defcustom idlwave-support-inheritance t
575 "Non-nil means, treat inheritance with completion, online help etc.
cef6cafe 576When nil, IDLWAVE only knows about the native methods and tags of a class,
05a1abfc
CD
577not about inherited ones."
578 :group 'idlwave-routine-info
579 :type 'boolean)
580
5e72c6b2
S
581(defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
582 "List of regular expressions for class-driven keyword inheritance.
583Keyword inheritance is often tied to class inheritance by \"chaining\"
584up the class tree. While it cannot be assumed that the presence of an
585_EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
586certain methods this assumption is almost always true. The methods
587for which to assume this can be set here."
588 :group 'idlwave-routine-info
589 :type '(repeat (regexp :tag "Match method:")))
31b58798 590
5e72c6b2 591
f32b3b91
CD
592(defcustom idlwave-completion-show-classes 1
593 "*Number of classes to show when completing object methods and keywords.
594When completing methods or keywords for an object with unknown class,
2e8b9c7d 595the *Completions* buffer will show the valid classes for each completion
f32b3b91
CD
596like this:
597
598MyMethod <Class1,Class2,Class3>
599
600The value of this variable may be nil to inhibit display, or an integer to
601indicate the maximum number of classes to display.
602
603On XEmacs, a full list of classes will also be placed into a `help-echo'
604property on the competion items, so that the list of classes for the current
605item is displayed in the echo area. If the value of this variable is a
606negative integer, the `help-echo' property will be suppressed."
15e42531 607 :group 'idlwave-completion
f32b3b91
CD
608 :type '(choice (const :tag "Don't show" nil)
609 (integer :tag "Number of classes shown" 1)))
610
611(defcustom idlwave-completion-fontify-classes t
612 "*Non-nil means, fontify the classes in completions buffer.
613This makes it easier to distinguish the completion items from the extra
614class info listed. See `idlwave-completion-show-classes'."
15e42531 615 :group 'idlwave-completion
f32b3b91
CD
616 :type 'boolean)
617
618(defcustom idlwave-query-class '((method-default . nil)
619 (keyword-default . nil))
620 "Association list governing specification of object classes for completion.
621
5e72c6b2
S
622When IDLWAVE tries to complete object-oriented methods, it usually
623cannot determine the class of a given object from context. In order
624to provide the user with a correct list of methods or keywords, it
76959b77
S
625needs to determine the appropriate class. IDLWAVE has two ways of
626doing this (well, three ways if you count the shell... see
627`idlwave-shell-query-for-class'):
628
6291. Combine the items of all available classes which contain this
630 method for the purpose of completion. So when completing a method,
631 all methods of all known classes are available, and when completing
632 a keyword, all keywords allowed for this method in any class are
633 shown. This behavior is very much like normal completion and is
634 therefore the default. It works much better than one might think -
635 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
636 become uncomfortably long. See also
5e72c6b2 637 `idlwave-completion-show-classes'.
f32b3b91
CD
638
6392. The second possibility is to ask the user on each occasion. To
640 make this less interruptive, IDLWAVE can store the class as a text
641 property on the object operator `->'. For a given object in the
642 source code, class selection will then be needed only once
643 - for example to complete the method. Keywords to the method can
644 then be completed directly, because the class is already known.
645 You will have to turn on the storage of the selected class
646 explicitly with the variable `idlwave-store-inquired-class'.
647
5e72c6b2
S
648This variable allows you to configure IDLWAVE's method and
649method-keyword completion behavior. Its value is an alist, which
650should contain at least two elements: (method-default . VALUE) and
facebc7b 651\(keyword-default . VALUE), where VALUE is either t or nil. These
5e72c6b2
S
652specify if the class should be found during method and keyword
653completion, respectively.
f32b3b91 654
31b58798 655The alist may have additional entries specifying exceptions from the
f32b3b91
CD
656keyword completion rule for specific methods, like INIT or
657GETPROPERTY. In order to turn on class specification for the INIT
658method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
15e42531 659 :group 'idlwave-completion
f32b3b91
CD
660 :type '(list
661 (cons (const method-default)
662 (boolean :tag "Determine class when completing METHODS "))
663 (cons (const keyword-default)
664 (boolean :tag "Determine class when completing KEYWORDS "))
665 (repeat
666 :tag "Exceptions to defaults"
667 :inline t
668 (cons (string :tag "MODULE" :value "")
669 (boolean :tag "Determine class for this method")))))
670
671(defcustom idlwave-store-inquired-class nil
672 "*Non-nil means, store class of a method call as text property on `->'.
673IDLWAVE sometimes has to ask the user for the class associated with a
674particular object method call. This happens during the commands
675`idlwave-routine-info' and `idlwave-complete', depending upon the
676value of the variable `idlwave-query-class'.
677
678When you specify a class, this information can be stored as a text
31b58798 679property on the `->' arrow in the source code, so that during the same
f32b3b91
CD
680editing session, IDLWAVE will not have to ask again. When this
681variable is non-nil, IDLWAVE will store and reuse the class information.
682The class stored can be checked and removed with `\\[idlwave-routine-info]'
683on the arrow.
684
685The default of this variable is nil, since the result of commands then
686is more predictable. However, if you know what you are doing, it can
687be nice to turn this on.
688
689An arrow which knows the class will be highlighted with
690`idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
691displays (with prefix arg: deletes) the class stored on the arrow
692at point."
15e42531 693 :group 'idlwave-completion
f32b3b91
CD
694 :type 'boolean)
695
696(defcustom idlwave-class-arrow-face 'bold
697 "*Face to highlight object operator arrows `->' which carry a class property.
698When IDLWAVE stores a class name as text property on an object arrow
facebc7b 699\(see variable `idlwave-store-inquired-class', it highlights the arrow
f32b3b91 700with this font in order to remind the user that this arrow is special."
15e42531 701 :group 'idlwave-completion
f32b3b91
CD
702 :type 'symbol)
703
704(defcustom idlwave-resize-routine-help-window t
705 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
15e42531 706 :group 'idlwave-completion
f32b3b91
CD
707 :type 'boolean)
708
709(defcustom idlwave-keyword-completion-adds-equal t
710 "*Non-nil means, completion automatically adds `=' after completed keywords."
15e42531 711 :group 'idlwave-completion
f32b3b91
CD
712 :type 'boolean)
713
714(defcustom idlwave-function-completion-adds-paren t
715 "*Non-nil means, completion automatically adds `(' after completed function.
0ff9b955 716nil means, don't add anything.
f32b3b91
CD
717A value of `2' means, also add the closing parenthesis and position cursor
718between the two."
15e42531 719 :group 'idlwave-completion
f32b3b91
CD
720 :type '(choice (const :tag "Nothing" nil)
721 (const :tag "(" t)
722 (const :tag "()" 2)))
723
724(defcustom idlwave-completion-restore-window-configuration t
725 "*Non-nil means, try to restore the window configuration after completion.
726When completion is not unique, Emacs displays a list of completions.
727This messes up your window configuration. With this variable set, IDLWAVE
728restores the old configuration after successful completion."
15e42531 729 :group 'idlwave-completion
f32b3b91
CD
730 :type 'boolean)
731
732;;; Variables for abbrev and action behavior -----------------------------
733
734(defgroup idlwave-abbrev-and-indent-action nil
735 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
736The variables in this group govern this."
737 :group 'idlwave)
738
739(defcustom idlwave-do-actions nil
740 "*Non-nil means performs actions when indenting.
741The actions that can be performed are listed in `idlwave-indent-action-table'."
742 :group 'idlwave-abbrev-and-indent-action
743 :type 'boolean)
744
745(defcustom idlwave-abbrev-start-char "\\"
746 "*A single character string used to start abbreviations in abbrev mode.
747Possible characters to chose from: ~`\%
748or even '?'. '.' is not a good choice because it can make structure
749field names act like abbrevs in certain circumstances.
750
751Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
752must set it directly using `setq' in the .emacs file before idlwave.el
753is loaded."
754 :group 'idlwave-abbrev-and-indent-action
755 :type 'string)
756
757(defcustom idlwave-surround-by-blank nil
758 "*Non-nil means, enable `idlwave-surround'.
595ab50b 759If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
f32b3b91
CD
760`idlwave-surround'.
761See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
762
763Also see the default key bindings for keys using `idlwave-surround'.
764Keys are bound and made into actions calling `idlwave-surround' with
765`idlwave-action-and-binding'.
766See help for `idlwave-action-and-binding' for examples.
767
768Also see help for `idlwave-surround'."
769 :group 'idlwave-abbrev-and-indent-action
770 :type 'boolean)
771
772(defcustom idlwave-pad-keyword t
52a244eb
S
773 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
774Whenever `idlwave-surround' is non-nil then this affects how '=' is
775padded for keywords and for variables. If t, pad the same as for
776assignments. If nil then spaces are removed. With any other value,
777spaces are left unchanged."
f32b3b91 778 :group 'idlwave-abbrev-and-indent-action
15e42531
CD
779 :type '(choice
780 (const :tag "Pad like assignments" t)
781 (const :tag "Remove space near `='" nil)
782 (const :tag "Keep space near `='" 'keep)))
f32b3b91
CD
783
784(defcustom idlwave-show-block t
785 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
786 :group 'idlwave-abbrev-and-indent-action
787 :type 'boolean)
788
789(defcustom idlwave-expand-generic-end nil
790 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
791 :group 'idlwave-abbrev-and-indent-action
792 :type 'boolean)
793
15e42531
CD
794(defcustom idlwave-reindent-end t
795 "*Non-nil means re-indent line after END was typed."
796 :group 'idlwave-abbrev-and-indent-action
797 :type 'boolean)
798
f32b3b91
CD
799(defcustom idlwave-abbrev-move t
800 "*Non-nil means the abbrev hook can move point.
801Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
802definitions, use the command `list-abbrevs', for abbrevs that move
803point. Moving point is useful, for example, to place point between
804parentheses of expanded functions.
805
806See `idlwave-check-abbrev'."
807 :group 'idlwave-abbrev-and-indent-action
808 :type 'boolean)
809
810(defcustom idlwave-abbrev-change-case nil
811 "*Non-nil means all abbrevs will be forced to either upper or lower case.
812If the value t, all expanded abbrevs will be upper case.
813If the value is 'down then abbrevs will be forced to lower case.
814If nil, the case will not change.
815If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
816upper case, regardless of this variable."
817 :group 'idlwave-abbrev-and-indent-action
818 :type 'boolean)
819
820(defcustom idlwave-reserved-word-upcase nil
821 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
822If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
823Has effect only if in abbrev-mode."
824 :group 'idlwave-abbrev-and-indent-action
825 :type 'boolean)
826
827;;; Action/Expand Tables.
828;;
829;; The average user may have difficulty modifying this directly. It
830;; can be modified/set in idlwave-mode-hook, but it is easier to use
831;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
832;; examples of how to add an action.
833;;
834;; The action table is used by `idlwave-indent-line' whereas both the
835;; action and expand tables are used by `idlwave-indent-and-action'. In
836;; general, the expand table is only used when a line is explicitly
837;; indented. Whereas, in addition to being used when the expand table
838;; is used, the action table is used when a line is indirectly
839;; indented via line splitting, auto-filling or a new line creation.
840;;
841;; Example actions:
842;;
843;; Capitalize system vars
844;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
845;;
846;; Capitalize procedure name
847;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
848;; '(capitalize-word 1) t)
849;;
850;; Capitalize common block name
851;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
852;; '(capitalize-word 1) t)
853;; Capitalize label
854;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
855;; '(capitalize-word -1) t)
856
857(defvar idlwave-indent-action-table nil
858 "*Associated array containing action lists of search string (car),
859and function as a cdr. This table is used by `idlwave-indent-line'.
860See documentation for `idlwave-do-action' for a complete description of
861the action lists.
862
863Additions to the table are made with `idlwave-action-and-binding' when a
864binding is not requested.
865See help on `idlwave-action-and-binding' for examples.")
866
867(defvar idlwave-indent-expand-table nil
868 "*Associated array containing action lists of search string (car),
869and function as a cdr. The table is used by the
870`idlwave-indent-and-action' function. See documentation for
871`idlwave-do-action' for a complete description of the action lists.
872
873Additions to the table are made with `idlwave-action-and-binding' when a
874binding is requested.
875See help on `idlwave-action-and-binding' for examples.")
876
877;;; Documentation header and history keyword ---------------------------------
878
879(defgroup idlwave-documentation nil
880 "Options for documenting IDLWAVE files."
881 :group 'idlwave)
882
883;; FIXME: make defcustom?
884(defvar idlwave-file-header
885 (list nil
886 ";+
887; NAME:
888;
889;
890;
891; PURPOSE:
892;
893;
894;
895; CATEGORY:
896;
897;
898;
899; CALLING SEQUENCE:
900;
901;
902;
903; INPUTS:
904;
905;
906;
907; OPTIONAL INPUTS:
908;
909;
910;
911; KEYWORD PARAMETERS:
912;
913;
914;
915; OUTPUTS:
916;
917;
918;
919; OPTIONAL OUTPUTS:
920;
921;
922;
923; COMMON BLOCKS:
924;
925;
926;
927; SIDE EFFECTS:
928;
929;
930;
931; RESTRICTIONS:
932;
933;
934;
935; PROCEDURE:
936;
937;
938;
939; EXAMPLE:
940;
941;
942;
943; MODIFICATION HISTORY:
944;
945;-
946")
947 "*A list (PATHNAME STRING) specifying the doc-header template to use for
948summarizing a file. If PATHNAME is non-nil then this file will be included.
0ff9b955 949Otherwise STRING is used. If nil, the file summary will be omitted.
f32b3b91
CD
950For example you might set PATHNAME to the path for the
951lib_template.pro file included in the IDL distribution.")
952
5e72c6b2
S
953(defcustom idlwave-header-to-beginning-of-file nil
954 "*Non-nil means, the documentation header will always be at start of file.
955When nil, the header is positioned between the PRO/FUNCTION line of
956the current routine and the code, allowing several routine headers in
957a file."
958 :group 'idlwave-documentation
959 :type 'boolean)
960
f32b3b91
CD
961(defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
962 "*The hook function used to update the timestamp of a function."
963 :group 'idlwave-documentation
964 :type 'function)
965
966(defcustom idlwave-doc-modifications-keyword "HISTORY"
967 "*The modifications keyword to use with the log documentation commands.
968A ':' is added to the keyword end.
969Inserted by doc-header and used to position logs by doc-modification.
970If nil it will not be inserted."
971 :group 'idlwave-documentation
972 :type 'string)
973
974(defcustom idlwave-doclib-start "^;+\\+"
975 "*Regexp matching the start of a document library header."
976 :group 'idlwave-documentation
977 :type 'regexp)
978
979(defcustom idlwave-doclib-end "^;+-"
980 "*Regexp matching the end of a document library header."
981 :group 'idlwave-documentation
982 :type 'regexp)
983
984;;; External Programs -------------------------------------------------------
985
986(defgroup idlwave-external-programs nil
05a1abfc 987 "Path locations of external commands used by IDLWAVE."
f32b3b91
CD
988 :group 'idlwave)
989
990;; WARNING: The following variable has recently been moved from
595ab50b 991;; idlw-shell.el to this file. I hope this does not break
f32b3b91
CD
992;; anything.
993
994(defcustom idlwave-shell-explicit-file-name "idl"
5e72c6b2 995 "*If non-nil, this is the command to run IDL.
f32b3b91 996Should be an absolute file path or path relative to the current environment
5e72c6b2
S
997execution search path. If you want to specify command line switches
998for the idl program, use `idlwave-shell-command-line-options'.
999
1000I know the name of this variable is badly chosen, but I cannot change
1001it without compromizing backwards-compatibility."
f32b3b91
CD
1002 :group 'idlwave-external-programs
1003 :type 'string)
1004
f32b3b91 1005(defcustom idlwave-shell-command-line-options nil
5e72c6b2
S
1006 "*A list of command line options for calling the IDL program.
1007Since IDL is executed directly without going through a shell like /bin/sh,
1008this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1009string for each argument. But you may also give a single string which
1010contains the options whitespace-separated. Emacs will be kind enough to
1011split it for you."
1012 :type '(choice
1013 string
1014 (repeat (string :value "")))
f32b3b91
CD
1015 :group 'idlwave-external-programs)
1016
1017(defcustom idlwave-help-application "idlhelp"
1018 "*The external application providing reference help for programming."
1019 :group 'idlwave-external-programs
1020 :type 'string)
1021
05a1abfc
CD
1022;;; Some Shell variables which must be defined here.-----------------------
1023
1024(defcustom idlwave-shell-debug-modifiers '()
1025 "List of modifiers to be used for the debugging commands.
1026Will be used to bind debugging commands in the shell buffer and in all
1027source buffers. These are additional convenience bindings, the debugging
1028commands are always available with the `C-c C-d' prefix.
1029If you set this to '(control shift), this means setting a breakpoint will
1030be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1031are `control', `meta', `super', `hyper', `alt', and `shift'."
1032 :group 'idlwave-shell-general-setup
1033 :type '(set :tag "Specify modifiers"
1034 (const control)
1035 (const meta)
1036 (const super)
1037 (const hyper)
1038 (const alt)
1039 (const shift)))
1040
1041(defcustom idlwave-shell-automatic-start nil
1042 "*If non-nil attempt invoke idlwave-shell if not already running.
1043This is checked when an attempt to send a command to an
1044IDL process is made."
1045 :group 'idlwave-shell-general-setup
1046 :type 'boolean)
1047
f32b3b91
CD
1048;;; Miscellaneous variables -------------------------------------------------
1049
1050(defgroup idlwave-misc nil
1051 "Miscellaneous options for IDLWAVE mode."
8ec3bce0 1052 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
f32b3b91
CD
1053 :group 'idlwave)
1054
1055(defcustom idlwave-startup-message t
1056 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1057 :group 'idlwave-misc
1058 :type 'boolean)
1059
31b58798 1060(defcustom idlwave-default-font-lock-items
facebc7b 1061 '(pros-and-functions batch-files idlwave-idl-keywords label goto
f32b3b91
CD
1062 common-blocks class-arrows)
1063 "Items which should be fontified on the default fontification level 2.
1064IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1065is everything and level 2 is specified by this list.
1066This variable must be set before IDLWAVE gets loaded. It is
1067a list of symbols, the following symbols are allowed.
1068
1069pros-and-functions Procedure and Function definitions
1070batch-files Batch Files
facebc7b 1071idlwave-idl-keywords IDL Keywords
f32b3b91
CD
1072label Statement Labels
1073goto Goto Statements
1074common-blocks Common Blocks
1075keyword-parameters Keyword Parameters in routine definitions and calls
1076system-variables System Variables
1077fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1078class-arrows Object Arrows with class property"
1079 :group 'idlwave-misc
1080 :type '(set
1081 :inline t :greedy t
1082 (const :tag "Procedure and Function definitions" pros-and-functions)
facebc7b
S
1083 (const :tag "Batch Files" batch-files)
1084 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1085 (const :tag "Statement Labels" label)
1086 (const :tag "Goto Statements" goto)
1087 (const :tag "Tags in Structure Definition" structtag)
1088 (const :tag "Structure Name" structname)
1089 (const :tag "Common Blocks" common-blocks)
1090 (const :tag "Keyword Parameters" keyword-parameters)
1091 (const :tag "System Variables" system-variables)
1092 (const :tag "FIXME: Warning" fixme)
f32b3b91
CD
1093 (const :tag "Object Arrows with class property " class-arrows)))
1094
1095(defcustom idlwave-mode-hook nil
1096 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1097 :group 'idlwave-misc
1098 :type 'hook)
1099
1100(defcustom idlwave-load-hook nil
1101 "Normal hook. Executed when idlwave.el is loaded."
1102 :group 'idlwave-misc
1103 :type 'hook)
1104
15e42531
CD
1105(defvar idlwave-experimental nil
1106 "Non-nil means turn on a few experimental features.
1107This variable is only for the maintainer, to test difficult stuff,
1108while still distributing stable releases.
1109As a user, you should not set this to t.")
1110
f32b3b91
CD
1111;;;
1112;;; End customization variables section
1113;;;
1114
1115;;; Non customization variables
1116
1117;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
52a244eb 1118;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
f32b3b91
CD
1119;;; and Carsten Dominik...
1120
76959b77 1121;; The following are the reserved words in IDL. Maybe we should
31b58798 1122;; highlight some more stuff as well?
76959b77
S
1123;; Procedure declarations. Fontify keyword plus procedure name.
1124(defvar idlwave-idl-keywords
31b58798 1125 ;; To update this regexp, update the list of keywords and
76959b77 1126 ;; evaluate the form.
31b58798 1127 ;; (insert
76959b77 1128 ;; (prin1-to-string
31b58798 1129 ;; (concat
76959b77 1130 ;; "\\<\\("
31b58798 1131 ;; (regexp-opt
52a244eb 1132 ;; '("||" "&&" "and" "or" "xor" "not"
31b58798 1133 ;; "eq" "ge" "gt" "le" "lt" "ne"
76959b77 1134 ;; "for" "do" "endfor"
31b58798 1135 ;; "if" "then" "endif" "else" "endelse"
76959b77
S
1136 ;; "case" "of" "endcase"
1137 ;; "switch" "break" "continue" "endswitch"
1138 ;; "begin" "end"
1139 ;; "repeat" "until" "endrep"
31b58798 1140 ;; "while" "endwhile"
76959b77
S
1141 ;; "goto" "return"
1142 ;; "inherits" "mod"
1143 ;; "compile_opt" "forward_function"
1144 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1145 ;; "\\)\\>")))
52a244eb
S
1146 "\\<\\(&&\\|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\\|||\\)\\>")
1147
76959b77 1148
facebc7b 1149(let* (;; Procedure declarations. Fontify keyword plus procedure name.
f32b3b91
CD
1150 ;; Function declarations. Fontify keyword plus function name.
1151 (pros-and-functions
1152 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1153 (1 font-lock-keyword-face)
1154 (2 font-lock-function-name-face nil t)))
1155
1156 ;; Common blocks
1157 (common-blocks
1158 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1159 (1 font-lock-keyword-face) ; "common"
1160 (2 font-lock-reference-face nil t) ; block name
1161 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1162 ;; Start with point after block name and comma
31b58798 1163 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
f32b3b91
CD
1164 nil
1165 (1 font-lock-variable-name-face) ; variable names
1166 )))
1167
1168 ;; Batch files
1169 (batch-files
1170 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1171
1172 ;; FIXME warning.
1173 (fixme
1174 '("\\<FIXME:" (0 font-lock-warning-face t)))
1175
1176 ;; Labels
1177 (label
1178 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1179
1180 ;; The goto statement and its label
1181 (goto
1182 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1183 (1 font-lock-keyword-face)
1184 (2 font-lock-reference-face)))
1185
52a244eb
S
1186 ;; Tags in structure definitions. Note that this definition
1187 ;; actually collides with labels, so we have to use the same
1188 ;; face. It also matches named subscript ranges,
1189 ;; e.g. vec{bottom:top]. No good way around this.
05a1abfc
CD
1190 (structtag
1191 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1192
1193 ;; Structure names
1194 (structname
1195 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1196 (2 font-lock-function-name-face)))
1197
52a244eb 1198 ;; Keyword parameters, like /xlog or ,xrange=[]
f32b3b91 1199 ;; This is anchored to the comma preceeding the keyword.
595ab50b
CD
1200 ;; Treats continuation lines, works only during whole buffer
1201 ;; fontification. Slow, use it only in fancy fontification.
f32b3b91 1202 (keyword-parameters
15e42531
CD
1203 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1204 (5 font-lock-reference-face)))
f32b3b91 1205
595ab50b 1206 ;; System variables start with a bang.
f32b3b91 1207 (system-variables
15e42531 1208 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
f32b3b91
CD
1209 (1 font-lock-variable-name-face)))
1210
1211 ;; Special and unusual operators (not used because too noisy)
1212 (special-operators
1213 '("[<>#]" (0 font-lock-keyword-face)))
1214
1215 ;; All operators (not used because too noisy)
1216 (all-operators
1217 '("[-*^#+<>/]" (0 font-lock-keyword-face)))
31b58798 1218
f32b3b91
CD
1219 ;; Arrows with text property `idlwave-class'
1220 (class-arrows
facebc7b
S
1221 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1222
1223 (defconst idlwave-font-lock-keywords-1
1224 (list pros-and-functions batch-files)
1225 "Subdued level highlighting for IDLWAVE mode.")
f32b3b91 1226
facebc7b
S
1227 (defconst idlwave-font-lock-keywords-2
1228 (mapcar 'symbol-value idlwave-default-font-lock-items)
1229 "Medium level highlighting for IDLWAVE mode.")
f32b3b91 1230
facebc7b 1231 (defconst idlwave-font-lock-keywords-3
f32b3b91
CD
1232 (list pros-and-functions
1233 batch-files
76959b77 1234 idlwave-idl-keywords
f32b3b91 1235 label goto
05a1abfc
CD
1236 structtag
1237 structname
f32b3b91
CD
1238 common-blocks
1239 keyword-parameters
1240 system-variables
facebc7b
S
1241 class-arrows)
1242 "Gaudy level highlighting for IDLWAVE mode."))
f32b3b91
CD
1243
1244(defun idlwave-match-class-arrows (limit)
1245 ;; Match an object arrow with class property
1246 (and idlwave-store-inquired-class
1247 (re-search-forward "->" limit 'limit)
1248 (get-text-property (match-beginning 0) 'idlwave-class)))
1249
1250(defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1251 "Default expressions to highlight in IDLWAVE mode.")
1252
1253(defvar idlwave-font-lock-defaults
1254 '((idlwave-font-lock-keywords
31b58798 1255 idlwave-font-lock-keywords-1
f32b3b91
CD
1256 idlwave-font-lock-keywords-2
1257 idlwave-font-lock-keywords-3)
31b58798
JB
1258 nil t
1259 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
f32b3b91
CD
1260 beginning-of-line))
1261
31b58798 1262(put 'idlwave-mode 'font-lock-defaults
f32b3b91
CD
1263 idlwave-font-lock-defaults) ; XEmacs
1264
1265(defconst idlwave-comment-line-start-skip "^[ \t]*;"
1266 "Regexp to match the start of a full-line comment.
1267That is the _beginning_ of a line containing a comment delimiter `;' preceded
1268only by whitespace.")
1269
31b58798 1270(defconst idlwave-begin-block-reg
05a1abfc 1271 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
f32b3b91
CD
1272 "Regular expression to find the beginning of a block. The case does
1273not matter. The search skips matches in comments.")
1274
52a244eb 1275(defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
f32b3b91
CD
1276 "Regular expression to find the beginning of a unit. The case does
1277not matter.")
1278
52a244eb 1279(defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
f32b3b91
CD
1280 "Regular expression to find the line that indicates the end of unit.
1281This line is the end of buffer or the start of another unit. The case does
1282not matter. The search skips matches in comments.")
1283
1284(defconst idlwave-continue-line-reg "\\<\\$"
1285 "Regular expression to match a continued line.")
1286
1287(defconst idlwave-end-block-reg
05a1abfc 1288 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
f32b3b91
CD
1289 "Regular expression to find the end of a block. The case does
1290not matter. The search skips matches found in comments.")
1291
1292(defconst idlwave-block-matches
1293 '(("pro" . "end")
1294 ("function" . "end")
1295 ("case" . "endcase")
1296 ("else" . "endelse")
1297 ("for" . "endfor")
1298 ("then" . "endif")
1299 ("repeat" . "endrep")
05a1abfc 1300 ("switch" . "endswitch")
f32b3b91
CD
1301 ("while" . "endwhile"))
1302 "Matches between statements and the corresponding END variant.
1303The cars are the reserved words starting a block. If the block really
1304begins with BEGIN, the cars are the reserved words before the begin
1305which can be used to identify the block type.
1306This is used to check for the correct END type, to close blocks and
1307to expand generic end statements to their detailed form.")
1308
1309(defconst idlwave-block-match-regexp
1310 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1311"Regular expression matching reserved words which can stand before
1312blocks starting with a BEGIN statement. The matches must have associations
1313`idlwave-block-matches'")
1314
52a244eb 1315(defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
f32b3b91
CD
1316 "Regular expression matching an IDL identifier.")
1317
1318(defconst idlwave-sysvar (concat "!" idlwave-identifier)
1319 "Regular expression matching IDL system variables.")
1320
1321(defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1322 "Regular expression matching IDL variable names.")
1323
1324(defconst idlwave-label (concat idlwave-identifier ":")
1325 "Regular expression matching IDL labels.")
1326
52a244eb
S
1327(defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1328 "\\(\\s *" idlwave-identifier "::\\)?"
1329))
1330
f32b3b91
CD
1331(defconst idlwave-statement-match
1332 (list
aa87aafc 1333 ;; "endif else" is the only possible "end" that can be
f32b3b91
CD
1334 ;; followed by a statement on the same line.
1335 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1336 ;; all other "end"s can not be followed by a statement.
1337 (cons 'end (list idlwave-end-block-reg nil))
1338 '(if . ("if\\>" "then"))
1339 '(for . ("for\\>" "do"))
1340 '(begin . ("begin\\>" nil))
1341 '(pdef . ("pro\\>\\|function\\>" nil))
1342 '(while . ("while\\>" "do"))
1343 '(repeat . ("repeat\\>" "repeat"))
1344 '(goto . ("goto\\>" nil))
1345 '(case . ("case\\>" nil))
05a1abfc 1346 '(switch . ("switch\\>" nil))
31b58798 1347 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
52a244eb
S
1348 "\\(" idlwave-method-call "\\s *\\)?"
1349 idlwave-identifier
1350 "\\s *(") nil))
31b58798 1351 (cons 'call (list (concat
52a244eb 1352 "\\(" idlwave-method-call "\\s *\\)?"
31b58798 1353 idlwave-identifier
52a244eb 1354 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
31b58798 1355 (cons 'assign (list (concat
52a244eb 1356 "\\(" idlwave-variable "\\) *=") nil)))
31b58798 1357
f32b3b91
CD
1358 "Associated list of statement matching regular expressions.
1359Each regular expression matches the start of an IDL statement. The
1360first element of each association is a symbol giving the statement
1361type. The associated value is a list. The first element of this list
1362is a regular expression matching the start of an IDL statement for
1363identifying the statement type. The second element of this list is a
1364regular expression for finding a substatement for the type. The
1365substatement starts after the end of the found match modulo
1366whitespace. If it is nil then the statement has no substatement. The
1367list order matters since matching an assignment statement exactly is
1368not possible without parsing. Thus assignment statement become just
15e42531 1369the leftover unidentified statements containing an equal sign." )
f32b3b91
CD
1370
1371(defvar idlwave-fill-function 'auto-fill-function
1372 "IDL mode auto fill function.")
1373
1374(defvar idlwave-comment-indent-function 'comment-indent-function
1375 "IDL mode comment indent function.")
1376
1377;; Note that this is documented in the v18 manuals as being a string
1378;; of length one rather than a single character.
1379;; The code in this file accepts either format for compatibility.
31b58798 1380(defvar idlwave-comment-indent-char ?\
f32b3b91
CD
1381 "Character to be inserted for IDL comment indentation.
1382Normally a space.")
1383
1384(defconst idlwave-continuation-char ?$
1385 "Character which is inserted as a last character on previous line by
1386 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1387
3938cb82 1388(defconst idlwave-mode-version "5.7_22")
f32b3b91
CD
1389
1390(defmacro idlwave-keyword-abbrev (&rest args)
1391 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
8a946354 1392 `(quote (lambda ()
5e72c6b2 1393 ,(append '(idlwave-check-abbrev) args))))
f32b3b91
CD
1394
1395;; If I take the time I can replace idlwave-keyword-abbrev with
1396;; idlwave-code-abbrev and remove the quoted abbrev check from
1397;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1398;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1399;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1400
1401(defmacro idlwave-code-abbrev (&rest args)
1402 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1403Specifically, if the abbrev is in a comment or string it is unexpanded.
1404Otherwise ARGS forms a list that is evaluated."
8a946354 1405 `(quote (lambda ()
5e72c6b2
S
1406 ,(prin1-to-string args) ;; Puts the code in the doc string
1407 (if (idlwave-quoted)
1408 (progn (unexpand-abbrev) nil)
1409 ,(append args)))))
f32b3b91
CD
1410
1411(defvar idlwave-mode-map (make-sparse-keymap)
1412 "Keymap used in IDL mode.")
1413
1414(defvar idlwave-mode-syntax-table (make-syntax-table)
1415 "Syntax table in use in `idlwave-mode' buffers.")
1416
1417(modify-syntax-entry ?+ "." idlwave-mode-syntax-table)
1418(modify-syntax-entry ?- "." idlwave-mode-syntax-table)
1419(modify-syntax-entry ?* "." idlwave-mode-syntax-table)
1420(modify-syntax-entry ?/ "." idlwave-mode-syntax-table)
1421(modify-syntax-entry ?^ "." idlwave-mode-syntax-table)
1422(modify-syntax-entry ?# "." idlwave-mode-syntax-table)
1423(modify-syntax-entry ?= "." idlwave-mode-syntax-table)
1424(modify-syntax-entry ?% "." idlwave-mode-syntax-table)
1425(modify-syntax-entry ?< "." idlwave-mode-syntax-table)
1426(modify-syntax-entry ?> "." idlwave-mode-syntax-table)
1427(modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table)
1428(modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table)
1429(modify-syntax-entry ?\\ "." idlwave-mode-syntax-table)
1430(modify-syntax-entry ?_ "_" idlwave-mode-syntax-table)
1431(modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table)
1432(modify-syntax-entry ?} "){" idlwave-mode-syntax-table)
1433(modify-syntax-entry ?$ "_" idlwave-mode-syntax-table)
1434(modify-syntax-entry ?. "." idlwave-mode-syntax-table)
1435(modify-syntax-entry ?\; "<" idlwave-mode-syntax-table)
1436(modify-syntax-entry ?\n ">" idlwave-mode-syntax-table)
1437(modify-syntax-entry ?\f ">" idlwave-mode-syntax-table)
1438
1439(defvar idlwave-find-symbol-syntax-table
1440 (copy-syntax-table idlwave-mode-syntax-table)
1441 "Syntax table that treats symbol characters as word characters.")
1442
05a1abfc
CD
1443(modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1444(modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1445(modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table)
1446(modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table)
1447
76959b77
S
1448(defmacro idlwave-with-special-syntax (&rest body)
1449 "Execute BODY with a different syntax table."
05a1abfc
CD
1450 `(let ((saved-syntax (syntax-table)))
1451 (unwind-protect
1452 (progn
1453 (set-syntax-table idlwave-find-symbol-syntax-table)
1454 ,@body)
1455 (set-syntax-table saved-syntax))))
1456
76959b77
S
1457;(defmacro idlwave-with-special-syntax1 (&rest body)
1458; "Execute BODY with a different syntax table."
1459; `(let ((saved-syntax (syntax-table)))
1460; (unwind-protect
1461; (progn
1462; (set-syntax-table idlwave-find-symbol-syntax-table)
1463; ,@body)
1464; (set-syntax-table saved-syntax))))
1465
f32b3b91
CD
1466(defun idlwave-action-and-binding (key cmd &optional select)
1467 "KEY and CMD are made into a key binding and an indent action.
1468KEY is a string - same as for the `define-key' function. CMD is a
1469function of no arguments or a list to be evaluated. CMD is bound to
1470KEY in `idlwave-mode-map' by defining an anonymous function calling
1471`self-insert-command' followed by CMD. If KEY contains more than one
1472character a binding will only be set if SELECT is 'both.
1473
5e72c6b2 1474\(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
f32b3b91
CD
1475replacing any previous value for KEY. If a binding is not set then it
1476will instead be placed in `idlwave-indent-action-table'.
1477
1478If the optional argument SELECT is nil then an action and binding are
1479created. If SELECT is 'noaction, then a binding is always set and no
1480action is created. If SELECT is 'both then an action and binding
1481will both be created even if KEY contains more than one character.
1482Otherwise, if SELECT is non-nil then only an action is created.
1483
1484Some examples:
1485No spaces before and 1 after a comma
1486 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1487A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1488 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1489Capitalize system variables - action only
1490 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1491 (if (not (equal select 'noaction))
1492 ;; Add action
1493 (let* ((table (if select 'idlwave-indent-action-table
1494 'idlwave-indent-expand-table))
3938cb82
S
1495 (table-key (regexp-quote key))
1496 (cell (assoc table-key (eval table))))
f32b3b91
CD
1497 (if cell
1498 ;; Replace action command
1499 (setcdr cell cmd)
1500 ;; New action
3938cb82 1501 (set table (append (eval table) (list (cons table-key cmd)))))))
f32b3b91
CD
1502 ;; Make key binding for action
1503 (if (or (and (null select) (= (length key) 1))
1504 (equal select 'noaction)
1505 (equal select 'both))
1506 (define-key idlwave-mode-map key
1507 (append '(lambda ()
1508 (interactive)
1509 (self-insert-command 1))
1510 (list (if (listp cmd)
1511 cmd
1512 (list cmd)))))))
1513
1514(fset 'idlwave-debug-map (make-sparse-keymap))
1515
595ab50b 1516(define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab)
15e42531 1517(define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab)
595ab50b 1518;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
f32b3b91
CD
1519(define-key idlwave-mode-map "'" 'idlwave-show-matching-quote)
1520(define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote)
76959b77 1521(define-key idlwave-mode-map "\C-g" 'idlwave-keyboard-quit)
f32b3b91
CD
1522(define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region)
1523(define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1524(define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram)
1525(define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block)
1526(define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block)
1527(define-key idlwave-mode-map "\C-c]" 'idlwave-close-block)
3938cb82 1528(define-key idlwave-mode-map [(meta control h)] 'idlwave-mark-subprogram)
f32b3b91
CD
1529(define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block)
1530(define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block)
1531(define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block)
1532(define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block)
1533(define-key idlwave-mode-map "\M-\r" 'idlwave-split-line)
1534(define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram)
1535(define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement)
1536(define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
1537;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1538;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
76959b77 1539(define-key idlwave-mode-map [(shift tab)] 'idlwave-indent-statement)
f32b3b91
CD
1540(define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
1541(define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph)
1542(define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde)
1543(define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header)
1544(define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification)
1545(define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case)
1546(define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map)
05a1abfc
CD
1547(when (and (boundp 'idlwave-shell-debug-modifiers)
1548 (listp idlwave-shell-debug-modifiers)
1549 (not (equal idlwave-shell-debug-modifiers '())))
1550 ;; Bind the debug commands also with the special modifiers.
1551 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
31b58798 1552 (mods-noshift (delq 'shift
05a1abfc 1553 (copy-sequence idlwave-shell-debug-modifiers))))
31b58798 1554 (define-key idlwave-mode-map
05a1abfc
CD
1555 (vector (append mods-noshift (list (if shift ?C ?c))))
1556 'idlwave-shell-save-and-run)
31b58798 1557 (define-key idlwave-mode-map
05a1abfc 1558 (vector (append mods-noshift (list (if shift ?B ?b))))
52a244eb 1559 'idlwave-shell-break-here)
31b58798 1560 (define-key idlwave-mode-map
52a244eb
S
1561 (vector (append mods-noshift (list (if shift ?E ?e))))
1562 'idlwave-shell-run-region)))
1563(define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1564(define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1565(define-key idlwave-mode-map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
f32b3b91
CD
1566(define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for)
1567;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1568;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1569(define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat)
1570(define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while)
15e42531 1571(define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
f32b3b91
CD
1572(define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell)
1573(define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
15e42531 1574(define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
22d5821d
CD
1575(autoload 'idlwave-shell "idlw-shell"
1576 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
8c7b4ec8
EZ
1577(autoload 'idlwave-shell-send-command "idlw-shell")
1578(autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
f32b3b91 1579 "Run `idlwave-shell' and switch back to current window" t)
8c7b4ec8 1580(autoload 'idlwave-shell-save-and-run "idlw-shell"
f32b3b91 1581 "Save and run buffer under the shell." t)
15e42531
CD
1582(autoload 'idlwave-shell-break-here "idlw-shell"
1583 "Set breakpoint in current line." t)
52a244eb
S
1584(autoload 'idlwave-shell-run-region "idlw-shell"
1585 "Compile and run the region." t)
f32b3b91 1586(define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module)
3938cb82 1587(define-key idlwave-mode-map "\C-c\C-t" 'idlwave-find-module-this-file)
f32b3b91 1588(define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info)
15e42531 1589(define-key idlwave-mode-map "\M-?" 'idlwave-context-help)
76959b77 1590(define-key idlwave-mode-map [(control meta ?\?)] 'idlwave-online-help)
52a244eb 1591;; Pickup both forms of Esc/Meta binding
f32b3b91 1592(define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
52a244eb
S
1593(define-key idlwave-mode-map [?\e?\t] 'idlwave-complete)
1594(define-key idlwave-mode-map "\M-\C-i" 'idlwave-complete)
1595(define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
1596(define-key idlwave-mode-map "\C-c=" 'idlwave-resolve)
31b58798 1597(define-key idlwave-mode-map
15e42531
CD
1598 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1599 'idlwave-mouse-context-help)
f32b3b91
CD
1600
1601;; Set action and key bindings.
1602;; See description of the function `idlwave-action-and-binding'.
1603;; Automatically add spaces for the following characters
52a244eb
S
1604;(idlwave-action-and-binding "&" '(idlwave-surround -1 -1 '(?&) 1
1605; (lambda (char) 0)))
f32b3b91 1606(idlwave-action-and-binding "<" '(idlwave-surround -1 -1))
5e72c6b2 1607;; Binding works for both > and ->, by changing the length of the token.
31b58798 1608(idlwave-action-and-binding ">" '(idlwave-surround -1 -1 '(?-) 1
5e72c6b2
S
1609 'idlwave-gtr-pad-hook))
1610(idlwave-action-and-binding "->" '(idlwave-surround -1 -1 nil 2) t)
f32b3b91 1611(idlwave-action-and-binding "," '(idlwave-surround 0 -1))
52a244eb 1612
f32b3b91
CD
1613;; Automatically add spaces to equal sign if not keyword
1614(idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1615
1616;;;
1617;;; Abbrev Section
1618;;;
1619;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1620;;; space is inserted (this is the space typed by the user to expanded
1621;;; the abbrev).
1622;;;
5e72c6b2
S
1623(defvar idlwave-mode-abbrev-table nil
1624 "Abbreviation table used for IDLWAVE mode")
1625(define-abbrev-table 'idlwave-mode-abbrev-table ())
1626
1627(defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1628 "Define-abbrev with backward compatibility.
1629
1630If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1631idlwave-mode-abbrev-table unless TABLE is non-nil."
1632 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1633 (args (list (or table idlwave-mode-abbrev-table)
1634 (if noprefix name (concat idlwave-abbrev-start-char name))
1635 expansion
1636 hook)))
1637 (condition-case nil
1638 (apply 'define-abbrev (append args '(0 t)))
1639 (error (apply 'define-abbrev args)))))
f32b3b91
CD
1640
1641(condition-case nil
31b58798 1642 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
f32b3b91
CD
1643 "w" idlwave-mode-syntax-table)
1644 (error nil))
1645
5e72c6b2
S
1646;;
1647;; Templates
1648;;
1649(idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1650(idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1651(idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1652(idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1653(idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1654(idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1655(idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1656(idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1657(idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1658;;
1659;; Keywords, system functions, conversion routines
1660;;
1661(idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1662(idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1663(idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1664(idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1665(idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1666(idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1667(idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1668(idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1669(idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1670(idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1671(idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1672(idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1673(idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1674(idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1675(idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1676(idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1677(idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1678(idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1679(idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1680(idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1681(idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1682(idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1683(idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1684(idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1685(idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1686(idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1687(idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1688(idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1689(idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1690(idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1691(idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1692(idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1693(idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1694(idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1695(idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1696(idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1697(idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1698(idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1699(idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1700(idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1701(idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1702(idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1703(idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1704(idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1705(idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1706(idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1707(idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1708(idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1709(idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1710(idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1711(idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1712(idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1713(idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1714(idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
3938cb82
S
1715(idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1716(idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
ff689efd 1717
5e72c6b2
S
1718;; This section is reserved words only. (From IDL user manual)
1719;;
1720(idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1721(idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1722(idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1723(idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1724(idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1725(idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1726(idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1727(idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1728(idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1729(idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1730(idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1731(idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1732(idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1733(idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1734(idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1735(idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1736(idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1737(idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1738(idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1739(idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1740(idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1741(idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1742(idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1743(idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1744(idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1745(idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1746(idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1747(idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1748(idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1749(idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1750(idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1751(idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1752(idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1753(idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1754(idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1755(idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1756(idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1757(idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1758(idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
f32b3b91
CD
1759
1760(defvar imenu-create-index-function)
1761(defvar extract-index-name-function)
1762(defvar prev-index-position-function)
1763(defvar imenu-extract-index-name-function)
1764(defvar imenu-prev-index-position-function)
5e72c6b2 1765;; defined later - so just make the compiler hush
31b58798 1766(defvar idlwave-mode-menu)
f32b3b91
CD
1767(defvar idlwave-mode-debug-menu)
1768
1769;;;###autoload
1770(defun idlwave-mode ()
3938cb82 1771 "Major mode for editing IDL source files (version 5.7_22).
f32b3b91
CD
1772
1773The main features of this mode are
1774
17751. Indentation and Formatting
1776 --------------------------
1777 Like other Emacs programming modes, C-j inserts a newline and indents.
1778 TAB is used for explicit indentation of the current line.
1779
5e72c6b2
S
1780 To start a continuation line, use \\[idlwave-split-line]. This
1781 function can also be used in the middle of a line to split the line
1782 at that point. When used inside a long constant string, the string
1783 is split at that point with the `+' concatenation operator.
f32b3b91
CD
1784
1785 Comments are indented as follows:
1786
1787 `;;;' Indentation remains unchanged.
1788 `;;' Indent like the surrounding code
1789 `;' Indent to a minimum column.
1790
1791 The indentation of comments starting in column 0 is never changed.
1792
5e72c6b2
S
1793 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1794 comment. The indentation of the second line of the paragraph
1795 relative to the first will be retained. Use
1796 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1797 comments. When the variable `idlwave-fill-comment-line-only' is
52a244eb 1798 nil, code can also be auto-filled and auto-indented.
f32b3b91
CD
1799
1800 To convert pre-existing IDL code to your formatting style, mark the
5e72c6b2
S
1801 entire buffer with \\[mark-whole-buffer] and execute
1802 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1803 again followed by \\[indent-region] (`indent-region').
f32b3b91
CD
1804
18052. Routine Info
1806 ------------
5e72c6b2
S
1807 IDLWAVE displays information about the calling sequence and the
1808 accepted keyword parameters of a procedure or function with
1809 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1810 source file of a module. These commands know about system
1811 routines, all routines in idlwave-mode buffers and (when the
1812 idlwave-shell is active) about all modules currently compiled under
52a244eb
S
1813 this shell. It also makes use of pre-compiled or custom-scanned
1814 user and library catalogs many popular libraries ship with by
1815 default. Use \\[idlwave-update-routine-info] to update this
15e42531
CD
1816 information, which is also used for completion (see item 4).
1817
18183. Online IDL Help
1819 ---------------
1820 \\[idlwave-context-help] displays the IDL documentation relevant
52a244eb
S
1821 for the system variable, keyword, or routine at point. A single
1822 key stroke gets you directly to the right place in the docs. The
1823 HTML help files package must be installed for this to work -- check
1824 the IDLWAVE webpage for the correct package for your version. See
1825 the manual to configure where and how the HTML help is displayed.
f32b3b91 1826
15e42531 18274. Completion
f32b3b91 1828 ----------
15e42531 1829 \\[idlwave-complete] completes the names of procedures, functions
52a244eb
S
1830 class names, keyword parameters, system variables and tags, class
1831 tags, structure tags, filenames and much more. It is context
1832 sensitive and figures out what is expected at point. Lower case
1833 strings are completed in lower case, other strings in mixed or
1834 upper case.
f32b3b91 1835
15e42531 18365. Code Templates and Abbreviations
f32b3b91
CD
1837 --------------------------------
1838 Many Abbreviations are predefined to expand to code fragments and templates.
1839 The abbreviations start generally with a `\\`. Some examples
1840
1841 \\pr PROCEDURE template
1842 \\fu FUNCTION template
1843 \\c CASE statement template
05a1abfc 1844 \\sw SWITCH statement template
f32b3b91
CD
1845 \\f FOR loop template
1846 \\r REPEAT Loop template
1847 \\w WHILE loop template
1848 \\i IF statement template
1849 \\elif IF-ELSE statement template
1850 \\b BEGIN
31b58798 1851
52a244eb
S
1852 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1853 have direct keybindings - see the list of keybindings below.
775591f7 1854
52a244eb
S
1855 \\[idlwave-doc-header] inserts a documentation header at the
1856 beginning of the current program unit (pro, function or main).
1857 Change log entries can be added to the current program unit with
1858 \\[idlwave-doc-modification].
f32b3b91 1859
15e42531 18606. Automatic Case Conversion
f32b3b91
CD
1861 -------------------------
1862 The case of reserved words and some abbrevs is controlled by
1863 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1864
15e42531 18657. Automatic END completion
f32b3b91
CD
1866 ------------------------
1867 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1868 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1869
15e42531 18708. Hooks
f32b3b91
CD
1871 -----
1872 Loading idlwave.el runs `idlwave-load-hook'.
1873 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1874
15e42531 18759. Documentation and Customization
f32b3b91 1876 -------------------------------
5e72c6b2
S
1877 Info documentation for this package is available. Use
1878 \\[idlwave-info] to display (complain to your sysadmin if that does
1879 not work). For Postscript, PDF, and HTML versions of the
1880 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
f32b3b91
CD
1881 IDLWAVE has customize support - see the group `idlwave'.
1882
15e42531 188310.Keybindings
f32b3b91
CD
1884 -----------
1885 Here is a list of all keybindings of this mode.
1886 If some of the key bindings below show with ??, use \\[describe-key]
1887 followed by the key sequence to see what the key sequence does.
1888
1889\\{idlwave-mode-map}"
1890
1891 (interactive)
1892 (kill-all-local-variables)
31b58798 1893
f32b3b91
CD
1894 (if idlwave-startup-message
1895 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1896 (setq idlwave-startup-message nil)
31b58798 1897
f32b3b91
CD
1898 (setq local-abbrev-table idlwave-mode-abbrev-table)
1899 (set-syntax-table idlwave-mode-syntax-table)
31b58798 1900
f32b3b91 1901 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
31b58798 1902
f32b3b91
CD
1903 (make-local-variable idlwave-comment-indent-function)
1904 (set idlwave-comment-indent-function 'idlwave-comment-hook)
31b58798 1905
f32b3b91
CD
1906 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1907 (set (make-local-variable 'comment-start) ";")
44825abf 1908 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
f32b3b91
CD
1909 (set (make-local-variable 'abbrev-all-caps) t)
1910 (set (make-local-variable 'indent-tabs-mode) nil)
1911 (set (make-local-variable 'completion-ignore-case) t)
31b58798 1912
f32b3b91
CD
1913 (use-local-map idlwave-mode-map)
1914
1915 (when (featurep 'easymenu)
1916 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1917 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1918
1919 (setq mode-name "IDLWAVE")
1920 (setq major-mode 'idlwave-mode)
1921 (setq abbrev-mode t)
31b58798 1922
f32b3b91
CD
1923 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1924 (setq comment-end "")
1925 (set (make-local-variable 'comment-multi-line) nil)
31b58798 1926 (set (make-local-variable 'paragraph-separate)
5e72c6b2 1927 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
f32b3b91
CD
1928 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1929 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
76959b77 1930 (set (make-local-variable 'parse-sexp-ignore-comments) t)
775591f7 1931
f32b3b91
CD
1932 ;; Set tag table list to use IDLTAGS as file name.
1933 (if (boundp 'tag-table-alist)
1934 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
31b58798 1935
f32b3b91 1936 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
52a244eb 1937 ;; Following line is for Emacs - XEmacs uses the corresponding property
f32b3b91
CD
1938 ;; on the `idlwave-mode' symbol.
1939 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1940
1941 ;; Imenu setup
1942 (set (make-local-variable 'imenu-create-index-function)
1943 'imenu-default-create-index-function)
1944 (set (make-local-variable 'imenu-extract-index-name-function)
1945 'idlwave-unit-name)
1946 (set (make-local-variable 'imenu-prev-index-position-function)
1947 'idlwave-prev-index-position)
1948
1949 ;; Make a local post-command-hook and add our hook to it
15e42531
CD
1950 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1951
1952 ;; Make local hooks for buffer updates
15e42531 1953 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
15e42531
CD
1954 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1955 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1956
52a244eb
S
1957 ;; Setup directories and file, if necessary
1958 (idlwave-setup)
1959
15e42531
CD
1960 ;; Update the routine info with info about current buffer?
1961 (idlwave-new-buffer-update)
f32b3b91
CD
1962
1963 ;; Run the mode hook
9a969196 1964 (run-mode-hooks 'idlwave-mode-hook))
f32b3b91 1965
52a244eb
S
1966(defvar idlwave-setup-done nil)
1967(defun idlwave-setup ()
1968 (unless idlwave-setup-done
1969 (if (not (file-directory-p idlwave-config-directory))
1970 (make-directory idlwave-config-directory))
31b58798
JB
1971 (setq idlwave-user-catalog-file (expand-file-name
1972 idlwave-user-catalog-file
52a244eb 1973 idlwave-config-directory)
31b58798
JB
1974 idlwave-path-file (expand-file-name
1975 idlwave-path-file
52a244eb
S
1976 idlwave-config-directory))
1977 (idlwave-read-paths) ; we may need these early
1978 (setq idlwave-setup-done t)))
1979
f32b3b91 1980;;
52a244eb 1981;; Code Formatting ----------------------------------------------------
31b58798 1982;;
f32b3b91
CD
1983
1984(defun idlwave-push-mark (&rest rest)
1985 "Push mark for compatibility with Emacs 18/19."
1986 (if (fboundp 'iconify-frame)
1987 (apply 'push-mark rest)
1988 (push-mark)))
1989
1990(defun idlwave-hard-tab ()
1991 "Inserts TAB in buffer in current position."
1992 (interactive)
1993 (insert "\t"))
1994
1995;;; This stuff is experimental
1996
1997(defvar idlwave-command-hook nil
1998 "If non-nil, a list that can be evaluated using `eval'.
1999It is evaluated in the lisp function `idlwave-command-hook' which is
2000placed in `post-command-hook'.")
2001
2002(defun idlwave-command-hook ()
2003 "Command run after every command.
2004Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2005sets the variable to zero afterwards."
2006 (and idlwave-command-hook
2007 (listp idlwave-command-hook)
2008 (condition-case nil
2009 (eval idlwave-command-hook)
2010 (error nil)))
2011 (setq idlwave-command-hook nil))
2012
2013;;; End experiment
2014
2015;; It would be better to use expand.el for better abbrev handling and
2016;; versatility.
2017
2018(defun idlwave-check-abbrev (arg &optional reserved)
2019 "Reverses abbrev expansion if in comment or string.
2020Argument ARG is the number of characters to move point
2021backward if `idlwave-abbrev-move' is non-nil.
2022If optional argument RESERVED is non-nil then the expansion
2023consists of reserved words, which will be capitalized if
2024`idlwave-reserved-word-upcase' is non-nil.
2025Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2026is non-nil, unless its value is \`down in which case the abbrev will be
2027made into all lowercase.
2028Returns non-nil if abbrev is left expanded."
2029 (if (idlwave-quoted)
2030 (progn (unexpand-abbrev)
2031 nil)
2032 (if (and reserved idlwave-reserved-word-upcase)
2033 (upcase-region last-abbrev-location (point))
2034 (cond
2035 ((equal idlwave-abbrev-change-case 'down)
2036 (downcase-region last-abbrev-location (point)))
2037 (idlwave-abbrev-change-case
2038 (upcase-region last-abbrev-location (point)))))
2039 (if (and idlwave-abbrev-move (> arg 0))
2040 (if (boundp 'post-command-hook)
2041 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2042 (backward-char arg)))
2043 t))
2044
2045(defun idlwave-in-comment ()
2046 "Returns t if point is inside a comment, nil otherwise."
2047 (save-excursion
2048 (let ((here (point)))
2049 (and (idlwave-goto-comment) (> here (point))))))
2050
2051(defun idlwave-goto-comment ()
2052 "Move to start of comment delimiter on current line.
2053Moves to end of line if there is no comment delimiter.
2054Ignores comment delimiters in strings.
2055Returns point if comment found and nil otherwise."
2056 (let ((eos (progn (end-of-line) (point)))
2057 (data (match-data))
2058 found)
2059 ;; Look for first comment delimiter not in a string
2060 (beginning-of-line)
2061 (setq found (search-forward comment-start eos 'lim))
2062 (while (and found (idlwave-in-quote))
2063 (setq found (search-forward comment-start eos 'lim)))
2064 (store-match-data data)
2065 (and found (not (idlwave-in-quote))
2066 (progn
2067 (backward-char 1)
2068 (point)))))
2069
5e72c6b2
S
2070(defvar transient-mark-mode)
2071(defvar zmacs-regions)
2072(defvar mark-active)
2073(defun idlwave-region-active-p ()
52a244eb 2074 "Is transient-mark-mode on and the region active?
5e72c6b2
S
2075Works on both Emacs and XEmacs."
2076 (if (featurep 'xemacs)
2077 (and zmacs-regions (region-active-p))
2078 (and transient-mark-mode mark-active)))
2079
f32b3b91
CD
2080(defun idlwave-show-matching-quote ()
2081 "Insert quote and show matching quote if this is end of a string."
2082 (interactive)
2083 (let ((bq (idlwave-in-quote))
2084 (inq last-command-char))
2085 (if (and bq (not (idlwave-in-comment)))
2086 (let ((delim (char-after bq)))
2087 (insert inq)
2088 (if (eq inq delim)
2089 (save-excursion
2090 (goto-char bq)
2091 (sit-for 1))))
2092 ;; Not the end of a string
2093 (insert inq))))
2094
2095(defun idlwave-show-begin-check ()
2096 "Ensure that the previous word was a token before `idlwave-show-begin'.
2097An END token must be preceded by whitespace."
5e72c6b2
S
2098 (if (not (idlwave-quoted))
2099 (if
2100 (save-excursion
2101 (backward-word 1)
2102 (backward-char 1)
2103 (looking-at "[ \t\n\f]"))
2104 (idlwave-show-begin))))
f32b3b91
CD
2105
2106(defun idlwave-show-begin ()
2107 "Finds the start of current block and blinks to it for a second.
2108Also checks if the correct end statement has been used."
2109 ;; All end statements are reserved words
76959b77 2110 ;; Re-indent end line
52a244eb
S
2111 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2112 ;;(backward-char 1)
76959b77
S
2113 (let* ((pos (point-marker))
2114 (last-abbrev-marker (copy-marker last-abbrev-location))
2115 (eol-pos (save-excursion (end-of-line) (point)))
2116 begin-pos end-pos end end1 )
2117 (if idlwave-reindent-end (idlwave-indent-line))
52a244eb 2118 (setq last-abbrev-location (marker-position last-abbrev-marker))
f32b3b91
CD
2119 (when (and (idlwave-check-abbrev 0 t)
2120 idlwave-show-block)
2121 (save-excursion
2122 ;; Move inside current block
76959b77 2123 (goto-char last-abbrev-marker)
f32b3b91 2124 (idlwave-block-jump-out -1 'nomark)
76959b77
S
2125 (setq begin-pos (point))
2126 (idlwave-block-jump-out 1 'nomark)
2127 (setq end-pos (point))
2128 (if (> end-pos eol-pos)
2129 (setq end-pos pos))
2130 (goto-char end-pos)
31b58798 2131 (setq end (buffer-substring
76959b77
S
2132 (progn
2133 (skip-chars-backward "a-zA-Z")
2134 (point))
2135 end-pos))
2136 (goto-char begin-pos)
f32b3b91
CD
2137 (when (setq end1 (cdr (idlwave-block-master)))
2138 (cond
5e72c6b2 2139 ((null end1)) ; no-operation
f32b3b91
CD
2140 ((string= (downcase end) (downcase end1))
2141 (sit-for 1))
2142 ((string= (downcase end) "end")
2143 ;; A generic end
2144 (if idlwave-expand-generic-end
2145 (save-excursion
2146 (goto-char pos)
2147 (backward-char 3)
2148 (insert (if (string= end "END") (upcase end1) end1))
2149 (delete-char 3)))
2150 (sit-for 1))
2151 (t
2152 (beep)
31b58798 2153 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
f32b3b91 2154 end1 end)
52a244eb
S
2155 (sit-for 1))))))))
2156 ;;(delete-char 1))
f32b3b91
CD
2157
2158(defun idlwave-block-master ()
2159 (let ((case-fold-search t))
2160 (save-excursion
2161 (cond
05a1abfc 2162 ((looking-at "pro\\|case\\|switch\\|function\\>")
f32b3b91
CD
2163 (assoc (downcase (match-string 0)) idlwave-block-matches))
2164 ((looking-at "begin\\>")
31b58798
JB
2165 (let ((limit (save-excursion
2166 (idlwave-beginning-of-statement)
f32b3b91
CD
2167 (point))))
2168 (cond
52a244eb
S
2169 ((re-search-backward ":[ \t]*\\=" limit t)
2170 ;; seems to be a case thing
2171 '("begin" . "end"))
f32b3b91
CD
2172 ((re-search-backward idlwave-block-match-regexp limit t)
2173 (assoc (downcase (match-string 1))
2174 idlwave-block-matches))
f32b3b91 2175 (t
52a244eb 2176 ;; Just a normal block
f32b3b91
CD
2177 '("begin" . "end")))))
2178 (t nil)))))
2179
2180(defun idlwave-close-block ()
2181 "Terminate the current block with the correct END statement."
2182 (interactive)
2183
2184 ;; Start new line if we are not in a new line
2185 (unless (save-excursion
2186 (skip-chars-backward " \t")
2187 (bolp))
2188 (let ((idlwave-show-block nil))
2189 (newline-and-indent)))
5e72c6b2
S
2190 (let ((last-abbrev-location (point))) ; for upcasing
2191 (insert "end")
2192 (idlwave-show-begin)))
2193
31b58798 2194(defun idlwave-gtr-pad-hook (char)
5e72c6b2 2195 "Let the > symbol expand around -> if present. The new token length
31b58798 2196is returned."
5e72c6b2 2197 2)
f32b3b91 2198
5e72c6b2 2199(defun idlwave-surround (&optional before after escape-chars length ec-hook)
595ab50b
CD
2200 "Surround the LENGTH characters before point with blanks.
2201LENGTH defaults to 1.
f32b3b91 2202Optional arguments BEFORE and AFTER affect the behavior before and
595ab50b
CD
2203after the characters (see also description of `idlwave-make-space'):
2204
2205nil do nothing
22060 force no spaces
2207integer > 0 force exactly n spaces
2208integer < 0 at least |n| spaces
f32b3b91
CD
2209
2210The function does nothing if any of the following conditions is true:
2211- `idlwave-surround-by-blank' is nil
2212- the character before point is inside a string or comment
595ab50b
CD
2213- the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2214 This hack is used to avoid padding of `>' when it is part of
5e72c6b2
S
2215 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2216
2217If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2218the named function will be called with a single argument of the
2219preceeding character. Then idlwave-surround will run as usual if
2220EC-HOOK returns non-nil, and a new length will be taken from the
2221return value."
2222 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2223 (let* ((length (or length 1)) ; establish a default for LENGTH
2224 (prev-char (char-after (- (point) (1+ length)))))
2225 (when (or (not (memq prev-char escape-chars))
31b58798
JB
2226 (and (fboundp ec-hook)
2227 (setq length
5e72c6b2
S
2228 (save-excursion (funcall ec-hook prev-char)))))
2229 (backward-char length)
2230 (save-restriction
2231 (let ((here (point)))
2232 (skip-chars-backward " \t")
2233 (if (bolp)
2234 ;; avoid clobbering indent
2235 (progn
2236 (move-to-column (idlwave-calculate-indent))
2237 (if (<= (point) here)
2238 (narrow-to-region (point) here))
2239 (goto-char here)))
2240 (idlwave-make-space before))
2241 (skip-chars-forward " \t"))
2242 (forward-char length)
2243 (idlwave-make-space after)
2244 ;; Check to see if the line should auto wrap
2245 (if (and (equal (char-after (1- (point))) ?\ )
2246 (> (current-column) fill-column))
2247 (funcall auto-fill-function))))))
f32b3b91
CD
2248
2249(defun idlwave-make-space (n)
2250 "Make space at point.
2251The space affected is all the spaces and tabs around point.
2252If n is non-nil then point is left abs(n) spaces from the beginning of
2253the contiguous space.
2254The amount of space at point is determined by N.
2255If the value of N is:
2256nil - do nothing.
595ab50b
CD
2257> 0 - exactly N spaces.
2258< 0 - a minimum of -N spaces, i.e., do not change if there are
2259 already -N spaces.
22600 - no spaces (i.e. remove any existing space)."
f32b3b91
CD
2261 (if (integerp n)
2262 (let
2263 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2264 (left (point))
2265 (end-col (progn (skip-chars-forward " \t") (current-column))))
2266 (delete-horizontal-space)
2267 (cond
2268 ((> n 0)
2269 (idlwave-indent-to (+ start-col n))
2270 (goto-char (+ left n)))
2271 ((< n 0)
2272 (idlwave-indent-to end-col (- n))
2273 (goto-char (- left n)))
2274 ;; n = 0, done
2275 ))))
2276
2277(defun idlwave-newline ()
2278 "Inserts a newline and indents the current and previous line."
2279 (interactive)
2280 ;;
2281 ;; Handle unterminated single and double quotes
2282 ;; If not in a comment and in a string then insertion of a newline
2283 ;; will mean unbalanced quotes.
2284 ;;
2285 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2286 (progn (beep)
2287 (message "Warning: unbalanced quotes?")))
2288 (newline)
2289 ;;
2290 ;; The current line is being split, the cursor should be at the
2291 ;; beginning of the new line skipping the leading indentation.
2292 ;;
2293 ;; The reason we insert the new line before indenting is that the
2294 ;; indenting could be confused by keywords (e.g. END) on the line
2295 ;; after the split point. This prevents us from just using
2296 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2297 ;;
2298 (beginning-of-line 0)
2299 (idlwave-indent-line)
2300 (forward-line)
2301 (idlwave-indent-line))
2302
2303;;
2304;; Use global variable 'comment-column' to set parallel comment
2305;;
2306;; Modeled on lisp.el
2307;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2308(defun idlwave-comment-hook ()
2309 "Compute indent for the beginning of the IDL comment delimiter."
2310 (if (or (looking-at idlwave-no-change-comment)
2311 (if idlwave-begin-line-comment
2312 (looking-at idlwave-begin-line-comment)
2313 (looking-at "^;")))
2314 (current-column)
2315 (if (looking-at idlwave-code-comment)
2316 (if (save-excursion (skip-chars-backward " \t") (bolp))
2317 ;; On line by itself, indent as code
2318 (let ((tem (idlwave-calculate-indent)))
2319 (if (listp tem) (car tem) tem))
2320 ;; after code - do not change
2321 (current-column))
2322 (skip-chars-backward " \t")
2323 (max (if (bolp) 0 (1+ (current-column)))
2324 comment-column))))
2325
2326(defun idlwave-split-line ()
2327 "Continue line by breaking line at point and indent the lines.
2328For a code line insert continuation marker. If the line is a line comment
2329then the new line will contain a comment with the same indentation.
2330Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2331non-nil."
2332 (interactive)
15e42531
CD
2333 ;; Expand abbreviation, just like normal RET would.
2334 (and abbrev-mode (expand-abbrev))
f32b3b91
CD
2335 (let (beg)
2336 (if (not (idlwave-in-comment))
2337 ;; For code line add continuation.
2338 ;; Check if splitting a string.
2339 (progn
2340 (if (setq beg (idlwave-in-quote))
2341 (if idlwave-split-line-string
2342 ;; Split the string.
2343 (progn (insert (setq beg (char-after beg)) " + "
2344 idlwave-continuation-char beg)
5e72c6b2
S
2345 (backward-char 1)
2346 (newline-and-indent)
2347 (forward-char 1))
f32b3b91
CD
2348 ;; Do not split the string.
2349 (beep)
2350 (message "Warning: continuation inside string!!")
2351 (insert " " idlwave-continuation-char))
2352 ;; Not splitting a string.
15e42531
CD
2353 (if (not (member (char-before) '(?\ ?\t)))
2354 (insert " "))
5e72c6b2
S
2355 (insert idlwave-continuation-char)
2356 (newline-and-indent)))
f32b3b91
CD
2357 (indent-new-comment-line))
2358 ;; Indent previous line
2359 (setq beg (- (point-max) (point)))
2360 (forward-line -1)
2361 (idlwave-indent-line)
2362 (goto-char (- (point-max) beg))
2363 ;; Reindent new line
2364 (idlwave-indent-line)))
2365
2366(defun idlwave-beginning-of-subprogram ()
2367 "Moves point to the beginning of the current program unit."
2368 (interactive)
2369 (idlwave-find-key idlwave-begin-unit-reg -1))
2370
2371(defun idlwave-end-of-subprogram ()
2372 "Moves point to the start of the next program unit."
2373 (interactive)
2374 (idlwave-end-of-statement)
2375 (idlwave-find-key idlwave-end-unit-reg 1))
2376
2377(defun idlwave-mark-statement ()
2378 "Mark current IDL statement."
2379 (interactive)
2380 (idlwave-end-of-statement)
2381 (let ((end (point)))
2382 (idlwave-beginning-of-statement)
2383 (idlwave-push-mark end nil t)))
2384
2385(defun idlwave-mark-block ()
2386 "Mark containing block."
2387 (interactive)
2388 (idlwave-end-of-statement)
2389 (idlwave-backward-up-block -1)
2390 (idlwave-end-of-statement)
2391 (let ((end (point)))
2392 (idlwave-backward-block)
2393 (idlwave-beginning-of-statement)
2394 (idlwave-push-mark end nil t)))
2395
2396
2397(defun idlwave-mark-subprogram ()
2398 "Put mark at beginning of program, point at end.
2399The marks are pushed."
2400 (interactive)
2401 (idlwave-end-of-statement)
2402 (idlwave-beginning-of-subprogram)
2403 (let ((beg (point)))
2404 (idlwave-forward-block)
2405 (idlwave-push-mark beg nil t))
2406 (exchange-point-and-mark))
2407
2408(defun idlwave-backward-up-block (&optional arg)
2409 "Move to beginning of enclosing block if prefix ARG >= 0.
2410If prefix ARG < 0 then move forward to enclosing block end."
2411 (interactive "p")
2412 (idlwave-block-jump-out (- arg) 'nomark))
2413
2414(defun idlwave-beginning-of-block ()
2415 "Go to the beginning of the current block."
2416 (interactive)
2417 (idlwave-block-jump-out -1 'nomark)
2418 (forward-word 1))
2419
2420(defun idlwave-end-of-block ()
2421 "Go to the beginning of the current block."
2422 (interactive)
2423 (idlwave-block-jump-out 1 'nomark)
2424 (backward-word 1))
2425
2426(defun idlwave-forward-block ()
2427 "Move across next nested block."
2428 (interactive)
2429 (if (idlwave-down-block 1)
2430 (idlwave-block-jump-out 1 'nomark)))
2431
2432(defun idlwave-backward-block ()
2433 "Move backward across previous nested block."
2434 (interactive)
2435 (if (idlwave-down-block -1)
2436 (idlwave-block-jump-out -1 'nomark)))
2437
2438(defun idlwave-down-block (&optional arg)
2439 "Go down a block.
2440With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2441Returns non-nil if successfull."
2442 (interactive "p")
2443 (let (status)
2444 (if (< arg 0)
2445 ;; Backward
2446 (let ((eos (save-excursion
2447 (idlwave-block-jump-out -1 'nomark)
2448 (point))))
31b58798 2449 (if (setq status (idlwave-find-key
f32b3b91
CD
2450 idlwave-end-block-reg -1 'nomark eos))
2451 (idlwave-beginning-of-statement)
2452 (message "No nested block before beginning of containing block.")))
2453 ;; Forward
2454 (let ((eos (save-excursion
2455 (idlwave-block-jump-out 1 'nomark)
2456 (point))))
31b58798 2457 (if (setq status (idlwave-find-key
f32b3b91
CD
2458 idlwave-begin-block-reg 1 'nomark eos))
2459 (idlwave-end-of-statement)
2460 (message "No nested block before end of containing block."))))
2461 status))
2462
2463(defun idlwave-mark-doclib ()
2464 "Put point at beginning of doc library header, mark at end.
2465The marks are pushed."
2466 (interactive)
2467 (let (beg
2468 (here (point)))
2469 (goto-char (point-max))
2470 (if (re-search-backward idlwave-doclib-start nil t)
31b58798 2471 (progn
f32b3b91
CD
2472 (setq beg (progn (beginning-of-line) (point)))
2473 (if (re-search-forward idlwave-doclib-end nil t)
2474 (progn
2475 (forward-line 1)
2476 (idlwave-push-mark beg nil t)
2477 (message "Could not find end of doc library header.")))
2478 (message "Could not find doc library header start.")
2479 (goto-char here)))))
2480
15e42531
CD
2481
2482(defun idlwave-current-routine ()
2483 "Return (NAME TYPE CLASS) of current routine."
2484 (idlwave-routines)
2485 (save-excursion
2486 (idlwave-beginning-of-subprogram)
2487 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2488 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2489 'pro 'function))
2490 (class (idlwave-sintern-class (match-string 3)))
2491 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2492 (list name type class)))))
2493
f32b3b91
CD
2494(defvar idlwave-shell-prompt-pattern)
2495(defun idlwave-beginning-of-statement ()
2496 "Move to beginning of the current statement.
2497Skips back past statement continuations.
2498Point is placed at the beginning of the line whether or not this is an
2499actual statement."
2500 (interactive)
2501 (cond
2502 ((eq major-mode 'idlwave-shell-mode)
2503 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2504 (goto-char (match-end 0))))
31b58798 2505 (t
f32b3b91
CD
2506 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2507 (idlwave-previous-statement)
2508 (beginning-of-line)))))
2509
2510(defun idlwave-previous-statement ()
2511 "Moves point to beginning of the previous statement.
2512Returns t if the current line before moving is the beginning of
2513the first non-comment statement in the file, and nil otherwise."
2514 (interactive)
2515 (let (first-statement)
2516 (if (not (= (forward-line -1) 0))
2517 ;; first line in file
2518 t
2519 ;; skip blank lines, label lines, include lines and line comments
2520 (while (and
2521 ;; The current statement is the first statement until we
2522 ;; reach another statement.
2523 (setq first-statement
2524 (or
2525 (looking-at idlwave-comment-line-start-skip)
2526 (looking-at "[ \t]*$")
2527 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2528 (looking-at "^@")))
2529 (= (forward-line -1) 0)))
2530 ;; skip continuation lines
2531 (while (and
2532 (save-excursion
2533 (forward-line -1)
2534 (idlwave-is-continuation-line))
2535 (= (forward-line -1) 0)))
2536 first-statement)))
2537
f32b3b91
CD
2538(defun idlwave-end-of-statement ()
2539 "Moves point to the end of the current IDL statement.
05a1abfc
CD
2540If not in a statement just moves to end of line. Returns position."
2541 (interactive)
2542 (while (and (idlwave-is-continuation-line)
2543 (= (forward-line 1) 0))
2544 (while (and (idlwave-is-comment-or-empty-line)
2545 (= (forward-line 1) 0))))
2546 (end-of-line)
2547 (point))
2548
2549(defun idlwave-end-of-statement0 ()
2550 "Moves point to the end of the current IDL statement.
f32b3b91
CD
2551If not in a statement just moves to end of line. Returns position."
2552 (interactive)
2553 (while (and (idlwave-is-continuation-line)
2554 (= (forward-line 1) 0)))
2555 (end-of-line)
2556 (point))
2557
2558(defun idlwave-next-statement ()
2559 "Moves point to beginning of the next IDL statement.
2560 Returns t if that statement is the last
2561 non-comment IDL statement in the file, and nil otherwise."
2562 (interactive)
2563 (let (last-statement)
2564 (idlwave-end-of-statement)
2565 ;; skip blank lines, label lines, include lines and line comments
2566 (while (and (= (forward-line 1) 0)
2567 ;; The current statement is the last statement until
2568 ;; we reach a new statement.
2569 (setq last-statement
2570 (or
2571 (looking-at idlwave-comment-line-start-skip)
2572 (looking-at "[ \t]*$")
2573 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2574 (looking-at "^@")))))
2575 last-statement))
2576
76959b77
S
2577(defun idlwave-skip-multi-commands (&optional lim)
2578 "Skip past multiple commands on a line (with `&')."
2579 (let ((save-point (point)))
2580 (when (re-search-forward ".*&" lim t)
2581 (goto-char (match-end 0))
31b58798 2582 (if (idlwave-quoted)
6b75c9af
S
2583 (goto-char save-point)
2584 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
76959b77
S
2585 (point)))
2586
15e42531 2587(defun idlwave-skip-label-or-case ()
f32b3b91
CD
2588 "Skip label or case statement element.
2589Returns position after label.
2590If there is no label point is not moved and nil is returned."
15e42531
CD
2591 ;; Case expressions and labels are terminated by a colon.
2592 ;; So we find the first colon in the line and make sure
2593 ;; - no `?' is before it (might be a ? b : c)
2594 ;; - it is not in a comment
2595 ;; - not in a string constant
2596 ;; - not in parenthesis (like a[0:3])
5e72c6b2 2597 ;; - not followed by another ":" in explicit class, ala a->b::c
15e42531 2598 ;; As many in this mode, this function is heuristic and not an exact
31b58798 2599 ;; parser.
5e72c6b2
S
2600 (let* ((start (point))
2601 (eos (save-excursion (idlwave-end-of-statement) (point)))
2602 (end (idlwave-find-key ":" 1 'nomark eos)))
f32b3b91 2603 (if (and end
15e42531 2604 (= (nth 0 (parse-partial-sexp start end)) 0)
5e72c6b2
S
2605 (not (string-match "\\?" (buffer-substring start end)))
2606 (not (string-match "^::" (buffer-substring end eos))))
f32b3b91
CD
2607 (progn
2608 (forward-char)
2609 (point))
2610 (goto-char start)
2611 nil)))
2612
2613(defun idlwave-start-of-substatement (&optional pre)
2614 "Move to start of next IDL substatement after point.
2615Uses the type of the current IDL statement to determine if the next
2616statement is on a new line or is a subpart of the current statement.
2617Returns point at start of substatement modulo whitespace.
2618If optional argument is non-nil move to beginning of current
15e42531 2619substatement."
f32b3b91
CD
2620 (let ((orig (point))
2621 (eos (idlwave-end-of-statement))
2622 (ifnest 0)
2623 st nst last)
2624 (idlwave-beginning-of-statement)
15e42531 2625 (idlwave-skip-label-or-case)
52a244eb
S
2626 (if (< (point) orig)
2627 (idlwave-skip-multi-commands orig))
f32b3b91
CD
2628 (setq last (point))
2629 ;; Continue looking for substatements until we are past orig
2630 (while (and (<= (point) orig) (not (eobp)))
2631 (setq last (point))
2632 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2633 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2634 (cond ((and nst
2635 (idlwave-find-key nst 1 'nomark eos))
2636 (goto-char (match-end 0)))
2637 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2638 (setq ifnest (1- ifnest))
2639 (goto-char (match-end 0)))
2640 (t (setq ifnest 0)
2641 (idlwave-next-statement))))
2642 (if pre (goto-char last))
15e42531
CD
2643 ;; If a continuation line starts here, move to next line
2644 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2645 (beginning-of-line 2))
f32b3b91
CD
2646 (point)))
2647
2648(defun idlwave-statement-type ()
2649 "Return the type of the current IDL statement.
2650Uses `idlwave-statement-match' to return a cons of (type . point) with
2651point the ending position where the type was determined. Type is the
2652association from `idlwave-statement-match', i.e. the cons cell from the
2653list not just the type symbol. Returns nil if not an identifiable
2654statement."
2655 (save-excursion
2656 ;; Skip whitespace within a statement which is spaces, tabs, continuations
76959b77
S
2657 ;; and possibly comments
2658 (while (looking-at "[ \t]*\\$")
f32b3b91
CD
2659 (forward-line 1))
2660 (skip-chars-forward " \t")
2661 (let ((st idlwave-statement-match)
2662 (case-fold-search t))
2663 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2664 (setq st (cdr st))))
2665 (if st
2666 (append st (match-end 0))))))
2667
2668(defun idlwave-expand-equal (&optional before after)
52a244eb
S
2669 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2670assignment. Which case is determined using
2671`idlwave-start-of-substatement' and `idlwave-statement-type'. The
2672equal sign will be surrounded by BEFORE and AFTER blanks. If
2673`idlwave-pad-keyword' is t then keyword assignment is treated just
15e42531
CD
2674like assignment statements. When nil, spaces are removed for keyword
2675assignment. Any other value keeps the current space around the `='.
31b58798 2676Limits in for loops are treated as keyword assignment.
52a244eb
S
2677
2678Starting with IDL 6.0, a number of op= assignments are available.
2679Since ambiguities of the form:
2680
2681r and= b
2682rand= b
2683
2684can occur, alphanumeric operator assignment will never be pre-padded,
2685only post-padded. You must use a space before these to disambiguate
2686\(not just for padding, but for proper parsing by IDL too!). Other
2687operators, such as ##=, ^=, etc., will be pre-padded.
2688
2689See `idlwave-surround'."
f32b3b91 2690 (if idlwave-surround-by-blank
31b58798 2691 (let
52a244eb 2692 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
31b58798 2693 (an-ops
52a244eb
S
2694 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2695 (len 1))
31b58798
JB
2696
2697 (save-excursion
52a244eb
S
2698 (let ((case-fold-search t))
2699 (backward-char)
31b58798 2700 (if (or
52a244eb
S
2701 (re-search-backward non-an-ops nil t)
2702 ;; Why doesn't ##? work for both?
31b58798 2703 (re-search-backward "\\(#\\)\\=" nil t))
52a244eb
S
2704 (setq len (1+ (length (match-string 1))))
2705 (when (re-search-backward an-ops nil t)
3938cb82 2706 ;(setq begin nil) ; won't modify begin
52a244eb 2707 (setq len (1+ (length (match-string 1))))))))
31b58798
JB
2708
2709 (if (eq t idlwave-pad-keyword)
52a244eb
S
2710 ;; Everything gets padded equally
2711 (idlwave-surround before after nil len)
2712 ;; Treating keywords/for variables specially...
2713 (let ((st (save-excursion ; To catch "for" variables
2714 (idlwave-start-of-substatement t)
2715 (idlwave-statement-type)))
2716 (what (save-excursion ; To catch keywords
2717 (skip-chars-backward "= \t")
2718 (nth 2 (idlwave-where)))))
2719 (cond ((or (memq what '(function-keyword procedure-keyword))
31b58798
JB
2720 (memq (caar st) '(for pdef)))
2721 (cond
52a244eb
S
2722 ((null idlwave-pad-keyword)
2723 (idlwave-surround 0 0)
2724 ) ; remove space
2725 (t))) ; leave any spaces alone
2726 (t (idlwave-surround before after nil len))))))))
31b58798 2727
f32b3b91 2728
5e72c6b2
S
2729(defun idlwave-indent-and-action (&optional arg)
2730 "Call `idlwave-indent-line' and do expand actions.
2731With prefix ARG non-nil, indent the entire sub-statement."
2732 (interactive "p")
05a1abfc 2733 (save-excursion
31b58798
JB
2734 (if (and idlwave-expand-generic-end
2735 (re-search-backward "\\<\\(end\\)\\s-*\\="
05a1abfc
CD
2736 (max 0 (- (point) 10)) t)
2737 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2738 (progn (goto-char (match-end 1))
5e72c6b2
S
2739 ;;Expand the END abbreviation, just as RET or Space would have.
2740 (if abbrev-mode (expand-abbrev)
2741 (idlwave-show-begin)))))
52a244eb
S
2742 (when (and (not arg) current-prefix-arg)
2743 (setq arg current-prefix-arg)
2744 (setq current-prefix-arg nil))
31b58798 2745 (if arg
5e72c6b2
S
2746 (idlwave-indent-statement)
2747 (idlwave-indent-line t)))
f32b3b91
CD
2748
2749(defun idlwave-indent-line (&optional expand)
2750 "Indents current IDL line as code or as a comment.
2751The actions in `idlwave-indent-action-table' are performed.
2752If the optional argument EXPAND is non-nil then the actions in
2753`idlwave-indent-expand-table' are performed."
2754 (interactive)
2755 ;; Move point out of left margin.
2756 (if (save-excursion
2757 (skip-chars-backward " \t")
2758 (bolp))
2759 (skip-chars-forward " \t"))
2760 (let ((mloc (point-marker)))
2761 (save-excursion
2762 (beginning-of-line)
2763 (if (looking-at idlwave-comment-line-start-skip)
2764 ;; Indentation for a line comment
2765 (progn
2766 (skip-chars-forward " \t")
2767 (idlwave-indent-left-margin (idlwave-comment-hook)))
2768 ;;
2769 ;; Code Line
2770 ;;
2771 ;; Before indenting, run action routines.
2772 ;;
2773 (if (and expand idlwave-do-actions)
2774 (mapcar 'idlwave-do-action idlwave-indent-expand-table))
2775 ;;
2776 (if idlwave-do-actions
2777 (mapcar 'idlwave-do-action idlwave-indent-action-table))
2778 ;;
2779 ;; No longer expand abbrevs on the line. The user can do this
2780 ;; manually using expand-region-abbrevs.
2781 ;;
2782 ;; Indent for code line
2783 ;;
2784 (beginning-of-line)
2785 (if (or
2786 ;; a label line
2787 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2788 ;; a batch command
2789 (looking-at "^[ \t]*@"))
2790 ;; leave flush left
2791 nil
2792 ;; indent the line
2793 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2794 ;; Adjust parallel comment
76959b77
S
2795 (end-of-line)
2796 (if (idlwave-in-comment)
2797 ;; Emacs 21 is too smart with fill-column on comment indent
2798 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2799 (1- (frame-width))
2800 fill-column)))
2801 (indent-for-comment)))))
f32b3b91
CD
2802 (goto-char mloc)
2803 ;; Get rid of marker
76959b77 2804 (set-marker mloc nil)))
f32b3b91
CD
2805
2806(defun idlwave-do-action (action)
2807 "Perform an action repeatedly on a line.
2808ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2809either a function name to be called with `funcall' or a list to be
2810evaluated with `eval'. The action performed by FUNC should leave point
2811after the match for REG - otherwise an infinite loop may be entered."
2812 (let ((action-key (car action))
2813 (action-routine (cdr action)))
2814 (beginning-of-line)
2815 (while (idlwave-look-at action-key)
2816 (if (listp action-routine)
2817 (eval action-routine)
2818 (funcall action-routine)))))
2819
2820(defun idlwave-indent-to (col &optional min)
2821 "Indent from point with spaces until column COL.
2822Inserts space before markers at point."
2823 (if (not min) (setq min 0))
2824 (insert-before-markers
15e42531 2825 (make-string (max min (- col (current-column))) ?\ )))
f32b3b91
CD
2826
2827(defun idlwave-indent-left-margin (col)
2828 "Indent the current line to column COL.
2829Indents such that first non-whitespace character is at column COL
2830Inserts spaces before markers at point."
2831 (save-excursion
2832 (beginning-of-line)
2833 (delete-horizontal-space)
2834 (idlwave-indent-to col)))
2835
2836(defun idlwave-indent-subprogram ()
2837 "Indents program unit which contains point."
2838 (interactive)
2839 (save-excursion
2840 (idlwave-end-of-statement)
2841 (idlwave-beginning-of-subprogram)
2842 (let ((beg (point)))
2843 (idlwave-forward-block)
2844 (message "Indenting subprogram...")
2845 (indent-region beg (point) nil))
2846 (message "Indenting subprogram...done.")))
2847
5e72c6b2
S
2848(defun idlwave-indent-statement ()
2849 "Indent current statement, including all continuation lines."
2850 (interactive)
2851 (save-excursion
2852 (idlwave-beginning-of-statement)
2853 (let ((beg (point)))
2854 (idlwave-end-of-statement)
2855 (indent-region beg (point) nil))))
2856
f32b3b91
CD
2857(defun idlwave-calculate-indent ()
2858 "Return appropriate indentation for current line as IDL code."
2859 (save-excursion
2860 (beginning-of-line)
2861 (cond
2862 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2863 ;; function
2864 ((idlwave-look-at idlwave-begin-unit-reg)
2865 0)
2866 ;; Check for continuation line
2867 ((save-excursion
2868 (and (= (forward-line -1) 0)
2869 (idlwave-is-continuation-line)))
2870 (idlwave-calculate-cont-indent))
2871 ;; calculate indent based on previous and current statements
52a244eb
S
2872 (t (let* (beg-prev-pos
2873 (the-indent
2874 ;; calculate indent based on previous statement
2875 (save-excursion
2876 (cond
2877 ;; Beginning of file
31b58798 2878 ((prog1
52a244eb
S
2879 (idlwave-previous-statement)
2880 (setq beg-prev-pos (point)))
2881 0)
2882 ;; Main block
2883 ((idlwave-look-at idlwave-begin-unit-reg t)
2884 (+ (idlwave-current-statement-indent)
2885 idlwave-main-block-indent))
2886 ;; Begin block
2887 ((idlwave-look-at idlwave-begin-block-reg t)
31b58798 2888 (+ (idlwave-min-current-statement-indent)
52a244eb
S
2889 idlwave-block-indent))
2890 ;; End Block
2891 ((idlwave-look-at idlwave-end-block-reg t)
2892 (progn
2893 ;; Match to the *beginning* of the block opener
2894 (goto-char beg-prev-pos)
2895 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2896 (idlwave-min-current-statement-indent)))
2897 ;; idlwave-end-offset
2898 ;; idlwave-block-indent))
31b58798 2899
52a244eb
S
2900 ;; Default to current indent
2901 ((idlwave-current-statement-indent))))))
f32b3b91
CD
2902 ;; adjust the indentation based on the current statement
2903 (cond
2904 ;; End block
5e72c6b2
S
2905 ((idlwave-look-at idlwave-end-block-reg)
2906 (+ the-indent idlwave-end-offset))
f32b3b91
CD
2907 (the-indent)))))))
2908
2909;;
52a244eb 2910;; Parentheses indent
f32b3b91
CD
2911;;
2912
5e72c6b2
S
2913(defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2914 "Calculate the continuation indent inside a paren group.
31b58798 2915Returns a cons-cell with (open . indent), where open is the
5e72c6b2
S
2916location of the open paren"
2917 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2918 ;; Found an innermost open paren.
2919 (when open
2920 (goto-char open)
2921 ;; Line up with next word unless this is a closing paren.
2922 (cons open
2923 (cond
52a244eb
S
2924 ;; Plain Kernighan-style nested indent
2925 (idlwave-indent-parens-nested
2926 (+ idlwave-continuation-indent (idlwave-current-indent)))
2927
5e72c6b2
S
2928 ;; This is a closed paren - line up under open paren.
2929 (close-exp
2930 (current-column))
52a244eb
S
2931
2932 ;; Empty (or just comment) follows -- revert to basic indent
5e72c6b2
S
2933 ((progn
2934 ;; Skip paren
2935 (forward-char 1)
2936 (looking-at "[ \t$]*\\(;.*\\)?$"))
52a244eb
S
2937 nil)
2938
2939 ;; Line up with first word after any blank space
5e72c6b2
S
2940 ((progn
2941 (skip-chars-forward " \t")
2942 (current-column))))))))
2943
f32b3b91 2944(defun idlwave-calculate-cont-indent ()
52a244eb
S
2945 "Calculates the IDL continuation indent column from the previous
2946statement. Note that here previous statement usually means the
2947beginning of the current statement if this statement is a continuation
2948of the previous line. Various special types of continuations,
2949including assignments, routine definitions, and parenthetical
2950groupings, are treated separately."
f32b3b91 2951 (save-excursion
52a244eb 2952 (let* ((case-fold-search t)
f32b3b91 2953 (end-reg (progn (beginning-of-line) (point)))
52a244eb
S
2954 (beg-last-statement (save-excursion (idlwave-previous-statement)
2955 (point)))
31b58798 2956 (beg-reg (progn (idlwave-start-of-substatement 'pre)
52a244eb
S
2957 (if (eq (line-beginning-position) end-reg)
2958 (goto-char beg-last-statement)
2959 (point))))
2960 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
2961 idlwave-continuation-indent))
2962 fancy-nonparen-indent fancy-paren-indent)
31b58798 2963 (cond
52a244eb
S
2964 ;; Align then with its matching if, etc.
2965 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
2966 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
2967 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
31b58798 2968 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
52a244eb
S
2969 "[ \t]*until")
2970 ("\\<case\\>" . "[ \t]*of")))
2971 match cont-re)
2972 (goto-char end-reg)
31b58798 2973 (and
52a244eb
S
2974 (setq cont-re
2975 (catch 'exit
2976 (while (setq match (car matchers))
2977 (if (looking-at (cdr match))
2978 (throw 'exit (car match)))
2979 (setq matchers (cdr matchers)))))
2980 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
2981 (if (looking-at "end") ;; that one's special
31b58798 2982 (- (idlwave-current-indent)
52a244eb
S
2983 (+ idlwave-block-indent idlwave-end-offset))
2984 (idlwave-current-indent)))
2985
2986 ;; Indent in from the previous line for continuing statements
2987 ((let ((matchers '("\\<then\\>"
2988 "\\<do\\>"
2989 "\\<repeat\\>"
2990 "\\<else\\>"))
2991 match)
2992 (catch 'exit
2993 (goto-char end-reg)
2994 (if (/= (forward-line -1) 0)
2995 (throw 'exit nil))
2996 (while (setq match (car matchers))
2997 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
2998 "\\(;.*\\)?$"))
2999 (throw 'exit t))
3000 (setq matchers (cdr matchers)))))
3001 (+ idlwave-continuation-indent (idlwave-current-indent)))
3002
3003 ;; Parenthetical indent, either traditional or Kernighan style
3004 ((setq fancy-paren-indent
3005 (let* ((end-reg end-reg)
3006 (close-exp (progn
3007 (goto-char end-reg)
31b58798 3008 (skip-chars-forward " \t")
52a244eb
S
3009 (looking-at "\\s)")))
3010 indent-cons)
3011 (catch 'loop
3012 (while (setq indent-cons (idlwave-calculate-paren-indent
3013 beg-reg end-reg close-exp))
3014 ;; First permitted containing paren
3015 (if (or
3016 idlwave-indent-to-open-paren
3017 idlwave-indent-parens-nested
3018 (null (cdr indent-cons))
3019 (< (- (cdr indent-cons) basic-indent)
3020 idlwave-max-extra-continuation-indent))
3021 (throw 'loop (cdr indent-cons)))
3022 (setq end-reg (car indent-cons))))))
5e72c6b2
S
3023 fancy-paren-indent)
3024
52a244eb
S
3025 ;; A continued assignment, or procedure call/definition
3026 ((and
3027 (> idlwave-max-extra-continuation-indent 0)
3028 (setq fancy-nonparen-indent
3029 (progn
3030 (goto-char beg-reg)
3031 (while (idlwave-look-at "&")) ; skip continued statements
3032 (cond
3033 ;; A continued Procedure call or definition
3034 ((progn
3035 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3036 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3037 (goto-char (match-end 0))
3038 ;; Comment only, or blank line with "$"? Basic indent.
3039 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3040 nil
3041 (current-column)))
31b58798 3042
52a244eb
S
3043 ;; Continued assignment (with =):
3044 ((catch 'assign ;
3045 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3046 (goto-char (match-end 0))
31b58798 3047 (if (null (idlwave-what-function beg-reg))
52a244eb
S
3048 (throw 'assign t))))
3049 (unless (or
3050 (idlwave-in-quote)
3051 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3052 (save-excursion
3053 (goto-char beg-last-statement)
3054 (eq (caar (idlwave-statement-type)) 'for)))
3055 (current-column))))))
3056 (< (- fancy-nonparen-indent basic-indent)
3057 idlwave-max-extra-continuation-indent))
3058 (if fancy-paren-indent ;calculated but disallowed paren indent
3059 (+ fancy-nonparen-indent idlwave-continuation-indent)
3060 fancy-nonparen-indent))
3061
3062 ;; Basic indent, by default
3063 (t basic-indent)))))
3064
3065
f32b3b91 3066
15e42531
CD
3067(defun idlwave-find-key (key-re &optional dir nomark limit)
3068 "Move to next match of the regular expression KEY-RE.
3069Matches inside comments or string constants will be ignored.
3070If DIR is negative, the search will be backwards.
3071At a successful match, the mark is pushed unless NOMARK is non-nil.
3072Searches are limited to LIMIT.
3073Searches are case-insensitive and use a special syntax table which
3074treats `$' and `_' as word characters.
3075Return value is the beginning of the match or (in case of failure) nil."
3076 (setq dir (or dir 0))
3077 (let ((case-fold-search t)
3078 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3079 found)
3080 (idlwave-with-special-syntax
3081 (save-excursion
3082 (catch 'exit
3083 (while (funcall search-func key-re limit t)
3084 (if (not (idlwave-quoted))
52a244eb
S
3085 (throw 'exit (setq found (match-beginning 0)))
3086 (if (or (and (> dir 0) (eobp))
3087 (and (< dir 0) (bobp)))
3088 (throw 'exit nil)))))))
15e42531
CD
3089 (if found
3090 (progn
3091 (if (not nomark) (push-mark))
3092 (goto-char found)
3093 found)
3094 nil)))
3095
f32b3b91
CD
3096(defun idlwave-block-jump-out (&optional dir nomark)
3097 "When optional argument DIR is non-negative, move forward to end of
3098current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3099regular expressions. When DIR is negative, move backwards to block beginning.
3100Recursively calls itself to skip over nested blocks. DIR defaults to
3101forward. Calls `push-mark' unless the optional argument NOMARK is
3102non-nil. Movement is limited by the start of program units because of
3103possibility of unbalanced blocks."
3104 (interactive "P")
3105 (or dir (setq dir 0))
3106 (let* ((here (point))
3107 (case-fold-search t)
3108 (limit (if (>= dir 0) (point-max) (point-min)))
31b58798 3109 (block-limit (if (>= dir 0)
f32b3b91
CD
3110 idlwave-begin-block-reg
3111 idlwave-end-block-reg))
3112 found
3113 (block-reg (concat idlwave-begin-block-reg "\\|"
3114 idlwave-end-block-reg))
3115 (unit-limit (or (save-excursion
3116 (if (< dir 0)
3117 (idlwave-find-key
3118 idlwave-begin-unit-reg dir t limit)
3119 (end-of-line)
31b58798 3120 (idlwave-find-key
f32b3b91
CD
3121 idlwave-end-unit-reg dir t limit)))
3122 limit)))
3123 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3124 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3125 (while (and found (looking-at block-limit))
3126 (if (>= dir 0) (forward-word 1))
3127 (idlwave-block-jump-out dir t)
3128 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3129 (if (not nomark) (push-mark here))
3130 (if (not found) (goto-char unit-limit)
3131 (if (>= dir 0) (forward-word 1)))))
3132
52a244eb
S
3133(defun idlwave-min-current-statement-indent (&optional end-reg)
3134 "The minimum indent in the current statement."
3135 (idlwave-beginning-of-statement)
3136 (if (not (idlwave-is-continuation-line))
3137 (idlwave-current-indent)
3138 (let ((min (idlwave-current-indent)) comm-or-empty)
3139 (while (and (= (forward-line 1) 0)
3140 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3141 (idlwave-is-continuation-line))
3142 (or (null end-reg) (< (point) end-reg)))
3143 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3144 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
31b58798 3145 min
52a244eb
S
3146 (min min (idlwave-current-indent))))))
3147
3148(defun idlwave-current-statement-indent (&optional last-line)
f32b3b91
CD
3149 "Return indentation of the current statement.
3150If in a statement, moves to beginning of statement before finding indent."
52a244eb
S
3151 (if last-line
3152 (idlwave-end-of-statement)
3153 (idlwave-beginning-of-statement))
f32b3b91
CD
3154 (idlwave-current-indent))
3155
3156(defun idlwave-current-indent ()
3157 "Return the column of the indentation of the current line.
3158Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3159 (save-excursion
3160 (beginning-of-line)
3161 (skip-chars-forward " \t")
3162 ;; if we are at the end of blank line return 0
3163 (cond ((eolp) 0)
3164 ((current-column)))))
3165
3166(defun idlwave-is-continuation-line ()
5e72c6b2
S
3167 "Tests if current line is continuation line.
3168Blank or comment-only lines following regular continuation lines (with
3169`$') count as continuations too."
f32b3b91 3170 (save-excursion
31b58798 3171 (or
5e72c6b2
S
3172 (idlwave-look-at "\\<\\$")
3173 (catch 'loop
31b58798 3174 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
5e72c6b2
S
3175 (eq (forward-line -1) 0))
3176 (if (idlwave-look-at "\\<\\$") (throw 'loop t)))))))
f32b3b91
CD
3177
3178(defun idlwave-is-comment-line ()
05a1abfc 3179 "Tests if the current line is a comment line."
f32b3b91
CD
3180 (save-excursion
3181 (beginning-of-line 1)
3182 (looking-at "[ \t]*;")))
3183
05a1abfc
CD
3184(defun idlwave-is-comment-or-empty-line ()
3185 "Tests if the current line is a comment line."
3186 (save-excursion
3187 (beginning-of-line 1)
3188 (looking-at "[ \t]*[;\n]")))
3189
f32b3b91 3190(defun idlwave-look-at (regexp &optional cont beg)
15e42531
CD
3191 "Searches current line from current point for REGEXP.
3192If optional argument CONT is non-nil, searches to the end of
3193the current statement.
3194If optional arg BEG is non-nil, search starts from the beginning of the
3195current statement.
3196Ignores matches that end in a comment or inside a string expression.
3197Returns point if successful, nil otherwise.
3198This function produces unexpected results if REGEXP contains quotes or
3199a comment delimiter. The search is case insensitive.
3200If successful leaves point after the match, otherwise, does not move point."
f32b3b91 3201 (let ((here (point))
f32b3b91 3202 (case-fold-search t)
15e42531
CD
3203 (eos (save-excursion
3204 (if cont (idlwave-end-of-statement) (end-of-line))
3205 (point)))
f32b3b91 3206 found)
15e42531
CD
3207 (idlwave-with-special-syntax
3208 (if beg (idlwave-beginning-of-statement))
3209 (while (and (setq found (re-search-forward regexp eos t))
3210 (idlwave-quoted))))
f32b3b91
CD
3211 (if (not found) (goto-char here))
3212 found))
3213
3214(defun idlwave-fill-paragraph (&optional nohang)
3215 "Fills paragraphs in comments.
3216A paragraph is made up of all contiguous lines having the same comment
3217leader (the leading whitespace before the comment delimiter and the
3218comment delimiter). In addition, paragraphs are separated by blank
3219line comments. The indentation is given by the hanging indent of the
3220first line, otherwise by the minimum indentation of the lines after
3221the first line. The indentation of the first line does not change.
3222Does not effect code lines. Does not fill comments on the same line
3223with code. The hanging indent is given by the end of the first match
3224matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3225optional argument NOHANG is non-nil then the hanging indent is
3226ignored."
3227 (interactive "P")
3228 ;; check if this is a line comment
3229 (if (save-excursion
3230 (beginning-of-line)
3231 (skip-chars-forward " \t")
3232 (looking-at comment-start))
3233 (let
3234 ((indent 999)
3235 pre here diff fill-prefix-reg bcl first-indent
3236 hang start end)
3237 ;; Change tabs to spaces in the surrounding paragraph.
3238 ;; The surrounding paragraph will be the largest containing block of
3239 ;; contiguous line comments. Thus, we may be changing tabs in
3240 ;; a much larger area than is needed, but this is the easiest
3241 ;; brute force way to do it.
3242 ;;
3243 ;; This has the undesirable side effect of replacing the tabs
3244 ;; permanently without the user's request or knowledge.
3245 (save-excursion
3246 (backward-paragraph)
3247 (setq start (point)))
3248 (save-excursion
3249 (forward-paragraph)
3250 (setq end (point)))
3251 (untabify start end)
3252 ;;
3253 (setq here (point))
3254 (beginning-of-line)
3255 (setq bcl (point))
3256 (re-search-forward
3257 (concat "^[ \t]*" comment-start "+")
3258 (save-excursion (end-of-line) (point))
3259 t)
3260 ;; Get the comment leader on the line and its length
3261 (setq pre (current-column))
3262 ;; the comment leader is the indentation plus exactly the
3263 ;; number of consecutive ";".
3264 (setq fill-prefix-reg
3265 (concat
3266 (setq fill-prefix
3267 (regexp-quote
3268 (buffer-substring (save-excursion
3269 (beginning-of-line) (point))
3270 (point))))
3271 "[^;]"))
31b58798 3272
f32b3b91
CD
3273 ;; Mark the beginning and end of the paragraph
3274 (goto-char bcl)
3275 (while (and (looking-at fill-prefix-reg)
3276 (not (looking-at paragraph-separate))
3277 (not (bobp)))
3278 (forward-line -1))
3279 ;; Move to first line of paragraph
3280 (if (/= (point) bcl)
3281 (forward-line 1))
3282 (setq start (point))
3283 (goto-char bcl)
3284 (while (and (looking-at fill-prefix-reg)
3285 (not (looking-at paragraph-separate))
3286 (not (eobp)))
3287 (forward-line 1))
3288 (beginning-of-line)
3289 (if (or (not (looking-at fill-prefix-reg))
3290 (looking-at paragraph-separate))
3291 (forward-line -1))
3292 (end-of-line)
3293 ;; if at end of buffer add a newline (need this because
3294 ;; fill-region needs END to be at the beginning of line after
3295 ;; the paragraph or it will add a line).
3296 (if (eobp)
3297 (progn (insert ?\n) (backward-char 1)))
3298 ;; Set END to the beginning of line after the paragraph
3299 ;; END is calculated as distance from end of buffer
3300 (setq end (- (point-max) (point) 1))
3301 ;;
3302 ;; Calculate the indentation for the paragraph.
3303 ;;
3304 ;; In the following while statements, after one iteration
3305 ;; point will be at the beginning of a line in which case
3306 ;; the while will not be executed for the
3307 ;; the first paragraph line and thus will not affect the
3308 ;; indentation.
3309 ;;
3310 ;; First check to see if indentation is based on hanging indent.
3311 (if (and (not nohang) idlwave-hanging-indent
3312 (setq hang
3313 (save-excursion
3314 (goto-char start)
3315 (idlwave-calc-hanging-indent))))
3316 ;; Adjust lines of paragraph by inserting spaces so that
3317 ;; each line's indent is at least as great as the hanging
3318 ;; indent. This is needed for fill-paragraph to work with
3319 ;; a fill-prefix.
3320 (progn
3321 (setq indent hang)
3322 (beginning-of-line)
3323 (while (> (point) start)
3324 (re-search-forward comment-start-skip
3325 (save-excursion (end-of-line) (point))
3326 t)
3327 (if (> (setq diff (- indent (current-column))) 0)
3328 (progn
3329 (if (>= here (point))
3330 ;; adjust the original location for the
3331 ;; inserted text.
3332 (setq here (+ here diff)))
15e42531 3333 (insert (make-string diff ?\ ))))
f32b3b91
CD
3334 (forward-line -1))
3335 )
31b58798 3336
f32b3b91
CD
3337 ;; No hang. Instead find minimum indentation of paragraph
3338 ;; after first line.
3339 ;; For the following while statement, since START is at the
aa87aafc 3340 ;; beginning of line and END is at the end of line
f32b3b91
CD
3341 ;; point is greater than START at least once (which would
3342 ;; be the case for a single line paragraph).
3343 (while (> (point) start)
3344 (beginning-of-line)
3345 (setq indent
3346 (min indent
3347 (progn
3348 (re-search-forward
3349 comment-start-skip
3350 (save-excursion (end-of-line) (point))
3351 t)
3352 (current-column))))
3353 (forward-line -1))
3354 )
3355 (setq fill-prefix (concat fill-prefix
3356 (make-string (- indent pre)
15e42531 3357 ?\ )))
f32b3b91
CD
3358 ;; first-line indent
3359 (setq first-indent
3360 (max
3361 (progn
3362 (re-search-forward
3363 comment-start-skip
3364 (save-excursion (end-of-line) (point))
3365 t)
3366 (current-column))
3367 indent))
31b58798 3368
f32b3b91
CD
3369 ;; try to keep point at its original place
3370 (goto-char here)
3371
3372 ;; In place of the more modern fill-region-as-paragraph, a hack
3373 ;; to keep whitespace untouched on the first line within the
3374 ;; indent length and to preserve any indent on the first line
3375 ;; (first indent).
3376 (save-excursion
3377 (setq diff
3378 (buffer-substring start (+ start first-indent -1)))
15e42531 3379 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
f32b3b91
CD
3380 (fill-region-as-paragraph
3381 start
3382 (- (point-max) end)
3383 (current-justification)
3384 nil)
3385 (delete-region start (+ start first-indent -1))
3386 (goto-char start)
3387 (insert diff))
3388 ;; When we want the point at the beginning of the comment
3389 ;; body fill-region will put it at the beginning of the line.
3390 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3391 (setq fill-prefix nil))))
3392
3393(defun idlwave-calc-hanging-indent ()
3394 "Calculate the position of the hanging indent for the comment
3395paragraph. The hanging indent position is given by the first match
3396with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3397non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3398the line.
3399If not found returns nil."
3400 (if idlwave-use-last-hang-indent
3401 (save-excursion
3402 (end-of-line)
3403 (if (re-search-backward
3404 idlwave-hang-indent-regexp
3405 (save-excursion (beginning-of-line) (point))
3406 t)
3407 (+ (current-column) (length idlwave-hang-indent-regexp))))
3408 (save-excursion
3409 (beginning-of-line)
3410 (if (re-search-forward
3411 idlwave-hang-indent-regexp
3412 (save-excursion (end-of-line) (point))
3413 t)
3414 (current-column)))))
3415
3416(defun idlwave-auto-fill ()
31b58798 3417 "Called to break lines in auto fill mode.
52a244eb
S
3418Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3419non-nil. Places a continuation character at the end of the line if
3420not in a comment. Splits strings with IDL concatenation operator `+'
3421if `idlwave-auto-fill-split-string' is non-nil."
f32b3b91
CD
3422 (if (<= (current-column) fill-column)
3423 nil ; do not to fill
3424 (if (or (not idlwave-fill-comment-line-only)
3425 (save-excursion
3426 ;; Check for comment line
3427 (beginning-of-line)
3428 (looking-at idlwave-comment-line-start-skip)))
3429 (let (beg)
3430 (idlwave-indent-line)
3431 ;; Prevent actions do-auto-fill which calls indent-line-function.
3432 (let (idlwave-do-actions
3433 (paragraph-start ".")
52a244eb
S
3434 (paragraph-separate ".")
3435 (fill-nobreak-predicate
3436 (if (and (idlwave-in-quote)
3437 idlwave-auto-fill-split-string)
3438 (lambda () ;; We'll need 5 spaces for " ' + $"
3439 (<= (- fill-column (current-column)) 5)
3440 ))))
f32b3b91
CD
3441 (do-auto-fill))
3442 (save-excursion
3443 (end-of-line 0)
3444 ;; Indent the split line
3445 (idlwave-indent-line)
3446 )
3447 (if (save-excursion
3448 (beginning-of-line)
3449 (looking-at idlwave-comment-line-start-skip))
3450 ;; A continued line comment
3451 ;; We treat continued line comments as part of a comment
3452 ;; paragraph. So we check for a hanging indent.
3453 (if idlwave-hanging-indent
3454 (let ((here (- (point-max) (point)))
3455 (indent
3456 (save-excursion
3457 (forward-line -1)
3458 (idlwave-calc-hanging-indent))))
3459 (if indent
3460 (progn
3461 ;; Remove whitespace between comment delimiter and
3462 ;; text, insert spaces for appropriate indentation.
3463 (beginning-of-line)
3464 (re-search-forward
3465 comment-start-skip
3466 (save-excursion (end-of-line) (point)) t)
3467 (delete-horizontal-space)
3468 (idlwave-indent-to indent)
3469 (goto-char (- (point-max) here)))
3470 )))
3471 ;; Split code or comment?
3472 (if (save-excursion
3473 (end-of-line 0)
3474 (idlwave-in-comment))
52a244eb 3475 ;; Splitting a non-full-line comment.
f32b3b91
CD
3476 ;; Insert the comment delimiter from split line
3477 (progn
3478 (save-excursion
3479 (beginning-of-line)
3480 (skip-chars-forward " \t")
3481 ;; Insert blank to keep off beginning of line
3482 (insert " "
3483 (save-excursion
3484 (forward-line -1)
3485 (buffer-substring (idlwave-goto-comment)
3486 (progn
3487 (skip-chars-forward "; ")
3488 (point))))))
3489 (idlwave-indent-line))
3490 ;; Split code line - add continuation character
3491 (save-excursion
3492 (end-of-line 0)
3493 ;; Check to see if we split a string
3494 (if (and (setq beg (idlwave-in-quote))
3495 idlwave-auto-fill-split-string)
3496 ;; Split the string and concatenate.
3497 ;; The first extra space is for the space
3498 ;; the line was split. That space was removed.
3499 (insert " " (char-after beg) " +"))
3500 (insert " $"))
3501 (if beg
3502 (if idlwave-auto-fill-split-string
3503 ;; Make the second part of continued string
3504 (save-excursion
3505 (beginning-of-line)
3506 (skip-chars-forward " \t")
3507 (insert (char-after beg)))
3508 ;; Warning
3509 (beep)
3510 (message "Warning: continuation inside a string.")))
3511 ;; Although do-auto-fill (via indent-new-comment-line) calls
3512 ;; idlwave-indent-line for the new line, re-indent again
3513 ;; because of the addition of the continuation character.
3514 (idlwave-indent-line))
3515 )))))
3516
3517(defun idlwave-auto-fill-mode (arg)
3518 "Toggle auto-fill mode for IDL mode.
3519With arg, turn auto-fill mode on if arg is positive.
3520In auto-fill mode, inserting a space at a column beyond `fill-column'
3521automatically breaks the line at a previous space."
3522 (interactive "P")
3523 (prog1 (set idlwave-fill-function
3524 (if (if (null arg)
3525 (not (symbol-value idlwave-fill-function))
3526 (> (prefix-numeric-value arg) 0))
3527 'idlwave-auto-fill
3528 nil))
3529 ;; update mode-line
3530 (set-buffer-modified-p (buffer-modified-p))))
3531
52a244eb
S
3532;(defun idlwave-fill-routine-call ()
3533; "Fill a routine definition or statement, indenting appropriately."
3534; (let ((where (idlwave-where)))))
3535
3536
f32b3b91
CD
3537(defun idlwave-doc-header (&optional nomark )
3538 "Insert a documentation header at the beginning of the unit.
3539Inserts the value of the variable idlwave-file-header. Sets mark before
3540moving to do insertion unless the optional prefix argument NOMARK
3541is non-nil."
3542 (interactive "P")
3543 (or nomark (push-mark))
3544 ;; make sure we catch the current line if it begins the unit
5e72c6b2
S
3545 (if idlwave-header-to-beginning-of-file
3546 (goto-char (point-min))
3547 (end-of-line)
3548 (idlwave-beginning-of-subprogram)
3549 (beginning-of-line)
3550 ;; skip function or procedure line
3551 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3552 (progn
3553 (idlwave-end-of-statement)
3554 (if (> (forward-line 1) 0) (insert "\n")))))
3555 (let ((pos (point)))
3556 (if idlwave-file-header
3557 (cond ((car idlwave-file-header)
a527b753 3558 (insert-file-contents (car idlwave-file-header)))
5e72c6b2
S
3559 ((stringp (car (cdr idlwave-file-header)))
3560 (insert (car (cdr idlwave-file-header))))))
3561 (goto-char pos)))
f32b3b91
CD
3562
3563(defun idlwave-default-insert-timestamp ()
3564 "Default timestamp insertion function"
3565 (insert (current-time-string))
3566 (insert ", " (user-full-name))
5e72c6b2 3567 (if (boundp 'user-mail-address)
31b58798 3568 (insert " <" user-mail-address ">")
5e72c6b2 3569 (insert " <" (user-login-name) "@" (system-name) ">"))
f32b3b91
CD
3570 ;; Remove extra spaces from line
3571 (idlwave-fill-paragraph)
3572 ;; Insert a blank line comment to separate from the date entry -
3573 ;; will keep the entry from flowing onto date line if re-filled.
5e72c6b2 3574 (insert "\n;\n;\t\t"))
f32b3b91
CD
3575
3576(defun idlwave-doc-modification ()
3577 "Insert a brief modification log at the beginning of the current program.
3578Looks for an occurrence of the value of user variable
3579`idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3580and places the point for the user to add a log. Before moving, saves
3581location on mark ring so that the user can return to previous point."
3582 (interactive)
3583 (push-mark)
05a1abfc
CD
3584 (let* (beg end)
3585 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3586 (progn
3587 (goto-char (point-min))
3588 (re-search-forward idlwave-doclib-start nil t)))
3589 (setq beg (match-beginning 0))
3590 (re-search-forward idlwave-doclib-end nil t)
3591 (setq end (match-end 0)))
3592 (progn
3593 (goto-char beg)
31b58798 3594 (if (re-search-forward
05a1abfc
CD
3595 (concat idlwave-doc-modifications-keyword ":")
3596 end t)
3597 (end-of-line)
3598 (goto-char end)
3599 (end-of-line -1)
3600 (insert "\n" comment-start "\n")
3601 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3602 (insert "\n;\n;\t")
3603 (run-hooks 'idlwave-timestamp-hook))
3604 (error "No valid DOCLIB header"))))
f32b3b91
CD
3605
3606;;; CJC 3/16/93
3607;;; Interface to expand-region-abbrevs which did not work when the
3608;;; abbrev hook associated with an abbrev moves point backwards
3609;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3610;;; The original would enter an infinite loop in attempting to expand
3611;;; .n (it would continually expand and unexpand the abbrev without expanding
3612;;; because the point would keep going back to the beginning of the
3613;;; abbrev instead of to the end of the abbrev). We now keep the
3614;;; abbrev hook from moving backwards.
3615;;;
3616(defun idlwave-expand-region-abbrevs (start end)
3617 "Expand each abbrev occurrence in the region.
3618Calling from a program, arguments are START END."
3619 (interactive "r")
3620 (save-excursion
3621 (goto-char (min start end))
3622 (let ((idlwave-show-block nil) ;Do not blink
3623 (idlwave-abbrev-move nil)) ;Do not move
3624 (expand-region-abbrevs start end 'noquery))))
3625
3626(defun idlwave-quoted ()
3627 "Returns t if point is in a comment or quoted string.
3628nil otherwise."
3629 (or (idlwave-in-comment) (idlwave-in-quote)))
3630
3631(defun idlwave-in-quote ()
3632 "Returns location of the opening quote
3633if point is in a IDL string constant, nil otherwise.
3634Ignores comment delimiters on the current line.
3635Properly handles nested quotation marks and octal
3636constants - a double quote followed by an octal digit."
3637;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3638;;; double quote followed by an octal digit to be an octal constant
3639;;; rather than a string. Therefore, there is no terminating double
3640;;; quote.
3641 (save-excursion
3642 ;; Because single and double quotes can quote each other we must
3643 ;; search for the string start from the beginning of line.
3644 (let* ((start (point))
3645 (eol (progn (end-of-line) (point)))
3646 (bq (progn (beginning-of-line) (point)))
3647 (endq (point))
3648 (data (match-data))
3649 delim
3650 found)
3651 (while (< endq start)
3652 ;; Find string start
3653 ;; Don't find an octal constant beginning with a double quote
52a244eb 3654 (if (re-search-forward "[\"']" eol 'lim)
f32b3b91
CD
3655 ;; Find the string end.
3656 ;; In IDL, two consecutive delimiters after the start of a
3657 ;; string act as an
3658 ;; escape for the delimiter in the string.
3659 ;; Two consecutive delimiters alone (i.e., not after the
aa87aafc 3660 ;; start of a string) is the null string.
f32b3b91
CD
3661 (progn
3662 ;; Move to position after quote
3663 (goto-char (1+ (match-beginning 0)))
3664 (setq bq (1- (point)))
3665 ;; Get the string delimiter
3666 (setq delim (char-to-string (preceding-char)))
3667 ;; Check for null string
3668 (if (looking-at delim)
3669 (progn (setq endq (point)) (forward-char 1))
3670 ;; Look for next unpaired delimiter
3671 (setq found (search-forward delim eol 'lim))
3672 (while (looking-at delim)
3673 (forward-char 1)
3674 (setq found (search-forward delim eol 'lim)))
3675 (if found
3676 (setq endq (- (point) 1))
3677 (setq endq (point)))
3678 ))
3679 (progn (setq bq (point)) (setq endq (point)))))
3680 (store-match-data data)
3681 ;; return string beginning position or nil
3682 (if (> start bq) bq))))
3683
76959b77
S
3684(defun idlwave-is-pointer-dereference (&optional limit)
3685 "Determines if the character after point is a pointer dereference *."
3686 (let ((pos (point)))
3687 (and
3688 (eq (char-after) ?\*)
3689 (not (idlwave-in-quote))
3690 (save-excursion
3691 (forward-char)
31b58798 3692 (re-search-backward (concat "\\(" idlwave-idl-keywords
76959b77
S
3693 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t)))))
3694
3695
f32b3b91
CD
3696;; Statement templates
3697
3698;; Replace these with a general template function, something like
3699;; expand.el (I think there was also something with a name similar to
3700;; dmacro.el)
3701
3702(defun idlwave-template (s1 s2 &optional prompt noindent)
3703 "Build a template with optional prompt expression.
3704
3705Opens a line if point is not followed by a newline modulo intervening
3706whitespace. S1 and S2 are strings. S1 is inserted at point followed
595ab50b
CD
3707by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3708adjusted according to `idlwave-abbrev-change-case'. If optional argument
f32b3b91
CD
3709PROMPT is a string then it is displayed as a message in the
3710minibuffer. The PROMPT serves as a reminder to the user of an
3711expression to enter.
3712
3713The lines containing S1 and S2 are reindented using `indent-region'
3714unless the optional second argument NOINDENT is non-nil."
15e42531 3715 (if (eq major-mode 'idlwave-shell-mode)
05a1abfc 3716 ;; This is a gross hack to avoit template abbrev expansion
15e42531
CD
3717 ;; in the shell. FIXME: This is a dirty hack.
3718 (if (and (eq this-command 'self-insert-command)
3719 (equal last-abbrev-location (point)))
3720 (insert last-abbrev-text)
3721 (error "No templates in idlwave-shell"))
3722 (cond ((eq idlwave-abbrev-change-case 'down)
3723 (setq s1 (downcase s1) s2 (downcase s2)))
3724 (idlwave-abbrev-change-case
3725 (setq s1 (upcase s1) s2 (upcase s2))))
3726 (let ((beg (save-excursion (beginning-of-line) (point)))
3727 end)
3728 (if (not (looking-at "\\s-*\n"))
3729 (open-line 1))
3730 (insert s1)
3731 (save-excursion
3732 (insert s2)
3733 (setq end (point)))
3734 (if (not noindent)
3735 (indent-region beg end nil))
3736 (if (stringp prompt)
3737 (message prompt)))))
31b58798 3738
595ab50b
CD
3739(defun idlwave-rw-case (string)
3740 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3741 (if idlwave-reserved-word-upcase
3742 (upcase string)
3743 string))
3744
f32b3b91
CD
3745(defun idlwave-elif ()
3746 "Build skeleton IDL if-else block."
3747 (interactive)
595ab50b
CD
3748 (idlwave-template
3749 (idlwave-rw-case "if")
3750 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3751 "Condition expression"))
f32b3b91
CD
3752
3753(defun idlwave-case ()
3754 "Build skeleton IDL case statement."
3755 (interactive)
31b58798 3756 (idlwave-template
595ab50b
CD
3757 (idlwave-rw-case "case")
3758 (idlwave-rw-case " of\n\nendcase")
3759 "Selector expression"))
f32b3b91 3760
05a1abfc
CD
3761(defun idlwave-switch ()
3762 "Build skeleton IDL switch statement."
3763 (interactive)
31b58798 3764 (idlwave-template
05a1abfc
CD
3765 (idlwave-rw-case "switch")
3766 (idlwave-rw-case " of\n\nendswitch")
3767 "Selector expression"))
3768
f32b3b91
CD
3769(defun idlwave-for ()
3770 "Build skeleton for loop statment."
3771 (interactive)
31b58798 3772 (idlwave-template
595ab50b
CD
3773 (idlwave-rw-case "for")
3774 (idlwave-rw-case " do begin\n\nendfor")
3775 "Loop expression"))
f32b3b91
CD
3776
3777(defun idlwave-if ()
3778 "Build skeleton for loop statment."
3779 (interactive)
595ab50b
CD
3780 (idlwave-template
3781 (idlwave-rw-case "if")
3782 (idlwave-rw-case " then begin\n\nendif")
3783 "Scalar logical expression"))
f32b3b91
CD
3784
3785(defun idlwave-procedure ()
3786 (interactive)
31b58798 3787 (idlwave-template
595ab50b
CD
3788 (idlwave-rw-case "pro")
3789 (idlwave-rw-case "\n\nreturn\nend")
3790 "Procedure name"))
f32b3b91
CD
3791
3792(defun idlwave-function ()
3793 (interactive)
31b58798 3794 (idlwave-template
595ab50b
CD
3795 (idlwave-rw-case "function")
3796 (idlwave-rw-case "\n\nreturn\nend")
3797 "Function name"))
f32b3b91
CD
3798
3799(defun idlwave-repeat ()
3800 (interactive)
595ab50b
CD
3801 (idlwave-template
3802 (idlwave-rw-case "repeat begin\n\nendrep until")
3803 (idlwave-rw-case "")
3804 "Exit condition"))
f32b3b91
CD
3805
3806(defun idlwave-while ()
3807 (interactive)
31b58798 3808 (idlwave-template
595ab50b
CD
3809 (idlwave-rw-case "while")
3810 (idlwave-rw-case " do begin\n\nendwhile")
3811 "Entry condition"))
f32b3b91
CD
3812
3813(defun idlwave-split-string (string &optional pattern)
3814 "Return a list of substrings of STRING which are separated by PATTERN.
3815If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3816 (or pattern
3817 (setq pattern "[ \f\t\n\r\v]+"))
3818 (let (parts (start 0))
3819 (while (string-match pattern string start)
3820 (setq parts (cons (substring string start (match-beginning 0)) parts)
3821 start (match-end 0)))
3822 (nreverse (cons (substring string start) parts))))
3823
3824(defun idlwave-replace-string (string replace_string replace_with)
3825 (let* ((start 0)
3826 (last (length string))
3827 (ret_string "")
3828 end)
3829 (while (setq end (string-match replace_string string start))
3830 (setq ret_string
3831 (concat ret_string (substring string start end) replace_with))
3832 (setq start (match-end 0)))
3833 (setq ret_string (concat ret_string (substring string start last)))))
3834
3835(defun idlwave-get-buffer-visiting (file)
3836 ;; Return the buffer currently visiting FILE
3837 (cond
3838 ((boundp 'find-file-compare-truenames) ; XEmacs
3839 (let ((find-file-compare-truenames t))
3840 (get-file-buffer file)))
3841 ((fboundp 'find-buffer-visiting) ; Emacs
3842 (find-buffer-visiting file))
3843 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3844
15e42531
CD
3845(defvar idlwave-outlawed-buffers nil
3846 "List of buffer pulled up by idlwave for special reasons.
3847Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3848
3849(defun idlwave-find-file-noselect (file &optional why)
f32b3b91
CD
3850 ;; Return a buffer visiting file.
3851 (or (idlwave-get-buffer-visiting file)
15e42531
CD
3852 (let ((buf (find-file-noselect file)))
3853 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3854 buf)))
3855
3856(defun idlwave-kill-autoloaded-buffers ()
52a244eb 3857 "Kill buffers created automatically by IDLWAVE.
15e42531
CD
3858Function prompts for a letter to identify the buffers to kill.
3859Possible letters are:
3860
3861f Buffers created by the command \\[idlwave-find-module] or mouse
3862 clicks in the routine info window.
3863s Buffers created by the IDLWAVE Shell to display where execution
3864 stopped or an error was found.
3865a Both of the above.
3866
3867Buffer containing unsaved changes require confirmation before they are killed."
3868 (interactive)
3869 (if (null idlwave-outlawed-buffers)
3870 (error "No IDLWAVE-created buffers available")
3871 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3872 (idlwave-count-outlawed-buffers 'find)
3873 (idlwave-count-outlawed-buffers 'shell)))
3874 (let ((c (read-char)))
3875 (cond
3876 ((member c '(?f ?\C-f))
3877 (idlwave-do-kill-autoloaded-buffers 'find))
3878 ((member c '(?s ?\C-s))
3879 (idlwave-do-kill-autoloaded-buffers 'shell))
3880 ((member c '(?a ?\C-a))
3881 (idlwave-do-kill-autoloaded-buffers t))
3882 (t (error "Abort"))))))
3883
3884(defun idlwave-count-outlawed-buffers (tag)
3885 "How many outlawed buffers have tag TAG?"
3886 (length (delq nil
31b58798
JB
3887 (mapcar
3888 (lambda (x) (eq (cdr x) tag))
15e42531
CD
3889 idlwave-outlawed-buffers))))
3890
3891(defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3892 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3893 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3894 (cnt 0)
3895 entry)
3896 (while (setq entry (pop list))
3897 (if (buffer-live-p (car entry))
3898 (and (or (memq t reasons)
3899 (memq (cdr entry) reasons))
3900 (kill-buffer (car entry))
3901 (incf cnt)
31b58798 3902 (setq idlwave-outlawed-buffers
15e42531 3903 (delq entry idlwave-outlawed-buffers)))
31b58798 3904 (setq idlwave-outlawed-buffers
15e42531
CD
3905 (delq entry idlwave-outlawed-buffers))))
3906 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3907
3908(defun idlwave-revoke-license-to-kill ()
3909 "Remove BUFFER from the buffers which may be killed.
3910Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3911Intended for `after-save-hook'."
3912 (let* ((buf (current-buffer))
3913 (entry (assq buf idlwave-outlawed-buffers)))
3914 ;; Revoke license
3915 (if entry
31b58798 3916 (setq idlwave-outlawed-buffers
15e42531
CD
3917 (delq entry idlwave-outlawed-buffers)))
3918 ;; Remove this function from the hook.
3919 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3920
3921(defvar idlwave-path-alist)
3922(defun idlwave-locate-lib-file (file)
f32b3b91 3923 ;; Find FILE on the scanned lib path and return a buffer visiting it
15e42531 3924 (let* ((dirs idlwave-path-alist)
f32b3b91
CD
3925 dir efile)
3926 (catch 'exit
15e42531 3927 (while (setq dir (car (pop dirs)))
f32b3b91
CD
3928 (if (file-regular-p
3929 (setq efile (expand-file-name file dir)))
15e42531 3930 (throw 'exit efile))))))
52a244eb 3931
15e42531
CD
3932(defun idlwave-expand-lib-file-name (file)
3933 ;; Find FILE on the scanned lib path and return a buffer visiting it
52a244eb 3934 ;; This is for, e.g., finding source with no user catalog
31b58798 3935 (cond
15e42531 3936 ((null file) nil)
15e42531
CD
3937 ((file-name-absolute-p file) file)
3938 (t (idlwave-locate-lib-file file))))
f32b3b91
CD
3939
3940(defun idlwave-make-tags ()
3941 "Creates the IDL tags file IDLTAGS in the current directory from
3942the list of directories specified in the minibuffer. Directories may be
3943for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3944specified top directories are searched if the directory name is prefixed
3945by @. Specify @ directories with care, it may take a long, long time if
3946you specify /."
3947 (interactive)
3948 (let (directory directories cmd append status numdirs dir getsubdirs
3949 buffer save_buffer files numfiles item errbuf)
31b58798 3950
f32b3b91
CD
3951 ;;
3952 ;; Read list of directories
3953 (setq directory (read-string "Tag Directories: " "."))
3954 (setq directories (idlwave-split-string directory "[ \t]+"))
3955 ;;
3956 ;; Set etags command, vars
3957 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3958\\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3959\\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3960 (setq append " ")
3961 (setq status 0)
3962 ;;
3963 ;; For each directory
3964 (setq numdirs 0)
3965 (setq dir (nth numdirs directories))
3966 (while (and dir)
3967 ;;
3968 ;; Find the subdirectories
3969 (if (string-match "^[@]\\(.+\\)$" dir)
3970 (setq getsubdirs t) (setq getsubdirs nil))
3971 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3972 (setq dir (expand-file-name dir))
3973 (if (file-directory-p dir)
3974 (progn
3975 (if (and getsubdirs)
3976 (progn
3977 (setq buffer (get-buffer-create "*idltags*"))
3978 (call-process "sh" nil buffer nil "-c"
3979 (concat "find " dir " -type d -print"))
3980 (setq save_buffer (current-buffer))
3981 (set-buffer buffer)
3982 (setq files (idlwave-split-string
3983 (idlwave-replace-string
3984 (buffer-substring 1 (point-max))
3985 "\n" "/*.pro ")
3986 "[ \t]+"))
3987 (set-buffer save_buffer)
3988 (kill-buffer buffer))
3989 (setq files (list (concat dir "/*.pro"))))
3990 ;;
3991 ;; For each subdirectory
3992 (setq numfiles 0)
3993 (setq item (nth numfiles files))
3994 (while (and item)
3995 ;;
3996 ;; Call etags
3997 (if (not (string-match "^[ \\t]*$" item))
3998 (progn
29a4e67d 3999 (message "%s" (concat "Tagging " item "..."))
f32b3b91 4000 (setq errbuf (get-buffer-create "*idltags-error*"))
52a244eb 4001 (setq status (+ status
31b58798 4002 (if (eq 0 (call-process
52a244eb
S
4003 "sh" nil errbuf nil "-c"
4004 (concat cmd append item)))
4005 0
4006 1)))
f32b3b91
CD
4007 ;;
4008 ;; Append additional tags
4009 (setq append " --append ")
4010 (setq numfiles (1+ numfiles))
4011 (setq item (nth numfiles files)))
4012 (progn
4013 (setq numfiles (1+ numfiles))
4014 (setq item (nth numfiles files))
4015 )))
31b58798 4016
f32b3b91
CD
4017 (setq numdirs (1+ numdirs))
4018 (setq dir (nth numdirs directories)))
4019 (progn
4020 (setq numdirs (1+ numdirs))
4021 (setq dir (nth numdirs directories)))))
31b58798 4022
f32b3b91
CD
4023 (setq errbuf (get-buffer-create "*idltags-error*"))
4024 (if (= status 0)
4025 (kill-buffer errbuf))
4026 (message "")
4027 ))
4028
4029(defun idlwave-toggle-comment-region (beg end &optional n)
4030 "Comment the lines in the region if the first non-blank line is
4031commented, and conversely, uncomment region. If optional prefix arg
4032N is non-nil, then for N positive, add N comment delimiters or for N
4033negative, remove N comment delimiters.
4034Uses `comment-region' which does not place comment delimiters on
4035blank lines."
4036 (interactive "r\nP")
4037 (if n
4038 (comment-region beg end (prefix-numeric-value n))
4039 (save-excursion
4040 (goto-char beg)
4041 (beginning-of-line)
4042 ;; skip blank lines
4043 (skip-chars-forward " \t\n")
4044 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
52a244eb
S
4045 (if (fboundp 'uncomment-region)
4046 (uncomment-region beg end)
4047 (comment-region beg end
4048 (- (length (buffer-substring
4049 (match-beginning 1)
4050 (match-end 1))))))
4051 (comment-region beg end)))))
f32b3b91
CD
4052
4053
4054;; ----------------------------------------------------------------------------
4055;; ----------------------------------------------------------------------------
4056;; ----------------------------------------------------------------------------
4057;; ----------------------------------------------------------------------------
4058;;
4059;; Completion and Routine Info
4060;;
4061
4062;; String "intern" functions
4063
4064;; For the completion and routine info function, we want to normalize
4065;; the case of procedure names etc. We do this by "interning" these
4066;; string is a hand-crafted way. Hashes are used to map the downcase
52a244eb
S
4067;; version of the strings to the cased versions. Most *-sint-*
4068;; variables consist of *two* hashes, a buffer+shell, followed by a
4069;; system hash. The former is re-scanned, and the latter takes case
4070;; precedence.
4071;;
4072;; Since these cased versions are really lisp objects, we can use `eq'
4073;; to search, which is a large performance boost. All new strings
4074;; need to be "sinterned". We do this as early as possible after
4075;; getting these strings from completion or buffer substrings. So
4076;; most of the code can simply assume to deal with "sinterned"
4077;; strings. The only exception is that the functions which scan whole
4078;; buffers for routine information do not intern the grabbed strings.
4079;; This is only done afterwards. Therefore in these functions it is
4080;; *not* safe to assume the strings can be compared with `eq' and be
4081;; fed into the routine assq functions.
f32b3b91
CD
4082
4083;; Here we define the hashing functions.
4084
4085;; The variables which hold the hashes.
4086(defvar idlwave-sint-routines '(nil))
4087(defvar idlwave-sint-keywords '(nil))
4088(defvar idlwave-sint-methods '(nil))
4089(defvar idlwave-sint-classes '(nil))
52a244eb
S
4090(defvar idlwave-sint-dirs '(nil))
4091(defvar idlwave-sint-libnames '(nil))
f32b3b91
CD
4092
4093(defun idlwave-reset-sintern (&optional what)
4094 "Reset all sintern hashes."
4095 ;; Make sure the hash functions are accessible.
4096 (if (or (not (fboundp 'gethash))
4097 (not (fboundp 'puthash)))
31b58798 4098 (progn
f32b3b91
CD
4099 (require 'cl)
4100 (or (fboundp 'puthash)
4101 (defalias 'puthash 'cl-puthash))))
4102 (let ((entries '((idlwave-sint-routines 1000 10)
4103 (idlwave-sint-keywords 1000 10)
4104 (idlwave-sint-methods 100 10)
4105 (idlwave-sint-classes 10 10))))
4106
4107 ;; Make sure these are lists
4108 (loop for entry in entries
4109 for var = (car entry)
4110 do (if (not (consp (symbol-value var))) (set var (list nil))))
4111
4112 (when (or (eq what t) (eq what 'syslib)
4113 (null (cdr idlwave-sint-routines)))
4114 ;; Reset the system & library hash
4115 (loop for entry in entries
4116 for var = (car entry) for size = (nth 1 entry)
31b58798 4117 do (setcdr (symbol-value var)
f32b3b91 4118 (make-hash-table ':size size ':test 'equal)))
52a244eb
S
4119 (setq idlwave-sint-dirs nil
4120 idlwave-sint-libnames nil))
f32b3b91
CD
4121
4122 (when (or (eq what t) (eq what 'bufsh)
4123 (null (car idlwave-sint-routines)))
4124 ;; Reset the buffer & shell hash
4125 (loop for entry in entries
4126 for var = (car entry) for size = (nth 1 entry)
31b58798 4127 do (setcar (symbol-value var)
f32b3b91
CD
4128 (make-hash-table ':size size ':test 'equal))))))
4129
4130(defun idlwave-sintern-routine-or-method (name &optional class set)
4131 (if class
4132 (idlwave-sintern-method name set)
4133 (idlwave-sintern-routine name set)))
4134
4135(defun idlwave-sintern (stype &rest args)
4136 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4137
4138;;(defmacro idlwave-sintern (type var)
4139;; `(cond ((not (stringp name)) name)
4140;; ((gethash (downcase name) (cdr ,var)))
4141;; ((gethash (downcase name) (car ,var)))
4142;; (set (idlwave-sintern-set name ,type ,var set))
4143;; (name)))
4144
4145(defun idlwave-sintern-routine (name &optional set)
4146 (cond ((not (stringp name)) name)
4147 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4148 ((gethash (downcase name) (car idlwave-sint-routines)))
4149 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4150 (name)))
4151(defun idlwave-sintern-keyword (name &optional set)
4152 (cond ((not (stringp name)) name)
4153 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4154 ((gethash (downcase name) (car idlwave-sint-keywords)))
4155 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4156 (name)))
4157(defun idlwave-sintern-method (name &optional set)
4158 (cond ((not (stringp name)) name)
4159 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4160 ((gethash (downcase name) (car idlwave-sint-methods)))
4161 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4162 (name)))
4163(defun idlwave-sintern-class (name &optional set)
4164 (cond ((not (stringp name)) name)
4165 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4166 ((gethash (downcase name) (car idlwave-sint-classes)))
4167 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4168 (name)))
4169
52a244eb
S
4170(defun idlwave-sintern-dir (dir &optional set)
4171 (car (or (member dir idlwave-sint-dirs)
4172 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4173(defun idlwave-sintern-libname (name &optional set)
4174 (car (or (member name idlwave-sint-libnames)
4175 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
f32b3b91
CD
4176
4177(defun idlwave-sintern-set (name type tables set)
4178 (let* ((func (or (cdr (assq type idlwave-completion-case))
4179 'identity))
4180 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4181 (table (if (eq set 'sys) (cdr tables) (car tables))))
4182 (puthash (downcase name) iname table)
4183 iname))
4184
52a244eb
S
4185(defun idlwave-sintern-keyword-list (kwd-list &optional set)
4186 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4187 (mapcar (lambda(x)
4188 (setcar x (idlwave-sintern-keyword (car x) set)))
4189 (cdr kwd-list))
4190 kwd-list)
4191
4192(defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4193 "Sintern all strings in the rinfo LIST. With optional parameter
4194SET: also set new patterns. Probably this will always have to be t.
4195If DEFAULT-DIR is passed, it is used as the base of the directory"
4196 (let (entry name type class kwds res source call new)
f32b3b91
CD
4197 (while list
4198 (setq entry (car list)
4199 list (cdr list)
4200 name (car entry)
4201 type (nth 1 entry)
4202 class (nth 2 entry)
4203 source (nth 3 entry)
4204 call (nth 4 entry)
52a244eb
S
4205 kwds (nthcdr 5 entry))
4206
4207 ;; The class and name
f32b3b91
CD
4208 (if class
4209 (progn
4210 (if (symbolp class) (setq class (symbol-name class)))
4211 (setq class (idlwave-sintern-class class set))
4212 (setq name (idlwave-sintern-method name set)))
4213 (setq name (idlwave-sintern-routine name set)))
31b58798 4214
52a244eb
S
4215 ;; The source
4216 (let ((source-type (car source))
4217 (source-file (nth 1 source))
31b58798 4218 (source-dir (if default-dir
52a244eb
S
4219 (file-name-as-directory default-dir)
4220 (nth 2 source)))
4221 (source-lib (nth 3 source)))
4222 (if (stringp source-dir)
4223 (setq source-dir (idlwave-sintern-dir source-dir set)))
4224 (if (stringp source-lib)
4225 (setq source-lib (idlwave-sintern-libname source-lib set)))
4226 (setq source (list source-type source-file source-dir source-lib)))
31b58798 4227
52a244eb
S
4228 ;; The keywords
4229 (setq kwds (mapcar (lambda (x)
4230 (idlwave-sintern-keyword-list x set))
4231 kwds))
4232
4233 ;; Build a canonicalized list
4234 (setq new (nconc (list name type class source call) kwds)
4235 res (cons new res)))
f32b3b91
CD
4236 (nreverse res)))
4237
05a1abfc
CD
4238;; Creating new sintern tables
4239
4240(defun idlwave-new-sintern-type (tag)
4241 "Define a variable and a function to sintern the new type TAG.
4242This defines the function `idlwave-sintern-TAG' and the variable
4243`idlwave-sint-TAGs'."
4244 (let* ((name (symbol-name tag))
4245 (names (concat name "s"))
4246 (var (intern (concat "idlwave-sint-" names)))
4247 (func (intern (concat "idlwave-sintern-" name))))
4248 (set var nil) ; initial value of the association list
4249 (fset func ; set the function
4250 `(lambda (name &optional set)
4251 (cond ((not (stringp name)) name)
4252 ((cdr (assoc (downcase name) ,var)))
4253 (set
4254 (setq ,var (cons (cons (downcase name) name) ,var))
4255 name)
4256 (name))))))
4257
4258(defun idlwave-reset-sintern-type (tag)
4259 "Reset the sintern variable associated with TAG."
4260 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4261
f32b3b91
CD
4262;;---------------------------------------------------------------------------
4263
4264
4265;; The variables which hold the information
15e42531 4266(defvar idlwave-system-routines nil
f32b3b91
CD
4267 "Holds the routine-info obtained by scanning buffers.")
4268(defvar idlwave-buffer-routines nil
4269 "Holds the routine-info obtained by scanning buffers.")
4270(defvar idlwave-compiled-routines nil
15e42531
CD
4271 "Holds the routine-info obtained by asking the shell.")
4272(defvar idlwave-unresolved-routines nil
4273 "Holds the unresolved routine-info obtained by asking the shell.")
52a244eb
S
4274(defvar idlwave-user-catalog-routines nil
4275 "Holds the procedure routine-info from the user scan.")
4276(defvar idlwave-library-catalog-routines nil
3938cb82
S
4277 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4278(defvar idlwave-library-catalog-libname nil
4279 "Name of library catalog loaded from .idlwave_catalog files.")
15e42531 4280(defvar idlwave-path-alist nil
52a244eb
S
4281 "Alist with !PATH directories and zero or more flags if the dir has
4282been scanned in a user catalog ('user) or discovered in a library
4283catalog \('lib).")
15e42531
CD
4284(defvar idlwave-true-path-alist nil
4285 "Like `idlwave-path-alist', but with true filenames.")
f32b3b91 4286(defvar idlwave-routines nil
52a244eb 4287 "Holds the combinded procedure/function/method routine-info.")
f32b3b91
CD
4288(defvar idlwave-class-alist nil
4289 "Holds the class names known to IDLWAVE.")
4290(defvar idlwave-class-history nil
4291 "The history of classes selected with the minibuffer.")
4292(defvar idlwave-force-class-query nil)
4293(defvar idlwave-before-completion-wconf nil
4294 "The window configuration just before the completion buffer was displayed.")
15e42531
CD
4295(defvar idlwave-last-system-routine-info-cons-cell nil
4296 "The last cons cell in the system routine info.")
f32b3b91
CD
4297
4298;;
4299;; The code to get routine info from different sources.
4300
15e42531 4301(defvar idlwave-system-routines)
5e72c6b2
S
4302(defvar idlwave-catalog-process nil
4303 "The background process currently updating the catalog.")
4304
f32b3b91
CD
4305(defun idlwave-routines ()
4306 "Provide a list of IDL routines.
4307This routine loads the builtin routines on the first call. Later it
4308only returns the value of the variable."
5e72c6b2
S
4309 (if (and idlwave-catalog-process
4310 (processp idlwave-catalog-process))
4311 (progn
4312 (cond
4313 ((equal (process-status idlwave-catalog-process) 'exit)
4314 (message "updating........")
4315 (setq idlwave-catalog-process nil)
4316 (idlwave-update-routine-info '(4)))
4317 ((equal (process-status idlwave-catalog-process) 'run)
4318 ;; Keep it running...
4319 )
4320 (t
4321 ;; Something is wrong, get rid of the process
4322 (message "Problem with catalog process") (beep)
4323 (condition-case nil
4324 (kill-process idlwave-catalog-process)
4325 (error nil))
4326 (setq idlwave-catalog-process nil)))))
f32b3b91
CD
4327 (or idlwave-routines
4328 (progn
4329 (idlwave-update-routine-info)
4330 ;; return the current value
4331 idlwave-routines)))
4332
05a1abfc
CD
4333(defvar idlwave-update-rinfo-hook nil
4334 "List of functions which should run after a global rinfo update.
4335Does not run after automatic updates of buffer or the shell.")
4336
5e72c6b2
S
4337(defun idlwave-rescan-catalog-directories ()
4338 "Rescan the previously selected directories. For batch processing."
4339 (idlwave-update-routine-info '(16)))
4340
4341(defun idlwave-rescan-asynchronously ()
4342 "Dispatch another emacs instance to update the idlwave catalog.
4343After the process finishes normally, the first access to routine info
4344will re-read the catalog."
4345 (interactive)
4346 (if (processp idlwave-catalog-process)
4347 (if (eq (process-status idlwave-catalog-process) 'run)
4348 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4349 (progn
4350 (condition-case nil
4351 (kill-process idlwave-catalog-process)
4352 (error nil))
4353 (error "Process killed, no new process started"))
4354 (error "Quit"))
4355 (condition-case nil
4356 (kill-process idlwave-catalog-process)
4357 (error nil))))
52a244eb
S
4358 (if (or (not idlwave-user-catalog-file)
4359 (not (stringp idlwave-user-catalog-file))
4360 (not (file-regular-p idlwave-user-catalog-file)))
5e72c6b2
S
4361 (error "No catalog has been produced yet"))
4362 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4363 (args (list "-batch"
4364 "-l" (expand-file-name "~/.emacs")
4365 "-l" "idlwave"
4366 "-f" "idlwave-rescan-catalog-directories"))
31b58798 4367 (process (apply 'start-process "idlcat"
5e72c6b2
S
4368 nil emacs args)))
4369 (setq idlwave-catalog-process process)
31b58798 4370 (set-process-sentinel
5e72c6b2
S
4371 process
4372 (lambda (pro why)
4373 (when (string-match "finished" why)
4374 (setq idlwave-routines nil
4375 idlwave-system-routines nil
4376 idlwave-catalog-process nil)
4377 (or (idlwave-start-load-rinfo-timer)
4378 (idlwave-update-routine-info '(4))))))
4379 (message "Background job started to update catalog file")))
4380
4381
52a244eb
S
4382;; Format for all routine info user catalog, library catalogs, etc.:
4383;;
4384;; ("ROUTINE" type class
4385;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4386;; (buffer pro_file dir) | (compiled pro_file dir)
4387;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
4388;;
4389;; DIR will be supplied dynamically while loading library catalogs,
4390;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4391;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4392;; be nil, as can LINK1, etc., if no HTML help is available.
4393
4394
5e72c6b2 4395(defvar idlwave-load-rinfo-idle-timer)
3938cb82
S
4396(defvar idlwave-shell-path-query)
4397
52a244eb 4398(defun idlwave-update-routine-info (&optional arg no-concatenate)
f32b3b91
CD
4399 "Update the internal routine-info lists.
4400These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4401and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4402about individual routines.
4403
4404The information can come from 4 sources:
44051. IDL programs in the current editing session
44062. Compiled modules in an IDL shell running as Emacs subprocess
44073. A list which covers the IDL system routines.
44084. A list which covers the prescanned library files.
4409
4410Scans all IDLWAVE-mode buffers of the current editing session (see
4411`idlwave-scan-all-buffers-for-routine-info').
4412When an IDL shell is running, this command also queries the IDL program
4413for currently compiled routines.
4414
4415With prefix ARG, also reload the system and library lists.
52a244eb
S
4416With two prefix ARG's, also rescans the chosen user catalog tree.
4417With three prefix args, dispatch asynchronous process to do the update.
4418
4419If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4420lists, but instead wait for the shell query to complete and
4421asynchronously finish updating routine info. This is set
4422automatically when called interactively. When you need routine
4423information updated immediately, leave NO-CONCATENATE nil."
751adbde 4424 (interactive "P\np")
5e72c6b2
S
4425 ;; Stop any idle processing
4426 (if (or (and (fboundp 'itimerp)
4427 (itimerp idlwave-load-rinfo-idle-timer))
4428 (and (fboundp 'timerp)
4429 (timerp idlwave-load-rinfo-idle-timer)))
4430 (cancel-timer idlwave-load-rinfo-idle-timer))
4431 (cond
4432 ((equal arg '(64))
4433 ;; Start a background process which updates the catalog.
4434 (idlwave-rescan-asynchronously))
4435 ((equal arg '(16))
52a244eb
S
4436 ;; Update the user catalog now, and wait for them.
4437 (idlwave-create-user-catalog-file t))
5e72c6b2
S
4438 (t
4439 (let* ((load (or arg
4440 idlwave-buffer-case-takes-precedence
4441 (null idlwave-routines)))
4442 ;; The override-idle means, even if the idle timer has done some
4443 ;; preparing work, load and renormalize everything anyway.
4444 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
31b58798 4445
f32b3b91 4446 (setq idlwave-buffer-routines nil
15e42531
CD
4447 idlwave-compiled-routines nil
4448 idlwave-unresolved-routines nil)
f32b3b91 4449 ;; Reset the appropriate hashes
5e72c6b2
S
4450 (if (get 'idlwave-reset-sintern 'done-by-idle)
4451 ;; reset was already done in idle time, so skip this step now once
4452 (put 'idlwave-reset-sintern 'done-by-idle nil)
4453 (idlwave-reset-sintern (cond (load t)
4454 ((null idlwave-system-routines) t)
4455 (t 'bufsh))))
31b58798 4456
f32b3b91
CD
4457 (if idlwave-buffer-case-takes-precedence
4458 ;; We can safely scan the buffer stuff first
4459 (progn
4460 (idlwave-update-buffer-routine-info)
5e72c6b2 4461 (and load (idlwave-load-system-rinfo override-idle)))
f32b3b91 4462 ;; We first do the system info, and then the buffers
5e72c6b2 4463 (and load (idlwave-load-system-rinfo override-idle))
f32b3b91
CD
4464 (idlwave-update-buffer-routine-info))
4465
4466 ;; Let's see if there is a shell
4467 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4468 (idlwave-shell-is-running)))
4469 (ask-shell (and shell-is-running
4470 idlwave-query-shell-for-routine-info)))
31b58798 4471
52a244eb 4472 ;; Load the library catalogs again, first re-scanning the path
31b58798 4473 (when arg
52a244eb
S
4474 (if shell-is-running
4475 (idlwave-shell-send-command idlwave-shell-path-query
4476 '(progn
4477 (idlwave-shell-get-path-info)
4478 (idlwave-scan-library-catalogs))
4479 'hide)
4480 (idlwave-scan-library-catalogs)))
775591f7 4481
f32b3b91 4482 (if (or (not ask-shell)
52a244eb 4483 (not no-concatenate))
f32b3b91
CD
4484 ;; 1. If we are not going to ask the shell, we need to do the
4485 ;; concatenation now.
52a244eb
S
4486 ;; 2. When this function is called non-interactively, it
4487 ;; means that someone needs routine info *now*. The
4488 ;; shell update causes the concatenation to be
4489 ;; *delayed*, so not in time for the current command.
4490 ;; Therefore, we do a concatenation now, even though
4491 ;; the shell might do it again.
4492 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
31b58798 4493
f32b3b91 4494 (when ask-shell
52a244eb 4495 ;; Ask the shell about the routines it knows of.
f32b3b91 4496 (message "Querying the shell")
5e72c6b2
S
4497 (idlwave-shell-update-routine-info nil t)))))))
4498
52a244eb
S
4499
4500(defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
5e72c6b2
S
4501(defvar idlwave-load-rinfo-idle-timer nil)
4502(defun idlwave-start-load-rinfo-timer ()
4503 (if (or (and (fboundp 'itimerp)
4504 (itimerp idlwave-load-rinfo-idle-timer))
4505 (and (fboundp 'timerp)
4506 (timerp idlwave-load-rinfo-idle-timer)))
4507 (cancel-timer idlwave-load-rinfo-idle-timer))
52a244eb 4508 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
5e72c6b2
S
4509 (setq idlwave-load-rinfo-idle-timer nil)
4510 (if (and idlwave-init-rinfo-when-idle-after
4511 (numberp idlwave-init-rinfo-when-idle-after)
4512 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4513 (not idlwave-routines))
4514 (condition-case nil
4515 (progn
4516 (setq idlwave-load-rinfo-idle-timer
4517 (run-with-idle-timer
4518 idlwave-init-rinfo-when-idle-after
4519 nil 'idlwave-load-rinfo-next-step)))
4520 (error nil))))
4521
3938cb82
S
4522(defvar idlwave-library-routines nil "Obsolete variable.")
4523
5e72c6b2
S
4524(defun idlwave-load-rinfo-next-step ()
4525 (let ((inhibit-quit t)
4526 (arr idlwave-load-rinfo-steps-done))
52a244eb 4527 (when (catch 'exit
5e72c6b2
S
4528 (when (not (aref arr 0))
4529 (message "Loading idlw-rinfo.el in idle time...")
4530 (load "idlw-rinfo" 'noerror 'nomessage)
4531 (message "Loading idlw-rinfo.el in idle time...done")
4532 (aset arr 0 t)
4533 (throw 'exit t))
4534 (when (not (aref arr 1))
4535 (message "Normalizing idlwave-system-routines in idle time...")
4536 (idlwave-reset-sintern t)
4537 (put 'idlwave-reset-sintern 'done-by-idle t)
4538 (setq idlwave-system-routines
4539 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4540 (message "Normalizing idlwave-system-routines in idle time...done")
4541 (aset arr 1 t)
4542 (throw 'exit t))
4543 (when (not (aref arr 2))
52a244eb
S
4544 (when (and (stringp idlwave-user-catalog-file)
4545 (file-regular-p idlwave-user-catalog-file))
4546 (message "Loading user catalog in idle time...")
5e72c6b2 4547 (condition-case nil
52a244eb
S
4548 (load-file idlwave-user-catalog-file)
4549 (error (throw 'exit nil)))
4550 ;; Check for the old style catalog and warn
4551 (if (and
4552 (boundp 'idlwave-library-routines)
4553 idlwave-library-routines)
775591f7 4554 (progn
52a244eb
S
4555 (setq idlwave-library-routines nil)
4556 (ding)
31b58798 4557 (message "Outdated user catalog: %s... recreate"
52a244eb
S
4558 idlwave-user-catalog-file))
4559 (message "Loading user catalog in idle time...done"))
4560 (aset arr 2 t)
4561 (throw 'exit t)))
5e72c6b2 4562 (when (not (aref arr 3))
52a244eb
S
4563 (when idlwave-user-catalog-routines
4564 (message "Normalizing user catalog routines in idle time...")
31b58798 4565 (setq idlwave-user-catalog-routines
52a244eb
S
4566 (idlwave-sintern-rinfo-list
4567 idlwave-user-catalog-routines 'sys))
31b58798 4568 (message
52a244eb 4569 "Normalizing user catalog routines in idle time...done"))
5e72c6b2
S
4570 (aset arr 3 t)
4571 (throw 'exit t))
4572 (when (not (aref arr 4))
31b58798 4573 (idlwave-scan-library-catalogs
52a244eb
S
4574 "Loading and normalizing library catalogs in idle time...")
4575 (aset arr 4 t)
4576 (throw 'exit t))
4577 (when (not (aref arr 5))
5e72c6b2
S
4578 (message "Finishing initialization in idle time...")
4579 (idlwave-routines)
4580 (message "Finishing initialization in idle time...done")
4581 (throw 'exit nil)))
52a244eb
S
4582 ;; restart the timer
4583 (if (sit-for 1)
4584 (idlwave-load-rinfo-next-step)
4585 (setq idlwave-load-rinfo-idle-timer
4586 (run-with-idle-timer
4587 idlwave-init-rinfo-when-idle-after
4588 nil 'idlwave-load-rinfo-next-step))))))
5e72c6b2
S
4589
4590(defun idlwave-load-system-rinfo (&optional force)
52a244eb 4591 ;; Load and case-treat the system and catalog files.
5e72c6b2
S
4592 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
4593 (load "idlw-rinfo" 'noerror 'nomessage))
4594 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
4595 (message "Normalizing idlwave-system-routines...")
4596 (setq idlwave-system-routines
4597 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4598 (message "Normalizing idlwave-system-routines...done"))
15e42531
CD
4599 (setq idlwave-routines (copy-sequence idlwave-system-routines))
4600 (setq idlwave-last-system-routine-info-cons-cell
4601 (nthcdr (1- (length idlwave-routines)) idlwave-routines))
52a244eb
S
4602 (when (and (stringp idlwave-user-catalog-file)
4603 (file-regular-p idlwave-user-catalog-file))
f32b3b91 4604 (condition-case nil
52a244eb
S
4605 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
4606 (load-file idlwave-user-catalog-file))
4607 (error nil))
4608 (when (boundp 'idlwave-library-routines)
4609 (setq idlwave-library-routines nil)
4610 (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file))
4611 (setq idlwave-true-path-alist nil)
4612 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
4613 (message "Normalizing user catalog routines...")
31b58798
JB
4614 (setq idlwave-user-catalog-routines
4615 (idlwave-sintern-rinfo-list
52a244eb
S
4616 idlwave-user-catalog-routines 'sys))
4617 (message "Normalizing user catalog routines...done")))
4618 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
4619 (idlwave-scan-library-catalogs
4620 "Loading and normalizing library catalogs..."))
05a1abfc
CD
4621 (run-hooks 'idlwave-after-load-rinfo-hook))
4622
f32b3b91
CD
4623
4624(defun idlwave-update-buffer-routine-info ()
4625 (let (res)
31b58798 4626 (cond
15e42531
CD
4627 ((eq idlwave-scan-all-buffers-for-routine-info t)
4628 ;; Scan all buffers, current buffer last
4629 (message "Scanning all buffers...")
31b58798 4630 (setq res (idlwave-get-routine-info-from-buffers
15e42531
CD
4631 (reverse (buffer-list)))))
4632 ((null idlwave-scan-all-buffers-for-routine-info)
4633 ;; Don't scan any buffers
4634 (setq res nil))
4635 (t
f32b3b91
CD
4636 ;; Just scan this buffer
4637 (if (eq major-mode 'idlwave-mode)
4638 (progn
4639 (message "Scanning current buffer...")
4640 (setq res (idlwave-get-routine-info-from-buffers
15e42531 4641 (list (current-buffer))))))))
f32b3b91 4642 ;; Put the result into the correct variable
31b58798 4643 (setq idlwave-buffer-routines
52a244eb 4644 (idlwave-sintern-rinfo-list res 'set))))
f32b3b91 4645
05a1abfc 4646(defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
f32b3b91 4647 "Put the different sources for routine information together."
31b58798 4648 ;; The sequence here is important because earlier definitions shadow
f32b3b91 4649 ;; later ones. We assume that if things in the buffers are newer
52a244eb 4650 ;; then in the shell of the system, they are meant to be different.
15e42531
CD
4651 (setcdr idlwave-last-system-routine-info-cons-cell
4652 (append idlwave-buffer-routines
4653 idlwave-compiled-routines
52a244eb
S
4654 idlwave-library-catalog-routines
4655 idlwave-user-catalog-routines))
f32b3b91 4656 (setq idlwave-class-alist nil)
15e42531 4657
f32b3b91 4658 ;; Give a message with information about the number of routines we have.
15e42531 4659 (unless quiet
31b58798 4660 (message
52a244eb 4661 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
15e42531
CD
4662 (length idlwave-buffer-routines)
4663 (length idlwave-compiled-routines)
52a244eb
S
4664 (length idlwave-library-catalog-routines)
4665 (length idlwave-user-catalog-routines)
05a1abfc
CD
4666 (length idlwave-system-routines)))
4667 (if run-hook
4668 (run-hooks 'idlwave-update-rinfo-hook)))
15e42531
CD
4669
4670(defun idlwave-class-alist ()
4671 "Return the class alist - make it if necessary."
4672 (or idlwave-class-alist
4673 (let (class)
4674 (loop for x in idlwave-routines do
4675 (when (and (setq class (nth 2 x))
4676 (not (assq class idlwave-class-alist)))
4677 (push (list class) idlwave-class-alist)))
31b58798 4678 idlwave-class-alist)))
15e42531
CD
4679
4680;; Three functions for the hooks
4681(defun idlwave-save-buffer-update ()
4682 (idlwave-update-current-buffer-info 'save-buffer))
4683(defun idlwave-kill-buffer-update ()
4684 (idlwave-update-current-buffer-info 'kill-buffer))
4685(defun idlwave-new-buffer-update ()
4686 (idlwave-update-current-buffer-info 'find-file))
4687
4688(defun idlwave-update-current-buffer-info (why)
52a244eb 4689 "Update idlwave-routines for current buffer. Can run from after-save-hook."
15e42531
CD
4690 (when (and (eq major-mode 'idlwave-mode)
4691 (or (eq t idlwave-auto-routine-info-updates)
4692 (memq why idlwave-auto-routine-info-updates))
4693 idlwave-scan-all-buffers-for-routine-info
4694 idlwave-routines)
4695 (condition-case nil
4696 (let (routines)
4697 (idlwave-replace-buffer-routine-info
4698 (buffer-file-name)
4699 (if (eq why 'kill-buffer)
4700 nil
4701 (setq routines
4702 (idlwave-sintern-rinfo-list
4703 (idlwave-get-routine-info-from-buffers
4704 (list (current-buffer))) 'set))))
4705 (idlwave-concatenate-rinfo-lists 'quiet)
4706 routines)
4707 (error nil))))
4708
4709(defun idlwave-replace-buffer-routine-info (file new)
4710 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
31b58798 4711 (let ((list idlwave-buffer-routines)
15e42531
CD
4712 found)
4713 (while list
4714 ;; The following test uses eq to make sure it works correctly
4715 ;; when two buffers visit the same file. Then the file names
4716 ;; will be equal, but not eq.
52a244eb 4717 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
15e42531
CD
4718 (progn
4719 (setcar list nil)
4720 (setq found t))
4721 (if found
31b58798 4722 ;; End of that section reached. Jump.
15e42531
CD
4723 (setq list nil)))
4724 (setq list (cdr list)))
4725 (setq idlwave-buffer-routines
4726 (append new (delq nil idlwave-buffer-routines)))))
f32b3b91
CD
4727
4728;;----- Scanning buffers -------------------
4729
4730(defun idlwave-get-routine-info-from-buffers (buffers)
4731 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4732 (let (buf routine-lists res)
4733 (save-excursion
4734 (while (setq buf (pop buffers))
4735 (set-buffer buf)
05a1abfc
CD
4736 (if (and (eq major-mode 'idlwave-mode)
4737 buffer-file-name)
f32b3b91
CD
4738 ;; yes, this buffer has the right mode.
4739 (progn (setq res (condition-case nil
4740 (idlwave-get-buffer-routine-info)
4741 (error nil)))
4742 (push res routine-lists)))))
4743 ;; Concatenate the individual lists and return the result
4744 (apply 'nconc routine-lists)))
4745
4746(defun idlwave-get-buffer-routine-info ()
4747 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4748 (let* ((case-fold-search t)
4749 routine-list string entry)
4750 (save-excursion
4751 (save-restriction
4752 (widen)
4753 (goto-char (point-min))
31b58798 4754 (while (re-search-forward
15e42531 4755 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
76959b77 4756 (setq string (buffer-substring-no-properties
f32b3b91 4757 (match-beginning 0)
31b58798 4758 (progn
f32b3b91
CD
4759 (idlwave-end-of-statement)
4760 (point))))
4761 (setq entry (idlwave-parse-definition string))
4762 (push entry routine-list))))
4763 routine-list))
4764
15e42531 4765(defvar idlwave-scanning-lib-dir)
f32b3b91
CD
4766(defun idlwave-parse-definition (string)
4767 "Parse a module definition."
4768 (let ((case-fold-search t)
4769 start name args type keywords class)
4770 ;; Remove comments
4771 (while (string-match ";.*" string)
4772 (setq string (replace-match "" t t string)))
4773 ;; Remove the continuation line stuff
4774 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
4775 (setq string (replace-match "\\1 " t nil string)))
05a1abfc
CD
4776 (while (string-match "\n" string)
4777 (setq string (replace-match " " t nil string)))
f32b3b91
CD
4778 ;; Match the name and type.
4779 (when (string-match
4780 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
4781 (setq start (match-end 0))
4782 (setq type (downcase (match-string 1 string)))
4783 (if (match-beginning 3)
4784 (setq class (match-string 3 string)))
4785 (setq name (match-string 4 string)))
4786 ;; Match normal args and keyword args
4787 (while (string-match
15e42531 4788 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
f32b3b91
CD
4789 string start)
4790 (setq start (match-end 0))
15e42531 4791 (if (match-beginning 3)
f32b3b91
CD
4792 (push (match-string 1 string) keywords)
4793 (push (match-string 1 string) args)))
4794 ;; Normalize and sort.
4795 (setq args (nreverse args))
31b58798 4796 (setq keywords (sort keywords (lambda (a b)
f32b3b91
CD
4797 (string< (downcase a) (downcase b)))))
4798 ;; Make and return the entry
4799 ;; We don't know which argument are optional, so this information
4800 ;; will not be contained in the calling sequence.
4801 (list name
4802 (if (equal type "pro") 'pro 'fun)
4803 class
4804 (cond ((not (boundp 'idlwave-scanning-lib))
52a244eb 4805 (list 'buffer (buffer-file-name)))
31b58798 4806; ((string= (downcase
15e42531
CD
4807; (file-name-sans-extension
4808; (file-name-nondirectory (buffer-file-name))))
4809; (downcase name))
4810; (list 'lib))
4811; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
52a244eb
S
4812 (t (list 'user (file-name-nondirectory (buffer-file-name))
4813 idlwave-scanning-lib-dir "UserLib")))
31b58798 4814 (concat
f32b3b91
CD
4815 (if (string= type "function") "Result = " "")
4816 (if class "Obj ->[%s::]" "")
4817 "%s"
4818 (if args
4819 (concat
4820 (if (string= type "function") "(" ", ")
4821 (mapconcat 'identity args ", ")
4822 (if (string= type "function") ")" ""))))
4823 (if keywords
52a244eb 4824 (cons nil (mapcar 'list keywords)) ;No help file
f32b3b91
CD
4825 nil))))
4826
f32b3b91 4827
52a244eb 4828;;----- Scanning the user catalog -------------------
15e42531
CD
4829
4830(defun idlwave-sys-dir ()
4831 "Return the syslib directory, or a dummy that never matches."
3938cb82
S
4832 (cond
4833 ((and idlwave-system-directory
4834 (not (string= idlwave-system-directory "")))
4835 idlwave-system-directory)
4836 ((getenv "IDL_DIR"))
4837 (t "@@@@@@@@")))
4838
52a244eb 4839
15e42531 4840
52a244eb 4841(defun idlwave-create-user-catalog-file (&optional arg)
f32b3b91 4842 "Scan all files on selected dirs of IDL search path for routine information.
52a244eb
S
4843
4844A widget checklist will allow you to choose the directories. Write
4845the result as a file `idlwave-user-catalog-file'. When this file
4846exists, will be automatically loaded to give routine information about
4847library routines. With ARG, just rescan the same directories as last
4848time - so no widget will pop up."
f32b3b91
CD
4849 (interactive "P")
4850 ;; Make sure the file is loaded if it exists.
52a244eb
S
4851 (if (and (stringp idlwave-user-catalog-file)
4852 (file-regular-p idlwave-user-catalog-file))
f32b3b91 4853 (condition-case nil
52a244eb 4854 (load-file idlwave-user-catalog-file)
f32b3b91
CD
4855 (error nil)))
4856 ;; Make sure the file name makes sense
52a244eb
S
4857 (unless (and (stringp idlwave-user-catalog-file)
4858 (> (length idlwave-user-catalog-file) 0)
f32b3b91 4859 (file-accessible-directory-p
52a244eb 4860 (file-name-directory idlwave-user-catalog-file))
31b58798 4861 (not (string= "" (file-name-nondirectory
52a244eb
S
4862 idlwave-user-catalog-file))))
4863 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
31b58798 4864
f32b3b91 4865 (cond
f32b3b91 4866 ;; Rescan the known directories
52a244eb
S
4867 ((and arg idlwave-path-alist
4868 (consp (car idlwave-path-alist)))
4869 (idlwave-scan-user-lib-files idlwave-path-alist))
4870
4871 ;; Expand the directories from library-path and run the widget
f32b3b91 4872 (idlwave-library-path
52a244eb 4873 (idlwave-display-user-catalog-widget
31b58798 4874 (if idlwave-true-path-alist
52a244eb
S
4875 ;; Propagate any flags on the existing path-alist
4876 (mapcar (lambda (x)
4877 (let ((path-entry (assoc (file-truename x)
4878 idlwave-true-path-alist)))
4879 (if path-entry
31b58798 4880 (cons x (cdr path-entry))
52a244eb
S
4881 (list x))))
4882 (idlwave-expand-path idlwave-library-path))
4883 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
4884
4885 ;; Ask the shell for the path and then run the widget
f32b3b91 4886 (t
f32b3b91 4887 (message "Asking the shell for IDL path...")
15e42531
CD
4888 (require 'idlw-shell)
4889 (idlwave-shell-send-command idlwave-shell-path-query
52a244eb 4890 '(idlwave-user-catalog-command-hook nil)
15e42531 4891 'hide))))
f32b3b91 4892
52a244eb
S
4893
4894;; Parse shell path information and select among it.
4895(defun idlwave-user-catalog-command-hook (&optional arg)
4896 ;; Command hook used by `idlwave-create-user-catalog-file'.
f32b3b91
CD
4897 (if arg
4898 ;; Scan immediately
52a244eb
S
4899 (idlwave-scan-user-lib-files idlwave-path-alist)
4900 ;; Set the path and display the widget
4901 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
4902 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
4903 (idlwave-display-user-catalog-widget idlwave-path-alist)))
4904
31b58798 4905(defconst idlwave-user-catalog-widget-help-string
52a244eb
S
4906 "This is the front-end to the creation of the IDLWAVE user catalog.
4907Please select the directories on IDL's search path from which you
4908would like to extract routine information, to be stored in the file:
f32b3b91
CD
4909
4910 %s
4911
52a244eb
S
4912If this is not the correct file, first set variable
4913`idlwave-user-catalog-file', and call this command again.
15e42531 4914
52a244eb
S
4915N.B. Many libraries include pre-scanned catalog files
4916\(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
4917not be scanned. You can scan your own libraries off-line using the
4918perl script `idlwave_catalog'.
15e42531 4919
f32b3b91
CD
4920After selecting the directories, choose [Scan & Save] to scan the library
4921directories and save the routine info.
4922\n")
4923
4924(defvar idlwave-widget)
4925(defvar widget-keymap)
52a244eb 4926(defun idlwave-display-user-catalog-widget (dirs-list)
f32b3b91
CD
4927 "Create the widget to select IDL search path directories for scanning."
4928 (interactive)
4929 (require 'widget)
4930 (require 'wid-edit)
52a244eb 4931 (unless dirs-list
f32b3b91
CD
4932 (error "Don't know IDL's search path"))
4933
f32b3b91
CD
4934 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4935 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4936 (kill-all-local-variables)
4937 (make-local-variable 'idlwave-widget)
52a244eb
S
4938 (widget-insert (format idlwave-user-catalog-widget-help-string
4939 idlwave-user-catalog-file))
31b58798 4940
f32b3b91 4941 (widget-create 'push-button
52a244eb 4942 :notify 'idlwave-widget-scan-user-lib-files
f32b3b91
CD
4943 "Scan & Save")
4944 (widget-insert " ")
4945 (widget-create 'push-button
52a244eb 4946 :notify 'idlwave-delete-user-catalog-file
f32b3b91
CD
4947 "Delete File")
4948 (widget-insert " ")
4949 (widget-create 'push-button
31b58798 4950 :notify
52a244eb
S
4951 '(lambda (&rest ignore)
4952 (let ((path-list (widget-get idlwave-widget :path-dirs)))
4953 (mapcar (lambda (x)
4954 (unless (memq 'lib (cdr x))
4955 (idlwave-path-alist-add-flag x 'user)))
4956 path-list)
4957 (idlwave-display-user-catalog-widget path-list)))
4958 "Select All Non-Lib")
f32b3b91
CD
4959 (widget-insert " ")
4960 (widget-create 'push-button
31b58798 4961 :notify
52a244eb
S
4962 '(lambda (&rest ignore)
4963 (let ((path-list (widget-get idlwave-widget :path-dirs)))
4964 (mapcar (lambda (x)
4965 (idlwave-path-alist-remove-flag x 'user))
4966 path-list)
4967 (idlwave-display-user-catalog-widget path-list)))
f32b3b91 4968 "Deselect All")
52a244eb
S
4969 (widget-insert " ")
4970 (widget-create 'push-button
4971 :notify (lambda (&rest ignore)
4972 (kill-buffer (current-buffer)))
4973 "Quit")
f32b3b91
CD
4974 (widget-insert "\n\n")
4975
52a244eb 4976 (widget-insert "Select Directories: \n")
31b58798 4977
f32b3b91
CD
4978 (setq idlwave-widget
4979 (apply 'widget-create
4980 'checklist
31b58798
JB
4981 :value (delq nil (mapcar (lambda (x)
4982 (if (memq 'user (cdr x))
52a244eb
S
4983 (car x)))
4984 dirs-list))
f32b3b91
CD
4985 :greedy t
4986 :tag "List of directories"
31b58798
JB
4987 (mapcar (lambda (x)
4988 (list 'item
52a244eb
S
4989 (if (memq 'lib (cdr x))
4990 (concat "[LIB] " (car x) )
4991 (car x)))) dirs-list)))
4992 (widget-put idlwave-widget :path-dirs dirs-list)
f32b3b91
CD
4993 (widget-insert "\n")
4994 (use-local-map widget-keymap)
4995 (widget-setup)
4996 (goto-char (point-min))
4997 (delete-other-windows))
31b58798 4998
52a244eb 4999(defun idlwave-delete-user-catalog-file (&rest ignore)
f32b3b91 5000 (if (yes-or-no-p
52a244eb 5001 (format "Delete file %s " idlwave-user-catalog-file))
f32b3b91 5002 (progn
52a244eb
S
5003 (delete-file idlwave-user-catalog-file)
5004 (message "%s has been deleted" idlwave-user-catalog-file))))
f32b3b91 5005
52a244eb
S
5006(defun idlwave-widget-scan-user-lib-files (&rest ignore)
5007 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
f32b3b91 5008 (let* ((widget idlwave-widget)
15e42531 5009 (selected-dirs (widget-value widget))
52a244eb
S
5010 (path-alist (widget-get widget :path-dirs))
5011 (this-path-alist path-alist)
5012 dir-entry)
5013 (while (setq dir-entry (pop this-path-alist))
31b58798 5014 (if (member
52a244eb
S
5015 (if (memq 'lib (cdr dir-entry))
5016 (concat "[LIB] " (car dir-entry))
5017 (car dir-entry))
5018 selected-dirs)
5019 (idlwave-path-alist-add-flag dir-entry 'user)
5020 (idlwave-path-alist-remove-flag dir-entry 'user)))
5021 (idlwave-scan-user-lib-files path-alist)))
f32b3b91
CD
5022
5023(defvar font-lock-mode)
52a244eb
S
5024(defun idlwave-scan-user-lib-files (path-alist)
5025 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
f32b3b91 5026 (let* ((idlwave-scanning-lib t)
15e42531 5027 (idlwave-scanning-lib-dir "")
f32b3b91 5028 (idlwave-completion-case nil)
15e42531 5029 dirs-alist dir files file)
52a244eb
S
5030 (setq idlwave-user-catalog-routines nil
5031 idlwave-path-alist path-alist ; for library-path instead
5032 idlwave-true-path-alist nil)
5033 (if idlwave-auto-write-paths (idlwave-write-paths))
f32b3b91
CD
5034 (save-excursion
5035 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5036 (idlwave-mode)
15e42531
CD
5037 (setq dirs-alist (reverse path-alist))
5038 (while (setq dir (pop dirs-alist))
52a244eb 5039 (when (memq 'user (cdr dir)) ; Has it marked for scan?
15e42531 5040 (setq dir (car dir))
52a244eb 5041 (setq idlwave-scanning-lib-dir dir)
15e42531
CD
5042 (when (file-directory-p dir)
5043 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5044 (while (setq file (pop files))
5045 (when (file-regular-p file)
5046 (if (not (file-readable-p file))
5047 (message "Skipping %s (no read permission)" file)
5048 (message "Scanning %s..." file)
5049 (erase-buffer)
5050 (insert-file-contents file 'visit)
52a244eb 5051 (setq idlwave-user-catalog-routines
15e42531
CD
5052 (append (idlwave-get-routine-info-from-buffers
5053 (list (current-buffer)))
52a244eb
S
5054 idlwave-user-catalog-routines)))))))))
5055 (message "Creating user catalog file...")
f32b3b91
CD
5056 (kill-buffer "*idlwave-scan.pro*")
5057 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
15e42531
CD
5058 (let ((font-lock-maximum-size 0)
5059 (auto-mode-alist nil))
52a244eb 5060 (find-file idlwave-user-catalog-file))
f32b3b91
CD
5061 (if (and (boundp 'font-lock-mode)
5062 font-lock-mode)
5063 (font-lock-mode 0))
5064 (erase-buffer)
52a244eb 5065 (insert ";; IDLWAVE user catalog file\n")
f32b3b91
CD
5066 (insert (format ";; Created %s\n\n" (current-time-string)))
5067
f32b3b91 5068 ;; Define the routine info list
52a244eb 5069 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5e72c6b2
S
5070 (let ((standard-output (current-buffer)))
5071 (mapcar (lambda (x)
5072 (insert "\n ")
5073 (prin1 x)
5074 (goto-char (point-max)))
52a244eb 5075 idlwave-user-catalog-routines))
f32b3b91 5076 (insert (format "))\n\n;;; %s ends here\n"
52a244eb 5077 (file-name-nondirectory idlwave-user-catalog-file)))
f32b3b91
CD
5078 (goto-char (point-min))
5079 ;; Save the buffer
5080 (save-buffer 0)
5081 (kill-buffer (current-buffer)))
52a244eb 5082 (message "Creating user catalog file...done")
f32b3b91 5083 (message "Info for %d routines saved in %s"
52a244eb
S
5084 (length idlwave-user-catalog-routines)
5085 idlwave-user-catalog-file)
f32b3b91
CD
5086 (sit-for 2)
5087 (idlwave-update-routine-info t))
5088
52a244eb
S
5089(defun idlwave-read-paths ()
5090 (if (and (stringp idlwave-path-file)
5091 (file-regular-p idlwave-path-file))
5092 (condition-case nil
5093 (load idlwave-path-file t t t)
5094 (error nil))))
5095
5096(defun idlwave-write-paths ()
5097 (interactive)
5098 (when (and idlwave-path-alist idlwave-system-directory)
5099 (let ((font-lock-maximum-size 0)
5100 (auto-mode-alist nil))
5101 (find-file idlwave-path-file))
5102 (if (and (boundp 'font-lock-mode)
5103 font-lock-mode)
5104 (font-lock-mode 0))
5105 (erase-buffer)
5106 (insert ";; IDLWAVE paths\n")
5107 (insert (format ";; Created %s\n\n" (current-time-string)))
5108 ;; Define the variable which knows the value of "!DIR"
5109 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5110 idlwave-system-directory))
31b58798 5111
52a244eb
S
5112 ;; Define the variable which contains a list of all scanned directories
5113 (insert "\n(setq idlwave-path-alist\n '(")
5114 (let ((standard-output (current-buffer)))
5115 (mapcar (lambda (x)
5116 (insert "\n ")
5117 (prin1 x)
5118 (goto-char (point-max)))
5119 idlwave-path-alist))
5120 (insert "))\n")
5121 (save-buffer 0)
5122 (kill-buffer (current-buffer))))
5123
5124
f32b3b91
CD
5125(defun idlwave-expand-path (path &optional default-dir)
5126 ;; Expand parts of path starting with '+' recursively into directory list.
5127 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5128 (message "Expanding path...")
5129 (let (path1 dir recursive)
5130 (while (setq dir (pop path))
5131 (if (setq recursive (string= (substring dir 0 1) "+"))
5132 (setq dir (substring dir 1)))
5133 (if (and recursive
5134 (not (file-name-absolute-p dir)))
5135 (setq dir (expand-file-name dir default-dir)))
5136 (if recursive
5137 ;; Expand recursively
5138 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5139 ;; Keep unchanged
5140 (push dir path1)))
5141 (message "Expanding path...done")
5142 (nreverse path1)))
5143
5144(defun idlwave-recursive-directory-list (dir)
5145 ;; Return a list of all directories below DIR, including DIR itself
5146 (let ((path (list dir)) path1 file files)
5147 (while (setq dir (pop path))
5148 (when (file-directory-p dir)
5149 (setq files (nreverse (directory-files dir t "[^.]")))
5150 (while (setq file (pop files))
31b58798 5151 (if (file-directory-p file)
f32b3b91
CD
5152 (push (file-name-as-directory file) path)))
5153 (push dir path1)))
5154 path1))
5155
52a244eb
S
5156
5157;;----- Scanning the library catalogs ------------------
5158
3938cb82
S
5159
5160
5161
52a244eb 5162(defun idlwave-scan-library-catalogs (&optional message-base no-load)
31b58798 5163 "Scan for library catalog files (.idlwave_catalog) and ingest.
52a244eb
S
5164
5165All directories on `idlwave-path-alist' (or `idlwave-library-path'
5166instead, if present) are searched. Print MESSAGE-BASE along with the
5167libraries being loaded, if passed, and skip loading/normalizing if
5168NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5169be set to nil to disable library catalog scanning."
5170 (when idlwave-use-library-catalogs
31b58798 5171 (let ((dirs
52a244eb
S
5172 (if idlwave-library-path
5173 (idlwave-expand-path idlwave-library-path)
5174 (mapcar 'car idlwave-path-alist)))
5175 (old-libname "")
5176 dir-entry dir flags catalog all-routines)
5177 (if message-base (message message-base))
5178 (while (setq dir (pop dirs))
5179 (catch 'continue
31b58798 5180 (when (file-readable-p
52a244eb
S
5181 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5182 (unless no-load
5183 (setq idlwave-library-catalog-routines nil)
5184 ;; Load the catalog file
5185 (condition-case nil
5186 (load catalog t t t)
5187 (error (throw 'continue t)))
31b58798
JB
5188 (when (and
5189 message-base
5190 (not (string= idlwave-library-catalog-libname
52a244eb 5191 old-libname)))
29a4e67d 5192 (message "%s" (concat message-base
52a244eb
S
5193 idlwave-library-catalog-libname))
5194 (setq old-libname idlwave-library-catalog-libname))
5195 (when idlwave-library-catalog-routines
5196 (setq all-routines
31b58798 5197 (append
52a244eb
S
5198 (idlwave-sintern-rinfo-list
5199 idlwave-library-catalog-routines 'sys dir)
5200 all-routines))))
31b58798 5201
52a244eb
S
5202 ;; Add a 'lib flag if on path-alist
5203 (when (and idlwave-path-alist
5204 (setq dir-entry (assoc dir idlwave-path-alist)))
5205 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5206 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5207 (if message-base (message (concat message-base "done"))))))
5208
5209;;----- Communicating with the Shell -------------------
f32b3b91
CD
5210
5211;; First, here is the idl program which can be used to query IDL for
31b58798 5212;; defined routines.
f32b3b91
CD
5213(defconst idlwave-routine-info.pro
5214 "
05a1abfc 5215;; START OF IDLWAVE SUPPORT ROUTINES
15e42531 5216pro idlwave_print_info_entry,name,func=func,separator=sep
f32b3b91 5217 ;; See if it's an object method
15e42531 5218 if name eq '' then return
31b58798 5219 func = keyword_set(func)
f32b3b91
CD
5220 methsep = strpos(name,'::')
5221 meth = methsep ne -1
31b58798 5222
f32b3b91
CD
5223 ;; Get routine info
5224 pars = routine_info(name,/parameters,functions=func)
5225 source = routine_info(name,/source,functions=func)
5226 nargs = pars.num_args
5227 nkw = pars.num_kw_args
5228 if nargs gt 0 then args = pars.args
5229 if nkw gt 0 then kwargs = pars.kw_args
31b58798 5230
f32b3b91 5231 ;; Trim the class, and make the name
31b58798 5232 if meth then begin
f32b3b91
CD
5233 class = strmid(name,0,methsep)
5234 name = strmid(name,methsep+2,strlen(name)-1)
31b58798 5235 if nargs gt 0 then begin
f32b3b91
CD
5236 ;; remove the self argument
5237 wh = where(args ne 'SELF',nargs)
52a244eb 5238 if nargs gt 0 then args = args[wh]
f32b3b91
CD
5239 endif
5240 endif else begin
5241 ;; No class, just a normal routine.
5242 class = \"\"
5243 endelse
31b58798 5244
f32b3b91
CD
5245 ;; Calling sequence
5246 cs = \"\"
5247 if func then cs = 'Result = '
5248 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5249 cs = cs + '%s'
5250 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5251 if nargs gt 0 then begin
5252 for j=0,nargs-1 do begin
52a244eb 5253 cs = cs + args[j]
f32b3b91
CD
5254 if j lt nargs-1 then cs = cs + ', '
5255 endfor
5256 end
5257 if func then cs = cs + ')'
5258 ;; Keyword arguments
5259 kwstring = ''
5260 if nkw gt 0 then begin
5261 for j=0,nkw-1 do begin
52a244eb 5262 kwstring = kwstring + ' ' + kwargs[j]
f32b3b91
CD
5263 endfor
5264 endif
31b58798 5265
52a244eb 5266 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
31b58798 5267
52a244eb 5268 print,ret + ': ' + name + sep + class + sep + source[0].path $
f32b3b91
CD
5269 + sep + cs + sep + kwstring
5270end
5271
5272pro idlwave_routine_info
52a244eb 5273 on_error,1
f32b3b91
CD
5274 sep = '<@>'
5275 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5276 all = routine_info()
5277 for i=0,n_elements(all)-1 do $
52a244eb 5278 idlwave_print_info_entry,all[i],separator=sep
f32b3b91
CD
5279 all = routine_info(/functions)
5280 for i=0,n_elements(all)-1 do $
52a244eb 5281 idlwave_print_info_entry,all[i],/func,separator=sep
f32b3b91
CD
5282 print,'>>>END OF IDLWAVE ROUTINE INFO'
5283end
05a1abfc
CD
5284
5285pro idlwave_get_sysvars
52a244eb 5286 on_error,1
05a1abfc
CD
5287 catch,error_status
5288 if error_status ne 0 then begin
5289 print, 'Cannot get info about system variables'
5290 endif else begin
5291 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5292 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5293 v = strsplit(s,' +',/regex,/extract) ; get variables
5294 for i=0,n_elements(v)-1 do begin
5295 t = [''] ; get tag list
5296 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5297 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5298 endfor
5299 endelse
5300end
5301
5302pro idlwave_get_class_tags, class
5303 res = execute('tags=tag_names({'+class+'})')
5e72c6b2 5304 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
05a1abfc
CD
5305end
5306;; END OF IDLWAVE SUPPORT ROUTINES
31b58798 5307"
05a1abfc 5308 "The idl programs to get info from the shell.")
f32b3b91 5309
15e42531
CD
5310(defvar idlwave-idlwave_routine_info-compiled nil
5311 "Remembers if the routine info procedure is already compiled.")
f32b3b91
CD
5312
5313(defvar idlwave-shell-temp-pro-file)
15e42531 5314(defvar idlwave-shell-temp-rinfo-save-file)
52a244eb 5315(defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait)
f32b3b91 5316 "Query the shell for routine_info of compiled modules and update the lists."
15e42531
CD
5317 ;; Save and compile the procedure. The compiled procedure is then
5318 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5319 ;; We need to RESTORE the procedure each time we use it, since
5e72c6b2 5320 ;; the user may have killed or redefined it. In particular,
15e42531
CD
5321 ;; .RESET_SESSION will kill all user procedures.
5322 (unless (and idlwave-idlwave_routine_info-compiled
5e72c6b2 5323 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
15e42531
CD
5324 (save-excursion
5325 (set-buffer (idlwave-find-file-noselect
5e72c6b2 5326 (idlwave-shell-temp-file 'pro)))
15e42531
CD
5327 (erase-buffer)
5328 (insert idlwave-routine-info.pro)
5329 (save-buffer 0))
31b58798 5330 (idlwave-shell-send-command
15e42531 5331 (concat ".run " idlwave-shell-temp-pro-file)
52a244eb 5332 nil 'hide wait)
5e72c6b2 5333; (message "SENDING SAVE") ; ????????????????????????
15e42531 5334 (idlwave-shell-send-command
31b58798 5335 (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5e72c6b2 5336 (idlwave-shell-temp-file 'rinfo))
52a244eb 5337 nil 'hide wait))
15e42531
CD
5338
5339 ;; Restore and execute the procedure, analyze the output
5e72c6b2 5340; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
15e42531
CD
5341 (idlwave-shell-send-command
5342 (format "RESTORE, '%s' & idlwave_routine_info"
5343 idlwave-shell-temp-rinfo-save-file)
5344 `(progn
5345 (idlwave-shell-routine-info-filter)
05a1abfc 5346 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
52a244eb 5347 'hide wait))
f32b3b91
CD
5348
5349;; ---------------------------------------------------------------------------
5350;;
5351;; Completion and displaying routine calling sequences
5352
15e42531 5353(defvar idlwave-completion-help-info nil)
52a244eb 5354(defvar idlwave-completion-help-links nil)
15e42531 5355(defvar idlwave-current-obj_new-class nil)
05a1abfc 5356(defvar idlwave-complete-special nil)
15e42531 5357
f32b3b91
CD
5358(defun idlwave-complete (&optional arg module class)
5359 "Complete a function, procedure or keyword name at point.
2e8b9c7d 5360This function is smart and figures out what can be completed
f32b3b91
CD
5361at this point.
5362- At the beginning of a statement it completes procedure names.
5363- In the middle of a statement it completes function names.
5364- after a `(' or `,' in the argument list of a function or procedure,
5365 it completes a keyword of the relevant function or procedure.
5366- In the first arg of `OBJ_NEW', it completes a class name.
5367
5e72c6b2 5368When several completions are possible, a list will be displayed in the
f32b3b91 5369*Completions* buffer. If this list is too long to fit into the
5e72c6b2
S
5370window, scrolling can be achieved by repeatedly pressing
5371\\[idlwave-complete].
f32b3b91
CD
5372
5373The function also knows about object methods. When it needs a class
5374name, the action depends upon `idlwave-query-class', which see. You
5e72c6b2
S
5375can force IDLWAVE to ask you for a class name with a
5376\\[universal-argument] prefix argument to this command.
f32b3b91
CD
5377
5378See also the variables `idlwave-keyword-completion-adds-equal' and
5379`idlwave-function-completion-adds-paren'.
5380
5381The optional ARG can be used to specify the completion type in order
5382to override IDLWAVE's idea of what should be completed at point.
5383Possible values are:
5384
53850 <=> query for the completion type
53861 <=> 'procedure
53872 <=> 'procedure-keyword
53883 <=> 'function
53894 <=> 'function-keyword
53905 <=> 'procedure-method
53916 <=> 'procedure-method-keyword
53927 <=> 'function-method
53938 <=> 'function-method-keyword
53949 <=> 'class
5395
5e72c6b2
S
5396As a special case, the universal argument C-u forces completion of
5397function names in places where the default would be a keyword.
5398
52a244eb
S
5399Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5400completion.
5401
f32b3b91
CD
5402For Lisp programmers only:
5403When we force a keyword, optional argument MODULE can contain the module name.
5404When we force a method or a method keyword, CLASS can specify the class."
5405 (interactive "P")
5406 (idlwave-routines)
5407 (let* ((where-list
5408 (if (and arg
52a244eb 5409 (or (and (integerp arg) (not (equal arg '(16))))
f32b3b91
CD
5410 (symbolp arg)))
5411 (idlwave-make-force-complete-where-list arg module class)
5412 (idlwave-where)))
5413 (what (nth 2 where-list))
52a244eb
S
5414 (idlwave-force-class-query (equal arg '(4)))
5415 (completion-regexp-list
5416 (if (equal arg '(16))
5417 (list (read-string (concat "Completion Regexp: "))))))
31b58798 5418
f32b3b91
CD
5419 (if (and module (string-match "::" module))
5420 (setq class (substring module 0 (match-beginning 0))
5421 module (substring module (match-end 0))))
5422
5423 (cond
5424
5425 ((and (null arg)
5426 (eq (car-safe last-command) 'idlwave-display-completion-list)
595ab50b 5427 (get-buffer-window "*Completions*"))
f32b3b91
CD
5428 (setq this-command last-command)
5429 (idlwave-scroll-completions))
5430
52a244eb 5431 ;; Complete a filename in quotes
05a1abfc
CD
5432 ((and (idlwave-in-quote)
5433 (not (eq what 'class)))
5434 (idlwave-complete-filename))
5435
52a244eb
S
5436 ;; Check for any special completion functions
5437 ((and idlwave-complete-special
5438 (idlwave-call-special idlwave-complete-special)))
31b58798 5439
f32b3b91
CD
5440 ((null what)
5441 (error "Nothing to complete here"))
5442
52a244eb 5443 ;; Complete a class
f32b3b91 5444 ((eq what 'class)
15e42531 5445 (setq idlwave-completion-help-info '(class))
f32b3b91
CD
5446 (idlwave-complete-class))
5447
5448 ((eq what 'procedure)
5449 ;; Complete a procedure name
5e72c6b2
S
5450 (let* ((cw-list (nth 3 where-list))
5451 (class-selector (idlwave-determine-class cw-list 'pro))
5452 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5453 (idlwave-all-class-inherits class-selector)))
f32b3b91
CD
5454 (isa (concat "procedure" (if class-selector "-method" "")))
5455 (type-selector 'pro))
31b58798 5456 (setq idlwave-completion-help-info
05a1abfc 5457 (list 'routine nil type-selector class-selector nil super-classes))
f32b3b91
CD
5458 (idlwave-complete-in-buffer
5459 'procedure (if class-selector 'method 'routine)
5460 (idlwave-routines) 'idlwave-selector
5461 (format "Select a %s name%s"
5462 isa
5463 (if class-selector
31b58798
JB
5464 (format " (class is %s)"
5465 (if (eq class-selector t)
76959b77 5466 "unknown" class-selector))
f32b3b91
CD
5467 ""))
5468 isa
52a244eb 5469 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
f32b3b91
CD
5470
5471 ((eq what 'function)
5472 ;; Complete a function name
5e72c6b2
S
5473 (let* ((cw-list (nth 3 where-list))
5474 (class-selector (idlwave-determine-class cw-list 'fun))
5475 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5476 (idlwave-all-class-inherits class-selector)))
f32b3b91
CD
5477 (isa (concat "function" (if class-selector "-method" "")))
5478 (type-selector 'fun))
31b58798 5479 (setq idlwave-completion-help-info
05a1abfc 5480 (list 'routine nil type-selector class-selector nil super-classes))
f32b3b91
CD
5481 (idlwave-complete-in-buffer
5482 'function (if class-selector 'method 'routine)
5483 (idlwave-routines) 'idlwave-selector
5484 (format "Select a %s name%s"
5485 isa
5486 (if class-selector
31b58798 5487 (format " (class is %s)"
76959b77
S
5488 (if (eq class-selector t)
5489 "unknown" class-selector))
f32b3b91
CD
5490 ""))
5491 isa
52a244eb 5492 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
f32b3b91 5493
52a244eb 5494 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5e72c6b2
S
5495 (equal arg '(4)))
5496 (idlwave-complete 3))
5497
f32b3b91
CD
5498 ((eq what 'procedure-keyword)
5499 ;; Complete a procedure keyword
5500 (let* ((where (nth 3 where-list))
5501 (name (car where))
5502 (method-selector name)
5503 (type-selector 'pro)
5504 (class (idlwave-determine-class where 'pro))
5505 (class-selector class)
05a1abfc 5506 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91 5507 (isa (format "procedure%s-keyword" (if class "-method" "")))
15e42531 5508 (entry (idlwave-best-rinfo-assq
f32b3b91 5509 name 'pro class (idlwave-routines)))
3938cb82 5510 (system (if entry (eq (car (nth 3 entry)) 'system)))
52a244eb 5511 (list (idlwave-entry-keywords entry 'do-link)))
f32b3b91
CD
5512 (unless (or entry (eq class t))
5513 (error "Nothing known about procedure %s"
5514 (idlwave-make-full-name class name)))
31b58798 5515 (setq list (idlwave-fix-keywords name 'pro class list
3938cb82 5516 super-classes system))
b6a97790 5517 (unless list (error "No keywords available for procedure %s"
3938cb82 5518 (idlwave-make-full-name class name)))
31b58798 5519 (setq idlwave-completion-help-info
52a244eb 5520 (list 'keyword name type-selector class-selector entry super-classes))
f32b3b91
CD
5521 (idlwave-complete-in-buffer
5522 'keyword 'keyword list nil
5523 (format "Select keyword for procedure %s%s"
5524 (idlwave-make-full-name class name)
15e42531 5525 (if (or (member '("_EXTRA") list)
31b58798 5526 (member '("_REF_EXTRA") list))
15e42531 5527 " (note _EXTRA)" ""))
f32b3b91
CD
5528 isa
5529 'idlwave-attach-keyword-classes)))
5530
5531 ((eq what 'function-keyword)
5532 ;; Complete a function keyword
5533 (let* ((where (nth 3 where-list))
5534 (name (car where))
5535 (method-selector name)
5536 (type-selector 'fun)
5537 (class (idlwave-determine-class where 'fun))
5538 (class-selector class)
05a1abfc 5539 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91 5540 (isa (format "function%s-keyword" (if class "-method" "")))
15e42531 5541 (entry (idlwave-best-rinfo-assq
f32b3b91 5542 name 'fun class (idlwave-routines)))
3938cb82 5543 (system (if entry (eq (car (nth 3 entry)) 'system)))
52a244eb 5544 (list (idlwave-entry-keywords entry 'do-link))
15e42531 5545 msg-name)
f32b3b91
CD
5546 (unless (or entry (eq class t))
5547 (error "Nothing known about function %s"
5548 (idlwave-make-full-name class name)))
31b58798 5549 (setq list (idlwave-fix-keywords name 'fun class list
3938cb82 5550 super-classes system))
15e42531
CD
5551 ;; OBJ_NEW: Messages mention the proper Init method
5552 (setq msg-name (if (and (null class)
5553 (string= (upcase name) "OBJ_NEW"))
5554 (concat idlwave-current-obj_new-class
5555 "::Init (via OBJ_NEW)")
5556 (idlwave-make-full-name class name)))
b6a97790 5557 (unless list (error "No keywords available for function %s"
3938cb82 5558 msg-name))
31b58798 5559 (setq idlwave-completion-help-info
05a1abfc 5560 (list 'keyword name type-selector class-selector nil super-classes))
f32b3b91
CD
5561 (idlwave-complete-in-buffer
5562 'keyword 'keyword list nil
15e42531
CD
5563 (format "Select keyword for function %s%s" msg-name
5564 (if (or (member '("_EXTRA") list)
31b58798 5565 (member '("_REF_EXTRA") list))
15e42531 5566 " (note _EXTRA)" ""))
f32b3b91
CD
5567 isa
5568 'idlwave-attach-keyword-classes)))
15e42531 5569
f32b3b91
CD
5570 (t (error "This should not happen (idlwave-complete)")))))
5571
05a1abfc
CD
5572(defvar idlwave-complete-special nil
5573 "List of special completion functions.
52a244eb
S
5574These functions are called for each completion. Each function must
5575check if its own special completion context is present. If yes, it
5576should use `idlwave-complete-in-buffer' to do some completion and
5577return t. If such a function returns t, *no further* attempts to
5578complete other contexts will be done. If the function returns nil,
5579other completions will be tried.")
76959b77
S
5580
5581(defun idlwave-call-special (functions &rest args)
5582 (let ((funcs functions)
5583 fun ret)
05a1abfc 5584 (catch 'exit
76959b77
S
5585 (while (setq fun (pop funcs))
5586 (if (setq ret (apply fun args))
5587 (throw 'exit ret)))
05a1abfc
CD
5588 nil)))
5589
f32b3b91
CD
5590(defun idlwave-make-force-complete-where-list (what &optional module class)
5591 ;; Return an artificial WHERE specification to force the completion
5592 ;; routine to complete a specific item independent of context.
5593 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5594 ;; MODULE and CLASS can be used to specify the routine name and class.
5595 ;; The class name will also be found in MODULE if that is like "class::mod".
5596 (let* ((what-list '(("procedure") ("procedure-keyword")
5597 ("function") ("function-keyword")
5598 ("procedure-method") ("procedure-method-keyword")
5599 ("function-method") ("function-method-keyword")
5600 ("class")))
5601 (module (idlwave-sintern-routine-or-method module class))
5602 (class (idlwave-sintern-class class))
31b58798 5603 (what (cond
f32b3b91
CD
5604 ((equal what 0)
5605 (setq what
31b58798 5606 (intern (completing-read
f32b3b91
CD
5607 "Complete what? " what-list nil t))))
5608 ((integerp what)
5609 (setq what (intern (car (nth (1- what) what-list)))))
5610 ((and what
5611 (symbolp what)
5612 (assoc (symbol-name what) what-list))
5613 what)
eac9c0ef 5614 (t (error "Invalid WHAT"))))
f32b3b91
CD
5615 (nil-list '(nil nil nil nil))
5616 (class-list (list nil nil (or class t) nil)))
5617
5618 (cond
5619
5620 ((eq what 'procedure)
5621 (list nil-list nil-list 'procedure nil-list nil))
5622
5623 ((eq what 'procedure-keyword)
5624 (let* ((class-selector nil)
05a1abfc 5625 (super-classes nil)
f32b3b91
CD
5626 (type-selector 'pro)
5627 (pro (or module
31b58798 5628 (idlwave-completing-read
f32b3b91
CD
5629 "Procedure: " (idlwave-routines) 'idlwave-selector))))
5630 (setq pro (idlwave-sintern-routine pro))
5631 (list nil-list nil-list 'procedure-keyword
5632 (list pro nil nil nil) nil)))
5633
5634 ((eq what 'function)
5635 (list nil-list nil-list 'function nil-list nil))
5636
5637 ((eq what 'function-keyword)
5638 (let* ((class-selector nil)
05a1abfc 5639 (super-classes nil)
f32b3b91
CD
5640 (type-selector 'fun)
5641 (func (or module
31b58798 5642 (idlwave-completing-read
f32b3b91
CD
5643 "Function: " (idlwave-routines) 'idlwave-selector))))
5644 (setq func (idlwave-sintern-routine func))
5645 (list nil-list nil-list 'function-keyword
5646 (list func nil nil nil) nil)))
5647
5648 ((eq what 'procedure-method)
5649 (list nil-list nil-list 'procedure class-list nil))
5650
5651 ((eq what 'procedure-method-keyword)
5652 (let* ((class (idlwave-determine-class class-list 'pro))
5653 (class-selector class)
05a1abfc 5654 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91
CD
5655 (type-selector 'pro)
5656 (pro (or module
5657 (idlwave-completing-read
5658 (format "Procedure in %s class: " class-selector)
5659 (idlwave-routines) 'idlwave-selector))))
5660 (setq pro (idlwave-sintern-method pro))
5661 (list nil-list nil-list 'procedure-keyword
5662 (list pro nil class nil) nil)))
5663
5664 ((eq what 'function-method)
5665 (list nil-list nil-list 'function class-list nil))
5666
5667 ((eq what 'function-method-keyword)
5668 (let* ((class (idlwave-determine-class class-list 'fun))
5669 (class-selector class)
05a1abfc 5670 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91
CD
5671 (type-selector 'fun)
5672 (func (or module
5673 (idlwave-completing-read
5674 (format "Function in %s class: " class-selector)
5675 (idlwave-routines) 'idlwave-selector))))
5676 (setq func (idlwave-sintern-method func))
5677 (list nil-list nil-list 'function-keyword
5678 (list func nil class nil) nil)))
5679
5680 ((eq what 'class)
5681 (list nil-list nil-list 'class nil-list nil))
31b58798 5682
eac9c0ef 5683 (t (error "Invalid value for WHAT")))))
f32b3b91
CD
5684
5685(defun idlwave-completing-read (&rest args)
5686 ;; Completing read, case insensitive
5687 (let ((old-value (default-value 'completion-ignore-case)))
5688 (unwind-protect
5689 (progn
5690 (setq-default completion-ignore-case t)
5691 (apply 'completing-read args))
5692 (setq-default completion-ignore-case old-value))))
5693
05a1abfc
CD
5694(defvar idlwave-shell-default-directory)
5695(defun idlwave-complete-filename ()
5696 "Use the comint stuff to complete a file name."
5697 (require 'comint)
5698 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5699 (comint-completion-addsuffix nil)
5700 (default-directory
5701 (if (and (boundp 'idlwave-shell-default-directory)
5702 (stringp idlwave-shell-default-directory)
5703 (file-directory-p idlwave-shell-default-directory))
5704 idlwave-shell-default-directory
31b58798 5705 default-directory)))
05a1abfc
CD
5706 (comint-dynamic-complete-filename)))
5707
f32b3b91
CD
5708(defun idlwave-make-full-name (class name)
5709 ;; Make a fully qualified module name including the class name
5710 (concat (if class (format "%s::" class) "") name))
5711
15e42531
CD
5712(defun idlwave-rinfo-assoc (name type class list)
5713 "Like `idlwave-rinfo-assq', but sintern strings first."
31b58798 5714 (idlwave-rinfo-assq
15e42531
CD
5715 (idlwave-sintern-routine-or-method name class)
5716 type (idlwave-sintern-class class) list))
5717
f32b3b91
CD
5718(defun idlwave-rinfo-assq (name type class list)
5719 ;; Works like assq, but also checks type and class
5720 (catch 'exit
5721 (let (match)
5722 (while (setq match (assq name list))
5723 (and (or (eq type t)
5724 (eq (nth 1 match) type))
5725 (eq (nth 2 match) class)
5726 (throw 'exit match))
5727 (setq list (cdr (memq match list)))))))
5728
05a1abfc 5729(defun idlwave-rinfo-assq-any-class (name type class list)
52a244eb 5730 ;; Return the first matching method on the inheritance list
05a1abfc
CD
5731 (let* ((classes (cons class (idlwave-all-class-inherits class)))
5732 class rtn)
5733 (while classes
5734 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
5735 (setq classes nil)))
5736 rtn))
5737
31b58798 5738(defun idlwave-best-rinfo-assq (name type class list &optional with-file
52a244eb
S
5739 keep-system)
5740 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
5741If WITH-FILE is passed, find the best rinfo entry with a file
5742included. If KEEP-SYSTEM is set, don't prune system for compiled
5743syslib files."
15e42531 5744 (let ((twins (idlwave-routine-twins
05a1abfc 5745 (idlwave-rinfo-assq-any-class name type class list)
15e42531
CD
5746 list))
5747 syslibp)
5748 (when (> (length twins) 1)
5749 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
52a244eb
S
5750 (if (and (null keep-system)
5751 (eq 'system (car (nth 3 (car twins))))
15e42531
CD
5752 (setq syslibp (idlwave-any-syslib (cdr twins)))
5753 (not (equal 1 syslibp)))
52a244eb
S
5754 ;; Its a compiled syslib, so we need to remove the system entry
5755 (setq twins (cdr twins)))
5756 (if with-file
5757 (setq twins (delq nil
5758 (mapcar (lambda (x)
5759 (if (nth 1 (nth 3 x)) x))
5760 twins)))))
15e42531
CD
5761 (car twins)))
5762
31b58798 5763(defun idlwave-best-rinfo-assoc (name type class list &optional with-file
52a244eb 5764 keep-system)
15e42531
CD
5765 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5766 (idlwave-best-rinfo-assq
5767 (idlwave-sintern-routine-or-method name class)
52a244eb 5768 type (idlwave-sintern-class class) list with-file keep-system))
15e42531
CD
5769
5770(defun idlwave-any-syslib (entries)
5771 "Does the entry list ENTRIES contain a syslib entry?
5772If yes, return the index (>=1)."
5773 (let (file (cnt 0))
5774 (catch 'exit
5775 (while entries
5776 (incf cnt)
52a244eb
S
5777 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
5778 (if (and file (idlwave-syslib-p file))
15e42531
CD
5779 (throw 'exit cnt)
5780 (setq entries (cdr entries))))
5781 nil)))
5782
f32b3b91
CD
5783(defun idlwave-all-assq (key list)
5784 "Return a list of all associations of Key in LIST."
5785 (let (rtn elt)
5786 (while (setq elt (assq key list))
5787 (push elt rtn)
5788 (setq list (cdr (memq elt list))))
5789 (nreverse rtn)))
5790
5791(defun idlwave-all-method-classes (method &optional type)
5792 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5793When TYPE is not specified, both procedures and functions will be considered."
5794 (if (null method)
15e42531 5795 (mapcar 'car (idlwave-class-alist))
f32b3b91
CD
5796 (let (rtn)
5797 (mapcar (lambda (x)
5798 (and (nth 2 x)
5799 (or (not type)
5800 (eq type (nth 1 x)))
5801 (push (nth 2 x) rtn)))
5802 (idlwave-all-assq method (idlwave-routines)))
5803 (idlwave-uniquify rtn))))
5804
5805(defun idlwave-all-method-keyword-classes (method keyword &optional type)
5806 "Return all classes which have a method METHOD with keyword KEYWORD.
5807TYPE is 'fun or 'pro.
5808When TYPE is not specified, both procedures and functions will be considered."
5809 (if (or (null method)
5810 (null keyword))
5811 nil
5812 (let (rtn)
5813 (mapcar (lambda (x)
52a244eb
S
5814 (and (nth 2 x) ; non-nil class
5815 (or (not type) ; correct or unspecified type
f32b3b91 5816 (eq type (nth 1 x)))
52a244eb 5817 (assoc keyword (idlwave-entry-keywords x))
f32b3b91
CD
5818 (push (nth 2 x) rtn)))
5819 (idlwave-all-assq method (idlwave-routines)))
5820 (idlwave-uniquify rtn))))
5821
05a1abfc
CD
5822(defun idlwave-members-only (list club)
5823 "Return list of all elements in LIST which are also in CLUB."
5824 (let (rtn)
5825 (while list
5826 (if (member (car list) club)
5827 (setq rtn (cons (car list) rtn)))
5828 (setq list (cdr list)))
5829 (nreverse rtn)))
5830
5831(defun idlwave-nonmembers-only (list club)
5832 "Return list of all elements in LIST which are not in CLUB."
5833 (let (rtn)
5834 (while list
5835 (if (member (car list) club)
5836 nil
5837 (setq rtn (cons (car list) rtn)))
5838 (setq list (cdr list)))
5839 (nreverse rtn)))
5840
5e72c6b2
S
5841(defun idlwave-explicit-class-listed (info)
5842 "Return whether or not the class is listed explicitly, ala a->b::c.
5843INFO is as returned by idlwave-what-function or -procedure."
5844 (let ((apos (nth 3 info)))
5845 (if apos
5846 (save-excursion (goto-char apos)
5847 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5848
76959b77
S
5849(defvar idlwave-determine-class-special nil
5850 "List of special functions for determining class.
5851Must accept two arguments: `apos' and `info'")
5852
f32b3b91 5853(defun idlwave-determine-class (info type)
31b58798 5854 ;; Determine the class of a routine call.
76959b77
S
5855 ;; INFO is the `cw-list' structure as returned by idlwave-where.
5856 ;; The second element in this structure is the class. When nil, we
5857 ;; return nil. When t, try to get the class from text properties at
5858 ;; the arrow. When the object is "self", we use the class of the
5859 ;; current routine. otherwise prompt the user for a class name.
5860 ;; Also stores the selected class as a text property at the arrow.
f32b3b91
CD
5861 ;; TYPE is 'fun or 'pro.
5862 (let* ((class (nth 2 info))
5863 (apos (nth 3 info))
5864 (nassoc (assoc (if (stringp (car info))
5865 (upcase (car info))
5866 (car info))
5867 idlwave-query-class))
5868 (dassoc (assq (if (car info) 'keyword-default 'method-default)
5869 idlwave-query-class))
5870 (query (cond (nassoc (cdr nassoc))
5871 (dassoc (cdr dassoc))
5872 (t t)))
5873 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
31b58798 5874 (is-self
15e42531
CD
5875 (and arrow
5876 (save-excursion (goto-char apos)
5877 (forward-word -1)
5878 (let ((case-fold-search t))
5879 (looking-at "self\\>")))))
f32b3b91 5880 (force-query idlwave-force-class-query)
76959b77 5881 store special-class class-alist)
f32b3b91
CD
5882 (cond
5883 ((null class) nil)
5884 ((eq t class)
5885 ;; There is an object which would like to know its class
5886 (if (and arrow (get-text-property apos 'idlwave-class)
5887 idlwave-store-inquired-class
5888 (not force-query))
5889 (setq class (get-text-property apos 'idlwave-class)
5890 class (idlwave-sintern-class class)))
76959b77
S
5891 (if (and (eq t class) is-self)
5892 (setq class (or (nth 2 (idlwave-current-routine)) class)))
5893
5894 ;; Before prompting, try any special class determination routines
31b58798 5895 (when (and (eq t class)
76959b77
S
5896 idlwave-determine-class-special
5897 (not force-query))
31b58798 5898 (setq special-class
76959b77 5899 (idlwave-call-special idlwave-determine-class-special apos))
31b58798 5900 (if special-class
76959b77
S
5901 (setq class (idlwave-sintern-class special-class)
5902 store idlwave-store-inquired-class)))
31b58798 5903
76959b77 5904 ;; Prompt for a class, if we need to
f32b3b91
CD
5905 (when (and (eq class t)
5906 (or force-query query))
31b58798 5907 (setq class-alist
f32b3b91
CD
5908 (mapcar 'list (idlwave-all-method-classes (car info) type)))
5909 (setq class
5910 (idlwave-sintern-class
5911 (cond
5912 ((and (= (length class-alist) 0) (not force-query))
5913 (error "No classes available with method %s" (car info)))
5914 ((and (= (length class-alist) 1) (not force-query))
5915 (car (car class-alist)))
31b58798 5916 (t
f32b3b91 5917 (setq store idlwave-store-inquired-class)
31b58798 5918 (idlwave-completing-read
f32b3b91
CD
5919 (format "Class%s: " (if (stringp (car info))
5920 (format " for %s method %s"
5921 type (car info))
5922 ""))
5923 class-alist nil nil nil 'idlwave-class-history))))))
76959b77
S
5924
5925 ;; Store it, if requested
f32b3b91
CD
5926 (when (and class (not (eq t class)))
5927 ;; We have a real class here
5928 (when (and store arrow)
76959b77 5929 (condition-case ()
31b58798
JB
5930 (add-text-properties
5931 apos (+ apos 2)
5932 `(idlwave-class ,class face ,idlwave-class-arrow-face
76959b77
S
5933 rear-nonsticky t))
5934 (error nil)))
f32b3b91
CD
5935 (setf (nth 2 info) class))
5936 ;; Return the class
5937 class)
5938 ;; Default as fallback
5939 (t class))))
5940
5941(defvar type-selector)
5942(defvar class-selector)
5943(defvar method-selector)
05a1abfc 5944(defvar super-classes)
f32b3b91
CD
5945(defun idlwave-selector (a)
5946 (and (eq (nth 1 a) type-selector)
5947 (or (and (nth 2 a) (eq class-selector t))
05a1abfc 5948 (eq (nth 2 a) class-selector)
52a244eb
S
5949 (memq (nth 2 a) super-classes))))
5950
5951(defun idlwave-add-file-link-selector (a)
5952 ;; Record a file link, if any, for the tested names during selection.
5953 (let ((sel (idlwave-selector a)) file)
5954 (if (and sel (setq file (idlwave-entry-has-help a)))
5955 (push (cons (car a) file) idlwave-completion-help-links))
5956 sel))
5957
f32b3b91
CD
5958
5959(defun idlwave-where ()
31b58798 5960 "Find out where we are.
f32b3b91 5961The return value is a list with the following stuff:
5e72c6b2 5962\(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
f32b3b91
CD
5963
5964PRO-LIST (PRO POINT CLASS ARROW)
5965FUNC-LIST (FUNC POINT CLASS ARROW)
5966COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
31b58798 5967CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5e72c6b2 5968 be completed here.
f32b3b91
CD
5969LAST-CHAR last relevant character before point (non-white non-comment,
5970 not part of current identifier or leading slash).
5971
5972In the lists, we have these meanings:
5973PRO: Procedure name
5974FUNC: Function name
5975POINT: Where is this
5976CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5e72c6b2 5977ARROW: Location of the arrow"
f32b3b91 5978 (idlwave-routines)
31b58798 5979 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
15e42531 5980 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
f32b3b91
CD
5981 (func-entry (idlwave-what-function bos))
5982 (func (car func-entry))
5983 (func-class (nth 1 func-entry))
5984 (func-arrow (nth 2 func-entry))
5985 (func-point (or (nth 3 func-entry) 0))
5986 (func-level (or (nth 4 func-entry) 0))
5987 (pro-entry (idlwave-what-procedure bos))
5988 (pro (car pro-entry))
5989 (pro-class (nth 1 pro-entry))
5990 (pro-arrow (nth 2 pro-entry))
5991 (pro-point (or (nth 3 pro-entry) 0))
5992 (last-char (idlwave-last-valid-char))
5993 (case-fold-search t)
52a244eb 5994 (match-string (buffer-substring bos (point)))
f32b3b91
CD
5995 cw cw-mod cw-arrow cw-class cw-point)
5996 (if (< func-point pro-point) (setq func nil))
5997 (cond
15e42531 5998 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
52a244eb 5999 match-string)
15e42531 6000 (setq cw 'class))
31b58798
JB
6001 ((string-match
6002 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
52a244eb
S
6003 (if (> pro-point 0)
6004 (buffer-substring pro-point (point))
6005 match-string))
f32b3b91
CD
6006 (setq cw 'procedure cw-class pro-class cw-point pro-point
6007 cw-arrow pro-arrow))
6008 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
52a244eb 6009 match-string)
f32b3b91 6010 nil)
05a1abfc 6011 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
52a244eb 6012 match-string)
31b58798 6013 (setq cw 'class))
05a1abfc 6014 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
52a244eb 6015 match-string)
31b58798
JB
6016 (setq cw 'class))
6017 ((and func
f32b3b91
CD
6018 (> func-point pro-point)
6019 (= func-level 1)
6020 (memq last-char '(?\( ?,)))
6021 (setq cw 'function-keyword cw-mod func cw-point func-point
6022 cw-class func-class cw-arrow func-arrow))
6023 ((and pro (eq last-char ?,))
6024 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6025 cw-class pro-class cw-arrow pro-arrow))
6026; ((member last-char '(?\' ?\) ?\] ?!))
6027; ;; after these chars, a function makes no sense
6028; ;; FIXME: I am sure there can be more in this list
6029; ;; FIXME: Do we want to do this at all?
6030; nil)
6031 ;; Everywhere else we try a function.
6032 (t
6033 (setq cw 'function)
6034 (save-excursion
52a244eb 6035 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
76959b77 6036 (setq cw-arrow (copy-marker (match-beginning 0))
52a244eb
S
6037 cw-class (if (match-end 4)
6038 (idlwave-sintern-class (match-string 4))
5e72c6b2 6039 t))))))
f32b3b91
CD
6040 (list (list pro pro-point pro-class pro-arrow)
6041 (list func func-point func-class func-arrow)
6042 cw
6043 (list cw-mod cw-point cw-class cw-arrow)
6044 last-char)))
6045
6046(defun idlwave-this-word (&optional class)
6047 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
52a244eb 6048 (setq class (or class "a-zA-Z0-9$_."))
f32b3b91 6049 (save-excursion
52a244eb 6050 (buffer-substring
f32b3b91
CD
6051 (progn (skip-chars-backward class) (point))
6052 (progn (skip-chars-forward class) (point)))))
6053
f32b3b91
CD
6054(defun idlwave-what-function (&optional bound)
6055 ;; Find out if point is within the argument list of a function.
76959b77
S
6056 ;; The return value is ("function-name" class arrow-start (point) level).
6057 ;; Level is 1 on the top level parentheses, higher further down.
f32b3b91
CD
6058
6059 ;; If the optional BOUND is an integer, bound backwards directed
6060 ;; searches to this point.
6061
6062 (catch 'exit
31b58798 6063 (let (pos
f32b3b91 6064 func-point
f32b3b91
CD
6065 (cnt 0)
6066 func arrow-start class)
15e42531
CD
6067 (idlwave-with-special-syntax
6068 (save-restriction
6069 (save-excursion
6070 (narrow-to-region (max 1 (or bound 0)) (point-max))
6071 ;; move back out of the current parenthesis
6072 (while (condition-case nil
6073 (progn (up-list -1) t)
6074 (error nil))
6075 (setq pos (point))
6076 (incf cnt)
6077 (when (and (= (following-char) ?\()
31b58798 6078 (re-search-backward
15e42531
CD
6079 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6080 bound t))
6081 (setq func (match-string 2)
6082 func-point (goto-char (match-beginning 2))
6083 pos func-point)
31b58798 6084 (if (re-search-backward
15e42531 6085 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
76959b77 6086 (setq arrow-start (copy-marker (match-beginning 0))
15e42531 6087 class (or (match-string 2) t)))
31b58798
JB
6088 (throw
6089 'exit
15e42531
CD
6090 (list
6091 (idlwave-sintern-routine-or-method func class)
6092 (idlwave-sintern-class class)
6093 arrow-start func-point cnt)))
6094 (goto-char pos))
6095 (throw 'exit nil)))))))
f32b3b91
CD
6096
6097(defun idlwave-what-procedure (&optional bound)
6098 ;; Find out if point is within the argument list of a procedure.
6099 ;; The return value is ("procedure-name" class arrow-pos (point)).
6100
6101 ;; If the optional BOUND is an integer, bound backwards directed
6102 ;; searches to this point.
6103 (let ((pos (point)) pro-point
6104 pro class arrow-start string)
31b58798 6105 (save-excursion
05a1abfc 6106 ;;(idlwave-beginning-of-statement)
15e42531 6107 (idlwave-start-of-substatement 'pre)
f32b3b91 6108 (setq string (buffer-substring (point) pos))
31b58798 6109 (if (string-match
76959b77
S
6110 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6111 (setq pro (match-string 1 string)
6112 pro-point (+ (point) (match-beginning 1)))
f32b3b91
CD
6113 (if (and (idlwave-skip-object)
6114 (setq string (buffer-substring (point) pos))
31b58798
JB
6115 (string-match
6116 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
52a244eb 6117 string))
f32b3b91
CD
6118 (setq pro (if (match-beginning 4)
6119 (match-string 4 string))
6120 pro-point (if (match-beginning 4)
6121 (+ (point) (match-beginning 4))
6122 pos)
76959b77 6123 arrow-start (copy-marker (+ (point) (match-beginning 1)))
f32b3b91
CD
6124 class (or (match-string 3 string) t)))))
6125 (list (idlwave-sintern-routine-or-method pro class)
6126 (idlwave-sintern-class class)
6127 arrow-start
6128 pro-point)))
6129
6130(defun idlwave-skip-object ()
6131 ;; If there is an object at point, move over it and return t.
6132 (let ((pos (point)))
6133 (if (catch 'exit
6134 (save-excursion
6135 (skip-chars-forward " ") ; white space
6136 (skip-chars-forward "*") ; de-reference
6137 (cond
6138 ((looking-at idlwave-identifier)
6139 (goto-char (match-end 0)))
6140 ((eq (following-char) ?\()
6141 nil)
6142 (t (throw 'exit nil)))
6143 (catch 'endwhile
6144 (while t
6145 (cond ((eq (following-char) ?.)
6146 (forward-char 1)
6147 (if (not (looking-at idlwave-identifier))
6148 (throw 'exit nil))
6149 (goto-char (match-end 0)))
6150 ((memq (following-char) '(?\( ?\[))
6151 (condition-case nil
6152 (forward-list 1)
6153 (error (throw 'exit nil))))
6154 (t (throw 'endwhile t)))))
6155 (if (looking-at "[ \t]*->")
6156 (throw 'exit (setq pos (match-beginning 0)))
6157 (throw 'exit nil))))
6158 (goto-char pos)
6159 nil)))
31b58798 6160
f32b3b91
CD
6161(defun idlwave-last-valid-char ()
6162 "Return the last character before point which is not white or a comment
6163and also not part of the current identifier. Since we do this in
6164order to identify places where keywords are, we consider the initial
6165`/' of a keyword as part of the identifier.
6166This function is not general, can only be used for completion stuff."
6167 (catch 'exit
6168 (save-excursion
6169 ;; skip the current identifier
6170 (skip-chars-backward "a-zA-Z0-9_$")
6171 ;; also skip a leading slash which might be belong to the keyword
6172 (if (eq (preceding-char) ?/)
6173 (backward-char 1))
6174 ;; FIXME: does not check if this is a valid identifier
6175 (while t
6176 (skip-chars-backward " \t")
6177 (cond
6178 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6179 ((eq (preceding-char) ?\n)
6180 (beginning-of-line 0)
3938cb82 6181 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
f32b3b91
CD
6182 ;; continuation line
6183 (goto-char (match-end 1))
6184 (throw 'exit nil)))
6185 (t (throw 'exit (preceding-char))))))))
6186
6187(defvar idlwave-complete-after-success-form nil
6188 "A form to evaluate after successful completion.")
6189(defvar idlwave-complete-after-success-form-force nil
6190 "A form to evaluate after completion selection in *Completions* buffer.")
6191(defconst idlwave-completion-mark (make-marker)
6192 "A mark pointing to the beginning of the completion string.")
6193
6194(defun idlwave-complete-in-buffer (type stype list selector prompt isa
52a244eb
S
6195 &optional prepare-display-function
6196 special-selector)
f32b3b91 6197 "Perform TYPE completion of word before point against LIST.
76959b77 6198SELECTOR is the PREDICATE argument for the completion function. Show
52a244eb
S
6199PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6200'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6201used only once, for `all-completions', and can be used to, e.g.,
6202accumulate information on matching completions."
f32b3b91
CD
6203 (let* ((completion-ignore-case t)
6204 beg (end (point)) slash part spart completion all-completions
6205 dpart dcompletion)
6206
6207 (unless list
6208 (error (concat prompt ": No completions available")))
6209
6210 ;; What is already in the buffer?
6211 (save-excursion
6212 (skip-chars-backward "a-zA-Z0-9_$")
6213 (setq slash (eq (preceding-char) ?/)
6214 beg (point)
6215 idlwave-complete-after-success-form
6216 (list 'idlwave-after-successful-completion
6217 (list 'quote type) slash beg)
6218 idlwave-complete-after-success-form-force
6219 (list 'idlwave-after-successful-completion
6220 (list 'quote type) slash (list 'quote 'force))))
6221
6222 ;; Try a completion
6223 (setq part (buffer-substring beg end)
6224 dpart (downcase part)
6225 spart (idlwave-sintern stype part)
6226 completion (try-completion part list selector)
52a244eb
S
6227 dcompletion (if (stringp completion) (downcase completion))
6228 idlwave-completion-help-links nil)
f32b3b91
CD
6229 (cond
6230 ((null completion)
6231 ;; nothing available.
76959b77 6232 (error (concat prompt ": no completion for \"%s\"") part))
f32b3b91
CD
6233 ((and (not (equal dpart dcompletion))
6234 (not (eq t completion)))
6235 ;; We can add something
6236 (delete-region beg end)
6237 (if (and (string= part dpart)
6238 (or (not (string= part ""))
6239 idlwave-complete-empty-string-as-lower-case)
6240 (not idlwave-completion-force-default-case))
6241 (insert dcompletion)
6242 (insert completion))
6243 (if (eq t (try-completion completion list selector))
6244 ;; Now this is a unique match
6245 (idlwave-after-successful-completion type slash beg))
6246 t)
6247 ((or (eq completion t)
52a244eb 6248 (and (= 1 (length (setq all-completions
f32b3b91 6249 (idlwave-uniquify
31b58798
JB
6250 (all-completions part list
6251 (or special-selector
52a244eb
S
6252 selector))))))
6253 (equal dpart dcompletion)))
f32b3b91
CD
6254 ;; This is already complete
6255 (idlwave-after-successful-completion type slash beg)
6256 (message "%s is already the complete %s" part isa)
6257 nil)
31b58798 6258 (t
f32b3b91
CD
6259 ;; We cannot add something - offer a list.
6260 (message "Making completion list...")
31b58798 6261
52a244eb
S
6262 (unless idlwave-completion-help-links ; already set somewhere?
6263 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6264 (let ((link (get-text-property 0 'link (car x))))
6265 (if link
31b58798 6266 (push (cons (car x) link)
52a244eb
S
6267 idlwave-completion-help-links))))
6268 list))
f32b3b91 6269 (let* ((list all-completions)
05a1abfc 6270 ;; "complete" means, this is already a valid completion
f32b3b91 6271 (complete (memq spart all-completions))
52a244eb
S
6272 (completion-highlight-first-word-only t)) ; XEmacs
6273; (completion-fixup-function ; Emacs
6274; (lambda () (and (eq (preceding-char) ?>)
6275; (re-search-backward " <" beg t)))))
31b58798 6276
f32b3b91
CD
6277 (setq list (sort list (lambda (a b)
6278 (string< (downcase a) (downcase b)))))
6279 (if prepare-display-function
6280 (setq list (funcall prepare-display-function list)))
6281 (if (and (string= part dpart)
6282 (or (not (string= part ""))
6283 idlwave-complete-empty-string-as-lower-case)
6284 (not idlwave-completion-force-default-case))
6285 (setq list (mapcar (lambda (x)
31b58798 6286 (if (listp x)
f32b3b91
CD
6287 (setcar x (downcase (car x)))
6288 (setq x (downcase x)))
6289 x)
6290 list)))
6291 (idlwave-display-completion-list list prompt beg complete))
6292 t))))
6293
6294(defun idlwave-complete-class ()
6295 "Complete a class at point."
6296 (interactive)
6297 ;; Call `idlwave-routines' to make sure the class list will be available
6298 (idlwave-routines)
15e42531
CD
6299 ;; Check for the special case of completing empty string after pro/function
6300 (if (let ((case-fold-search t))
6301 (save-excursion
6302 (and
6303 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6304 (- (point) 15) t)
6305 (goto-char (point-min))
31b58798 6306 (re-search-forward
15e42531
CD
6307 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6308 ;; Yank the full class specification
6309 (insert (match-string 2))
52a244eb 6310 ;; Do the completion, using list gathered from `idlwave-routines'
31b58798
JB
6311 (idlwave-complete-in-buffer
6312 'class 'class (idlwave-class-alist) nil
52a244eb
S
6313 "Select a class" "class"
6314 '(lambda (list) ;; Push it to help-links if system help available
6315 (mapcar (lambda (x)
6316 (let* ((entry (idlwave-class-info x))
6317 (link (nth 1 (assq 'link entry))))
31b58798 6318 (if link (push (cons x link)
52a244eb
S
6319 idlwave-completion-help-links))
6320 x))
6321 list)))))
f32b3b91 6322
76959b77 6323(defun idlwave-attach-classes (list type show-classes)
05a1abfc 6324 ;; Attach the proper class list to a LIST of completion items.
76959b77
S
6325 ;; TYPE, when 'kwd, shows classes for method keywords, when
6326 ;; 'class-tag, for class tags, and otherwise for methods.
f32b3b91 6327 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
76959b77
S
6328 (if (or (null show-classes) ; don't want to see classes
6329 (null class-selector) ; not a method call
31b58798 6330 (and
76959b77
S
6331 (stringp class-selector) ; the class is already known
6332 (not super-classes))) ; no possibilities for inheritance
6333 ;; In these cases, we do not have to do anything
6334 list
05a1abfc
CD
6335 (let* ((do-prop (and (>= show-classes 0)
6336 (>= emacs-major-version 21)))
f32b3b91 6337 (do-buf (not (= show-classes 0)))
76959b77 6338 ;; (do-dots (featurep 'xemacs))
05a1abfc 6339 (do-dots t)
76959b77 6340 (inherit (if (and (not (eq type 'class-tag)) super-classes)
05a1abfc 6341 (cons class-selector super-classes)))
f32b3b91
CD
6342 (max (abs show-classes))
6343 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6344 classes nclasses class-info space)
31b58798 6345 (mapcar
f32b3b91
CD
6346 (lambda (x)
6347 ;; get the classes
76959b77
S
6348 (if (eq type 'class-tag)
6349 ;; Just one class for tags
6350 (setq classes
31b58798 6351 (list
76959b77 6352 (idlwave-class-or-superclass-with-tag class-selector x)))
52a244eb 6353 ;; Multiple classes for method or method-keyword
76959b77
S
6354 (setq classes
6355 (if (eq type 'kwd)
6356 (idlwave-all-method-keyword-classes
6357 method-selector x type-selector)
6358 (idlwave-all-method-classes x type-selector)))
6359 (if inherit
31b58798 6360 (setq classes
76959b77
S
6361 (delq nil
6362 (mapcar (lambda (x) (if (memq x inherit) x nil))
6363 classes)))))
f32b3b91
CD
6364 (setq nclasses (length classes))
6365 ;; Make the separator between item and class-info
6366 (if do-dots
6367 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6368 (setq space " "))
6369 (if do-buf
6370 ;; We do want info in the buffer
6371 (if (<= nclasses max)
6372 (setq class-info (concat
6373 space
6374 "<" (mapconcat 'identity classes ",") ">"))
6375 (setq class-info (format "%s<%d classes>" space nclasses)))
6376 (setq class-info nil))
6377 (when do-prop
6378 ;; We do want properties
6379 (setq x (copy-sequence x))
6380 (put-text-property 0 (length x)
52a244eb
S
6381 'help-echo (mapconcat 'identity classes " ")
6382 x))
f32b3b91
CD
6383 (if class-info
6384 (list x class-info)
6385 x))
6386 list))))
6387
6388(defun idlwave-attach-method-classes (list)
6389 ;; Call idlwave-attach-classes with method parameters
76959b77 6390 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
f32b3b91
CD
6391(defun idlwave-attach-keyword-classes (list)
6392 ;; Call idlwave-attach-classes with keyword parameters
76959b77
S
6393 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6394(defun idlwave-attach-class-tag-classes (list)
6395 ;; Call idlwave-attach-classes with class structure tags
6396 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
31b58798 6397
f32b3b91
CD
6398
6399;;----------------------------------------------------------------------
6400;;----------------------------------------------------------------------
6401;;----------------------------------------------------------------------
6402;;----------------------------------------------------------------------
6403;;----------------------------------------------------------------------
5e72c6b2
S
6404(defvar rtn)
6405(defun idlwave-pset (item)
6406 (set 'rtn item))
6407
6408(defun idlwave-popup-select (ev list title &optional sort)
6409 "Select an item in LIST with a popup menu.
6410TITLE is the title to put atop the popup. If SORT is non-nil,
6411sort the list before displaying"
6412 (let ((maxpopup idlwave-max-popup-menu-items)
6413 rtn menu resp)
6414 (cond ((null list))
6415 ((= 1 (length list))
6416 (setq rtn (car list)))
6417 ((featurep 'xemacs)
31b58798 6418 (if sort (setq list (sort list (lambda (a b)
5e72c6b2
S
6419 (string< (upcase a) (upcase b))))))
6420 (setq menu
6421 (append (list title)
6422 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6423 x)))
6424 list)))
6425 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6426 (setq resp (get-popup-menu-response menu))
6427 (funcall (event-function resp) (event-object resp)))
6428 (t
31b58798 6429 (if sort (setq list (sort list (lambda (a b)
5e72c6b2
S
6430 (string< (upcase a) (upcase b))))))
6431 (setq menu (cons title
6432 (list
6433 (append (list "")
6434 (mapcar (lambda(x) (cons x x)) list)))))
6435 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6436 (setq rtn (x-popup-menu ev menu))))
6437 rtn))
6438
6439(defun idlwave-split-menu-xemacs (menu N)
6440 "Split the MENU into submenus of maximum length N."
6441 (if (<= (length menu) (1+ N))
6442 ;; No splitting needed
6443 menu
6444 (let* ((title (car menu))
6445 (entries (cdr menu))
6446 (menu (list title))
6447 (cnt 0)
6448 (nextmenu nil))
6449 (while entries
6450 (while (and entries (< cnt N))
6451 (setq cnt (1+ cnt)
6452 nextmenu (cons (car entries) nextmenu)
6453 entries (cdr entries)))
6454 (setq nextmenu (nreverse nextmenu))
6455 (setq nextmenu (cons (format "%s...%s"
6456 (aref (car nextmenu) 0)
6457 (aref (nth (1- cnt) nextmenu) 0))
6458 nextmenu))
6459 (setq menu (cons nextmenu menu)
6460 nextmenu nil
6461 cnt 0))
6462 (nreverse menu))))
6463
6464(defun idlwave-split-menu-emacs (menu N)
6465 "Split the MENU into submenus of maximum length N."
6466 (if (<= (length (nth 1 menu)) (1+ N))
6467 ;; No splitting needed
6468 menu
6469 (let* ((title (car menu))
6470 (entries (cdr (nth 1 menu)))
6471 (menu nil)
6472 (cnt 0)
6473 (nextmenu nil))
6474 (while entries
6475 (while (and entries (< cnt N))
6476 (setq cnt (1+ cnt)
6477 nextmenu (cons (car entries) nextmenu)
6478 entries (cdr entries)))
6479 (setq nextmenu (nreverse nextmenu))
6480 (prin1 nextmenu)
6481 (setq nextmenu (cons (format "%s...%s"
6482 (car (car nextmenu))
6483 (car (nth (1- cnt) nextmenu)))
6484 nextmenu))
6485 (setq menu (cons nextmenu menu)
6486 nextmenu nil
6487 cnt 0))
6488 (setq menu (nreverse menu))
6489 (setq menu (cons title menu))
6490 menu)))
f32b3b91 6491
15e42531
CD
6492(defvar idlwave-completion-setup-hook nil)
6493
f32b3b91
CD
6494(defun idlwave-scroll-completions (&optional message)
6495 "Scroll the completion window on this frame."
6496 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6497 (win (selected-window)))
6498 (unwind-protect
6499 (progn
6500 (select-window cwin)
6501 (condition-case nil
6502 (scroll-up)
6503 (error (if (and (listp last-command)
6504 (nth 2 last-command))
6505 (progn
6506 (select-window win)
6507 (eval idlwave-complete-after-success-form))
6508 (set-window-start cwin (point-min)))))
6509 (and message (message message)))
6510 (select-window win))))
6511
6512(defun idlwave-display-completion-list (list &optional message beg complete)
6513 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6514 (unless (and (get-buffer-window "*Completions*")
6515 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6516 (move-marker idlwave-completion-mark beg)
6517 (setq idlwave-before-completion-wconf (current-window-configuration)))
6518
6519 (if (featurep 'xemacs)
31b58798 6520 (idlwave-display-completion-list-xemacs
15e42531 6521 list)
f32b3b91
CD
6522 (idlwave-display-completion-list-emacs list))
6523
6524 ;; Store a special value in `this-command'. When `idlwave-complete'
6525 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6526 (setq this-command (list 'idlwave-display-completion-list message complete))
6527
6528 ;; Mark the completions buffer as created by cib
6529 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6530
6531 ;; Fontify the classes
6532 (if (and idlwave-completion-fontify-classes
6533 (consp (car list)))
6534 (idlwave-completion-fontify-classes))
6535
15e42531
CD
6536 ;; Run the hook
6537 (run-hooks 'idlwave-completion-setup-hook)
6538
f32b3b91
CD
6539 ;; Display the message
6540 (message (or message "Making completion list...done")))
6541
6542(defun idlwave-choose (function &rest args)
6543 "Call FUNCTION as a completion chooser and pass ARGS to it."
6544 (let ((completion-ignore-case t)) ; install correct value
6545 (apply function args))
15e42531
CD
6546 (if (and (eq major-mode 'idlwave-shell-mode)
6547 (boundp 'font-lock-mode)
6548 (not font-lock-mode))
52a244eb 6549 ;; For the shell, remove the fontification of the word before point
15e42531
CD
6550 (let ((beg (save-excursion
6551 (skip-chars-backward "a-zA-Z0-9_")
6552 (point))))
6553 (remove-text-properties beg (point) '(face nil))))
f32b3b91
CD
6554 (eval idlwave-complete-after-success-form-force))
6555
76959b77
S
6556(defun idlwave-keyboard-quit ()
6557 (interactive)
6558 (unwind-protect
6559 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
6560 (idlwave-restore-wconf-after-completion))
6561 (keyboard-quit)))
6562
f32b3b91
CD
6563(defun idlwave-restore-wconf-after-completion ()
6564 "Restore the old (before completion) window configuration."
6565 (and idlwave-completion-restore-window-configuration
6566 idlwave-before-completion-wconf
6567 (set-window-configuration idlwave-before-completion-wconf)))
6568
52a244eb
S
6569(defun idlwave-one-key-select (sym prompt delay)
6570 "Make the user select an element from the alist in the variable SYM.
6571The keys of the alist are expected to be strings. The function returns the
6572car of the selected association.
6573To do this, PROMPT is displayed and and the user must hit a letter key to
6574select an entry. If the user does not reply within DELAY seconds, a help
6575window with the options is displayed automatically.
6576The key which is associated with each option is generated automatically.
6577First, the strings are checked for preselected keys, like in \"[P]rint\".
6578If these don't exist, a letter in the string is automatically selected."
6579 (let* ((alist (symbol-value sym))
6580 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
6581 '(fit-window-to-buffer)))
6582 keys-alist char)
6583 ;; First check the cache
6584 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
6585 (setq keys-alist (get sym :one-key-alist-cache))
6586 ;; Need to make new list
6587 (setq keys-alist (idlwave-make-one-key-alist alist))
6588 (put sym :one-key-alist-cache keys-alist)
6589 (put sym :one-key-alist-last alist))
6590 ;; Display prompt and wait for quick reply
6591 (message "%s[%s]" prompt
6592 (mapconcat (lambda(x) (char-to-string (car x)))
6593 keys-alist ""))
6594 (if (sit-for delay)
6595 ;; No quick reply: Show help
6596 (save-window-excursion
6597 (with-output-to-temp-buffer "*Completions*"
6598 (mapcar (lambda(x)
6599 (princ (nth 1 x))
6600 (princ "\n"))
31b58798 6601 keys-alist))
52a244eb
S
6602 (setq char (read-char)))
6603 (setq char (read-char)))
6604 (message nil)
6605 ;; Return the selected result
6606 (nth 2 (assoc char keys-alist))))
6607
6608;; Used for, e.g., electric debug super-examine.
6609(defun idlwave-make-one-key-alist (alist)
6610 "Make an alist for single key selection."
6611 (let ((l alist) keys-alist name start char help
6612 (cnt 0)
6613 (case-fold-search nil))
6614 (while l
6615 (setq name (car (car l))
6616 l (cdr l))
6617 (catch 'exit
6618 ;; First check if the configuration predetermined a key
6619 (if (string-match "\\[\\(.\\)\\]" name)
6620 (progn
6621 (setq char (string-to-char (downcase (match-string 1 name)))
6622 help (format "%c: %s" char name)
6623 keys-alist (cons (list char help name) keys-alist))
6624 (throw 'exit t)))
6625 ;; Then check for capital letters
6626 (setq start 0)
6627 (while (string-match "[A-Z]" name start)
6628 (setq start (match-end 0)
6629 char (string-to-char (downcase (match-string 0 name))))
6630 (if (not (assoc char keys-alist))
6631 (progn
6632 (setq help (format "%c: %s" char
6633 (replace-match
6634 (concat "[" (match-string 0 name) "]")
6635 t t name))
6636 keys-alist (cons (list char help name) keys-alist))
6637 (throw 'exit t))))
6638 ;; Now check for lowercase letters
6639 (setq start 0)
6640 (while (string-match "[a-z]" name start)
6641 (setq start (match-end 0)
6642 char (string-to-char (match-string 0 name)))
6643 (if (not (assoc char keys-alist))
6644 (progn
6645 (setq help (format "%c: %s" char
6646 (replace-match
6647 (concat "[" (match-string 0 name) "]")
6648 t t name))
6649 keys-alist (cons (list char help name) keys-alist))
6650 (throw 'exit t))))
6651 ;; Bummer, nothing found! Use a stupid number
6652 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
6653 help (format "%c: %s" char name)
6654 keys-alist (cons (list char help name) keys-alist))))
6655 (nreverse keys-alist)))
6656
f32b3b91
CD
6657(defun idlwave-set-local (var value &optional buffer)
6658 "Set the buffer-local value of VAR in BUFFER to VALUE."
6659 (save-excursion
6660 (set-buffer (or buffer (current-buffer)))
6661 (set (make-local-variable var) value)))
6662
6663(defun idlwave-local-value (var &optional buffer)
6664 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6665 (save-excursion
6666 (set-buffer (or buffer (current-buffer)))
6667 (and (local-variable-p var (current-buffer))
6668 (symbol-value var))))
6669
15e42531
CD
6670;; In XEmacs, we can use :activate-callback directly to advice the
6671;; choose functions. We use the private keymap only for the online
6672;; help feature.
f32b3b91 6673
15e42531
CD
6674(defvar idlwave-completion-map nil
6675 "Keymap for completion-list-mode with idlwave-complete.")
6676
6677(defun idlwave-display-completion-list-xemacs (list &rest cl-args)
f32b3b91 6678 (with-output-to-temp-buffer "*Completions*"
15e42531
CD
6679 (apply 'display-completion-list list
6680 ':activate-callback 'idlwave-default-choose-completion
6681 cl-args))
6682 (save-excursion
6683 (set-buffer "*Completions*")
6684 (use-local-map
6685 (or idlwave-completion-map
6686 (setq idlwave-completion-map
6687 (idlwave-make-modified-completion-map-xemacs
6688 (current-local-map)))))))
f32b3b91
CD
6689
6690(defun idlwave-default-choose-completion (&rest args)
6691 "Execute `default-choose-completion' and then restore the win-conf."
6692 (apply 'idlwave-choose 'default-choose-completion args))
6693
15e42531
CD
6694(defun idlwave-make-modified-completion-map-xemacs (old-map)
6695 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6696 (let ((new-map (copy-keymap old-map)))
6697 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
6698 (define-key new-map [button3] (lambda ()
6699 (interactive)
6700 (setq this-command last-command)))
6701 new-map))
f32b3b91 6702
76959b77 6703;; In Emacs we also replace keybindings in the completion
15e42531 6704;; map in order to install our wrappers.
f32b3b91
CD
6705
6706(defun idlwave-display-completion-list-emacs (list)
6707 "Display completion list and install the choose wrappers."
6708 (with-output-to-temp-buffer "*Completions*"
6709 (display-completion-list list))
6710 (save-excursion
6711 (set-buffer "*Completions*")
6712 (use-local-map
6713 (or idlwave-completion-map
6714 (setq idlwave-completion-map
15e42531
CD
6715 (idlwave-make-modified-completion-map-emacs
6716 (current-local-map)))))))
6717
6718(defun idlwave-make-modified-completion-map-emacs (old-map)
f32b3b91
CD
6719 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6720 (let ((new-map (copy-keymap old-map)))
31b58798 6721 (substitute-key-definition
f32b3b91
CD
6722 'choose-completion 'idlwave-choose-completion new-map)
6723 (substitute-key-definition
6724 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
15e42531 6725 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
f32b3b91
CD
6726 new-map))
6727
6728(defun idlwave-choose-completion (&rest args)
6729 "Choose the completion that point is in or next to."
6730 (interactive)
6731 (apply 'idlwave-choose 'choose-completion args))
6732
6733(defun idlwave-mouse-choose-completion (&rest args)
6734 "Click on an alternative in the `*Completions*' buffer to choose it."
6735 (interactive "e")
6736 (apply 'idlwave-choose 'mouse-choose-completion args))
6737
6738;;----------------------------------------------------------------------
6739;;----------------------------------------------------------------------
6740
05a1abfc 6741;;; ------------------------------------------------------------------------
52a244eb 6742;;; Stucture parsing code, and code to manage class info
05a1abfc
CD
6743
6744;;
6745;; - Go again over the documentation how to write a completion
6746;; plugin. It is in self.el, but currently still very bad.
31b58798
JB
6747;; This could be in a separate file in the distribution, or
6748;; in an appendix for the manual.
52a244eb
S
6749
6750(defvar idlwave-struct-skip
6751 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
6752 "Regexp for skipping continued blank or comment-only lines in
6753structures")
6754
6755(defvar idlwave-struct-tag-regexp
6756 (concat "[{,]" ;leading comma/brace
6757 idlwave-struct-skip ; 4 groups
6758 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
6759 "[ \t]*:") ; the final colon
6760 "Regexp for structure tags.")
05a1abfc
CD
6761
6762(defun idlwave-struct-tags ()
6763 "Return a list of all tags in the structure defined at point.
6764Point is expected just before the opening `{' of the struct definition."
6765 (save-excursion
6766 (let* ((borders (idlwave-struct-borders))
6767 (beg (car borders))
6768 (end (cdr borders))
6769 tags)
6770 (goto-char beg)
52a244eb
S
6771 (save-restriction
6772 (narrow-to-region beg end)
6773 (while (re-search-forward idlwave-struct-tag-regexp end t)
6774 ;; Check if we are still on the top level of the structure.
6775 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6776 (= (point) beg))
6777 (push (match-string-no-properties 5) tags))
6778 (goto-char (match-end 0))))
6779 (nreverse tags))))
05a1abfc 6780
76959b77
S
6781(defun idlwave-find-struct-tag (tag)
6782 "Find a given TAG in the structure defined at point."
6783 (let* ((borders (idlwave-struct-borders))
6784 (beg (car borders))
6785 (end (cdr borders))
6786 (case-fold-search t))
31b58798 6787 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
76959b77
S
6788 end t)))
6789
05a1abfc
CD
6790(defun idlwave-struct-inherits ()
6791 "Return a list of all `inherits' names in the struct at point.
6792Point is expected just before the opening `{' of the struct definition."
6793 (save-excursion
6794 (let* ((borders (idlwave-struct-borders))
6795 (beg (car borders))
6796 (end (cdr borders))
6797 (case-fold-search t)
6798 names)
6799 (goto-char beg)
52a244eb
S
6800 (save-restriction
6801 (narrow-to-region beg end)
31b58798 6802 (while (re-search-forward
52a244eb
S
6803 (concat "[{,]" ;leading comma/brace
6804 idlwave-struct-skip ; 4 groups
6805 "inherits" ; The INHERITS tag
6806 idlwave-struct-skip ; 4 more
6807 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
6808 end t)
6809 ;; Check if we are still on the top level of the structure.
6810 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6811 (= (point) beg))
6812 (push (match-string-no-properties 9) names))
6813 (goto-char (match-end 0))))
05a1abfc
CD
6814 (nreverse names))))
6815
5e72c6b2 6816(defun idlwave-in-structure ()
52a244eb 6817 "Return t if point is inside an IDL structure definition."
5e72c6b2
S
6818 (let ((beg (point)))
6819 (save-excursion
6820 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6821 (if (idlwave-find-structure-definition nil nil 'back)
6822 (let ((borders (idlwave-struct-borders)))
6823 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6824 (and (> beg (car borders)) (< beg (cdr borders))))))))))
05a1abfc
CD
6825
6826(defun idlwave-struct-borders ()
6827 "Return the borders of the {...} after point as a cons cell."
6828 (let (beg)
6829 (save-excursion
6830 (skip-chars-forward "^{")
6831 (setq beg (point))
6832 (condition-case nil (forward-list 1)
6833 (error (goto-char beg)))
6834 (cons beg (point)))))
6835
6836(defun idlwave-find-structure-definition (&optional var name bound)
52a244eb
S
6837 "Search forward for a structure definition. If VAR is non-nil,
6838search for a structure assigned to variable VAR. If NAME is non-nil,
6839search for a named structure NAME, if a string, or a generic named
6840structure otherwise. If BOUND is an integer, limit the search. If
6841BOUND is the symbol `all', we search first back and then forward
6842through the entire file. If BOUND is the symbol `back' we search only
6843backward."
76959b77 6844 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
05a1abfc
CD
6845 (case-fold-search t)
6846 (lim (if (integerp bound) bound nil))
6847 (re (concat
6848 (if var
6849 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6850 "\\(\\)")
6851 "=" ws "\\({\\)"
31b58798 6852 (if name
52a244eb 6853 (if (stringp name)
31b58798 6854 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
52a244eb
S
6855 ;; Just a generic name
6856 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
6857 ""))))
5e72c6b2 6858 (if (or (and (or (eq bound 'all) (eq bound 'back))
05a1abfc 6859 (re-search-backward re nil t))
5e72c6b2 6860 (and (not (eq bound 'back)) (re-search-forward re lim t)))
52a244eb
S
6861 (progn
6862 (goto-char (match-beginning 3))
6863 (match-string-no-properties 5)))))
6864
31b58798 6865(defvar idlwave-class-info nil)
52a244eb
S
6866(defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
6867(defvar idlwave-class-reset nil) ; to reset buffer-local classes
05a1abfc 6868
05a1abfc 6869(add-hook 'idlwave-update-rinfo-hook
52a244eb 6870 (lambda () (setq idlwave-class-reset t)))
05a1abfc
CD
6871(add-hook 'idlwave-after-load-rinfo-hook
6872 (lambda () (setq idlwave-class-info nil)))
6873
6874(defun idlwave-class-info (class)
6875 (let (list entry)
52a244eb
S
6876 (if idlwave-class-info
6877 (if idlwave-class-reset
31b58798 6878 (setq
52a244eb
S
6879 idlwave-class-reset nil
6880 idlwave-class-info ; Remove any visited in a buffer
31b58798
JB
6881 (delq nil (mapcar
6882 (lambda (x)
6883 (let ((filebuf
6884 (idlwave-class-file-or-buffer
52a244eb
S
6885 (or (cdr (assq 'found-in x)) (car x)))))
6886 (if (cdr filebuf)
6887 nil
6888 x)))
6889 idlwave-class-info))))
6890 ;; Info is nil, put in the system stuff to start.
05a1abfc
CD
6891 (setq idlwave-class-info idlwave-system-class-info)
6892 (setq list idlwave-class-info)
6893 (while (setq entry (pop list))
6894 (idlwave-sintern-class-info entry)))
6895 (setq class (idlwave-sintern-class class))
52a244eb
S
6896 (or (assq class idlwave-class-info)
6897 (progn (idlwave-scan-class-info class)
6898 (assq class idlwave-class-info)))))
05a1abfc
CD
6899
6900(defun idlwave-sintern-class-info (entry)
6901 "Sintern the class names in a class-info entry."
6902 (let ((taglist (assq 'tags entry))
6903 (inherits (assq 'inherits entry)))
6904 (setcar entry (idlwave-sintern-class (car entry) 'set))
6905 (if inherits
6906 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6907 (cdr inherits))))))
6908
52a244eb
S
6909(defun idlwave-find-class-definition (class &optional all-hook alt-class)
6910 "Find class structure definition(s)
6911If ALL-HOOK is set, find all named structure definitions in a given
6912class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
6913set, look for the name__define pro, and inside of it, for the ALT-CLASS
6914class/struct definition"
6915 (let ((case-fold-search t) end-lim list name)
6916 (when (re-search-forward
6917 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
6918 (if all-hook
6919 (progn
6920 ;; For everything there
6921 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
31b58798 6922 (while (setq name
52a244eb
S
6923 (idlwave-find-structure-definition nil t end-lim))
6924 (funcall all-hook name)))
6925 (idlwave-find-structure-definition nil (or alt-class class))))))
76959b77 6926
52a244eb
S
6927
6928(defun idlwave-class-file-or-buffer (class)
6929 "Find buffer visiting CLASS definition"
05a1abfc 6930 (let* ((pro (concat (downcase class) "__define"))
52a244eb
S
6931 (file (idlwave-routine-source-file
6932 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6933 (idlwave-routines))))))
6934 (cons file (if file (idlwave-get-buffer-visiting file)))))
6935
6936
6937(defun idlwave-scan-class-info (class)
6938 "Scan all class and named structure info in the class__define pro"
6939 (let* ((idlwave-auto-routine-info-updates nil)
6940 (filebuf (idlwave-class-file-or-buffer class))
6941 (file (car filebuf))
6942 (buf (cdr filebuf))
6943 (class (idlwave-sintern-class class)))
6944 (if (or
6945 (not file)
6946 (and ;; neither a regular file nor a visited buffer
6947 (not buf)
6948 (not (file-regular-p file))))
6949 nil ; Cannot find the file/buffer to get any info
05a1abfc 6950 (save-excursion
52a244eb
S
6951 (if buf (set-buffer buf)
6952 ;; Read the file in temporarily
05a1abfc
CD
6953 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6954 (erase-buffer)
6955 (unless (eq major-mode 'idlwave-mode)
6956 (idlwave-mode))
6957 (insert-file-contents file))
6958 (save-excursion
6959 (goto-char 1)
31b58798 6960 (idlwave-find-class-definition class
52a244eb
S
6961 ;; Scan all of the structures found there
6962 (lambda (name)
6963 (let* ((this-class (idlwave-sintern-class name))
31b58798 6964 (entry
52a244eb
S
6965 (list this-class
6966 (cons 'tags (idlwave-struct-tags))
6967 (cons 'inherits (idlwave-struct-inherits)))))
6968 (if (not (eq this-class class))
6969 (setq entry (nconc entry (list (cons 'found-in class)))))
6970 (idlwave-sintern-class-info entry)
6971 (push entry idlwave-class-info)))))))))
6972
6973(defun idlwave-class-found-in (class)
6974 "Return the FOUND-IN property of the class."
6975 (cdr (assq 'found-in (idlwave-class-info class))))
05a1abfc
CD
6976(defun idlwave-class-tags (class)
6977 "Return the native tags in CLASS."
6978 (cdr (assq 'tags (idlwave-class-info class))))
6979(defun idlwave-class-inherits (class)
6980 "Return the direct superclasses of CLASS."
6981 (cdr (assq 'inherits (idlwave-class-info class))))
6982
52a244eb 6983
05a1abfc
CD
6984(defun idlwave-all-class-tags (class)
6985 "Return a list of native and inherited tags in CLASS."
76959b77
S
6986 (condition-case err
6987 (apply 'append (mapcar 'idlwave-class-tags
6988 (cons class (idlwave-all-class-inherits class))))
31b58798 6989 (error
76959b77
S
6990 (idlwave-class-tag-reset)
6991 (error "%s" (error-message-string err)))))
6992
05a1abfc
CD
6993
6994(defun idlwave-all-class-inherits (class)
6995 "Return a list of all superclasses of CLASS (recursively expanded).
5e72c6b2 6996The list is cached in `idlwave-class-info' for faster access."
05a1abfc
CD
6997 (cond
6998 ((not idlwave-support-inheritance) nil)
6999 ((eq class nil) nil)
7000 ((eq class t) nil)
7001 (t
7002 (let ((info (idlwave-class-info class))
7003 entry)
7004 (if (setq entry (assq 'all-inherits info))
7005 (cdr entry)
76959b77
S
7006 ;; Save the depth of inheritance scan to check for circular references
7007 (let ((inherits (mapcar (lambda (x) (cons x 0))
7008 (idlwave-class-inherits class)))
05a1abfc
CD
7009 rtn all-inherits cl)
7010 (while inherits
7011 (setq cl (pop inherits)
76959b77
S
7012 rtn (cons (car cl) rtn)
7013 inherits (append (mapcar (lambda (x)
7014 (cons x (1+ (cdr cl))))
7015 (idlwave-class-inherits (car cl)))
7016 inherits))
7017 (if (> (cdr cl) 999)
7018 (error
7019 "Class scan: inheritance depth exceeded. Circular inheritance?")
7020 ))
05a1abfc
CD
7021 (setq all-inherits (nreverse rtn))
7022 (nconc info (list (cons 'all-inherits all-inherits)))
7023 all-inherits))))))
7024
52a244eb 7025(defun idlwave-entry-keywords (entry &optional record-link)
31b58798 7026 "Return the flat entry keywords alist from routine-info entry.
52a244eb
S
7027If RECORD-LINK is non-nil, the keyword text is copied and a text
7028property indicating the link is added."
7029 (let (kwds)
7030 (mapcar
31b58798 7031 (lambda (key-list)
52a244eb
S
7032 (let ((file (car key-list)))
7033 (mapcar (lambda (key-cons)
7034 (let ((key (car key-cons))
7035 (link (cdr key-cons)))
7036 (when (and record-link file)
7037 (setq key (copy-sequence key))
31b58798 7038 (put-text-property
52a244eb 7039 0 (length key)
31b58798
JB
7040 'link
7041 (concat
7042 file
7043 (if link
52a244eb
S
7044 (concat idlwave-html-link-sep
7045 (number-to-string link))))
7046 key))
7047 (push (list key) kwds)))
7048 (cdr key-list))))
7049 (nthcdr 5 entry))
7050 (nreverse kwds)))
7051
7052(defun idlwave-entry-find-keyword (entry keyword)
7053 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7054 (catch 'exit
7055 (mapc
31b58798 7056 (lambda (key-list)
52a244eb
S
7057 (let ((file (car key-list))
7058 (kwd (assoc keyword (cdr key-list))))
7059 (when kwd
31b58798 7060 (setq kwd (cons (car kwd)
52a244eb 7061 (if (and file (cdr kwd))
31b58798 7062 (concat file
52a244eb
S
7063 idlwave-html-link-sep
7064 (number-to-string (cdr kwd)))
7065 (cdr kwd))))
7066 (throw 'exit kwd))))
7067 (nthcdr 5 entry))))
05a1abfc
CD
7068
7069;;==========================================================================
7070;;
7071;; Completing class structure tags. This is a completion plugin.
7072;; The necessary taglist is constructed dynamically
7073
7074(defvar idlwave-current-tags-class nil)
7075(defvar idlwave-current-class-tags nil)
7076(defvar idlwave-current-native-class-tags nil)
76959b77
S
7077(defvar idlwave-sint-class-tags nil)
7078(idlwave-new-sintern-type 'class-tag)
05a1abfc 7079(add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
76959b77 7080(add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
05a1abfc
CD
7081
7082(defun idlwave-complete-class-structure-tag ()
7083 "Complete a structure tag on a `self' argument in an object method."
7084 (interactive)
7085 (let ((pos (point))
7086 (case-fold-search t))
7087 (if (save-excursion
7088 ;; Check if the context is right
52a244eb 7089 (skip-chars-backward "a-zA-Z0-9._$")
05a1abfc
CD
7090 (and (< (point) (- pos 4))
7091 (looking-at "self\\.")))
76959b77
S
7092 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7093 (super-classes (idlwave-all-class-inherits class-selector)))
05a1abfc 7094 ;; Check if we are in a class routine
76959b77 7095 (unless class-selector
e8af40ee 7096 (error "Not in a method procedure or function"))
05a1abfc 7097 ;; Check if we need to update the "current" class
76959b77
S
7098 (if (not (equal class-selector idlwave-current-tags-class))
7099 (idlwave-prepare-class-tag-completion class-selector))
31b58798 7100 (setq idlwave-completion-help-info
76959b77 7101 (list 'idlwave-complete-class-structure-tag-help
31b58798 7102 (idlwave-sintern-routine
76959b77
S
7103 (concat class-selector "__define"))
7104 nil))
05a1abfc
CD
7105 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7106 (idlwave-complete-in-buffer
31b58798 7107 'class-tag 'class-tag
05a1abfc 7108 idlwave-current-class-tags nil
76959b77
S
7109 (format "Select a tag of class %s" class-selector)
7110 "class tag"
7111 'idlwave-attach-class-tag-classes))
05a1abfc
CD
7112 t) ; return t to skip other completions
7113 nil)))
7114
76959b77 7115(defun idlwave-class-tag-reset ()
05a1abfc
CD
7116 (setq idlwave-current-tags-class nil))
7117
7118(defun idlwave-prepare-class-tag-completion (class)
7119 "Find and parse the necessary class definitions for class structure tags."
76959b77 7120 (setq idlwave-sint-class-tags nil)
05a1abfc
CD
7121 (setq idlwave-current-tags-class class)
7122 (setq idlwave-current-class-tags
7123 (mapcar (lambda (x)
76959b77 7124 (list (idlwave-sintern-class-tag x 'set)))
05a1abfc
CD
7125 (idlwave-all-class-tags class)))
7126 (setq idlwave-current-native-class-tags
7127 (mapcar 'downcase (idlwave-class-tags class))))
7128
7129;===========================================================================
7130;;
7131;; Completing system variables and their structure fields
52a244eb 7132;; This is also a plugin.
05a1abfc
CD
7133
7134(defvar idlwave-sint-sysvars nil)
7135(defvar idlwave-sint-sysvartags nil)
7136(idlwave-new-sintern-type 'sysvar)
7137(idlwave-new-sintern-type 'sysvartag)
7138(add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7139(add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
05a1abfc
CD
7140(add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7141
52a244eb
S
7142(defvar idlwave-executive-commands-alist nil
7143 "Alist of system variables and their help files.")
7144
05a1abfc
CD
7145(defvar idlwave-system-variables-alist nil
7146 "Alist of system variables and the associated structure tags.
7147Gets set in `idlw-rinfo.el'.")
05a1abfc
CD
7148
7149(defun idlwave-complete-sysvar-or-tag ()
7150 "Complete a system variable."
7151 (interactive)
7152 (let ((pos (point))
7153 (case-fold-search t))
7154 (cond ((save-excursion
7155 ;; Check if the context is right for system variable
7156 (skip-chars-backward "[a-zA-Z0-9_$]")
7157 (equal (char-before) ?!))
7158 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
31b58798 7159 (idlwave-complete-in-buffer 'sysvar 'sysvar
05a1abfc
CD
7160 idlwave-system-variables-alist nil
7161 "Select a system variable"
7162 "system variable")
7163 t) ; return t to skip other completions
7164 ((save-excursion
7165 ;; Check if the context is right for sysvar tag
52a244eb 7166 (skip-chars-backward "a-zA-Z0-9_$.")
05a1abfc
CD
7167 (and (equal (char-before) ?!)
7168 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7169 (<= (match-end 0) pos)))
7170 ;; Complete a system variable tag
7171 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7172 (entry (assq var idlwave-system-variables-alist))
52a244eb
S
7173 (tags (cdr (assq 'tags entry))))
7174 (or entry (error "!%s is not a known system variable" var))
05a1abfc
CD
7175 (or tags (error "System variable !%s is not a structure" var))
7176 (setq idlwave-completion-help-info
52a244eb 7177 (list 'idlwave-complete-sysvar-tag-help var))
31b58798 7178 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
05a1abfc
CD
7179 tags nil
7180 "Select a system variable tag"
7181 "system variable tag")
7182 t)) ; return t to skip other completions
7183 (t nil))))
7184
3938cb82 7185(defvar link) ;dynamic
05a1abfc 7186(defun idlwave-complete-sysvar-help (mode word)
52a244eb
S
7187 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7188 (entry (assoc word idlwave-system-variables-alist)))
7189 (cond
7190 ((eq mode 'test)
7191 (and (stringp word) entry (nth 1 (assq 'link entry))))
7192 ((eq mode 'set)
7193 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7194 (t (error "This should not happen")))))
7195
7196(defun idlwave-complete-sysvar-tag-help (mode word)
7197 (let* ((var (nth 1 idlwave-completion-help-info))
7198 (entry (assoc var idlwave-system-variables-alist))
7199 (tags (cdr (assq 'tags entry)))
7200 (main (nth 1 (assq 'link entry)))
7201 target main-base)
7202 (cond
7203 ((eq mode 'test) ; we can at least link the main
7204 (and (stringp word) entry main))
7205 ((eq mode 'set)
31b58798
JB
7206 (if entry
7207 (setq link
52a244eb
S
7208 (if (setq target (cdr (assoc word tags)))
7209 (idlwave-substitute-link-target main target)
7210 main)))) ;; setting dynamic!!!
7211 (t (error "This should not happen")))))
7212
7213(defun idlwave-substitute-link-target (link target)
7214 "Substitute the target anchor for the given link."
7215 (let (main-base)
7216 (setq main-base (if (string-match "#" link)
7217 (substring link 0 (match-beginning 0))
7218 link))
7219 (if target
7220 (concat main-base idlwave-html-link-sep (number-to-string target))
7221 link)))
76959b77
S
7222
7223;; Fake help in the source buffer for class structure tags.
52a244eb 7224;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
31b58798 7225(defvar name)
52a244eb 7226(defvar kwd)
76959b77
S
7227(defvar idlwave-help-do-class-struct-tag nil)
7228(defun idlwave-complete-class-structure-tag-help (mode word)
7229 (cond
7230 ((eq mode 'test) ; nothing gets fontified for class tags
7231 nil)
7232 ((eq mode 'set)
52a244eb 7233 (let (class-with found-in)
31b58798
JB
7234 (when (setq class-with
7235 (idlwave-class-or-superclass-with-tag
76959b77
S
7236 idlwave-current-tags-class
7237 word))
31b58798 7238 (if (assq (idlwave-sintern-class class-with)
76959b77 7239 idlwave-system-class-info)
ff689efd 7240 (error "No help available for system class tags"))
52a244eb
S
7241 (if (setq found-in (idlwave-class-found-in class-with))
7242 (setq name (cons (concat found-in "__define") class-with))
7243 (setq name (concat class-with "__define")))))
76959b77
S
7244 (setq kwd word
7245 idlwave-help-do-class-struct-tag t))
7246 (t (error "This should not happen"))))
7247
7248(defun idlwave-class-or-superclass-with-tag (class tag)
7249 "Find and return the CLASS or one of its superclass with the
7250associated TAG, if any."
31b58798 7251 (let ((sclasses (cons class (cdr (assq 'all-inherits
76959b77
S
7252 (idlwave-class-info class)))))
7253 cl)
7254 (catch 'exit
7255 (while sclasses
7256 (setq cl (pop sclasses))
7257 (let ((tags (idlwave-class-tags cl)))
7258 (while tags
7259 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
31b58798 7260 (throw 'exit cl))
76959b77
S
7261 (setq tags (cdr tags))))))))
7262
05a1abfc
CD
7263
7264(defun idlwave-sysvars-reset ()
7265 (if (and (fboundp 'idlwave-shell-is-running)
52a244eb
S
7266 (idlwave-shell-is-running)
7267 idlwave-idlwave_routine_info-compiled)
05a1abfc
CD
7268 (idlwave-shell-send-command "idlwave_get_sysvars"
7269 'idlwave-process-sysvars 'hide)))
7270
7271(defun idlwave-process-sysvars ()
7272 (idlwave-shell-filter-sysvars)
7273 (setq idlwave-sint-sysvars nil
7274 idlwave-sint-sysvartags nil)
7275 (idlwave-sintern-sysvar-alist))
7276
05a1abfc 7277(defun idlwave-sintern-sysvar-alist ()
52a244eb 7278 (let ((list idlwave-system-variables-alist) entry tags)
05a1abfc
CD
7279 (while (setq entry (pop list))
7280 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
52a244eb
S
7281 (setq tags (assq 'tags entry))
7282 (if tags
31b58798
JB
7283 (setcdr tags
7284 (mapcar (lambda (x)
52a244eb
S
7285 (cons (idlwave-sintern-sysvartag (car x) 'set)
7286 (cdr x)))
7287 (cdr tags)))))))
05a1abfc
CD
7288
7289(defvar idlwave-shell-command-output)
7290(defun idlwave-shell-filter-sysvars ()
52a244eb 7291 "Get any new system variables and tags."
05a1abfc
CD
7292 (let ((text idlwave-shell-command-output)
7293 (start 0)
7294 (old idlwave-system-variables-alist)
52a244eb 7295 var tags type name class link old-entry)
05a1abfc
CD
7296 (setq idlwave-system-variables-alist nil)
7297 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7298 text start)
7299 (setq start (match-end 0)
7300 var (match-string 1 text)
31b58798 7301 tags (if (match-end 3)
52a244eb
S
7302 (idlwave-split-string (match-string 3 text))))
7303 ;; Maintain old links, if present
7304 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7305 (setq link (assq 'link old-entry))
05a1abfc 7306 (setq idlwave-system-variables-alist
31b58798
JB
7307 (cons (list var
7308 (cons
7309 'tags
7310 (mapcar (lambda (x)
7311 (cons x
7312 (cdr (assq
7313 (idlwave-sintern-sysvartag x)
52a244eb
S
7314 (cdr (assq 'tags old-entry))))))
7315 tags)) link)
05a1abfc
CD
7316 idlwave-system-variables-alist)))
7317 ;; Keep the old value if query was not successful
7318 (setq idlwave-system-variables-alist
7319 (or idlwave-system-variables-alist old))))
7320
f32b3b91
CD
7321(defun idlwave-completion-fontify-classes ()
7322 "Goto the *Completions* buffer and fontify the class info."
7323 (when (featurep 'font-lock)
7324 (save-excursion
7325 (set-buffer "*Completions*")
7326 (save-excursion
7327 (goto-char (point-min))
76959b77
S
7328 (let ((buffer-read-only nil))
7329 (while (re-search-forward "\\.*<[^>]+>" nil t)
7330 (put-text-property (match-beginning 0) (match-end 0)
7331 'face 'font-lock-string-face)))))))
f32b3b91
CD
7332
7333(defun idlwave-uniquify (list)
52a244eb 7334 (let ((ht (make-hash-table :size (length list) :test 'equal)))
31b58798 7335 (delq nil
52a244eb 7336 (mapcar (lambda (x)
31b58798 7337 (unless (gethash x ht)
52a244eb
S
7338 (puthash x t ht)
7339 x))
7340 list))))
f32b3b91
CD
7341
7342(defun idlwave-after-successful-completion (type slash &optional verify)
7343 "Add `=' or `(' after successful completion of keyword and function.
7344Restore the pre-completion window configuration if possible."
7345 (cond
7346 ((eq type 'procedure)
7347 nil)
7348 ((eq type 'function)
7349 (cond
7350 ((equal idlwave-function-completion-adds-paren nil) nil)
7351 ((or (equal idlwave-function-completion-adds-paren t)
7352 (equal idlwave-function-completion-adds-paren 1))
7353 (insert "("))
7354 ((equal idlwave-function-completion-adds-paren 2)
7355 (insert "()")
7356 (backward-char 1))
7357 (t nil)))
7358 ((eq type 'keyword)
7359 (if (and idlwave-keyword-completion-adds-equal
7360 (not slash))
7361 (progn (insert "=") t)
7362 nil)))
7363
7364 ;; Restore the pre-completion window configuration if this is safe.
31b58798
JB
7365
7366 (if (or (eq verify 'force) ; force
7367 (and
f32b3b91 7368 (get-buffer-window "*Completions*") ; visible
31b58798 7369 (idlwave-local-value 'idlwave-completion-p
f32b3b91
CD
7370 "*Completions*") ; cib-buffer
7371 (eq (marker-buffer idlwave-completion-mark)
7372 (current-buffer)) ; buffer OK
7373 (equal (marker-position idlwave-completion-mark)
7374 verify))) ; pos OK
7375 (idlwave-restore-wconf-after-completion))
7376 (move-marker idlwave-completion-mark nil)
7377 (setq idlwave-before-completion-wconf nil))
7378
15e42531
CD
7379(defun idlwave-mouse-context-help (ev &optional arg)
7380 "Call `idlwave-context-help' on the clicked location."
7381 (interactive "eP")
7382 (mouse-set-point ev)
7383 (idlwave-context-help arg))
7384
7385(defvar idlwave-last-context-help-pos nil)
7386(defun idlwave-context-help (&optional arg)
7387 "Display IDL Online Help on context.
76959b77
S
7388If point is on a keyword, help for that keyword will be shown. If
7389point is on a routine name or in the argument list of a routine, help
7390for that routine will be displayed. Works for system routines and
7391keywords, it pulls up text help. For other routies and keywords,
7392visits the source file, finding help in the header (if
7393`idlwave-help-source-try-header' is non-nil) or the routine definition
7394itself."
f32b3b91 7395 (interactive "P")
15e42531
CD
7396 (idlwave-do-context-help arg))
7397
7398(defun idlwave-mouse-completion-help (ev)
7399 "Display online help about the completion at point."
7400 (interactive "eP")
52a244eb
S
7401 ;; Restore last-command for next command, to make
7402 ;; scrolling/cancelling of completions work.
15e42531
CD
7403 (setq this-command last-command)
7404 (idlwave-do-mouse-completion-help ev))
15e42531 7405
f32b3b91 7406(defun idlwave-routine-info (&optional arg external)
52a244eb
S
7407 "Display a routines calling sequence and list of keywords. When
7408point is on the name a function or procedure, or in the argument list
7409of a function or procedure, this command displays a help buffer with
7410the information. When called with prefix arg, enforce class query.
f32b3b91
CD
7411
7412When point is on an object operator `->', display the class stored in
7413this arrow, if any (see `idlwave-store-inquired-class'). With a
7414prefix arg, the class property is cleared out."
7415
7416 (interactive "P")
7417 (idlwave-routines)
7418 (if (string-match "->" (buffer-substring
7419 (max (point-min) (1- (point)))
7420 (min (+ 2 (point)) (point-max))))
7421 ;; Cursor is on an arrow
7422 (if (get-text-property (point) 'idlwave-class)
7423 ;; arrow has class property
7424 (if arg
7425 ;; Remove property
7426 (save-excursion
7427 (backward-char 1)
7428 (when (looking-at ".?\\(->\\)")
7429 (remove-text-properties (match-beginning 1) (match-end 1)
7430 '(idlwave-class nil face nil))
7431 (message "Class property removed from arrow")))
7432 ;; Echo class property
7433 (message "Arrow has text property identifying object to be class %s"
7434 (get-text-property (point) 'idlwave-class)))
7435 ;; No property found
7436 (message "Arrow has no class text property"))
7437
7438 ;; Not on an arrow...
7439 (let* ((idlwave-query-class nil)
7440 (idlwave-force-class-query (equal arg '(4)))
7441 (module (idlwave-what-module)))
15e42531 7442 (if (car module)
05a1abfc
CD
7443 (apply 'idlwave-display-calling-sequence
7444 (idlwave-fix-module-if-obj_new module))
e8af40ee 7445 (error "Don't know which calling sequence to show")))))
f32b3b91
CD
7446
7447(defun idlwave-resolve (&optional arg)
52a244eb 7448 "Call RESOLVE_ROUTINE on the module name at point.
f32b3b91
CD
7449Like `idlwave-routine-info', this looks for a routine call at point.
7450After confirmation in the minibuffer, it will use the shell to issue
7451a RESOLVE call for this routine, to attempt to make it defined and its
7452routine info available for IDLWAVE. If the routine is a method call,
7453both `class__method' and `class__define' will be tried.
7454With ARG, enforce query for the class of object methods."
7455 (interactive "P")
7456 (let* ((idlwave-query-class nil)
7457 (idlwave-force-class-query (equal arg '(4)))
7458 (module (idlwave-what-module))
7459 (name (idlwave-make-full-name (nth 2 module) (car module)))
7460 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7461 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7462 (kwd "")
7463 class)
7464 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7465 resolve)
7466 (setq type (match-string 1 resolve)
31b58798 7467 class (if (match-beginning 2)
f32b3b91
CD
7468 (match-string 3 resolve)
7469 nil)
7470 name (match-string 4 resolve)))
7471 (if (string= (downcase type) "function")
7472 (setq kwd ",/is_function"))
7473
7474 (cond
7475 ((null class)
31b58798 7476 (idlwave-shell-send-command
f32b3b91
CD
7477 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7478 'idlwave-update-routine-info
7479 nil t))
7480 (t
31b58798 7481 (idlwave-shell-send-command
f32b3b91 7482 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
31b58798
JB
7483 (list 'idlwave-shell-send-command
7484 (format "resolve_routine,'%s__%s'%s"
f32b3b91
CD
7485 (downcase class) (downcase name) kwd)
7486 '(idlwave-update-routine-info)
7487 nil t))))))
7488
3938cb82
S
7489(defun idlwave-find-module-this-file ()
7490 (interactive)
7491 (idlwave-find-module '(4)))
7492
f32b3b91
CD
7493(defun idlwave-find-module (&optional arg)
7494 "Find the source code of an IDL module.
52a244eb
S
7495Works for modules for which IDLWAVE has routine info available. The
7496function offers as default the module name `idlwave-routine-info'
7497would use. With ARG limit to this buffer. With two prefix ARG's
7498force class query for object methods."
f32b3b91
CD
7499 (interactive "P")
7500 (let* ((idlwave-query-class nil)
52a244eb
S
7501 (idlwave-force-class-query (equal arg '(16)))
7502 (this-buffer (equal arg '(4)))
05a1abfc 7503 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
52a244eb 7504 (default (if module
31b58798 7505 (concat (idlwave-make-full-name
52a244eb
S
7506 (nth 2 module) (car module))
7507 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
7508 "none"))
31b58798 7509 (list
52a244eb
S
7510 (idlwave-uniquify
7511 (delq nil
31b58798 7512 (mapcar (lambda (x)
52a244eb
S
7513 (if (eq 'system (car-safe (nth 3 x)))
7514 ;; Take out system routines with no source.
7515 nil
7516 (list
31b58798 7517 (concat (idlwave-make-full-name
52a244eb
S
7518 (nth 2 x) (car x))
7519 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
7520 (if this-buffer
7521 (idlwave-save-buffer-update)
7522 (idlwave-routines))))))
f32b3b91 7523 (name (idlwave-completing-read
52a244eb
S
7524 (if (or (not this-buffer)
7525 (assoc default list))
7526 (format "Module (Default %s): " default)
7527 (format "Module in this file: "))
f32b3b91
CD
7528 list))
7529 type class)
7530 (if (string-match "\\`\\s-*\\'" name)
7531 ;; Nothing, use the default.
7532 (setq name default))
7533 (if (string-match "<[fp]>" name)
7534 (setq type (substring name -2 -1)
7535 name (substring name 0 -3)))
7536 (if (string-match "\\(.*\\)::\\(.*\\)" name)
7537 (setq class (match-string 1 name)
7538 name (match-string 2 name)))
7539 (setq name (idlwave-sintern-routine-or-method name class)
7540 class (idlwave-sintern-class class)
7541 type (cond ((equal type "f") 'fun)
7542 ((equal type "p") 'pro)
7543 (t t)))
52a244eb 7544 (idlwave-do-find-module name type class nil this-buffer)))
f32b3b91 7545
31b58798 7546(defun idlwave-do-find-module (name type class
52a244eb 7547 &optional force-source this-buffer)
f32b3b91 7548 (let ((name1 (idlwave-make-full-name class name))
31b58798 7549 source buf1 entry
f32b3b91 7550 (buf (current-buffer))
05a1abfc 7551 (pos (point))
52a244eb
S
7552 file name2)
7553 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
7554 'WITH-FILE)
05a1abfc
CD
7555 source (or force-source (nth 3 entry))
7556 name2 (if (nth 2 entry)
7557 (idlwave-make-full-name (nth 2 entry) name)
775591f7 7558 name1))
31b58798 7559 (if source
52a244eb
S
7560 (setq file (idlwave-routine-source-file source)))
7561 (unless file ; Try to find it on the path.
31b58798
JB
7562 (setq file
7563 (idlwave-expand-lib-file-name
52a244eb
S
7564 (if class
7565 (format "%s__define.pro" (downcase class))
7566 (format "%s.pro" (downcase name))))))
f32b3b91
CD
7567 (cond
7568 ((or (null name) (equal name ""))
7569 (error "Abort"))
f32b3b91 7570 ((eq (car source) 'system)
31b58798 7571 (error "Source code for system routine %s is not available"
05a1abfc 7572 name2))
52a244eb 7573 ((or (not file) (not (file-regular-p file)))
e8af40ee 7574 (error "Source code for routine %s is not available"
05a1abfc 7575 name2))
52a244eb
S
7576 (t
7577 (when (not this-buffer)
31b58798 7578 (setq buf1
52a244eb
S
7579 (idlwave-find-file-noselect file 'find))
7580 (pop-to-buffer buf1 t))
15e42531 7581 (goto-char (point-max))
f32b3b91 7582 (let ((case-fold-search t))
15e42531 7583 (if (re-search-backward
f32b3b91 7584 (concat "^[ \t]*\\<"
52a244eb
S
7585 (cond ((eq type 'fun) "function")
7586 ((eq type 'pro) "pro")
f32b3b91 7587 (t "\\(pro\\|function\\)"))
31b58798 7588 "\\>[ \t]+"
05a1abfc 7589 (regexp-quote (downcase name2))
f32b3b91
CD
7590 "[^a-zA-Z0-9_$]")
7591 nil t)
7592 (goto-char (match-beginning 0))
7593 (pop-to-buffer buf)
7594 (goto-char pos)
05a1abfc 7595 (error "Could not find routine %s" name2)))))))
f32b3b91
CD
7596
7597(defun idlwave-what-module ()
7598 "Return a default module for stuff near point.
7599Used by `idlwave-routine-info' and `idlwave-find-module'."
7600 (idlwave-routines)
15e42531
CD
7601 (if (let ((case-fold-search t))
7602 (save-excursion
7603 (idlwave-beginning-of-statement)
7604 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
7605 ;; This is a function or procedure definition statement
7606 ;; We return the defined routine as module.
7607 (list
52a244eb
S
7608 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
7609 (match-string-no-properties 2))
15e42531
CD
7610 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
7611 (idlwave-sintern-class (match-string 3)))
7612
52a244eb 7613 ;; Not a definition statement - analyze precise position.
15e42531
CD
7614 (let* ((where (idlwave-where))
7615 (cw (nth 2 where))
7616 (pro (car (nth 0 where)))
7617 (func (car (nth 1 where)))
7618 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
7619 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
7620 (following-char)))
7621 )
7622 (cond
7623 ((and (eq cw 'procedure)
7624 (not (equal this-word "")))
31b58798 7625 (setq this-word (idlwave-sintern-routine-or-method
15e42531
CD
7626 this-word (nth 2 (nth 3 where))))
7627 (list this-word 'pro
31b58798 7628 (idlwave-determine-class
15e42531
CD
7629 (cons this-word (cdr (nth 3 where)))
7630 'pro)))
31b58798 7631 ((and (eq cw 'function)
15e42531
CD
7632 (not (equal this-word ""))
7633 (or (eq next-char ?\() ; exclude arrays, vars.
7634 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
31b58798 7635 (setq this-word (idlwave-sintern-routine-or-method
15e42531
CD
7636 this-word (nth 2 (nth 3 where))))
7637 (list this-word 'fun
7638 (idlwave-determine-class
7639 (cons this-word (cdr (nth 3 where)))
7640 'fun)))
7641 ((and (memq cw '(function-keyword procedure-keyword))
7642 (not (equal this-word ""))
7643 (eq next-char ?\()) ; A function!
7644 (setq this-word (idlwave-sintern-routine this-word))
7645 (list this-word 'fun nil))
7646 (func
7647 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
7648 (pro
7649 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
7650 (t nil)))))
f32b3b91 7651
05a1abfc
CD
7652(defun idlwave-what-module-find-class ()
7653 "Call idlwave-what-module and find the inherited class if necessary."
7654 (let* ((module (idlwave-what-module))
7655 (class (nth 2 module))
7656 classes)
7657 (if (and (= (length module) 3)
7658 (stringp class))
7659 (list (car module)
7660 (nth 1 module)
7661 (apply 'idlwave-find-inherited-class module))
7662 module)))
7663
7664(defun idlwave-find-inherited-class (name type class)
7665 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
7666 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
7667 (if entry
7668 (nth 2 entry)
7669 class)))
7670
7671(defun idlwave-fix-module-if-obj_new (module)
31b58798 7672 "Check if MODULE points to obj_new.
52a244eb
S
7673If yes, and if the cursor is in the keyword region, change to the
7674appropriate Init method."
05a1abfc
CD
7675 (let* ((name (car module))
7676 (pos (point))
7677 (case-fold-search t)
7678 string)
7679 (if (and (stringp name)
7680 (equal (downcase name) "obj_new")
7681 (save-excursion
7682 (idlwave-beginning-of-statement)
7683 (setq string (buffer-substring (point) pos))
7684 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7685 string)))
7686 (let ((name "Init")
7687 (class (match-string 1 string)))
7688 (setq module (list (idlwave-sintern-method "Init")
7689 'fun
7690 (idlwave-sintern-class class)))))
7691 module))
7692
31b58798 7693(defun idlwave-fix-keywords (name type class keywords
3938cb82 7694 &optional super-classes system)
52a244eb
S
7695 "Update a list of keywords.
7696Translate OBJ_NEW, adding all super-class keywords, or all keywords
3938cb82
S
7697from all classes if class equals t. If SYSTEM is non-nil, don't
7698demand _EXTRA in the keyword list."
5e72c6b2 7699 (let ((case-fold-search t))
f32b3b91
CD
7700
7701 ;; If this is the OBJ_NEW function, try to figure out the class and use
7702 ;; the keywords from the corresponding INIT method.
5e72c6b2 7703 (if (and (equal (upcase name) "OBJ_NEW")
05a1abfc
CD
7704 (or (eq major-mode 'idlwave-mode)
7705 (eq major-mode 'idlwave-shell-mode)))
f32b3b91
CD
7706 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7707 (string (buffer-substring bos (point)))
7708 (case-fold-search t)
7709 class)
7710 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7711 string)
7712 (setq class (idlwave-sintern-class (match-string 1 string)))
15e42531 7713 (setq idlwave-current-obj_new-class class)
31b58798
JB
7714 (setq keywords
7715 (append keywords
52a244eb
S
7716 (idlwave-entry-keywords
7717 (idlwave-rinfo-assq
7718 (idlwave-sintern-method "INIT")
7719 'fun
7720 class
7721 (idlwave-routines)) 'do-link))))))
31b58798 7722
f32b3b91
CD
7723 ;; If the class is `t', combine all keywords of all methods NAME
7724 (when (eq class t)
52a244eb
S
7725 (mapc (lambda (entry)
7726 (and
7727 (nth 2 entry) ; non-nil class
7728 (eq (nth 1 entry) type) ; correct type
31b58798
JB
7729 (setq keywords
7730 (append keywords
52a244eb
S
7731 (idlwave-entry-keywords entry 'do-link)))))
7732 (idlwave-all-assq name (idlwave-routines)))
5e72c6b2 7733 (setq keywords (idlwave-uniquify keywords)))
31b58798 7734
5e72c6b2 7735 ;; If we have inheritance, add all keywords from superclasses, if
52a244eb 7736 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
31b58798 7737 (when (and
52a244eb 7738 super-classes
5e72c6b2
S
7739 idlwave-keyword-class-inheritance
7740 (stringp class)
31b58798 7741 (or
3938cb82
S
7742 system
7743 (assq (idlwave-sintern-keyword "_extra") keywords)
7744 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
5e72c6b2
S
7745 ;; Check if one of the keyword-class regexps matches the name
7746 (let ((regexps idlwave-keyword-class-inheritance) re)
7747 (catch 'exit
7748 (while (setq re (pop regexps))
7749 (if (string-match re name) (throw 'exit t))))))
52a244eb
S
7750
7751 (loop for entry in (idlwave-routines) do
7752 (and (nth 2 entry) ; non-nil class
7753 (memq (nth 2 entry) super-classes) ; an inherited class
7754 (eq (nth 1 entry) type) ; correct type
7755 (eq (car entry) name) ; correct name
5e72c6b2 7756 (mapcar (lambda (k) (add-to-list 'keywords k))
52a244eb 7757 (idlwave-entry-keywords entry 'do-link))))
f32b3b91 7758 (setq keywords (idlwave-uniquify keywords)))
31b58798 7759
f32b3b91
CD
7760 ;; Return the final list
7761 keywords))
7762
15e42531 7763(defun idlwave-expand-keyword (keyword module)
2e8b9c7d 7764 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
15e42531
CD
7765KEYWORD may be an exact match or an abbreviation of a keyword.
7766If the match is exact, KEYWORD itself is returned, even if there may be other
7767keywords of which KEYWORD is an abbreviation. This is necessary because some
7768system routines have keywords which are prefixes of other keywords.
7769If KEYWORD is an abbreviation of several keywords, a list of all possible
7770completions is returned.
7771If the abbreviation was unique, the correct keyword is returned.
7772If it cannot be a keyword, the function return nil.
7773If we do not know about MODULE, just return KEYWORD literally."
7774 (let* ((name (car module))
7775 (type (nth 1 module))
7776 (class (nth 2 module))
7777 (kwd (idlwave-sintern-keyword keyword))
7778 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
52a244eb 7779 (kwd-alist (idlwave-entry-keywords entry))
15e42531
CD
7780 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7781 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7782 (completion-ignore-case t)
7783 candidates)
31b58798 7784 (cond ((assq kwd kwd-alist)
15e42531
CD
7785 kwd)
7786 ((setq candidates (all-completions kwd kwd-alist))
7787 (if (= (length candidates) 1)
7788 (car candidates)
7789 candidates))
7790 ((and entry extra)
31b58798 7791 ;; Inheritance may cause this keyword to be correct
15e42531
CD
7792 keyword)
7793 (entry
7794 ;; We do know the function, which does not have the keyword.
7795 nil)
7796 (t
7797 ;; We do not know the function, so this just might be a correct
7798 ;; keyword - return it as it is.
7799 keyword))))
7800
7801(defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
f32b3b91 7802(defvar idlwave-rinfo-map (make-sparse-keymap))
31b58798 7803(define-key idlwave-rinfo-mouse-map
f32b3b91
CD
7804 (if (featurep 'xemacs) [button2] [mouse-2])
7805 'idlwave-mouse-active-rinfo)
31b58798 7806(define-key idlwave-rinfo-mouse-map
15e42531
CD
7807 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7808 'idlwave-mouse-active-rinfo-shift)
31b58798 7809(define-key idlwave-rinfo-mouse-map
f32b3b91
CD
7810 (if (featurep 'xemacs) [button3] [mouse-3])
7811 'idlwave-mouse-active-rinfo-right)
15e42531
CD
7812(define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7813(define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7814(define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7815(defvar idlwave-popup-source nil)
7816(defvar idlwave-rinfo-marker (make-marker))
7817
7818(defun idlwave-quit-help ()
7819 (interactive)
7820 (let ((ri-window (get-buffer-window "*Help*"))
7821 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7822 (when (and olh-window
7823 (fboundp 'idlwave-help-quit))
7824 (select-window olh-window)
7825 (idlwave-help-quit))
7826 (when (window-live-p ri-window)
7827 (delete-window ri-window))))
f32b3b91 7828
05a1abfc
CD
7829(defun idlwave-display-calling-sequence (name type class
7830 &optional initial-class)
f32b3b91 7831 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
05a1abfc
CD
7832 (let* ((initial-class (or initial-class class))
7833 (entry (or (idlwave-best-rinfo-assq name type class
15e42531 7834 (idlwave-routines))
31b58798 7835 (idlwave-rinfo-assq name type class
15e42531 7836 idlwave-unresolved-routines)))
f32b3b91
CD
7837 (name (or (car entry) name))
7838 (class (or (nth 2 entry) class))
05a1abfc 7839 (superclasses (idlwave-all-class-inherits initial-class))
15e42531
CD
7840 (twins (idlwave-routine-twins entry))
7841 (dtwins (idlwave-study-twins twins))
7842 (all dtwins)
52a244eb 7843 (system (eq (car (nth 3 entry)) 'system))
f32b3b91 7844 (calling-seq (nth 4 entry))
52a244eb
S
7845 (keywords (idlwave-entry-keywords entry 'do-link))
7846 (html-file (car (nth 5 entry)))
15e42531 7847 (help-echo-kwd
52a244eb 7848 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
15e42531 7849 (help-echo-use
52a244eb 7850 "Button2/3: Online Help")
15e42531 7851 (help-echo-src
52a244eb 7852 "Button2: Jump to source and back | Button3: Source in Help window.")
05a1abfc
CD
7853 (help-echo-class
7854 "Button2: Display info about same method in superclass")
f32b3b91 7855 (col 0)
52a244eb 7856 (data (list name type class (current-buffer) nil initial-class))
f32b3b91 7857 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
15e42531
CD
7858 (face 'idlwave-help-link-face)
7859 beg props win cnt total)
31b58798 7860 ;; Fix keywords, but don't add chained super-classes, since these
52a244eb 7861 ;; are shown separately for that super-class
f32b3b91
CD
7862 (setq keywords (idlwave-fix-keywords name type class keywords))
7863 (cond
7864 ((null entry)
05a1abfc
CD
7865 (error "No %s %s known %s" type name
7866 (if initial-class (concat "in class " initial-class) "")))
f32b3b91 7867 ((or (null name) (equal name ""))
e8af40ee 7868 (error "No function or procedure call at point"))
f32b3b91 7869 ((null calling-seq)
52a244eb 7870 (error "Calling sequence of %s %s not available" type name))
f32b3b91
CD
7871 (t
7872 (save-excursion
15e42531 7873 (move-marker idlwave-rinfo-marker (point))
f32b3b91 7874 (set-buffer (get-buffer-create "*Help*"))
15e42531 7875 (use-local-map idlwave-rinfo-map)
f32b3b91
CD
7876 (setq buffer-read-only nil)
7877 (erase-buffer)
7878 (set (make-local-variable 'idlwave-popup-source) nil)
15e42531
CD
7879 (set (make-local-variable 'idlwave-current-obj_new-class)
7880 idlwave-current-obj_new-class)
05a1abfc
CD
7881 (when superclasses
7882 (setq props (list 'mouse-face 'highlight
7883 km-prop idlwave-rinfo-mouse-map
7884 'help-echo help-echo-class
7885 'data (cons 'class data)))
7886 (let ((classes (cons initial-class superclasses)) c)
7887 (insert "Classes: ")
7888 (while (setq c (pop classes))
7889 (insert " ")
7890 (setq beg (point))
7891 (insert c)
7892 (if (equal (downcase c) (downcase class))
7893 (add-text-properties beg (point) (list 'face 'bold))
52a244eb 7894 ;; If Method exists in a different class link it
05a1abfc
CD
7895 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7896 (add-text-properties beg (point) props))))
7897 (insert "\n")))
52a244eb
S
7898 (setq props (list 'mouse-face 'highlight
7899 km-prop idlwave-rinfo-mouse-map
7900 'help-echo help-echo-use
7901 'data (cons 'usage data)))
31b58798 7902 (if html-file (setq props (append (list 'face face 'link html-file)
52a244eb 7903 props)))
f32b3b91
CD
7904 (insert "Usage: ")
7905 (setq beg (point))
7906 (insert (if class
52a244eb
S
7907 (format calling-seq class name class name class name)
7908 (format calling-seq name name name name))
f32b3b91
CD
7909 "\n")
7910 (add-text-properties beg (point) props)
31b58798 7911
f32b3b91
CD
7912 (insert "Keywords:")
7913 (if (null keywords)
7914 (insert " No keywords accepted.")
7915 (setq col 9)
7916 (mapcar
7917 (lambda (x)
31b58798 7918 (if (>= (+ col 1 (length (car x)))
f32b3b91
CD
7919 (window-width))
7920 (progn
7921 (insert "\n ")
7922 (setq col 9)))
7923 (insert " ")
7924 (setq beg (point)
52a244eb 7925 ;; Relevant keywords already have link property attached
f32b3b91 7926 props (list 'mouse-face 'highlight
15e42531 7927 km-prop idlwave-rinfo-mouse-map
f32b3b91 7928 'data (cons 'keyword data)
15e42531 7929 'help-echo help-echo-kwd
f32b3b91 7930 'keyword (car x)))
52a244eb 7931 (if system (setq props (append (list 'face face) props)))
f32b3b91
CD
7932 (insert (car x))
7933 (add-text-properties beg (point) props)
7934 (setq col (+ col 1 (length (car x)))))
7935 keywords))
31b58798 7936
15e42531 7937 (setq cnt 1 total (length all))
52a244eb 7938 ;; Here entry is (key file (list of type-conses))
15e42531
CD
7939 (while (setq entry (pop all))
7940 (setq props (list 'mouse-face 'highlight
7941 km-prop idlwave-rinfo-mouse-map
7942 'help-echo help-echo-src
52a244eb
S
7943 'source (list (car (car (nth 2 entry))) ;type
7944 (nth 1 entry)
7945 nil
7946 (cdr (car (nth 2 entry))))
15e42531
CD
7947 'data (cons 'source data)))
7948 (idlwave-insert-source-location
31b58798 7949 (format "\n%-8s %s"
15e42531
CD
7950 (if (equal cnt 1)
7951 (if (> total 1) "Sources:" "Source:")
7952 "")
7953 (if (> total 1) "- " ""))
7954 entry props)
7955 (incf cnt)
7956 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7957 ;; No more source lines, please
31b58798 7958 (insert (format
15e42531
CD
7959 "\n Source information truncated to %d entries."
7960 idlwave-rinfo-max-source-lines))
7961 (setq all nil)))
10c8e594 7962 (goto-char (point-min))
f32b3b91
CD
7963 (setq buffer-read-only t))
7964 (display-buffer "*Help*")
7965 (if (and (setq win (get-buffer-window "*Help*"))
7966 idlwave-resize-routine-help-window)
7967 (progn
7968 (let ((ww (selected-window)))
7969 (unwind-protect
7970 (progn
7971 (select-window win)
31b58798 7972 (enlarge-window (- (/ (frame-height) 2)
f32b3b91
CD
7973 (window-height)))
7974 (shrink-window-if-larger-than-buffer))
7975 (select-window ww)))))))))
7976
15e42531
CD
7977(defun idlwave-insert-source-location (prefix entry &optional file-props)
7978 "Insert a source location into the routine info buffer.
52a244eb
S
7979Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
7980it."
15e42531
CD
7981 (let* ((key (car entry))
7982 (file (nth 1 entry))
7983 (types (nth 2 entry))
52a244eb
S
7984 (shell-flag (assq 'compiled types))
7985 (buffer-flag (assq 'buffer types))
7986 (user-flag (assq 'user types))
7987 (lib-flag (assq 'lib types))
7988 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
7989 (and user-flag (idlwave-count-memq 'user types))
7990 (and lib-flag (idlwave-count-memq 'lib types))
15e42531
CD
7991 1))
7992 (doflags t)
7993 beg special)
7994
7995 (insert prefix)
7996
7997 (cond
7998 ((eq key 'system)
7999 (setq doflags nil)
52a244eb
S
8000 (insert "System "))
8001
15e42531
CD
8002 ((eq key 'builtin)
8003 (setq doflags nil)
52a244eb
S
8004 (insert "Builtin "))
8005
15e42531 8006 ((and (not file) shell-flag)
52a244eb
S
8007 (insert "Unresolved"))
8008
31b58798 8009 ((null file)
52a244eb 8010 (insert "ERROR"))
31b58798 8011
15e42531
CD
8012 ((idlwave-syslib-p file)
8013 (if (string-match "obsolete" (file-name-directory file))
52a244eb
S
8014 (insert "Obsolete ")
8015 (insert "SystemLib ")))
8016
8017 ;; New special syntax: taken directly from routine-info for
8018 ;; library catalog routines
8019 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8020 (insert (format "%-10s" special)))
8021
8022 ;; Old special syntax: a matching regexp
8023 ((setq special (idlwave-special-lib-test file))
8024 (insert (format "%-10s" special)))
31b58798 8025
52a244eb 8026 ;; Catch-all with file
15e42531 8027 ((idlwave-lib-p file) (insert "Library "))
52a244eb
S
8028
8029 ;; Sanity catch all
15e42531
CD
8030 (t (insert "Other ")))
8031
8032 (when doflags
8033 (insert (concat
8034 " ["
52a244eb
S
8035 (if lib-flag "L" "-")
8036 (if user-flag "C" "-")
15e42531
CD
8037 (if shell-flag "S" "-")
8038 (if buffer-flag "B" "-")
8039 "] ")))
31b58798 8040 (when (> ndupl 1)
15e42531
CD
8041 (setq beg (point))
8042 (insert (format "(%dx) " ndupl))
8043 (add-text-properties beg (point) (list 'face 'bold)))
8044 (when (and file (not (equal file "")))
8045 (setq beg (point))
8046 (insert (apply 'abbreviate-file-name
8047 (if (featurep 'xemacs) (list file t) (list file))))
8048 (if file-props
8049 (add-text-properties beg (point) file-props)))))
8050
8051(defun idlwave-special-lib-test (file)
8052 "Check the path of FILE against the regexps which define special libs.
8053Return the name of the special lib if there is a match."
8054 (let ((alist idlwave-special-lib-alist)
8055 entry rtn)
8056 (cond
8057 ((stringp file)
8058 (while (setq entry (pop alist))
8059 (if (string-match (car entry) file)
8060 (setq rtn (cdr entry)
8061 alist nil)))
8062 rtn)
8063 (t nil))))
31b58798 8064
f32b3b91
CD
8065(defun idlwave-mouse-active-rinfo-right (ev)
8066 (interactive "e")
8067 (idlwave-mouse-active-rinfo ev 'right))
8068
15e42531 8069(defun idlwave-mouse-active-rinfo-shift (ev)
f32b3b91 8070 (interactive "e")
15e42531
CD
8071 (idlwave-mouse-active-rinfo ev nil 'shift))
8072
8073(defun idlwave-active-rinfo-space ()
8074 (interactive)
8075 (idlwave-mouse-active-rinfo nil 'right))
8076
8077(defun idlwave-mouse-active-rinfo (ev &optional right shift)
8078 "Does the mouse actions in the routine info buffer.
8079Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8080was pressed."
8081 (interactive "e")
8082 (if ev (mouse-set-point ev))
31b58798 8083 (let (data id name type class buf bufwin source link keyword
3938cb82 8084 word initial-class)
f32b3b91 8085 (setq data (get-text-property (point) 'data)
15e42531 8086 source (get-text-property (point) 'source)
f32b3b91 8087 keyword (get-text-property (point) 'keyword)
52a244eb 8088 link (get-text-property (point) 'link)
f32b3b91 8089 id (car data)
15e42531 8090 name (nth 1 data) type (nth 2 data) class (nth 3 data)
f32b3b91 8091 buf (nth 4 data)
05a1abfc
CD
8092 initial-class (nth 6 data)
8093 word (idlwave-this-word)
f32b3b91 8094 bufwin (get-buffer-window buf t))
52a244eb
S
8095
8096 (cond ((eq id 'class) ; Switch class being displayed
05a1abfc 8097 (if (window-live-p bufwin) (select-window bufwin))
31b58798 8098 (idlwave-display-calling-sequence
05a1abfc 8099 (idlwave-sintern-method name)
31b58798 8100 type (idlwave-sintern-class word)
05a1abfc 8101 initial-class))
52a244eb
S
8102 ((eq id 'usage) ; Online help on this routine
8103 (idlwave-online-help link name type class))
8104 ((eq id 'source) ; Source in help or buffer
8105 (if right ; In help
15e42531
CD
8106 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8107 (idlwave-help-source-try-header nil)
52a244eb 8108 ;; Fake idlwave-routines so help will find the right entry
15e42531 8109 (idlwave-routines
52a244eb 8110 (list (list name type class source ""))))
15e42531 8111 (idlwave-help-get-special-help name type class nil))
52a244eb 8112 ;; Otherwise just pop to the source
f32b3b91
CD
8113 (setq idlwave-popup-source (not idlwave-popup-source))
8114 (if idlwave-popup-source
8115 (condition-case err
15e42531 8116 (idlwave-do-find-module name type class source)
f32b3b91
CD
8117 (error
8118 (setq idlwave-popup-source nil)
8119 (if (window-live-p bufwin) (select-window bufwin))
8120 (error (nth 1 err))))
8121 (if bufwin
8122 (select-window bufwin)
15e42531
CD
8123 (pop-to-buffer buf))
8124 (goto-char (marker-position idlwave-rinfo-marker)))))
f32b3b91
CD
8125 ((eq id 'keyword)
8126 (if right
52a244eb 8127 (idlwave-online-help link name type class keyword)
15e42531
CD
8128 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8129
8130(defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8131 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8132 (let ((bwin (get-buffer-window buffer)))
8133 (if idlwave-complete-empty-string-as-lower-case
8134 (setq keyword (downcase keyword)))
8135 (if bwin
8136 (select-window bwin)
8137 (pop-to-buffer buffer)
8138 (setq bwin (get-buffer-window buffer)))
8139 (if (eq (preceding-char) ?/)
8140 (insert keyword)
31b58798 8141 (unless (save-excursion
15e42531 8142 (re-search-backward
31b58798 8143 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
15e42531
CD
8144 (min (- (point) 100) (point-min)) t))
8145 (insert ", "))
8146 (if shift (insert "/"))
8147 (insert keyword)
8148 (if (and (not shift)
8149 idlwave-keyword-completion-adds-equal)
8150 (insert "=")))))
8151
8152(defun idlwave-list-buffer-load-path-shadows (&optional arg)
8153 "List the load path shadows of all routines defined in current buffer."
8154 (interactive "P")
8155 (idlwave-routines)
8156 (if (eq major-mode 'idlwave-mode)
8157 (idlwave-list-load-path-shadows
8158 nil (idlwave-update-current-buffer-info 'save-buffer)
8159 "in current buffer")
8160 (error "Current buffer is not in idlwave-mode")))
8161
8162(defun idlwave-list-shell-load-path-shadows (&optional arg)
8163 "List the load path shadows of all routines compiled under the shell.
8164This is very useful for checking an IDL application. Just compile the
8165application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8166routines and update IDLWAVE internal info. Then check for shadowing
8167with this command."
8168 (interactive "P")
8169 (cond
8170 ((or (not (fboundp 'idlwave-shell-is-running))
8171 (not (idlwave-shell-is-running)))
8172 (error "Shell is not running"))
8173 ((null idlwave-compiled-routines)
e8af40ee 8174 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
15e42531
CD
8175 (t
8176 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8177 "in the shell"))))
8178
8179(defun idlwave-list-all-load-path-shadows (&optional arg)
8180 "List the load path shadows of all routines known to IDLWAVE."
8181 (interactive "P")
8182 (idlwave-list-load-path-shadows nil nil "globally"))
8183
8184(defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8185 "List the routines which are defined multiple times.
8186Search the information IDLWAVE has about IDL routines for multiple
8187definitions.
8188When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8189
8190When IDL hits a routine call which is not defined, it will search on
8191the load path in order to find a definition. The output of this
8192command can be used to detect possible name clashes during this process."
8193 (idlwave-routines) ; Make sure everything is loaded.
52a244eb 8194 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
31b58798 8195 (or (y-or-n-p
52a244eb 8196 "You don't have any user or library catalogs. Continue anyway? ")
15e42531
CD
8197 (error "Abort")))
8198 (let* ((routines (append idlwave-system-routines
8199 idlwave-compiled-routines
52a244eb
S
8200 idlwave-library-catalog-routines
8201 idlwave-user-catalog-routines
15e42531
CD
8202 idlwave-buffer-routines
8203 nil))
8204 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8205 (keymap (make-sparse-keymap))
8206 (props (list 'mouse-face 'highlight
8207 km-prop keymap
31b58798 8208 'help-echo "Mouse2: Find source"))
15e42531
CD
8209 (nroutines (length (or special-routines routines)))
8210 (step (/ nroutines 99))
8211 (n 0)
8212 (next-perc 1)
8213 (cnt 0)
8214 (idlwave-sort-prefer-buffer-info nil)
8215 routine twins dtwins twin done props1 lroutines)
8216
8217 (if special-routines
8218 ;; Just looking for shadows of a few special routines
8219 (setq lroutines routines
8220 routines special-routines))
8221
8222 (message "Sorting routines...")
8223 (setq routines (sort routines
8224 (lambda (a b)
8225 (string< (downcase (idlwave-make-full-name
8226 (nth 2 a) (car a)))
8227 (downcase (idlwave-make-full-name
8228 (nth 2 b) (car b)))))))
8229 (message "Sorting routines...done")
8230
8231 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
31b58798 8232 (lambda (ev)
15e42531
CD
8233 (interactive "e")
8234 (mouse-set-point ev)
8235 (apply 'idlwave-do-find-module
8236 (get-text-property (point) 'find-args))))
8237 (define-key keymap [(return)]
31b58798 8238 (lambda ()
15e42531
CD
8239 (interactive)
8240 (apply 'idlwave-do-find-module
8241 (get-text-property (point) 'find-args))))
8242 (message "Compiling list...( 0%%)")
8243 (save-excursion
8244 (set-buffer (get-buffer-create "*Shadows*"))
8245 (setq buffer-read-only nil)
8246 (erase-buffer)
8247 (while (setq routine (pop routines))
8248 (setq n (1+ n))
8249 (if (= (* next-perc step) n)
8250 (progn
8251 (message "Compiling list...(%2d%%)" next-perc)
8252 (setq next-perc (1+ next-perc))))
8253 ;; Get a list of all twins
8254 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8255 (if (memq routine done)
8256 (setq dtwins nil)
8257 (setq dtwins (idlwave-study-twins twins)))
5e72c6b2 8258 ;; Mark all twins as dealt with
15e42531
CD
8259 (setq done (append twins done))
8260 (when (or (> (length dtwins) 1)
52a244eb
S
8261 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8262 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8263 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
15e42531
CD
8264 (incf cnt)
8265 (insert (format "\n%s%s"
31b58798 8266 (idlwave-make-full-name (nth 2 routine)
52a244eb 8267 (car routine))
15e42531
CD
8268 (if (eq (nth 1 routine) 'fun) "()" "")))
8269 (while (setq twin (pop dtwins))
8270 (setq props1 (append (list 'find-args
31b58798
JB
8271 (list (nth 0 routine)
8272 (nth 1 routine)
52a244eb 8273 (nth 2 routine)))
15e42531
CD
8274 props))
8275 (idlwave-insert-source-location "\n - " twin props1))))
8276 (goto-char (point-min))
8277 (setq buffer-read-only t))
8278 (setq loc (or loc ""))
8279 (if (> cnt 0)
8280 (progn
8281 (display-buffer (get-buffer "*Shadows*"))
8282 (message "%d case%s of shadowing found %s"
8283 cnt (if (= cnt 1) "" "s") loc))
8284 (message "No shadowing conflicts found %s" loc))))
8285
8286(defun idlwave-print-source (routine)
8287 (let* ((source (nth 3 routine))
8288 (stype (car source))
52a244eb
S
8289 (sfile (idlwave-routine-source-file source)))
8290 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
15e42531
CD
8291 (if (and (eq stype 'compiled)
8292 (or (not (stringp sfile))
8293 (not (string-match "\\S-" sfile))))
8294 (setq stype 'unresolved))
31b58798 8295 (princ (format " %-10s %s\n"
15e42531
CD
8296 stype
8297 (if sfile sfile "No source code available")))))
8298
8299(defun idlwave-routine-twins (entry &optional list)
8300 "Return all twin entries of ENTRY in LIST.
8301LIST defaults to `idlwave-routines'.
8302Twin entries are those which have the same name, type, and class.
8303ENTRY will also be returned, as the first item of this list."
8304 (let* ((name (car entry))
8305 (type (nth 1 entry))
8306 (class (nth 2 entry))
8307 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8308 twins candidate)
8309 (while (setq candidate (pop candidates))
8310 (if (and (not (eq candidate entry))
8311 (eq type (nth 1 candidate))
8312 (eq class (nth 2 candidate)))
8313 (push candidate twins)))
31b58798 8314 (if (setq candidate (idlwave-rinfo-assq name type class
15e42531
CD
8315 idlwave-unresolved-routines))
8316 (push candidate twins))
8317 (cons entry (nreverse twins))))
8318
8319(defun idlwave-study-twins (entries)
31b58798 8320 "Return dangerous twins of first entry in ENTRIES.
52a244eb
S
8321Dangerous twins are routines with same name, but in different files on
8322the load path. If a file is in the system library and has an entry in
8323the `idlwave-system-routines' list, we omit the latter as
8324non-dangerous because many IDL routines are implemented as library
8325routines, and may have been scanned."
15e42531 8326 (let* ((entry (car entries))
31b58798 8327 (name (car entry)) ;
15e42531
CD
8328 (type (nth 1 entry)) ; Must be bound for
8329 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8330 (cnt 0)
52a244eb 8331 source type type-cons file alist syslibp key)
15e42531
CD
8332 (while (setq entry (pop entries))
8333 (incf cnt)
8334 (setq source (nth 3 entry)
8335 type (car source)
52a244eb
S
8336 type-cons (cons type (nth 3 source))
8337 file (idlwave-routine-source-file source))
8338
15e42531
CD
8339 ;; Make KEY to index entry properly
8340 (setq key (cond ((eq type 'system) type)
8341 (file (file-truename file))
8342 (t 'unresolved)))
52a244eb
S
8343
8344 ;; Check for an entry in the system library
31b58798 8345 (if (and file
15e42531
CD
8346 (not syslibp)
8347 (idlwave-syslib-p file))
15e42531 8348 (setq syslibp t))
31b58798 8349
52a244eb
S
8350 ;; If there's more than one matching entry for the same file, just
8351 ;; append the type-cons to the type list.
15e42531 8352 (if (setq entry (assoc key alist))
52a244eb
S
8353 (push type-cons (nth 2 entry))
8354 (push (list key file (list type-cons)) alist)))
31b58798 8355
15e42531 8356 (setq alist (nreverse alist))
31b58798 8357
15e42531 8358 (when syslibp
52a244eb
S
8359 ;; File is in system *library* - remove any 'system entry
8360 (setq alist (delq (assq 'system alist) alist)))
31b58798 8361
52a244eb
S
8362 ;; If 'system remains and we've scanned the syslib, it's a builtin
8363 ;; (rather than a !DIR/lib/.pro file bundled as source).
15e42531
CD
8364 (when (and (idlwave-syslib-scanned-p)
8365 (setq entry (assoc 'system alist)))
8366 (setcar entry 'builtin))
8367 (sort alist 'idlwave-routine-twin-compare)))
8368
15e42531
CD
8369(defvar type)
8370(defvar class)
8371(defvar idlwave-sort-prefer-buffer-info t
8372 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8373
8374(defmacro idlwave-xor (a b)
8375 `(and (or ,a ,b)
8376 (not (and ,a ,b))))
8377
8378(defun idlwave-routine-entry-compare (a b)
8379 "Compare two routine info entries for sortiung. This is the general case.
8380It first compates class, names, and type. If it turns out that A and B
cef6cafe 8381are twins (same name, class, and type), calls another routine which
15e42531
CD
8382compares twins on the basis of their file names and path locations."
8383 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8384 (cond
8385 ((not (equal (idlwave-downcase-safe class)
8386 (idlwave-downcase-safe (nth 2 b))))
8387 ;; Class decides
8388 (cond ((null (nth 2 b)) nil)
8389 ((null class) t)
8390 (t (string< (downcase class) (downcase (nth 2 b))))))
8391 ((not (equal (downcase name) (downcase (car b))))
8392 ;; Name decides
8393 (string< (downcase name) (downcase (car b))))
8394 ((not (eq type (nth 1 b)))
8395 ;; Type decides
8396 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
31b58798 8397 (t
15e42531
CD
8398 ;; A and B are twins - so the decision is more complicated.
8399 ;; Call twin-compare with the proper arguments.
8400 (idlwave-routine-entry-compare-twins a b)))))
8401
8402(defun idlwave-routine-entry-compare-twins (a b)
52a244eb
S
8403 "Compare two routine entries, under the assumption that they are
8404twins. This basically calls `idlwave-routine-twin-compare' with the
8405correct args."
8406 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8407 (asrc (nth 3 a))
8408 (atype (car asrc))
8409 (bsrc (nth 3 b))
8410 (btype (car bsrc))
8411 (afile (idlwave-routine-source-file asrc))
8412 (bfile (idlwave-routine-source-file bsrc)))
15e42531
CD
8413 (idlwave-routine-twin-compare
8414 (if (stringp afile)
8415 (list (file-truename afile) afile (list atype))
8416 (list atype afile (list atype)))
8417 (if (stringp bfile)
8418 (list (file-truename bfile) bfile (list btype))
8419 (list btype bfile (list btype))))
8420 ))
8421
8422(defun idlwave-routine-twin-compare (a b)
8423 "Compare two routine twin entries for sorting.
8424In here, A and B are not normal routine info entries, but special
8425lists (KEY FILENAME (TYPES...)).
8426This expects NAME TYPE CLASS to be bound to the right values."
8427 (let* (;; Dis-assemble entries
8428 (akey (car a)) (bkey (car b))
8429 (afile (nth 1 a)) (bfile (nth 1 b))
8430 (atypes (nth 2 a)) (btypes (nth 2 b))
8431 ;; System routines?
8432 (asysp (memq akey '(builtin system)))
8433 (bsysp (memq bkey '(builtin system)))
8434 ;; Compiled routines?
8435 (acompp (memq 'compiled atypes))
8436 (bcompp (memq 'compiled btypes))
8437 ;; Unresolved?
8438 (aunresp (or (eq akey 'unresolved)
8439 (and acompp (not afile))))
8440 (bunresp (or (eq bkey 'unresolved)
8441 (and bcompp (not bfile))))
8442 ;; Buffer info available?
8443 (abufp (memq 'buffer atypes))
8444 (bbufp (memq 'buffer btypes))
8445 ;; On search path?
8446 (tpath-alist (idlwave-true-path-alist))
52a244eb
S
8447 (apathp (and (stringp akey)
8448 (assoc (file-name-directory akey) tpath-alist)))
31b58798 8449 (bpathp (and (stringp bkey)
52a244eb 8450 (assoc (file-name-directory bkey) tpath-alist)))
15e42531
CD
8451 ;; How early on search path? High number means early since we
8452 ;; measure the tail of the path list
8453 (anpath (length (memq apathp tpath-alist)))
8454 (bnpath (length (memq bpathp tpath-alist)))
8455 ;; Look at file names
8456 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8457 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8458 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8459 (regexp-quote (downcase class))
8460 (regexp-quote (downcase name)))
8461 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8462 ;; Is file name derived from the routine name?
8463 ;; Method file or class definition file?
8464 (anamep (string-match fname-re aname))
8465 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8466 (bnamep (string-match fname-re bname))
8467 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8468
8469 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8470 ;; doesn't it? The difficult stuff is hidden above...
8471 (cond
8472 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8473 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8474 ((and idlwave-sort-prefer-buffer-info
8475 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8476 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8477 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8478 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8479 ((and class anamep bnamep ; both file names match ->
8480 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8481 ((> anpath bnpath) t) ; Who is first on path?
8482 (t nil)))) ; Default
8483
52a244eb 8484(defun idlwave-routine-source-file (source)
31b58798 8485 (if (nth 2 source)
52a244eb
S
8486 (expand-file-name (nth 1 source) (nth 2 source))
8487 (nth 1 source)))
8488
15e42531
CD
8489(defun idlwave-downcase-safe (string)
8490 "Donwcase if string, else return unchanged."
8491 (if (stringp string)
8492 (downcase string)
8493 string))
8494
8495(defun idlwave-count-eq (elt list)
8496 "How often is ELT in LIST?"
8497 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
8498
52a244eb
S
8499(defun idlwave-count-memq (elt alist)
8500 "How often is ELT a key in ALIST?"
8501 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
8502
15e42531 8503(defun idlwave-syslib-p (file)
52a244eb 8504 "Non-nil if FILE is in the system library."
15e42531
CD
8505 (let* ((true-syslib (file-name-as-directory
8506 (file-truename
8507 (expand-file-name "lib" (idlwave-sys-dir)))))
8508 (true-file (file-truename file)))
8509 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
8510
8511(defun idlwave-lib-p (file)
8512 "Non-nil if file is in the library"
8513 (let ((true-dir (file-name-directory (file-truename file))))
8514 (assoc true-dir (idlwave-true-path-alist))))
8515
52a244eb
S
8516(defun idlwave-path-alist-add-flag (list-entry flag)
8517 "Add a flag to the path list entry, if not set."
8518 (let ((flags (cdr list-entry)))
8519 (add-to-list 'flags flag)
8520 (setcdr list-entry flags)))
8521
8522(defun idlwave-path-alist-remove-flag (list-entry flag)
8523 "Remove a flag to the path list entry, if set."
8524 (let ((flags (delq flag (cdr list-entry))))
8525 (setcdr list-entry flags)))
8526
15e42531
CD
8527(defun idlwave-true-path-alist ()
8528 "Return `idlwave-path-alist' alist with true-names.
52a244eb 8529Info is cached, but relies on the functions setting `idlwave-path-alist'
15e42531
CD
8530to reset the variable `idlwave-true-path-alist' to nil."
8531 (or idlwave-true-path-alist
8532 (setq idlwave-true-path-alist
8533 (mapcar (lambda(x) (cons
8534 (file-name-as-directory
8535 (file-truename
8536 (directory-file-name
8537 (car x))))
8538 (cdr x)))
8539 idlwave-path-alist))))
8540
8541(defun idlwave-syslib-scanned-p ()
8542 "Non-nil if the system lib file !DIR/lib has been scanned."
8543 (let* ((true-syslib (file-name-as-directory
8544 (file-truename
8545 (expand-file-name "lib" (idlwave-sys-dir))))))
8546 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
8547
8548;; ----------------------------------------------------------------------------
8549;;
8550;; Online Help display
8551
f32b3b91
CD
8552
8553;; ----------------------------------------------------------------------------
8554;;
8555;; Additions for use with imenu.el and func-menu.el
8556;; (pop-up a list of IDL units in the current file).
8557;;
8558
8559(defun idlwave-prev-index-position ()
8560 "Search for the previous procedure or function.
8561Return nil if not found. For use with imenu.el."
8562 (save-match-data
8563 (cond
8564 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
8565 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
8566 (t nil))))
8567
8568(defun idlwave-unit-name ()
8569 "Return the unit name.
8570Assumes that point is at the beginning of the unit as found by
8571`idlwave-prev-index-position'."
8572 (forward-sexp 2)
8573 (forward-sexp -1)
8574 (let ((begin (point)))
31b58798 8575 (re-search-forward
52a244eb 8576 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
f32b3b91
CD
8577 (if (fboundp 'buffer-substring-no-properties)
8578 (buffer-substring-no-properties begin (point))
8579 (buffer-substring begin (point)))))
8580
facebc7b
S
8581(defalias 'idlwave-function-menu
8582 (condition-case nil
f32b3b91
CD
8583 (progn
8584 (require 'func-menu)
facebc7b
S
8585 'function-menu)
8586 (error (condition-case nil
8587 (progn
8588 (require 'imenu)
8589 'imenu)
8590 (error nil)))))
f32b3b91 8591
52a244eb 8592;; Here we hack func-menu.el in order to support this new mode.
f32b3b91
CD
8593;; The latest versions of func-menu.el already have this stuff in, so
8594;; we hack only if it is not already there.
8595(when (fboundp 'eval-after-load)
8596 (eval-after-load "func-menu"
8597 '(progn
8598 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
8599 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
8600 (setq fume-function-name-regexp-alist
8601 (cons '(idlwave-mode . fume-function-name-regexp-idl)
8602 fume-function-name-regexp-alist)))
8603 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
8604 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
8605 (setq fume-find-function-name-method-alist
8606 (cons '(idlwave-mode . fume-find-next-idl-function-name)
8607 fume-find-function-name-method-alist))))))
8608
8609(defun idlwave-edit-in-idlde ()
8610 "Edit the current file in IDL Development environment."
8611 (interactive)
8612 (start-process "idldeclient" nil
8613 idlwave-shell-explicit-file-name "-c" "-e"
8614 (buffer-file-name) "&"))
31b58798 8615
f32b3b91
CD
8616(defun idlwave-launch-idlhelp ()
8617 "Start the IDLhelp application."
8618 (interactive)
8619 (start-process "idlhelp" nil idlwave-help-application))
31b58798 8620
f32b3b91
CD
8621;; Menus - using easymenu.el
8622(defvar idlwave-mode-menu-def
8623 `("IDLWAVE"
8624 ["PRO/FUNC menu" idlwave-function-menu t]
8625 ("Motion"
8626 ["Subprogram Start" idlwave-beginning-of-subprogram t]
8627 ["Subprogram End" idlwave-end-of-subprogram t]
8628 ["Block Start" idlwave-beginning-of-block t]
8629 ["Block End" idlwave-end-of-block t]
8630 ["Up Block" idlwave-backward-up-block t]
8631 ["Down Block" idlwave-down-block t]
8632 ["Skip Block Backward" idlwave-backward-block t]
8633 ["Skip Block Forward" idlwave-forward-block t])
8634 ("Mark"
8635 ["Subprogram" idlwave-mark-subprogram t]
8636 ["Block" idlwave-mark-block t]
8637 ["Header" idlwave-mark-doclib t])
8638 ("Format"
8639 ["Indent Subprogram" idlwave-indent-subprogram t]
8640 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
8641 ["Continue/Split line" idlwave-split-line t]
8642 "--"
8643 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
8644 :selected (symbol-value idlwave-fill-function)])
8645 ("Templates"
8646 ["Procedure" idlwave-procedure t]
8647 ["Function" idlwave-function t]
8648 ["Doc Header" idlwave-doc-header t]
8649 ["Log" idlwave-doc-modification t]
8650 "--"
8651 ["Case" idlwave-case t]
8652 ["For" idlwave-for t]
8653 ["Repeat" idlwave-repeat t]
8654 ["While" idlwave-while t]
8655 "--"
8656 ["Close Block" idlwave-close-block t])
15e42531 8657 ("Completion"
f32b3b91
CD
8658 ["Complete" idlwave-complete t]
8659 ("Complete Special"
8660 ["1 Procedure Name" (idlwave-complete 'procedure) t]
8661 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
8662 "--"
8663 ["3 Function Name" (idlwave-complete 'function) t]
8664 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
8665 "--"
8666 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
8667 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
8668 "--"
8669 ["7 Function Method Name" (idlwave-complete 'function-method) t]
8670 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
8671 "--"
15e42531
CD
8672 ["9 Class Name" idlwave-complete-class t]))
8673 ("Routine Info"
f32b3b91 8674 ["Show Routine Info" idlwave-routine-info t]
52a244eb 8675 ["Online Context Help" idlwave-context-help t]
f32b3b91
CD
8676 "--"
8677 ["Find Routine Source" idlwave-find-module t]
15e42531 8678 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
f32b3b91
CD
8679 "--"
8680 ["Update Routine Info" idlwave-update-routine-info t]
8681 "--"
52a244eb
S
8682 "IDL User Catalog"
8683 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
15e42531 8684 ["Scan Directories" (idlwave-update-routine-info '(16))
5e72c6b2
S
8685 (and idlwave-path-alist (not idlwave-catalog-process))]
8686 ["Scan Directories &" (idlwave-update-routine-info '(64))
8687 (and idlwave-path-alist (not idlwave-catalog-process))]
15e42531
CD
8688 "--"
8689 "Routine Shadows"
8690 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
8691 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
8692 ["Check Everything" idlwave-list-all-load-path-shadows t])
8693 ("Misc"
8694 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
8695 "--"
8696 ["Insert TAB character" idlwave-hard-tab t])
f32b3b91
CD
8697 "--"
8698 ("External"
8699 ["Generate IDL tags" idlwave-make-tags t]
8700 ["Start IDL shell" idlwave-shell t]
8701 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
8702 ["Launch IDL Help" idlwave-launch-idlhelp t])
8703 "--"
8704 ("Customize"
8705 ["Browse IDLWAVE Group" idlwave-customize t]
8706 "--"
31b58798 8707 ["Build Full Customize Menu" idlwave-create-customize-menu
f32b3b91
CD
8708 (fboundp 'customize-menu-create)])
8709 ("Documentation"
8710 ["Describe Mode" describe-mode t]
8711 ["Abbreviation List" idlwave-list-abbrevs t]
8712 "--"
8713 ["Commentary in idlwave.el" idlwave-show-commentary t]
595ab50b 8714 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
f32b3b91
CD
8715 "--"
8716 ["Info" idlwave-info t]
8717 "--"
8718 ["Launch IDL Help" idlwave-launch-idlhelp t])))
8719
8720(defvar idlwave-mode-debug-menu-def
8721 '("Debug"
8722 ["Start IDL shell" idlwave-shell t]
8723 ["Save and .RUN buffer" idlwave-shell-save-and-run
31b58798 8724 (and (boundp 'idlwave-shell-automatic-start)
f32b3b91
CD
8725 idlwave-shell-automatic-start)]))
8726
8727(if (or (featurep 'easymenu) (load "easymenu" t))
8728 (progn
31b58798
JB
8729 (easy-menu-define idlwave-mode-menu idlwave-mode-map
8730 "IDL and WAVE CL editing menu"
f32b3b91 8731 idlwave-mode-menu-def)
31b58798
JB
8732 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
8733 "IDL and WAVE CL editing menu"
f32b3b91
CD
8734 idlwave-mode-debug-menu-def)))
8735
8736(defun idlwave-customize ()
8737 "Call the customize function with idlwave as argument."
8738 (interactive)
31b58798 8739 ;; Try to load the code for the shell, so that we can customize it
f32b3b91 8740 ;; as well.
22d5821d
CD
8741 (or (featurep 'idlw-shell)
8742 (load "idlw-shell" t))
f32b3b91
CD
8743 (customize-browse 'idlwave))
8744
8745(defun idlwave-create-customize-menu ()
8746 "Create a full customization menu for IDLWAVE, insert it into the menu."
8747 (interactive)
8748 (if (fboundp 'customize-menu-create)
8749 (progn
31b58798 8750 ;; Try to load the code for the shell, so that we can customize it
f32b3b91 8751 ;; as well.
22d5821d
CD
8752 (or (featurep 'idlw-shell)
8753 (load "idlw-shell" t))
31b58798 8754 (easy-menu-change
f32b3b91
CD
8755 '("IDLWAVE") "Customize"
8756 `(["Browse IDLWAVE group" idlwave-customize t]
8757 "--"
8758 ,(customize-menu-create 'idlwave)
8759 ["Set" Custom-set t]
8760 ["Save" Custom-save t]
8761 ["Reset to Current" Custom-reset-current t]
8762 ["Reset to Saved" Custom-reset-saved t]
8763 ["Reset to Standard Settings" Custom-reset-standard t]))
8764 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8765 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8766
8767(defun idlwave-show-commentary ()
8768 "Use the finder to view the file documentation from `idlwave.el'."
8769 (interactive)
8770 (require 'finder)
8771 (finder-commentary "idlwave.el"))
8772
8773(defun idlwave-shell-show-commentary ()
595ab50b 8774 "Use the finder to view the file documentation from `idlw-shell.el'."
f32b3b91
CD
8775 (interactive)
8776 (require 'finder)
595ab50b 8777 (finder-commentary "idlw-shell.el"))
f32b3b91
CD
8778
8779(defun idlwave-info ()
8780 "Read documentation for IDLWAVE in the info system."
8781 (interactive)
8782 (require 'info)
8783 (Info-goto-node "(idlwave)"))
8784
8785(defun idlwave-list-abbrevs (arg)
8786 "Show the code abbreviations define in IDLWAVE mode.
8787This lists all abbrevs where the replacement text differs from the input text.
8788These are the ones the users want to learn to speed up their writing.
8789
8790The function does *not* list abbrevs which replace a word with itself
8791to call a hook. These hooks are used to change the case of words or
8792to blink the matching `begin', and the user does not need to know them.
8793
8794With arg, list all abbrevs with the corresponding hook.
8795
8796This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8797
8798 (interactive "P")
8799 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8800 abbrevs
8801 str rpl func fmt (len-str 0) (len-rpl 0))
31b58798 8802 (mapatoms
f32b3b91
CD
8803 (lambda (sym)
8804 (if (symbol-value sym)
8805 (progn
8806 (setq str (symbol-name sym)
8807 rpl (symbol-value sym)
8808 func (symbol-function sym))
8809 (if arg
8810 (setq func (prin1-to-string func))
8811 (if (and (listp func) (stringp (nth 2 func)))
8812 (setq rpl (concat "EVAL: " (nth 2 func))
8813 func "")
8814 (setq func "")))
8815 (if (or arg (not (string= rpl str)))
8816 (progn
8817 (setq len-str (max len-str (length str)))
8818 (setq len-rpl (max len-rpl (length rpl)))
8819 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8820 table)
8821 ;; sort the list
8822 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8823 ;; Make the format
8824 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8825 (with-output-to-temp-buffer "*Help*"
8826 (if arg
8827 (progn
31b58798 8828 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
f32b3b91
CD
8829 (princ "=========================================\n\n")
8830 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8831 (princ (format fmt "---" "-------" "----")))
8832 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8833 (princ "================================================\n\n")
8834 (princ (format fmt "KEY" "ACTION" ""))
8835 (princ (format fmt "---" "------" "")))
8836 (mapcar
8837 (lambda (list)
8838 (setq str (car list)
8839 rpl (nth 1 list)
8840 func (nth 2 list))
8841 (princ (format fmt str rpl func)))
8842 abbrevs)))
8843 ;; Make sure each abbreviation uses only one display line
8844 (save-excursion
8845 (set-buffer "*Help*")
8846 (setq truncate-lines t)))
8847
5e72c6b2
S
8848;; Add .pro files to speedbar for support, if it's loaded
8849(eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8850
5e72c6b2
S
8851;; Set an idle timer to load the routine info.
8852;; Will only work on systems which support this.
8853(or idlwave-routines (idlwave-start-load-rinfo-timer))
8854
52a244eb
S
8855;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
8856
15e42531 8857;; Run the hook
f32b3b91
CD
8858(run-hooks 'idlwave-load-hook)
8859
8860(provide 'idlwave)
8861
8df608c1 8862;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
f32b3b91 8863;;; idlwave.el ends here