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